Changeset 158236 in webkit


Ignore:
Timestamp:
Oct 29, 2013, 4:12:43 PM (12 years ago)
Author:
ap@apple.com
Message:

Beef up CryptoKey
https://bugs.webkit.org/show_bug.cgi?id=123462

Reviewed by Sam Weinig.

  • WebCore.xcodeproj/project.pbxproj: Added new files.
  • crypto/CryptoAlgorithmIdentifier.h: Added an enum with all registered algorithms

(they don't have to be all implemented in any port).

  • crypto/CryptoKey.cpp:

(WebCore::CryptoKey::CryptoKey): Initialize base class variables.
(WebCore::CryptoKey::type): Convert internal representation for bindings use.
(WebCore::CryptoKey::buildAlgorithmDescription): Ditto. This function is supposed
to be called by derived classes before adding other keyes.
(WebCore::CryptoKey::usages): Convert internal representation for bindings use.

  • crypto/CryptoKey.h:

(WebCore::CryptoKey::extractable): Expose for bindings.
(WebCore::CryptoKey::allows): A faster way to check allowed key usage from C++ code.

  • crypto/CryptoKey.idl: Added SkipVTableValidation, because validation doesn't work

with derived classes. Corrected "usages" attribute name.

  • crypto/CryptoKeyFormat.h: Added.
  • crypto/CryptoKeyType.h: Added.
  • crypto/CryptoKeyUsage.h: Added.

Added enums used by CryptoKey.

Location:
trunk/Source/WebCore
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r158235 r158236  
     12013-10-29  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Beef up CryptoKey
     4        https://bugs.webkit.org/show_bug.cgi?id=123462
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebCore.xcodeproj/project.pbxproj: Added new files.
     9
     10        * crypto/CryptoAlgorithmIdentifier.h: Added an enum with all registered algorithms
     11        (they don't have to be all implemented in any port).
     12
     13        * crypto/CryptoKey.cpp:
     14        (WebCore::CryptoKey::CryptoKey): Initialize base class variables.
     15        (WebCore::CryptoKey::type): Convert internal representation for bindings use.
     16        (WebCore::CryptoKey::buildAlgorithmDescription): Ditto. This function is supposed
     17        to be called by derived classes before adding other keyes.
     18        (WebCore::CryptoKey::usages): Convert internal representation for bindings use.
     19
     20        * crypto/CryptoKey.h:
     21        (WebCore::CryptoKey::extractable): Expose for bindings.
     22        (WebCore::CryptoKey::allows): A faster way to check allowed key usage from C++ code.
     23
     24        * crypto/CryptoKey.idl: Added SkipVTableValidation, because validation doesn't work
     25        with derived classes. Corrected "usages" attribute name.
     26
     27        * crypto/CryptoKeyFormat.h: Added.
     28        * crypto/CryptoKeyType.h: Added.
     29        * crypto/CryptoKeyUsage.h: Added.
     30        Added enums used by CryptoKey.
     31
    1322013-10-29  Hugo Parente Lima  <hugo.lima@openbossa.org>
    233
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r158232 r158236  
    55595559                E16A84F914C85CCC002977DF /* CSSBorderImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E16A84F714C85CCC002977DF /* CSSBorderImage.cpp */; };
    55605560                E16A84FA14C85CCC002977DF /* CSSBorderImage.h in Headers */ = {isa = PBXBuildFile; fileRef = E16A84F814C85CCC002977DF /* CSSBorderImage.h */; };
     5561                E172AF70180F289500FBADB9 /* CryptoKeyUsage.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */; };
     5562                E172AF77180F366C00FBADB9 /* CryptoKeyFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF76180F366C00FBADB9 /* CryptoKeyFormat.h */; };
    55615563                E17B491516A9B094001C8839 /* TransitionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E17B491316A9B093001C8839 /* TransitionEvent.cpp */; };
    55625564                E17B491616A9B094001C8839 /* TransitionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E17B491416A9B093001C8839 /* TransitionEvent.h */; };
     
    55735575                E187056316E54A0D00585E97 /* MainThreadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = E187056216E54A0D00585E97 /* MainThreadTask.h */; };
    55745576                E18772F1126E2629003DD586 /* Language.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18772F0126E2629003DD586 /* Language.cpp */; };
     5577                E19727161820549E00592D51 /* CryptoKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = E19727151820549E00592D51 /* CryptoKeyType.h */; };
    55755578                E1A1470811102B1500EEC0F3 /* ContainerNodeAlgorithms.h in Headers */ = {isa = PBXBuildFile; fileRef = E1A1470711102B1500EEC0F3 /* ContainerNodeAlgorithms.h */; };
    55765579                E1A3162D134BC32D007C9A4F /* WebNSAttributedStringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E1A3162B134BC32D007C9A4F /* WebNSAttributedStringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    56205623                E1C4DE690EA75C1E0023CCD6 /* ActiveDOMObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
    56215624                E1C4DE6E0EA75C650023CCD6 /* ActiveDOMObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */; };
     5625                E1C657251816E69D00256CDD /* CryptoAlgorithmIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */; };
    56225626                E1C8BE5D0E8BD15A0064CB7D /* JSWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C8BE5C0E8BD15A0064CB7D /* JSWorker.cpp */; };
    56235627                E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1CA5CBB0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp */; };
     
    1256012564                E16A84F714C85CCC002977DF /* CSSBorderImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSBorderImage.cpp; sourceTree = "<group>"; };
    1256112565                E16A84F814C85CCC002977DF /* CSSBorderImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSBorderImage.h; sourceTree = "<group>"; };
     12566                E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyUsage.h; sourceTree = "<group>"; };
     12567                E172AF76180F366C00FBADB9 /* CryptoKeyFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyFormat.h; sourceTree = "<group>"; };
    1256212568                E176580C180DF3A0005A96D1 /* OESElementIndexUint.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = OESElementIndexUint.idl; path = canvas/OESElementIndexUint.idl; sourceTree = "<group>"; };
    1256312569                E17B490B16A97269001C8839 /* TransitionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TransitionEvent.idl; sourceTree = "<group>"; };
     
    1257612582                E187056216E54A0D00585E97 /* MainThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThreadTask.h; sourceTree = "<group>"; };
    1257712583                E18772F0126E2629003DD586 /* Language.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Language.cpp; sourceTree = "<group>"; };
     12584                E19727151820549E00592D51 /* CryptoKeyType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyType.h; sourceTree = "<group>"; };
    1257812585                E1A1470711102B1500EEC0F3 /* ContainerNodeAlgorithms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContainerNodeAlgorithms.h; sourceTree = "<group>"; };
    1257912586                E1A3162B134BC32D007C9A4F /* WebNSAttributedStringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNSAttributedStringExtras.h; sourceTree = "<group>"; };
     
    1263012637                E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActiveDOMObject.h; sourceTree = "<group>"; };
    1263112638                E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActiveDOMObject.cpp; sourceTree = "<group>"; };
     12639                E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmIdentifier.h; sourceTree = "<group>"; };
    1263212640                E1C6CFC21746D293007B87A1 /* DOMWindowConstructors.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMWindowConstructors.idl; sourceTree = "<group>"; };
    1263312641                E1C8BE5C0E8BD15A0064CB7D /* JSWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorker.cpp; sourceTree = "<group>"; };
     
    2023120239                                E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */,
    2023220240                                E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */,
     20241                                E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */,
    2023320242                                E157A8DC18172C2C009F821D /* CryptoKey.idl */,
    2023420243                                E157A8E218173A3A009F821D /* CryptoKey.cpp */,
    2023520244                                E157A8E318173A3A009F821D /* CryptoKey.h */,
     20245                                E172AF76180F366C00FBADB9 /* CryptoKeyFormat.h */,
     20246                                E19727151820549E00592D51 /* CryptoKeyType.h */,
     20247                                E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */,
    2023620248                                E1FF8F5C1807364B00132674 /* SubtleCrypto.idl */,
    2023720249                                E1FF8F5D1807442100132674 /* SubtleCrypto.cpp */,
     
    2260122613                                658436860AE01B7400E53753 /* FrameLoadRequest.h in Headers */,
    2260222614                                628D214E12131EF40055DCFC /* FrameNetworkingContext.h in Headers */,
     22615                                E172AF70180F289500FBADB9 /* CryptoKeyUsage.h in Headers */,
    2260322616                                93309E0E099E64920056E581 /* FrameSelection.h in Headers */,
    2260422617                                7CE30DAA171B63D200EC33E1 /* FrameSnapshottingMac.h in Headers */,
     
    2300423017                                A9D247FF0D757E6900FDF959 /* JSDOMPlugin.h in Headers */,
    2300523018                                A9D248010D757E6900FDF959 /* JSDOMPluginArray.h in Headers */,
     23019                                E19727161820549E00592D51 /* CryptoKeyType.h in Headers */,
    2300623020                                BC5A86B60C3367E800EEA649 /* JSDOMSelection.h in Headers */,
    2300723021                                4ACBC0CB12713D0A0094F9B2 /* JSDOMSettableTokenList.h in Headers */,
     
    2321823232                                1AFE119A0CBFFCC4003017FA /* JSSQLResultSetRowList.h in Headers */,
    2321923233                                B59DD6A511902A62007E9684 /* JSSQLStatementCallback.h in Headers */,
     23234                                E172AF77180F366C00FBADB9 /* CryptoKeyFormat.h in Headers */,
    2322023235                                B59DD6A911902A71007E9684 /* JSSQLStatementErrorCallback.h in Headers */,
    2322123236                                BC82432A0D0CE8A200460C8F /* JSSQLTransaction.h in Headers */,
     
    2460624621                                AAA728F716D1D8BC00D3BBC6 /* WebAccessibilityObjectWrapperIOS.h in Headers */,
    2460724622                                AA478A7F16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.h in Headers */,
     24623                                E1C657251816E69D00256CDD /* CryptoAlgorithmIdentifier.h in Headers */,
    2460824624                                93F199A808245E59001E9ABC /* WebCoreFrameView.h in Headers */,
    2460924625                                CDC69DDA16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.h in Headers */,
  • trunk/Source/WebCore/crypto/CryptoKey.cpp

    r157936 r158236  
    3030
    3131#include "CryptoAlgorithmDescriptionBuilder.h"
     32#include "CryptoAlgorithmRegistry.h"
     33#include <wtf/text/WTFString.h>
    3234
    3335namespace WebCore {
     36
     37CryptoKey::CryptoKey(CryptoAlgorithmIdentifier algorithm, CryptoKeyType type, bool extractable, CryptoKeyUsage usages)
     38    : m_algorithm(algorithm)
     39    , m_type(type)
     40    , m_extractable(extractable)
     41    , m_usages(usages)
     42{
     43}
    3444
    3545CryptoKey::~CryptoKey()
     
    3747}
    3848
    39 void CryptoKey::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& /*builder*/) const
     49String CryptoKey::type() const
    4050{
    41     // Will do something like builder.add("name", m_algorithmName);
     51    switch (m_type) {
     52    case CryptoKeyType::Secret:
     53        return ASCIILiteral("secret");
     54    case CryptoKeyType::Public:
     55        return ASCIILiteral("public");
     56    case CryptoKeyType::Private:
     57        return ASCIILiteral("private");
     58    }
     59}
     60
     61void CryptoKey::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
     62{
     63    builder.add("name", CryptoAlgorithmRegistry::shared().nameForIdentifier(m_algorithm));
    4264    // Subclasses will add other keys.
     65}
     66
     67Vector<String> CryptoKey::usages() const
     68{
     69    Vector<String> result;
     70    if (m_usages & CryptoKeyUsageEncrypt)
     71        result.append(ASCIILiteral("encrypt"));
     72    if (m_usages & CryptoKeyUsageDecrypt)
     73        result.append(ASCIILiteral("decrypt"));
     74    if (m_usages & CryptoKeyUsageSign)
     75        result.append(ASCIILiteral("sign"));
     76    if (m_usages & CryptoKeyUsageVerify)
     77        result.append(ASCIILiteral("verify"));
     78    if (m_usages & CryptoKeyUsageDeriveKey)
     79        result.append(ASCIILiteral("deriveKey"));
     80    if (m_usages & CryptoKeyUsageDeriveBits)
     81        result.append(ASCIILiteral("deriveBits"));
     82    if (m_usages & CryptoKeyUsageWrapKey)
     83        result.append(ASCIILiteral("wrapKey"));
     84    if (m_usages & CryptoKeyUsageUnwrapKey)
     85        result.append(ASCIILiteral("unwrapKey"));
     86
     87    return result;
    4388}
    4489
  • trunk/Source/WebCore/crypto/CryptoKey.h

    r157936 r158236  
    2727#define CryptoKey_h
    2828
     29#include "CryptoAlgorithmIdentifier.h"
     30#include "CryptoKeyType.h"
     31#include "CryptoKeyUsage.h"
    2932#include <wtf/Forward.h>
    3033#include <wtf/RefCounted.h>
     
    3740class CryptoAlgorithmDescriptionBuilder;
    3841
     42ENUM_CLASS(CryptoKeyType) {
     43    Secret,
     44    Public,
     45    Private
     46};
     47
    3948class CryptoKey : public RefCounted<CryptoKey> {
    4049public:
     50    CryptoKey(CryptoAlgorithmIdentifier, CryptoKeyType, bool extractable, CryptoKeyUsage);
    4151    virtual ~CryptoKey();
    4252
    43     virtual String type() const = 0;
    44     virtual bool extractable() const = 0;
     53    String type() const;
     54    bool extractable() const { return m_extractable; }
    4555    virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const;
    46     virtual Vector<String> usage() const = 0;
     56    Vector<String> usages() const;
     57
     58    bool allows(CryptoKeyUsage usage) const { return usage == (m_usages & usage); }
     59
     60private:
     61    CryptoAlgorithmIdentifier m_algorithm;
     62    CryptoKeyType m_type;
     63    bool m_extractable;
     64    CryptoKeyUsage m_usages;
    4765};
    4866
  • trunk/Source/WebCore/crypto/CryptoKey.idl

    r157936 r158236  
    4545    InterfaceName=Key,
    4646    NoInterfaceObject,
    47     OperationsNotDeletable
     47    OperationsNotDeletable,
     48    SkipVTableValidation
    4849] interface CryptoKey {
    4950    readonly attribute KeyType type;
    5051    readonly attribute boolean extractable;
    5152    [Custom] readonly attribute Algorithm algorithm;
    52     readonly attribute KeyUsage[] usage;
     53    readonly attribute KeyUsage[] usages;
    5354};
Note: See TracChangeset for help on using the changeset viewer.