OLD | NEW |
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/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.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/evp.h> | 10 #include <openssl/evp.h> |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 class TestChannelIDKey : public ChannelIDKey { | 26 class TestChannelIDKey : public ChannelIDKey { |
27 public: | 27 public: |
28 explicit TestChannelIDKey(EVP_PKEY* ecdsa_key) : ecdsa_key_(ecdsa_key) {} | 28 explicit TestChannelIDKey(EVP_PKEY* ecdsa_key) : ecdsa_key_(ecdsa_key) {} |
29 virtual ~TestChannelIDKey() OVERRIDE {} | 29 virtual ~TestChannelIDKey() OVERRIDE {} |
30 | 30 |
31 // ChannelIDKey implementation. | 31 // ChannelIDKey implementation. |
32 | 32 |
33 virtual bool Sign(StringPiece signed_data, | 33 virtual bool Sign(StringPiece signed_data, |
34 string* out_signature) const OVERRIDE { | 34 string* out_signature) const OVERRIDE { |
35 EVP_MD_CTX md_ctx; | 35 crypto::ScopedEVP_MD_CTX md_ctx(EVP_MD_CTX_create()); |
36 EVP_MD_CTX_init(&md_ctx); | 36 if (!md_ctx || |
37 crypto::ScopedEVP_MD_CTX md_ctx_cleanup(&md_ctx); | 37 EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, |
38 | |
39 if (EVP_DigestSignInit(&md_ctx, NULL, EVP_sha256(), NULL, | |
40 ecdsa_key_.get()) != 1) { | 38 ecdsa_key_.get()) != 1) { |
41 return false; | 39 return false; |
42 } | 40 } |
43 | 41 |
44 EVP_DigestUpdate(&md_ctx, ChannelIDVerifier::kContextStr, | 42 EVP_DigestUpdate(md_ctx.get(), ChannelIDVerifier::kContextStr, |
45 strlen(ChannelIDVerifier::kContextStr) + 1); | 43 strlen(ChannelIDVerifier::kContextStr) + 1); |
46 EVP_DigestUpdate(&md_ctx, ChannelIDVerifier::kClientToServerStr, | 44 EVP_DigestUpdate(md_ctx.get(), ChannelIDVerifier::kClientToServerStr, |
47 strlen(ChannelIDVerifier::kClientToServerStr) + 1); | 45 strlen(ChannelIDVerifier::kClientToServerStr) + 1); |
48 EVP_DigestUpdate(&md_ctx, signed_data.data(), signed_data.size()); | 46 EVP_DigestUpdate(md_ctx.get(), signed_data.data(), signed_data.size()); |
49 | 47 |
50 size_t sig_len; | 48 size_t sig_len; |
51 if (!EVP_DigestSignFinal(&md_ctx, NULL, &sig_len)) { | 49 if (!EVP_DigestSignFinal(md_ctx.get(), NULL, &sig_len)) { |
52 return false; | 50 return false; |
53 } | 51 } |
54 | 52 |
55 scoped_ptr<uint8[]> der_sig(new uint8[sig_len]); | 53 scoped_ptr<uint8[]> der_sig(new uint8[sig_len]); |
56 if (!EVP_DigestSignFinal(&md_ctx, der_sig.get(), &sig_len)) { | 54 if (!EVP_DigestSignFinal(md_ctx.get(), der_sig.get(), &sig_len)) { |
57 return false; | 55 return false; |
58 } | 56 } |
59 | 57 |
60 uint8* derp = der_sig.get(); | 58 uint8* derp = der_sig.get(); |
61 crypto::ScopedECDSA_SIG sig( | 59 crypto::ScopedECDSA_SIG sig( |
62 d2i_ECDSA_SIG(NULL, const_cast<const uint8**>(&derp), sig_len)); | 60 d2i_ECDSA_SIG(NULL, const_cast<const uint8**>(&derp), sig_len)); |
63 if (sig.get() == NULL) { | 61 if (sig.get() == NULL) { |
64 return false; | 62 return false; |
65 } | 63 } |
66 | 64 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 }; | 157 }; |
160 | 158 |
161 // static | 159 // static |
162 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() { | 160 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() { |
163 return new TestChannelIDSource(); | 161 return new TestChannelIDSource(); |
164 } | 162 } |
165 | 163 |
166 } // namespace test | 164 } // namespace test |
167 | 165 |
168 } // namespace net | 166 } // namespace net |
OLD | NEW |