Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Unified Diff: net/quic/test_tools/crypto_test_utils_openssl.cc

Issue 303933002: WTC: Started port of patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/quic/test_tools/crypto_test_utils_openssl.cc
===================================================================
--- net/quic/test_tools/crypto_test_utils_openssl.cc (revision 271770)
+++ net/quic/test_tools/crypto_test_utils_openssl.cc (working copy)
@@ -30,31 +30,22 @@
namespace test {
-class TestChannelIDSigner : public ChannelIDSigner {
+class TestChannelIDKey : public ChannelIDKey {
public:
- virtual ~TestChannelIDSigner() { }
+ explicit TestChannelIDKey(EVP_PKEY* ecdsa_key) : ecdsa_key_(ecdsa_key) {}
+ virtual ~TestChannelIDKey() { }
- // ChannelIDSigner implementation.
+ // ChannelIDKey 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;
- }
-
+ 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,13 +85,42 @@
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:
static EVP_PKEY* HostnameToKey(const string& hostname) {
// In order to generate a deterministic key for a given hostname the
// hostname is hashed with SHA-256 and the resulting digest is treated as a
@@ -143,29 +163,11 @@
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

Powered by Google App Engine
This is Rietveld 408576698