Chromium Code Reviews| 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), | |
|
davidben
2014/11/07 23:37:45
This seems silly, but I'm not familiar enough with
| |
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 return Status::Success(); | 857 return Status::Success(); |
| 844 } | 858 } |
| 845 default: | 859 default: |
| 846 return Status::ErrorUnexpected(); | 860 return Status::ErrorUnexpected(); |
| 847 } | 861 } |
| 848 } | 862 } |
| 849 | 863 |
| 850 } // namespace webcrypto | 864 } // namespace webcrypto |
| 851 | 865 |
| 852 } // namespace content | 866 } // namespace content |
| OLD | NEW |