OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/app/signature_validator_win.h" | 5 #include "chrome/app/signature_validator_win.h" |
6 | 6 |
7 #include <atlstr.h> | 7 #include <atlstr.h> |
8 #include <softpub.h> | 8 #include <softpub.h> |
9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <stdint.h> |
10 #include <wintrust.h> | 11 #include <wintrust.h> |
11 | 12 |
12 #include <algorithm> | 13 #include <algorithm> |
13 | 14 |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/macros.h" |
15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
19 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
20 #include "crypto/sha2.h" | 22 #include "crypto/sha2.h" |
21 #include "crypto/wincrypt_shim.h" | 23 #include "crypto/wincrypt_shim.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 bool ExtractPublicKeyHash(const CERT_CONTEXT* cert_context, | 27 bool ExtractPublicKeyHash(const CERT_CONTEXT* cert_context, |
26 std::string* public_key_hash) { | 28 std::string* public_key_hash) { |
27 public_key_hash->clear(); | 29 public_key_hash->clear(); |
28 | 30 |
29 CRYPT_BIT_BLOB crypt_blob = | 31 CRYPT_BIT_BLOB crypt_blob = |
30 cert_context->pCertInfo->SubjectPublicKeyInfo.PublicKey; | 32 cert_context->pCertInfo->SubjectPublicKeyInfo.PublicKey; |
31 | 33 |
32 // Key blobs that are not an integral number of bytes are unsupported. | 34 // Key blobs that are not an integral number of bytes are unsupported. |
33 if (crypt_blob.cUnusedBits != 0) | 35 if (crypt_blob.cUnusedBits != 0) |
34 return false; | 36 return false; |
35 | 37 |
36 uint8 hash[crypto::kSHA256Length] = {}; | 38 uint8_t hash[crypto::kSHA256Length] = {}; |
37 | 39 |
38 base::StringPiece key_bytes(reinterpret_cast<char*>( | 40 base::StringPiece key_bytes(reinterpret_cast<char*>( |
39 crypt_blob.pbData), crypt_blob.cbData); | 41 crypt_blob.pbData), crypt_blob.cbData); |
40 crypto::SHA256HashString(key_bytes, hash, crypto::kSHA256Length); | 42 crypto::SHA256HashString(key_bytes, hash, crypto::kSHA256Length); |
41 | 43 |
42 *public_key_hash = base::ToLowerASCII(base::HexEncode(hash, arraysize(hash))); | 44 *public_key_hash = base::ToLowerASCII(base::HexEncode(hash, arraysize(hash))); |
43 return true; | 45 return true; |
44 } | 46 } |
45 | 47 |
46 // The traits class for HCERTSTORE handles that can be closed via | 48 // The traits class for HCERTSTORE handles that can be closed via |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // to make sure the cert is current. | 214 // to make sure the cert is current. |
213 std::vector<std::string>::const_iterator it = std::find( | 215 std::vector<std::string>::const_iterator it = std::find( |
214 expected_hashes.begin(), | 216 expected_hashes.begin(), |
215 expected_hashes.end(), | 217 expected_hashes.end(), |
216 cert_info.public_key_hash()); | 218 cert_info.public_key_hash()); |
217 if (it == expected_hashes.end() || !cert_info.IsValidNow()) | 219 if (it == expected_hashes.end() || !cert_info.IsValidNow()) |
218 return false; | 220 return false; |
219 | 221 |
220 return true; | 222 return true; |
221 } | 223 } |
OLD | NEW |