diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 01:59:01 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 01:59:01 +0000 |
commit | e0e087f07253fe3d95aeafdfa337463d4334b7fa (patch) | |
tree | a6fa2b390d98f6c3c0beef87915407c4d27c5ed6 /net/base/x509_certificate_win.cc | |
parent | b73bb80b3496c7e1e8de3d808fc451663885d0b7 (diff) | |
download | chromium_src-e0e087f07253fe3d95aeafdfa337463d4334b7fa.zip chromium_src-e0e087f07253fe3d95aeafdfa337463d4334b7fa.tar.gz chromium_src-e0e087f07253fe3d95aeafdfa337463d4334b7fa.tar.bz2 |
Change the HTTP cache to cache the entire certificate chain for SSL sites
When persisting an X509Certificate to a pickle, such as when storing to the HTTP cache, persist any intermediate certificates in addition to the end-entity certificate. This will allow the complete certificate chain to be displayed to the end user when viewing a cached entry, independent of whether a network request has been made to that site during the browsing session.
R=agl
BUG=7065
TEST=X509CertificateTest.Persist
Review URL: http://codereview.chromium.org/4645001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/x509_certificate_win.cc')
-rw-r--r-- | net/base/x509_certificate_win.cc | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/net/base/x509_certificate_win.cc b/net/base/x509_certificate_win.cc index a1a3eae..fd5076d 100644 --- a/net/base/x509_certificate_win.cc +++ b/net/base/x509_certificate_win.cc @@ -550,29 +550,6 @@ bool X509Certificate::IsIssuedByKnownRoot(PCCERT_CHAIN_CONTEXT chain_context) { } // static -X509Certificate* X509Certificate::CreateFromPickle(const Pickle& pickle, - void** pickle_iter) { - const char* data; - int length; - if (!pickle.ReadData(pickle_iter, &data, &length)) - return NULL; - - OSCertHandle cert_handle = NULL; - if (!CertAddSerializedElementToStore( - NULL, // the cert won't be persisted in any cert store - reinterpret_cast<const BYTE*>(data), length, - CERT_STORE_ADD_USE_EXISTING, 0, CERT_STORE_CERTIFICATE_CONTEXT_FLAG, - NULL, reinterpret_cast<const void **>(&cert_handle))) - return NULL; - - X509Certificate* cert = CreateFromHandle(cert_handle, - SOURCE_LONE_CERT_IMPORT, - OSCertHandles()); - FreeOSCertHandle(cert_handle); - return cert; -} - -// static X509Certificate* X509Certificate::CreateSelfSigned( crypto::RSAPrivateKey* key, const std::string& subject, @@ -635,23 +612,6 @@ X509Certificate* X509Certificate::CreateSelfSigned( return cert; } -void X509Certificate::Persist(Pickle* pickle) { - DCHECK(cert_handle_); - DWORD length; - if (!CertSerializeCertificateStoreElement(cert_handle_, 0, - NULL, &length)) { - NOTREACHED(); - return; - } - BYTE* data = reinterpret_cast<BYTE*>(pickle->BeginWriteData(length)); - if (!CertSerializeCertificateStoreElement(cert_handle_, 0, - data, &length)) { - NOTREACHED(); - length = 0; - } - pickle->TrimWriteData(length); -} - void X509Certificate::GetDNSNames(std::vector<std::string>* dns_names) const { dns_names->clear(); if (cert_handle_) { @@ -1044,4 +1004,45 @@ SHA1Fingerprint X509Certificate::CalculateFingerprint( return sha1; } +// static +X509Certificate::OSCertHandle +X509Certificate::ReadCertHandleFromPickle(const Pickle& pickle, + void** pickle_iter) { + const char* data; + int length; + if (!pickle.ReadData(pickle_iter, &data, &length)) + return NULL; + + OSCertHandle cert_handle = NULL; + if (!CertAddSerializedElementToStore( + NULL, // the cert won't be persisted in any cert store + reinterpret_cast<const BYTE*>(data), length, + CERT_STORE_ADD_USE_EXISTING, 0, CERT_STORE_CERTIFICATE_CONTEXT_FLAG, + NULL, reinterpret_cast<const void **>(&cert_handle))) { + return NULL; + } + + return cert_handle; +} + +// static +bool X509Certificate::WriteCertHandleToPickle(OSCertHandle cert_handle, + Pickle* pickle) { + DWORD length = 0; + if (!CertSerializeCertificateStoreElement(cert_handle, 0, NULL, &length)) + return false; + + std::vector<BYTE> buffer(length); + // Serialize |cert_handle| in a way that will preserve any extended + // attributes set on the handle, such as the location to the certificate's + // private key. + if (!CertSerializeCertificateStoreElement(cert_handle, 0, &buffer[0], + &length)) { + return false; + } + + return pickle->WriteData(reinterpret_cast<const char*>(&buffer[0]), + length); +} + } // namespace net |