OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "crypto/ec_signature_creator.h" | 5 #include "crypto/ec_signature_creator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #if !defined(USE_OPENSSL) | |
11 #include <cryptohi.h> | |
12 #include <secerr.h> | |
13 #endif | |
wtc
2012/09/12 19:47:45
The Chromium Coding Style page recommends that the
agl
2012/09/12 21:41:46
(moot)
| |
14 | |
10 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
11 #include "crypto/ec_private_key.h" | 16 #include "crypto/ec_private_key.h" |
12 #include "crypto/signature_verifier.h" | 17 #include "crypto/signature_verifier.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
14 | 19 |
15 #if defined(USE_OPENSSL) | 20 #if defined(USE_OPENSSL) |
16 // Once ECSignatureCreator is implemented for OpenSSL, remove this #if block. | 21 // Once ECSignatureCreator is implemented for OpenSSL, remove this #if block. |
17 // TODO(rch): When that happens, also add some exported keys from each to | 22 // TODO(rch): When that happens, also add some exported keys from each to |
18 // test interop between NSS and OpenSSL. | 23 // test interop between NSS and OpenSSL. |
19 TEST(ECSignatureCreatorTest, OpenSSLStub) { | 24 TEST(ECSignatureCreatorTest, OpenSSLStub) { |
(...skipping 26 matching lines...) Expand all Loading... | |
46 | 51 |
47 std::string data("Hello, World!"); | 52 std::string data("Hello, World!"); |
48 std::vector<uint8> signature; | 53 std::vector<uint8> signature; |
49 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8*>(data.c_str()), | 54 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8*>(data.c_str()), |
50 data.size(), | 55 data.size(), |
51 &signature)); | 56 &signature)); |
52 | 57 |
53 std::vector<uint8> public_key_info; | 58 std::vector<uint8> public_key_info; |
54 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); | 59 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); |
55 | 60 |
56 // This is the algorithm ID for SHA-1 with EC encryption. | 61 // This is the algorithm ID for SHA-256 with EC encryption. |
57 const uint8 kECDSAWithSHA1AlgorithmID[] = { | 62 const uint8 kECDSAWithSHA256AlgorithmID[] = { |
58 0x30, 0x0b, | 63 0x30, 0x0c, |
59 0x06, 0x07, | 64 0x06, 0x08, |
60 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x01, | 65 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, |
61 0x05, 0x00 | 66 0x05, 0x00 |
62 }; | 67 }; |
68 | |
69 // SignatureVerifier expects the signatures to be DER encoded. | |
wtc
2012/09/12 19:47:45
It would be bad if ECSignatureCreator and Signatur
agl
2012/09/12 21:41:46
I've changed the SPDY code to decode the DER signa
| |
70 SECItem der_signature; | |
71 SECItem sig; | |
72 sig.type = siBuffer; | |
73 sig.len = signature.size(); | |
74 sig.data = signature.data(); | |
75 SECStatus rv = DSAU_EncodeDerSigWithLen(&der_signature, &sig, sig.len); | |
76 ASSERT_EQ(SECSuccess, rv); | |
77 | |
63 crypto::SignatureVerifier verifier; | 78 crypto::SignatureVerifier verifier; |
64 ASSERT_TRUE(verifier.VerifyInit( | 79 ASSERT_TRUE(verifier.VerifyInit( |
65 kECDSAWithSHA1AlgorithmID, sizeof(kECDSAWithSHA1AlgorithmID), | 80 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), |
66 &signature.front(), signature.size(), | 81 der_signature.data, der_signature.len, |
67 &public_key_info.front(), public_key_info.size())); | 82 &public_key_info.front(), public_key_info.size())); |
68 | 83 |
84 SECITEM_FreeItem(&der_signature, | |
85 PR_FALSE /* don't free der_signature itself */); | |
86 | |
69 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 87 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
70 data.size()); | 88 data.size()); |
71 ASSERT_TRUE(verifier.VerifyFinal()); | 89 ASSERT_TRUE(verifier.VerifyFinal()); |
72 } | 90 } |
73 #endif // !defined(USE_OPENSSL) | 91 #endif // !defined(USE_OPENSSL) |
OLD | NEW |