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

Unified 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: adjusted #ifdef to fix android (openssl) build 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/renderer/webcrypto/webcrypto_impl_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/webcrypto/webcrypto_impl_nss.cc
diff --git a/content/renderer/webcrypto/webcrypto_impl_nss.cc b/content/renderer/webcrypto/webcrypto_impl_nss.cc
index 73319df1a78b837fa4c7a93a762d6307cd06e3f8..29dc04dd9998d4bce3232903394f50c0439d5d79 100644
--- a/content/renderer/webcrypto/webcrypto_impl_nss.cc
+++ b/content/renderer/webcrypto/webcrypto_impl_nss.cc
@@ -325,6 +325,30 @@ bool ImportKeyInternalRaw(
return true;
}
+bool ExportKeyInternalRaw(
+ const blink::WebCryptoKey& key,
+ blink::WebArrayBuffer* buffer) {
+
+ DCHECK(key.handle());
+ DCHECK(buffer);
+
+ if (key.type() != blink::WebCryptoKeyTypeSecret || !key.extractable())
+ return false;
+
+ SymKeyHandle* sym_key = reinterpret_cast<SymKeyHandle*>(key.handle());
+
+ if (PK11_ExtractKeyValue(sym_key->key()) != SECSuccess)
+ return false;
+
+ const SECItem* key_data = PK11_GetKeyData(sym_key->key());
+ if (!key_data)
+ return false;
+
+ *buffer = webcrypto::CreateArrayBuffer(key_data->data, key_data->len);
+
+ return true;
+}
+
typedef scoped_ptr<CERTSubjectPublicKeyInfo,
crypto::NSSDestroyer<CERTSubjectPublicKeyInfo,
SECKEY_DestroySubjectPublicKeyInfo> >
@@ -424,8 +448,7 @@ bool ExportKeyInternalSpki(
DCHECK(spki_der->data);
DCHECK(spki_der->len);
- *buffer = blink::WebArrayBuffer::create(spki_der->len, 1);
- memcpy(buffer->data(), spki_der->data, spki_der->len);
+ *buffer = webcrypto::CreateArrayBuffer(spki_der->data, spki_der->len);
return true;
}
@@ -827,8 +850,7 @@ bool WebCryptoImpl::ExportKeyInternal(
blink::WebArrayBuffer* buffer) {
switch (format) {
case blink::WebCryptoKeyFormatRaw:
- // TODO(padolph): Implement raw export
- return false;
+ return ExportKeyInternalRaw(key, buffer);
case blink::WebCryptoKeyFormatSpki:
return ExportKeyInternalSpki(key, buffer);
case blink::WebCryptoKeyFormatPkcs8:
« 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