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

Unified Diff: net/quic/test_tools/crypto_test_utils_nss.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
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/crypto_test_utils_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/crypto_test_utils_nss.cc
===================================================================
--- net/quic/test_tools/crypto_test_utils_nss.cc (revision 271770)
+++ net/quic/test_tools/crypto_test_utils_nss.cc (working copy)
@@ -20,31 +20,16 @@
namespace test {
-// TODO(rtenneti): Implement NSS support ChannelIDSigner. Convert Sign() to be
-// asynchronous using completion callback. After porting TestChannelIDSigner,
-// implement real ChannelIDSigner.
-class TestChannelIDSigner : public ChannelIDSigner {
+class TestChannelIDKey : public ChannelIDKey {
public:
- virtual ~TestChannelIDSigner() {
- STLDeleteValues(&hostname_to_key_);
- }
+ explicit TestChannelIDKey(crypto::ECPrivateKey* ec_private_key)
+ : ec_private_key_(ec_private_key) {}
+ virtual ~TestChannelIDKey() {}
- // ChannelIDSigner implementation.
+ // ChannelIDKey implementation.
- virtual bool Sign(const string& hostname,
- StringPiece signed_data,
- string* out_key,
+ virtual bool Sign(StringPiece signed_data,
string* out_signature) OVERRIDE {
- crypto::ECPrivateKey* ecdsa_keypair = HostnameToKey(hostname);
- if (!ecdsa_keypair) {
- return false;
- }
-
- *out_key = SerializeKey(ecdsa_keypair->public_key());
- if (out_key->empty()) {
- return false;
- }
-
unsigned char hash_buf[SHA256_LENGTH];
SECItem hash_item = { siBuffer, hash_buf, sizeof(hash_buf) };
@@ -77,22 +62,50 @@
kSignatureLength
};
- if (PK11_Sign(ecdsa_keypair->key(), &sig_item, &hash_item) != SECSuccess) {
+ if (PK11_Sign(ec_private_key_->key(), &sig_item,
+ &hash_item) != SECSuccess) {
return false;
}
*out_signature = signature;
return true;
}
- virtual string GetKeyForHostname(const string& hostname) OVERRIDE {
- crypto::ECPrivateKey* ecdsa_keypair = HostnameToKey(hostname);
- if (!ecdsa_keypair) {
+ virtual string SerializeKey() OVERRIDE {
+ const SECKEYPublicKey* public_key = ec_private_key_->public_key();
+ // public_key->u.ec.publicValue is 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 unsigned int kExpectedKeyLength = 65;
+
+ const unsigned char* const data = public_key->u.ec.publicValue.data;
+ const unsigned int len = public_key->u.ec.publicValue.len;
+ if (len != kExpectedKeyLength || data[0] != 0x04) {
return "";
}
- return SerializeKey(ecdsa_keypair->public_key());
+
+ string key(reinterpret_cast<const char*>(data + 1), kExpectedKeyLength - 1);
+ return key;
}
private:
+ crypto::ECPrivateKey* ec_private_key_;
wtc 2014/05/28 22:02:01 Note that the destructor of this class does not de
+};
+
+class TestChannelIDSource : public ChannelIDSource {
+ public:
+ virtual ~TestChannelIDSource() {
+ STLDeleteValues(&hostname_to_key_);
+ }
+
+ // 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:
typedef std::map<string, crypto::ECPrivateKey*> HostnameToKeyMap;
crypto::ECPrivateKey* HostnameToKey(const string& hostname) {
@@ -109,28 +122,12 @@
return keypair;
}
- static string SerializeKey(const SECKEYPublicKey* public_key) {
- // public_key->u.ec.publicValue is 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 unsigned int kExpectedKeyLength = 65;
-
- const unsigned char* const data = public_key->u.ec.publicValue.data;
- const unsigned int len = public_key->u.ec.publicValue.len;
- if (len != kExpectedKeyLength || data[0] != 0x04) {
- return "";
- }
-
- string key(reinterpret_cast<const char*>(data + 1), kExpectedKeyLength - 1);
- return key;
- }
-
HostnameToKeyMap hostname_to_key_;
};
// static
-ChannelIDSigner* CryptoTestUtils::ChannelIDSignerForTesting() {
- return new TestChannelIDSigner();
+ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() {
+ return new TestChannelIDSource();
}
} // namespace test
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/crypto_test_utils_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698