Title: [163976] trunk
Revision
163976
Author
[email protected]
Date
2014-02-12 13:08:40 -0800 (Wed, 12 Feb 2014)

Log Message

Wrap WebCrypto keys in SerializedScriptValue
https://bugs.webkit.org/show_bug.cgi?id=128680

Reviewed by Anders Carlsson.

Source/WebCore: 

Test: crypto/subtle/rsa-indexeddb.html

Added Mac code to wrap a key with AES-GCM. We then serialize it into a plist,
because more custom formats would be crazy (even the custom format in SerializedScriptValue
makes me nervous, we'll certainly need to change CryptoKey in the future).

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* crypto/CommonCryptoUtilities.h:
* crypto/SerializedCryptoKeyWrap.h: Added.
* crypto/mac/SerializedCryptoKeyWrapMac.mm: Added.
(WebCore::vectorFromNSData):
(WebCore::wrapSerializedCryptoKey):
(WebCore::unwrapSerializedCryptoKey):

Source/WebKit/mac: 

Retrieve a master key (placeholder code for now), and use it to wrap key data.

* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::wrapCryptoKey):
(WebChromeClient::unwrapCryptoKey):

Source/WebKit2: 

Retrieve a master key (placeholder code for now), and use it to wrap key data.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):

LayoutTests: 

* crypto/subtle/rsa-indexeddb-expected.txt: Added.
* crypto/subtle/rsa-indexeddb.html: Added.
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (163975 => 163976)


--- trunk/LayoutTests/ChangeLog	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/ChangeLog	2014-02-12 21:08:40 UTC (rev 163976)
@@ -1,3 +1,18 @@
+2014-02-12  Alexey Proskuryakov  <[email protected]>
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        * crypto/subtle/rsa-indexeddb-expected.txt: Added.
+        * crypto/subtle/rsa-indexeddb.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+        * platform/win/TestExpectations:
+        * platform/wincairo/TestExpectations:
+
 2014-02-12  Brendan Long  <[email protected]>
 
         Implement DataCue for metadata cues

Added: trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt (0 => 163976)


--- trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt	2014-02-12 21:08:40 UTC (rev 163976)
@@ -0,0 +1,15 @@
+Test storing a private RSA key in IndexedDB, and retrieving it.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS retrievedKey.type is 'private'
+PASS retrievedKey.extractable is true
+PASS retrievedKey.algorithm.name is 'RSASSA-PKCS1-v1_5'
+PASS retrievedKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(retrievedKey.algorithm.publicExponent) is '010001'
+PASS retrievedKey.usages is ["sign", "verify"]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt
___________________________________________________________________

Added: svn:mime-type

Added: svn:eol-style

Added: trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html (0 => 163976)


--- trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html	2014-02-12 21:08:40 UTC (rev 163976)
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+
+description("Test storing a private RSA key in IndexedDB, and retrieving it.");
+
+jsTestIsAsync = true;
+
+var privateKeyJSON = {
+    kty: "RSA",
+    alg: "RS256",
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB",
+    d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+    p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+    q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+    dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+    dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+    qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk"
+};
+
+crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(privateKeyJSON)), null, true, ["sign", "verify"]).then(function(key) {
+    var openRequest = indexedDB.open("crypto_subtle");
+    openRequest._onupgradeneeded_ = function(event) {
+        var objectStore = event.target.result.createObjectStore("rsa-indexeddb");
+    }
+    openRequest._onerror_ = function(event) {
+        testFailed("Could not open database: " + event.target.error.name);
+        finishJSTest();
+    }
+    openRequest._onsuccess_ = function(event) {
+        db = event.target.result;
+        storeKey();
+    }
+
+    function storeKey() {
+        var objectStore = db.transaction("rsa-indexeddb", "readwrite").objectStore("rsa-indexeddb");
+        var req = objectStore.put(key, "mykey");
+        req._onerror_ = function(event) {
+            testFailed("Could not put a key into database: " + event.target.error.name);
+            finishJSTest();
+        }
+        req._onsuccess_ = function(event) { readKey(); }
+    }
+
+    function readKey() {
+        var objectStore = db.transaction("rsa-indexeddb").objectStore("rsa-indexeddb");
+        var req = objectStore.get("mykey");
+        req._onerror_ = function(event) {
+            testFailed("Could not get a key from database: " + event.target.error.name);
+            finishJSTest();
+        }
+        req._onsuccess_ = function(event) {
+            window.retrievedKey = event.target.result;
+            shouldBe("retrievedKey.type", "'private'");
+            shouldBe("retrievedKey.extractable", "true");
+            shouldBe("retrievedKey.algorithm.name", "'RSASSA-PKCS1-v1_5'");
+            shouldBe("retrievedKey.algorithm.modulusLength", "2048");
+            shouldBe("bytesToHexString(retrievedKey.algorithm.publicExponent)", "'010001'");
+            shouldBe("retrievedKey.usages", '["sign", "verify"]');
+
+            finishJSTest();
+        }
+    }
+});
+</script>
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html
___________________________________________________________________

Added: svn:mime-type

Modified: trunk/LayoutTests/platform/efl/TestExpectations (163975 => 163976)


--- trunk/LayoutTests/platform/efl/TestExpectations	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/efl/TestExpectations	2014-02-12 21:08:40 UTC (rev 163976)
@@ -271,6 +271,7 @@
 webkit.org/b/87661 http/tests/security/cross-origin-worker-indexeddb-allowed.html [ Skip ]
 webkit.org/b/87661 http/tests/security/cross-origin-worker-indexeddb.html [ Skip ]
 webkit.org/b/87661 http/tests/security/no-indexeddb-from-sandbox.html [ Skip ]
+webkit.org/b/87661 crypto/subtle/rsa-indexeddb.html [ Skip ]
 
 #////////////////////////////////////////////////////////////////////////////////////////
 # TESTS EXPECTED TO FAIL

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (163975 => 163976)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2014-02-12 21:08:40 UTC (rev 163976)
@@ -493,6 +493,7 @@
 webkit.org/b/107194 http/tests/security/cross-origin-worker-indexeddb-allowed.html [ Skip ]
 webkit.org/b/107194 http/tests/security/cross-origin-worker-indexeddb.html [ Skip ]
 webkit.org/b/107194 http/tests/security/no-indexeddb-from-sandbox.html [ Skip ]
+crypto/subtle/rsa-indexeddb.html
 
 # crypto.subtle is not yet enabled
 crypto/subtle [ Skip ]

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (163975 => 163976)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2014-02-12 21:08:40 UTC (rev 163976)
@@ -5,3 +5,4 @@
 http/tests/security/cross-origin-worker-indexeddb-allowed.html
 http/tests/security/cross-origin-worker-indexeddb.html
 http/tests/security/no-indexeddb-from-sandbox.html
+crypto/subtle/rsa-indexeddb.html

Modified: trunk/LayoutTests/platform/win/TestExpectations (163975 => 163976)


--- trunk/LayoutTests/platform/win/TestExpectations	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/win/TestExpectations	2014-02-12 21:08:40 UTC (rev 163976)
@@ -1084,6 +1084,7 @@
 http/tests/security/cross-origin-worker-indexeddb-allowed.html
 http/tests/security/cross-origin-worker-indexeddb.html
 http/tests/security/no-indexeddb-from-sandbox.html
+crypto/subtle/rsa-indexeddb.html
 
 # StorageTracker is not enabled.
 storage/domstorage/localstorage/storagetracker

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (163975 => 163976)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2014-02-12 21:08:40 UTC (rev 163976)
@@ -1581,6 +1581,7 @@
 http/tests/security/cross-origin-worker-indexeddb-allowed.html
 http/tests/security/cross-origin-worker-indexeddb.html
 http/tests/security/no-indexeddb-from-sandbox.html
+crypto/subtle/rsa-indexeddb.html
 
 # StorageTracker is not enabled.
 storage/domstorage/localstorage/storagetracker

Modified: trunk/Source/WebCore/ChangeLog (163975 => 163976)


--- trunk/Source/WebCore/ChangeLog	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/ChangeLog	2014-02-12 21:08:40 UTC (rev 163976)
@@ -1,3 +1,25 @@
+2014-02-12  Alexey Proskuryakov  <[email protected]>
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        Test: crypto/subtle/rsa-indexeddb.html
+
+        Added Mac code to wrap a key with AES-GCM. We then serialize it into a plist,
+        because more custom formats would be crazy (even the custom format in SerializedScriptValue
+        makes me nervous, we'll certainly need to change CryptoKey in the future).
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * crypto/CommonCryptoUtilities.h:
+        * crypto/SerializedCryptoKeyWrap.h: Added.
+        * crypto/mac/SerializedCryptoKeyWrapMac.mm: Added.
+        (WebCore::vectorFromNSData):
+        (WebCore::wrapSerializedCryptoKey):
+        (WebCore::unwrapSerializedCryptoKey):
+
 2014-02-12  Brent Fulgham  <[email protected]>
 
         Wheel events don't latch to inner scrollable elements 

Modified: trunk/Source/WebCore/WebCore.exp.in (163975 => 163976)


--- trunk/Source/WebCore/WebCore.exp.in	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-02-12 21:08:40 UTC (rev 163976)
@@ -911,6 +911,7 @@
 #endif
 __ZN7WebCore23getFileModificationTimeERKN3WTF6StringERl
 __ZN7WebCore23getHostnamesWithCookiesERKNS_21NetworkStorageSessionERN3WTF7HashSetINS3_6StringENS3_10StringHashENS3_10HashTraitsIS5_EEEE
+__ZN7WebCore23wrapSerializedCryptoKeyERKN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEES5_RS3_
 __ZN7WebCore24CachedResourceHandleBase11setResourceEPNS_14CachedResourceE
 __ZN7WebCore24DocumentMarkerController10markersForEPNS_4NodeENS_14DocumentMarker11MarkerTypesE
 __ZN7WebCore24DocumentMarkerController13removeMarkersENS_14DocumentMarker11MarkerTypesE
@@ -933,6 +934,7 @@
 __ZN7WebCore25addLanguageChangeObserverEPvPFvS0_E
 __ZN7WebCore25computeViewportAttributesENS_17ViewportArgumentsEiiifNS_7IntSizeE
 __ZN7WebCore25createCanonicalUUIDStringEv
+__ZN7WebCore25unwrapSerializedCryptoKeyERKN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEES5_RS3_
 __ZN7WebCore26ContextDestructionObserver16contextDestroyedEv
 __ZN7WebCore26ContextDestructionObserverC2EPNS_22ScriptExecutionContextE
 __ZN7WebCore26ContextDestructionObserverD2Ev

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (163975 => 163976)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-02-12 21:08:40 UTC (rev 163976)
@@ -5784,6 +5784,8 @@
 		E18258AC0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */; };
 		E187056316E54A0D00585E97 /* MainThreadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = E187056216E54A0D00585E97 /* MainThreadTask.h */; };
 		E18772F1126E2629003DD586 /* Language.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18772F0126E2629003DD586 /* Language.cpp */; };
+		E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */; };
 		E19727161820549E00592D51 /* CryptoKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = E19727151820549E00592D51 /* CryptoKeyType.h */; };
 		E19AC3EE1824DC7900349426 /* CryptoAlgorithmSHA224.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3E61824DC7900349426 /* CryptoAlgorithmSHA224.cpp */; };
 		E19AC3EF1824DC7900349426 /* CryptoAlgorithmSHA224.h in Headers */ = {isa = PBXBuildFile; fileRef = E19AC3E71824DC7900349426 /* CryptoAlgorithmSHA224.h */; };
@@ -13076,6 +13078,8 @@
 		E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; };
 		E187056216E54A0D00585E97 /* MainThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThreadTask.h; sourceTree = "<group>"; };
 		E18772F0126E2629003DD586 /* Language.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Language.cpp; sourceTree = "<group>"; };
+		E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedCryptoKeyWrap.h; sourceTree = "<group>"; };
+		E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SerializedCryptoKeyWrapMac.mm; path = mac/SerializedCryptoKeyWrapMac.mm; sourceTree = "<group>"; };
 		E19727151820549E00592D51 /* CryptoKeyType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyType.h; sourceTree = "<group>"; };
 		E19AC3E61824DC7900349426 /* CryptoAlgorithmSHA224.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmSHA224.cpp; sourceTree = "<group>"; };
 		E19AC3E71824DC7900349426 /* CryptoAlgorithmSHA224.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmSHA224.h; sourceTree = "<group>"; };
@@ -21035,6 +21039,7 @@
 				E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
 				E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
 				E1FE13621834351100892F13 /* CryptoDigestMac.cpp */,
+				E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */,
 			);
 			name = mac;
 			sourceTree = "<group>";
@@ -21236,6 +21241,7 @@
 				E125F855182C0F8300D84CD9 /* CryptoKeySerialization.h */,
 				E19727151820549E00592D51 /* CryptoKeyType.h */,
 				E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */,
+				E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */,
 				E1FF8F5C1807364B00132674 /* SubtleCrypto.idl */,
 				E1FF8F5D1807442100132674 /* SubtleCrypto.cpp */,
 				E1FF8F5E1807442100132674 /* SubtleCrypto.h */,
@@ -23436,6 +23442,7 @@
 				2E37DFDB12DBAFB800A6B233 /* DOMURL.h in Headers */,
 				15C770A6100D41CD005BA267 /* DOMValidityState.h in Headers */,
 				BC1A37C0097C715F0019F3D8 /* DOMViews.h in Headers */,
+				E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */,
 				31C0FF490E4CEFDD007D6FE5 /* DOMWebKitAnimationEvent.h in Headers */,
 				31C0FF4B0E4CEFDD007D6FE5 /* DOMWebKitAnimationEventInternal.h in Headers */,
 				415B3A6E17CBE267000FCCE8 /* AccessibilitySearchFieldButtons.h in Headers */,
@@ -26320,6 +26327,7 @@
 				512DD8FB0D91E6AF000F89EE /* ArchiveResource.cpp in Sources */,
 				E1FE137A184D21BB00892F13 /* CryptoAlgorithmAES_KW.cpp in Sources */,
 				512DD8F70D91E6AF000F89EE /* ArchiveResourceCollection.cpp in Sources */,
+				E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */,
 				49B3760C15C6C6840059131D /* ArrayValue.cpp in Sources */,
 				FD5686C913AC180200B69C68 /* AsyncAudioDecoder.cpp in Sources */,
 				E1CDE92015018ED000862CC5 /* AsyncFileStream.cpp in Sources */,

Modified: trunk/Source/WebCore/crypto/CommonCryptoUtilities.h (163975 => 163976)


--- trunk/Source/WebCore/crypto/CommonCryptoUtilities.h	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/crypto/CommonCryptoUtilities.h	2014-02-12 21:08:40 UTC (rev 163976)
@@ -89,6 +89,7 @@
 extern "C" void CCRSACryptorRelease(CCRSACryptorRef key);
 extern "C" CCCryptorStatus CCRSAGetKeyComponents(CCRSACryptorRef rsaKey, uint8_t *modulus, size_t *modulusLength, uint8_t *exponent, size_t *exponentLength, uint8_t *p, size_t *pLength, uint8_t *q, size_t *qLength);
 extern "C" CCRSAKeyType CCRSAGetKeyType(CCRSACryptorRef key);
+extern "C" CCCryptorStatus CCCryptorGCM(CCOperation op, CCAlgorithm alg, const void* key, size_t keyLength, const void* iv, size_t ivLen, const void* aData, size_t aDataLen, const void* dataIn, size_t dataInLength, void* dataOut, const void* tag, size_t* tagLength);
 
 namespace WebCore {
 

Added: trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h (0 => 163976)


--- trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h	                        (rev 0)
+++ trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h	2014-02-12 21:08:40 UTC (rev 163976)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SerializedCryptoKeyWrap_h
+#define SerializedCryptoKeyWrap_h
+
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+namespace WebCore {
+
+bool wrapSerializedCryptoKey(const Vector<uint8_t>& masterKey, const Vector<uint8_t>& key, Vector<uint8_t>& result);
+bool unwrapSerializedCryptoKey(const Vector<uint8_t>& masterKey, const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key);
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
+
+#endif // SerializedCryptoKeyWrap_h
Property changes on: trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm (0 => 163976)


--- trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm	                        (rev 0)
+++ trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm	2014-02-12 21:08:40 UTC (rev 163976)
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SerializedCryptoKeyWrap.h"
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+#include "CommonCryptoUtilities.h"
+#include <CommonCrypto/CommonSymmetricKeywrap.h>
+#include <wtf/text/CString.h>
+#include <wtf/CryptographicUtilities.h>
+
+namespace WebCore {
+
+const NSUInteger currentSerializationVersion = 1;
+
+const NSString* versionKey = @"version";
+const NSString* wrappedKEKKey = @"wrappedKEK";
+const NSString* encryptedKeyKey = @"encryptedKey";
+const NSString* tagKey = @"tag";
+
+inline Vector<uint8_t> vectorFromNSData(NSData* data)
+{
+    Vector<uint8_t> result;
+    result.append((const uint8_t*)[data bytes], [data length]);
+    return result;
+}
+
+bool wrapSerializedCryptoKey(const Vector<uint8_t>& masterKey, const Vector<uint8_t>& key, Vector<uint8_t>& result)
+{
+    Vector<uint8_t> kek(16);
+    CCRandomCopyBytes(kCCRandomDefault, kek.data(), kek.size());
+
+    Vector<uint8_t> wrappedKEK(CCSymmetricWrappedSize(kCCWRAPAES, kek.size()));
+
+    size_t wrappedKEKSize = wrappedKEK.size();
+    CCCryptorStatus status = CCSymmetricKeyWrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, masterKey.data(), masterKey.size(), kek.data(), kek.size(), wrappedKEK.data(), &wrappedKEKSize);
+    if (status != kCCSuccess)
+        return false;
+
+    wrappedKEK.shrink(wrappedKEKSize);
+
+    Vector<uint8_t> encryptedKey(key.size());
+    size_t tagLength = 16;
+    uint8_t tag[tagLength];
+
+    status = CCCryptorGCM(kCCEncrypt, kCCAlgorithmAES128, kek.data(), kek.size(),
+        nullptr, 0, // iv
+        nullptr, 0, // auth data
+        key.data(), key.size(),
+        encryptedKey.data(),
+        tag, &tagLength);
+
+    if (status != kCCSuccess)
+        return false;
+    RELEASE_ASSERT(tagLength == 16);
+
+    auto dictionary = @{
+        versionKey: [NSNumber numberWithUnsignedInteger:currentSerializationVersion],
+        wrappedKEKKey: [NSData dataWithBytes:wrappedKEK.data() length:wrappedKEK.size()],
+        encryptedKeyKey: [NSData dataWithBytes:encryptedKey.data() length:encryptedKey.size()],
+        tagKey: [NSData dataWithBytes:tag length:tagLength]
+    };
+
+    NSData* serialization = [NSPropertyListSerialization dataWithPropertyList:dictionary format:NSPropertyListBinaryFormat_v1_0 options:0 error:nullptr];
+    if (!serialization)
+        return false;
+
+    result = vectorFromNSData(serialization);
+    return true;
+}
+
+bool unwrapSerializedCryptoKey(const Vector<uint8_t>& masterKey, const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key)
+{
+    NSDictionary* dictionary = [NSPropertyListSerialization propertyListWithData:[NSData dataWithBytesNoCopy:(void*)wrappedKey.data() length:wrappedKey.size() freeWhenDone:NO] options:0 format:nullptr error:nullptr];
+    if (!dictionary)
+        return false;
+
+    id versionObject = [dictionary objectForKey:versionKey];
+    if (![versionObject isKindOfClass:[NSNumber class]])
+        return false;
+    if ([versionObject unsignedIntegerValue] > currentSerializationVersion)
+        return false;
+
+    id wrappedKEKObject = [dictionary objectForKey:wrappedKEKKey];
+    if (![wrappedKEKObject isKindOfClass:[NSData class]])
+        return false;
+    Vector<uint8_t> wrappedKEK = vectorFromNSData(wrappedKEKObject);
+
+    id encryptedKeyObject = [dictionary objectForKey:encryptedKeyKey];
+    if (![encryptedKeyObject isKindOfClass:[NSData class]])
+        return false;
+    Vector<uint8_t> encryptedKey = vectorFromNSData(encryptedKeyObject);
+
+    id tagObject = [dictionary objectForKey:tagKey];
+    if (![tagObject isKindOfClass:[NSData class]])
+        return false;
+    Vector<uint8_t> tag = vectorFromNSData(tagObject);
+    if (tag.size() != 16)
+        return false;
+
+    Vector<uint8_t> kek(CCSymmetricUnwrappedSize(kCCWRAPAES, wrappedKEK.size()));
+    size_t kekSize = kek.size();
+    CCCryptorStatus status = CCSymmetricKeyUnwrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, masterKey.data(), masterKey.size(), wrappedKEK.data(), wrappedKEK.size(), kek.data(), &kekSize);
+    if (status != kCCSuccess)
+        return false;
+    kek.shrink(kekSize);
+
+    size_t tagLength = 16;
+    uint8_t actualTag[tagLength];
+
+    key.resize(encryptedKey.size());
+    status = CCCryptorGCM(kCCDecrypt, kCCAlgorithmAES128, kek.data(), kek.size(),
+        nullptr, 0, // iv
+        nullptr, 0, // auth data
+        encryptedKey.data(), encryptedKey.size(),
+        key.data(),
+        actualTag, &tagLength);
+
+    if (status != kCCSuccess)
+        return false;
+    RELEASE_ASSERT(tagLength == 16);
+
+    if (constantTimeMemcmp(tag.data(), actualTag, tagLength))
+        return false;
+
+    return true;
+}
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
Property changes on: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebKit/mac/ChangeLog (163975 => 163976)


--- trunk/Source/WebKit/mac/ChangeLog	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit/mac/ChangeLog	2014-02-12 21:08:40 UTC (rev 163976)
@@ -1,3 +1,16 @@
+2014-02-12  Alexey Proskuryakov  <[email protected]>
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        Retrieve a master key (placeholder code for now), and use it to wrap key data.
+
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::wrapCryptoKey):
+        (WebChromeClient::unwrapCryptoKey):
+
 2014-02-11  Ryosuke Niwa  <[email protected]>
 
         Frame::rectForSelection shouldn't instantiate FrameSelection

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm (163975 => 163976)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm	2014-02-12 21:08:40 UTC (rev 163976)
@@ -79,6 +79,7 @@
 #import <WebCore/Page.h>
 #import <WebCore/PlatformScreen.h>
 #import <WebCore/ResourceRequest.h>
+#import <WebCore/SerializedCryptoKeyWrap.h>
 #import <WebCore/Widget.h>
 #import <WebCore/WindowFeatures.h>
 #import <wtf/PassRefPtr.h>
@@ -1001,13 +1002,15 @@
 #if ENABLE(SUBTLE_CRYPTO)
 bool WebChromeClient::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) const
 {
-    wrappedKey = key;
-    return true;
+    Vector<uint8_t> masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    return wrapSerializedCryptoKey(masterKey, key, wrappedKey);
 }
 
 bool WebChromeClient::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) const
 {
-    key = wrappedKey;
-    return true;
+    Vector<uint8_t> masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    return unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
 }
 #endif

Modified: trunk/Source/WebKit2/ChangeLog (163975 => 163976)


--- trunk/Source/WebKit2/ChangeLog	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit2/ChangeLog	2014-02-12 21:08:40 UTC (rev 163976)
@@ -1,3 +1,19 @@
+2014-02-12  Alexey Proskuryakov  <[email protected]>
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        Retrieve a master key (placeholder code for now), and use it to wrap key data.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::wrapCryptoKey):
+        (WebKit::WebPageProxy::unwrapCryptoKey):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::wrapCryptoKey):
+        (WebKit::WebPageProxy::unwrapCryptoKey):
+
 2014-02-12  Zan Dobersek  <[email protected]>
 
         [CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (163975 => 163976)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2014-02-12 21:08:40 UTC (rev 163976)
@@ -4479,19 +4479,17 @@
         m_process->send(Messages::WebPage::SetScrollPinningBehavior(pinning), m_pageID);
 }
 
-#if ENABLE(SUBTLE_CRYPTO)
+#if ENABLE(SUBTLE_CRYPTO) && !PLATFORM(COCOA)
 void WebPageProxy::wrapCryptoKey(const Vector<uint8_t>& key, bool& succeeded, Vector<uint8_t>& wrappedKey)
 {
-    // FIXME: Implement.
-    wrappedKey = key;
-    succeeded = true;
+    notImplemented();
+    succeeded = false;
 }
 
 void WebPageProxy::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, bool& succeeded, Vector<uint8_t>& key)
 {
-    // FIXME: Implement.
-    key = wrappedKey;
-    succeeded = true;
+    notImplemented();
+    succeeded = false;
 }
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (163975 => 163976)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2014-02-12 21:08:40 UTC (rev 163976)
@@ -44,6 +44,7 @@
 #import <WebCore/DictationAlternative.h>
 #import <WebCore/GraphicsLayer.h>
 #import <WebCore/RuntimeApplicationChecks.h>
+#import <WebCore/SerializedCryptoKeyWrap.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/TextAlternativeWithRange.h>
 #import <WebCore/UserAgent.h>
@@ -572,4 +573,20 @@
     [[NSWorkspace sharedWorkspace] openFile:pdfFilename];
 }
 
+#if ENABLE(SUBTLE_CRYPTO)
+void WebPageProxy::wrapCryptoKey(const Vector<uint8_t>& key, bool& succeeded, Vector<uint8_t>& wrappedKey)
+{
+    Vector<uint8_t> masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    succeeded = wrapSerializedCryptoKey(masterKey, key, wrappedKey);
+}
+
+void WebPageProxy::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, bool& succeeded, Vector<uint8_t>& key)
+{
+    Vector<uint8_t> masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    succeeded = unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
+}
+#endif
+
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to