OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 #include <sechash.h> | 9 #include <sechash.h> |
10 | 10 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 NULL)); | 317 NULL)); |
318 if (!pk11_sym_key.get()) { | 318 if (!pk11_sym_key.get()) { |
319 return false; | 319 return false; |
320 } | 320 } |
321 | 321 |
322 *key = blink::WebCryptoKey::create(new SymKeyHandle(pk11_sym_key.Pass()), | 322 *key = blink::WebCryptoKey::create(new SymKeyHandle(pk11_sym_key.Pass()), |
323 type, extractable, algorithm, usage_mask); | 323 type, extractable, algorithm, usage_mask); |
324 return true; | 324 return true; |
325 } | 325 } |
326 | 326 |
| 327 bool ExportKeyInternalRaw( |
| 328 const blink::WebCryptoKey& key, |
| 329 blink::WebArrayBuffer* buffer) { |
| 330 |
| 331 DCHECK(key.handle()); |
| 332 DCHECK(buffer); |
| 333 |
| 334 if (key.type() != blink::WebCryptoKeyTypeSecret || !key.extractable()) |
| 335 return false; |
| 336 |
| 337 SymKeyHandle* const sym_key = reinterpret_cast<SymKeyHandle*>(key.handle()); |
| 338 |
| 339 if (PK11_ExtractKeyValue(sym_key->key()) != SECSuccess) |
| 340 return false; |
| 341 |
| 342 SECItem* const key_data = PK11_GetKeyData(sym_key->key()); |
| 343 if (!key_data) |
| 344 return false; |
| 345 DCHECK(key_data->data); |
| 346 |
| 347 *buffer = blink::WebArrayBuffer::create(key_data->len, 1); |
| 348 memcpy(buffer->data(), key_data->data, key_data->len); |
| 349 |
| 350 return true; |
| 351 } |
| 352 |
327 typedef scoped_ptr<CERTSubjectPublicKeyInfo, | 353 typedef scoped_ptr<CERTSubjectPublicKeyInfo, |
328 crypto::NSSDestroyer<CERTSubjectPublicKeyInfo, | 354 crypto::NSSDestroyer<CERTSubjectPublicKeyInfo, |
329 SECKEY_DestroySubjectPublicKeyInfo> > | 355 SECKEY_DestroySubjectPublicKeyInfo> > |
330 ScopedCERTSubjectPublicKeyInfo; | 356 ScopedCERTSubjectPublicKeyInfo; |
331 | 357 |
332 // Validates an NSS KeyType against a WebCrypto algorithm. Some NSS KeyTypes | 358 // Validates an NSS KeyType against a WebCrypto algorithm. Some NSS KeyTypes |
333 // contain enough information to fabricate a Web Crypto algorithm, which is | 359 // contain enough information to fabricate a Web Crypto algorithm, which is |
334 // returned if the input algorithm isNull(). This function indicates failure by | 360 // returned if the input algorithm isNull(). This function indicates failure by |
335 // returning a Null algorithm. | 361 // returning a Null algorithm. |
336 blink::WebCryptoAlgorithm ResolveNssKeyTypeWithInputAlgorithm( | 362 blink::WebCryptoAlgorithm ResolveNssKeyTypeWithInputAlgorithm( |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 return false; | 845 return false; |
820 } | 846 } |
821 } | 847 } |
822 | 848 |
823 bool WebCryptoImpl::ExportKeyInternal( | 849 bool WebCryptoImpl::ExportKeyInternal( |
824 blink::WebCryptoKeyFormat format, | 850 blink::WebCryptoKeyFormat format, |
825 const blink::WebCryptoKey& key, | 851 const blink::WebCryptoKey& key, |
826 blink::WebArrayBuffer* buffer) { | 852 blink::WebArrayBuffer* buffer) { |
827 switch (format) { | 853 switch (format) { |
828 case blink::WebCryptoKeyFormatRaw: | 854 case blink::WebCryptoKeyFormatRaw: |
829 // TODO(padolph): Implement raw export | 855 return ExportKeyInternalRaw(key, buffer); |
830 return false; | |
831 case blink::WebCryptoKeyFormatSpki: | 856 case blink::WebCryptoKeyFormatSpki: |
832 return ExportKeyInternalSpki(key, buffer); | 857 return ExportKeyInternalSpki(key, buffer); |
833 case blink::WebCryptoKeyFormatPkcs8: | 858 case blink::WebCryptoKeyFormatPkcs8: |
834 // TODO(padolph): Implement pkcs8 export | 859 // TODO(padolph): Implement pkcs8 export |
835 return false; | 860 return false; |
836 default: | 861 default: |
837 return false; | 862 return false; |
838 } | 863 } |
839 } | 864 } |
840 | 865 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 break; | 954 break; |
930 } | 955 } |
931 default: | 956 default: |
932 return false; | 957 return false; |
933 } | 958 } |
934 | 959 |
935 return true; | 960 return true; |
936 } | 961 } |
937 | 962 |
938 } // namespace content | 963 } // namespace content |
OLD | NEW |