| 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/nss/rsa_key_nss.h" | 5 #include "content/child/webcrypto/nss/rsa_key_nss.h" |
| 6 | 6 |
| 7 #include <secasn1.h> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 10 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/generate_key_result.h" | 11 #include "content/child/webcrypto/generate_key_result.h" |
| 10 #include "content/child/webcrypto/jwk.h" | 12 #include "content/child/webcrypto/jwk.h" |
| 11 #include "content/child/webcrypto/nss/key_nss.h" | 13 #include "content/child/webcrypto/nss/key_nss.h" |
| 12 #include "content/child/webcrypto/nss/util_nss.h" | 14 #include "content/child/webcrypto/nss/util_nss.h" |
| 13 #include "content/child/webcrypto/status.h" | 15 #include "content/child/webcrypto/status.h" |
| 14 #include "content/child/webcrypto/webcrypto_util.h" | 16 #include "content/child/webcrypto/webcrypto_util.h" |
| 15 #include "crypto/scoped_nss_types.h" | 17 #include "crypto/scoped_nss_types.h" |
| 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 bool extractable, | 635 bool extractable, |
| 634 blink::WebCryptoKeyUsageMask usages, | 636 blink::WebCryptoKeyUsageMask usages, |
| 635 blink::WebCryptoKey* key) const { | 637 blink::WebCryptoKey* key) const { |
| 636 Status status = NssSupportsRsaPrivateKeyImport(); | 638 Status status = NssSupportsRsaPrivateKeyImport(); |
| 637 if (status.IsError()) | 639 if (status.IsError()) |
| 638 return status; | 640 return status; |
| 639 | 641 |
| 640 if (!key_data.byte_length()) | 642 if (!key_data.byte_length()) |
| 641 return Status::ErrorImportEmptyKeyData(); | 643 return Status::ErrorImportEmptyKeyData(); |
| 642 | 644 |
| 645 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); |
| 646 if (!arena.get()) |
| 647 return Status::OperationError(); |
| 648 |
| 643 // The binary blob 'key_data' is expected to be a DER-encoded ASN.1 PKCS#8 | 649 // The binary blob 'key_data' is expected to be a DER-encoded ASN.1 PKCS#8 |
| 644 // private key info object. | 650 // private key info object. Excess data is illegal, but NSS silently accepts |
| 645 SECItem pki_der = MakeSECItemForBuffer(key_data); | 651 // it, so first ensure that 'key_data' consists of a single ASN.1 element. |
| 652 SECItem key_item = MakeSECItemForBuffer(key_data); |
| 653 SECItem pki_der; |
| 654 if (SEC_QuickDERDecodeItem(arena.get(), |
| 655 &pki_der, |
| 656 SEC_ASN1_GET(SEC_AnyTemplate), |
| 657 &key_item) != SECSuccess) { |
| 658 return Status::DataError(); |
| 659 } |
| 646 | 660 |
| 647 SECKEYPrivateKey* seckey_private_key = NULL; | 661 SECKEYPrivateKey* seckey_private_key = NULL; |
| 648 crypto::ScopedPK11Slot slot(PK11_GetInternalSlot()); | 662 crypto::ScopedPK11Slot slot(PK11_GetInternalSlot()); |
| 649 if (PK11_ImportDERPrivateKeyInfoAndReturnKey(slot.get(), | 663 if (PK11_ImportDERPrivateKeyInfoAndReturnKey(slot.get(), |
| 650 &pki_der, | 664 &pki_der, |
| 651 NULL, // nickname | 665 NULL, // nickname |
| 652 NULL, // publicValue | 666 NULL, // publicValue |
| 653 false, // isPerm | 667 false, // isPerm |
| 654 false, // isPrivate | 668 false, // isPrivate |
| 655 KU_ALL, // usage | 669 KU_ALL, // usage |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 key->algorithm().rsaHashedParams()->publicExponent().size())) { | 918 key->algorithm().rsaHashedParams()->publicExponent().size())) { |
| 905 return Status::ErrorUnexpected(); | 919 return Status::ErrorUnexpected(); |
| 906 } | 920 } |
| 907 | 921 |
| 908 return Status::Success(); | 922 return Status::Success(); |
| 909 } | 923 } |
| 910 | 924 |
| 911 } // namespace webcrypto | 925 } // namespace webcrypto |
| 912 | 926 |
| 913 } // namespace content | 927 } // namespace content |
| OLD | NEW |