Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/cert/cert_verify_proc_whitelist.h" | |
| 6 | |
| 7 #include <cstdlib> | |
| 8 | |
| 9 #include "net/cert/x509_certificate.h" | |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const uint8_t kBuiltinWhitelistHashes[][crypto::kSHA256Length] = {}; | |
| 16 | |
| 17 const PublicKeyWhitelist kBuiltinWhitelist[] = { | |
| 18 { { 0x00 }, | |
| 19 kBuiltinWhitelistHashes, | |
| 20 0 }, | |
| 21 }; | |
| 22 const size_t kBuiltinWhitelistSize = 0; | |
|
davidben
2015/03/31 02:02:13
I'm guessing this will later be replaced with a #i
Ryan Sleevi
2015/03/31 18:33:52
Yup. Potentially in a subsequent CL.
| |
| 23 | |
| 24 const PublicKeyWhitelist* g_whitelist = kBuiltinWhitelist; | |
| 25 size_t g_whitelist_size = kBuiltinWhitelistSize; | |
| 26 | |
| 27 // Comparator to compare a SHA256HashValue with a uint8_t array containing a | |
| 28 // raw SHA-256 hash. | |
| 29 // Return value follows memcmp semantics. | |
| 30 int CompareHashValueToRawHash(const void* key, const void* element) { | |
| 31 const SHA256HashValue* search_key = | |
| 32 reinterpret_cast<const SHA256HashValue*>(key); | |
| 33 return memcmp(search_key->data, element, sizeof(search_key->data)); | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 bool IsNonWhitelistedCertificate( | |
| 39 const X509Certificate& cert, | |
| 40 const HashValueVector& public_key_hashes) { | |
| 41 if (g_whitelist_size == 0) | |
| 42 return false; | |
|
davidben
2015/03/31 02:02:13
The for loop still works out fine. i < g_whitelist
Ryan Sleevi
2015/03/31 18:33:52
Right, it's defined, I just thought it was more re
davidben
2015/03/31 18:42:05
Mmm. I generally don't like unnecessary special-ca
| |
| 43 for (size_t i = 0; i < g_whitelist_size; ++i) { | |
| 44 for (const auto& hash : public_key_hashes) { | |
|
davidben
2015/03/31 02:02:13
Potential nuisance: if a root we whitelist ever cr
Ryan Sleevi
2015/03/31 18:33:52
We already implicitly have the ability to whitelis
| |
| 45 if (hash.tag != HASH_VALUE_SHA256) | |
| 46 continue; | |
| 47 if (memcmp(hash.data(), g_whitelist[i].public_key, | |
| 48 crypto::kSHA256Length) != 0) { | |
| 49 continue; | |
| 50 } | |
| 51 const SHA256HashValue leaf_hash = | |
| 52 X509Certificate::CalculateFingerprint256(cert.os_cert_handle()); | |
| 53 void* result = bsearch(&leaf_hash, g_whitelist[i].whitelist, | |
| 54 g_whitelist[i].whitelist_size, | |
| 55 crypto::kSHA256Length, CompareHashValueToRawHash); | |
| 56 if (result == nullptr) | |
| 57 return true; | |
| 58 return false; | |
| 59 } | |
| 60 } | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 void SetCertificateWhitelistForTesting( | |
| 65 const PublicKeyWhitelist* whitelist, | |
| 66 size_t whitelist_size) { | |
| 67 if (whitelist == nullptr || whitelist_size == 0) { | |
| 68 g_whitelist = kBuiltinWhitelist; | |
| 69 g_whitelist_size = kBuiltinWhitelistSize; | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 g_whitelist = whitelist; | |
| 74 g_whitelist_size = whitelist_size; | |
| 75 } | |
| 76 | |
| 77 } // namespace net | |
| OLD | NEW |