Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: content/renderer/webcrypto/webcrypto_impl_nss.cc

Issue 100593002: [webcrypto] Add symmetric key export for NSS and OpenSSL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes for eroman Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/webcrypto/webcrypto_impl_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 NULL)); 318 NULL));
319 if (!pk11_sym_key.get()) { 319 if (!pk11_sym_key.get()) {
320 return false; 320 return false;
321 } 321 }
322 322
323 *key = blink::WebCryptoKey::create(new SymKeyHandle(pk11_sym_key.Pass()), 323 *key = blink::WebCryptoKey::create(new SymKeyHandle(pk11_sym_key.Pass()),
324 type, extractable, algorithm, usage_mask); 324 type, extractable, algorithm, usage_mask);
325 return true; 325 return true;
326 } 326 }
327 327
328 bool ExportKeyInternalRaw(
329 const blink::WebCryptoKey& key,
330 blink::WebArrayBuffer* buffer) {
331
332 DCHECK(key.handle());
333 DCHECK(buffer);
334
335 if (key.type() != blink::WebCryptoKeyTypeSecret || !key.extractable())
336 return false;
337
338 SymKeyHandle* sym_key = reinterpret_cast<SymKeyHandle*>(key.handle());
339
340 if (PK11_ExtractKeyValue(sym_key->key()) != SECSuccess)
341 return false;
342
343 const SECItem* key_data = PK11_GetKeyData(sym_key->key());
344 if (!key_data)
345 return false;
346 DCHECK(key_data->data);
eroman 2013/12/05 02:53:58 If it is possible to have empty keys, then is this
padolph 2013/12/05 03:34:16 Removed.
347
348 *buffer = webcrypto::CreateArrayBuffer(key_data->data, key_data->len);
349
350 return true;
351 }
352
328 typedef scoped_ptr<CERTSubjectPublicKeyInfo, 353 typedef scoped_ptr<CERTSubjectPublicKeyInfo,
329 crypto::NSSDestroyer<CERTSubjectPublicKeyInfo, 354 crypto::NSSDestroyer<CERTSubjectPublicKeyInfo,
330 SECKEY_DestroySubjectPublicKeyInfo> > 355 SECKEY_DestroySubjectPublicKeyInfo> >
331 ScopedCERTSubjectPublicKeyInfo; 356 ScopedCERTSubjectPublicKeyInfo;
332 357
333 // Validates an NSS KeyType against a WebCrypto algorithm. Some NSS KeyTypes 358 // Validates an NSS KeyType against a WebCrypto algorithm. Some NSS KeyTypes
334 // contain enough information to fabricate a Web Crypto algorithm, which is 359 // contain enough information to fabricate a Web Crypto algorithm, which is
335 // returned if the input algorithm isNull(). This function indicates failure by 360 // returned if the input algorithm isNull(). This function indicates failure by
336 // returning a Null algorithm. 361 // returning a Null algorithm.
337 blink::WebCryptoAlgorithm ResolveNssKeyTypeWithInputAlgorithm( 362 blink::WebCryptoAlgorithm ResolveNssKeyTypeWithInputAlgorithm(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 reinterpret_cast<PublicKeyHandle*>(key.handle()); 442 reinterpret_cast<PublicKeyHandle*>(key.handle());
418 443
419 const crypto::ScopedSECItem spki_der( 444 const crypto::ScopedSECItem spki_der(
420 SECKEY_EncodeDERSubjectPublicKeyInfo(pub_key->key())); 445 SECKEY_EncodeDERSubjectPublicKeyInfo(pub_key->key()));
421 if (!spki_der) 446 if (!spki_der)
422 return false; 447 return false;
423 448
424 DCHECK(spki_der->data); 449 DCHECK(spki_der->data);
425 DCHECK(spki_der->len); 450 DCHECK(spki_der->len);
426 451
427 *buffer = blink::WebArrayBuffer::create(spki_der->len, 1); 452 *buffer = webcrypto::CreateArrayBuffer(spki_der->data, spki_der->len);
428 memcpy(buffer->data(), spki_der->data, spki_der->len);
429 453
430 return true; 454 return true;
431 } 455 }
432 456
433 bool ImportKeyInternalPkcs8( 457 bool ImportKeyInternalPkcs8(
434 const unsigned char* key_data, 458 const unsigned char* key_data,
435 unsigned key_data_size, 459 unsigned key_data_size,
436 const blink::WebCryptoAlgorithm& algorithm_or_null, 460 const blink::WebCryptoAlgorithm& algorithm_or_null,
437 bool extractable, 461 bool extractable,
438 blink::WebCryptoKeyUsageMask usage_mask, 462 blink::WebCryptoKeyUsageMask usage_mask,
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 return false; 844 return false;
821 } 845 }
822 } 846 }
823 847
824 bool WebCryptoImpl::ExportKeyInternal( 848 bool WebCryptoImpl::ExportKeyInternal(
825 blink::WebCryptoKeyFormat format, 849 blink::WebCryptoKeyFormat format,
826 const blink::WebCryptoKey& key, 850 const blink::WebCryptoKey& key,
827 blink::WebArrayBuffer* buffer) { 851 blink::WebArrayBuffer* buffer) {
828 switch (format) { 852 switch (format) {
829 case blink::WebCryptoKeyFormatRaw: 853 case blink::WebCryptoKeyFormatRaw:
830 // TODO(padolph): Implement raw export 854 return ExportKeyInternalRaw(key, buffer);
831 return false;
832 case blink::WebCryptoKeyFormatSpki: 855 case blink::WebCryptoKeyFormatSpki:
833 return ExportKeyInternalSpki(key, buffer); 856 return ExportKeyInternalSpki(key, buffer);
834 case blink::WebCryptoKeyFormatPkcs8: 857 case blink::WebCryptoKeyFormatPkcs8:
835 // TODO(padolph): Implement pkcs8 export 858 // TODO(padolph): Implement pkcs8 export
836 return false; 859 return false;
837 default: 860 default:
838 return false; 861 return false;
839 } 862 }
840 } 863 }
841 864
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 1011
989 *key = blink::WebCryptoKey::create(new PublicKeyHandle(pubkey.Pass()), 1012 *key = blink::WebCryptoKey::create(new PublicKeyHandle(pubkey.Pass()),
990 blink::WebCryptoKeyTypePublic, 1013 blink::WebCryptoKeyTypePublic,
991 extractable, 1014 extractable,
992 algorithm, 1015 algorithm,
993 usage_mask); 1016 usage_mask);
994 return true; 1017 return true;
995 } 1018 }
996 1019
997 } // namespace content 1020 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/webcrypto/webcrypto_impl_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698