OLD | NEW |
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (status.IsError()) | 227 if (status.IsError()) |
228 return status; | 228 return status; |
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 bool checkEmptyUsage = true; |
237 switch (format) { | 238 switch (format) { |
238 case blink::WebCryptoKeyFormatSpki: | 239 case blink::WebCryptoKeyFormatSpki: |
239 return CheckKeyCreationUsages(all_public_key_usages_, usages); | 240 return CheckKeyCreationUsages(all_public_key_usages_, usages, |
| 241 checkEmptyUsage); |
240 case blink::WebCryptoKeyFormatPkcs8: | 242 case blink::WebCryptoKeyFormatPkcs8: |
241 return CheckKeyCreationUsages(all_private_key_usages_, usages); | 243 return CheckKeyCreationUsages(all_private_key_usages_, usages, |
| 244 checkEmptyUsage); |
242 case blink::WebCryptoKeyFormatJwk: | 245 case blink::WebCryptoKeyFormatJwk: |
243 // The JWK could represent either a public key or private key. The usages | 246 // 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 | 247 // must make sense for one of the two. The usages will be checked again by |
245 // ImportKeyJwk() once the key type has been determined. | 248 // ImportKeyJwk() once the key type has been determined. |
246 if (CheckKeyCreationUsages(all_private_key_usages_, usages).IsSuccess() || | 249 if (CheckKeyCreationUsages(all_private_key_usages_, usages, |
247 CheckKeyCreationUsages(all_public_key_usages_, usages).IsSuccess()) { | 250 checkEmptyUsage).IsSuccess() || |
| 251 CheckKeyCreationUsages(all_public_key_usages_, usages, |
| 252 checkEmptyUsage).IsSuccess()) { |
248 return Status::Success(); | 253 return Status::Success(); |
249 } | 254 } |
250 return Status::ErrorCreateKeyBadUsages(); | 255 return Status::ErrorCreateKeyBadUsages(); |
251 default: | 256 default: |
252 return Status::ErrorUnsupportedImportKeyFormat(); | 257 return Status::ErrorUnsupportedImportKeyFormat(); |
253 } | 258 } |
254 } | 259 } |
255 | 260 |
256 Status RsaHashedAlgorithm::ImportKeyPkcs8( | 261 Status RsaHashedAlgorithm::ImportKeyPkcs8( |
257 const CryptoData& key_data, | 262 const CryptoData& key_data, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 key->algorithm().rsaHashedParams()->publicExponent().size())) { | 449 key->algorithm().rsaHashedParams()->publicExponent().size())) { |
445 return Status::ErrorUnexpected(); | 450 return Status::ErrorUnexpected(); |
446 } | 451 } |
447 | 452 |
448 return Status::Success(); | 453 return Status::Success(); |
449 } | 454 } |
450 | 455 |
451 } // namespace webcrypto | 456 } // namespace webcrypto |
452 | 457 |
453 } // namespace content | 458 } // namespace content |
OLD | NEW |