Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1177)

Side by Side Diff: chrome/browser/extensions/api/messaging/message_property_provider.cc

Issue 1076063002: Remove certificates from Channel ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some small style/formatting issues Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/cert/x509_util.h » ('j') | net/cert/x509_util_nss.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" 5 #include "chrome/browser/extensions/api/messaging/message_property_provider.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 28 matching lines...) Expand all
39 base::MessageLoopProxy::current(), 39 base::MessageLoopProxy::current(),
40 request_context_getter, 40 request_context_getter,
41 source_url.host(), 41 source_url.host(),
42 reply)); 42 reply));
43 } 43 }
44 44
45 // Helper struct to bind the memory addresses that will be written to by 45 // Helper struct to bind the memory addresses that will be written to by
46 // ChannelIDService::GetChannelID to the callback provided to 46 // ChannelIDService::GetChannelID to the callback provided to
47 // MessagePropertyProvider::GetChannelID. 47 // MessagePropertyProvider::GetChannelID.
48 struct MessagePropertyProvider::GetChannelIDOutput { 48 struct MessagePropertyProvider::GetChannelIDOutput {
49 std::string domain_bound_private_key; 49 scoped_ptr<crypto::ECPrivateKey> channel_id_key;
50 std::string domain_bound_cert;
51 net::ChannelIDService::RequestHandle request_handle; 50 net::ChannelIDService::RequestHandle request_handle;
52 }; 51 };
53 52
54 // static 53 // static
55 void MessagePropertyProvider::GetChannelIDOnIOThread( 54 void MessagePropertyProvider::GetChannelIDOnIOThread(
56 scoped_refptr<base::TaskRunner> original_task_runner, 55 scoped_refptr<base::TaskRunner> original_task_runner,
57 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 56 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
58 const std::string& host, 57 const std::string& host,
59 const ChannelIDCallback& reply) { 58 const ChannelIDCallback& reply) {
60 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 59 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
61 net::ChannelIDService* channel_id_service = 60 net::ChannelIDService* channel_id_service =
62 request_context_getter->GetURLRequestContext()-> 61 request_context_getter->GetURLRequestContext()->
63 channel_id_service(); 62 channel_id_service();
64 GetChannelIDOutput* output = new GetChannelIDOutput(); 63 GetChannelIDOutput* output = new GetChannelIDOutput();
65 net::CompletionCallback net_completion_callback = 64 net::CompletionCallback net_completion_callback =
66 base::Bind(&MessagePropertyProvider::GotChannelID, 65 base::Bind(&MessagePropertyProvider::GotChannelID,
67 original_task_runner, 66 original_task_runner,
68 base::Owned(output), 67 base::Owned(output),
69 reply); 68 reply);
70 int status = channel_id_service->GetChannelID( 69 int status = channel_id_service->GetChannelID(host, &output->channel_id_key,
71 host, 70 net_completion_callback,
72 &output->domain_bound_private_key, 71 &output->request_handle);
73 &output->domain_bound_cert,
74 net_completion_callback,
75 &output->request_handle);
76 if (status == net::ERR_IO_PENDING) 72 if (status == net::ERR_IO_PENDING)
77 return; 73 return;
78 GotChannelID(original_task_runner, output, reply, status); 74 GotChannelID(original_task_runner, output, reply, status);
79 } 75 }
80 76
81 // static 77 // static
82 void MessagePropertyProvider::GotChannelID( 78 void MessagePropertyProvider::GotChannelID(
83 scoped_refptr<base::TaskRunner> original_task_runner, 79 scoped_refptr<base::TaskRunner> original_task_runner,
84 struct GetChannelIDOutput* output, 80 struct GetChannelIDOutput* output,
85 const ChannelIDCallback& reply, 81 const ChannelIDCallback& reply,
86 int status) { 82 int status) {
87 base::Closure no_tls_channel_id_closure = base::Bind(reply, ""); 83 base::Closure no_tls_channel_id_closure = base::Bind(reply, "");
88 if (status != net::OK) { 84 if (status != net::OK) {
89 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); 85 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure);
90 return; 86 return;
91 } 87 }
92 base::StringPiece spki; 88 std::vector<uint8> spki_vector;
93 if (!net::asn1::ExtractSPKIFromDERCert(output->domain_bound_cert, &spki)) { 89 if (!output->channel_id_key->ExportPublicKey(&spki_vector)) {
94 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); 90 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure);
95 return; 91 return;
96 } 92 }
93 base::StringPiece spki(reinterpret_cast<char*>(&spki_vector[0]),
Ryan Sleevi 2015/04/15 22:50:02 vector_as_array<> is far safer for this (see base/
nharper 2015/04/25 02:59:19 Done.
94 spki_vector.size());
97 base::DictionaryValue jwk_value; 95 base::DictionaryValue jwk_value;
98 if (!net::JwkSerializer::ConvertSpkiFromDerToJwk(spki, &jwk_value)) { 96 if (!net::JwkSerializer::ConvertSpkiFromDerToJwk(spki, &jwk_value)) {
99 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); 97 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure);
100 return; 98 return;
101 } 99 }
102 std::string jwk_str; 100 std::string jwk_str;
103 base::JSONWriter::Write(&jwk_value, &jwk_str); 101 base::JSONWriter::Write(&jwk_value, &jwk_str);
104 original_task_runner->PostTask(FROM_HERE, base::Bind(reply, jwk_str)); 102 original_task_runner->PostTask(FROM_HERE, base::Bind(reply, jwk_str));
105 } 103 }
106 104
107 } // namespace extensions 105 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | net/cert/x509_util.h » ('j') | net/cert/x509_util_nss.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698