Changeset 192126 in webkit


Ignore:
Timestamp:
Nov 6, 2015 8:44:02 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore:
Allow an optional hash algorithm to be passed to generateKey for RSA keys.
https://bugs.webkit.org/show_bug.cgi?id=144938

Unreviewed initial submission.

Test: crypto/subtle/rsa-export-generated-keys.html

This changeset allows an optional hash parameter to be passed to the generate
key function for RSA type keys. Previously, there was no way to export generated
keys, as no hash function could be associated with the key (required for JWK).

The current WebCrypto API draft requires the hash function to be specified in the
algorithm object passed to generateKey (http://www.w3.org/TR/WebCryptoAPI 20.4),
however, they were made optional in this implementation to maintain compatiblity.

Patch by Scott Valentine <svalentine@ikayzo.com> on 2015-11-06

  • bindings/js/JSCryptoAlgorithmDictionary.cpp:

(WebCore::getHashAlgorithm):
(WebCore::createHmacParams):
(WebCore::createHmacKeyParams):
(WebCore::createRsaKeyGenParams):
(WebCore::createRsaOaepParams):
(WebCore::createRsaSsaParams):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Deleted.

  • bindings/js/SerializedScriptValue.cpp:

(WebCore::CloneDeserializer::readRSAKey):

  • crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:

(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):

  • crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:

(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):

  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:

(WebCore::CryptoAlgorithmRSA_OAEP::generateKey):
(WebCore::CryptoAlgorithmRSA_OAEP::importKey):

  • crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:

(WebCore::CryptoKeyRSA::CryptoKeyRSA):
(WebCore::CryptoKeyRSA::create):
(WebCore::CryptoKeyRSA::generatePair):
(WebCore::CryptoKeyRSA::restrictToHash): Deleted.

  • crypto/keys/CryptoKeyRSA.h:
  • crypto/mac/CryptoKeyRSAMac.cpp:

(WebCore::CryptoKeyRSA::CryptoKeyRSA):
(WebCore::CryptoKeyRSA::create):
(WebCore::CryptoKeyRSA::generatePair):
(WebCore::CryptoKeyRSA::restrictToHash): Deleted.

  • crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:

LayoutTests:
Adding new tests for exporting generated RSA keys.
https://bugs.webkit.org/show_bug.cgi?id=144938

Unreviewed initial submission.

Patch by Scott Valentine <svalentine@ikayzo.com> on 2015-11-06

  • crypto/subtle/rsa-export-generated-keys-expected.txt: Added.
  • crypto/subtle/rsa-export-generated-keys.html: Added.
Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r192124 r192126  
     12015-11-06  Scott Valentine  <svalentine@ikayzo.com>
     2
     3        Adding new tests for exporting generated RSA keys.
     4        https://bugs.webkit.org/show_bug.cgi?id=144938
     5
     6        Unreviewed initial submission.
     7
     8        * crypto/subtle/rsa-export-generated-keys-expected.txt: Added.
     9        * crypto/subtle/rsa-export-generated-keys.html: Added.
     10
    1112015-11-06  Wenson Hsieh  <wenson_hsieh@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r192124 r192126  
     12015-11-06  Scott Valentine  <svalentine@ikayzo.com>
     2
     3        Allow an optional hash algorithm to be passed to generateKey for RSA keys.
     4        https://bugs.webkit.org/show_bug.cgi?id=144938
     5
     6        Unreviewed initial submission.
     7
     8        Test: crypto/subtle/rsa-export-generated-keys.html
     9
     10        This changeset allows an optional hash parameter to be passed to the generate
     11        key function for RSA type keys. Previously, there was no way to export generated
     12        keys, as no hash function could be associated with the key (required for JWK).
     13
     14        The current WebCrypto API draft requires the hash function to be specified in the
     15        algorithm object passed to generateKey (http://www.w3.org/TR/WebCryptoAPI 20.4),
     16        however, they were made optional in this implementation to maintain compatiblity.
     17
     18        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
     19        (WebCore::getHashAlgorithm):
     20        (WebCore::createHmacParams):
     21        (WebCore::createHmacKeyParams):
     22        (WebCore::createRsaKeyGenParams):
     23        (WebCore::createRsaOaepParams):
     24        (WebCore::createRsaSsaParams):
     25        (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Deleted.
     26        * bindings/js/SerializedScriptValue.cpp:
     27        (WebCore::CloneDeserializer::readRSAKey):
     28        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
     29        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey):
     30        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
     31        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
     32        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):
     33        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
     34        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
     35        (WebCore::CryptoAlgorithmRSA_OAEP::generateKey):
     36        (WebCore::CryptoAlgorithmRSA_OAEP::importKey):
     37        * crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
     38        (WebCore::CryptoKeyRSA::CryptoKeyRSA):
     39        (WebCore::CryptoKeyRSA::create):
     40        (WebCore::CryptoKeyRSA::generatePair):
     41        (WebCore::CryptoKeyRSA::restrictToHash): Deleted.
     42        * crypto/keys/CryptoKeyRSA.h:
     43        * crypto/mac/CryptoKeyRSAMac.cpp:
     44        (WebCore::CryptoKeyRSA::CryptoKeyRSA):
     45        (WebCore::CryptoKeyRSA::create):
     46        (WebCore::CryptoKeyRSA::generatePair):
     47        (WebCore::CryptoKeyRSA::restrictToHash): Deleted.
     48        * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
     49
    1502015-11-06  Wenson Hsieh  <wenson_hsieh@apple.com>
    251
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp

    r182205 r192126  
    4747namespace WebCore {
    4848
     49enum class HashRequirement {
     50    Optional,
     51    Required,
     52};
     53
    4954bool JSCryptoAlgorithmDictionary::getAlgorithmIdentifier(ExecState* exec, JSValue value, CryptoAlgorithmIdentifier& algorithmIdentifier)
    5055{
     
    99104}
    100105
    101 static bool getHashAlgorithm(JSDictionary& dictionary, CryptoAlgorithmIdentifier& result)
     106static bool getHashAlgorithm(JSDictionary& dictionary, CryptoAlgorithmIdentifier& result, HashRequirement isRequired)
    102107{
    103108    // FXIME: Teach JSDictionary how to return JSValues, and use that to get hash element value.
     
    114119
    115120    if (hash.isUndefinedOrNull()) {
    116         setDOMException(exec, NOT_SUPPORTED_ERR);
     121        if (isRequired == HashRequirement::Required)
     122            setDOMException(exec, NOT_SUPPORTED_ERR);
    117123        return false;
    118124    }
     
    178184    auto result = std::make_unique<CryptoAlgorithmHmacParams>();
    179185
    180     if (!getHashAlgorithm(jsDictionary, result->hash)) {
     186    if (!getHashAlgorithm(jsDictionary, result->hash, HashRequirement::Required)) {
    181187        ASSERT(exec->hadException());
    182188        return nullptr;
     
    196202    auto result = std::make_unique<CryptoAlgorithmHmacKeyParams>();
    197203
    198     if (!getHashAlgorithm(jsDictionary, result->hash)) {
     204    if (!getHashAlgorithm(jsDictionary, result->hash, HashRequirement::Required)) {
    199205        ASSERT(exec->hadException());
    200206        return nullptr;
     
    215221    }
    216222
     223    JSDictionary jsDictionary(exec, value.getObject());
    217224    auto result = std::make_unique<CryptoAlgorithmRsaKeyGenParams>();
    218225
     
    237244    result->publicExponent.append(publicExponentArray->data(), publicExponentArray->byteLength());
    238245
     246    result->hasHash = getHashAlgorithm(jsDictionary, result->hash, HashRequirement::Optional);
     247
    239248    return WTF::move(result);
    240249}
     
    256265    auto result = std::make_unique<CryptoAlgorithmRsaOaepParams>();
    257266
    258     if (!getHashAlgorithm(jsDictionary, result->hash)) {
     267    if (!getHashAlgorithm(jsDictionary, result->hash, HashRequirement::Required)) {
    259268        ASSERT(exec->hadException());
    260269        return nullptr;
     
    290299    auto result = std::make_unique<CryptoAlgorithmRsaSsaParams>();
    291300
    292     if (!getHashAlgorithm(jsDictionary, result->hash)) {
     301    if (!getHashAlgorithm(jsDictionary, result->hash, HashRequirement::Required)) {
    293302        ASSERT(exec->hadException());
    294303        return nullptr;
     
    598607    switch (algorithm) {
    599608    case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
    600         return std::make_unique<CryptoAlgorithmParameters>();
    601     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     609    case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     610    case CryptoAlgorithmIdentifier::RSA_PSS:
     611    case CryptoAlgorithmIdentifier::RSA_OAEP:
    602612        return createRsaKeyParamsWithHash(exec, value);
    603     case CryptoAlgorithmIdentifier::RSA_PSS:
    604         return std::make_unique<CryptoAlgorithmParameters>();
    605     case CryptoAlgorithmIdentifier::RSA_OAEP:
    606         return createRsaKeyParamsWithHash(exec, value);
    607613    case CryptoAlgorithmIdentifier::ECDSA:
    608614    case CryptoAlgorithmIdentifier::ECDH:
  • trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp

    r182205 r192126  
    194194    } else if (m_jwkAlgorithmName == "RSA1_5") {
    195195        algorithm = algorithmRegisty.create(CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5);
    196         parameters = std::make_unique<CryptoAlgorithmParameters>();
     196        parameters = std::make_unique<CryptoAlgorithmRsaKeyParamsWithHash>();
    197197    } else if (m_jwkAlgorithmName == "RSA-OAEP") {
    198198        algorithm = algorithmRegisty.create(CryptoAlgorithmIdentifier::RSA_OAEP);
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r190838 r192126  
    20242024        if (type == CryptoKeyAsymmetricTypeSubtag::Public) {
    20252025            auto keyData = CryptoKeyDataRSAComponents::createPublic(modulus, exponent);
    2026             auto key = CryptoKeyRSA::create(algorithm, *keyData, extractable, usages);
    2027             if (isRestrictedToHash)
    2028                 key->restrictToHash(hash);
     2026            auto key = CryptoKeyRSA::create(algorithm, hash, isRestrictedToHash, *keyData, extractable, usages);
    20292027            result = WTF::move(key);
    20302028            return true;
     
    20412039        if (!primeCount) {
    20422040            auto keyData = CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent);
    2043             auto key = CryptoKeyRSA::create(algorithm, *keyData, extractable, usages);
    2044             if (isRestrictedToHash)
    2045                 key->restrictToHash(hash);
     2041            auto key = CryptoKeyRSA::create(algorithm, hash, isRestrictedToHash, *keyData, extractable, usages);
    20462042            result = WTF::move(key);
    20472043            return true;
     
    20752071
    20762072        auto keyData = CryptoKeyDataRSAComponents::createPrivateWithAdditionalData(modulus, exponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos);
    2077         auto key = CryptoKeyRSA::create(algorithm, *keyData, extractable, usages);
    2078         if (isRestrictedToHash)
    2079             key->restrictToHash(hash);
     2073        auto key = CryptoKeyRSA::create(algorithm, hash, isRestrictedToHash, *keyData, extractable, usages);
    20802074        result = WTF::move(key);
    20812075        return true;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp

    r188118 r192126  
    3030
    3131#include "CryptoAlgorithmRsaKeyGenParams.h"
     32#include "CryptoAlgorithmRsaKeyParamsWithHash.h"
    3233#include "CryptoKeyDataRSAComponents.h"
    3334#include "CryptoKeyRSA.h"
     
    9394    };
    9495
    95     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, WTF::move(keyPairCallback), WTF::move(failureCallback));
     96    CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5, rsaParameters.hash, rsaParameters.hasHash, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, WTF::move(keyPairCallback), WTF::move(failureCallback));
    9697}
    9798
    98 void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters&, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, KeyCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
     99void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, KeyCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
    99100{
     101    const CryptoAlgorithmRsaKeyParamsWithHash& rsaParameters = downcast<CryptoAlgorithmRsaKeyParamsWithHash>(parameters);
    100102    const CryptoKeyDataRSAComponents& rsaComponents = downcast<CryptoKeyDataRSAComponents>(keyData);
    101103
    102     RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5, rsaComponents, extractable, usage);
     104    RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5, rsaParameters.hash, rsaParameters.hasHash, rsaComponents, extractable, usage);
    103105    if (!result) {
    104106        failureCallback();
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp

    r188118 r192126  
    102102    };
    103103
    104     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, WTF::move(keyPairCallback), WTF::move(failureCallback));
     104    CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.hash, rsaParameters.hasHash, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, WTF::move(keyPairCallback), WTF::move(failureCallback));
    105105}
    106106
     
    110110    const CryptoKeyDataRSAComponents& rsaComponents = downcast<CryptoKeyDataRSAComponents>(keyData);
    111111
    112     RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaComponents, extractable, usage);
     112    RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaKeyParameters.hash, rsaKeyParameters.hasHash, rsaComponents, extractable, usage);
    113113    if (!result) {
    114114        failureCallback();
    115115        return;
    116116    }
    117 
    118     if (rsaKeyParameters.hasHash)
    119         result->restrictToHash(rsaKeyParameters.hash);
    120117
    121118    callback(*result);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp

    r188118 r192126  
    102102    };
    103103
    104     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSA_OAEP, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, WTF::move(keyPairCallback), WTF::move(failureCallback));
     104    CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSA_OAEP, rsaParameters.hash, rsaParameters.hasHash, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, WTF::move(keyPairCallback), WTF::move(failureCallback));
    105105}
    106106
     
    110110    const CryptoKeyDataRSAComponents& rsaComponents = downcast<CryptoKeyDataRSAComponents>(keyData);
    111111
    112     RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSA_OAEP, rsaComponents, extractable, usage);
     112    RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSA_OAEP, rsaKeyParameters.hash, rsaKeyParameters.hasHash, rsaComponents, extractable, usage);
    113113    if (!result) {
    114114        failureCallback();
    115115        return;
    116116    }
    117 
    118     if (rsaKeyParameters.hasHash)
    119         result->restrictToHash(rsaKeyParameters.hash);
    120117
    121118    callback(*result);
  • trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp

    r189675 r192126  
    4040};
    4141
    42 CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
     42CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
    4343    : CryptoKey(identifier, type, extractable, usage)
    4444    , m_platformKey(platformKey)
    45     , m_restrictedToSpecificHash(false)
     45    , m_restrictedToSpecificHash(hasHash)
     46    , m_hash(hash)
    4647{
    4748    notImplemented();
    4849}
    4950
    50 RefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier identifier, const CryptoKeyDataRSAComponents& keyData, bool extractable, CryptoKeyUsage usage)
     51RefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, const CryptoKeyDataRSAComponents& keyData, bool extractable, CryptoKeyUsage usage)
    5152{
    5253    notImplemented();
    5354    UNUSED_PARAM(identifier);
     55    UNUSED_PARAM(hash);
     56    UNUSED_PARAM(hasHash);
    5457    UNUSED_PARAM(keyData);
    5558    UNUSED_PARAM(extractable);
     
    6265{
    6366    notImplemented();
    64 }
    65 
    66 void CryptoKeyRSA::restrictToHash(CryptoAlgorithmIdentifier identifier)
    67 {
    68     m_restrictedToSpecificHash = true;
    69     m_hash = identifier;
    7067}
    7168
     
    9996}
    10097
    101 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, KeyPairCallback callback, VoidCallback failureCallback)
     98void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, KeyPairCallback callback, VoidCallback failureCallback)
    10299{
    103100    notImplemented();
     
    105102
    106103    UNUSED_PARAM(algorithm);
     104    UNUSED_PARAM(hash);
     105    UNUSED_PARAM(hasHash);
    107106    UNUSED_PARAM(modulusLength);
    108107    UNUSED_PARAM(publicExponent);
  • trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h

    r189675 r192126  
    5050class CryptoKeyRSA final : public CryptoKey {
    5151public:
    52     static Ref<CryptoKeyRSA> create(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
     52    static Ref<CryptoKeyRSA> create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
    5353    {
    54         return adoptRef(*new CryptoKeyRSA(identifier, type, platformKey, extractable, usage));
     54        return adoptRef(*new CryptoKeyRSA(identifier, hash, hasHash, type, platformKey, extractable, usage));
    5555    }
    56     static RefPtr<CryptoKeyRSA> create(CryptoAlgorithmIdentifier, const CryptoKeyDataRSAComponents&, bool extractable, CryptoKeyUsage);
     56    static RefPtr<CryptoKeyRSA> create(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, const CryptoKeyDataRSAComponents&, bool extractable, CryptoKeyUsage);
    5757    virtual ~CryptoKeyRSA();
    5858
    59     void restrictToHash(CryptoAlgorithmIdentifier);
    6059    bool isRestrictedToHash(CryptoAlgorithmIdentifier&) const;
    6160
     
    6463    typedef std::function<void(CryptoKeyPair&)> KeyPairCallback;
    6564    typedef std::function<void()> VoidCallback;
    66     static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage, KeyPairCallback, VoidCallback failureCallback);
     65    static void generatePair(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage, KeyPairCallback, VoidCallback failureCallback);
    6766
    6867    PlatformRSAKey platformKey() const { return m_platformKey; }
    6968
    7069private:
    71     CryptoKeyRSA(CryptoAlgorithmIdentifier, CryptoKeyType, PlatformRSAKey, bool extractable, CryptoKeyUsage);
     70    CryptoKeyRSA(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType, PlatformRSAKey, bool extractable, CryptoKeyUsage);
    7271
    7372    virtual CryptoKeyClass keyClass() const override { return CryptoKeyClass::RSA; }
  • trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp

    r189675 r192126  
    9797}
    9898
    99 CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
     99CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
    100100    : CryptoKey(identifier, type, extractable, usage)
    101101    , m_platformKey(platformKey)
    102     , m_restrictedToSpecificHash(false)
    103 {
    104 }
    105 
    106 RefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier identifier, const CryptoKeyDataRSAComponents& keyData, bool extractable, CryptoKeyUsage usage)
     102    , m_restrictedToSpecificHash(hasHash)
     103    , m_hash(hash)
     104{
     105}
     106
     107RefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, const CryptoKeyDataRSAComponents& keyData, bool extractable, CryptoKeyUsage usage)
    107108{
    108109    if (keyData.type() == CryptoKeyDataRSAComponents::Type::Private && !keyData.hasAdditionalPrivateKeyParameters()) {
     
    130131    }
    131132
    132     return adoptRef(new CryptoKeyRSA(identifier, keyData.type() == CryptoKeyDataRSAComponents::Type::Public ? CryptoKeyType::Public : CryptoKeyType::Private, cryptor, extractable, usage));
     133    return adoptRef(new CryptoKeyRSA(identifier, hash, hasHash, keyData.type() == CryptoKeyDataRSAComponents::Type::Public ? CryptoKeyType::Public : CryptoKeyType::Private, cryptor, extractable, usage));
    133134}
    134135
     
    136137{
    137138    CCRSACryptorRelease(m_platformKey);
    138 }
    139 
    140 void CryptoKeyRSA::restrictToHash(CryptoAlgorithmIdentifier identifier)
    141 {
    142     m_restrictedToSpecificHash = true;
    143     m_hash = identifier;
    144139}
    145140
     
    240235}
    241236
    242 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, KeyPairCallback callback, VoidCallback failureCallback)
     237void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, KeyPairCallback callback, VoidCallback failureCallback)
    243238{
    244239    uint32_t e;
     
    268263        }
    269264        callOnWebThreadOrDispatchAsyncOnMainThread(^{
    270             RefPtr<CryptoKeyRSA> publicKey = CryptoKeyRSA::create(algorithm, CryptoKeyType::Public, ccPublicKey, true, usage);
    271             RefPtr<CryptoKeyRSA> privateKey = CryptoKeyRSA::create(algorithm, CryptoKeyType::Private, ccPrivateKey, extractable, usage);
     265            RefPtr<CryptoKeyRSA> publicKey = CryptoKeyRSA::create(algorithm, hash, hasHash, CryptoKeyType::Public, ccPublicKey, true, usage);
     266            RefPtr<CryptoKeyRSA> privateKey = CryptoKeyRSA::create(algorithm, hash, hasHash, CryptoKeyType::Private, ccPrivateKey, extractable, usage);
    272267            (*localCallback)(CryptoKeyPair::create(publicKey.release(), privateKey.release()));
    273268            delete localCallback;
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h

    r174331 r192126  
    3636class CryptoAlgorithmRsaKeyGenParams final : public CryptoAlgorithmParameters {
    3737public:
     38    CryptoAlgorithmRsaKeyGenParams()
     39        : hasHash(false)
     40    {
     41    }
    3842    // The length, in bits, of the RSA modulus.
    3943    unsigned modulusLength;
    4044    // The RSA public exponent, encoded as BigInteger.
    4145    Vector<uint8_t> publicExponent;
     46    // The hash algorith identifier
     47    bool hasHash;
     48    CryptoAlgorithmIdentifier hash;
    4249
    4350    virtual Class parametersClass() const override { return Class::RsaKeyGenParams; }
Note: See TracChangeset for help on using the changeset viewer.