| Index: net/cert/x509_certificate_win.cc
|
| diff --git a/net/cert/x509_certificate_win.cc b/net/cert/x509_certificate_win.cc
|
| index c679107371a8594e8202b725bf4078d46f7b8074..81ef8260c79a22c6b6eb1583292eddf4c5ea341c 100644
|
| --- a/net/cert/x509_certificate_win.cc
|
| +++ b/net/cert/x509_certificate_win.cc
|
| @@ -26,8 +26,8 @@ namespace {
|
|
|
| typedef crypto::ScopedCAPIHandle<
|
| HCERTSTORE,
|
| - crypto::CAPIDestroyerWithFlags<HCERTSTORE,
|
| - CertCloseStore, 0> > ScopedHCERTSTORE;
|
| + crypto::CAPIDestroyerWithFlags<HCERTSTORE, CertCloseStore, 0> >
|
| + ScopedHCERTSTORE;
|
|
|
| void ExplodedTimeToSystemTime(const base::Time::Exploded& exploded,
|
| SYSTEMTIME* system_time) {
|
| @@ -80,13 +80,14 @@ void AddCertsFromStore(HCERTSTORE store,
|
| while ((cert = CertEnumCertificatesInStore(store, cert)) != NULL) {
|
| PCCERT_CONTEXT to_add = NULL;
|
| if (CertAddCertificateContextToStore(
|
| - NULL, // The cert won't be persisted in any cert store. This breaks
|
| - // any association the context currently has to |store|, which
|
| - // allows us, the caller, to safely close |store| without
|
| - // releasing the cert handles.
|
| - cert,
|
| - CERT_STORE_ADD_USE_EXISTING,
|
| - &to_add) && to_add != NULL) {
|
| + NULL, // The cert won't be persisted in any cert store. This breaks
|
| + // any association the context currently has to |store|, which
|
| + // allows us, the caller, to safely close |store| without
|
| + // releasing the cert handles.
|
| + cert,
|
| + CERT_STORE_ADD_USE_EXISTING,
|
| + &to_add) &&
|
| + to_add != NULL) {
|
| // When processing stores generated from PKCS#7/PKCS#12 files, it
|
| // appears that the order returned is the inverse of the order that it
|
| // appeared in the file.
|
| @@ -109,9 +110,18 @@ X509Certificate::OSCertHandles ParsePKCS7(const char* data, size_t length) {
|
| CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED |
|
| CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED;
|
|
|
| - if (!CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &data_blob, expected_types,
|
| - CERT_QUERY_FORMAT_FLAG_BINARY, 0, NULL, NULL, NULL,
|
| - &out_store, NULL, NULL) || out_store == NULL) {
|
| + if (!CryptQueryObject(CERT_QUERY_OBJECT_BLOB,
|
| + &data_blob,
|
| + expected_types,
|
| + CERT_QUERY_FORMAT_FLAG_BINARY,
|
| + 0,
|
| + NULL,
|
| + NULL,
|
| + NULL,
|
| + &out_store,
|
| + NULL,
|
| + NULL) ||
|
| + out_store == NULL) {
|
| return results;
|
| }
|
|
|
| @@ -124,14 +134,13 @@ X509Certificate::OSCertHandles ParsePKCS7(const char* data, size_t length) {
|
| // Given a CERT_NAME_BLOB, returns true if it appears in a given list,
|
| // formatted as a vector of strings holding DER-encoded X.509
|
| // DistinguishedName entries.
|
| -bool IsCertNameBlobInIssuerList(
|
| - CERT_NAME_BLOB* name_blob,
|
| - const std::vector<std::string>& issuer_names) {
|
| +bool IsCertNameBlobInIssuerList(CERT_NAME_BLOB* name_blob,
|
| + const std::vector<std::string>& issuer_names) {
|
| for (std::vector<std::string>::const_iterator it = issuer_names.begin();
|
| - it != issuer_names.end(); ++it) {
|
| + it != issuer_names.end();
|
| + ++it) {
|
| CERT_NAME_BLOB issuer_blob;
|
| - issuer_blob.pbData =
|
| - reinterpret_cast<BYTE*>(const_cast<char*>(it->data()));
|
| + issuer_blob.pbData = reinterpret_cast<BYTE*>(const_cast<char*>(it->data()));
|
| issuer_blob.cbData = static_cast<DWORD>(it->length());
|
|
|
| BOOL rb = CertCompareCertificateName(
|
| @@ -161,8 +170,8 @@ void X509Certificate::Initialize() {
|
| scoped_ptr<uint8[]> serial_bytes(new uint8[serial->cbData]);
|
| for (unsigned i = 0; i < serial->cbData; i++)
|
| serial_bytes[i] = serial->pbData[serial->cbData - i - 1];
|
| - serial_number_ = std::string(
|
| - reinterpret_cast<char*>(serial_bytes.get()), serial->cbData);
|
| + serial_number_ =
|
| + std::string(reinterpret_cast<char*>(serial_bytes.get()), serial->cbData);
|
| }
|
|
|
| void X509Certificate::GetSubjectAltName(
|
| @@ -190,9 +199,9 @@ void X509Certificate::GetSubjectAltName(
|
| dns_names->push_back(base::UTF16ToASCII(entry.pwszDNSName));
|
| } else if (ip_addrs &&
|
| entry.dwAltNameChoice == CERT_ALT_NAME_IP_ADDRESS) {
|
| - ip_addrs->push_back(std::string(
|
| - reinterpret_cast<const char*>(entry.IPAddress.pbData),
|
| - entry.IPAddress.cbData));
|
| + ip_addrs->push_back(
|
| + std::string(reinterpret_cast<const char*>(entry.IPAddress.pbData),
|
| + entry.IPAddress.cbData));
|
| }
|
| }
|
| }
|
| @@ -203,9 +212,12 @@ PCCERT_CONTEXT X509Certificate::CreateOSCertChainForCert() const {
|
| // any intermediate certificates in |intermediate_ca_certs_|. The store
|
| // will be referenced in the returned PCCERT_CONTEXT, and will not be freed
|
| // until the PCCERT_CONTEXT is freed.
|
| - ScopedHCERTSTORE store(CertOpenStore(
|
| - CERT_STORE_PROV_MEMORY, 0, NULL,
|
| - CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL));
|
| + ScopedHCERTSTORE store(
|
| + CertOpenStore(CERT_STORE_PROV_MEMORY,
|
| + 0,
|
| + NULL,
|
| + CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG,
|
| + NULL));
|
| if (!store.get())
|
| return NULL;
|
|
|
| @@ -215,15 +227,14 @@ PCCERT_CONTEXT X509Certificate::CreateOSCertChainForCert() const {
|
| // has already been unlocked (eg: PIN prompt), then the first time that the
|
| // identity is used for client auth, it may prompt the user again.
|
| PCCERT_CONTEXT primary_cert;
|
| - BOOL ok = CertAddCertificateContextToStore(store.get(), os_cert_handle(),
|
| - CERT_STORE_ADD_ALWAYS,
|
| - &primary_cert);
|
| + BOOL ok = CertAddCertificateContextToStore(
|
| + store.get(), os_cert_handle(), CERT_STORE_ADD_ALWAYS, &primary_cert);
|
| if (!ok || !primary_cert)
|
| return NULL;
|
|
|
| for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) {
|
| - CertAddCertificateContextToStore(store.get(), intermediate_ca_certs_[i],
|
| - CERT_STORE_ADD_ALWAYS, NULL);
|
| + CertAddCertificateContextToStore(
|
| + store.get(), intermediate_ca_certs_[i], CERT_STORE_ADD_ALWAYS, NULL);
|
| }
|
|
|
| // Note: |store| is explicitly not released, as the call to CertCloseStore()
|
| @@ -249,23 +260,29 @@ bool X509Certificate::IsSameOSCert(X509Certificate::OSCertHandle a,
|
| if (a == b)
|
| return true;
|
| return a->cbCertEncoded == b->cbCertEncoded &&
|
| - memcmp(a->pbCertEncoded, b->pbCertEncoded, a->cbCertEncoded) == 0;
|
| + memcmp(a->pbCertEncoded, b->pbCertEncoded, a->cbCertEncoded) == 0;
|
| }
|
|
|
| // static
|
| X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes(
|
| - const char* data, int length) {
|
| + const char* data,
|
| + int length) {
|
| OSCertHandle cert_handle = NULL;
|
| - if (!CertAddEncodedCertificateToStore(
|
| - NULL, X509_ASN_ENCODING, reinterpret_cast<const BYTE*>(data),
|
| - length, CERT_STORE_ADD_USE_EXISTING, &cert_handle))
|
| + if (!CertAddEncodedCertificateToStore(NULL,
|
| + X509_ASN_ENCODING,
|
| + reinterpret_cast<const BYTE*>(data),
|
| + length,
|
| + CERT_STORE_ADD_USE_EXISTING,
|
| + &cert_handle))
|
| return NULL;
|
|
|
| return cert_handle;
|
| }
|
|
|
| X509Certificate::OSCertHandles X509Certificate::CreateOSCertHandlesFromBytes(
|
| - const char* data, int length, Format format) {
|
| + const char* data,
|
| + int length,
|
| + Format format) {
|
| OSCertHandles results;
|
| switch (format) {
|
| case FORMAT_SINGLE_CERTIFICATE: {
|
| @@ -297,16 +314,20 @@ void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) {
|
| }
|
|
|
| // static
|
| -SHA1HashValue X509Certificate::CalculateFingerprint(
|
| - OSCertHandle cert) {
|
| +SHA1HashValue X509Certificate::CalculateFingerprint(OSCertHandle cert) {
|
| DCHECK(NULL != cert->pbCertEncoded);
|
| DCHECK_NE(static_cast<DWORD>(0), cert->cbCertEncoded);
|
|
|
| BOOL rv;
|
| SHA1HashValue sha1;
|
| DWORD sha1_size = sizeof(sha1.data);
|
| - rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded,
|
| - cert->cbCertEncoded, sha1.data, &sha1_size);
|
| + rv = CryptHashCertificate(NULL,
|
| + CALG_SHA1,
|
| + 0,
|
| + cert->pbCertEncoded,
|
| + cert->cbCertEncoded,
|
| + sha1.data,
|
| + &sha1_size);
|
| DCHECK(rv && sha1_size == sizeof(sha1.data));
|
| if (!rv)
|
| memset(sha1.data, 0, sizeof(sha1.data));
|
| @@ -338,8 +359,8 @@ SHA1HashValue X509Certificate::CalculateCAFingerprint(
|
| }
|
|
|
| // static
|
| -X509Certificate::OSCertHandle
|
| -X509Certificate::ReadOSCertHandleFromPickle(PickleIterator* pickle_iter) {
|
| +X509Certificate::OSCertHandle X509Certificate::ReadOSCertHandleFromPickle(
|
| + PickleIterator* pickle_iter) {
|
| const char* data;
|
| int length;
|
| if (!pickle_iter->ReadData(&data, &length))
|
| @@ -359,9 +380,14 @@ X509Certificate::ReadOSCertHandleFromPickle(PickleIterator* pickle_iter) {
|
|
|
| OSCertHandle cert_handle = NULL;
|
| if (!CertAddSerializedElementToStore(
|
| - store.get(), reinterpret_cast<const BYTE*>(data), length,
|
| - CERT_STORE_ADD_NEW, 0, CERT_STORE_CERTIFICATE_CONTEXT_FLAG,
|
| - NULL, reinterpret_cast<const void **>(&cert_handle))) {
|
| + store.get(),
|
| + reinterpret_cast<const BYTE*>(data),
|
| + length,
|
| + CERT_STORE_ADD_NEW,
|
| + 0,
|
| + CERT_STORE_CERTIFICATE_CONTEXT_FLAG,
|
| + NULL,
|
| + reinterpret_cast<const void**>(&cert_handle))) {
|
| return NULL;
|
| }
|
|
|
| @@ -378,9 +404,8 @@ X509Certificate::ReadOSCertHandleFromPickle(PickleIterator* pickle_iter) {
|
| // static
|
| bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle,
|
| Pickle* pickle) {
|
| - return pickle->WriteData(
|
| - reinterpret_cast<char*>(cert_handle->pbCertEncoded),
|
| - cert_handle->cbCertEncoded);
|
| + return pickle->WriteData(reinterpret_cast<char*>(cert_handle->pbCertEncoded),
|
| + cert_handle->cbCertEncoded);
|
| }
|
|
|
| // static
|
| @@ -400,9 +425,9 @@ void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle,
|
| CHECK_EQ(oid_info->dwGroupId,
|
| static_cast<DWORD>(CRYPT_PUBKEY_ALG_OID_GROUP_ID));
|
|
|
| - *size_bits = CertGetPublicKeyLength(
|
| - X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
|
| - &cert_handle->pCertInfo->SubjectPublicKeyInfo);
|
| + *size_bits =
|
| + CertGetPublicKeyLength(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
|
| + &cert_handle->pCertInfo->SubjectPublicKeyInfo);
|
|
|
| if (IS_SPECIAL_OID_INFO_ALGID(oid_info->Algid)) {
|
| // For an EC public key, oid_info->Algid is CALG_OID_INFO_PARAMETERS
|
| @@ -433,7 +458,6 @@ void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle,
|
|
|
| bool X509Certificate::IsIssuedByEncoded(
|
| const std::vector<std::string>& valid_issuers) {
|
| -
|
| // If the certificate's issuer in the list?
|
| if (IsCertNameBlobInIssuerList(&cert_handle_->pCertInfo->Issuer,
|
| valid_issuers)) {
|
| @@ -441,9 +465,9 @@ bool X509Certificate::IsIssuedByEncoded(
|
| }
|
| // Otherwise, is any of the intermediate CA subjects in the list?
|
| for (OSCertHandles::iterator it = intermediate_ca_certs_.begin();
|
| - it != intermediate_ca_certs_.end(); ++it) {
|
| - if (IsCertNameBlobInIssuerList(&(*it)->pCertInfo->Issuer,
|
| - valid_issuers)) {
|
| + it != intermediate_ca_certs_.end();
|
| + ++it) {
|
| + if (IsCertNameBlobInIssuerList(&(*it)->pCertInfo->Issuer, valid_issuers)) {
|
| return true;
|
| }
|
| }
|
|
|