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

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

Issue 413523003: [webcrypto] Properly fail-fast when importing RSA key as JWK with bad usages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert patchset 5; won't generalize well for DH keys 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/child/webcrypto/openssl/rsa_key_openssl.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/generate_key_result.h"
10 #include "content/child/webcrypto/jwk.h" 10 #include "content/child/webcrypto/jwk.h"
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 605
606 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( 606 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(
607 blink::WebCryptoKeyFormat format, 607 blink::WebCryptoKeyFormat format,
608 blink::WebCryptoKeyUsageMask usages) const { 608 blink::WebCryptoKeyUsageMask usages) const {
609 switch (format) { 609 switch (format) {
610 case blink::WebCryptoKeyFormatSpki: 610 case blink::WebCryptoKeyFormatSpki:
611 return CheckKeyCreationUsages(all_public_key_usages_, usages); 611 return CheckKeyCreationUsages(all_public_key_usages_, usages);
612 case blink::WebCryptoKeyFormatPkcs8: 612 case blink::WebCryptoKeyFormatPkcs8:
613 return CheckKeyCreationUsages(all_private_key_usages_, usages); 613 return CheckKeyCreationUsages(all_private_key_usages_, usages);
614 case blink::WebCryptoKeyFormatJwk: 614 case blink::WebCryptoKeyFormatJwk:
615 return CheckKeyCreationUsages( 615 // The JWK could represent either a public key or private key. The usages
616 all_public_key_usages_ | all_private_key_usages_, usages); 616 // must make sense for one of the two. The usages will be checked again by
617 // ImportKeyJwk() once the key type has been determined.
618 if (CheckKeyCreationUsages(all_private_key_usages_, usages)
619 .IsSuccess() ||
620 CheckKeyCreationUsages(all_public_key_usages_, usages)
621 .IsSuccess()) {
622 return Status::Success();
623 }
624 return Status::ErrorCreateKeyBadUsages();
617 default: 625 default:
618 return Status::ErrorUnsupportedImportKeyFormat(); 626 return Status::ErrorUnsupportedImportKeyFormat();
619 } 627 }
620 } 628 }
621 629
622 Status RsaHashedAlgorithm::ImportKeyPkcs8( 630 Status RsaHashedAlgorithm::ImportKeyPkcs8(
623 const CryptoData& key_data, 631 const CryptoData& key_data,
624 const blink::WebCryptoAlgorithm& algorithm, 632 const blink::WebCryptoAlgorithm& algorithm,
625 bool extractable, 633 bool extractable,
626 blink::WebCryptoKeyUsageMask usages, 634 blink::WebCryptoKeyUsageMask usages,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 return Status::Success(); 843 return Status::Success();
836 } 844 }
837 default: 845 default:
838 return Status::ErrorUnexpected(); 846 return Status::ErrorUnexpected();
839 } 847 }
840 } 848 }
841 849
842 } // namespace webcrypto 850 } // namespace webcrypto
843 851
844 } // namespace content 852 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/openssl/rsa_key_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698