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

Unified Diff: Source/bindings/v8/SerializedScriptValue.cpp

Issue 268273002: [webcrypto] Make KeyPair structured clonable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months 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
Index: Source/bindings/v8/SerializedScriptValue.cpp
diff --git a/Source/bindings/v8/SerializedScriptValue.cpp b/Source/bindings/v8/SerializedScriptValue.cpp
index fefbc866b8a84f0a46b3effa9be025f069046230..691fb541814f7d54ac7c34007b8bfb31c2f08f0b 100644
--- a/Source/bindings/v8/SerializedScriptValue.cpp
+++ b/Source/bindings/v8/SerializedScriptValue.cpp
@@ -37,6 +37,7 @@
#include "V8FileList.h"
#include "V8ImageData.h"
#include "V8Key.h"
+#include "V8KeyPair.h"
#include "V8MessagePort.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
@@ -225,6 +226,7 @@ enum SerializationTag {
// props = algorithmId:uint32_t, type:uint32_t, modulusLengthBits:uint32_t, publicExponentLength:uint32_t, publicExponent:byte[publicExponentLength]
// If subtag=RsaHashedKeyTag:
// props = <same as for RsaKeyTag>, hashId:uint32_t
+ CryptoKeyPairTag = 'k', // publicKey:CryptoKey, privateKey:CryptoKey
ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref]
GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and pushed onto the open stack (ref)
GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref)
@@ -506,9 +508,10 @@ public:
doWriteUint32(blobIndices[i]);
}
- bool writeCryptoKey(const blink::WebCryptoKey& key)
+ bool writeCryptoKey(const blink::WebCryptoKey& key, bool includeTag)
{
- append(static_cast<uint8_t>(CryptoKeyTag));
+ if (includeTag)
+ append(static_cast<uint8_t>(CryptoKeyTag));
switch (key.algorithm().paramsType()) {
case blink::WebCryptoKeyAlgorithmParamsTypeAes:
@@ -537,6 +540,12 @@ public:
return true;
}
+ bool writeCryptoKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey)
+ {
+ append(static_cast<uint8_t>(CryptoKeyPairTag));
+ return writeCryptoKey(publicKey, false) && writeCryptoKey(privateKey, false);
+ }
+
void writeArrayBuffer(const ArrayBuffer& arrayBuffer)
{
append(ArrayBufferTag);
@@ -1356,7 +1365,15 @@ private:
Key* key = V8Key::toNative(value.As<v8::Object>());
if (!key)
return 0;
jsbell 2014/05/06 20:38:09 (not this cl, but related) nit: return false
eroman 2014/05/06 21:35:17 Done.
- return m_writer.writeCryptoKey(key->key());
+ return m_writer.writeCryptoKey(key->key(), true);
+ }
+
+ bool writeCryptoKeyPair(v8::Handle<v8::Value> value)
+ {
+ KeyPair* keyPair = V8KeyPair::toNative(value.As<v8::Object>());
+ if (!keyPair)
+ return 0;
jsbell 2014/05/06 20:38:09 nit: return false
eroman 2014/05/06 21:35:17 Done.
+ return m_writer.writeCryptoKeyPair(keyPair->publicKey()->key(), keyPair->privateKey()->key());
}
void writeImageData(v8::Handle<v8::Value> value)
@@ -1576,6 +1593,9 @@ Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat
else if (V8Key::hasInstance(value, m_isolate)) {
if (!writeCryptoKey(value))
return handleError(DataCloneError, "Couldn't serialize key data", next);
+ } else if (V8KeyPair::hasInstance(value, m_isolate)) {
+ if (!writeCryptoKeyPair(value))
+ return handleError(DataCloneError, "Couldn't serialize key data", next);
} else if (V8ImageData::hasInstance(value, m_isolate))
writeImageData(value);
else if (value->IsRegExp())
@@ -1738,6 +1758,11 @@ public:
return false;
creator.pushObjectReference(*value);
break;
+ case CryptoKeyPairTag:
+ if (!readCryptoKeyPair(value))
+ return false;
+ creator.pushObjectReference(*value);
+ break;
case ImageDataTag:
if (!readImageData(value))
return false;
@@ -2231,6 +2256,16 @@ private:
bool readCryptoKey(v8::Handle<v8::Value>* value)
{
+ blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
+ if (!readCryptoKey(key))
+ return false;
+
+ *value = toV8(Key::create(key), v8::Handle<v8::Object>(), m_isolate);
+ return true;
+ }
+
+ bool readCryptoKey(blink::WebCryptoKey& key)
+ {
uint32_t rawKeyType;
if (!doReadUint32(&rawKeyType))
return false;
@@ -2274,13 +2309,25 @@ private:
const uint8_t* keyData = m_buffer + m_position;
m_position += keyDataLength;
- blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
if (!blink::Platform::current()->crypto()->deserializeKeyForClone(
algorithm, type, extractable, usages, keyData, keyDataLength, key)) {
return false;
}
- *value = toV8(Key::create(key), v8::Handle<v8::Object>(), m_isolate);
+ return true;
+ }
+
+ bool readCryptoKeyPair(v8::Handle<v8::Value>* value)
+ {
+ blink::WebCryptoKey publicKey = blink::WebCryptoKey::createNull();
+ blink::WebCryptoKey privateKey = blink::WebCryptoKey::createNull();
+
+ if (!readCryptoKey(publicKey) || publicKey.type() != blink::WebCryptoKeyTypePublic)
+ return false;
+ if (!readCryptoKey(privateKey) || privateKey.type() != blink::WebCryptoKeyTypePrivate)
+ return false;
+
+ *value = toV8(KeyPair::create(publicKey, privateKey), v8::Handle<v8::Object>(), m_isolate);
return true;
}
« LayoutTests/crypto/clone-rsaKeyPair.html ('K') | « LayoutTests/crypto/resources/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698