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

Side by Side Diff: net/socket/ssl_client_socket_nss.cc

Issue 2944008: Refactor X509Certificate caching to cache the OS handle, rather than the X509Certificate (Closed)
Patch Set: Rebase to trunk after splitting out 4645001 Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 if (!chain_context) { 1649 if (!chain_context) {
1650 DWORD err = GetLastError(); 1650 DWORD err = GetLastError();
1651 if (err != CRYPT_E_NOT_FOUND) 1651 if (err != CRYPT_E_NOT_FOUND)
1652 DLOG(ERROR) << "CertFindChainInStore failed: " << err; 1652 DLOG(ERROR) << "CertFindChainInStore failed: " << err;
1653 break; 1653 break;
1654 } 1654 }
1655 1655
1656 // Get the leaf certificate. 1656 // Get the leaf certificate.
1657 PCCERT_CONTEXT cert_context = 1657 PCCERT_CONTEXT cert_context =
1658 chain_context->rgpChain[0]->rgpElement[0]->pCertContext; 1658 chain_context->rgpChain[0]->rgpElement[0]->pCertContext;
1659 // Copy it to our own certificate store, so that we can close the "MY" 1659 // Copy the certificate into a NULL store, so that we can close the "MY"
1660 // certificate store before returning from this function. 1660 // store before returning from this function.
1661 PCCERT_CONTEXT cert_context2; 1661 PCCERT_CONTEXT cert_context2;
1662 BOOL ok = CertAddCertificateContextToStore(X509Certificate::cert_store(), 1662 BOOL ok = CertAddCertificateContextToStore(NULL, cert_context,
1663 cert_context,
1664 CERT_STORE_ADD_USE_EXISTING, 1663 CERT_STORE_ADD_USE_EXISTING,
1665 &cert_context2); 1664 &cert_context2);
1666 if (!ok) { 1665 if (!ok) {
1667 NOTREACHED(); 1666 NOTREACHED();
1668 continue; 1667 continue;
1669 } 1668 }
1670 1669
1671 // Copy the rest of the chain to our own store as well. Copying the chain 1670 // Copy the rest of the chain to our own store as well. Copying the chain
1672 // stops gracefully if an error is encountered, with the partial chain 1671 // stops gracefully if an error is encountered, with the partial chain
1673 // being used as the intermediates, rather than failing to consider the 1672 // being used as the intermediates, rather than failing to consider the
1674 // client certificate. 1673 // client certificate.
1675 net::X509Certificate::OSCertHandles intermediates; 1674 net::X509Certificate::OSCertHandles intermediates;
1676 for (DWORD i = 1; i < chain_context->rgpChain[0]->cElement; i++) { 1675 for (DWORD i = 1; i < chain_context->rgpChain[0]->cElement; i++) {
1677 PCCERT_CONTEXT intermediate_copy; 1676 PCCERT_CONTEXT intermediate_copy;
1678 ok = CertAddCertificateContextToStore(X509Certificate::cert_store(), 1677 ok = CertAddCertificateContextToStore(
1678 NULL,
1679 chain_context->rgpChain[0]->rgpElement[i]->pCertContext, 1679 chain_context->rgpChain[0]->rgpElement[i]->pCertContext,
1680 CERT_STORE_ADD_USE_EXISTING, &intermediate_copy); 1680 CERT_STORE_ADD_USE_EXISTING, &intermediate_copy);
1681 if (!ok) { 1681 if (!ok) {
1682 NOTREACHED(); 1682 NOTREACHED();
1683 break; 1683 break;
1684 } 1684 }
1685 intermediates.push_back(intermediate_copy); 1685 intermediates.push_back(intermediate_copy);
1686 } 1686 }
1687 1687
1688 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( 1688 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
1689 cert_context2, X509Certificate::SOURCE_LONE_CERT_IMPORT, 1689 cert_context2, intermediates);
1690 intermediates);
1691 that->client_certs_.push_back(cert); 1690 that->client_certs_.push_back(cert);
1692 1691
1693 X509Certificate::FreeOSCertHandle(cert_context2); 1692 X509Certificate::FreeOSCertHandle(cert_context2);
1694 for (net::X509Certificate::OSCertHandles::iterator it = 1693 for (net::X509Certificate::OSCertHandles::iterator it =
1695 intermediates.begin(); it != intermediates.end(); ++it) { 1694 intermediates.begin(); it != intermediates.end(); ++it) {
1696 net::X509Certificate::FreeOSCertHandle(*it); 1695 net::X509Certificate::FreeOSCertHandle(*it);
1697 } 1696 }
1698 } 1697 }
1699 1698
1700 BOOL ok = CertCloseStore(my_cert_store, CERT_CLOSE_STORE_CHECK_FLAG); 1699 BOOL ok = CertCloseStore(my_cert_store, CERT_CLOSE_STORE_CHECK_FLAG);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 secCertTimeValid) 1841 secCertTimeValid)
1843 continue; 1842 continue;
1844 // Filter by issuer. 1843 // Filter by issuer.
1845 // 1844 //
1846 // TODO(davidben): This does a binary comparison of the DER-encoded 1845 // TODO(davidben): This does a binary comparison of the DER-encoded
1847 // issuers. We should match according to RFC 5280 sec. 7.1. We should find 1846 // issuers. We should match according to RFC 5280 sec. 7.1. We should find
1848 // an appropriate NSS function or add one if needbe. 1847 // an appropriate NSS function or add one if needbe.
1849 if (ca_names->nnames && 1848 if (ca_names->nnames &&
1850 NSS_CmpCertChainWCANames(node->cert, ca_names) != SECSuccess) 1849 NSS_CmpCertChainWCANames(node->cert, ca_names) != SECSuccess)
1851 continue; 1850 continue;
1851 // TODO(rsleevi): Explicitly specify the intermediates for the client
1852 // certificate. As implemented, the current behaviour is that NSS will
1853 // rebuild the chain any time it needs to, such as to display or send
1854 // to the server.
1852 X509Certificate* x509_cert = X509Certificate::CreateFromHandle( 1855 X509Certificate* x509_cert = X509Certificate::CreateFromHandle(
1853 node->cert, X509Certificate::SOURCE_LONE_CERT_IMPORT, 1856 node->cert, net::X509Certificate::OSCertHandles());
1854 net::X509Certificate::OSCertHandles());
1855 that->client_certs_.push_back(x509_cert); 1857 that->client_certs_.push_back(x509_cert);
1856 } 1858 }
1857 CERT_DestroyCertList(client_certs); 1859 CERT_DestroyCertList(client_certs);
1858 } 1860 }
1859 1861
1860 // Tell NSS to suspend the client authentication. We will then abort the 1862 // Tell NSS to suspend the client authentication. We will then abort the
1861 // handshake by returning ERR_SSL_CLIENT_AUTH_CERT_NEEDED. 1863 // handshake by returning ERR_SSL_CLIENT_AUTH_CERT_NEEDED.
1862 return SECWouldBlock; 1864 return SECWouldBlock;
1863 } 1865 }
1864 #endif // NSS_PLATFORM_CLIENT_AUTH 1866 #endif // NSS_PLATFORM_CLIENT_AUTH
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 case SSL_CONNECTION_VERSION_TLS1_1: 2485 case SSL_CONNECTION_VERSION_TLS1_1:
2484 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); 2486 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1);
2485 break; 2487 break;
2486 case SSL_CONNECTION_VERSION_TLS1_2: 2488 case SSL_CONNECTION_VERSION_TLS1_2:
2487 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); 2489 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2);
2488 break; 2490 break;
2489 }; 2491 };
2490 } 2492 }
2491 2493
2492 } // namespace net 2494 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698