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

Side by Side Diff: net/quic/crypto/channel_id_openssl.cc

Issue 16638016: Implement ChannelIDVerifier using NSS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Disable QuicCryptoServerStreamTest.ChannelID. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/quic/crypto/channel_id.h" 5 #include "net/quic/crypto/channel_id.h"
6 6
7 #include <openssl/bn.h> 7 #include <openssl/bn.h>
8 #include <openssl/ec.h> 8 #include <openssl/ec.h>
9 #include <openssl/ecdsa.h> 9 #include <openssl/ecdsa.h>
10 #include <openssl/obj_mac.h> 10 #include <openssl/obj_mac.h>
11 #include <openssl/sha.h> 11 #include <openssl/sha.h>
12 12
13 #include "crypto/openssl_util.h" 13 #include "crypto/openssl_util.h"
14 14
15 using base::StringPiece; 15 using base::StringPiece;
16 16
17 namespace net { 17 namespace net {
18 18
19 // static 19 // static
20 bool ChannelIDVerifier::Verify(StringPiece key, 20 bool ChannelIDVerifier::Verify(StringPiece key,
21 StringPiece signed_data, 21 StringPiece signed_data,
22 StringPiece signature) { 22 StringPiece signature) {
23 return VerifyRaw(key, signed_data, signature, true);
24 }
25
26 // static
27 bool ChannelIDVerifier::VerifyRaw(StringPiece key,
28 StringPiece signed_data,
29 StringPiece signature,
30 bool is_channel_id_signature) {
23 if (key.size() != 32 * 2 || 31 if (key.size() != 32 * 2 ||
24 signature.size() != 32 * 2) { 32 signature.size() != 32 * 2) {
25 return false; 33 return false;
26 } 34 }
27 35
28 crypto::ScopedOpenSSL<EC_GROUP, EC_GROUP_free> p256( 36 crypto::ScopedOpenSSL<EC_GROUP, EC_GROUP_free> p256(
29 EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)); 37 EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
30 if (p256.get() == NULL) { 38 if (p256.get() == NULL) {
31 return false; 39 return false;
32 } 40 }
(...skipping 25 matching lines...) Expand all
58 66
59 crypto::ScopedOpenSSL<EC_KEY, EC_KEY_free> ecdsa_key(EC_KEY_new()); 67 crypto::ScopedOpenSSL<EC_KEY, EC_KEY_free> ecdsa_key(EC_KEY_new());
60 if (ecdsa_key.get() == NULL || 68 if (ecdsa_key.get() == NULL ||
61 !EC_KEY_set_group(ecdsa_key.get(), p256.get()) || 69 !EC_KEY_set_group(ecdsa_key.get(), p256.get()) ||
62 !EC_KEY_set_public_key(ecdsa_key.get(), point.get())) { 70 !EC_KEY_set_public_key(ecdsa_key.get(), point.get())) {
63 return false; 71 return false;
64 } 72 }
65 73
66 SHA256_CTX sha256; 74 SHA256_CTX sha256;
67 SHA256_Init(&sha256); 75 SHA256_Init(&sha256);
68 SHA256_Update(&sha256, ChannelIDVerifier::kContextStr, 76 if (is_channel_id_signature) {
69 strlen(ChannelIDVerifier::kContextStr) + 1); 77 SHA256_Update(&sha256, kContextStr, strlen(kContextStr) + 1);
70 SHA256_Update(&sha256, ChannelIDVerifier::kClientToServerStr, 78 SHA256_Update(&sha256, kClientToServerStr, strlen(kClientToServerStr) + 1);
71 strlen(ChannelIDVerifier::kClientToServerStr) + 1); 79 }
72 SHA256_Update(&sha256, signed_data.data(), signed_data.size()); 80 SHA256_Update(&sha256, signed_data.data(), signed_data.size());
73 81
74 unsigned char digest[SHA256_DIGEST_LENGTH]; 82 unsigned char digest[SHA256_DIGEST_LENGTH];
75 SHA256_Final(digest, &sha256); 83 SHA256_Final(digest, &sha256);
76 84
77 return ECDSA_do_verify(digest, sizeof(digest), &sig, ecdsa_key.get()) == 1; 85 return ECDSA_do_verify(digest, sizeof(digest), &sig, ecdsa_key.get()) == 1;
78 } 86 }
79 87
80 } // namespace net 88 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698