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/cert/ct_log_verifier.h" | 5 #include "net/cert/ct_log_verifier.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <nss.h> | 9 #include <nss.h> |
10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 CTLogVerifier::~CTLogVerifier() { | 61 CTLogVerifier::~CTLogVerifier() { |
62 if (public_key_) | 62 if (public_key_) |
63 SECKEY_DestroyPublicKey(public_key_); | 63 SECKEY_DestroyPublicKey(public_key_); |
64 } | 64 } |
65 | 65 |
66 CTLogVerifier::CTLogVerifier() | 66 CTLogVerifier::CTLogVerifier() |
67 : hash_algorithm_(ct::DigitallySigned::HASH_ALGO_NONE), | 67 : hash_algorithm_(ct::DigitallySigned::HASH_ALGO_NONE), |
68 signature_algorithm_(ct::DigitallySigned::SIG_ALGO_ANONYMOUS), | 68 signature_algorithm_(ct::DigitallySigned::SIG_ALGO_ANONYMOUS), |
69 public_key_(NULL) {} | 69 public_key_(NULL) { |
| 70 } |
70 | 71 |
71 bool CTLogVerifier::Init(const base::StringPiece& public_key, | 72 bool CTLogVerifier::Init(const base::StringPiece& public_key, |
72 const base::StringPiece& description) { | 73 const base::StringPiece& description) { |
73 SECItem key_data; | 74 SECItem key_data; |
74 | 75 |
75 crypto::EnsureNSSInit(); | 76 crypto::EnsureNSSInit(); |
76 | 77 |
77 key_data.data = reinterpret_cast<unsigned char*>( | 78 key_data.data = |
78 const_cast<char*>(public_key.data())); | 79 reinterpret_cast<unsigned char*>(const_cast<char*>(public_key.data())); |
79 key_data.len = public_key.size(); | 80 key_data.len = public_key.size(); |
80 | 81 |
81 CERTSubjectPublicKeyInfo* public_key_info = | 82 CERTSubjectPublicKeyInfo* public_key_info = |
82 SECKEY_DecodeDERSubjectPublicKeyInfo(&key_data); | 83 SECKEY_DecodeDERSubjectPublicKeyInfo(&key_data); |
83 if (!public_key_info) { | 84 if (!public_key_info) { |
84 DVLOG(1) << "Failed decoding public key."; | 85 DVLOG(1) << "Failed decoding public key."; |
85 return false; | 86 return false; |
86 } | 87 } |
87 | 88 |
88 public_key_ = SECKEY_ExtractPublicKey(public_key_info); | 89 public_key_ = SECKEY_ExtractPublicKey(public_key_info); |
(...skipping 30 matching lines...) Expand all Loading... |
119 DVLOG(1) << "Too small a public key."; | 120 DVLOG(1) << "Too small a public key."; |
120 return false; | 121 return false; |
121 } | 122 } |
122 | 123 |
123 return true; | 124 return true; |
124 } | 125 } |
125 | 126 |
126 bool CTLogVerifier::VerifySignature(const base::StringPiece& data_to_sign, | 127 bool CTLogVerifier::VerifySignature(const base::StringPiece& data_to_sign, |
127 const base::StringPiece& signature) { | 128 const base::StringPiece& signature) { |
128 SECItem sig_data; | 129 SECItem sig_data; |
129 sig_data.data = reinterpret_cast<unsigned char*>(const_cast<char*>( | 130 sig_data.data = |
130 signature.data())); | 131 reinterpret_cast<unsigned char*>(const_cast<char*>(signature.data())); |
131 sig_data.len = signature.size(); | 132 sig_data.len = signature.size(); |
132 | 133 |
133 SECStatus rv = VFY_VerifyDataDirect( | 134 SECStatus rv = VFY_VerifyDataDirect( |
134 reinterpret_cast<const unsigned char*>(data_to_sign.data()), | 135 reinterpret_cast<const unsigned char*>(data_to_sign.data()), |
135 data_to_sign.size(), public_key_, &sig_data, | 136 data_to_sign.size(), |
136 GetNSSSigAlg(signature_algorithm_), GetNSSHashAlg(hash_algorithm_), | 137 public_key_, |
137 NULL, NULL); | 138 &sig_data, |
| 139 GetNSSSigAlg(signature_algorithm_), |
| 140 GetNSSHashAlg(hash_algorithm_), |
| 141 NULL, |
| 142 NULL); |
138 DVLOG(1) << "Signature verification result: " << (rv == SECSuccess); | 143 DVLOG(1) << "Signature verification result: " << (rv == SECSuccess); |
139 return rv == SECSuccess; | 144 return rv == SECSuccess; |
140 } | 145 } |
141 | 146 |
142 } // namespace net | 147 } // namespace net |
OLD | NEW |