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

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

Issue 346323002: net: Implement ChannelIDSourceChromium, which is based on Chromium's (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Rebase Created 6 years, 6 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_chromium.cc ('k') | no next file » | 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 280648)
+++ net/quic/test_tools/crypto_test_utils_nss.cc (working copy)
@@ -4,14 +4,12 @@
#include "net/quic/test_tools/crypto_test_utils.h"
-#include <keyhi.h>
-#include <pk11pub.h>
-#include <sechash.h>
-
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "crypto/ec_private_key.h"
+#include "crypto/ec_signature_creator.h"
#include "net/quic/crypto/channel_id.h"
+#include "net/quic/crypto/channel_id_chromium.h"
using base::StringPiece;
using std::string;
@@ -20,79 +18,6 @@
namespace test {
-// TODO(rtenneti): Convert Sign() to be asynchronous using a completion
-// callback.
-class TestChannelIDKey : public ChannelIDKey {
- public:
- explicit TestChannelIDKey(crypto::ECPrivateKey* ecdsa_keypair)
- : ecdsa_keypair_(ecdsa_keypair) {}
- virtual ~TestChannelIDKey() {}
-
- // ChannelIDKey implementation.
-
- virtual bool Sign(StringPiece signed_data,
- string* out_signature) const OVERRIDE {
- unsigned char hash_buf[SHA256_LENGTH];
- SECItem hash_item = { siBuffer, hash_buf, sizeof(hash_buf) };
-
- HASHContext* sha256 = HASH_Create(HASH_AlgSHA256);
- if (!sha256) {
- return false;
- }
- HASH_Begin(sha256);
- HASH_Update(sha256,
- reinterpret_cast<const unsigned char*>(
- ChannelIDVerifier::kContextStr),
- strlen(ChannelIDVerifier::kContextStr) + 1);
- HASH_Update(sha256,
- reinterpret_cast<const unsigned char*>(
- ChannelIDVerifier::kClientToServerStr),
- strlen(ChannelIDVerifier::kClientToServerStr) + 1);
- HASH_Update(sha256,
- reinterpret_cast<const unsigned char*>(signed_data.data()),
- signed_data.size());
- HASH_End(sha256, hash_buf, &hash_item.len, sizeof(hash_buf));
- HASH_Destroy(sha256);
-
- // The signature consists of a pair of 32-byte numbers.
- static const unsigned int kSignatureLength = 32 * 2;
- string signature;
- SECItem sig_item = {
- siBuffer,
- reinterpret_cast<unsigned char*>(
- WriteInto(&signature, kSignatureLength + 1)),
- kSignatureLength
- };
-
- if (PK11_Sign(ecdsa_keypair_->key(), &sig_item, &hash_item) != SECSuccess) {
- return false;
- }
- *out_signature = signature;
- return true;
- }
-
- virtual string SerializeKey() const OVERRIDE {
- const SECKEYPublicKey* public_key = ecdsa_keypair_->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;
- }
-
- private:
- crypto::ECPrivateKey* ecdsa_keypair_;
-};
-
class TestChannelIDSource : public ChannelIDSource {
public:
virtual ~TestChannelIDSource() {
@@ -105,7 +30,7 @@
const string& hostname,
scoped_ptr<ChannelIDKey>* channel_id_key,
ChannelIDSourceCallback* /*callback*/) OVERRIDE {
- channel_id_key->reset(new TestChannelIDKey(HostnameToKey(hostname)));
+ channel_id_key->reset(new ChannelIDKeyChromium(HostnameToKey(hostname)));
return QUIC_SUCCESS;
}
@@ -115,7 +40,7 @@
crypto::ECPrivateKey* HostnameToKey(const string& hostname) {
HostnameToKeyMap::const_iterator it = hostname_to_key_.find(hostname);
if (it != hostname_to_key_.end()) {
- return it->second;
+ return it->second->Copy();
}
crypto::ECPrivateKey* keypair = crypto::ECPrivateKey::Create();
@@ -123,7 +48,7 @@
return NULL;
}
hostname_to_key_[hostname] = keypair;
- return keypair;
+ return keypair->Copy();
}
HostnameToKeyMap hostname_to_key_;
« no previous file with comments | « net/quic/test_tools/crypto_test_utils_chromium.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698