Changeset 163863 in webkit


Ignore:
Timestamp:
Feb 10, 2014 10:32:39 PM (10 years ago)
Author:
ap@apple.com
Message:

Add hooks for wrapping CryptoKeys in SerializedScriptValue
https://bugs.webkit.org/show_bug.cgi?id=128567

Reviewed by Anders Carlsson.

Source/WebCore:

  • bindings/js/SerializedScriptValue.cpp: Changed SerializedScriptValue to serialize

wrapped keys. Added a version number to crypto key serialization.

  • dom/Document.cpp:

(WebCore::Document::wrapCryptoKey):
(WebCore::Document::unwrapCryptoKey):

  • dom/Document.h:
  • dom/ScriptExecutionContext.h:
  • page/ChromeClient.h:

(WebCore::ChromeClient::wrapCryptoKey):
(WebCore::ChromeClient::unwrapCryptoKey):
Hand wrapping/unwrapping over to client code.

  • workers/WorkerGlobalScope.cpp:

(WebCore::WorkerGlobalScope::wrapCryptoKey):
(WebCore::WorkerGlobalScope::unwrapCryptoKey):

  • workers/WorkerGlobalScope.h:

Not implemented in workers. SubtleCrypto is currently not exposed in workers. It used
to be possible in WebKit implementation to post a CryptoKey to a worker anyway,
but this doesn't work any more.

Source/WebKit/mac:

  • WebCoreSupport/WebChromeClient.h:
  • WebCoreSupport/WebChromeClient.mm:

(WebChromeClient::wrapCryptoKey):
(WebChromeClient::unwrapCryptoKey):
Dummy implementation, to be filled in later.

Source/WebKit2:

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::wrapCryptoKey):
(WebKit::WebChromeClient::unwrapCryptoKey):

  • WebProcess/WebCoreSupport/WebChromeClient.h:

Dummy implementation, to be filled in later.

Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r163858 r163863  
     12014-02-10  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Add hooks for wrapping CryptoKeys in SerializedScriptValue
     4        https://bugs.webkit.org/show_bug.cgi?id=128567
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * bindings/js/SerializedScriptValue.cpp: Changed SerializedScriptValue to serialize
     9        wrapped keys. Added a version number to crypto key serialization.
     10
     11        * dom/Document.cpp:
     12        (WebCore::Document::wrapCryptoKey):
     13        (WebCore::Document::unwrapCryptoKey):
     14        * dom/Document.h:
     15        * dom/ScriptExecutionContext.h:
     16        * page/ChromeClient.h:
     17        (WebCore::ChromeClient::wrapCryptoKey):
     18        (WebCore::ChromeClient::unwrapCryptoKey):
     19        Hand wrapping/unwrapping over to client code.
     20
     21        * workers/WorkerGlobalScope.cpp:
     22        (WebCore::WorkerGlobalScope::wrapCryptoKey):
     23        (WebCore::WorkerGlobalScope::unwrapCryptoKey):
     24        * workers/WorkerGlobalScope.h:
     25        Not implemented in workers. SubtleCrypto is currently not exposed in workers. It used
     26        to be possible in WebKit implementation to post a CryptoKey to a worker anyway,
     27        but this doesn't work any more.
     28
    1292014-02-10  ChangSeok Oh  <changseok.oh@collabora.com>
    230
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r163844 r163863  
    4747#include "JSNavigator.h"
    4848#include "NotImplemented.h"
     49#include "ScriptExecutionContext.h"
    4950#include "SharedBuffer.h"
    5051#include "WebCoreJSClientData.h"
     
    167168#if ENABLE(SUBTLE_CRYPTO)
    168169
     170const uint32_t currentKeyFormatVersion = 1;
     171
    169172enum class CryptoKeyClassSubtag {
    170173    HMAC = 0,
     
    294297 *    | ArrayBufferViewTag ArrayBufferViewSubtag <byteOffset:uint32_t> <byteLength:uint32_t> (ArrayBuffer | ObjectReference)
    295298 *    | ArrayBufferTransferTag <value:uint32_t>
    296  *    | CryptoKeyTag <extractable:int32_t> <usagesCount:uint32_t> <usages:byte{usagesCount}> CryptoKeyClassSubtag (CryptoKeyHMAC | CryptoKeyAES | CryptoKeyRSA)
     299 *    | CryptoKeyTag <wrappedKeyLength:uint32_t> <factor:byte{wrappedKeyLength}>
     300 *
     301 * Inside wrapped crypto key, data is serialized in this format:
     302 *
     303 * <keyFormatVersion:uint32_t> <extractable:int32_t> <usagesCount:uint32_t> <usages:byte{usagesCount}> CryptoKeyClassSubtag (CryptoKeyHMAC | CryptoKeyAES | CryptoKeyRSA)
    297304 *
    298305 * String :-
     
    386393    MarkedArgumentBuffer m_gcBuffer;
    387394};
     395
     396#if ENABLE(SUBTLE_CRYPTO)
     397static bool wrapCryptoKey(ExecState* exec, const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey)
     398{
     399    ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(exec);
     400    if (!scriptExecutionContext)
     401        return false;
     402    return scriptExecutionContext->wrapCryptoKey(key, wrappedKey);
     403}
     404
     405static bool unwrapCryptoKey(ExecState* exec, const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key)
     406{
     407    ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(exec);
     408    if (!scriptExecutionContext)
     409        return false;
     410    return scriptExecutionContext->unwrapCryptoKey(wrappedKey, key);
     411}
     412#endif
    388413
    389414#if ASSUME_LITTLE_ENDIAN
     
    831856            if (CryptoKey* key = toCryptoKey(obj)) {
    832857                write(CryptoKeyTag);
    833                 write(key);
     858                Vector<uint8_t> serializedKey;
     859                Vector<String> dummyBlobURLs;
     860                CloneSerializer rawKeySerializer(m_exec, nullptr, nullptr, dummyBlobURLs, serializedKey);
     861                rawKeySerializer.write(key);
     862                Vector<uint8_t> wrappedKey;
     863                if (!wrapCryptoKey(m_exec, serializedKey, wrappedKey))
     864                    return false;
     865                write(wrappedKey);
    834866                return true;
    835867            }
     
    10961128    void write(const CryptoKey* key)
    10971129    {
     1130        write(currentKeyFormatVersion);
     1131
    10981132        write(key->extractable());
    10991133
     
    19902024    bool readCryptoKey(JSValue& cryptoKey)
    19912025    {
     2026        uint32_t keyFormatVersion;
     2027        if (!read(keyFormatVersion) || keyFormatVersion > currentKeyFormatVersion)
     2028            return false;
     2029
    19922030        int32_t extractable;
    19932031        if (!read(extractable))
     
    22612299#if ENABLE(SUBTLE_CRYPTO)
    22622300        case CryptoKeyTag: {
     2301            Vector<uint8_t> wrappedKey;
     2302            if (!read(wrappedKey)) {
     2303                fail();
     2304                return JSValue();
     2305            }
     2306            Vector<uint8_t> serializedKey;
     2307            if (!unwrapCryptoKey(m_exec, wrappedKey, serializedKey)) {
     2308                fail();
     2309                return JSValue();
     2310            }
    22632311            JSValue cryptoKey;
    2264             if (!readCryptoKey(cryptoKey)) {
     2312            CloneDeserializer rawKeyDeserializer(m_exec, m_globalObject, nullptr, nullptr, serializedKey);
     2313            if (!rawKeyDeserializer.readCryptoKey(cryptoKey)) {
    22652314                fail();
    22662315                return JSValue();
  • trunk/Source/WebCore/dom/Document.cpp

    r163725 r163863  
    59955995}
    59965996
     5997#if ENABLE(SUBTLE_CRYPTO)
     5998bool Document::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey)
     5999{
     6000    Page* page = this->page();
     6001    if (!page)
     6002        return false;
     6003    return page->chrome().client().wrapCryptoKey(key, wrappedKey);
     6004}
     6005
     6006bool Document::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key)
     6007{
     6008    Page* page = this->page();
     6009    if (!page)
     6010        return false;
     6011    return page->chrome().client().unwrapCryptoKey(wrappedKey, key);
     6012}
     6013#endif // ENABLE(SUBTLE_CRYPTO)
     6014
    59976015} // namespace WebCore
  • trunk/Source/WebCore/dom/Document.h

    r163654 r163863  
    12271227    void setVisualUpdatesAllowedByClient(bool);
    12281228
     1229#if ENABLE(SUBTLE_CRYPTO)
     1230    virtual bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) override;
     1231    virtual bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) override;
     1232#endif
     1233
    12291234protected:
    12301235    enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r163568 r163863  
    8989    PublicURLManager& publicURLManager();
    9090#endif
     91
    9192    // Active objects are not garbage collected even if inaccessible, e.g. because their activity may result in callbacks being invoked.
    9293    bool canSuspendActiveDOMObjects();
     
    156157#if ENABLE(SQL_DATABASE)
    157158    void setDatabaseContext(DatabaseContext*);
     159#endif
     160
     161#if ENABLE(SUBTLE_CRYPTO)
     162    virtual bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) = 0;
     163    virtual bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) = 0;
    158164#endif
    159165
  • trunk/Source/WebCore/page/ChromeClient.h

    r163726 r163863  
    404404    virtual bool shouldUseTiledBackingForFrameView(const FrameView*) const { return false; }
    405405
     406#if ENABLE(SUBTLE_CRYPTO)
     407    virtual bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const { return false; }
     408    virtual bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const { return false; }
     409#endif
     410
    406411protected:
    407412    virtual ~ChromeClient() { }
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r163568 r163863  
    344344}
    345345
     346#if ENABLE(SUBTLE_CRYPTO)
     347bool WorkerGlobalScope::wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&)
     348{
     349    return false;
     350}
     351
     352bool WorkerGlobalScope::unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&)
     353{
     354    return false;
     355}
     356#endif // ENABLE(SUBTLE_CRYPTO)
     357
    346358} // namespace WebCore
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r163568 r163863  
    136136        virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) override;
    137137
     138#if ENABLE(SUBTLE_CRYPTO)
     139        virtual bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) override;
     140        virtual bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) override;
     141#endif
     142
    138143    protected:
    139144        WorkerGlobalScope(const URL&, const String& userAgent, std::unique_ptr<GroupSettings>, WorkerThread*, PassRefPtr<SecurityOrigin> topOrigin);
  • trunk/Source/WebKit/mac/ChangeLog

    r163739 r163863  
     12014-02-10  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Add hooks for wrapping CryptoKeys in SerializedScriptValue
     4        https://bugs.webkit.org/show_bug.cgi?id=128567
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * WebCoreSupport/WebChromeClient.h:
     9        * WebCoreSupport/WebChromeClient.mm:
     10        (WebChromeClient::wrapCryptoKey):
     11        (WebChromeClient::unwrapCryptoKey):
     12        Dummy implementation, to be filled in later.
     13
    1142014-02-08  Ryosuke Niwa  <rniwa@webkit.org>
    215
  • trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.h

    r163724 r163863  
    196196    virtual void numWheelEventHandlersChanged(unsigned) override { }
    197197
     198#if ENABLE(SUBTLE_CRYPTO)
     199    virtual bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const override;
     200    virtual bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const override;
     201#endif
     202
    198203#if PLATFORM(IOS)
    199204    WebView* webView() const { return m_webView; }
  • trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm

    r163717 r163863  
    997997}
    998998
    999 #endif
     999#if ENABLE(SUBTLE_CRYPTO)
     1000bool WebChromeClient::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) const
     1001{
     1002    wrappedKey = key;
     1003    return true;
     1004}
     1005
     1006bool WebChromeClient::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) const
     1007{
     1008    key = wrappedKey;
     1009    return true;
     1010}
     1011#endif
     1012
     1013#endif
  • trunk/Source/WebKit2/ChangeLog

    r163862 r163863  
     12014-02-10  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Add hooks for wrapping CryptoKeys in SerializedScriptValue
     4        https://bugs.webkit.org/show_bug.cgi?id=128567
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/WebPageProxy.cpp:
     9        (WebKit::WebPageProxy::wrapCryptoKey):
     10        (WebKit::WebPageProxy::unwrapCryptoKey):
     11        * UIProcess/WebPageProxy.h:
     12        * UIProcess/WebPageProxy.messages.in:
     13        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     14        (WebKit::WebChromeClient::wrapCryptoKey):
     15        (WebKit::WebChromeClient::unwrapCryptoKey):
     16        * WebProcess/WebCoreSupport/WebChromeClient.h:
     17        Dummy implementation, to be filled in later.
     18
    1192014-02-10  Dan Bernstein  <mitz@apple.com>
    220
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r163860 r163863  
    44804480}
    44814481
     4482#if ENABLE(SUBTLE_CRYPTO)
     4483void WebPageProxy::wrapCryptoKey(const Vector<uint8_t>& key, bool& succeeded, Vector<uint8_t>& wrappedKey)
     4484{
     4485    // FIXME: Implement.
     4486    wrappedKey = key;
     4487    succeeded = true;
     4488}
     4489
     4490void WebPageProxy::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, bool& succeeded, Vector<uint8_t>& key)
     4491{
     4492    // FIXME: Implement.
     4493    key = wrappedKey;
     4494    succeeded = true;
     4495}
     4496#endif
     4497
    44824498} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r163836 r163863  
    888888#endif
    889889
     890#if ENABLE(SUBTLE_CRYPTO)
     891    void wrapCryptoKey(const Vector<uint8_t>&, bool& succeeded, Vector<uint8_t>&);
     892    void unwrapCryptoKey(const Vector<uint8_t>&, bool& succeeded, Vector<uint8_t>&);
     893#endif
     894
    890895private:
    891896    WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r163516 r163863  
    335335   
    336336    DidSaveToPageCache()
     337
     338#if ENABLE(SUBTLE_CRYPTO)
     339    WrapCryptoKey(Vector<uint8_t> key) -> (bool succeeded, Vector<uint8_t> wrappedKey)
     340    UnwrapCryptoKey(Vector<uint8_t> wrappedKey) -> (bool succeeded, Vector<uint8_t> key)
     341#endif
    337342}
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r163724 r163863  
    939939}
    940940
     941#if ENABLE(SUBTLE_CRYPTO)
     942bool WebChromeClient::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) const
     943{
     944    bool succeeded;
     945    if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::WrapCryptoKey(key), Messages::WebPageProxy::WrapCryptoKey::Reply(succeeded, wrappedKey), m_page->pageID()))
     946        return false;
     947    return succeeded;
     948}
     949
     950bool WebChromeClient::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) const
     951{
     952    bool succeeded;
     953    if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::UnwrapCryptoKey(wrappedKey), Messages::WebPageProxy::UnwrapCryptoKey::Reply(succeeded, key), m_page->pageID()))
     954        return false;
     955    return succeeded;
     956}
     957#endif
     958
     959
    941960} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r163724 r163863  
    271271    virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) const override;
    272272
     273#if ENABLE(SUBTLE_CRYPTO)
     274    virtual bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const override;
     275    virtual bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const override;
     276#endif
     277
    273278    String m_cachedToolTip;
    274279    mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
Note: See TracChangeset for help on using the changeset viewer.