OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromium.h" | 5 #include "net/quic/crypto/channel_id_chromium.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/macros.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "crypto/ec_private_key.h" | 12 #include "crypto/ec_private_key.h" |
12 #include "crypto/ec_signature_creator.h" | 13 #include "crypto/ec_signature_creator.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 #include "net/cert/asn1_util.h" | 15 #include "net/cert/asn1_util.h" |
15 #include "net/ssl/channel_id_service.h" | 16 #include "net/ssl/channel_id_service.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 ChannelIDKeyChromium::ChannelIDKeyChromium( | 20 ChannelIDKeyChromium::ChannelIDKeyChromium( |
20 scoped_ptr<crypto::ECPrivateKey> ec_private_key) | 21 scoped_ptr<crypto::ECPrivateKey> ec_private_key) |
21 : ec_private_key_(std::move(ec_private_key)) {} | 22 : ec_private_key_(std::move(ec_private_key)) {} |
22 | 23 |
23 ChannelIDKeyChromium::~ChannelIDKeyChromium() {} | 24 ChannelIDKeyChromium::~ChannelIDKeyChromium() {} |
24 | 25 |
25 bool ChannelIDKeyChromium::Sign(base::StringPiece signed_data, | 26 bool ChannelIDKeyChromium::Sign(base::StringPiece signed_data, |
26 std::string* out_signature) const { | 27 std::string* out_signature) const { |
27 scoped_ptr<crypto::ECSignatureCreator> sig_creator( | 28 scoped_ptr<crypto::ECSignatureCreator> sig_creator( |
28 crypto::ECSignatureCreator::Create(ec_private_key_.get())); | 29 crypto::ECSignatureCreator::Create(ec_private_key_.get())); |
29 if (!sig_creator) { | 30 if (!sig_creator) { |
30 return false; | 31 return false; |
31 } | 32 } |
32 const size_t len1 = strlen(ChannelIDVerifier::kContextStr) + 1; | 33 const size_t len1 = strlen(ChannelIDVerifier::kContextStr) + 1; |
33 const size_t len2 = strlen(ChannelIDVerifier::kClientToServerStr) + 1; | 34 const size_t len2 = strlen(ChannelIDVerifier::kClientToServerStr) + 1; |
34 std::vector<uint8> data(len1 + len2 + signed_data.size()); | 35 std::vector<uint8_t> data(len1 + len2 + signed_data.size()); |
35 memcpy(&data[0], ChannelIDVerifier::kContextStr, len1); | 36 memcpy(&data[0], ChannelIDVerifier::kContextStr, len1); |
36 memcpy(&data[len1], ChannelIDVerifier::kClientToServerStr, len2); | 37 memcpy(&data[len1], ChannelIDVerifier::kClientToServerStr, len2); |
37 memcpy(&data[len1 + len2], signed_data.data(), signed_data.size()); | 38 memcpy(&data[len1 + len2], signed_data.data(), signed_data.size()); |
38 std::vector<uint8> der_signature; | 39 std::vector<uint8_t> der_signature; |
39 if (!sig_creator->Sign(&data[0], data.size(), &der_signature)) { | 40 if (!sig_creator->Sign(&data[0], data.size(), &der_signature)) { |
40 return false; | 41 return false; |
41 } | 42 } |
42 std::vector<uint8> raw_signature; | 43 std::vector<uint8_t> raw_signature; |
43 if (!sig_creator->DecodeSignature(der_signature, &raw_signature)) { | 44 if (!sig_creator->DecodeSignature(der_signature, &raw_signature)) { |
44 return false; | 45 return false; |
45 } | 46 } |
46 memcpy(base::WriteInto(out_signature, raw_signature.size() + 1), | 47 memcpy(base::WriteInto(out_signature, raw_signature.size() + 1), |
47 &raw_signature[0], raw_signature.size()); | 48 &raw_signature[0], raw_signature.size()); |
48 return true; | 49 return true; |
49 } | 50 } |
50 | 51 |
51 std::string ChannelIDKeyChromium::SerializeKey() const { | 52 std::string ChannelIDKeyChromium::SerializeKey() const { |
52 std::string out_key; | 53 std::string out_key; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 220 } |
220 return status; | 221 return status; |
221 } | 222 } |
222 | 223 |
223 void ChannelIDSourceChromium::OnJobComplete(Job* job) { | 224 void ChannelIDSourceChromium::OnJobComplete(Job* job) { |
224 active_jobs_.erase(job); | 225 active_jobs_.erase(job); |
225 delete job; | 226 delete job; |
226 } | 227 } |
227 | 228 |
228 } // namespace net | 229 } // namespace net |
OLD | NEW |