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 <windows.h> | 5 #include <windows.h> |
6 #include <atlstr.h> | 6 #include <atlstr.h> |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
7 #include <wintrust.h> | 9 #include <wintrust.h> |
8 | 10 |
9 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" |
15 #include "base/path_service.h" | 17 #include "base/path_service.h" |
16 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
18 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
19 #include "chrome/app/signature_validator_win.h" | 21 #include "chrome/app/signature_validator_win.h" |
20 #include "crypto/sha2.h" | 22 #include "crypto/sha2.h" |
21 #include "crypto/wincrypt_shim.h" | 23 #include "crypto/wincrypt_shim.h" |
22 #include "net/cert/test_root_certs.h" | 24 #include "net/cert/test_root_certs.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 | 26 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 void SetExpectedHash(const base::FilePath& cert_path) { | 71 void SetExpectedHash(const base::FilePath& cert_path) { |
70 char cert_buffer[CERT_BUFFER_SIZE]; | 72 char cert_buffer[CERT_BUFFER_SIZE]; |
71 base::ReadFile(cert_path, cert_buffer, CERT_BUFFER_SIZE); | 73 base::ReadFile(cert_path, cert_buffer, CERT_BUFFER_SIZE); |
72 | 74 |
73 PCCERT_CONTEXT cert = CertCreateCertificateContext(X509_ASN_ENCODING, | 75 PCCERT_CONTEXT cert = CertCreateCertificateContext(X509_ASN_ENCODING, |
74 reinterpret_cast<byte*>(&cert_buffer), | 76 reinterpret_cast<byte*>(&cert_buffer), |
75 CERT_BUFFER_SIZE); | 77 CERT_BUFFER_SIZE); |
76 | 78 |
77 CRYPT_BIT_BLOB blob = cert->pCertInfo->SubjectPublicKeyInfo.PublicKey; | 79 CRYPT_BIT_BLOB blob = cert->pCertInfo->SubjectPublicKeyInfo.PublicKey; |
78 size_t public_key_length = blob.cbData; | 80 size_t public_key_length = blob.cbData; |
79 uint8* public_key = blob.pbData; | 81 uint8_t* public_key = blob.pbData; |
80 | 82 |
81 uint8 hash[crypto::kSHA256Length] = {0}; | 83 uint8_t hash[crypto::kSHA256Length] = {0}; |
82 | 84 |
83 base::StringPiece key_bytes(reinterpret_cast<char*>(public_key), | 85 base::StringPiece key_bytes(reinterpret_cast<char*>(public_key), |
84 public_key_length); | 86 public_key_length); |
85 crypto::SHA256HashString(key_bytes, hash, crypto::kSHA256Length); | 87 crypto::SHA256HashString(key_bytes, hash, crypto::kSHA256Length); |
86 | 88 |
87 std::string public_key_hash = | 89 std::string public_key_hash = |
88 base::ToLowerASCII(base::HexEncode(hash, arraysize(hash))); | 90 base::ToLowerASCII(base::HexEncode(hash, arraysize(hash))); |
89 expected_hashes_.push_back(public_key_hash); | 91 expected_hashes_.push_back(public_key_hash); |
90 } | 92 } |
91 | 93 |
(...skipping 30 matching lines...) Expand all Loading... |
122 TEST_F(SignatureValidatorTest, CertPinningTest) { | 124 TEST_F(SignatureValidatorTest, CertPinningTest) { |
123 RunTest(L"different_hash.dll", true, false); | 125 RunTest(L"different_hash.dll", true, false); |
124 } | 126 } |
125 | 127 |
126 TEST_F(SignatureValidatorTest, ExpiredCertTest) { | 128 TEST_F(SignatureValidatorTest, ExpiredCertTest) { |
127 //TODO(caitkp): Figure out how to sign a dll with an expired cert. | 129 //TODO(caitkp): Figure out how to sign a dll with an expired cert. |
128 RunTest(L"expired.dll", false, false); | 130 RunTest(L"expired.dll", false, false); |
129 } | 131 } |
130 | 132 |
131 | 133 |
OLD | NEW |