Title: [163999] trunk
Revision
163999
Author
[email protected]
Date
2014-02-12 16:39:21 -0800 (Wed, 12 Feb 2014)

Log Message

[WK2] Add a C API to get WebCrypto master key from a client
https://bugs.webkit.org/show_bug.cgi?id=128702

Reviewed by Anders Carlsson.

Source/WebKit2: 

Added a new version of WKContextClient, with a function that returns the key.

* UIProcess/API/C/WKContext.h:
* UIProcess/WebContextClient.cpp:
(WebKit::WebContextClient::copyWebCryptoMasterKey):
* UIProcess/WebContextClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):
* UIProcess/mac/WebPageProxyMac.mm:

Tools: 

* WebKitTestRunner/TestController.cpp:
(WTR::copyWebCryptoMasterKey):
(WTR::TestController::initialize):
Return a hardcoded key.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (163998 => 163999)


--- trunk/Source/WebKit2/ChangeLog	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Source/WebKit2/ChangeLog	2014-02-13 00:39:21 UTC (rev 163999)
@@ -1,3 +1,21 @@
+2014-02-12  Alexey Proskuryakov  <[email protected]>
+
+        [WK2] Add a C API to get WebCrypto master key from a client
+        https://bugs.webkit.org/show_bug.cgi?id=128702
+
+        Reviewed by Anders Carlsson.
+
+        Added a new version of WKContextClient, with a function that returns the key.
+
+        * UIProcess/API/C/WKContext.h:
+        * UIProcess/WebContextClient.cpp:
+        (WebKit::WebContextClient::copyWebCryptoMasterKey):
+        * UIProcess/WebContextClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::wrapCryptoKey):
+        (WebKit::WebPageProxy::unwrapCryptoKey):
+        * UIProcess/mac/WebPageProxyMac.mm:
+
 2014-02-12  Anders Carlsson  <[email protected]>
 
         Add destinationFrame property to WKNavigationAction

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKContext.h (163998 => 163999)


--- trunk/Source/WebKit2/UIProcess/API/C/WKContext.h	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKContext.h	2014-02-13 00:39:21 UTC (rev 163999)
@@ -47,6 +47,7 @@
 typedef void (*WKContextPlugInAutoStartOriginHashesChangedCallback)(WKContextRef context, const void *clientInfo);
 typedef void (*WKContextNetworkProcessDidCrashCallback)(WKContextRef context, const void *clientInfo);
 typedef void (*WKContextPlugInInformationBecameAvailableCallback)(WKContextRef context, WKArrayRef plugIn, const void *clientInfo);
+typedef WKDataRef (*WKContextCopyWebCryptoMasterKeyCallback)(WKContextRef context, const void *clientInfo);
 
 typedef struct WKContextClientBase {
     int                                                                 version;
@@ -62,7 +63,19 @@
     WKContextPlugInInformationBecameAvailableCallback                   plugInInformationBecameAvailable;
 } WKContextClientV0;
 
-enum { kWKContextClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 };
+typedef struct WKContextClientV1 {
+    WKContextClientBase                                                 base;
+
+    // Version 0.
+    WKContextPlugInAutoStartOriginHashesChangedCallback                 plugInAutoStartOriginHashesChanged;
+    WKContextNetworkProcessDidCrashCallback                             networkProcessDidCrash;
+    WKContextPlugInInformationBecameAvailableCallback                   plugInInformationBecameAvailable;
+
+    // Version 1.
+    WKContextCopyWebCryptoMasterKeyCallback                             copyWebCryptoMasterKey;
+} WKContextClientV1;
+
+enum { kWKContextClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 1 };
 typedef struct WKContextClient {
     int                                                                 version;
     const void *                                                        clientInfo;

Modified: trunk/Source/WebKit2/UIProcess/WebContextClient.cpp (163998 => 163999)


--- trunk/Source/WebKit2/UIProcess/WebContextClient.cpp	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Source/WebKit2/UIProcess/WebContextClient.cpp	2014-02-13 00:39:21 UTC (rev 163999)
@@ -58,4 +58,12 @@
     m_client.plugInInformationBecameAvailable(toAPI(context), toAPI(plugInInfo), m_client.base.clientInfo);
 }
 
+PassRefPtr<API::Data> WebContextClient::copyWebCryptoMasterKey(WebContext* context)
+{
+    if (!m_client.copyWebCryptoMasterKey)
+        return nullptr;
+
+    return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(context), m_client.base.clientInfo)));
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebContextClient.h (163998 => 163999)


--- trunk/Source/WebKit2/UIProcess/WebContextClient.h	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Source/WebKit2/UIProcess/WebContextClient.h	2014-02-13 00:39:21 UTC (rev 163999)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 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
@@ -27,13 +27,14 @@
 #define WebContextClient_h
 
 #include "APIClient.h"
+#include "APIData.h"
 #include "WKContext.h"
 
 namespace API {
 class Array;
 
 template<> struct ClientTraits<WKContextClientBase> {
-    typedef std::tuple<WKContextClientV0> Versions;
+    typedef std::tuple<WKContextClientV0, WKContextClientV1> Versions;
 };
 }
 
@@ -46,6 +47,7 @@
     void plugInAutoStartOriginHashesChanged(WebContext*);
     void networkProcessDidCrash(WebContext*);
     void plugInInformationBecameAvailable(WebContext*, API::Array*);
+    PassRefPtr<API::Data> copyWebCryptoMasterKey(WebContext*);
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (163998 => 163999)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2014-02-13 00:39:21 UTC (rev 163999)
@@ -4483,15 +4483,25 @@
 #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.
+    RefPtr<API::Data> keyData = m_process->context().client().copyWebCryptoMasterKey(&m_process->context());
+    if (!keyData) {
+        succeeded = false;
+        return;
+    }
+
+    Vector<uint8_t> masterKey = keyData->dataReference().vector();
     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.
+    RefPtr<API::Data> keyData = m_process->context().client().copyWebCryptoMasterKey(&m_process->context());
+    if (!keyData) {
+        succeeded = false;
+        return;
+    }
+
+    Vector<uint8_t> masterKey = keyData->dataReference().vector();
     succeeded = unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
 }
 #endif

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (163998 => 163999)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2014-02-13 00:39:21 UTC (rev 163999)
@@ -39,6 +39,7 @@
 #import "StringUtilities.h"
 #import "TextChecker.h"
 #import "WKBrowsingContextControllerInternal.h"
+#import "WebContext.h"
 #import "WebPageMessages.h"
 #import "WebProcessProxy.h"
 #import <WebCore/DictationAlternative.h>

Modified: trunk/Tools/ChangeLog (163998 => 163999)


--- trunk/Tools/ChangeLog	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Tools/ChangeLog	2014-02-13 00:39:21 UTC (rev 163999)
@@ -1,3 +1,15 @@
+2014-02-12  Alexey Proskuryakov  <[email protected]>
+
+        [WK2] Add a C API to get WebCrypto master key from a client
+        https://bugs.webkit.org/show_bug.cgi?id=128702
+
+        Reviewed by Anders Carlsson.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::copyWebCryptoMasterKey):
+        (WTR::TestController::initialize):
+        Return a hardcoded key.
+
 2014-02-12  David Farler  <[email protected]>
 
         Upstream iOS old-run-webkit-tests for use with DumpRenderTree in the iOS Simulator

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (163998 => 163999)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2014-02-13 00:38:25 UTC (rev 163998)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2014-02-13 00:39:21 UTC (rev 163999)
@@ -81,6 +81,12 @@
     return staticBlankURL;
 }
 
+static WKDataRef copyWebCryptoMasterKey(WKContextRef, const void*)
+{
+    // Any 128 bit key would do, all we need for testing is to implement the callback.
+    return WKDataCreate((const uint8_t*)"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16);
+}
+
 static TestController* controller;
 
 TestController& TestController::shared()
@@ -336,6 +342,15 @@
 
     platformInitializeContext();
 
+    WKContextClientV1 contextClient = {
+        { 1, this },
+        nullptr, // plugInAutoStartOriginHashesChanged
+        nullptr, // networkProcessDidCrash,
+        nullptr, // plugInInformationBecameAvailable,
+        copyWebCryptoMasterKey
+    };
+    WKContextSetClient(m_context.get(), &contextClient.base);
+
     WKContextInjectedBundleClientV1 injectedBundleClient = {
         { 1, this },
         didReceiveMessageFromInjectedBundle,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to