| 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 "content/child/webcrypto/nss/rsa_key_nss.h" | 5 #include "content/child/webcrypto/nss/rsa_key_nss.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/generate_key_result.h" |
| 9 #include "content/child/webcrypto/jwk.h" | 10 #include "content/child/webcrypto/jwk.h" |
| 10 #include "content/child/webcrypto/nss/key_nss.h" | 11 #include "content/child/webcrypto/nss/key_nss.h" |
| 11 #include "content/child/webcrypto/nss/util_nss.h" | 12 #include "content/child/webcrypto/nss/util_nss.h" |
| 12 #include "content/child/webcrypto/status.h" | 13 #include "content/child/webcrypto/status.h" |
| 13 #include "content/child/webcrypto/webcrypto_util.h" | 14 #include "content/child/webcrypto/webcrypto_util.h" |
| 14 #include "crypto/scoped_nss_types.h" | 15 #include "crypto/scoped_nss_types.h" |
| 15 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 16 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 17 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 *key = blink::WebCryptoKey::create(key_handle.release(), | 499 *key = blink::WebCryptoKey::create(key_handle.release(), |
| 499 blink::WebCryptoKeyTypePublic, | 500 blink::WebCryptoKeyTypePublic, |
| 500 extractable, | 501 extractable, |
| 501 key_algorithm, | 502 key_algorithm, |
| 502 usage_mask); | 503 usage_mask); |
| 503 return Status::Success(); | 504 return Status::Success(); |
| 504 } | 505 } |
| 505 | 506 |
| 506 } // namespace | 507 } // namespace |
| 507 | 508 |
| 508 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeGenerateKeyPair( | 509 Status RsaHashedAlgorithm::GenerateKey( |
| 510 const blink::WebCryptoAlgorithm& algorithm, |
| 511 bool extractable, |
| 509 blink::WebCryptoKeyUsageMask combined_usage_mask, | 512 blink::WebCryptoKeyUsageMask combined_usage_mask, |
| 510 blink::WebCryptoKeyUsageMask* public_usage_mask, | 513 GenerateKeyResult* result) const { |
| 511 blink::WebCryptoKeyUsageMask* private_usage_mask) const { | |
| 512 Status status = CheckKeyCreationUsages( | 514 Status status = CheckKeyCreationUsages( |
| 513 all_public_key_usages_ | all_private_key_usages_, combined_usage_mask); | 515 all_public_key_usages_ | all_private_key_usages_, combined_usage_mask); |
| 514 if (status.IsError()) | 516 if (status.IsError()) |
| 515 return status; | 517 return status; |
| 516 | 518 |
| 517 *public_usage_mask = combined_usage_mask & all_public_key_usages_; | 519 const blink::WebCryptoKeyUsageMask public_usage_mask = |
| 518 *private_usage_mask = combined_usage_mask & all_private_key_usages_; | 520 combined_usage_mask & all_public_key_usages_; |
| 521 const blink::WebCryptoKeyUsageMask private_usage_mask = |
| 522 combined_usage_mask & all_private_key_usages_; |
| 519 | 523 |
| 520 return Status::Success(); | |
| 521 } | |
| 522 | |
| 523 Status RsaHashedAlgorithm::GenerateKeyPair( | |
| 524 const blink::WebCryptoAlgorithm& algorithm, | |
| 525 bool extractable, | |
| 526 blink::WebCryptoKeyUsageMask public_usage_mask, | |
| 527 blink::WebCryptoKeyUsageMask private_usage_mask, | |
| 528 blink::WebCryptoKey* public_key, | |
| 529 blink::WebCryptoKey* private_key) const { | |
| 530 unsigned int public_exponent = 0; | 524 unsigned int public_exponent = 0; |
| 531 unsigned int modulus_length_bits = 0; | 525 unsigned int modulus_length_bits = 0; |
| 532 Status status = GetRsaKeyGenParameters(algorithm.rsaHashedKeyGenParams(), | 526 status = GetRsaKeyGenParameters(algorithm.rsaHashedKeyGenParams(), |
| 533 &public_exponent, | 527 &public_exponent, |
| 534 &modulus_length_bits); | 528 &modulus_length_bits); |
| 535 if (status.IsError()) | 529 if (status.IsError()) |
| 536 return status; | 530 return status; |
| 537 | 531 |
| 538 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); | 532 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); |
| 539 if (!slot) | 533 if (!slot) |
| 540 return Status::OperationError(); | 534 return Status::OperationError(); |
| 541 | 535 |
| 542 PK11RSAGenParams rsa_gen_params; | 536 PK11RSAGenParams rsa_gen_params; |
| 543 rsa_gen_params.keySizeInBits = modulus_length_bits; | 537 rsa_gen_params.keySizeInBits = modulus_length_bits; |
| 544 rsa_gen_params.pe = public_exponent; | 538 rsa_gen_params.pe = public_exponent; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 crypto::ScopedSECKEYPublicKey(sec_public_key), CryptoData(spki_data))); | 578 crypto::ScopedSECKEYPublicKey(sec_public_key), CryptoData(spki_data))); |
| 585 | 579 |
| 586 std::vector<uint8_t> pkcs8_data; | 580 std::vector<uint8_t> pkcs8_data; |
| 587 status = ExportKeyPkcs8Nss(scoped_sec_private_key.get(), &pkcs8_data); | 581 status = ExportKeyPkcs8Nss(scoped_sec_private_key.get(), &pkcs8_data); |
| 588 if (status.IsError()) | 582 if (status.IsError()) |
| 589 return status; | 583 return status; |
| 590 | 584 |
| 591 scoped_ptr<PrivateKeyNss> private_key_handle( | 585 scoped_ptr<PrivateKeyNss> private_key_handle( |
| 592 new PrivateKeyNss(scoped_sec_private_key.Pass(), CryptoData(pkcs8_data))); | 586 new PrivateKeyNss(scoped_sec_private_key.Pass(), CryptoData(pkcs8_data))); |
| 593 | 587 |
| 594 *public_key = blink::WebCryptoKey::create(public_key_handle.release(), | 588 result->set_type(GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR); |
| 595 blink::WebCryptoKeyTypePublic, | 589 *result->mutable_public_key() = |
| 596 true, | 590 blink::WebCryptoKey::create(public_key_handle.release(), |
| 597 key_algorithm, | 591 blink::WebCryptoKeyTypePublic, |
| 598 public_usage_mask); | 592 true, |
| 599 *private_key = blink::WebCryptoKey::create(private_key_handle.release(), | 593 key_algorithm, |
| 600 blink::WebCryptoKeyTypePrivate, | 594 public_usage_mask); |
| 601 extractable, | 595 *result->mutable_private_key() = |
| 602 key_algorithm, | 596 blink::WebCryptoKey::create(private_key_handle.release(), |
| 603 private_usage_mask); | 597 blink::WebCryptoKeyTypePrivate, |
| 598 extractable, |
| 599 key_algorithm, |
| 600 private_usage_mask); |
| 604 | 601 |
| 605 return Status::Success(); | 602 return Status::Success(); |
| 606 } | 603 } |
| 607 | 604 |
| 608 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( | 605 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( |
| 609 blink::WebCryptoKeyFormat format, | 606 blink::WebCryptoKeyFormat format, |
| 610 blink::WebCryptoKeyUsageMask usage_mask) const { | 607 blink::WebCryptoKeyUsageMask usage_mask) const { |
| 611 switch (format) { | 608 switch (format) { |
| 612 case blink::WebCryptoKeyFormatSpki: | 609 case blink::WebCryptoKeyFormatSpki: |
| 613 return CheckKeyCreationUsages(all_public_key_usages_, usage_mask); | 610 return CheckKeyCreationUsages(all_public_key_usages_, usage_mask); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 return Status::Success(); | 834 return Status::Success(); |
| 838 } | 835 } |
| 839 default: | 836 default: |
| 840 return Status::ErrorUnexpected(); | 837 return Status::ErrorUnexpected(); |
| 841 } | 838 } |
| 842 } | 839 } |
| 843 | 840 |
| 844 } // namespace webcrypto | 841 } // namespace webcrypto |
| 845 | 842 |
| 846 } // namespace content | 843 } // namespace content |
| OLD | NEW |