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/ec_key_openssl.h" | 5 #include "content/child/webcrypto/openssl/ec_key_openssl.h" |
6 | 6 |
7 #include <openssl/ec.h> | 7 #include <openssl/ec.h> |
8 #include <openssl/ec_key.h> | 8 #include <openssl/ec_key.h> |
9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
10 #include <openssl/pkcs12.h> | 10 #include <openssl/pkcs12.h> |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 272 |
273 status = CreateWebCryptoPrivateKey(private_pkey.Pass(), key_algorithm, | 273 status = CreateWebCryptoPrivateKey(private_pkey.Pass(), key_algorithm, |
274 extractable, private_usages, &private_key); | 274 extractable, private_usages, &private_key); |
275 if (status.IsError()) | 275 if (status.IsError()) |
276 return status; | 276 return status; |
277 | 277 |
278 result->AssignKeyPair(public_key, private_key); | 278 result->AssignKeyPair(public_key, private_key); |
279 return Status::Success(); | 279 return Status::Success(); |
280 } | 280 } |
281 | 281 |
282 // TODO(eroman): This is identical to RSA. | |
283 Status EcAlgorithm::VerifyKeyUsagesBeforeImportKey( | 282 Status EcAlgorithm::VerifyKeyUsagesBeforeImportKey( |
284 blink::WebCryptoKeyFormat format, | 283 blink::WebCryptoKeyFormat format, |
285 blink::WebCryptoKeyUsageMask usages) const { | 284 blink::WebCryptoKeyUsageMask usages) const { |
286 switch (format) { | 285 return VerifyUsagesBeforeImportAsymmetricKey(format, all_public_key_usages_, |
287 case blink::WebCryptoKeyFormatSpki: | 286 all_private_key_usages_, usages); |
288 return CheckKeyCreationUsages(all_public_key_usages_, usages); | |
289 case blink::WebCryptoKeyFormatPkcs8: | |
290 return CheckKeyCreationUsages(all_private_key_usages_, usages); | |
291 case blink::WebCryptoKeyFormatJwk: | |
292 // The JWK could represent either a public key or private key. The usages | |
293 // must make sense for one of the two. The usages will be checked again by | |
294 // ImportKeyJwk() once the key type has been determined. | |
295 if (CheckKeyCreationUsages(all_private_key_usages_, usages).IsSuccess() || | |
296 CheckKeyCreationUsages(all_public_key_usages_, usages).IsSuccess()) { | |
297 return Status::Success(); | |
298 } | |
299 return Status::ErrorCreateKeyBadUsages(); | |
300 default: | |
301 return Status::ErrorUnsupportedImportKeyFormat(); | |
302 } | |
303 } | 287 } |
304 | 288 |
305 Status EcAlgorithm::ImportKeyPkcs8(const CryptoData& key_data, | 289 Status EcAlgorithm::ImportKeyPkcs8(const CryptoData& key_data, |
306 const blink::WebCryptoAlgorithm& algorithm, | 290 const blink::WebCryptoAlgorithm& algorithm, |
307 bool extractable, | 291 bool extractable, |
308 blink::WebCryptoKeyUsageMask usages, | 292 blink::WebCryptoKeyUsageMask usages, |
309 blink::WebCryptoKey* key) const { | 293 blink::WebCryptoKey* key) const { |
310 crypto::ScopedEVP_PKEY private_key; | 294 crypto::ScopedEVP_PKEY private_key; |
311 Status status = | 295 Status status = |
312 ImportUnverifiedPkeyFromPkcs8(key_data, EVP_PKEY_EC, &private_key); | 296 ImportUnverifiedPkeyFromPkcs8(key_data, EVP_PKEY_EC, &private_key); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 key->algorithm().ecParams()->namedCurve()) { | 555 key->algorithm().ecParams()->namedCurve()) { |
572 return Status::ErrorUnexpected(); | 556 return Status::ErrorUnexpected(); |
573 } | 557 } |
574 | 558 |
575 return Status::Success(); | 559 return Status::Success(); |
576 } | 560 } |
577 | 561 |
578 } // namespace webcrypto | 562 } // namespace webcrypto |
579 | 563 |
580 } // namespace content | 564 } // namespace content |
OLD | NEW |