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

Side by Side Diff: content/child/webcrypto/openssl/rsa_key_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: 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 "content/child/webcrypto/openssl/rsa_key_openssl.h" 5 #include "content/child/webcrypto/openssl/rsa_key_openssl.h"
6 6
7 #include <openssl/evp.h> 7 #include <openssl/evp.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 } // namespace 153 } // namespace
154 154
155 Status RsaHashedAlgorithm::GenerateKey( 155 Status RsaHashedAlgorithm::GenerateKey(
156 const blink::WebCryptoAlgorithm& algorithm, 156 const blink::WebCryptoAlgorithm& algorithm,
157 bool extractable, 157 bool extractable,
158 blink::WebCryptoKeyUsageMask combined_usages, 158 blink::WebCryptoKeyUsageMask combined_usages,
159 GenerateKeyResult* result) const { 159 GenerateKeyResult* result) const {
160 Status status = CheckKeyCreationUsages( 160 Status status = CheckKeyCreationUsages(
161 all_public_key_usages_ | all_private_key_usages_, combined_usages); 161 all_public_key_usages_ | all_private_key_usages_, combined_usages, false);
162 if (status.IsError()) 162 if (status.IsError())
163 return status; 163 return status;
164 164
165 const blink::WebCryptoKeyUsageMask public_usages = 165 const blink::WebCryptoKeyUsageMask public_usages =
166 combined_usages & all_public_key_usages_; 166 combined_usages & all_public_key_usages_;
167 const blink::WebCryptoKeyUsageMask private_usages = 167 const blink::WebCryptoKeyUsageMask private_usages =
168 combined_usages & all_private_key_usages_; 168 combined_usages & all_private_key_usages_;
169 169
170 if (private_usages == 0) 170 if (private_usages == 0)
171 return Status::ErrorCreateKeyEmptyUsages(); 171 return Status::ErrorCreateKeyEmptyUsages();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 229
230 result->AssignKeyPair(public_key, private_key); 230 result->AssignKeyPair(public_key, private_key);
231 return Status::Success(); 231 return Status::Success();
232 } 232 }
233 233
234 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( 234 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(
235 blink::WebCryptoKeyFormat format, 235 blink::WebCryptoKeyFormat format,
236 blink::WebCryptoKeyUsageMask usages) const { 236 blink::WebCryptoKeyUsageMask usages) const {
237 switch (format) { 237 switch (format) {
238 case blink::WebCryptoKeyFormatSpki: 238 case blink::WebCryptoKeyFormatSpki:
239 return CheckKeyCreationUsages(all_public_key_usages_, usages); 239 return CheckKeyCreationUsages(all_public_key_usages_, usages, false);
240 case blink::WebCryptoKeyFormatPkcs8: 240 case blink::WebCryptoKeyFormatPkcs8:
241 return CheckKeyCreationUsages(all_private_key_usages_, usages); 241 return CheckKeyCreationUsages(all_private_key_usages_, usages, true);
242 case blink::WebCryptoKeyFormatJwk: 242 case blink::WebCryptoKeyFormatJwk:
243 // The JWK could represent either a public key or private key. The usages 243 // The JWK could represent either a public key or private key. The usages
244 // must make sense for one of the two. The usages will be checked again by 244 // must make sense for one of the two. The usages will be checked again by
245 // ImportKeyJwk() once the key type has been determined. 245 // ImportKeyJwk() once the key type has been determined.
246 if (CheckKeyCreationUsages(all_private_key_usages_, usages).IsSuccess() || 246 if (CheckKeyCreationUsages(
247 CheckKeyCreationUsages(all_public_key_usages_, usages).IsSuccess()) { 247 all_private_key_usages_, usages, true).IsSuccess() ||
248 CheckKeyCreationUsages(
249 all_public_key_usages_, usages, false).IsSuccess()) {
248 return Status::Success(); 250 return Status::Success();
249 } 251 }
250 return Status::ErrorCreateKeyBadUsages(); 252 return Status::ErrorCreateKeyBadUsages();
251 default: 253 default:
252 return Status::ErrorUnsupportedImportKeyFormat(); 254 return Status::ErrorUnsupportedImportKeyFormat();
253 } 255 }
254 } 256 }
255 257
256 Status RsaHashedAlgorithm::ImportKeyPkcs8( 258 Status RsaHashedAlgorithm::ImportKeyPkcs8(
257 const CryptoData& key_data, 259 const CryptoData& key_data,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 key->algorithm().rsaHashedParams()->publicExponent().size())) { 446 key->algorithm().rsaHashedParams()->publicExponent().size())) {
445 return Status::ErrorUnexpected(); 447 return Status::ErrorUnexpected();
446 } 448 }
447 449
448 return Status::Success(); 450 return Status::Success();
449 } 451 }
450 452
451 } // namespace webcrypto 453 } // namespace webcrypto
452 454
453 } // namespace content 455 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698