Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: content/child/webcrypto/nss/rsa_key_nss.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/child/webcrypto/nss/rsa_key_nss.h ('k') | content/child/webcrypto/nss/rsa_oaep_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 blink::WebCryptoKey public_key =
595 blink::WebCryptoKeyTypePublic, 589 blink::WebCryptoKey::create(public_key_handle.release(),
596 true, 590 blink::WebCryptoKeyTypePublic,
597 key_algorithm, 591 true,
598 public_usage_mask); 592 key_algorithm,
599 *private_key = blink::WebCryptoKey::create(private_key_handle.release(), 593 public_usage_mask);
600 blink::WebCryptoKeyTypePrivate,
601 extractable,
602 key_algorithm,
603 private_usage_mask);
604 594
595 blink::WebCryptoKey private_key =
596 blink::WebCryptoKey::create(private_key_handle.release(),
597 blink::WebCryptoKeyTypePrivate,
598 extractable,
599 key_algorithm,
600 private_usage_mask);
601
602 result->AssignKeyPair(public_key, private_key);
605 return Status::Success(); 603 return Status::Success();
606 } 604 }
607 605
608 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( 606 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(
609 blink::WebCryptoKeyFormat format, 607 blink::WebCryptoKeyFormat format,
610 blink::WebCryptoKeyUsageMask usage_mask) const { 608 blink::WebCryptoKeyUsageMask usage_mask) const {
611 switch (format) { 609 switch (format) {
612 case blink::WebCryptoKeyFormatSpki: 610 case blink::WebCryptoKeyFormatSpki:
613 return CheckKeyCreationUsages(all_public_key_usages_, usage_mask); 611 return CheckKeyCreationUsages(all_public_key_usages_, usage_mask);
614 case blink::WebCryptoKeyFormatPkcs8: 612 case blink::WebCryptoKeyFormatPkcs8:
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 return Status::Success(); 835 return Status::Success();
838 } 836 }
839 default: 837 default:
840 return Status::ErrorUnexpected(); 838 return Status::ErrorUnexpected();
841 } 839 }
842 } 840 }
843 841
844 } // namespace webcrypto 842 } // namespace webcrypto
845 843
846 } // namespace content 844 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/nss/rsa_key_nss.h ('k') | content/child/webcrypto/nss/rsa_oaep_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698