 Chromium Code Reviews
 Chromium Code Reviews Issue 1042973002:
  Implement the ability to whitelist certs from specific issuers  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1042973002:
  Implement the ability to whitelist certs from specific issuers  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: net/cert/cert_verify_proc.cc | 
| diff --git a/net/cert/cert_verify_proc.cc b/net/cert/cert_verify_proc.cc | 
| index d987e3dc04c079d67078a53df9e6a35e1161fb65..13096d81fbed30f6c4a8ac15e55edc9a0d2cec8b 100644 | 
| --- a/net/cert/cert_verify_proc.cc | 
| +++ b/net/cert/cert_verify_proc.cc | 
| @@ -12,6 +12,7 @@ | 
| #include "base/strings/stringprintf.h" | 
| #include "base/time/time.h" | 
| #include "build/build_config.h" | 
| +#include "crypto/sha2.h" | 
| #include "net/base/net_errors.h" | 
| #include "net/base/net_util.h" | 
| #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 
| @@ -39,6 +40,7 @@ | 
| namespace net { | 
| namespace { | 
| +#include "net/cert/cert_verify_proc_whitelist-inc.cc" | 
| 
davidben
2015/03/30 21:59:14
Maybe cert_verify_proc_whitelist.h or cert_verify_
 
Ryan Sleevi
2015/03/30 22:27:05
net_error_list makes some sense because it's inclu
 | 
| // Constants used to build histogram names | 
| const char kLeafCert[] = "Leaf"; | 
| @@ -164,6 +166,12 @@ bool ExaminePublicKeys(const scoped_refptr<X509Certificate>& cert, | 
| return weak_key; | 
| } | 
| +int CompareHashValueToRawHash(const void* key, const void* element) { | 
| + const SHA256HashValue* search_key = | 
| + reinterpret_cast<const SHA256HashValue*>(key); | 
| + return memcmp(search_key->data, element, sizeof(search_key->data)); | 
| +} | 
| + | 
| } // namespace | 
| // static | 
| @@ -235,6 +243,12 @@ int CertVerifyProc::Verify(X509Certificate* cert, | 
| rv = MapCertStatusToNetError(verify_result->cert_status); | 
| } | 
| + if (IsNonWhitelistedCert(*verify_result->verified_cert, | 
| + verify_result->public_key_hashes)) { | 
| + verify_result->cert_status |= CERT_STATUS_AUTHORITY_INVALID; | 
| + rv = MapCertStatusToNetError(verify_result->cert_status); | 
| + } | 
| 
davidben
2015/03/30 21:59:14
Just to confirm this is fine: were the underlying
 
Ryan Sleevi
2015/03/30 22:27:05
Yup
 | 
| + | 
| // Check for weak keys in the entire verified chain. | 
| bool weak_key = ExaminePublicKeys(verify_result->verified_cert, | 
| verify_result->is_issued_by_known_root); | 
| @@ -669,4 +683,28 @@ bool CertVerifyProc::HasTooLongValidity(const X509Certificate& cert) { | 
| return false; | 
| } | 
| +// static | 
| +bool CertVerifyProc::IsNonWhitelistedCert(const X509Certificate& cert, | 
| + const HashValueVector& hashes) { | 
| + for (size_t i = 0; i < arraysize(kWhitelistedIssuers); ++i) { | 
| + for (const auto& hash : hashes) { | 
| + if (hash.tag == HASH_VALUE_SHA256 && | 
| + memcmp(hash.data(), kWhitelistedIssuers[i].public_key, | 
| + crypto::kSHA256Length) == 0) { | 
| + const SHA256HashValue leaf_hash = | 
| + X509Certificate::CalculateFingerprint256(cert.os_cert_handle()); | 
| + void* result = | 
| + bsearch(&leaf_hash, kWhitelistedIssuers[i].whitelist, | 
| 
davidben
2015/03/30 21:59:14
Optional: std::lower_bound might save you some cas
 
Ryan Sleevi
2015/03/30 22:27:05
Adds an extra compare and the extra check. Also en
 | 
| + kWhitelistedIssuers[i].whitelist_size, | 
| + sizeof(leaf_hash.data), CompareHashValueToRawHash); | 
| 
davidben
2015/03/30 21:59:14
Nit: Probably clearer to do sizeof(leaf_data.data)
 
Ryan Sleevi
2015/03/30 22:27:05
I don't believe that's guaranteed to optimize the
 
davidben
2015/03/30 22:29:22
Oh, I just meant if you were to switch to a differ
 | 
| + if (result == nullptr) | 
| + return true; | 
| + return false; | 
| + } | 
| + } | 
| + } | 
| + | 
| + return false; | 
| +} | 
| + | 
| } // namespace net |