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

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

Issue 745443002: Check that usage isn't empty when generateKey() is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more tests Created 6 years, 1 month 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
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 <secasn1.h> 7 #include <secasn1.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/child/webcrypto/crypto_data.h" 10 #include "content/child/webcrypto/crypto_data.h"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 bool extractable, 513 bool extractable,
514 blink::WebCryptoKeyUsageMask combined_usages, 514 blink::WebCryptoKeyUsageMask combined_usages,
515 GenerateKeyResult* result) const { 515 GenerateKeyResult* result) const {
516 Status status = CheckKeyCreationUsages( 516 Status status = CheckKeyCreationUsages(
517 all_public_key_usages_ | all_private_key_usages_, combined_usages); 517 all_public_key_usages_ | all_private_key_usages_, combined_usages);
518 if (status.IsError()) 518 if (status.IsError())
519 return status; 519 return status;
520 520
521 const blink::WebCryptoKeyUsageMask public_usages = 521 const blink::WebCryptoKeyUsageMask public_usages =
522 combined_usages & all_public_key_usages_; 522 combined_usages & all_public_key_usages_;
523 const blink::WebCryptoKeyUsageMask private_usages = 523 const blink::WebCryptoKeyUsageMask private_usages =
eroman 2014/11/20 23:40:09 Move the check up to here.
nharper 2014/11/21 22:12:01 Done.
524 combined_usages & all_private_key_usages_; 524 combined_usages & all_private_key_usages_;
525 525
526 unsigned int public_exponent = 0; 526 unsigned int public_exponent = 0;
527 unsigned int modulus_length_bits = 0; 527 unsigned int modulus_length_bits = 0;
528 status = GetRsaKeyGenParameters(algorithm.rsaHashedKeyGenParams(), 528 status = GetRsaKeyGenParameters(algorithm.rsaHashedKeyGenParams(),
529 &public_exponent, 529 &public_exponent,
530 &modulus_length_bits); 530 &modulus_length_bits);
531 if (status.IsError()) 531 if (status.IsError())
532 return status; 532 return status;
533 533
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 public_usages); 595 public_usages);
596 596
597 blink::WebCryptoKey private_key = 597 blink::WebCryptoKey private_key =
598 blink::WebCryptoKey::create(private_key_handle.release(), 598 blink::WebCryptoKey::create(private_key_handle.release(),
599 blink::WebCryptoKeyTypePrivate, 599 blink::WebCryptoKeyTypePrivate,
600 extractable, 600 extractable,
601 key_algorithm, 601 key_algorithm,
602 private_usages); 602 private_usages);
603 603
604 result->AssignKeyPair(public_key, private_key); 604 result->AssignKeyPair(public_key, private_key);
605 if (result->private_key().usages() == 0) {
eroman 2014/11/20 23:40:09 Move the failure to before the key has been genera
nharper 2014/11/21 22:12:01 Done.
606 return Status::ErrorCreateKeyBadUsages();
607 }
605 return Status::Success(); 608 return Status::Success();
606 } 609 }
607 610
608 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( 611 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(
609 blink::WebCryptoKeyFormat format, 612 blink::WebCryptoKeyFormat format,
610 blink::WebCryptoKeyUsageMask usages) const { 613 blink::WebCryptoKeyUsageMask usages) const {
611 switch (format) { 614 switch (format) {
612 case blink::WebCryptoKeyFormatSpki: 615 case blink::WebCryptoKeyFormatSpki:
613 return CheckKeyCreationUsages(all_public_key_usages_, usages); 616 return CheckKeyCreationUsages(all_public_key_usages_, usages);
614 case blink::WebCryptoKeyFormatPkcs8: 617 case blink::WebCryptoKeyFormatPkcs8:
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 key->algorithm().rsaHashedParams()->publicExponent().size())) { 921 key->algorithm().rsaHashedParams()->publicExponent().size())) {
919 return Status::ErrorUnexpected(); 922 return Status::ErrorUnexpected();
920 } 923 }
921 924
922 return Status::Success(); 925 return Status::Success();
923 } 926 }
924 927
925 } // namespace webcrypto 928 } // namespace webcrypto
926 929
927 } // namespace content 930 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/nss/sym_key_nss.cc » ('j') | content/child/webcrypto/nss/sym_key_nss.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698