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

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

Issue 777403004: [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 <cryptohi.h> 5 #include <cryptohi.h>
6 #include <pk11pub.h> 6 #include <pk11pub.h>
7 #include <secerr.h> 7 #include <secerr.h>
8 #include <sechash.h> 8 #include <sechash.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 class HmacImplementation : public AlgorithmImplementation { 54 class HmacImplementation : public AlgorithmImplementation {
55 public: 55 public:
56 HmacImplementation() {} 56 HmacImplementation() {}
57 57
58 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 58 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
59 bool extractable, 59 bool extractable,
60 blink::WebCryptoKeyUsageMask usages, 60 blink::WebCryptoKeyUsageMask usages,
61 GenerateKeyResult* result) const override { 61 GenerateKeyResult* result) const override {
62 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages); 62 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages, false);
eroman 2014/12/09 21:04:46 Same here.
Habib Virji 2014/12/15 18:48:55 Done.
63 if (status.IsError()) 63 if (status.IsError())
64 return status; 64 return status;
65 65
66 const blink::WebCryptoHmacKeyGenParams* params = 66 const blink::WebCryptoHmacKeyGenParams* params =
67 algorithm.hmacKeyGenParams(); 67 algorithm.hmacKeyGenParams();
68 68
69 const blink::WebCryptoAlgorithm& hash = params->hash(); 69 const blink::WebCryptoAlgorithm& hash = params->hash();
70 CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM; 70 CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM;
71 if (!WebCryptoHashToHMACMechanism(hash, &mechanism)) 71 if (!WebCryptoHashToHMACMechanism(hash, &mechanism))
72 return Status::ErrorUnsupported(); 72 return Status::ErrorUnsupported();
73 73
74 unsigned int keylen_bits = 0; 74 unsigned int keylen_bits = 0;
75 status = GetHmacKeyGenLengthInBits(params, &keylen_bits); 75 status = GetHmacKeyGenLengthInBits(params, &keylen_bits);
76 if (status.IsError()) 76 if (status.IsError())
77 return status; 77 return status;
78 78
79 return GenerateSecretKeyNss( 79 return GenerateSecretKeyNss(
80 blink::WebCryptoKeyAlgorithm::createHmac(hash.id(), keylen_bits), 80 blink::WebCryptoKeyAlgorithm::createHmac(hash.id(), keylen_bits),
81 extractable, usages, keylen_bits / 8, mechanism, result); 81 extractable, usages, keylen_bits / 8, mechanism, result);
82 } 82 }
83 83
84 Status VerifyKeyUsagesBeforeImportKey( 84 Status VerifyKeyUsagesBeforeImportKey(
85 blink::WebCryptoKeyFormat format, 85 blink::WebCryptoKeyFormat format,
86 blink::WebCryptoKeyUsageMask usages) const override { 86 blink::WebCryptoKeyUsageMask usages) const override {
87 switch (format) { 87 switch (format) {
88 case blink::WebCryptoKeyFormatRaw: 88 case blink::WebCryptoKeyFormatRaw:
89 case blink::WebCryptoKeyFormatJwk: 89 case blink::WebCryptoKeyFormatJwk:
90 return CheckKeyCreationUsages(kAllKeyUsages, usages); 90 return CheckKeyCreationUsages(kAllKeyUsages, usages, true);
91 default: 91 default:
92 return Status::ErrorUnsupportedImportKeyFormat(); 92 return Status::ErrorUnsupportedImportKeyFormat();
93 } 93 }
94 } 94 }
95 95
96 Status ImportKeyRaw(const CryptoData& key_data, 96 Status ImportKeyRaw(const CryptoData& key_data,
97 const blink::WebCryptoAlgorithm& algorithm, 97 const blink::WebCryptoAlgorithm& algorithm,
98 bool extractable, 98 bool extractable,
99 blink::WebCryptoKeyUsageMask usages, 99 blink::WebCryptoKeyUsageMask usages,
100 blink::WebCryptoKey* key) const override { 100 blink::WebCryptoKey* key) const override {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 } // namespace 237 } // namespace
238 238
239 AlgorithmImplementation* CreatePlatformHmacImplementation() { 239 AlgorithmImplementation* CreatePlatformHmacImplementation() {
240 return new HmacImplementation; 240 return new HmacImplementation;
241 } 241 }
242 242
243 } // namespace webcrypto 243 } // namespace webcrypto
244 244
245 } // namespace content 245 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698