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

Side by Side Diff: content/child/webcrypto/nss/aes_key_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: Support for throwing error if usage is empty in HMAC and AES 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
« no previous file with comments | « no previous file | content/child/webcrypto/nss/hmac_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/aes_key_nss.h" 5 #include "content/child/webcrypto/nss/aes_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/jwk.h" 9 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/nss/key_nss.h" 10 #include "content/child/webcrypto/nss/key_nss.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return CheckKeyCreationUsages(all_key_usages_, usages); 65 return CheckKeyCreationUsages(all_key_usages_, usages);
66 default: 66 default:
67 return Status::ErrorUnsupportedImportKeyFormat(); 67 return Status::ErrorUnsupportedImportKeyFormat();
68 } 68 }
69 } 69 }
70 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data, 70 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data,
71 const blink::WebCryptoAlgorithm& algorithm, 71 const blink::WebCryptoAlgorithm& algorithm,
72 bool extractable, 72 bool extractable,
73 blink::WebCryptoKeyUsageMask usages, 73 blink::WebCryptoKeyUsageMask usages,
74 blink::WebCryptoKey* key) const { 74 blink::WebCryptoKey* key) const {
75 if (usages == 0)
76 return Status::ErrorImportKeyEmptyUsages();
eroman 2014/12/08 18:46:32 Move this into VerifyKeyUsagesBeforeImportKey() si
77
75 const unsigned int keylen_bytes = key_data.byte_length(); 78 const unsigned int keylen_bytes = key_data.byte_length();
76 Status status = VerifyAesKeyLengthForImport(keylen_bytes); 79 Status status = VerifyAesKeyLengthForImport(keylen_bytes);
77 if (status.IsError()) 80 if (status.IsError())
78 return status; 81 return status;
79 82
80 // No possibility of overflow. 83 // No possibility of overflow.
81 unsigned int keylen_bits = keylen_bytes * 8; 84 unsigned int keylen_bits = keylen_bytes * 8;
82 85
83 return ImportKeyRawNss( 86 return ImportKeyRawNss(
84 key_data, 87 key_data,
85 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), 88 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
86 extractable, usages, import_mechanism_, import_flags_, key); 89 extractable, usages, import_mechanism_, import_flags_, key);
87 } 90 }
88 91
89 Status AesAlgorithm::ImportKeyJwk(const CryptoData& key_data, 92 Status AesAlgorithm::ImportKeyJwk(const CryptoData& key_data,
90 const blink::WebCryptoAlgorithm& algorithm, 93 const blink::WebCryptoAlgorithm& algorithm,
91 bool extractable, 94 bool extractable,
92 blink::WebCryptoKeyUsageMask usages, 95 blink::WebCryptoKeyUsageMask usages,
93 blink::WebCryptoKey* key) const { 96 blink::WebCryptoKey* key) const {
97 if (usages == 0)
98 return Status::ErrorImportKeyEmptyUsages();
99
94 std::vector<uint8_t> raw_data; 100 std::vector<uint8_t> raw_data;
95 Status status = ReadAesSecretKeyJwk(key_data, jwk_suffix_, extractable, 101 Status status = ReadAesSecretKeyJwk(key_data, jwk_suffix_, extractable,
96 usages, &raw_data); 102 usages, &raw_data);
97 if (status.IsError()) 103 if (status.IsError())
98 return status; 104 return status;
99 105
100 return ImportKeyRaw(CryptoData(raw_data), algorithm, extractable, usages, 106 return ImportKeyRaw(CryptoData(raw_data), algorithm, extractable, usages,
101 key); 107 key);
102 } 108 }
103 109
(...skipping 29 matching lines...) Expand all
133 blink::WebCryptoKeyUsageMask usages, 139 blink::WebCryptoKeyUsageMask usages,
134 const CryptoData& key_data, 140 const CryptoData& key_data,
135 blink::WebCryptoKey* key) const { 141 blink::WebCryptoKey* key) const {
136 return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable, 142 return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable,
137 usages, key); 143 usages, key);
138 } 144 }
139 145
140 } // namespace webcrypto 146 } // namespace webcrypto
141 147
142 } // namespace content 148 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/nss/hmac_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698