Changeset 209077 in webkit


Ignore:
Timestamp:
Nov 29, 2016 10:51:45 AM (7 years ago)
Author:
dbates@webkit.org
Message:

CryptoAlgorithm::generateKey() should take lvalue reference to const CryptoAlgorithmParameters
https://bugs.webkit.org/show_bug.cgi?id=165111

Reviewed by Darin Adler.

CryptoAlgorithm::generateKey() and its overrides always expect to receive a non-null pointer
to a CryptoAlgorithmParameter object and never take ownership of it. This kind of relationship
is best expressed by modifying CryptoAlgorithm::generateKey() to take a lvalue reference to
a const CryptoAlgorithmParameter object.

  • bindings/js/JSSubtleCryptoCustom.cpp:

(WebCore::jsSubtleCryptoFunctionGenerateKeyPromise):

  • crypto/CryptoAlgorithm.cpp:

(WebCore::CryptoAlgorithm::generateKey):

  • crypto/CryptoAlgorithm.h:
  • crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:

(WebCore::CryptoAlgorithmAES_CBC::generateKey):

  • crypto/algorithms/CryptoAlgorithmAES_CBC.h:
  • crypto/algorithms/CryptoAlgorithmAES_KW.cpp:

(WebCore::CryptoAlgorithmAES_KW::generateKey):

  • crypto/algorithms/CryptoAlgorithmAES_KW.h:
  • crypto/algorithms/CryptoAlgorithmHMAC.cpp:

(WebCore::CryptoAlgorithmHMAC::generateKey):

  • crypto/algorithms/CryptoAlgorithmHMAC.h:
  • crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:

(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey):

  • crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
  • crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:

(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):

  • crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:

(WebCore::CryptoAlgorithmRSA_OAEP::generateKey):

  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r209076 r209077  
     12016-11-29  Daniel Bates  <dabates@apple.com>
     2
     3        CryptoAlgorithm::generateKey() should take lvalue reference to const CryptoAlgorithmParameters
     4        https://bugs.webkit.org/show_bug.cgi?id=165111
     5
     6        Reviewed by Darin Adler.
     7
     8        CryptoAlgorithm::generateKey() and its overrides always expect to receive a non-null pointer
     9        to a CryptoAlgorithmParameter object and never take ownership of it. This kind of relationship
     10        is best expressed by modifying CryptoAlgorithm::generateKey() to take a lvalue reference to
     11        a const CryptoAlgorithmParameter object.
     12
     13        * bindings/js/JSSubtleCryptoCustom.cpp:
     14        (WebCore::jsSubtleCryptoFunctionGenerateKeyPromise):
     15        * crypto/CryptoAlgorithm.cpp:
     16        (WebCore::CryptoAlgorithm::generateKey):
     17        * crypto/CryptoAlgorithm.h:
     18        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
     19        (WebCore::CryptoAlgorithmAES_CBC::generateKey):
     20        * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
     21        * crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
     22        (WebCore::CryptoAlgorithmAES_KW::generateKey):
     23        * crypto/algorithms/CryptoAlgorithmAES_KW.h:
     24        * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
     25        (WebCore::CryptoAlgorithmHMAC::generateKey):
     26        * crypto/algorithms/CryptoAlgorithmHMAC.h:
     27        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
     28        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey):
     29        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
     30        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
     31        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):
     32        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
     33        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
     34        (WebCore::CryptoAlgorithmRSA_OAEP::generateKey):
     35        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
     36
    1372016-11-29  Andy Estes  <aestes@apple.com>
    238
  • trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp

    r208918 r209077  
    553553    // regardless what kind of keys it produces: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-generateKey
    554554    // That's simply not efficient for AES and HMAC keys. Therefore, we perform it as an async task conditionally.
    555     algorithm->generateKey(WTFMove(params), extractable, keyUsages, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state));
     555    algorithm->generateKey(*params, extractable, keyUsages, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state));
    556556}
    557557
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp

    r208918 r209077  
    4343}
    4444
    45 void CryptoAlgorithm::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
     45void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    4646{
    4747    exceptionCallback(NOT_SUPPORTED_ERR);
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.h

    r208918 r209077  
    6767    virtual void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    6868    virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    69     virtual void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
     69    virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
    7070    virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
    7171    virtual void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp

    r208985 r209077  
    8989}
    9090
    91 void CryptoAlgorithmAES_CBC::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    92 {
    93     ASSERT(parameters);
    94     auto& aesParameters = downcast<CryptoAlgorithmAesKeyGenParams>(*parameters);
     91void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
     92{
     93    const auto& aesParameters = downcast<CryptoAlgorithmAesKeyGenParams>(parameters);
    9594
    9695    if (usagesAreInvalidForCryptoAlgorithmAES_CBC(usages)) {
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h

    r208918 r209077  
    4747    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4848    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    49     void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
     49    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    5050    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5151    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp

    r208985 r209077  
    6464}
    6565
    66 void CryptoAlgorithmAES_KW::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
     66void CryptoAlgorithmAES_KW::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    6767{
    68     ASSERT(parameters);
    6968    if (usagesAreInvalidForCryptoAlgorithmAES_KW(usages)) {
    7069        exceptionCallback(SYNTAX_ERR);
     
    7271    }
    7372
    74     auto result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_KW, downcast<CryptoAlgorithmAesKeyGenParams>(*parameters).length, extractable, usages);
     73    auto result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_KW, downcast<CryptoAlgorithmAesKeyGenParams>(parameters).length, extractable, usages);
    7574    if (!result) {
    7675        exceptionCallback(OperationError);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.h

    r208891 r209077  
    4444    CryptoAlgorithmIdentifier identifier() const final;
    4545
    46     void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
     46    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    4747    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    4848    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp

    r208985 r209077  
    7070}
    7171
    72 void CryptoAlgorithmHMAC::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    73 {
    74     ASSERT(parameters);
    75     const auto& hmacParameters = downcast<CryptoAlgorithmHmacKeyParams>(*parameters);
     72void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
     73{
     74    const auto& hmacParameters = downcast<CryptoAlgorithmHmacKeyParams>(parameters);
    7675
    7776    if (usagesAreInvalidForCryptoAlgorithmHMAC(usages)) {
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h

    r208891 r209077  
    4545    CryptoAlgorithmIdentifier identifier() const final;
    4646
    47     void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
     47    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    4848    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    4949    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp

    r208985 r209077  
    7878}
    7979
    80 void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
     80void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
    8181{
    82     ASSERT(parameters);
    83     const auto& rsaParameters = downcast<CryptoAlgorithmRsaKeyGenParams>(*parameters);
     82    const auto& rsaParameters = downcast<CryptoAlgorithmRsaKeyGenParams>(parameters);
    8483
    8584    if (usages & (CryptoKeyUsageSign | CryptoKeyUsageVerify | CryptoKeyUsageDeriveKey | CryptoKeyUsageDeriveBits | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey)) {
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h

    r208918 r209077  
    4747    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4848    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    49     void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
     49    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    5050    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5151    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp

    r208891 r209077  
    6969}
    7070
    71 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
    72 {
    73     ASSERT(parameters);
    74     const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedKeyGenParams>(*parameters);
     71void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
     72{
     73    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedKeyGenParams>(parameters);
    7574
    7675    if (usages & (CryptoKeyUsageDecrypt | CryptoKeyUsageEncrypt | CryptoKeyUsageDeriveKey | CryptoKeyUsageDeriveBits | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey)) {
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h

    r208891 r209077  
    4545    CryptoAlgorithmIdentifier identifier() const final;
    4646
    47     void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
     47    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    4848    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    4949    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp

    r208918 r209077  
    8989}
    9090
    91 void CryptoAlgorithmRSA_OAEP::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
    92 {
    93     ASSERT(parameters);
    94     const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedKeyGenParams>(*parameters);
     91void CryptoAlgorithmRSA_OAEP::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
     92{
     93    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedKeyGenParams>(parameters);
    9594
    9695    if (usages & (CryptoKeyUsageSign | CryptoKeyUsageVerify | CryptoKeyUsageDeriveKey | CryptoKeyUsageDeriveBits)) {
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h

    r208918 r209077  
    4747    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4848    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    49     void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
     49    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    5050    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5151    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
Note: See TracChangeset for help on using the changeset viewer.