| 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 "components/variations/variations_seed_store.h" | 5 #include "components/variations/variations_seed_store.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // Signature verification is disabled on mobile platforms for now, since it | 32 // Signature verification is disabled on mobile platforms for now, since it |
| 33 // adds about ~15ms to the startup time on mobile (vs. a couple ms on desktop). | 33 // adds about ~15ms to the startup time on mobile (vs. a couple ms on desktop). |
| 34 bool SignatureVerificationEnabled() { | 34 bool SignatureVerificationEnabled() { |
| 35 #if defined(OS_IOS) || defined(OS_ANDROID) | 35 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 36 return false; | 36 return false; |
| 37 #else | 37 #else |
| 38 return true; | 38 return true; |
| 39 #endif | 39 #endif |
| 40 } | 40 } |
| 41 | 41 |
| 42 // This is the algorithm ID for ECDSA with SHA-256. Parameters are ABSENT. | |
| 43 // RFC 5758: | |
| 44 // ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) | |
| 45 // us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 2 } | |
| 46 // ... | |
| 47 // When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or | |
| 48 // ecdsa-with-SHA512 algorithm identifier appears in the algorithm field | |
| 49 // as an AlgorithmIdentifier, the encoding MUST omit the parameters | |
| 50 // field. That is, the AlgorithmIdentifier SHALL be a SEQUENCE of one | |
| 51 // component, the OID ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with- | |
| 52 // SHA384, or ecdsa-with-SHA512. | |
| 53 // See also RFC 5480, Appendix A. | |
| 54 const uint8_t kECDSAWithSHA256AlgorithmID[] = { | |
| 55 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, | |
| 56 }; | |
| 57 | |
| 58 // The ECDSA public key of the variations server for verifying variations seed | 42 // The ECDSA public key of the variations server for verifying variations seed |
| 59 // signatures. | 43 // signatures. |
| 60 const uint8_t kPublicKey[] = { | 44 const uint8_t kPublicKey[] = { |
| 61 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, | 45 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, |
| 62 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, | 46 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, |
| 63 0x04, 0x51, 0x7c, 0x31, 0x4b, 0x50, 0x42, 0xdd, 0x59, 0xda, 0x0b, 0xfa, 0x43, | 47 0x04, 0x51, 0x7c, 0x31, 0x4b, 0x50, 0x42, 0xdd, 0x59, 0xda, 0x0b, 0xfa, 0x43, |
| 64 0x44, 0x33, 0x7c, 0x5f, 0xa1, 0x0b, 0xd5, 0x82, 0xf6, 0xac, 0x04, 0x19, 0x72, | 48 0x44, 0x33, 0x7c, 0x5f, 0xa1, 0x0b, 0xd5, 0x82, 0xf6, 0xac, 0x04, 0x19, 0x72, |
| 65 0x6c, 0x40, 0xd4, 0x3e, 0x56, 0xe2, 0xa0, 0x80, 0xa0, 0x41, 0xb3, 0x23, 0x7b, | 49 0x6c, 0x40, 0xd4, 0x3e, 0x56, 0xe2, 0xa0, 0x80, 0xa0, 0x41, 0xb3, 0x23, 0x7b, |
| 66 0x71, 0xc9, 0x80, 0x87, 0xde, 0x35, 0x0d, 0x25, 0x71, 0x09, 0x7f, 0xb4, 0x15, | 50 0x71, 0xc9, 0x80, 0x87, 0xde, 0x35, 0x0d, 0x25, 0x71, 0x09, 0x7f, 0xb4, 0x15, |
| 67 0x2b, 0xff, 0x82, 0x4d, 0xd3, 0xfe, 0xc5, 0xef, 0x20, 0xc6, 0xa3, 0x10, 0xbf, | 51 0x2b, 0xff, 0x82, 0x4d, 0xd3, 0xfe, 0xc5, 0xef, 0x20, 0xc6, 0xa3, 0x10, 0xbf, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 return VARIATIONS_SEED_SIGNATURE_ENUM_SIZE; | 318 return VARIATIONS_SEED_SIGNATURE_ENUM_SIZE; |
| 335 | 319 |
| 336 if (base64_seed_signature.empty()) | 320 if (base64_seed_signature.empty()) |
| 337 return VARIATIONS_SEED_SIGNATURE_MISSING; | 321 return VARIATIONS_SEED_SIGNATURE_MISSING; |
| 338 | 322 |
| 339 std::string signature; | 323 std::string signature; |
| 340 if (!base::Base64Decode(base64_seed_signature, &signature)) | 324 if (!base::Base64Decode(base64_seed_signature, &signature)) |
| 341 return VARIATIONS_SEED_SIGNATURE_DECODE_FAILED; | 325 return VARIATIONS_SEED_SIGNATURE_DECODE_FAILED; |
| 342 | 326 |
| 343 crypto::SignatureVerifier verifier; | 327 crypto::SignatureVerifier verifier; |
| 344 if (!verifier.VerifyInit( | 328 if (!verifier.VerifyInit(crypto::SignatureVerifier::ECDSA_SHA256, |
| 345 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), | 329 reinterpret_cast<const uint8_t*>(signature.data()), |
| 346 reinterpret_cast<const uint8_t*>(signature.data()), signature.size(), | 330 signature.size(), kPublicKey, |
| 347 kPublicKey, arraysize(kPublicKey))) { | 331 arraysize(kPublicKey))) { |
| 348 return VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE; | 332 return VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE; |
| 349 } | 333 } |
| 350 | 334 |
| 351 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(seed_bytes.data()), | 335 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(seed_bytes.data()), |
| 352 seed_bytes.size()); | 336 seed_bytes.size()); |
| 353 if (verifier.VerifyFinal()) | 337 if (verifier.VerifyFinal()) |
| 354 return VARIATIONS_SEED_SIGNATURE_VALID; | 338 return VARIATIONS_SEED_SIGNATURE_VALID; |
| 355 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 339 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
| 356 } | 340 } |
| 357 | 341 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 528 } |
| 545 return true; | 529 return true; |
| 546 } | 530 } |
| 547 | 531 |
| 548 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { | 532 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { |
| 549 RecordSeedStoreHistogram( | 533 RecordSeedStoreHistogram( |
| 550 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); | 534 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); |
| 551 } | 535 } |
| 552 | 536 |
| 553 } // namespace variations | 537 } // namespace variations |
| OLD | NEW |