OLD | NEW |
| (Empty) |
1 // Copyright 2016 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/ssl/ssl_platform_key.h" | |
6 | |
7 #include <pk11pub.h> | |
8 #include <stdint.h> | |
9 #include <string.h> | |
10 | |
11 #include <memory> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "base/files/file_path.h" | |
16 #include "base/files/file_util.h" | |
17 #include "base/memory/ref_counted.h" | |
18 #include "crypto/scoped_test_nss_db.h" | |
19 #include "net/ssl/ssl_private_key.h" | |
20 #include "net/ssl/ssl_private_key_test_util.h" | |
21 #include "net/test/cert_test_util.h" | |
22 #include "net/test/test_data_directory.h" | |
23 #include "testing/gtest/include/gtest/gtest.h" | |
24 | |
25 namespace net { | |
26 | |
27 TEST(SSLPlatformKeyChromecastTest, KeyMatches) { | |
28 std::string pkcs8; | |
29 base::FilePath pkcs8_path = | |
30 GetTestCertsDirectory().AppendASCII("client_1.pk8"); | |
31 ASSERT_TRUE(base::ReadFileToString(pkcs8_path, &pkcs8)); | |
32 | |
33 // Import the key into a test NSS database. | |
34 crypto::ScopedTestNSSDB test_db; | |
35 scoped_refptr<X509Certificate> cert = ImportClientCertAndKeyFromFile( | |
36 GetTestCertsDirectory(), "client_1.pem", "client_1.pk8", test_db.slot()); | |
37 ASSERT_TRUE(cert); | |
38 | |
39 // Look up the key. | |
40 scoped_refptr<SSLPrivateKey> key = FetchClientCertPrivateKey(cert.get()); | |
41 ASSERT_TRUE(key); | |
42 | |
43 // Only support SHA-256 and SHA-1. | |
44 std::vector<SSLPrivateKey::Hash> expected_hashes = { | |
45 SSLPrivateKey::Hash::SHA256, SSLPrivateKey::Hash::SHA1, | |
46 }; | |
47 EXPECT_EQ(expected_hashes, key->GetDigestPreferences()); | |
48 | |
49 TestSSLPrivateKeyMatches(key.get(), pkcs8); | |
50 } | |
51 | |
52 } // namespace net | |
OLD | NEW |