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

Side by Side Diff: chrome/browser/ui/android/ssl_client_certificate_request.cc

Issue 1304143010: Plumbing SSLPrivateKey Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unused function in Android. Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/ui/android/ssl_client_certificate_request.h" 5 #include "chrome/browser/ui/android/ssl_client_certificate_request.h"
6 6
7 #include "base/android/jni_array.h" 7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" 14 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
15 #include "chrome/browser/ui/android/window_android_helper.h" 15 #include "chrome/browser/ui/android/window_android_helper.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/client_certificate_delegate.h" 17 #include "content/public/browser/client_certificate_delegate.h"
18 #include "crypto/scoped_openssl_types.h" 18 #include "crypto/scoped_openssl_types.h"
19 #include "jni/SSLClientCertificateRequest_jni.h" 19 #include "jni/SSLClientCertificateRequest_jni.h"
20 #include "net/android/keystore_openssl.h" 20 #include "net/android/keystore_openssl.h"
21 #include "net/base/host_port_pair.h" 21 #include "net/base/host_port_pair.h"
22 #include "net/cert/cert_database.h" 22 #include "net/cert/cert_database.h"
23 #include "net/cert/x509_certificate.h" 23 #include "net/cert/x509_certificate.h"
24 #include "net/ssl/openssl_client_key_store.h"
25 #include "net/ssl/ssl_cert_request_info.h" 24 #include "net/ssl/ssl_cert_request_info.h"
26 #include "net/ssl/ssl_client_cert_type.h" 25 #include "net/ssl/ssl_client_cert_type.h"
26 #include "net/ssl/ssl_platform_key.h"
27 #include "net/ssl/ssl_private_key.h"
27 #include "ui/android/window_android.h" 28 #include "ui/android/window_android.h"
28 29
29 namespace chrome { 30 namespace chrome {
30 31
31 namespace { 32 namespace {
32 33
33 // Must be called on the I/O thread to record a client certificate
34 // and its private key in the OpenSSLClientKeyStore.
35 void RecordClientCertificateKey(
36 const scoped_refptr<net::X509Certificate>& client_cert,
37 crypto::ScopedEVP_PKEY private_key) {
38 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
39 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey(
40 client_cert.get(), private_key.get());
41 }
42
43 void StartClientCertificateRequest( 34 void StartClientCertificateRequest(
44 const net::SSLCertRequestInfo* cert_request_info, 35 const net::SSLCertRequestInfo* cert_request_info,
45 ui::WindowAndroid* window, 36 ui::WindowAndroid* window,
46 scoped_ptr<content::ClientCertificateDelegate> delegate) { 37 scoped_ptr<content::ClientCertificateDelegate> delegate) {
47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
48 39
49 // Build the |key_types| JNI parameter, as a String[] 40 // Build the |key_types| JNI parameter, as a String[]
50 std::vector<std::string> key_types; 41 std::vector<std::string> key_types;
51 for (size_t n = 0; n < cert_request_info->cert_key_types.size(); ++n) { 42 for (size_t n = 0; n < cert_request_info->cert_key_types.size(); ++n) {
52 switch (cert_request_info->cert_key_types[n]) { 43 switch (cert_request_info->cert_key_types[n]) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 const JavaParamRef<jobjectArray>& encoded_chain_ref, 117 const JavaParamRef<jobjectArray>& encoded_chain_ref,
127 const JavaParamRef<jobject>& private_key_ref) { 118 const JavaParamRef<jobject>& private_key_ref) {
128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
129 120
130 // Take back ownership of the delegate object. 121 // Take back ownership of the delegate object.
131 scoped_ptr<content::ClientCertificateDelegate> delegate( 122 scoped_ptr<content::ClientCertificateDelegate> delegate(
132 reinterpret_cast<content::ClientCertificateDelegate*>(request_id)); 123 reinterpret_cast<content::ClientCertificateDelegate*>(request_id));
133 124
134 if (encoded_chain_ref == NULL || private_key_ref == NULL) { 125 if (encoded_chain_ref == NULL || private_key_ref == NULL) {
135 LOG(ERROR) << "No client certificate selected"; 126 LOG(ERROR) << "No client certificate selected";
136 delegate->ContinueWithCertificate(nullptr); 127 delegate->ContinueWithCertificate(nullptr, nullptr);
137 return; 128 return;
138 } 129 }
139 130
140 // Convert the encoded chain to a vector of strings. 131 // Convert the encoded chain to a vector of strings.
141 std::vector<std::string> encoded_chain_strings; 132 std::vector<std::string> encoded_chain_strings;
142 if (encoded_chain_ref) { 133 if (encoded_chain_ref) {
143 base::android::JavaArrayOfByteArrayToStringVector( 134 base::android::JavaArrayOfByteArrayToStringVector(
144 env, encoded_chain_ref, &encoded_chain_strings); 135 env, encoded_chain_ref, &encoded_chain_strings);
145 } 136 }
146 137
(...skipping 10 matching lines...) Expand all
157 } 148 }
158 149
159 // Create an EVP_PKEY wrapper for the private key JNI reference. 150 // Create an EVP_PKEY wrapper for the private key JNI reference.
160 crypto::ScopedEVP_PKEY private_key( 151 crypto::ScopedEVP_PKEY private_key(
161 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); 152 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref));
162 if (!private_key.get()) { 153 if (!private_key.get()) {
163 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; 154 LOG(ERROR) << "Could not create OpenSSL wrapper for private key";
164 return; 155 return;
165 } 156 }
166 157
167 // RecordClientCertificateKey() must be called on the I/O thread, 158 scoped_refptr<net::SSLPrivateKey> client_private_key =
168 // before the callback is called with the selected certificate on 159 net::WrapOpenSSLPrivateKey(private_key.Pass());
169 // the UI thread. 160
170 content::BrowserThread::PostTaskAndReply( 161 content::BrowserThread::PostTask(
171 content::BrowserThread::IO, FROM_HERE, 162 content::BrowserThread::IO, FROM_HERE,
172 base::Bind(&RecordClientCertificateKey, client_cert,
173 base::Passed(&private_key)),
174 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, 163 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate,
175 base::Owned(delegate.release()), client_cert)); 164 base::Owned(delegate.release()), client_cert,
165 client_private_key));
176 } 166 }
177 167
178 static void NotifyClientCertificatesChanged() { 168 static void NotifyClientCertificatesChanged() {
179 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged(); 169 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged();
180 } 170 }
181 171
182 static void NotifyClientCertificatesChangedOnIOThread( 172 static void NotifyClientCertificatesChangedOnIOThread(
183 JNIEnv* env, 173 JNIEnv* env,
184 const JavaParamRef<jclass>&) { 174 const JavaParamRef<jclass>&) {
185 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { 175 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
(...skipping 17 matching lines...) Expand all
203 net::SSLCertRequestInfo* cert_request_info, 193 net::SSLCertRequestInfo* cert_request_info,
204 scoped_ptr<content::ClientCertificateDelegate> delegate) { 194 scoped_ptr<content::ClientCertificateDelegate> delegate) {
205 ui::WindowAndroid* window = 195 ui::WindowAndroid* window =
206 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); 196 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid();
207 DCHECK(window); 197 DCHECK(window);
208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
209 StartClientCertificateRequest(cert_request_info, window, delegate.Pass()); 199 StartClientCertificateRequest(cert_request_info, window, delegate.Pass());
210 } 200 }
211 201
212 } // namespace chrome 202 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698