| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/base/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
| 6 | 6 |
| 7 #include <openssl/bytestring.h> | 7 #include <openssl/bytestring.h> |
| 8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/base64.h" | 14 #include "base/base64.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/threading/worker_pool.h" | 21 #include "base/threading/worker_pool.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "crypto/scoped_openssl_types.h" | |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 24 |
| 26 #if defined(USE_NSS_CERTS) | 25 #if defined(USE_NSS_CERTS) |
| 27 #include <private/pprthred.h> // PR_DetachThread | 26 #include <private/pprthred.h> // PR_DetachThread |
| 28 #include "crypto/nss_crypto_module_delegate.h" | 27 #include "crypto/nss_crypto_module_delegate.h" |
| 29 #include "crypto/scoped_test_nss_db.h" | 28 #include "crypto/scoped_test_nss_db.h" |
| 30 #endif | 29 #endif |
| 31 | 30 |
| 32 namespace net { | 31 namespace net { |
| 33 | 32 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 CBS public_key_and_challenge_raw; | 115 CBS public_key_and_challenge_raw; |
| 117 ASSERT_TRUE(CBS_get_asn1_element(&child, &public_key_and_challenge_raw, | 116 ASSERT_TRUE(CBS_get_asn1_element(&child, &public_key_and_challenge_raw, |
| 118 CBS_ASN1_SEQUENCE)); | 117 CBS_ASN1_SEQUENCE)); |
| 119 | 118 |
| 120 // Parse out the PublicKeyAndChallenge. | 119 // Parse out the PublicKeyAndChallenge. |
| 121 CBS copy = public_key_and_challenge_raw; | 120 CBS copy = public_key_and_challenge_raw; |
| 122 CBS public_key_and_challenge; | 121 CBS public_key_and_challenge; |
| 123 ASSERT_TRUE( | 122 ASSERT_TRUE( |
| 124 CBS_get_asn1(©, &public_key_and_challenge, CBS_ASN1_SEQUENCE)); | 123 CBS_get_asn1(©, &public_key_and_challenge, CBS_ASN1_SEQUENCE)); |
| 125 ASSERT_EQ(0u, CBS_len(©)); | 124 ASSERT_EQ(0u, CBS_len(©)); |
| 126 crypto::ScopedEVP_PKEY key(EVP_parse_public_key(&public_key_and_challenge)); | 125 bssl::UniquePtr<EVP_PKEY> key( |
| 126 EVP_parse_public_key(&public_key_and_challenge)); |
| 127 ASSERT_TRUE(key); | 127 ASSERT_TRUE(key); |
| 128 CBS challenge_spkac; | 128 CBS challenge_spkac; |
| 129 ASSERT_TRUE(CBS_get_asn1(&public_key_and_challenge, &challenge_spkac, | 129 ASSERT_TRUE(CBS_get_asn1(&public_key_and_challenge, &challenge_spkac, |
| 130 CBS_ASN1_IA5STRING)); | 130 CBS_ASN1_IA5STRING)); |
| 131 ASSERT_EQ(0u, CBS_len(&public_key_and_challenge)); | 131 ASSERT_EQ(0u, CBS_len(&public_key_and_challenge)); |
| 132 | 132 |
| 133 // The challenge must match. | 133 // The challenge must match. |
| 134 ASSERT_EQ(challenge, StringPieceFromCBS(challenge_spkac)); | 134 ASSERT_EQ(challenge, StringPieceFromCBS(challenge_spkac)); |
| 135 | 135 |
| 136 // The next element must be the AlgorithmIdentifier for MD5 with RSA. | 136 // The next element must be the AlgorithmIdentifier for MD5 with RSA. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 | 147 |
| 148 // Finally, parse the signature. | 148 // Finally, parse the signature. |
| 149 CBS signature; | 149 CBS signature; |
| 150 ASSERT_TRUE(CBS_get_asn1(&child, &signature, CBS_ASN1_BITSTRING)); | 150 ASSERT_TRUE(CBS_get_asn1(&child, &signature, CBS_ASN1_BITSTRING)); |
| 151 ASSERT_EQ(0u, CBS_len(&child)); | 151 ASSERT_EQ(0u, CBS_len(&child)); |
| 152 uint8_t pad; | 152 uint8_t pad; |
| 153 ASSERT_TRUE(CBS_get_u8(&signature, &pad)); | 153 ASSERT_TRUE(CBS_get_u8(&signature, &pad)); |
| 154 ASSERT_EQ(0u, pad); | 154 ASSERT_EQ(0u, pad); |
| 155 | 155 |
| 156 // Check the signature. | 156 // Check the signature. |
| 157 crypto::ScopedEVP_MD_CTX ctx(EVP_MD_CTX_create()); | 157 bssl::ScopedEVP_MD_CTX ctx; |
| 158 ASSERT_TRUE( | 158 ASSERT_TRUE( |
| 159 EVP_DigestVerifyInit(ctx.get(), nullptr, EVP_md5(), nullptr, key.get())); | 159 EVP_DigestVerifyInit(ctx.get(), nullptr, EVP_md5(), nullptr, key.get())); |
| 160 ASSERT_TRUE(EVP_DigestVerifyUpdate(ctx.get(), | 160 ASSERT_TRUE(EVP_DigestVerifyUpdate(ctx.get(), |
| 161 CBS_data(&public_key_and_challenge_raw), | 161 CBS_data(&public_key_and_challenge_raw), |
| 162 CBS_len(&public_key_and_challenge_raw))); | 162 CBS_len(&public_key_and_challenge_raw))); |
| 163 ASSERT_TRUE(EVP_DigestVerifyFinal(ctx.get(), CBS_data(&signature), | 163 ASSERT_TRUE(EVP_DigestVerifyFinal(ctx.get(), CBS_data(&signature), |
| 164 CBS_len(&signature))); | 164 CBS_len(&signature))); |
| 165 } | 165 } |
| 166 | 166 |
| 167 TEST_F(KeygenHandlerTest, SmokeTest) { | 167 TEST_F(KeygenHandlerTest, SmokeTest) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 events[i] = NULL; | 221 events[i] = NULL; |
| 222 | 222 |
| 223 VLOG(1) << "KeygenHandler " << i << " produced: " << results[i]; | 223 VLOG(1) << "KeygenHandler " << i << " produced: " << results[i]; |
| 224 AssertValidSignedPublicKeyAndChallenge(results[i], "some challenge"); | 224 AssertValidSignedPublicKeyAndChallenge(results[i], "some challenge"); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace | 228 } // namespace |
| 229 | 229 |
| 230 } // namespace net | 230 } // namespace net |
| OLD | NEW |