OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived | 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived |
6 // from AuthCertificateCallback() in | 6 // from AuthCertificateCallback() in |
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. | 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. |
8 | 8 |
9 /* ***** BEGIN LICENSE BLOCK ***** | 9 /* ***** BEGIN LICENSE BLOCK ***** |
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
(...skipping 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2159 SECItem der_cert; | 2159 SECItem der_cert; |
2160 der_cert.type = siDERCertBuffer; | 2160 der_cert.type = siDERCertBuffer; |
2161 der_cert.data = cert_context->pbCertEncoded; | 2161 der_cert.data = cert_context->pbCertEncoded; |
2162 der_cert.len = cert_context->cbCertEncoded; | 2162 der_cert.len = cert_context->cbCertEncoded; |
2163 | 2163 |
2164 // TODO(rsleevi): Error checking for NSS allocation errors. | 2164 // TODO(rsleevi): Error checking for NSS allocation errors. |
2165 *result_certs = CERT_NewCertList(); | 2165 *result_certs = CERT_NewCertList(); |
2166 CERTCertDBHandle* db_handle = CERT_GetDefaultCertDB(); | 2166 CERTCertDBHandle* db_handle = CERT_GetDefaultCertDB(); |
2167 CERTCertificate* user_cert = CERT_NewTempCertificate( | 2167 CERTCertificate* user_cert = CERT_NewTempCertificate( |
2168 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); | 2168 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); |
2169 if (!user_cert) { | |
2170 // Importing the certificate can fail for reasons including a serial | |
2171 // number collision. See crbug.com/97355. | |
2172 CERT_DestroyCertList(*result_certs); | |
2173 *result_certs = NULL; | |
2174 return SECFailure; | |
2175 } | |
2169 CERT_AddCertToListTail(*result_certs, user_cert); | 2176 CERT_AddCertToListTail(*result_certs, user_cert); |
2170 | 2177 |
2171 // Add the intermediates. | 2178 // Add the intermediates. |
2172 X509Certificate::OSCertHandles intermediates = | 2179 X509Certificate::OSCertHandles intermediates = |
2173 that->ssl_config_.client_cert->GetIntermediateCertificates(); | 2180 that->ssl_config_.client_cert->GetIntermediateCertificates(); |
2174 for (X509Certificate::OSCertHandles::const_iterator it = | 2181 for (X509Certificate::OSCertHandles::const_iterator it = |
2175 intermediates.begin(); it != intermediates.end(); ++it) { | 2182 intermediates.begin(); it != intermediates.end(); ++it) { |
2176 der_cert.data = (*it)->pbCertEncoded; | 2183 der_cert.data = (*it)->pbCertEncoded; |
2177 der_cert.len = (*it)->cbCertEncoded; | 2184 der_cert.len = (*it)->cbCertEncoded; |
2178 | 2185 |
2179 CERTCertificate* intermediate = CERT_NewTempCertificate( | 2186 CERTCertificate* intermediate = CERT_NewTempCertificate( |
2180 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); | 2187 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); |
2188 if (!intermediate) { | |
2189 CERT_DestroyCertList(*result_certs); | |
2190 *result_certs = NULL; | |
2191 return SECFailure; | |
2192 } | |
2181 CERT_AddCertToListTail(*result_certs, intermediate); | 2193 CERT_AddCertToListTail(*result_certs, intermediate); |
2182 } | 2194 } |
2183 *result_private_key = key_context; | 2195 *result_private_key = key_context; |
2184 return SECSuccess; | 2196 return SECSuccess; |
2185 } | 2197 } |
2186 PORT_Free(key_context); | 2198 PORT_Free(key_context); |
2187 LOG(WARNING) << "Client cert found without private key"; | 2199 LOG(WARNING) << "Client cert found without private key"; |
2188 } | 2200 } |
2189 // Send no client certificate. | 2201 // Send no client certificate. |
2190 return SECFailure; | 2202 return SECFailure; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2313 os_error = SecCertificateGetData(cert_ref, &cert_data); | 2325 os_error = SecCertificateGetData(cert_ref, &cert_data); |
2314 if (os_error != noErr) | 2326 if (os_error != noErr) |
2315 break; | 2327 break; |
2316 | 2328 |
2317 SECItem der_cert; | 2329 SECItem der_cert; |
2318 der_cert.type = siDERCertBuffer; | 2330 der_cert.type = siDERCertBuffer; |
2319 der_cert.data = cert_data.Data; | 2331 der_cert.data = cert_data.Data; |
2320 der_cert.len = cert_data.Length; | 2332 der_cert.len = cert_data.Length; |
2321 CERTCertificate* nss_cert = CERT_NewTempCertificate( | 2333 CERTCertificate* nss_cert = CERT_NewTempCertificate( |
2322 CERT_GetDefaultCertDB(), &der_cert, NULL, PR_FALSE, PR_TRUE); | 2334 CERT_GetDefaultCertDB(), &der_cert, NULL, PR_FALSE, PR_TRUE); |
2335 if (!nss_cert) { | |
2336 // In the event of an NSS error we make up an OS error and reuse | |
2337 // the error handling, below. | |
2338 os_error = errKCCreateChainFailed; | |
mattm
2011/09/22 21:31:19
Do we need a break here?
agl
2011/09/22 22:07:09
I don't think so but, on the other hand, why not?
| |
2339 } | |
2323 CERT_AddCertToListTail(*result_certs, nss_cert); | 2340 CERT_AddCertToListTail(*result_certs, nss_cert); |
2324 } | 2341 } |
2325 } | 2342 } |
2326 if (os_error == noErr) { | 2343 if (os_error == noErr) { |
2327 CFRelease(chain); | 2344 CFRelease(chain); |
2328 return SECSuccess; | 2345 return SECSuccess; |
2329 } | 2346 } |
2330 LOG(WARNING) << "Client cert found, but could not be used: " | 2347 LOG(WARNING) << "Client cert found, but could not be used: " |
2331 << os_error; | 2348 << os_error; |
2332 if (*result_certs) { | 2349 if (*result_certs) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2498 valid_thread_id_ = base::PlatformThread::CurrentId(); | 2515 valid_thread_id_ = base::PlatformThread::CurrentId(); |
2499 } | 2516 } |
2500 | 2517 |
2501 bool SSLClientSocketNSS::CalledOnValidThread() const { | 2518 bool SSLClientSocketNSS::CalledOnValidThread() const { |
2502 EnsureThreadIdAssigned(); | 2519 EnsureThreadIdAssigned(); |
2503 base::AutoLock auto_lock(lock_); | 2520 base::AutoLock auto_lock(lock_); |
2504 return valid_thread_id_ == base::PlatformThread::CurrentId(); | 2521 return valid_thread_id_ == base::PlatformThread::CurrentId(); |
2505 } | 2522 } |
2506 | 2523 |
2507 } // namespace net | 2524 } // namespace net |
OLD | NEW |