OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <openssl/bytestring.h> |
5 #include <openssl/digest.h> | 6 #include <openssl/digest.h> |
6 #include <openssl/ecdsa.h> | 7 #include <openssl/ecdsa.h> |
7 #include <openssl/err.h> | 8 #include <openssl/err.h> |
8 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
9 #include <openssl/pem.h> | 10 #include <openssl/pem.h> |
10 #include <openssl/rsa.h> | 11 #include <openssl/rsa.h> |
| 12 #include <openssl/x509.h> |
11 | 13 |
12 #include "base/android/build_info.h" | |
13 #include "base/android/jni_android.h" | 14 #include "base/android/jni_android.h" |
14 #include "base/android/jni_array.h" | 15 #include "base/android/jni_array.h" |
15 #include "base/android/scoped_java_ref.h" | 16 #include "base/android/scoped_java_ref.h" |
16 #include "base/bind.h" | 17 #include "base/bind.h" |
17 #include "base/callback.h" | |
18 #include "base/compiler_specific.h" | |
19 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
20 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
21 #include "base/files/scoped_file.h" | |
22 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
23 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
25 #include "crypto/auto_cbb.h" | |
26 #include "crypto/openssl_util.h" | 23 #include "crypto/openssl_util.h" |
27 #include "crypto/scoped_openssl_types.h" | |
28 #include "net/android/keystore.h" | 24 #include "net/android/keystore.h" |
29 #include "net/ssl/scoped_openssl_types.h" | 25 #include "net/cert/x509_certificate.h" |
30 #include "net/ssl/ssl_platform_key_android.h" | 26 #include "net/ssl/ssl_platform_key_android.h" |
31 #include "net/ssl/ssl_private_key.h" | 27 #include "net/ssl/ssl_private_key.h" |
| 28 #include "net/test/cert_test_util.h" |
32 #include "net/test/jni/AndroidKeyStoreTestUtil_jni.h" | 29 #include "net/test/jni/AndroidKeyStoreTestUtil_jni.h" |
33 #include "net/test/test_data_directory.h" | 30 #include "net/test/test_data_directory.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
35 | 32 |
36 namespace net { | 33 namespace net { |
37 | 34 |
38 namespace { | 35 namespace { |
39 | 36 |
40 typedef base::android::ScopedJavaLocalRef<jobject> ScopedJava; | 37 typedef base::android::ScopedJavaLocalRef<jobject> ScopedJava; |
41 | 38 |
42 // Resize a string to |size| bytes of data, then return its data buffer | 39 // Resize a string to |size| bytes of data, then return its data buffer |
43 // address cast as an 'unsigned char*', as expected by OpenSSL functions. | 40 // address cast as an 'unsigned char*', as expected by OpenSSL functions. |
44 // |str| the target string. | 41 // |str| the target string. |
45 // |size| the number of bytes to write into the string. | 42 // |size| the number of bytes to write into the string. |
46 // Return the string's new buffer in memory, as an 'unsigned char*' | 43 // Return the string's new buffer in memory, as an 'unsigned char*' |
47 // pointer. | 44 // pointer. |
48 unsigned char* OpenSSLWriteInto(std::string* str, size_t size) { | 45 unsigned char* OpenSSLWriteInto(std::string* str, size_t size) { |
49 return reinterpret_cast<unsigned char*>(base::WriteInto(str, size + 1)); | 46 return reinterpret_cast<unsigned char*>(base::WriteInto(str, size + 1)); |
50 } | 47 } |
51 | 48 |
| 49 bool ReadTestFile(const char* filename, std::string* pkcs8) { |
| 50 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 51 base::FilePath file_path = certs_dir.AppendASCII(filename); |
| 52 return base::ReadFileToString(file_path, pkcs8); |
| 53 } |
| 54 |
52 // Load a given private key file into an EVP_PKEY. | 55 // Load a given private key file into an EVP_PKEY. |
53 // |filename| is the key file path. | 56 // |filename| is the key file path. |
54 // Returns a new EVP_PKEY on success, NULL on failure. | 57 // Returns a new EVP_PKEY on success, NULL on failure. |
55 EVP_PKEY* ImportPrivateKeyFile(const char* filename) { | 58 bssl::UniquePtr<EVP_PKEY> ImportPrivateKeyFile(const char* filename) { |
| 59 std::string pkcs8; |
| 60 if (!ReadTestFile(filename, &pkcs8)) |
| 61 return nullptr; |
| 62 |
56 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 63 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 64 CBS cbs; |
| 65 CBS_init(&cbs, reinterpret_cast<const uint8_t*>(pkcs8.data()), pkcs8.size()); |
| 66 bssl::UniquePtr<EVP_PKEY> pkey(EVP_parse_private_key(&cbs)); |
| 67 if (!pkey) { |
| 68 LOG(ERROR) << "Could not load private key file: " << filename; |
| 69 return nullptr; |
| 70 } |
57 | 71 |
58 // Load file in memory. | |
59 base::FilePath certs_dir = GetTestCertsDirectory(); | |
60 base::FilePath file_path = certs_dir.AppendASCII(filename); | |
61 base::ScopedFILE handle(base::OpenFile(file_path, "rb")); | |
62 if (!handle) { | |
63 LOG(ERROR) << "Could not open private key file: " << filename; | |
64 return NULL; | |
65 } | |
66 // Assume it is PEM_encoded. Load it as an EVP_PKEY. | |
67 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL); | |
68 if (!pkey) { | |
69 LOG(ERROR) << "Could not load public key file: " << filename; | |
70 return NULL; | |
71 } | |
72 return pkey; | 72 return pkey; |
73 } | 73 } |
74 | 74 |
75 // Convert a private key into its PKCS#8 encoded representation. | 75 // Imports the public key from the specified test certificate. |
76 // |pkey| is the EVP_PKEY handle for the private key. | 76 bssl::UniquePtr<EVP_PKEY> ImportPublicKeyFromCertificateFile( |
77 // |pkcs8| will receive the PKCS#8 bytes. | 77 const char* filename) { |
78 // Returns true on success, false otherwise. | |
79 bool GetPrivateKeyPkcs8Bytes(const crypto::ScopedEVP_PKEY& pkey, | |
80 std::string* pkcs8) { | |
81 uint8_t* der; | |
82 size_t der_len; | |
83 crypto::AutoCBB cbb; | |
84 if (!CBB_init(cbb.get(), 0) || | |
85 !EVP_marshal_private_key(cbb.get(), pkey.get()) || | |
86 !CBB_finish(cbb.get(), &der, &der_len)) { | |
87 return false; | |
88 } | |
89 pkcs8->assign(reinterpret_cast<const char*>(der), der_len); | |
90 OPENSSL_free(der); | |
91 return true; | |
92 } | |
93 | |
94 bool ImportPrivateKeyFileAsPkcs8(const char* filename, std::string* pkcs8) { | |
95 crypto::ScopedEVP_PKEY pkey(ImportPrivateKeyFile(filename)); | |
96 if (!pkey) | |
97 return false; | |
98 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8); | |
99 } | |
100 | |
101 // Same as ImportPrivateKey, but for public ones. | |
102 EVP_PKEY* ImportPublicKeyFile(const char* filename) { | |
103 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 78 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
104 | 79 |
105 // Load file as PEM data. | 80 scoped_refptr<X509Certificate> cert = |
106 base::FilePath certs_dir = GetTestCertsDirectory(); | 81 ImportCertFromFile(GetTestCertsDirectory(), filename); |
107 base::FilePath file_path = certs_dir.AppendASCII(filename); | 82 if (!cert) { |
108 base::ScopedFILE handle(base::OpenFile(file_path, "rb")); | 83 LOG(ERROR) << "Could not open certificate file: " << filename; |
109 if (!handle) { | 84 return nullptr; |
110 LOG(ERROR) << "Could not open public key file: " << filename; | |
111 return NULL; | |
112 } | 85 } |
113 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL); | 86 |
| 87 bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert->os_cert_handle())); |
114 if (!pkey) { | 88 if (!pkey) { |
115 LOG(ERROR) << "Could not load public key file: " << filename; | 89 LOG(ERROR) << "Could not load public key from certificate: " << filename; |
116 return NULL; | 90 return nullptr; |
117 } | 91 } |
| 92 |
118 return pkey; | 93 return pkey; |
119 } | 94 } |
120 | 95 |
121 // Retrieve a JNI local ref from encoded PKCS#8 data. | 96 // Retrieve a JNI local ref from encoded PKCS#8 data. |
122 ScopedJava GetPKCS8PrivateKeyJava(android::PrivateKeyType key_type, | 97 ScopedJava GetPKCS8PrivateKeyJava(android::PrivateKeyType key_type, |
123 const std::string& pkcs8_key) { | 98 const std::string& pkcs8_key) { |
124 JNIEnv* env = base::android::AttachCurrentThread(); | 99 JNIEnv* env = base::android::AttachCurrentThread(); |
125 base::android::ScopedJavaLocalRef<jbyteArray> bytes( | 100 base::android::ScopedJavaLocalRef<jbyteArray> bytes( |
126 base::android::ToJavaByteArray( | 101 base::android::ToJavaByteArray( |
127 env, reinterpret_cast<const uint8_t*>(pkcs8_key.data()), | 102 env, reinterpret_cast<const uint8_t*>(pkcs8_key.data()), |
128 pkcs8_key.size())); | 103 pkcs8_key.size())); |
129 | 104 |
130 ScopedJava key(Java_AndroidKeyStoreTestUtil_createPrivateKeyFromPKCS8( | 105 ScopedJava key(Java_AndroidKeyStoreTestUtil_createPrivateKeyFromPKCS8( |
131 env, key_type, bytes)); | 106 env, key_type, bytes)); |
132 | 107 |
133 return key; | 108 return key; |
134 } | 109 } |
135 | 110 |
136 const char kTestRsaKeyFile[] = "android-test-key-rsa.pem"; | 111 const char kTestRsaKeyFile[] = "client_1.pk8"; |
137 | 112 |
138 // Retrieve a JNI local ref for our test RSA key. | 113 // Retrieve a JNI local ref for our test RSA key. |
139 ScopedJava GetRSATestKeyJava() { | 114 ScopedJava GetRSATestKeyJava() { |
140 std::string key; | 115 std::string key; |
141 if (!ImportPrivateKeyFileAsPkcs8(kTestRsaKeyFile, &key)) | 116 if (!ReadTestFile(kTestRsaKeyFile, &key)) |
142 return ScopedJava(); | 117 return ScopedJava(); |
143 return GetPKCS8PrivateKeyJava(android::PRIVATE_KEY_TYPE_RSA, key); | 118 return GetPKCS8PrivateKeyJava(android::PRIVATE_KEY_TYPE_RSA, key); |
144 } | 119 } |
145 | 120 |
146 const char kTestEcdsaKeyFile[] = "android-test-key-ecdsa.pem"; | 121 const char kTestEcdsaKeyFile[] = "client_4.pk8"; |
147 const char kTestEcdsaPublicKeyFile[] = "android-test-key-ecdsa-public.pem"; | 122 const char kTestEcdsaCertificateFile[] = "client_4.pem"; |
148 | 123 |
149 // Retrieve a JNI local ref for our test ECDSA key. | 124 // Retrieve a JNI local ref for our test ECDSA key. |
150 ScopedJava GetECDSATestKeyJava() { | 125 ScopedJava GetECDSATestKeyJava() { |
151 std::string key; | 126 std::string key; |
152 if (!ImportPrivateKeyFileAsPkcs8(kTestEcdsaKeyFile, &key)) | 127 if (!ReadTestFile(kTestEcdsaKeyFile, &key)) |
153 return ScopedJava(); | 128 return ScopedJava(); |
154 return GetPKCS8PrivateKeyJava(android::PRIVATE_KEY_TYPE_ECDSA, key); | 129 return GetPKCS8PrivateKeyJava(android::PRIVATE_KEY_TYPE_ECDSA, key); |
155 } | 130 } |
156 | 131 |
157 // Call this function to verify that one message signed with our | 132 // Call this function to verify that one message signed with our |
158 // test ECDSA private key is correct. Since ECDSA signing introduces | 133 // test ECDSA private key is correct. Since ECDSA signing introduces |
159 // random elements in the signature, it is not possible to compare | 134 // random elements in the signature, it is not possible to compare |
160 // signature bits directly. However, one can use the public key | 135 // signature bits directly. However, one can use the public key |
161 // to do the check. | 136 // to do the check. |
162 bool VerifyTestECDSASignature(const base::StringPiece& message, | 137 bool VerifyTestECDSASignature(const base::StringPiece& message, |
163 const base::StringPiece& signature) { | 138 const base::StringPiece& signature) { |
164 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 139 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
165 | 140 |
166 crypto::ScopedEVP_PKEY pkey(ImportPublicKeyFile(kTestEcdsaPublicKeyFile)); | 141 bssl::UniquePtr<EVP_PKEY> pkey = |
| 142 ImportPublicKeyFromCertificateFile(kTestEcdsaCertificateFile); |
167 if (!pkey) | 143 if (!pkey) |
168 return false; | 144 return false; |
169 crypto::ScopedEC_KEY pub_key(EVP_PKEY_get1_EC_KEY(pkey.get())); | 145 |
| 146 EC_KEY* pub_key = EVP_PKEY_get0_EC_KEY(pkey.get()); |
170 if (!pub_key) { | 147 if (!pub_key) { |
171 LOG(ERROR) << "Could not get ECDSA public key"; | 148 LOG(ERROR) << "Could not get ECDSA public key"; |
172 return false; | 149 return false; |
173 } | 150 } |
174 | 151 |
175 const unsigned char* digest = | 152 const unsigned char* digest = |
176 reinterpret_cast<const unsigned char*>(message.data()); | 153 reinterpret_cast<const unsigned char*>(message.data()); |
177 int digest_len = static_cast<int>(message.size()); | 154 int digest_len = static_cast<int>(message.size()); |
178 const unsigned char* sigbuf = | 155 const unsigned char* sigbuf = |
179 reinterpret_cast<const unsigned char*>(signature.data()); | 156 reinterpret_cast<const unsigned char*>(signature.data()); |
180 int siglen = static_cast<int>(signature.size()); | 157 int siglen = static_cast<int>(signature.size()); |
181 | 158 |
182 int ret = ECDSA_verify(0, digest, digest_len, sigbuf, siglen, pub_key.get()); | 159 if (!ECDSA_verify(0, digest, digest_len, sigbuf, siglen, pub_key)) { |
183 if (ret != 1) { | |
184 LOG(ERROR) << "ECDSA_verify() failed"; | 160 LOG(ERROR) << "ECDSA_verify() failed"; |
185 return false; | 161 return false; |
186 } | 162 } |
187 return true; | 163 return true; |
188 } | 164 } |
189 | 165 |
190 // Sign a message with OpenSSL, return the result as a string. | 166 // Sign a message with OpenSSL, return the result as a string. |
191 // |message| is the message to be signed. | 167 // |message| is the message to be signed. |
192 // |openssl_key| is an OpenSSL EVP_PKEY to use. | 168 // |openssl_key| is an OpenSSL EVP_PKEY to use. |
193 // |result| receives the result. | 169 // |result| receives the result. |
194 // Returns true on success, false otherwise. | 170 // Returns true on success, false otherwise. |
195 bool SignWithOpenSSL(int hash_nid, | 171 bool SignWithOpenSSL(int hash_nid, |
196 const base::StringPiece& message, | 172 const base::StringPiece& message, |
197 EVP_PKEY* openssl_key, | 173 EVP_PKEY* openssl_key, |
198 std::string* result) { | 174 std::string* result) { |
199 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 175 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 176 |
| 177 RSA* rsa = EVP_PKEY_get0_RSA(openssl_key); |
| 178 if (!rsa) { |
| 179 LOG(ERROR) << "Could not get RSA from EVP_PKEY"; |
| 180 return false; |
| 181 } |
| 182 |
200 const unsigned char* digest = | 183 const unsigned char* digest = |
201 reinterpret_cast<const unsigned char*>(message.data()); | 184 reinterpret_cast<const unsigned char*>(message.data()); |
202 unsigned int digest_len = static_cast<unsigned int>(message.size()); | 185 unsigned int digest_len = static_cast<unsigned int>(message.size()); |
| 186 |
| 187 // With RSA, the signature will always be RSA_size() bytes. |
| 188 size_t max_signature_size = static_cast<size_t>(RSA_size(rsa)); |
203 std::string signature; | 189 std::string signature; |
204 size_t signature_size; | 190 unsigned char* p = OpenSSLWriteInto(&signature, max_signature_size); |
205 size_t max_signature_size; | 191 unsigned int p_len = 0; |
206 int key_type = EVP_PKEY_id(openssl_key); | 192 if (!RSA_sign(hash_nid, digest, digest_len, p, &p_len, rsa)) { |
207 switch (key_type) { | 193 LOG(ERROR) << "RSA_sign() failed"; |
208 case EVP_PKEY_RSA: { | 194 return false; |
209 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(openssl_key)); | |
210 if (!rsa) { | |
211 LOG(ERROR) << "Could not get RSA from EVP_PKEY"; | |
212 return false; | |
213 } | |
214 // With RSA, the signature will always be RSA_size() bytes. | |
215 max_signature_size = static_cast<size_t>(RSA_size(rsa.get())); | |
216 unsigned char* p = OpenSSLWriteInto(&signature, max_signature_size); | |
217 unsigned int p_len = 0; | |
218 int ret = RSA_sign(hash_nid, digest, digest_len, p, &p_len, rsa.get()); | |
219 if (ret != 1) { | |
220 LOG(ERROR) << "RSA_sign() failed"; | |
221 return false; | |
222 } | |
223 signature_size = static_cast<size_t>(p_len); | |
224 break; | |
225 } | |
226 default: | |
227 LOG(WARNING) << "Invalid OpenSSL key type: " << key_type; | |
228 return false; | |
229 } | 195 } |
230 | 196 |
| 197 size_t signature_size = static_cast<size_t>(p_len); |
231 if (signature_size == 0) { | 198 if (signature_size == 0) { |
232 LOG(ERROR) << "Signature is empty!"; | 199 LOG(ERROR) << "Signature is empty!"; |
233 return false; | 200 return false; |
234 } | 201 } |
235 if (signature_size > max_signature_size) { | 202 if (signature_size > max_signature_size) { |
236 LOG(ERROR) << "Signature size mismatch, actual " << signature_size | 203 LOG(ERROR) << "Signature size mismatch, actual " << signature_size |
237 << ", expected <= " << max_signature_size; | 204 << ", expected <= " << max_signature_size; |
238 return false; | 205 return false; |
239 } | 206 } |
240 signature.resize(signature_size); | 207 signature.resize(signature_size); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 286 |
320 TEST(SSLPlatformKeyAndroid, RSA) { | 287 TEST(SSLPlatformKeyAndroid, RSA) { |
321 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 288 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
322 | 289 |
323 ScopedJava rsa_key = GetRSATestKeyJava(); | 290 ScopedJava rsa_key = GetRSATestKeyJava(); |
324 ASSERT_FALSE(rsa_key.is_null()); | 291 ASSERT_FALSE(rsa_key.is_null()); |
325 | 292 |
326 scoped_refptr<SSLPrivateKey> wrapper_key = WrapJavaPrivateKey(rsa_key); | 293 scoped_refptr<SSLPrivateKey> wrapper_key = WrapJavaPrivateKey(rsa_key); |
327 ASSERT_TRUE(wrapper_key); | 294 ASSERT_TRUE(wrapper_key); |
328 | 295 |
329 crypto::ScopedEVP_PKEY openssl_key(ImportPrivateKeyFile(kTestRsaKeyFile)); | 296 bssl::UniquePtr<EVP_PKEY> openssl_key = ImportPrivateKeyFile(kTestRsaKeyFile); |
330 ASSERT_TRUE(openssl_key); | 297 ASSERT_TRUE(openssl_key); |
331 | 298 |
332 // Check that the wrapper key returns the correct length and type. | 299 // Check that the wrapper key returns the correct length and type. |
333 EXPECT_EQ(SSLPrivateKey::Type::RSA, wrapper_key->GetType()); | 300 EXPECT_EQ(SSLPrivateKey::Type::RSA, wrapper_key->GetType()); |
334 EXPECT_EQ(static_cast<size_t>(EVP_PKEY_size(openssl_key.get())), | 301 EXPECT_EQ(static_cast<size_t>(EVP_PKEY_size(openssl_key.get())), |
335 wrapper_key->GetMaxSignatureLengthInBytes()); | 302 wrapper_key->GetMaxSignatureLengthInBytes()); |
336 | 303 |
337 // Test signing against each hash. | 304 // Test signing against each hash. |
338 for (const auto& hash : kHashes) { | 305 for (const auto& hash : kHashes) { |
339 SCOPED_TRACE(hash.name); | 306 SCOPED_TRACE(hash.name); |
(...skipping 11 matching lines...) Expand all Loading... |
351 | 318 |
352 TEST(SSLPlatformKeyAndroid, ECDSA) { | 319 TEST(SSLPlatformKeyAndroid, ECDSA) { |
353 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 320 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
354 | 321 |
355 ScopedJava ecdsa_key = GetECDSATestKeyJava(); | 322 ScopedJava ecdsa_key = GetECDSATestKeyJava(); |
356 ASSERT_FALSE(ecdsa_key.is_null()); | 323 ASSERT_FALSE(ecdsa_key.is_null()); |
357 | 324 |
358 scoped_refptr<SSLPrivateKey> wrapper_key = WrapJavaPrivateKey(ecdsa_key); | 325 scoped_refptr<SSLPrivateKey> wrapper_key = WrapJavaPrivateKey(ecdsa_key); |
359 ASSERT_TRUE(wrapper_key); | 326 ASSERT_TRUE(wrapper_key); |
360 | 327 |
361 crypto::ScopedEVP_PKEY openssl_key(ImportPrivateKeyFile(kTestEcdsaKeyFile)); | 328 bssl::UniquePtr<EVP_PKEY> openssl_key = |
| 329 ImportPrivateKeyFile(kTestEcdsaKeyFile); |
362 ASSERT_TRUE(openssl_key); | 330 ASSERT_TRUE(openssl_key); |
363 | 331 |
364 // Check that the wrapper key returns the correct length and type. | 332 // Check that the wrapper key returns the correct length and type. |
365 EXPECT_EQ(SSLPrivateKey::Type::ECDSA, wrapper_key->GetType()); | 333 EXPECT_EQ(SSLPrivateKey::Type::ECDSA, wrapper_key->GetType()); |
366 EXPECT_EQ(static_cast<size_t>(EVP_PKEY_size(openssl_key.get())), | 334 EXPECT_EQ(static_cast<size_t>(EVP_PKEY_size(openssl_key.get())), |
367 wrapper_key->GetMaxSignatureLengthInBytes()); | 335 wrapper_key->GetMaxSignatureLengthInBytes()); |
368 | 336 |
369 // Test signing against each hash. | 337 // Test signing against each hash. |
370 for (const auto& hash : kHashes) { | 338 for (const auto& hash : kHashes) { |
371 // ECDSA does not sign MD5-SHA1. | 339 // ECDSA does not sign MD5-SHA1. |
372 if (hash.nid == NID_md5_sha1) | 340 if (hash.nid == NID_md5_sha1) |
373 continue; | 341 continue; |
374 | 342 |
375 SCOPED_TRACE(hash.name); | 343 SCOPED_TRACE(hash.name); |
376 const EVP_MD* md = EVP_get_digestbynid(hash.nid); | 344 const EVP_MD* md = EVP_get_digestbynid(hash.nid); |
377 ASSERT_TRUE(md); | 345 ASSERT_TRUE(md); |
378 std::string digest(EVP_MD_size(md), 'a'); | 346 std::string digest(EVP_MD_size(md), 'a'); |
379 | 347 |
380 std::string signature; | 348 std::string signature; |
381 DoKeySigningWithWrapper(wrapper_key.get(), hash.hash, digest, &signature); | 349 DoKeySigningWithWrapper(wrapper_key.get(), hash.hash, digest, &signature); |
382 ASSERT_TRUE(VerifyTestECDSASignature(digest, signature)); | 350 ASSERT_TRUE(VerifyTestECDSASignature(digest, signature)); |
383 } | 351 } |
384 } | 352 } |
385 | 353 |
386 } // namespace net | 354 } // namespace net |
OLD | NEW |