OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/dnssec_keyset.h" | 5 #include "net/base/dnssec_keyset.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <cryptoht.h> | 8 #include <cryptoht.h> |
9 #include <keyhi.h> | 9 #include <keyhi.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "crypto/nss_util.h" | 14 #include "crypto/nss_util.h" |
15 #include "net/base/dns_util.h" | 15 #include "net/base/dns_util.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // These are encoded AlgorithmIdentifiers for the given signature algorithm. | 19 // These are encoded AlgorithmIdentifiers for the given signature algorithm |
| 20 // from RFC 4055. |
| 21 |
| 22 // 1.2.840.113549.1.1.5 |
20 const unsigned char kRSAWithSHA1[] = { | 23 const unsigned char kRSAWithSHA1[] = { |
21 0x30, 0xd, 0x6, 0x9, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0xd, 0x1, 0x1, 0x5, 5, 0 | 24 0x30, 0xd, 0x6, 0x9, 0x2a, 0x86, 0x48, 0x86, |
| 25 0xf7, 0xd, 0x1, 0x1, 0x5, 0x5, 0x0, |
22 }; | 26 }; |
23 | 27 |
| 28 // 1.2.840.113549.1.1.11 |
24 const unsigned char kRSAWithSHA256[] = { | 29 const unsigned char kRSAWithSHA256[] = { |
25 0x30, 0xd, 0x6, 0x9, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0xd, 0x1, 0x1, 0xb, 5, 0 | 30 0x30, 0xd, 0x6, 0x9, 0x2a, 0x86, 0x48, 0x86, |
| 31 0xf7, 0xd, 0x1, 0x1, 0xb, 0x5, 0x0, |
| 32 }; |
| 33 |
| 34 // 1.2.840.113549.1.1.13 |
| 35 const unsigned char kRSAWithSHA512[] = { |
| 36 0x30, 0xd, 0x6, 0x9, 0x2a, 0x86, 0x48, 0x86, |
| 37 0xf7, 0xd, 0x1, 0x1, 0xd, 0x5, 0x0, |
26 }; | 38 }; |
27 | 39 |
28 } // namespace | 40 } // namespace |
29 | 41 |
30 namespace net { | 42 namespace net { |
31 | 43 |
32 DNSSECKeySet::DNSSECKeySet() | 44 DNSSECKeySet::DNSSECKeySet() |
33 : ignore_timestamps_(false) { | 45 : ignore_timestamps_(false) { |
34 } | 46 } |
35 | 47 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 base::StringPiece signature_algorithm; | 148 base::StringPiece signature_algorithm; |
137 if (algorithm == kDNSSEC_RSA_SHA1 || | 149 if (algorithm == kDNSSEC_RSA_SHA1 || |
138 algorithm == kDNSSEC_RSA_SHA1_NSEC3) { | 150 algorithm == kDNSSEC_RSA_SHA1_NSEC3) { |
139 signature_algorithm = base::StringPiece( | 151 signature_algorithm = base::StringPiece( |
140 reinterpret_cast<const char*>(kRSAWithSHA1), | 152 reinterpret_cast<const char*>(kRSAWithSHA1), |
141 sizeof(kRSAWithSHA1)); | 153 sizeof(kRSAWithSHA1)); |
142 } else if (algorithm == kDNSSEC_RSA_SHA256) { | 154 } else if (algorithm == kDNSSEC_RSA_SHA256) { |
143 signature_algorithm = base::StringPiece( | 155 signature_algorithm = base::StringPiece( |
144 reinterpret_cast<const char*>(kRSAWithSHA256), | 156 reinterpret_cast<const char*>(kRSAWithSHA256), |
145 sizeof(kRSAWithSHA256)); | 157 sizeof(kRSAWithSHA256)); |
| 158 } else if (algorithm == kDNSSEC_RSA_SHA512) { |
| 159 signature_algorithm = base::StringPiece( |
| 160 reinterpret_cast<const char*>(kRSAWithSHA512), |
| 161 sizeof(kRSAWithSHA512)); |
146 } else { | 162 } else { |
147 // Unknown algorithm. | 163 // Unknown algorithm. |
148 return false; | 164 return false; |
149 } | 165 } |
150 | 166 |
151 // Check the signature with each trusted key which has a matching keyid. | 167 // Check the signature with each trusted key which has a matching keyid. |
152 DCHECK_EQ(public_keys_.size(), keyids_.size()); | 168 DCHECK_EQ(public_keys_.size(), keyids_.size()); |
153 for (unsigned i = 0; i < public_keys_.size(); i++) { | 169 for (unsigned i = 0; i < public_keys_.size(); i++) { |
154 if (keyids_[i] != keyid) | 170 if (keyids_[i] != keyid) |
155 continue; | 171 continue; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // subjectPublicKey BIT STRING } | 339 // subjectPublicKey BIT STRING } |
324 std::string DNSSECKeySet::ASN1WrapDNSKEY(const base::StringPiece& dnskey) { | 340 std::string DNSSECKeySet::ASN1WrapDNSKEY(const base::StringPiece& dnskey) { |
325 const unsigned char* data = | 341 const unsigned char* data = |
326 reinterpret_cast<const unsigned char*>(dnskey.data()); | 342 reinterpret_cast<const unsigned char*>(dnskey.data()); |
327 | 343 |
328 if (dnskey.size() < 5 || dnskey.size() > 32767) | 344 if (dnskey.size() < 5 || dnskey.size() > 32767) |
329 return ""; | 345 return ""; |
330 const uint8 algorithm = data[3]; | 346 const uint8 algorithm = data[3]; |
331 if (algorithm != kDNSSEC_RSA_SHA1 && | 347 if (algorithm != kDNSSEC_RSA_SHA1 && |
332 algorithm != kDNSSEC_RSA_SHA1_NSEC3 && | 348 algorithm != kDNSSEC_RSA_SHA1_NSEC3 && |
333 algorithm != kDNSSEC_RSA_SHA256) { | 349 algorithm != kDNSSEC_RSA_SHA256 && |
| 350 algorithm != kDNSSEC_RSA_SHA512) { |
334 return ""; | 351 return ""; |
335 } | 352 } |
336 | 353 |
337 unsigned exp_length; | 354 unsigned exp_length; |
338 unsigned exp_offset; | 355 unsigned exp_offset; |
339 // First we extract the public exponent. | 356 // First we extract the public exponent. |
340 if (data[4] == 0) { | 357 if (data[4] == 0) { |
341 if (dnskey.size() < 7) | 358 if (dnskey.size() < 7) |
342 return ""; | 359 return ""; |
343 exp_length = static_cast<unsigned>(data[5]) << 8 | | 360 exp_length = static_cast<unsigned>(data[5]) << 8 | |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 out[j++] = exp >> (8 * i); | 469 out[j++] = exp >> (8 * i); |
453 length--; | 470 length--; |
454 } | 471 } |
455 | 472 |
456 DCHECK_EQ(0u, length); | 473 DCHECK_EQ(0u, length); |
457 | 474 |
458 return std::string(reinterpret_cast<char*>(out.get()), j); | 475 return std::string(reinterpret_cast<char*>(out.get()), j); |
459 } | 476 } |
460 | 477 |
461 } // namespace net | 478 } // namespace net |
OLD | NEW |