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

Side by Side Diff: content/child/webcrypto/openssl/hmac_openssl.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: Updated issues in ecdh tests and other review comments. 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 <openssl/hmac.h> 5 #include <openssl/hmac.h>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/child/webcrypto/algorithm_implementation.h" 9 #include "content/child/webcrypto/algorithm_implementation.h"
10 #include "content/child/webcrypto/crypto_data.h" 10 #include "content/child/webcrypto/crypto_data.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 class HmacImplementation : public AlgorithmImplementation { 64 class HmacImplementation : public AlgorithmImplementation {
65 public: 65 public:
66 HmacImplementation() {} 66 HmacImplementation() {}
67 67
68 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 68 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
69 bool extractable, 69 bool extractable,
70 blink::WebCryptoKeyUsageMask usages, 70 blink::WebCryptoKeyUsageMask usages,
71 GenerateKeyResult* result) const override { 71 GenerateKeyResult* result) const override {
72 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages); 72 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages, false);
73 if (status.IsError()) 73 if (status.IsError())
74 return status; 74 return status;
75 75
76 const blink::WebCryptoHmacKeyGenParams* params = 76 const blink::WebCryptoHmacKeyGenParams* params =
77 algorithm.hmacKeyGenParams(); 77 algorithm.hmacKeyGenParams();
78 78
79 unsigned int keylen_bits = 0; 79 unsigned int keylen_bits = 0;
80 status = GetHmacKeyGenLengthInBits(params, &keylen_bits); 80 status = GetHmacKeyGenLengthInBits(params, &keylen_bits);
81 if (status.IsError()) 81 if (status.IsError())
82 return status; 82 return status;
83 83
84 return GenerateSecretKeyOpenSsl(blink::WebCryptoKeyAlgorithm::createHmac( 84 return GenerateSecretKeyOpenSsl(blink::WebCryptoKeyAlgorithm::createHmac(
85 params->hash().id(), keylen_bits), 85 params->hash().id(), keylen_bits),
86 extractable, usages, keylen_bits, result); 86 extractable, usages, keylen_bits, result);
87 } 87 }
88 88
89 Status VerifyKeyUsagesBeforeImportKey( 89 Status VerifyKeyUsagesBeforeImportKey(
90 blink::WebCryptoKeyFormat format, 90 blink::WebCryptoKeyFormat format,
91 blink::WebCryptoKeyUsageMask usages) const override { 91 blink::WebCryptoKeyUsageMask usages) const override {
92 switch (format) { 92 switch (format) {
93 case blink::WebCryptoKeyFormatRaw: 93 case blink::WebCryptoKeyFormatRaw:
94 case blink::WebCryptoKeyFormatJwk: 94 case blink::WebCryptoKeyFormatJwk:
95 return CheckKeyCreationUsages(kAllKeyUsages, usages); 95 return CheckKeyCreationUsages(kAllKeyUsages, usages, false);
96 default: 96 default:
97 return Status::ErrorUnsupportedImportKeyFormat(); 97 return Status::ErrorUnsupportedImportKeyFormat();
98 } 98 }
99 } 99 }
100 100
101 Status ImportKeyRaw(const CryptoData& key_data, 101 Status ImportKeyRaw(const CryptoData& key_data,
102 const blink::WebCryptoAlgorithm& algorithm, 102 const blink::WebCryptoAlgorithm& algorithm,
103 bool extractable, 103 bool extractable,
104 blink::WebCryptoKeyUsageMask usages, 104 blink::WebCryptoKeyUsageMask usages,
105 blink::WebCryptoKey* key) const override { 105 blink::WebCryptoKey* key) const override {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 } // namespace 235 } // namespace
236 236
237 AlgorithmImplementation* CreatePlatformHmacImplementation() { 237 AlgorithmImplementation* CreatePlatformHmacImplementation() {
238 return new HmacImplementation; 238 return new HmacImplementation;
239 } 239 }
240 240
241 } // namespace webcrypto 241 } // namespace webcrypto
242 242
243 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698