OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 // TODO(wtc,mattm): this is temporary while DBC support is changed into | 375 // TODO(wtc,mattm): this is temporary while DBC support is changed into |
376 // Channel ID. | 376 // Channel ID. |
377 return false; | 377 return false; |
378 } | 378 } |
379 | 379 |
380 void DestroyCertificates(CERTCertificate** certs, size_t len) { | 380 void DestroyCertificates(CERTCertificate** certs, size_t len) { |
381 for (size_t i = 0; i < len; i++) | 381 for (size_t i = 0; i < len; i++) |
382 CERT_DestroyCertificate(certs[i]); | 382 CERT_DestroyCertificate(certs[i]); |
383 } | 383 } |
384 | 384 |
385 // Helper functions to make it possible to log events from within the | |
386 // SSLClientSocketNSS::Core. | |
387 void AddLogEvent(BoundNetLog* net_log, | |
388 NetLog::EventType event_type) { | |
eroman
2012/06/14 17:45:50
Might fit on one line
mmenke
2012/06/14 18:03:45
Done.
| |
389 if (!net_log) | |
390 return; | |
391 net_log->AddEvent(event_type); | |
392 } | |
393 | |
385 // Helper function to make it possible to log events from within the | 394 // Helper function to make it possible to log events from within the |
386 // SSLClientSocketNSS::Core. Can't use Bind with BoundNetLog::AddEntry directly | 395 // SSLClientSocketNSS::Core. |
387 // on Windows because it is overloaded. | |
388 // TODO(mmenke): Other than shutdown, NetLog is threadsafe. Figure out if this | |
389 // is needed. | |
390 void AddLogEventWithCallback(BoundNetLog* net_log, | 396 void AddLogEventWithCallback(BoundNetLog* net_log, |
391 NetLog::EventType event_type, | 397 NetLog::EventType event_type, |
392 const NetLog::ParametersCallback& callback) { | 398 const NetLog::ParametersCallback& callback) { |
393 if (!net_log) | 399 if (!net_log) |
394 return; | 400 return; |
395 net_log->AddEvent(event_type, callback); | 401 net_log->AddEvent(event_type, callback); |
396 } | 402 } |
397 | 403 |
398 // Helper functions to make it possible to log events from within the | |
399 // SSLClientSocketNSS::Core. Can't use Bind with BoundNetLog::AddEntry directly | |
400 // on Windows because it is overloaded. | |
401 // TODO(mmenke): This function is deprecated, delete it. | |
402 void AddLogEvent(BoundNetLog* net_log, | |
403 NetLog::EventType event_type, | |
404 const scoped_refptr<NetLog::EventParameters>& event_params) { | |
405 if (!net_log) | |
406 return; | |
407 net_log->AddEvent(event_type, event_params); | |
408 } | |
409 | |
410 // Helper function to make it easier to call BoundNetLog::AddByteTransferEvent | 404 // Helper function to make it easier to call BoundNetLog::AddByteTransferEvent |
411 // from within the SSLClientSocketNSS::Core. | 405 // from within the SSLClientSocketNSS::Core. |
412 // AddByteTransferEvent expects to receive a const char*, which within the | 406 // AddByteTransferEvent expects to receive a const char*, which within the |
413 // Core is backed by an IOBuffer. If the "const char*" is bound via | 407 // Core is backed by an IOBuffer. If the "const char*" is bound via |
414 // base::Bind and posted to another thread, and the IOBuffer that backs that | 408 // base::Bind and posted to another thread, and the IOBuffer that backs that |
415 // pointer then goes out of scope on the origin thread, this would result in | 409 // pointer then goes out of scope on the origin thread, this would result in |
416 // an invalid read of a stale pointer. | 410 // an invalid read of a stale pointer. |
417 // Instead, provide a signature that accepts an IOBuffer*, so that a reference | 411 // Instead, provide a signature that accepts an IOBuffer*, so that a reference |
418 // to the owning IOBuffer can be bound to the Callback. This ensures that the | 412 // to the owning IOBuffer can be bound to the Callback. This ensures that the |
419 // IOBuffer will stay alive long enough to cross threads if needed. | 413 // IOBuffer will stay alive long enough to cross threads if needed. |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1311 CERTCertList** result_certs, | 1305 CERTCertList** result_certs, |
1312 void** result_private_key, | 1306 void** result_private_key, |
1313 CERTCertificate** result_nss_certificate, | 1307 CERTCertificate** result_nss_certificate, |
1314 SECKEYPrivateKey** result_nss_private_key) { | 1308 SECKEYPrivateKey** result_nss_private_key) { |
1315 Core* core = reinterpret_cast<Core*>(arg); | 1309 Core* core = reinterpret_cast<Core*>(arg); |
1316 DCHECK(core->OnNSSTaskRunner()); | 1310 DCHECK(core->OnNSSTaskRunner()); |
1317 | 1311 |
1318 core->PostOrRunCallback( | 1312 core->PostOrRunCallback( |
1319 FROM_HERE, | 1313 FROM_HERE, |
1320 base::Bind(&AddLogEvent, core->weak_net_log_, | 1314 base::Bind(&AddLogEvent, core->weak_net_log_, |
1321 NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED, | 1315 NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED)); |
1322 scoped_refptr<NetLog::EventParameters>())); | |
1323 | 1316 |
1324 const SECItem* cert_types = SSL_GetRequestedClientCertificateTypes(socket); | 1317 const SECItem* cert_types = SSL_GetRequestedClientCertificateTypes(socket); |
1325 | 1318 |
1326 // Check if a domain-bound certificate is requested. | 1319 // Check if a domain-bound certificate is requested. |
1327 if (DomainBoundCertNegotiated(socket)) { | 1320 if (DomainBoundCertNegotiated(socket)) { |
1328 return core->DomainBoundClientAuthHandler(cert_types, | 1321 return core->DomainBoundClientAuthHandler(cert_types, |
1329 result_nss_certificate, | 1322 result_nss_certificate, |
1330 result_nss_private_key); | 1323 result_nss_private_key); |
1331 } | 1324 } |
1332 | 1325 |
(...skipping 24 matching lines...) Expand all Loading... | |
1357 | 1350 |
1358 // TODO(rsleevi): Error checking for NSS allocation errors. | 1351 // TODO(rsleevi): Error checking for NSS allocation errors. |
1359 CERTCertDBHandle* db_handle = CERT_GetDefaultCertDB(); | 1352 CERTCertDBHandle* db_handle = CERT_GetDefaultCertDB(); |
1360 CERTCertificate* user_cert = CERT_NewTempCertificate( | 1353 CERTCertificate* user_cert = CERT_NewTempCertificate( |
1361 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); | 1354 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); |
1362 if (!user_cert) { | 1355 if (!user_cert) { |
1363 // Importing the certificate can fail for reasons including a serial | 1356 // Importing the certificate can fail for reasons including a serial |
1364 // number collision. See crbug.com/97355. | 1357 // number collision. See crbug.com/97355. |
1365 core->PostOrRunCallback( | 1358 core->PostOrRunCallback( |
1366 FROM_HERE, | 1359 FROM_HERE, |
1367 base::Bind(&AddLogEvent, core->weak_net_log_, | 1360 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1368 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1361 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1369 make_scoped_refptr( | 1362 NetLog::IntegerCallback("cert_count", 0))); |
eroman
2012/06/14 17:45:50
[optional]: "cert_count" is repeated several times
mmenke
2012/06/14 18:03:45
Done.
| |
1370 new NetLogIntegerParameter("cert_count", 0)))); | |
1371 return SECFailure; | 1363 return SECFailure; |
1372 } | 1364 } |
1373 CERTCertList* cert_chain = CERT_NewCertList(); | 1365 CERTCertList* cert_chain = CERT_NewCertList(); |
1374 CERT_AddCertToListTail(cert_chain, user_cert); | 1366 CERT_AddCertToListTail(cert_chain, user_cert); |
1375 | 1367 |
1376 // Add the intermediates. | 1368 // Add the intermediates. |
1377 X509Certificate::OSCertHandles intermediates = | 1369 X509Certificate::OSCertHandles intermediates = |
1378 core->ssl_config_.client_cert->GetIntermediateCertificates(); | 1370 core->ssl_config_.client_cert->GetIntermediateCertificates(); |
1379 for (X509Certificate::OSCertHandles::const_iterator it = | 1371 for (X509Certificate::OSCertHandles::const_iterator it = |
1380 intermediates.begin(); it != intermediates.end(); ++it) { | 1372 intermediates.begin(); it != intermediates.end(); ++it) { |
1381 der_cert.data = (*it)->pbCertEncoded; | 1373 der_cert.data = (*it)->pbCertEncoded; |
1382 der_cert.len = (*it)->cbCertEncoded; | 1374 der_cert.len = (*it)->cbCertEncoded; |
1383 | 1375 |
1384 CERTCertificate* intermediate = CERT_NewTempCertificate( | 1376 CERTCertificate* intermediate = CERT_NewTempCertificate( |
1385 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); | 1377 db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE); |
1386 if (!intermediate) { | 1378 if (!intermediate) { |
1387 CERT_DestroyCertList(cert_chain); | 1379 CERT_DestroyCertList(cert_chain); |
1388 core->PostOrRunCallback( | 1380 core->PostOrRunCallback( |
1389 FROM_HERE, | 1381 FROM_HERE, |
1390 base::Bind(&AddLogEvent, core->weak_net_log_, | 1382 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1391 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1383 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1392 make_scoped_refptr( | 1384 NetLog::IntegerCallback("cert_count", 0))); |
1393 new NetLogIntegerParameter("cert_count", 0)))); | |
1394 return SECFailure; | 1385 return SECFailure; |
1395 } | 1386 } |
1396 CERT_AddCertToListTail(cert_chain, intermediate); | 1387 CERT_AddCertToListTail(cert_chain, intermediate); |
1397 } | 1388 } |
1398 PCERT_KEY_CONTEXT key_context = reinterpret_cast<PCERT_KEY_CONTEXT>( | 1389 PCERT_KEY_CONTEXT key_context = reinterpret_cast<PCERT_KEY_CONTEXT>( |
1399 PORT_ZAlloc(sizeof(CERT_KEY_CONTEXT))); | 1390 PORT_ZAlloc(sizeof(CERT_KEY_CONTEXT))); |
1400 key_context->cbSize = sizeof(*key_context); | 1391 key_context->cbSize = sizeof(*key_context); |
1401 // NSS will free this context when no longer in use, but the | 1392 // NSS will free this context when no longer in use, but the |
1402 // |must_free| result from CryptAcquireCertificatePrivateKey was false | 1393 // |must_free| result from CryptAcquireCertificatePrivateKey was false |
1403 // so we increment the refcount to negate NSS's future decrement. | 1394 // so we increment the refcount to negate NSS's future decrement. |
1404 CryptContextAddRef(crypt_prov, NULL, 0); | 1395 CryptContextAddRef(crypt_prov, NULL, 0); |
1405 key_context->hCryptProv = crypt_prov; | 1396 key_context->hCryptProv = crypt_prov; |
1406 key_context->dwKeySpec = key_spec; | 1397 key_context->dwKeySpec = key_spec; |
1407 *result_private_key = key_context; | 1398 *result_private_key = key_context; |
1408 *result_certs = cert_chain; | 1399 *result_certs = cert_chain; |
1409 | 1400 |
1410 int cert_count = 1 + intermediates.size(); | 1401 int cert_count = 1 + intermediates.size(); |
1411 core->PostOrRunCallback( | 1402 core->PostOrRunCallback( |
1412 FROM_HERE, | 1403 FROM_HERE, |
1413 base::Bind(&AddLogEvent, core->weak_net_log_, | 1404 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1414 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1405 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1415 make_scoped_refptr( | 1406 NetLog::IntegerCallback("cert_count", cert_count))); |
1416 new NetLogIntegerParameter("cert_count", | |
1417 cert_count)))); | |
1418 return SECSuccess; | 1407 return SECSuccess; |
1419 } | 1408 } |
1420 LOG(WARNING) << "Client cert found without private key"; | 1409 LOG(WARNING) << "Client cert found without private key"; |
1421 } | 1410 } |
1422 | 1411 |
1423 // Send no client certificate. | 1412 // Send no client certificate. |
1424 core->PostOrRunCallback( | 1413 core->PostOrRunCallback( |
1425 FROM_HERE, | 1414 FROM_HERE, |
1426 base::Bind(&AddLogEvent, core->weak_net_log_, | 1415 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1427 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1416 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1428 make_scoped_refptr( | 1417 NetLog::IntegerCallback("cert_count", 0))); |
1429 new NetLogIntegerParameter("cert_count", 0)))); | |
1430 return SECFailure; | 1418 return SECFailure; |
1431 } | 1419 } |
1432 | 1420 |
1433 core->nss_handshake_state_.client_certs.clear(); | 1421 core->nss_handshake_state_.client_certs.clear(); |
1434 | 1422 |
1435 std::vector<CERT_NAME_BLOB> issuer_list(ca_names->nnames); | 1423 std::vector<CERT_NAME_BLOB> issuer_list(ca_names->nnames); |
1436 for (int i = 0; i < ca_names->nnames; ++i) { | 1424 for (int i = 0; i < ca_names->nnames; ++i) { |
1437 issuer_list[i].cbData = ca_names->names[i].len; | 1425 issuer_list[i].cbData = ca_names->names[i].len; |
1438 issuer_list[i].pbData = ca_names->names[i].data; | 1426 issuer_list[i].pbData = ca_names->names[i].data; |
1439 } | 1427 } |
1440 | 1428 |
1441 // Client certificates of the user are in the "MY" system certificate store. | 1429 // Client certificates of the user are in the "MY" system certificate store. |
1442 HCERTSTORE my_cert_store = CertOpenSystemStore(NULL, L"MY"); | 1430 HCERTSTORE my_cert_store = CertOpenSystemStore(NULL, L"MY"); |
1443 if (!my_cert_store) { | 1431 if (!my_cert_store) { |
1444 PLOG(ERROR) << "Could not open the \"MY\" system certificate store"; | 1432 PLOG(ERROR) << "Could not open the \"MY\" system certificate store"; |
1445 | 1433 |
1446 core->PostOrRunCallback( | 1434 core->PostOrRunCallback( |
1447 FROM_HERE, | 1435 FROM_HERE, |
1448 base::Bind(&AddLogEvent, core->weak_net_log_, | 1436 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1449 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1437 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1450 make_scoped_refptr( | 1438 NetLog::IntegerCallback("cert_count", 0))); |
1451 new NetLogIntegerParameter("cert_count", 0)))); | |
1452 return SECFailure; | 1439 return SECFailure; |
1453 } | 1440 } |
1454 | 1441 |
1455 // Enumerate the client certificates. | 1442 // Enumerate the client certificates. |
1456 CERT_CHAIN_FIND_BY_ISSUER_PARA find_by_issuer_para; | 1443 CERT_CHAIN_FIND_BY_ISSUER_PARA find_by_issuer_para; |
1457 memset(&find_by_issuer_para, 0, sizeof(find_by_issuer_para)); | 1444 memset(&find_by_issuer_para, 0, sizeof(find_by_issuer_para)); |
1458 find_by_issuer_para.cbSize = sizeof(find_by_issuer_para); | 1445 find_by_issuer_para.cbSize = sizeof(find_by_issuer_para); |
1459 find_by_issuer_para.pszUsageIdentifier = szOID_PKIX_KP_CLIENT_AUTH; | 1446 find_by_issuer_para.pszUsageIdentifier = szOID_PKIX_KP_CLIENT_AUTH; |
1460 find_by_issuer_para.cIssuer = ca_names->nnames; | 1447 find_by_issuer_para.cIssuer = ca_names->nnames; |
1461 find_by_issuer_para.rgIssuer = ca_names->nnames ? &issuer_list[0] : NULL; | 1448 find_by_issuer_para.rgIssuer = ca_names->nnames ? &issuer_list[0] : NULL; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1583 } | 1570 } |
1584 } | 1571 } |
1585 if (os_error == noErr) { | 1572 if (os_error == noErr) { |
1586 int cert_count = 0; | 1573 int cert_count = 0; |
1587 if (chain) { | 1574 if (chain) { |
1588 cert_count = CFArrayGetCount(chain); | 1575 cert_count = CFArrayGetCount(chain); |
1589 CFRelease(chain); | 1576 CFRelease(chain); |
1590 } | 1577 } |
1591 core->PostOrRunCallback( | 1578 core->PostOrRunCallback( |
1592 FROM_HERE, | 1579 FROM_HERE, |
1593 base::Bind(&AddLogEvent, core->weak_net_log_, | 1580 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1594 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1581 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1595 make_scoped_refptr( | 1582 NetLog::IntegerCallback("cert_count", cert_count))); |
1596 new NetLogIntegerParameter("cert_count", | |
1597 cert_count)))); | |
1598 return SECSuccess; | 1583 return SECSuccess; |
1599 } | 1584 } |
1600 OSSTATUS_LOG(WARNING, os_error) | 1585 OSSTATUS_LOG(WARNING, os_error) |
1601 << "Client cert found, but could not be used"; | 1586 << "Client cert found, but could not be used"; |
1602 if (*result_certs) { | 1587 if (*result_certs) { |
1603 CERT_DestroyCertList(*result_certs); | 1588 CERT_DestroyCertList(*result_certs); |
1604 *result_certs = NULL; | 1589 *result_certs = NULL; |
1605 } | 1590 } |
1606 if (*result_private_key) | 1591 if (*result_private_key) |
1607 *result_private_key = NULL; | 1592 *result_private_key = NULL; |
1608 if (private_key) | 1593 if (private_key) |
1609 CFRelease(private_key); | 1594 CFRelease(private_key); |
1610 if (chain) | 1595 if (chain) |
1611 CFRelease(chain); | 1596 CFRelease(chain); |
1612 } | 1597 } |
1613 | 1598 |
1614 // Send no client certificate. | 1599 // Send no client certificate. |
1615 core->PostOrRunCallback( | 1600 core->PostOrRunCallback( |
1616 FROM_HERE, | 1601 FROM_HERE, |
1617 base::Bind(&AddLogEvent, core->weak_net_log_, | 1602 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1618 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1603 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1619 make_scoped_refptr( | 1604 NetLog::IntegerCallback("cert_count", 0))); |
1620 new NetLogIntegerParameter("cert_count", 0)))); | |
1621 return SECFailure; | 1605 return SECFailure; |
1622 } | 1606 } |
1623 | 1607 |
1624 core->nss_handshake_state_.client_certs.clear(); | 1608 core->nss_handshake_state_.client_certs.clear(); |
1625 | 1609 |
1626 // First, get the cert issuer names allowed by the server. | 1610 // First, get the cert issuer names allowed by the server. |
1627 std::vector<CertPrincipal> valid_issuers; | 1611 std::vector<CertPrincipal> valid_issuers; |
1628 int n = ca_names->nnames; | 1612 int n = ca_names->nnames; |
1629 for (int i = 0; i < n; i++) { | 1613 for (int i = 0; i < n; i++) { |
1630 // Parse each name into a CertPrincipal object. | 1614 // Parse each name into a CertPrincipal object. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1663 PRFileDesc* socket, | 1647 PRFileDesc* socket, |
1664 CERTDistNames* ca_names, | 1648 CERTDistNames* ca_names, |
1665 CERTCertificate** result_certificate, | 1649 CERTCertificate** result_certificate, |
1666 SECKEYPrivateKey** result_private_key) { | 1650 SECKEYPrivateKey** result_private_key) { |
1667 Core* core = reinterpret_cast<Core*>(arg); | 1651 Core* core = reinterpret_cast<Core*>(arg); |
1668 DCHECK(core->OnNSSTaskRunner()); | 1652 DCHECK(core->OnNSSTaskRunner()); |
1669 | 1653 |
1670 core->PostOrRunCallback( | 1654 core->PostOrRunCallback( |
1671 FROM_HERE, | 1655 FROM_HERE, |
1672 base::Bind(&AddLogEvent, core->weak_net_log_, | 1656 base::Bind(&AddLogEvent, core->weak_net_log_, |
1673 NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED, | 1657 NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED)); |
1674 scoped_refptr<NetLog::EventParameters>())); | |
1675 | 1658 |
1676 const SECItem* cert_types = SSL_GetRequestedClientCertificateTypes(socket); | 1659 const SECItem* cert_types = SSL_GetRequestedClientCertificateTypes(socket); |
1677 | 1660 |
1678 // Check if a domain-bound certificate is requested. | 1661 // Check if a domain-bound certificate is requested. |
1679 if (DomainBoundCertNegotiated(socket)) { | 1662 if (DomainBoundCertNegotiated(socket)) { |
1680 return core->DomainBoundClientAuthHandler( | 1663 return core->DomainBoundClientAuthHandler( |
1681 cert_types, result_certificate, result_private_key); | 1664 cert_types, result_certificate, result_private_key); |
1682 } | 1665 } |
1683 | 1666 |
1684 // Regular client certificate requested. | 1667 // Regular client certificate requested. |
1685 core->client_auth_cert_needed_ = !core->ssl_config_.send_client_cert; | 1668 core->client_auth_cert_needed_ = !core->ssl_config_.send_client_cert; |
1686 void* wincx = SSL_RevealPinArg(socket); | 1669 void* wincx = SSL_RevealPinArg(socket); |
1687 | 1670 |
1688 // Second pass: a client certificate should have been selected. | 1671 // Second pass: a client certificate should have been selected. |
1689 if (core->ssl_config_.send_client_cert) { | 1672 if (core->ssl_config_.send_client_cert) { |
1690 if (core->ssl_config_.client_cert) { | 1673 if (core->ssl_config_.client_cert) { |
1691 CERTCertificate* cert = CERT_DupCertificate( | 1674 CERTCertificate* cert = CERT_DupCertificate( |
1692 core->ssl_config_.client_cert->os_cert_handle()); | 1675 core->ssl_config_.client_cert->os_cert_handle()); |
1693 SECKEYPrivateKey* privkey = PK11_FindKeyByAnyCert(cert, wincx); | 1676 SECKEYPrivateKey* privkey = PK11_FindKeyByAnyCert(cert, wincx); |
1694 if (privkey) { | 1677 if (privkey) { |
1695 // TODO(jsorianopastor): We should wait for server certificate | 1678 // TODO(jsorianopastor): We should wait for server certificate |
1696 // verification before sending our credentials. See | 1679 // verification before sending our credentials. See |
1697 // http://crbug.com/13934. | 1680 // http://crbug.com/13934. |
1698 *result_certificate = cert; | 1681 *result_certificate = cert; |
1699 *result_private_key = privkey; | 1682 *result_private_key = privkey; |
1700 // A cert_count of -1 means the number of certificates is unknown. | 1683 // A cert_count of -1 means the number of certificates is unknown. |
1701 // NSS will construct the certificate chain. | 1684 // NSS will construct the certificate chain. |
1702 core->PostOrRunCallback( | 1685 core->PostOrRunCallback( |
1703 FROM_HERE, | 1686 FROM_HERE, |
1704 base::Bind(&AddLogEvent, core->weak_net_log_, | 1687 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1705 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1688 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1706 make_scoped_refptr( | 1689 NetLog::IntegerCallback("cert_count", -1))); |
1707 new NetLogIntegerParameter("cert_count", -1)))); | |
1708 | 1690 |
1709 return SECSuccess; | 1691 return SECSuccess; |
1710 } | 1692 } |
1711 LOG(WARNING) << "Client cert found without private key"; | 1693 LOG(WARNING) << "Client cert found without private key"; |
1712 } | 1694 } |
1713 // Send no client certificate. | 1695 // Send no client certificate. |
1714 core->PostOrRunCallback( | 1696 core->PostOrRunCallback( |
1715 FROM_HERE, | 1697 FROM_HERE, |
1716 base::Bind(&AddLogEvent, core->weak_net_log_, | 1698 base::Bind(&AddLogEventWithCallback, core->weak_net_log_, |
1717 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 1699 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
1718 make_scoped_refptr( | 1700 NetLog::IntegerCallback("cert_count", 0))); |
1719 new NetLogIntegerParameter("cert_count", 0)))); | |
1720 return SECFailure; | 1701 return SECFailure; |
1721 } | 1702 } |
1722 | 1703 |
1723 core->nss_handshake_state_.client_certs.clear(); | 1704 core->nss_handshake_state_.client_certs.clear(); |
1724 | 1705 |
1725 // Iterate over all client certificates. | 1706 // Iterate over all client certificates. |
1726 CERTCertList* client_certs = CERT_FindUserCertsByUsage( | 1707 CERTCertList* client_certs = CERT_FindUserCertsByUsage( |
1727 CERT_GetDefaultCertDB(), certUsageSSLClient, | 1708 CERT_GetDefaultCertDB(), certUsageSSLClient, |
1728 PR_FALSE, PR_FALSE, wincx); | 1709 PR_FALSE, PR_FALSE, wincx); |
1729 if (client_certs) { | 1710 if (client_certs) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1957 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 1938 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
1958 | 1939 |
1959 if (result < 0) | 1940 if (result < 0) |
1960 return result; | 1941 return result; |
1961 | 1942 |
1962 if (!nss_bufs_) { | 1943 if (!nss_bufs_) { |
1963 LOG(DFATAL) << "!nss_bufs_"; | 1944 LOG(DFATAL) << "!nss_bufs_"; |
1964 int rv = ERR_UNEXPECTED; | 1945 int rv = ERR_UNEXPECTED; |
1965 PostOrRunCallback( | 1946 PostOrRunCallback( |
1966 FROM_HERE, | 1947 FROM_HERE, |
1967 base::Bind(&AddLogEvent, weak_net_log_, | 1948 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
1968 NetLog::TYPE_SSL_READ_ERROR, | 1949 NetLog::TYPE_SSL_READ_ERROR, |
1969 make_scoped_refptr(new SSLErrorParams(rv, 0)))); | 1950 CreateNetLogSSLErrorCallback(rv, 0))); |
1970 return rv; | 1951 return rv; |
1971 } | 1952 } |
1972 | 1953 |
1973 bool network_moved; | 1954 bool network_moved; |
1974 int rv; | 1955 int rv; |
1975 do { | 1956 do { |
1976 rv = DoPayloadRead(); | 1957 rv = DoPayloadRead(); |
1977 network_moved = DoTransportIO(); | 1958 network_moved = DoTransportIO(); |
1978 } while (rv == ERR_IO_PENDING && network_moved); | 1959 } while (rv == ERR_IO_PENDING && network_moved); |
1979 | 1960 |
1980 return rv; | 1961 return rv; |
1981 } | 1962 } |
1982 | 1963 |
1983 int SSLClientSocketNSS::Core::DoWriteLoop(int result) { | 1964 int SSLClientSocketNSS::Core::DoWriteLoop(int result) { |
1984 DCHECK(OnNSSTaskRunner()); | 1965 DCHECK(OnNSSTaskRunner()); |
1985 DCHECK(handshake_callback_called_); | 1966 DCHECK(handshake_callback_called_); |
1986 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 1967 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
1987 | 1968 |
1988 if (result < 0) | 1969 if (result < 0) |
1989 return result; | 1970 return result; |
1990 | 1971 |
1991 if (!nss_bufs_) { | 1972 if (!nss_bufs_) { |
1992 LOG(DFATAL) << "!nss_bufs_"; | 1973 LOG(DFATAL) << "!nss_bufs_"; |
1993 int rv = ERR_UNEXPECTED; | 1974 int rv = ERR_UNEXPECTED; |
1994 PostOrRunCallback( | 1975 PostOrRunCallback( |
1995 FROM_HERE, | 1976 FROM_HERE, |
1996 base::Bind(&AddLogEvent, weak_net_log_, | 1977 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
1997 NetLog::TYPE_SSL_READ_ERROR, | 1978 NetLog::TYPE_SSL_READ_ERROR, |
1998 make_scoped_refptr(new SSLErrorParams(rv, 0)))); | 1979 CreateNetLogSSLErrorCallback(rv, 0))); |
1999 return rv; | 1980 return rv; |
2000 } | 1981 } |
2001 | 1982 |
2002 bool network_moved; | 1983 bool network_moved; |
2003 int rv; | 1984 int rv; |
2004 do { | 1985 do { |
2005 rv = DoPayloadWrite(); | 1986 rv = DoPayloadWrite(); |
2006 network_moved = DoTransportIO(); | 1987 network_moved = DoTransportIO(); |
2007 } while (rv == ERR_IO_PENDING && network_moved); | 1988 } while (rv == ERR_IO_PENDING && network_moved); |
2008 | 1989 |
(...skipping 12 matching lines...) Expand all Loading... | |
2021 // code so that the higher level code will attempt to delete the socket and | 2002 // code so that the higher level code will attempt to delete the socket and |
2022 // redo the handshake. | 2003 // redo the handshake. |
2023 if (client_auth_cert_needed_) { | 2004 if (client_auth_cert_needed_) { |
2024 if (domain_bound_cert_xtn_negotiated_) { | 2005 if (domain_bound_cert_xtn_negotiated_) { |
2025 GotoState(STATE_GET_DOMAIN_BOUND_CERT_COMPLETE); | 2006 GotoState(STATE_GET_DOMAIN_BOUND_CERT_COMPLETE); |
2026 net_error = ERR_IO_PENDING; | 2007 net_error = ERR_IO_PENDING; |
2027 } else { | 2008 } else { |
2028 net_error = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; | 2009 net_error = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; |
2029 PostOrRunCallback( | 2010 PostOrRunCallback( |
2030 FROM_HERE, | 2011 FROM_HERE, |
2031 base::Bind(&AddLogEvent, weak_net_log_, | 2012 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2032 NetLog::TYPE_SSL_HANDSHAKE_ERROR, | 2013 NetLog::TYPE_SSL_HANDSHAKE_ERROR, |
2033 make_scoped_refptr(new SSLErrorParams(net_error, 0)))); | 2014 CreateNetLogSSLErrorCallback(net_error, 0))); |
2034 | 2015 |
2035 // If the handshake already succeeded (because the server requests but | 2016 // If the handshake already succeeded (because the server requests but |
2036 // doesn't require a client cert), we need to invalidate the SSL session | 2017 // doesn't require a client cert), we need to invalidate the SSL session |
2037 // so that we won't try to resume the non-client-authenticated session in | 2018 // so that we won't try to resume the non-client-authenticated session in |
2038 // the next handshake. This will cause the server to ask for a client | 2019 // the next handshake. This will cause the server to ask for a client |
2039 // cert again. | 2020 // cert again. |
2040 if (rv == SECSuccess && SSL_InvalidateSession(nss_fd_) != SECSuccess) | 2021 if (rv == SECSuccess && SSL_InvalidateSession(nss_fd_) != SECSuccess) |
2041 LOG(WARNING) << "Couldn't invalidate SSL session: " << PR_GetError(); | 2022 LOG(WARNING) << "Couldn't invalidate SSL session: " << PR_GetError(); |
2042 } | 2023 } |
2043 } else if (rv == SECSuccess) { | 2024 } else if (rv == SECSuccess) { |
2044 if (!handshake_callback_called_) { | 2025 if (!handshake_callback_called_) { |
2045 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=562434 - | 2026 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=562434 - |
2046 // SSL_ForceHandshake returned SECSuccess prematurely. | 2027 // SSL_ForceHandshake returned SECSuccess prematurely. |
2047 rv = SECFailure; | 2028 rv = SECFailure; |
2048 net_error = ERR_SSL_PROTOCOL_ERROR; | 2029 net_error = ERR_SSL_PROTOCOL_ERROR; |
2049 PostOrRunCallback( | 2030 PostOrRunCallback( |
2050 FROM_HERE, | 2031 FROM_HERE, |
2051 base::Bind(&AddLogEvent, weak_net_log_, | 2032 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2052 NetLog::TYPE_SSL_HANDSHAKE_ERROR, | 2033 NetLog::TYPE_SSL_HANDSHAKE_ERROR, |
2053 make_scoped_refptr( | 2034 CreateNetLogSSLErrorCallback(net_error, 0))); |
2054 new SSLErrorParams(net_error, 0)))); | |
2055 } else { | 2035 } else { |
2056 #if defined(SSL_ENABLE_OCSP_STAPLING) | 2036 #if defined(SSL_ENABLE_OCSP_STAPLING) |
2057 // TODO(agl): figure out how to plumb an OCSP response into the Mac | 2037 // TODO(agl): figure out how to plumb an OCSP response into the Mac |
2058 // system library and update IsOCSPStaplingSupported for Mac. | 2038 // system library and update IsOCSPStaplingSupported for Mac. |
2059 if (!nss_handshake_state_.predicted_cert_chain_correct && | 2039 if (!nss_handshake_state_.predicted_cert_chain_correct && |
2060 IsOCSPStaplingSupported()) { | 2040 IsOCSPStaplingSupported()) { |
2061 unsigned int len = 0; | 2041 unsigned int len = 0; |
2062 SSL_GetStapledOCSPResponse(nss_fd_, NULL, &len); | 2042 SSL_GetStapledOCSPResponse(nss_fd_, NULL, &len); |
2063 if (len) { | 2043 if (len) { |
2064 const unsigned int orig_len = len; | 2044 const unsigned int orig_len = len; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2119 ssl_config_.version_max == SSL_PROTOCOL_VERSION_TLS1_1) { | 2099 ssl_config_.version_max == SSL_PROTOCOL_VERSION_TLS1_1) { |
2120 net_error = ERR_SSL_PROTOCOL_ERROR; | 2100 net_error = ERR_SSL_PROTOCOL_ERROR; |
2121 } | 2101 } |
2122 | 2102 |
2123 // If not done, stay in this state | 2103 // If not done, stay in this state |
2124 if (net_error == ERR_IO_PENDING) { | 2104 if (net_error == ERR_IO_PENDING) { |
2125 GotoState(STATE_HANDSHAKE); | 2105 GotoState(STATE_HANDSHAKE); |
2126 } else { | 2106 } else { |
2127 PostOrRunCallback( | 2107 PostOrRunCallback( |
2128 FROM_HERE, | 2108 FROM_HERE, |
2129 base::Bind(&AddLogEvent, weak_net_log_, | 2109 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2130 NetLog::TYPE_SSL_HANDSHAKE_ERROR, | 2110 NetLog::TYPE_SSL_HANDSHAKE_ERROR, |
2131 make_scoped_refptr( | 2111 CreateNetLogSSLErrorCallback(net_error, prerr))); |
2132 new SSLErrorParams(net_error, prerr)))); | |
2133 } | 2112 } |
2134 } | 2113 } |
2135 | 2114 |
2136 return net_error; | 2115 return net_error; |
2137 } | 2116 } |
2138 | 2117 |
2139 int SSLClientSocketNSS::Core::DoGetDBCertComplete(int result) { | 2118 int SSLClientSocketNSS::Core::DoGetDBCertComplete(int result) { |
2140 SECStatus rv; | 2119 SECStatus rv; |
2141 PostOrRunCallback( | 2120 PostOrRunCallback( |
2142 FROM_HERE, | 2121 FROM_HERE, |
(...skipping 17 matching lines...) Expand all Loading... | |
2160 SECKEYPrivateKey* key; | 2139 SECKEYPrivateKey* key; |
2161 int error = ImportDBCertAndKey(&cert, &key); | 2140 int error = ImportDBCertAndKey(&cert, &key); |
2162 if (error != OK) | 2141 if (error != OK) |
2163 return error; | 2142 return error; |
2164 | 2143 |
2165 CERTCertificateList* cert_chain = | 2144 CERTCertificateList* cert_chain = |
2166 CERT_CertChainFromCert(cert, certUsageSSLClient, PR_FALSE); | 2145 CERT_CertChainFromCert(cert, certUsageSSLClient, PR_FALSE); |
2167 | 2146 |
2168 PostOrRunCallback( | 2147 PostOrRunCallback( |
2169 FROM_HERE, | 2148 FROM_HERE, |
2170 base::Bind(&AddLogEvent, weak_net_log_, | 2149 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2171 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 2150 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
2172 make_scoped_refptr( | 2151 NetLog::IntegerCallback("cert_count", cert_chain->len))); |
2173 new NetLogIntegerParameter("cert_count", | |
2174 cert_chain->len)))); | |
2175 | 2152 |
2176 rv = SSL_RestartHandshakeAfterCertReq(nss_fd_, cert, key, cert_chain); | 2153 rv = SSL_RestartHandshakeAfterCertReq(nss_fd_, cert, key, cert_chain); |
2177 if (rv != SECSuccess) | 2154 if (rv != SECSuccess) |
2178 return MapNSSError(PORT_GetError()); | 2155 return MapNSSError(PORT_GetError()); |
2179 | 2156 |
2180 GotoState(STATE_HANDSHAKE); | 2157 GotoState(STATE_HANDSHAKE); |
2181 return OK; | 2158 return OK; |
2182 } | 2159 } |
2183 | 2160 |
2184 int SSLClientSocketNSS::Core::DoPayloadRead() { | 2161 int SSLClientSocketNSS::Core::DoPayloadRead() { |
2185 DCHECK(OnNSSTaskRunner()); | 2162 DCHECK(OnNSSTaskRunner()); |
2186 DCHECK(user_read_buf_); | 2163 DCHECK(user_read_buf_); |
2187 DCHECK_GT(user_read_buf_len_, 0); | 2164 DCHECK_GT(user_read_buf_len_, 0); |
2188 | 2165 |
2189 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); | 2166 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); |
2190 if (client_auth_cert_needed_) { | 2167 if (client_auth_cert_needed_) { |
2191 // We don't need to invalidate the non-client-authenticated SSL session | 2168 // We don't need to invalidate the non-client-authenticated SSL session |
2192 // because the server will renegotiate anyway. | 2169 // because the server will renegotiate anyway. |
2193 rv = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; | 2170 rv = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; |
2194 PostOrRunCallback( | 2171 PostOrRunCallback( |
2195 FROM_HERE, | 2172 FROM_HERE, |
2196 base::Bind(&AddLogEvent, weak_net_log_, | 2173 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2197 NetLog::TYPE_SSL_READ_ERROR, | 2174 NetLog::TYPE_SSL_READ_ERROR, |
2198 make_scoped_refptr(new SSLErrorParams(rv, 0)))); | 2175 CreateNetLogSSLErrorCallback(rv, 0))); |
2199 return rv; | 2176 return rv; |
2200 } | 2177 } |
2201 if (rv >= 0) { | 2178 if (rv >= 0) { |
2202 PostOrRunCallback( | 2179 PostOrRunCallback( |
2203 FROM_HERE, | 2180 FROM_HERE, |
2204 base::Bind(&LogByteTransferEvent, weak_net_log_, | 2181 base::Bind(&LogByteTransferEvent, weak_net_log_, |
2205 NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, rv, | 2182 NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, rv, |
2206 scoped_refptr<IOBuffer>(user_read_buf_))); | 2183 scoped_refptr<IOBuffer>(user_read_buf_))); |
2207 return rv; | 2184 return rv; |
2208 } | 2185 } |
2209 PRErrorCode prerr = PR_GetError(); | 2186 PRErrorCode prerr = PR_GetError(); |
2210 if (prerr == PR_WOULD_BLOCK_ERROR) | 2187 if (prerr == PR_WOULD_BLOCK_ERROR) |
2211 return ERR_IO_PENDING; | 2188 return ERR_IO_PENDING; |
2212 | 2189 |
2213 rv = HandleNSSError(prerr, false); | 2190 rv = HandleNSSError(prerr, false); |
2214 PostOrRunCallback( | 2191 PostOrRunCallback( |
2215 FROM_HERE, | 2192 FROM_HERE, |
2216 base::Bind(&AddLogEvent, weak_net_log_, | 2193 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2217 NetLog::TYPE_SSL_READ_ERROR, | 2194 NetLog::TYPE_SSL_READ_ERROR, |
2218 make_scoped_refptr(new SSLErrorParams(rv, prerr)))); | 2195 CreateNetLogSSLErrorCallback(rv, prerr))); |
2219 return rv; | 2196 return rv; |
2220 } | 2197 } |
2221 | 2198 |
2222 int SSLClientSocketNSS::Core::DoPayloadWrite() { | 2199 int SSLClientSocketNSS::Core::DoPayloadWrite() { |
2223 DCHECK(OnNSSTaskRunner()); | 2200 DCHECK(OnNSSTaskRunner()); |
2224 | 2201 |
2225 DCHECK(user_write_buf_); | 2202 DCHECK(user_write_buf_); |
2226 | 2203 |
2227 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); | 2204 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); |
2228 if (rv >= 0) { | 2205 if (rv >= 0) { |
2229 PostOrRunCallback( | 2206 PostOrRunCallback( |
2230 FROM_HERE, | 2207 FROM_HERE, |
2231 base::Bind(&LogByteTransferEvent, weak_net_log_, | 2208 base::Bind(&LogByteTransferEvent, weak_net_log_, |
2232 NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, | 2209 NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, |
2233 scoped_refptr<IOBuffer>(user_write_buf_))); | 2210 scoped_refptr<IOBuffer>(user_write_buf_))); |
2234 return rv; | 2211 return rv; |
2235 } | 2212 } |
2236 PRErrorCode prerr = PR_GetError(); | 2213 PRErrorCode prerr = PR_GetError(); |
2237 if (prerr == PR_WOULD_BLOCK_ERROR) | 2214 if (prerr == PR_WOULD_BLOCK_ERROR) |
2238 return ERR_IO_PENDING; | 2215 return ERR_IO_PENDING; |
2239 | 2216 |
2240 rv = HandleNSSError(prerr, false); | 2217 rv = HandleNSSError(prerr, false); |
2241 PostOrRunCallback( | 2218 PostOrRunCallback( |
2242 FROM_HERE, | 2219 FROM_HERE, |
2243 base::Bind(&AddLogEvent, weak_net_log_, | 2220 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2244 NetLog::TYPE_SSL_WRITE_ERROR, | 2221 NetLog::TYPE_SSL_WRITE_ERROR, |
2245 make_scoped_refptr(new SSLErrorParams(rv, prerr)))); | 2222 CreateNetLogSSLErrorCallback(rv, prerr))); |
2246 return rv; | 2223 return rv; |
2247 } | 2224 } |
2248 | 2225 |
2249 // Do as much network I/O as possible between the buffer and the | 2226 // Do as much network I/O as possible between the buffer and the |
2250 // transport socket. Return true if some I/O performed, false | 2227 // transport socket. Return true if some I/O performed, false |
2251 // otherwise (error or ERR_IO_PENDING). | 2228 // otherwise (error or ERR_IO_PENDING). |
2252 bool SSLClientSocketNSS::Core::DoTransportIO() { | 2229 bool SSLClientSocketNSS::Core::DoTransportIO() { |
2253 DCHECK(OnNSSTaskRunner()); | 2230 DCHECK(OnNSSTaskRunner()); |
2254 | 2231 |
2255 bool network_moved = false; | 2232 bool network_moved = false; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2481 domain_bound_cert_type_ = CLIENT_CERT_INVALID_TYPE; | 2458 domain_bound_cert_type_ = CLIENT_CERT_INVALID_TYPE; |
2482 rv = SECFailure; | 2459 rv = SECFailure; |
2483 } | 2460 } |
2484 } else { | 2461 } else { |
2485 rv = SECFailure; | 2462 rv = SECFailure; |
2486 } | 2463 } |
2487 | 2464 |
2488 int cert_count = (rv == SECSuccess) ? 1 : 0; | 2465 int cert_count = (rv == SECSuccess) ? 1 : 0; |
2489 PostOrRunCallback( | 2466 PostOrRunCallback( |
2490 FROM_HERE, | 2467 FROM_HERE, |
2491 base::Bind(&AddLogEvent, weak_net_log_, | 2468 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
2492 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, | 2469 NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED, |
2493 make_scoped_refptr( | 2470 NetLog::IntegerCallback("cert_count", cert_count))); |
2494 new NetLogIntegerParameter("cert_count", | |
2495 cert_count)))); | |
2496 return rv; | 2471 return rv; |
2497 } | 2472 } |
2498 | 2473 |
2499 int SSLClientSocketNSS::Core::ImportDBCertAndKey(CERTCertificate** cert, | 2474 int SSLClientSocketNSS::Core::ImportDBCertAndKey(CERTCertificate** cert, |
2500 SECKEYPrivateKey** key) { | 2475 SECKEYPrivateKey** key) { |
2501 // Set the certificate. | 2476 // Set the certificate. |
2502 SECItem cert_item; | 2477 SECItem cert_item; |
2503 cert_item.data = (unsigned char*) domain_bound_cert_.data(); | 2478 cert_item.data = (unsigned char*) domain_bound_cert_.data(); |
2504 cert_item.len = domain_bound_cert_.size(); | 2479 cert_item.len = domain_bound_cert_.size(); |
2505 *cert = CERT_NewTempCertificate(CERT_GetDefaultCertDB(), | 2480 *cert = CERT_NewTempCertificate(CERT_GetDefaultCertDB(), |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 } | 2665 } |
2691 | 2666 |
2692 int SSLClientSocketNSS::Core::DoGetDomainBoundCert( | 2667 int SSLClientSocketNSS::Core::DoGetDomainBoundCert( |
2693 const std::string& origin, | 2668 const std::string& origin, |
2694 const std::vector<uint8>& requested_cert_types) { | 2669 const std::vector<uint8>& requested_cert_types) { |
2695 DCHECK(OnNetworkTaskRunner()); | 2670 DCHECK(OnNetworkTaskRunner()); |
2696 | 2671 |
2697 if (detached_) | 2672 if (detached_) |
2698 return ERR_FAILED; | 2673 return ERR_FAILED; |
2699 | 2674 |
2700 weak_net_log_->BeginEvent(NetLog::TYPE_SSL_GET_DOMAIN_BOUND_CERT, NULL); | 2675 weak_net_log_->BeginEvent(NetLog::TYPE_SSL_GET_DOMAIN_BOUND_CERT); |
2701 | 2676 |
2702 int rv = server_bound_cert_service_->GetDomainBoundCert( | 2677 int rv = server_bound_cert_service_->GetDomainBoundCert( |
2703 origin, | 2678 origin, |
2704 requested_cert_types, | 2679 requested_cert_types, |
2705 &domain_bound_cert_type_, | 2680 &domain_bound_cert_type_, |
2706 &domain_bound_private_key_, | 2681 &domain_bound_private_key_, |
2707 &domain_bound_cert_, | 2682 &domain_bound_cert_, |
2708 base::Bind(&Core::OnGetDomainBoundCertComplete, base::Unretained(this)), | 2683 base::Bind(&Core::OnGetDomainBoundCertComplete, base::Unretained(this)), |
2709 &domain_bound_cert_request_handle_); | 2684 &domain_bound_cert_request_handle_); |
2710 | 2685 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2935 | 2910 |
2936 int SSLClientSocketNSS::Connect(const CompletionCallback& callback) { | 2911 int SSLClientSocketNSS::Connect(const CompletionCallback& callback) { |
2937 EnterFunction(""); | 2912 EnterFunction(""); |
2938 DCHECK(transport_.get()); | 2913 DCHECK(transport_.get()); |
2939 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 2914 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
2940 DCHECK(user_connect_callback_.is_null()); | 2915 DCHECK(user_connect_callback_.is_null()); |
2941 DCHECK(!callback.is_null()); | 2916 DCHECK(!callback.is_null()); |
2942 | 2917 |
2943 EnsureThreadIdAssigned(); | 2918 EnsureThreadIdAssigned(); |
2944 | 2919 |
2945 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL); | 2920 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); |
2946 | 2921 |
2947 int rv = Init(); | 2922 int rv = Init(); |
2948 if (rv != OK) { | 2923 if (rv != OK) { |
2949 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 2924 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
2950 return rv; | 2925 return rv; |
2951 } | 2926 } |
2952 | 2927 |
2953 rv = InitializeSSLOptions(); | 2928 rv = InitializeSSLOptions(); |
2954 if (rv != OK) { | 2929 if (rv != OK) { |
2955 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 2930 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3522 } | 3497 } |
3523 | 3498 |
3524 start_cert_verification_time_ = base::TimeTicks::Now(); | 3499 start_cert_verification_time_ = base::TimeTicks::Now(); |
3525 | 3500 |
3526 if (ssl_host_info_.get() && !ssl_host_info_->state().certs.empty() && | 3501 if (ssl_host_info_.get() && !ssl_host_info_->state().certs.empty() && |
3527 core_->state().predicted_cert_chain_correct) { | 3502 core_->state().predicted_cert_chain_correct) { |
3528 // If the SSLHostInfo had a prediction for the certificate chain of this | 3503 // If the SSLHostInfo had a prediction for the certificate chain of this |
3529 // server then it will have optimistically started a verification of that | 3504 // server then it will have optimistically started a verification of that |
3530 // chain. So, if the prediction was correct, we should wait for that | 3505 // chain. So, if the prediction was correct, we should wait for that |
3531 // verification to finish rather than start our own. | 3506 // verification to finish rather than start our own. |
3532 net_log_.AddEvent(NetLog::TYPE_SSL_VERIFICATION_MERGED, NULL); | 3507 net_log_.AddEvent(NetLog::TYPE_SSL_VERIFICATION_MERGED); |
3533 UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 1 /* true */, 2); | 3508 UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 1 /* true */, 2); |
3534 base::TimeTicks end_time = ssl_host_info_->verification_end_time(); | 3509 base::TimeTicks end_time = ssl_host_info_->verification_end_time(); |
3535 if (end_time.is_null()) | 3510 if (end_time.is_null()) |
3536 end_time = base::TimeTicks::Now(); | 3511 end_time = base::TimeTicks::Now(); |
3537 UMA_HISTOGRAM_TIMES("Net.SSLVerificationMergedMsSaved", | 3512 UMA_HISTOGRAM_TIMES("Net.SSLVerificationMergedMsSaved", |
3538 end_time - ssl_host_info_->verification_start_time()); | 3513 end_time - ssl_host_info_->verification_start_time()); |
3539 server_cert_verify_result_ = &ssl_host_info_->cert_verify_result(); | 3514 server_cert_verify_result_ = &ssl_host_info_->cert_verify_result(); |
3540 return ssl_host_info_->WaitForCertVerification( | 3515 return ssl_host_info_->WaitForCertVerification( |
3541 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, | 3516 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, |
3542 base::Unretained(this))); | 3517 base::Unretained(this))); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3715 EnsureThreadIdAssigned(); | 3690 EnsureThreadIdAssigned(); |
3716 base::AutoLock auto_lock(lock_); | 3691 base::AutoLock auto_lock(lock_); |
3717 return valid_thread_id_ == base::PlatformThread::CurrentId(); | 3692 return valid_thread_id_ == base::PlatformThread::CurrentId(); |
3718 } | 3693 } |
3719 | 3694 |
3720 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { | 3695 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { |
3721 return server_bound_cert_service_; | 3696 return server_bound_cert_service_; |
3722 } | 3697 } |
3723 | 3698 |
3724 } // namespace net | 3699 } // namespace net |
OLD | NEW |