Chromium Code Reviews| Index: net/quic/test_tools/crypto_test_utils_openssl.cc |
| diff --git a/net/quic/test_tools/crypto_test_utils_openssl.cc b/net/quic/test_tools/crypto_test_utils_openssl.cc |
| index bb08a044aa45f082d986c18172b508282a5b2727..b56fa044f0f29d4e884ee72f0b6df1edae45c841 100644 |
| --- a/net/quic/test_tools/crypto_test_utils_openssl.cc |
| +++ b/net/quic/test_tools/crypto_test_utils_openssl.cc |
| @@ -30,31 +30,22 @@ namespace net { |
| namespace test { |
| -class TestChannelIDSigner : public ChannelIDSigner { |
| +class TestChannelIDKey : public ChannelIDKey { |
|
wtc
2014/05/28 22:04:29
net/quic/test_tools/crypto_test_utils_nss.cc also
|
| public: |
| - virtual ~TestChannelIDSigner() { } |
| + explicit TestChannelIDKey(EVP_PKEY* ecdsa_key) : ecdsa_key_(ecdsa_key) {} |
| + virtual ~TestChannelIDKey() { } |
| - // ChannelIDSigner implementation. |
| - |
| - virtual bool Sign(const string& hostname, |
| - StringPiece signed_data, |
| - string* out_key, |
| - string* out_signature) OVERRIDE { |
| - crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> ecdsa_key( |
| - HostnameToKey(hostname)); |
| - |
| - *out_key = SerializeKey(ecdsa_key.get()); |
| - if (out_key->empty()) { |
| - return false; |
| - } |
| + // ChannelIDKey implementation. |
| + virtual bool Sign(StringPiece signed_data, |
| + string* out_signature) override { |
| EVP_MD_CTX md_ctx; |
| EVP_MD_CTX_init(&md_ctx); |
| crypto::ScopedOpenSSL<EVP_MD_CTX, EvpMdCtxCleanUp> |
| md_ctx_cleanup(&md_ctx); |
| if (EVP_DigestSignInit(&md_ctx, NULL, EVP_sha256(), NULL, |
| - ecdsa_key.get()) != 1) { |
| + ecdsa_key_.get()) != 1) { |
| return false; |
| } |
| @@ -94,10 +85,39 @@ class TestChannelIDSigner : public ChannelIDSigner { |
| return true; |
| } |
| - virtual string GetKeyForHostname(const string& hostname) OVERRIDE { |
| - crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> ecdsa_key( |
| - HostnameToKey(hostname)); |
| - return SerializeKey(ecdsa_key.get()); |
| + virtual string SerializeKey() override { |
| + // i2d_PublicKey will produce an ANSI X9.62 public key which, for a P-256 |
| + // key, is 0x04 (meaning uncompressed) followed by the x and y field |
| + // elements as 32-byte, big-endian numbers. |
| + static const int kExpectedKeyLength = 65; |
| + |
| + int len = i2d_PublicKey(ecdsa_key_.get(), NULL); |
| + if (len != kExpectedKeyLength) { |
| + return ""; |
| + } |
| + |
| + uint8 buf[kExpectedKeyLength]; |
| + uint8* derp = buf; |
| + i2d_PublicKey(ecdsa_key_.get(), &derp); |
| + |
| + return string(reinterpret_cast<char*>(buf + 1), kExpectedKeyLength - 1); |
| + } |
| + |
| + private: |
| + crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> ecdsa_key_; |
| +}; |
| + |
| +class TestChannelIDSource : public ChannelIDSource { |
| + public: |
| + virtual ~TestChannelIDSource() {} |
| + |
| + // ChannelIDSource implementation. |
| + |
| + virtual bool GetChannelIDKey( |
| + const string& hostname, |
| + scoped_ptr<ChannelIDKey>* channel_id_key) override { |
| + channel_id_key->reset(new TestChannelIDKey(HostnameToKey(hostname))); |
| + return true; |
| } |
| private: |
| @@ -143,29 +163,11 @@ class TestChannelIDSigner : public ChannelIDSigner { |
| return pkey.release(); |
| } |
| - |
| - static string SerializeKey(EVP_PKEY* key) { |
| - // i2d_PublicKey will produce an ANSI X9.62 public key which, for a P-256 |
| - // key, is 0x04 (meaning uncompressed) followed by the x and y field |
| - // elements as 32-byte, big-endian numbers. |
| - static const int kExpectedKeyLength = 65; |
| - |
| - int len = i2d_PublicKey(key, NULL); |
| - if (len != kExpectedKeyLength) { |
| - return ""; |
| - } |
| - |
| - uint8 buf[kExpectedKeyLength]; |
| - uint8* derp = buf; |
| - i2d_PublicKey(key, &derp); |
| - |
| - return string(reinterpret_cast<char*>(buf + 1), kExpectedKeyLength - 1); |
| - } |
| }; |
| // static |
| -ChannelIDSigner* CryptoTestUtils::ChannelIDSignerForTesting() { |
| - return new TestChannelIDSigner(); |
| +ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() { |
| + return new TestChannelIDSource(); |
| } |
| } // namespace test |