Changeset 159944 in webkit


Ignore:
Timestamp:
Dec 2, 2013 11:50:51 AM (10 years ago)
Author:
ap@apple.com
Message:

Add support for WebCrypto RSA-OAEP
https://bugs.webkit.org/show_bug.cgi?id=125084

Reviewed by Sam Weinig.

Source/WebCore:

Tests: crypto/subtle/rsa-oaep-key-manipulation.html

crypto/subtle/rsa-oaep-plaintext-length.html
crypto/subtle/rsa-oaep-wrap-unwrap-aes.html

  • WebCore.xcodeproj/project.pbxproj: Added new files.
  • bindings/js/JSCryptoAlgorithmDictionary.cpp:

(WebCore::createRsaOaepParams):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
Added RSA-OAEP parameters.

  • bindings/js/JSCryptoKeySerializationJWK.cpp:

(WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
(WebCore::JSCryptoKeySerializationJWK::keySizeIsValid):
(WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON):
Support RSA-OAEP in JWK. It is more limited than general WebCrypto, as JWK only
allows SHA-1 as hash.

  • crypto/CommonCryptoUtilities.cpp: Added. (WebCore::getCommonCryptoDigestAlgorithm):
  • crypto/CommonCryptoUtilities.h: Added.

Extracted some shared code and forward declarations for CommonCrypto.

  • crypto/CryptoAlgorithmParameters.h: (WebCore::CryptoAlgorithmParameters::Class):
  • crypto/parameters/CryptoAlgorithmRsaOaepParams.h: Added.

Added RsaOaepParams.

  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp: Added.
  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.h: Added.
  • crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp: Added.
  • crypto/mac/CryptoAlgorithmHMACMac.cpp:

(WebCore::getCommonCryptoHMACAlgorithm):
(WebCore::CryptoAlgorithmHMAC::platformSign):
(WebCore::CryptoAlgorithmHMAC::platformVerify):

  • crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
  • crypto/mac/CryptoKeyMac.cpp:
  • crypto/mac/CryptoKeyRSAMac.cpp:

Use CommonCryptoUtilities.

  • crypto/mac/CryptoAlgorithmRegistryMac.cpp:

(WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Register RSA-OAEP.

LayoutTests:

  • crypto/subtle/rsa-oaep-key-manipulation-expected.txt: Added.
  • crypto/subtle/rsa-oaep-key-manipulation.html: Added.
  • crypto/subtle/rsa-oaep-plaintext-length-expected.txt: Added.
  • crypto/subtle/rsa-oaep-plaintext-length.html: Added.
  • crypto/subtle/rsa-oaep-wrap-unwrap-aes-expected.txt: Added.
  • crypto/subtle/rsa-oaep-wrap-unwrap-aes.html: Added.
Location:
trunk
Files:
12 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r159943 r159944  
     12013-12-02  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Add support for WebCrypto RSA-OAEP
     4        https://bugs.webkit.org/show_bug.cgi?id=125084
     5
     6        Reviewed by Sam Weinig.
     7
     8        * crypto/subtle/rsa-oaep-key-manipulation-expected.txt: Added.
     9        * crypto/subtle/rsa-oaep-key-manipulation.html: Added.
     10        * crypto/subtle/rsa-oaep-plaintext-length-expected.txt: Added.
     11        * crypto/subtle/rsa-oaep-plaintext-length.html: Added.
     12        * crypto/subtle/rsa-oaep-wrap-unwrap-aes-expected.txt: Added.
     13        * crypto/subtle/rsa-oaep-wrap-unwrap-aes.html: Added.
     14
    1152013-12-01  Filip Pizlo  <fpizlo@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r159939 r159944  
     12013-12-02  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Add support for WebCrypto RSA-OAEP
     4        https://bugs.webkit.org/show_bug.cgi?id=125084
     5
     6        Reviewed by Sam Weinig.
     7
     8        Tests: crypto/subtle/rsa-oaep-key-manipulation.html
     9               crypto/subtle/rsa-oaep-plaintext-length.html
     10               crypto/subtle/rsa-oaep-wrap-unwrap-aes.html
     11
     12        * WebCore.xcodeproj/project.pbxproj: Added new files.
     13
     14        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
     15        (WebCore::createRsaOaepParams):
     16        (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt):
     17        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt):
     18        (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
     19        Added RSA-OAEP parameters.
     20
     21        * bindings/js/JSCryptoKeySerializationJWK.cpp:
     22        (WebCore::JSCryptoKeySerializationJWK::reconcileAlgorithm):
     23        (WebCore::JSCryptoKeySerializationJWK::keySizeIsValid):
     24        (WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON):
     25        Support RSA-OAEP in JWK. It is more limited than general WebCrypto, as JWK only
     26        allows SHA-1 as hash.
     27
     28        * crypto/CommonCryptoUtilities.cpp: Added. (WebCore::getCommonCryptoDigestAlgorithm):
     29        * crypto/CommonCryptoUtilities.h: Added.
     30        Extracted some shared code and forward declarations for CommonCrypto.
     31
     32        * crypto/CryptoAlgorithmParameters.h: (WebCore::CryptoAlgorithmParameters::Class):
     33        * crypto/parameters/CryptoAlgorithmRsaOaepParams.h: Added.
     34        Added RsaOaepParams.
     35
     36        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp: Added.
     37        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h: Added.
     38        * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp: Added.
     39
     40        * crypto/mac/CryptoAlgorithmHMACMac.cpp:
     41        (WebCore::getCommonCryptoHMACAlgorithm):
     42        (WebCore::CryptoAlgorithmHMAC::platformSign):
     43        (WebCore::CryptoAlgorithmHMAC::platformVerify):
     44        * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
     45        * crypto/mac/CryptoKeyMac.cpp:
     46        * crypto/mac/CryptoKeyRSAMac.cpp:
     47        Use CommonCryptoUtilities.
     48
     49        * crypto/mac/CryptoAlgorithmRegistryMac.cpp:
     50        (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Register RSA-OAEP.
     51
    1522013-12-02  Andres Gomez  <agomez@igalia.com>
    253
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r159856 r159944  
    57295729                E1FE13641834351100892F13 /* CryptoDigestMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FE13621834351100892F13 /* CryptoDigestMac.cpp */; };
    57305730                E1FE136718343A1000892F13 /* CryptoDigest.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FE136618343A1000892F13 /* CryptoDigest.h */; };
     5731                E1FE136A183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FE1368183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp */; };
     5732                E1FE136B183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FE1369183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h */; };
     5733                E1FE136D183FE21D00892F13 /* CryptoAlgorithmRsaOaepParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FE136C183FE21D00892F13 /* CryptoAlgorithmRsaOaepParams.h */; };
     5734                E1FE1370183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FE136E183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp */; };
     5735                E1FE137418402A6700892F13 /* CommonCryptoUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FE137218402A6700892F13 /* CommonCryptoUtilities.cpp */; };
     5736                E1FE137518402A6700892F13 /* CommonCryptoUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FE137318402A6700892F13 /* CommonCryptoUtilities.h */; };
    57315737                E1FF57A30F01255B00891EBB /* ThreadGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; };
    57325738                E1FF57A60F01256B00891EBB /* ThreadGlobalData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */; };
     
    1284912855                E1FE13621834351100892F13 /* CryptoDigestMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoDigestMac.cpp; path = mac/CryptoDigestMac.cpp; sourceTree = "<group>"; };
    1285012856                E1FE136618343A1000892F13 /* CryptoDigest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoDigest.h; sourceTree = "<group>"; };
     12857                E1FE1368183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSA_OAEP.cpp; sourceTree = "<group>"; };
     12858                E1FE1369183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRSA_OAEP.h; sourceTree = "<group>"; };
     12859                E1FE136C183FE21D00892F13 /* CryptoAlgorithmRsaOaepParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoAlgorithmRsaOaepParams.h; path = parameters/CryptoAlgorithmRsaOaepParams.h; sourceTree = "<group>"; };
     12860                E1FE136E183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmRSA_OAEPMac.cpp; path = mac/CryptoAlgorithmRSA_OAEPMac.cpp; sourceTree = "<group>"; };
     12861                E1FE137218402A6700892F13 /* CommonCryptoUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommonCryptoUtilities.cpp; sourceTree = "<group>"; };
     12862                E1FE137318402A6700892F13 /* CommonCryptoUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonCryptoUtilities.h; sourceTree = "<group>"; };
    1285112863                E1FF57A20F01255B00891EBB /* ThreadGlobalData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadGlobalData.h; sourceTree = "<group>"; };
    1285212864                E1FF57A50F01256B00891EBB /* ThreadGlobalData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadGlobalData.cpp; sourceTree = "<group>"; };
     
    2040720419                        isa = PBXGroup;
    2040820420                        children = (
     20421                                E1FE137218402A6700892F13 /* CommonCryptoUtilities.cpp */,
     20422                                E1FE137318402A6700892F13 /* CommonCryptoUtilities.h */,
    2040920423                                E125F843182425C900D84CD9 /* CryptoAlgorithmAES_CBCMac.cpp */,
    2041020424                                E125F8371822F1EB00D84CD9 /* CryptoAlgorithmHMACMac.cpp */,
    2041120425                                E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */,
    2041220426                                E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */,
     20427                                E1FE136E183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp */,
    2041320428                                E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
    2041420429                                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
     
    2042520440                                E125F82F1822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp */,
    2042620441                                E125F8301822F11B00D84CD9 /* CryptoAlgorithmHMAC.h */,
     20442                                E1FE1368183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp */,
     20443                                E1FE1369183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h */,
    2042720444                                E1BD3317182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp */,
    2042820445                                E1BD3318182D8DDD00C05D9F /* CryptoAlgorithmRSASSA_PKCS1_v1_5.h */,
     
    2243822455                                93309DDF099E64920056E581 /* DeleteFromTextNodeCommand.h in Headers */,
    2243922456                                07C59B6417F4D1C4000FBCBB /* MockMediaStreamCenter.h in Headers */,
     22457                                E1FE136B183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h in Headers */,
    2244022458                                93309DE1099E64920056E581 /* DeleteSelectionCommand.h in Headers */,
    2244122459                                FD1660A513787C6D001FFA7B /* DenormalDisabler.h in Headers */,
     
    2258722605                                2ED609BD1145B07100C8684E /* DOMFormData.h in Headers */,
    2258822606                                BC1A37B6097C715F0019F3D8 /* DOMHTML.h in Headers */,
     22607                                E1FE137518402A6700892F13 /* CommonCryptoUtilities.h in Headers */,
    2258922608                                85DF81270AA7787200486AD7 /* DOMHTMLAnchorElement.h in Headers */,
    2259022609                                B595FF471824CEE300FF51CD /* RenderIterator.h in Headers */,
     
    2370723726                                078E092B17D14D1C00420AA1 /* RTCStatsRequestImpl.h in Headers */,
    2370823727                                B266CD4E0C3AEC6500EB08D2 /* JSSVGException.h in Headers */,
     23728                                E1FE136D183FE21D00892F13 /* CryptoAlgorithmRsaOaepParams.h in Headers */,
    2370923729                                B2FA3D6B0AB75A6F000E5AC4 /* JSSVGFEBlendElement.h in Headers */,
    2371023730                                B2FA3D6D0AB75A6F000E5AC4 /* JSSVGFEColorMatrixElement.h in Headers */,
     
    2671326733                                BC6932730D7E293900AE44D1 /* JSDOMWindowBase.cpp in Sources */,
    2671426734                                BCD9C2620C17AA67005C90A2 /* JSDOMWindowCustom.cpp in Sources */,
     26735                                E1FE136A183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp in Sources */,
    2671526736                                BCBFB53C0DCD29CF0019B3E5 /* JSDOMWindowShell.cpp in Sources */,
    2671626737                                FD7868B9136B999200D403DF /* JSDynamicsCompressorNode.cpp in Sources */,
     
    2816028181                                2E3BBF071162DA1100B9409A /* UUID.cpp in Sources */,
    2816128182                                50D32857163B313F0016111E /* ValidatedCustomFilterOperation.cpp in Sources */,
     28183                                E1FE137418402A6700892F13 /* CommonCryptoUtilities.cpp in Sources */,
    2816228184                                F5A154271279534D00D0B0C0 /* ValidationMessage.cpp in Sources */,
    2816328185                                FD3160AE12B026F700C1A359 /* VectorMath.cpp in Sources */,
     
    2820328225                                A0EE0DF5144F825500F80B0D /* WebGLDebugRendererInfo.cpp in Sources */,
    2820428226                                A0EE0DF7144F825500F80B0D /* WebGLDebugShaders.cpp in Sources */,
     28227                                E1FE1370183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp in Sources */,
    2820528228                                6E3FAE8E14733FDB00E42307 /* WebGLDepthTexture.cpp in Sources */,
    2820628229                                6EBF0E5412A8929800DB1709 /* WebGLExtension.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp

    r159717 r159944  
    3636#include "CryptoAlgorithmRsaKeyGenParams.h"
    3737#include "CryptoAlgorithmRsaKeyParamsWithHash.h"
     38#include "CryptoAlgorithmRsaOaepParams.h"
    3839#include "CryptoAlgorithmRsaSsaParams.h"
    3940#include "ExceptionCode.h"
     
    245246}
    246247
    247 static std::unique_ptr<CryptoAlgorithmParameters> createRsaSsaParams(ExecState* exec, JSValue value)
     248static std::unique_ptr<CryptoAlgorithmParameters> createRsaOaepParams(ExecState* exec, JSValue value)
    248249{
    249250    if (!value.isObject()) {
     
    253254
    254255    JSDictionary jsDictionary(exec, value.getObject());
    255     auto result = std::make_unique<CryptoAlgorithmRsaSsaParams>();
     256    auto result = std::make_unique<CryptoAlgorithmRsaOaepParams>();
    256257
    257258    if (!getHashAlgorithm(jsDictionary, result->hash)) {
     
    260261    }
    261262
     263    JSValue labelValue = getProperty(exec, value.getObject(), "label");
     264    if (exec->hadException())
     265        return nullptr;
     266
     267    result->hasLabel = !labelValue.isUndefinedOrNull();
     268    if (!result->hasLabel)
     269        return std::move(result);
     270
     271    CryptoOperationData labelData;
     272    if (!cryptoOperationDataFromJSValue(exec, labelValue, labelData)) {
     273        ASSERT(exec->hadException());
     274        return nullptr;
     275    }
     276
     277    result->label.append(labelData.first, labelData.second);
     278
    262279    return std::move(result);
    263280}
    264281
     282static std::unique_ptr<CryptoAlgorithmParameters> createRsaSsaParams(ExecState* exec, JSValue value)
     283{
     284    if (!value.isObject()) {
     285        throwTypeError(exec);
     286        return nullptr;
     287    }
     288
     289    JSDictionary jsDictionary(exec, value.getObject());
     290    auto result = std::make_unique<CryptoAlgorithmRsaSsaParams>();
     291
     292    if (!getHashAlgorithm(jsDictionary, result->hash)) {
     293        ASSERT(exec->hadException());
     294        return nullptr;
     295    }
     296
     297    return std::move(result);
     298}
     299
    265300std::unique_ptr<CryptoAlgorithmParameters> JSCryptoAlgorithmDictionary::createParametersForEncrypt(ExecState* exec, CryptoAlgorithmIdentifier algorithm, JSValue value)
    266301{
     
    269304    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    270305    case CryptoAlgorithmIdentifier::RSA_PSS:
    271     case CryptoAlgorithmIdentifier::RSA_OAEP:
     306        setDOMException(exec, NOT_SUPPORTED_ERR);
     307        return nullptr;
     308    case CryptoAlgorithmIdentifier::RSA_OAEP:
     309        return createRsaOaepParams(exec, value);
    272310    case CryptoAlgorithmIdentifier::ECDSA:
    273311    case CryptoAlgorithmIdentifier::ECDH:
     
    301339    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
    302340    case CryptoAlgorithmIdentifier::RSA_PSS:
    303     case CryptoAlgorithmIdentifier::RSA_OAEP:
     341        setDOMException(exec, NOT_SUPPORTED_ERR);
     342        return nullptr;
     343    case CryptoAlgorithmIdentifier::RSA_OAEP:
     344        return createRsaOaepParams(exec, value);
    304345    case CryptoAlgorithmIdentifier::ECDSA:
    305346    case CryptoAlgorithmIdentifier::ECDH:
     
    529570        return createRsaKeyParamsWithHash(exec, value);
    530571    case CryptoAlgorithmIdentifier::RSA_PSS:
    531     case CryptoAlgorithmIdentifier::RSA_OAEP:
    532     case CryptoAlgorithmIdentifier::ECDSA:
    533     case CryptoAlgorithmIdentifier::ECDH:
    534     case CryptoAlgorithmIdentifier::AES_CTR:
    535     case CryptoAlgorithmIdentifier::AES_CBC:
    536     case CryptoAlgorithmIdentifier::AES_CMAC:
    537     case CryptoAlgorithmIdentifier::AES_GCM:
    538     case CryptoAlgorithmIdentifier::AES_CFB:
    539572        return std::make_unique<CryptoAlgorithmParameters>();
     573    case CryptoAlgorithmIdentifier::RSA_OAEP:
     574        return createRsaKeyParamsWithHash(exec, value);
     575    case CryptoAlgorithmIdentifier::ECDSA:
     576    case CryptoAlgorithmIdentifier::ECDH:
     577    case CryptoAlgorithmIdentifier::AES_CTR:
     578    case CryptoAlgorithmIdentifier::AES_CBC:
     579    case CryptoAlgorithmIdentifier::AES_CMAC:
     580    case CryptoAlgorithmIdentifier::AES_GCM:
     581    case CryptoAlgorithmIdentifier::AES_CFB:
     582        return std::make_unique<CryptoAlgorithmParameters>();
    540583    case CryptoAlgorithmIdentifier::HMAC:
    541584        return createHmacParams(exec, value);
  • trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp

    r159717 r159944  
    191191        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5);
    192192        parameters = createRSAKeyParametersWithHash(CryptoAlgorithmIdentifier::SHA_512);
     193    } else if (m_jwkAlgorithmName == "RSA-OAEP") {
     194        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::RSA_OAEP);
     195        parameters = createRSAKeyParametersWithHash(CryptoAlgorithmIdentifier::SHA_1);
    193196    } else if (m_jwkAlgorithmName == "A128CBC") {
    194197        algorithm = CryptoAlgorithmRegistry::shared().create(CryptoAlgorithmIdentifier::AES_CBC);
     
    219222    if (algorithm->identifier() == CryptoAlgorithmIdentifier::HMAC)
    220223        return toCryptoAlgorithmHmacParams(*parameters).hash == toCryptoAlgorithmHmacParams(*suggestedParameters).hash;
    221     if (algorithm->identifier() == CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5) {
     224    if (algorithm->identifier() == CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5
     225        || algorithm->identifier() == CryptoAlgorithmIdentifier::RSA_OAEP) {
    222226        CryptoAlgorithmRsaKeyParamsWithHash& rsaKeyParameters = toCryptoAlgorithmRsaKeyParamsWithHash(*parameters);
    223227        CryptoAlgorithmRsaKeyParamsWithHash& suggestedRSAKeyParameters = toCryptoAlgorithmRsaKeyParamsWithHash(*suggestedParameters);
     
    284288    if (m_jwkAlgorithmName == "RS512")
    285289        return sizeInBits >= 2048;
     290    if (m_jwkAlgorithmName == "RSA_OAEP")
     291        return sizeInBits >= 2048;
    286292    return true;
    287293}
     
    537543            break;
    538544        }
     545        break;
     546    }
     547    case CryptoAlgorithmIdentifier::RSA_OAEP: {
     548        const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key);
     549        CryptoAlgorithmIdentifier hash;
     550        // WebCrypto RSA-OAEP keys are not tied to any particular hash, unless previously imported from JWK, which only supports SHA-1.
     551        if (rsaKey.isRestrictedToHash(hash) && hash != CryptoAlgorithmIdentifier::SHA_1)
     552            break;
     553        if (rsaKey.keySizeInBits() < 2048)
     554            break;
     555        jwkAlgorithm = "RSA-OAEP";
    539556        break;
    540557    }
  • trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h

    r159717 r159944  
    4747        RsaKeyGenParams,
    4848        RsaKeyParamsWithHash,
     49        RsaOaepParams,
    4950        RsaSsaParams
    5051    };
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp

    r159717 r159944  
    3636namespace WebCore {
    3737
    38 static bool getCommonCryptoAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCHmacAlgorithm& algorithm)
     38static bool getCommonCryptoHMACAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCHmacAlgorithm& algorithm)
    3939{
    4040    switch (hashFunction) {
     
    9292{
    9393    CCHmacAlgorithm algorithm;
    94     if (!getCommonCryptoAlgorithm(parameters.hash, algorithm)) {
     94    if (!getCommonCryptoHMACAlgorithm(parameters.hash, algorithm)) {
    9595        ec = NOT_SUPPORTED_ERR;
    9696        return;
     
    105105{
    106106    CCHmacAlgorithm algorithm;
    107     if (!getCommonCryptoAlgorithm(parameters.hash, algorithm)) {
     107    if (!getCommonCryptoHMACAlgorithm(parameters.hash, algorithm)) {
    108108        ec = NOT_SUPPORTED_ERR;
    109109        return;
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp

    r159717 r159944  
    2929#if ENABLE(SUBTLE_CRYPTO)
    3030
     31#include "CommonCryptoUtilities.h"
    3132#include "CryptoAlgorithmRsaSsaParams.h"
    3233#include "CryptoDigest.h"
     
    3536#include <CommonCrypto/CommonCryptor.h>
    3637
    37 #if defined(__has_include)
    38 #if __has_include(<CommonCrypto/CommonRSACryptor.h>)
    39 #include <CommonCrypto/CommonRSACryptor.h>
    40 #endif
    41 #endif
    42 
    43 #ifndef _CC_RSACRYPTOR_H_
    44 enum {
    45     ccPKCS1Padding = 1001
    46 };
    47 typedef uint32_t CCAsymmetricPadding;
    48 
    49 enum {
    50     kCCDigestSHA1 = 8,
    51     kCCDigestSHA224 = 9,
    52     kCCDigestSHA256 = 10,
    53     kCCDigestSHA384 = 11,
    54     kCCDigestSHA512 = 12,
    55 };
    56 typedef uint32_t CCDigestAlgorithm;
    57 
    58 enum {
    59     kCCNotVerified    = -4306
    60 };
    61 #endif
    62 
    63 extern "C" CCCryptorStatus CCRSACryptorSign(CCRSACryptorRef privateKey, CCAsymmetricPadding padding, const void *hashToSign, size_t hashSignLen, CCDigestAlgorithm digestType, size_t saltLen, void *signedData, size_t *signedDataLen);
    64 extern "C" CCCryptorStatus CCRSACryptorVerify(CCRSACryptorRef publicKey, CCAsymmetricPadding padding, const void *hash, size_t hashLen, CCDigestAlgorithm digestType, size_t saltLen, const void *signedData, size_t signedDataLen);
    65 
    6638namespace WebCore {
    67 
    68 static bool getCommonCryptoDigestAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCDigestAlgorithm& algorithm)
    69 {
    70     switch (hashFunction) {
    71     case CryptoAlgorithmIdentifier::SHA_1:
    72         algorithm = kCCDigestSHA1;
    73         return true;
    74     case CryptoAlgorithmIdentifier::SHA_224:
    75         algorithm = kCCDigestSHA224;
    76         return true;
    77     case CryptoAlgorithmIdentifier::SHA_256:
    78         algorithm = kCCDigestSHA256;
    79         return true;
    80     case CryptoAlgorithmIdentifier::SHA_384:
    81         algorithm = kCCDigestSHA384;
    82         return true;
    83     case CryptoAlgorithmIdentifier::SHA_512:
    84         algorithm = kCCDigestSHA512;
    85         return true;
    86     default:
    87         return false;
    88     }
    89 }
    9039
    9140void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp

    r159717 r159944  
    3232#include "CryptoAlgorithmHMAC.h"
    3333#include "CryptoAlgorithmRSASSA_PKCS1_v1_5.h"
     34#include "CryptoAlgorithmRSA_OAEP.h"
    3435#include "CryptoAlgorithmSHA1.h"
    3536#include "CryptoAlgorithmSHA224.h"
     
    4546    registerAlgorithm<CryptoAlgorithmHMAC>();
    4647    registerAlgorithm<CryptoAlgorithmRSASSA_PKCS1_v1_5>();
     48    registerAlgorithm<CryptoAlgorithmRSA_OAEP>();
    4749    registerAlgorithm<CryptoAlgorithmSHA1>();
    4850    registerAlgorithm<CryptoAlgorithmSHA224>();
  • trunk/Source/WebCore/crypto/mac/CryptoKeyMac.cpp

    r159390 r159944  
    2929#if ENABLE(SUBTLE_CRYPTO)
    3030
    31 #if defined(__has_include) && (PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
    32 #if __has_include(<CommonCrypto/CommonRandomSPI.h>)
    33 #include <CommonCrypto/CommonRandomSPI.h>
    34 #endif
    35 #endif
    36 
    37 typedef struct __CCRandom *CCRandomRef;
    38 extern const CCRandomRef kCCRandomDefault;
    39 extern "C" int CCRandomCopyBytes(CCRandomRef rnd, void *bytes, size_t count);
     31#include "CommonCryptoUtilities.h"
    4032
    4133namespace WebCore {
  • trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp

    r159578 r159944  
    2929#if ENABLE(SUBTLE_CRYPTO)
    3030
     31#include "CommonCryptoUtilities.h"
    3132#include "CryptoAlgorithmDescriptionBuilder.h"
    3233#include "CryptoAlgorithmRegistry.h"
     
    3435#include "CryptoKeyPair.h"
    3536#include <CommonCrypto/CommonCryptor.h>
    36 
    37 #if defined(__has_include)
    38 #if __has_include(<CommonCrypto/CommonRSACryptor.h>)
    39 #include <CommonCrypto/CommonRSACryptor.h>
    40 #endif
    41 #endif
    42 
    43 #ifndef _CC_RSACRYPTOR_H_
    44 enum {
    45     ccRSAKeyPublic          = 0,
    46     ccRSAKeyPrivate         = 1
    47 };
    48 typedef uint32_t CCRSAKeyType;
    49 #endif
    50 
    51 extern "C" CCCryptorStatus CCRSACryptorCreateFromData(CCRSAKeyType keyType, uint8_t *modulus, size_t modulusLength, uint8_t *exponent, size_t exponentLength, uint8_t *p, size_t pLength, uint8_t *q, size_t qLength, CCRSACryptorRef *ref);
    52 extern "C" CCCryptorStatus CCRSACryptorGeneratePair(size_t keysize, uint32_t e, CCRSACryptorRef *publicKey, CCRSACryptorRef *privateKey);
    53 extern "C" CCRSACryptorRef CCRSACryptorGetPublicKeyFromPrivateKey(CCRSACryptorRef privkey);
    54 extern "C" void CCRSACryptorRelease(CCRSACryptorRef key);
    55 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);
    56 extern "C" CCRSAKeyType CCRSAGetKeyType(CCRSACryptorRef key);
    5737
    5838namespace WebCore {
Note: See TracChangeset for help on using the changeset viewer.