| 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/platform_crypto.h" | 5 #include "content/child/webcrypto/platform_crypto.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 #include <secerr.h> | 9 #include <secerr.h> |
| 10 #include <sechash.h> | 10 #include <sechash.h> |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // To understand this workaround see the fix for 981170: | 535 // To understand this workaround see the fix for 981170: |
| 536 // https://hg.mozilla.org/projects/nss/rev/753bb69e543c | 536 // https://hg.mozilla.org/projects/nss/rev/753bb69e543c |
| 537 if (!NSS_VersionCheck("3.16") && PORT_GetError() == SEC_ERROR_BAD_DATA) | 537 if (!NSS_VersionCheck("3.16") && PORT_GetError() == SEC_ERROR_BAD_DATA) |
| 538 return Status::Error(); | 538 return Status::Error(); |
| 539 #endif | 539 #endif |
| 540 | 540 |
| 541 *unwrapped_key = new_key.Pass(); | 541 *unwrapped_key = new_key.Pass(); |
| 542 return Status::Success(); | 542 return Status::Success(); |
| 543 } | 543 } |
| 544 | 544 |
| 545 void CopySECItemToVector(const SECItem& item, std::vector<uint8>* out) { |
| 546 out->assign(item.data, item.data + item.len); |
| 547 } |
| 548 |
| 545 // From PKCS#1 [http://tools.ietf.org/html/rfc3447]: | 549 // From PKCS#1 [http://tools.ietf.org/html/rfc3447]: |
| 546 // | 550 // |
| 547 // RSAPrivateKey ::= SEQUENCE { | 551 // RSAPrivateKey ::= SEQUENCE { |
| 548 // version Version, | 552 // version Version, |
| 549 // modulus INTEGER, -- n | 553 // modulus INTEGER, -- n |
| 550 // publicExponent INTEGER, -- e | 554 // publicExponent INTEGER, -- e |
| 551 // privateExponent INTEGER, -- d | 555 // privateExponent INTEGER, -- d |
| 552 // prime1 INTEGER, -- p | 556 // prime1 INTEGER, -- p |
| 553 // prime2 INTEGER, -- q | 557 // prime2 INTEGER, -- q |
| 554 // exponent1 INTEGER, -- d mod (p-1) | 558 // exponent1 INTEGER, -- d mod (p-1) |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 return Status::Error(); | 792 return Status::Error(); |
| 789 | 793 |
| 790 DCHECK(spki_der->data); | 794 DCHECK(spki_der->data); |
| 791 DCHECK(spki_der->len); | 795 DCHECK(spki_der->len); |
| 792 | 796 |
| 793 *buffer = CreateArrayBuffer(spki_der->data, spki_der->len); | 797 *buffer = CreateArrayBuffer(spki_der->data, spki_der->len); |
| 794 | 798 |
| 795 return Status::Success(); | 799 return Status::Success(); |
| 796 } | 800 } |
| 797 | 801 |
| 802 Status ExportRsaPublicKey(PublicKey* key, |
| 803 std::vector<uint8>* modulus, |
| 804 std::vector<uint8>* public_exponent) { |
| 805 DCHECK(key); |
| 806 DCHECK(key->key()); |
| 807 if (key->key()->keyType != rsaKey) |
| 808 return Status::ErrorUnsupported(); |
| 809 CopySECItemToVector(key->key()->u.rsa.modulus, modulus); |
| 810 CopySECItemToVector(key->key()->u.rsa.publicExponent, public_exponent); |
| 811 if (modulus->empty() || public_exponent->empty()) |
| 812 return Status::ErrorUnexpected(); |
| 813 return Status::Success(); |
| 814 } |
| 815 |
| 798 Status ExportKeyPkcs8(PrivateKey* key, | 816 Status ExportKeyPkcs8(PrivateKey* key, |
| 799 const blink::WebCryptoKeyAlgorithm& key_algorithm, | 817 const blink::WebCryptoKeyAlgorithm& key_algorithm, |
| 800 blink::WebArrayBuffer* buffer) { | 818 blink::WebArrayBuffer* buffer) { |
| 801 // TODO(eroman): Support other RSA key types as they are added to Blink. | 819 // TODO(eroman): Support other RSA key types as they are added to Blink. |
| 802 if (key_algorithm.id() != blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 && | 820 if (key_algorithm.id() != blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 && |
| 803 key_algorithm.id() != blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5) | 821 key_algorithm.id() != blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5) |
| 804 return Status::ErrorUnsupported(); | 822 return Status::ErrorUnsupported(); |
| 805 | 823 |
| 806 const SECOidTag algorithm = SEC_OID_PKCS1_RSA_ENCRYPTION; | 824 const SECOidTag algorithm = SEC_OID_PKCS1_RSA_ENCRYPTION; |
| 807 const int kPrivateKeyInfoVersion = 0; | 825 const int kPrivateKeyInfoVersion = 0; |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 key_algorithm, | 1492 key_algorithm, |
| 1475 usage_mask); | 1493 usage_mask); |
| 1476 return Status::Success(); | 1494 return Status::Success(); |
| 1477 } | 1495 } |
| 1478 | 1496 |
| 1479 } // namespace platform | 1497 } // namespace platform |
| 1480 | 1498 |
| 1481 } // namespace webcrypto | 1499 } // namespace webcrypto |
| 1482 | 1500 |
| 1483 } // namespace content | 1501 } // namespace content |
| OLD | NEW |