Title: [277142] trunk
Revision
277142
Author
[email protected]
Date
2021-05-06 17:17:05 -0700 (Thu, 06 May 2021)

Log Message

[OpenSSL] Implement CryptoAlgorithmRSA*
https://bugs.webkit.org/show_bug.cgi?id=225294

Reviewed by Don Olmstead.

Implement RSA for OpenSSL.

Implement CryptoAlgorithmRSA_OAEP, CryptoAlgorithmRSA_PSS,
CryptoAlgorithmRSAES_PKCS1_v1_5, CryptoAlgorithmRSASA_PKCS1_v1_5,
and CryptoKeyRSA for OpenSSL.

.:

Note that if such OpenSSL version that does not support RSA_OAEP or
RSA_PSS, the WebCrypto API for those algorithm will return a
NotSupportedError.

* Source/cmake/OptionsPlayStation.cmake:
* Source/cmake/OptionsWinCairo.cmake:

Source/WebCore:

Note that if such OpenSSL version that does not support RSA_OAEP or
RSA_PSS, the WebCrypto API for those algorithm will return a
NotSupportedError.

Also note that OpenSSL accepts RSA_PSS salt length longer than the hash
length. This makes the
crypto/subtle/rsa-pss-import-key-sign-large-salt.html test fail.

Test: Existing crypto/subtle tests

* crypto/keys/CryptoKeyRSA.h: Use the EVP_PKEY struct for the platform
key.
* crypto/openssl/CryptoAlgorithmHMACOpenSSL.cpp: Move HMACAlgorithm()
to OpenSSLUtilities as DigestAlgorithm().
* crypto/openssl/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
Implemented.
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
Implemented.
* crypto/openssl/CryptoAlgorithmRSASSA_PKCS1_v1_5OpenSSL.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
Implemented.
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify):
Implemented.
* crypto/openssl/CryptoAlgorithmRSA_OAEPOpenSSL.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt): Implemented.
(WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): Implemented.
* crypto/openssl/CryptoAlgorithmRSA_PSSOpenSSL.cpp:
(WebCore::CryptoAlgorithmRSA_PSS::platformSign): Implemented.
(WebCore::CryptoAlgorithmRSA_PSS::platformVerify): Implemented.
* crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp:
(WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
Registered RSAES_PKCS1_v_1_5, RSASSA_PKCS1_v1_5, RSA_OAEP, and RSA_PSS.
* crypto/openssl/CryptoKeyRSAOpenSSL.cpp:
(WebCore::getRSAModulusLength):
(WebCore::convertToBytes):
(WebCore::convertToBigNumber):
(WebCore::CryptoKeyRSA::create):
(WebCore::CryptoKeyRSA::CryptoKeyRSA):
(WebCore::CryptoKeyRSA::isRestrictedToHash const):
(WebCore::CryptoKeyRSA::keySizeInBits const):
(WebCore::exponentVectorToUInt32):
(WebCore::CryptoKeyRSA::generatePair):
(WebCore::CryptoKeyRSA::importSpki):
(WebCore::CryptoKeyRSA::importPkcs8):
(WebCore::CryptoKeyRSA::exportSpki const):
(WebCore::CryptoKeyRSA::exportPkcs8 const):
(WebCore::CryptoKeyRSA::algorithm const):
(WebCore::CryptoKeyRSA::exportData const):
* crypto/openssl/OpenSSLCryptoUniquePtr.h:
(WebCore::OpenSSLCryptoPtrDeleter<EVP_PKEY_CTX>::operator() const):
Added.
(WebCore::OpenSSLCryptoPtrDeleter<RSA>::operator() const): Added.
(WebCore::OpenSSLCryptoPtrDeleter<PKCS8_PRIV_KEY_INFO>::operator() const): Added.
(WebCore::OpenSSLCryptoPtrDeleter<BIGNUM>::operator() const): Added.
(WebCore::OpenSSLCryptoPtrDeleter<BN_CTX>::operator() const): Added.
* crypto/openssl/OpenSSLUtilities.cpp:
(WebCore::digestAlgorithm): Added.
(WebCore::calculateDigest): Added.
* crypto/openssl/OpenSSLUtilities.h:
* platform/OpenSSL.cmake:

Source/WTF:

Note that if such OpenSSL version that does not support RSA_OAEP or
RSA_PSS, the WebCrypto API for those algorithm will return a
NotSupportedError.

* wtf/Platform.h: Set HAVE_RSA_PSS for USE(OPENSSL)

LayoutTests:

Add wincairo platform expectations for
rsa-generate/import-key-malformed-parameters, modifying RSA-PSS
related results from NotSupported to appropriate errors.

* platform/wincairo/TestExpectations: Unskip tests that are now supported.
* platform/wincairo/crypto/subtle/rsa-generate-key-malformed-parameters-expected.txt: Added.
* platform/wincairo/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (277141 => 277142)


--- trunk/ChangeLog	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/ChangeLog	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,3 +1,23 @@
+2021-05-06  Yoshiaki Jitsukawa  <[email protected]>
+
+        [OpenSSL] Implement CryptoAlgorithmRSA*
+        https://bugs.webkit.org/show_bug.cgi?id=225294
+
+        Reviewed by Don Olmstead.
+
+        Implement RSA for OpenSSL.
+
+        Implement CryptoAlgorithmRSA_OAEP, CryptoAlgorithmRSA_PSS,
+        CryptoAlgorithmRSAES_PKCS1_v1_5, CryptoAlgorithmRSASA_PKCS1_v1_5,
+        and CryptoKeyRSA for OpenSSL.
+
+        Note that if such OpenSSL version that does not support RSA_OAEP or
+        RSA_PSS, the WebCrypto API for those algorithm will return a
+        NotSupportedError.
+
+        * Source/cmake/OptionsPlayStation.cmake:
+        * Source/cmake/OptionsWinCairo.cmake:
+
 2021-05-05  Michael Catanzaro  <[email protected]>
 
         USE_64KB_PAGE_BLOCK build option is broken

Modified: trunk/LayoutTests/ChangeLog (277141 => 277142)


--- trunk/LayoutTests/ChangeLog	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/LayoutTests/ChangeLog	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,3 +1,24 @@
+2021-05-06  Yoshiaki Jitsukawa  <[email protected]>
+
+        [OpenSSL] Implement CryptoAlgorithmRSA*
+        https://bugs.webkit.org/show_bug.cgi?id=225294
+
+        Reviewed by Don Olmstead.
+
+        Implement RSA for OpenSSL.
+
+        Implement CryptoAlgorithmRSA_OAEP, CryptoAlgorithmRSA_PSS,
+        CryptoAlgorithmRSAES_PKCS1_v1_5, CryptoAlgorithmRSASA_PKCS1_v1_5,
+        and CryptoKeyRSA for OpenSSL.
+
+        Add wincairo platform expectations for
+        rsa-generate/import-key-malformed-parameters, modifying RSA-PSS
+        related results from NotSupported to appropriate errors.
+
+        * platform/wincairo/TestExpectations: Unskip tests that are now supported.
+        * platform/wincairo/crypto/subtle/rsa-generate-key-malformed-parameters-expected.txt: Added.
+        * platform/wincairo/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt: Added.
+
 2021-05-06  Robert Jenner  <[email protected]>
 
         [ BigSur Debug ] webgl/1.0.3/conformance/glsl/misc/_expression_-list-in-declarator-initializer.html is a flaky timeout

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (277141 => 277142)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2021-05-07 00:17:05 UTC (rev 277142)
@@ -715,22 +715,10 @@
 # crypto
 #//////////////////////////////////////////////////////////////////////////////////////////
 
-# Crypts other than AES are not supported.
-crypto/subtle/aes-cbc-import-key-unwrap-jwk-rsa-key-private.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-unwrap-jwk-rsa-key-public.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-private.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-public.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html [ Skip ]
-crypto/subtle/aes-cbc-import-key-wrap-spki-key.html [ Skip ]
-crypto/subtle/aes-export-key-malformed-parameters.html [ Skip ]
+# Crypts other than AES and RSA are not supported.
 crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html [ Skip ]
-crypto/subtle/aes-import-key-malformed-parameters.html [ Skip ]
-crypto/subtle/decrypt-malformed-parameters.html [ Skip ]
 crypto/subtle/derive-bits-malformed-parameters.html [ Skip ]
 crypto/subtle/derive-key-malformed-parameters.html [ Skip ]
-crypto/subtle/digest-malformed-parameters.html [ Skip ]
 crypto/subtle/ecdh-derive-bits-length-limits.html [ Skip ]
 crypto/subtle/ecdh-derive-bits-malformed-parametrs.html [ Skip ]
 crypto/subtle/ecdh-generate-export-jwk-key-p256.html [ Skip ]
@@ -824,12 +812,9 @@
 crypto/subtle/ec-import-spki-key-export-spki-key-p256.html [ Skip ]
 crypto/subtle/ec-import-spki-key-export-spki-key-p384.html [ Skip ]
 crypto/subtle/ec-import-spki-key-export-spki-key-p521.html [ Skip ]
-crypto/subtle/encrypt-malformed-parameters.html [ Skip ]
-crypto/subtle/export-key-malformed-parameters.html [ Skip ]
 crypto/subtle/gc.html [ Skip ]
 crypto/subtle/gc-2.html [ Skip ]
 crypto/subtle/gc-3.html [ Skip ]
-crypto/subtle/generate-key-malformed-parameters.html [ Skip ]
 crypto/subtle/hkdf-derive-bits-length-limits.html [ Skip ]
 crypto/subtle/hkdf-derive-bits-malformed-parametrs.html [ Skip ]
 crypto/subtle/hkdf-import-key.html [ Skip ]
@@ -836,134 +821,37 @@
 crypto/subtle/hkdf-import-key-derive-bits.html [ Skip ]
 crypto/subtle/hkdf-import-key-derive-hmac-key.html [ Skip ]
 crypto/subtle/hkdf-import-key-malformed-parameters.html [ Skip ]
-crypto/subtle/import-key-malformed-parameters.html [ Skip ]
 crypto/subtle/pbkdf2-derive-bits-malformed-parametrs.html [ Skip ]
 crypto/subtle/pbkdf2-import-key.html [ Skip ]
 crypto/subtle/pbkdf2-import-key-derive-bits.html [ Skip ]
 crypto/subtle/pbkdf2-import-key-derive-hmac-key.html [ Skip ]
 crypto/subtle/pbkdf2-import-key-malformed-parameters.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-jwk.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-generate-key.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-generate-key-extractable.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-private-key.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-leading-zero.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-minimum.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-non-extractable.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-key-encrypt.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html [ Skip ]
-crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html [ Skip ]
-crypto/subtle/rsa-export-key-malformed-parameters.html [ Skip ]
-crypto/subtle/rsa-generate-key-malformed-parameters.html [ Skip ]
-crypto/subtle/rsa-import-jwk-key-export-jwk-key-private.html [ Skip ]
-crypto/subtle/rsa-import-jwk-key-export-jwk-key-public.html [ Skip ]
-crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html [ Skip ]
-crypto/subtle/rsa-import-jwk-key-export-spki-key.html [ Skip ]
-crypto/subtle/rsa-import-key-malformed-parameters.html [ Skip ]
-crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html [ Skip ]
-crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html [ Skip ]
-crypto/subtle/rsa-import-spki-key-export-jwk-key.html [ Skip ]
-crypto/subtle/rsa-import-spki-key-export-spki-key.html [ Skip ]
-crypto/subtle/rsa-import-spki-small-key.html [ Skip ]
 crypto/subtle/rsa-indexeddb.html [ Skip ]
 crypto/subtle/rsa-indexeddb-non-exportable.html [ Skip ]
 crypto/subtle/rsa-indexeddb-non-exportable-private.html [ Skip ]
 crypto/subtle/rsa-indexeddb-private.html [ Skip ]
-crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html [ Skip ]
-crypto/subtle/rsa-oaep-encrypt-malformed-parameters.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-jwk-sha1.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-jwk-sha224.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-jwk-sha256.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-jwk-sha384.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-jwk-sha512.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-export-key-spki.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-key.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html [ Skip ]
-crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-private-key.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-public-key-sha1.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-public-key-sha224.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-public-key-sha256.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-public-key-sha384.html [ Skip ]
-crypto/subtle/rsa-oaep-import-jwk-public-key-sha512.html [ Skip ]
-crypto/subtle/rsa-oaep-import-key-decrypt.html [ Skip ]
-crypto/subtle/rsa-oaep-import-key-decrypt-label.html [ Skip ]
-crypto/subtle/rsa-oaep-import-key-encrypt.html [ Skip ]
-crypto/subtle/rsa-oaep-import-key-encrypt-label.html [ Skip ]
-crypto/subtle/rsa-oaep-import-key-unwrap-jwk-oct-key.html [ Skip ]
-crypto/subtle/rsa-oaep-import-key-wrap-jwk-oct-key.html [ Skip ]
-crypto/subtle/rsa-oaep-import-pkcs8-key.html [ Skip ]
-crypto/subtle/rsa-oaep-import-spki-key.html [ Skip ]
-crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html [ Skip ]
-crypto/subtle/rsa-oaep-plaintext-length.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-jwk-sha1.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-jwk-sha224.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-jwk-sha256.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-jwk-sha384.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-jwk-sha512.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-pkcs8.html [ Skip ]
-crypto/subtle/rsa-pss-generate-export-key-spki.html [ Skip ]
-crypto/subtle/rsa-pss-generate-key.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-private-key.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-public-key-empty-usages.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-public-key-sha1.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-public-key-sha224.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-public-key-sha256.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-public-key-sha384.html [ Skip ]
-crypto/subtle/rsa-pss-import-jwk-public-key-sha512.html [ Skip ]
-crypto/subtle/rsa-pss-import-key-sign.html [ Skip ]
-crypto/subtle/rsa-pss-import-key-sign-large-salt.html [ Skip ]
-crypto/subtle/rsa-pss-import-key-verify.html [ Skip ]
-crypto/subtle/rsa-pss-import-pkcs8-key.html [ Skip ]
-crypto/subtle/rsa-pss-import-spki-key.html [ Skip ]
-crypto/subtle/rsa-pss-import-spki-key-empty-usages.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha1.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha224.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha256.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha384.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha512.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-key-sign-verify.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-generate-key-with-leading-zeroes-in-exponent.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-private-key.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha1.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha224.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha256.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha384.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha512.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha1.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha224.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha256.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha384.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha512.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html [ Skip ]
-crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html [ Skip ]
-crypto/subtle/sha1-digest.html [ Skip ]
-crypto/subtle/sha224-digest.html [ Skip ]
-crypto/subtle/sha256-digest.html [ Skip ]
-crypto/subtle/sha384-digest.html [ Skip ]
-crypto/subtle/sha512-digest.html [ Skip ]
-crypto/subtle/sign-malformed-parameters.html [ Skip ]
-crypto/subtle/unwrap-key-malformed-parameters.html [ Skip ]
-crypto/subtle/verify-malformed-parameters.html [ Skip ]
-crypto/subtle/wrap-key-malformed-parameters.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha1.html [ Pass ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha224.html [ Pass ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha256.html [ Pass ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha384.html [ Pass ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha512.html [ Pass ]
+crypto/subtle/rsa-pss-generate-export-key-pkcs8.html [ Pass ]
+crypto/subtle/rsa-pss-generate-export-key-spki.html [ Pass ]
+crypto/subtle/rsa-pss-generate-key.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-private-key.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-public-key-empty-usages.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha1.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha224.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha256.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha384.html [ Pass ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha512.html [ Pass ]
+crypto/subtle/rsa-pss-import-key-sign.html [ Pass ]
+# Large salt should be supported.
+crypto/subtle/rsa-pss-import-key-sign-large-salt.html [ Failure ]
+crypto/subtle/rsa-pss-import-key-verify.html [ Pass ]
+crypto/subtle/rsa-pss-import-pkcs8-key.html [ Pass ]
+crypto/subtle/rsa-pss-import-spki-key.html [ Pass ]
+crypto/subtle/rsa-pss-import-spki-key-empty-usages.html [ Pass ]
 
 # https://bugs.webkit.org/show_bug.cgi?id=221569
 crypto/crypto-random-values-oom.html [ Skip ]

Added: trunk/LayoutTests/platform/wincairo/crypto/subtle/rsa-generate-key-malformed-parameters-expected.txt (0 => 277142)


--- trunk/LayoutTests/platform/wincairo/crypto/subtle/rsa-generate-key-malformed-parameters-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/wincairo/crypto/subtle/rsa-generate-key-malformed-parameters-expected.txt	2021-05-07 00:17:05 UTC (rev 277142)
@@ -0,0 +1,46 @@
+Test generating an RSA key with malformed-paramters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.generateKey("RSAES-PKCS1-v1_5", extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member RsaKeyGenParams.modulusLength is required and must be an instance of unsigned long.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5"}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member RsaKeyGenParams.modulusLength is required and must be an instance of unsigned long.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: undefined, publicExponent: publicExponent}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member RsaKeyGenParams.modulusLength is required and must be an instance of unsigned long.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: Symbol(), publicExponent: publicExponent}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Cannot convert a symbol to a number.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: 1}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: true}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: null}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: undefined}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member RsaKeyGenParams.publicExponent is required and must be an instance of Uint8Array.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: { }}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: Symbol()}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: "foo"}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: [ ]}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["sign", "verify"]) rejected promise  with TypeError: Member RsaHashedKeyGenParams.hash is required and must be an instance of (object or DOMString).
+PASS crypto.subtle.generateKey({name: "RSA-OAEP", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["decrypt", "encrypt"]) rejected promise  with TypeError: Member RsaHashedKeyGenParams.hash is required and must be an instance of (object or DOMString).
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["sign"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["deriveKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["deriveBits"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["wrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSAES-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent}, extractable, ["unwrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["encrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["decrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["deriveKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["deriveBits"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["wrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["unwrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-OAEP", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["sign"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-OAEP", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-OAEP", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["deriveKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-OAEP", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["deriveBits"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-PSS", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["encrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-PSS", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["decrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-PSS", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["deriveKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-PSS", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["deriveBits"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-PSS", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["wrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSA-PSS", modulusLength: 2048, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["unwrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.generateKey({name: "RSASSA-PKCS1-v1_5", modulusLength: 0, publicExponent: publicExponent, hash: "sha-1"}, extractable, ["sign", "verify"]) rejected promise  with OperationError: The operation failed for an operation-specific reason.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/wincairo/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt (0 => 277142)


--- trunk/LayoutTests/platform/wincairo/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/wincairo/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt	2021-05-07 00:17:05 UTC (rev 277142)
@@ -0,0 +1,94 @@
+Test importing a RSA key with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: ""}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["sign"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: ""}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["sign"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: ""}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: "sig"}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: ""}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: "enc"}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: "sig"}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: ""}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: "enc"}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, use: ""}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "foo"}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RS224"}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RS256"}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-224"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RS384"}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-256"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RS512"}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-384"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RS1"}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-512"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-224"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-256"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-384"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSASSA-PKCS1-v1_5", hash: "sha-512"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RSA-OAEP-224"}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RSA-OAEP-256"}, {name: "RSA-OAEP", hash: "sha-224"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RSA-OAEP-384"}, {name: "RSA-OAEP", hash: "sha-256"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RSA-OAEP-512"}, {name: "RSA-OAEP", hash: "sha-384"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "RSA-OAEP"}, {name: "RSA-OAEP", hash: "sha-512"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-OAEP", hash: "sha-224"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-OAEP", hash: "sha-256"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-OAEP", hash: "sha-384"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-OAEP", hash: "sha-512"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "PS224"}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "PS256"}, {name: "RSA-PSS", hash: "sha-224"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "PS384"}, {name: "RSA-PSS", hash: "sha-256"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "PS512"}, {name: "RSA-PSS", hash: "sha-384"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: "PS1"}, {name: "RSA-PSS", hash: "sha-512"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-PSS", hash: "sha-224"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-PSS", hash: "sha-256"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-PSS", hash: "sha-384"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, alg: ""}, {name: "RSA-PSS", hash: "sha-512"}, extractable, ["verify"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "oct", n: n, e: e}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, key_ops: ["sign", "verify"]}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, key_ops: [ ]}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, ext: false}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA"}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", e: e}, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq, qi: qi, oth: [{r: q, d: dq, t: qi}]}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, q: q, dp: dp, dq: dq, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, dp: dp, dq: dq, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dq: dq, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: "", q: q, dp: dp, dq: dq, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", spkiKey, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("spki", spkiKey, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["sign"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("spki", spkiKey, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["sign"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-PSS", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError: A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("spki", malformedKey0, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey1, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey2, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey4, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey6, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey0, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey1, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey3, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey5, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey7, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Modified: trunk/Source/WTF/ChangeLog (277141 => 277142)


--- trunk/Source/WTF/ChangeLog	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WTF/ChangeLog	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,3 +1,22 @@
+2021-05-06  Yoshiaki Jitsukawa  <[email protected]>
+
+        [OpenSSL] Implement CryptoAlgorithmRSA*
+        https://bugs.webkit.org/show_bug.cgi?id=225294
+
+        Reviewed by Don Olmstead.
+
+        Implement RSA for OpenSSL.
+
+        Implement CryptoAlgorithmRSA_OAEP, CryptoAlgorithmRSA_PSS,
+        CryptoAlgorithmRSAES_PKCS1_v1_5, CryptoAlgorithmRSASA_PKCS1_v1_5,
+        and CryptoKeyRSA for OpenSSL.
+
+        Note that if such OpenSSL version that does not support RSA_OAEP or
+        RSA_PSS, the WebCrypto API for those algorithm will return a
+        NotSupportedError.
+
+        * wtf/Platform.h: Set HAVE_RSA_PSS for USE(OPENSSL)
+
 2021-05-06  Chris Dumez  <[email protected]>
 
         Regression(r254389?) navigator.languages returns all lowercase languages for ports using CF

Modified: trunk/Source/WTF/wtf/Platform.h (277141 => 277142)


--- trunk/Source/WTF/wtf/Platform.h	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WTF/wtf/Platform.h	2021-05-07 00:17:05 UTC (rev 277142)
@@ -148,7 +148,7 @@
 #endif
 
 /* FIXME: The availability of RSA_PSS should not depend on the policy decision to USE(GCRYPT). */
-#if PLATFORM(MAC) || PLATFORM(IOS) || PLATFORM(MACCATALYST) || USE(GCRYPT)
+#if PLATFORM(MAC) || PLATFORM(IOS) || PLATFORM(MACCATALYST) || USE(GCRYPT) || USE(OPENSSL)
 #define HAVE_RSA_PSS 1
 #endif
 

Modified: trunk/Source/WebCore/ChangeLog (277141 => 277142)


--- trunk/Source/WebCore/ChangeLog	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/ChangeLog	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,3 +1,78 @@
+2021-05-06  Yoshiaki Jitsukawa  <[email protected]>
+
+        [OpenSSL] Implement CryptoAlgorithmRSA*
+        https://bugs.webkit.org/show_bug.cgi?id=225294
+
+        Reviewed by Don Olmstead.
+
+        Implement RSA for OpenSSL.
+
+        Implement CryptoAlgorithmRSA_OAEP, CryptoAlgorithmRSA_PSS,
+        CryptoAlgorithmRSAES_PKCS1_v1_5, CryptoAlgorithmRSASA_PKCS1_v1_5,
+        and CryptoKeyRSA for OpenSSL.
+
+        Note that if such OpenSSL version that does not support RSA_OAEP or
+        RSA_PSS, the WebCrypto API for those algorithm will return a
+        NotSupportedError.
+
+        Also note that OpenSSL accepts RSA_PSS salt length longer than the hash
+        length. This makes the
+        crypto/subtle/rsa-pss-import-key-sign-large-salt.html test fail.
+
+        Test: Existing crypto/subtle tests
+
+        * crypto/keys/CryptoKeyRSA.h: Use the EVP_PKEY struct for the platform
+        key.
+        * crypto/openssl/CryptoAlgorithmHMACOpenSSL.cpp: Move HMACAlgorithm()
+        to OpenSSLUtilities as DigestAlgorithm().
+        * crypto/openssl/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp:
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
+        Implemented.
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
+        Implemented.
+        * crypto/openssl/CryptoAlgorithmRSASSA_PKCS1_v1_5OpenSSL.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
+        Implemented.
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify):
+        Implemented.
+        * crypto/openssl/CryptoAlgorithmRSA_OAEPOpenSSL.cpp:
+        (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt): Implemented.
+        (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): Implemented.
+        * crypto/openssl/CryptoAlgorithmRSA_PSSOpenSSL.cpp:
+        (WebCore::CryptoAlgorithmRSA_PSS::platformSign): Implemented.
+        (WebCore::CryptoAlgorithmRSA_PSS::platformVerify): Implemented.
+        * crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp:
+        (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
+        Registered RSAES_PKCS1_v_1_5, RSASSA_PKCS1_v1_5, RSA_OAEP, and RSA_PSS.
+        * crypto/openssl/CryptoKeyRSAOpenSSL.cpp:
+        (WebCore::getRSAModulusLength):
+        (WebCore::convertToBytes):
+        (WebCore::convertToBigNumber):
+        (WebCore::CryptoKeyRSA::create):
+        (WebCore::CryptoKeyRSA::CryptoKeyRSA):
+        (WebCore::CryptoKeyRSA::isRestrictedToHash const):
+        (WebCore::CryptoKeyRSA::keySizeInBits const):
+        (WebCore::exponentVectorToUInt32):
+        (WebCore::CryptoKeyRSA::generatePair):
+        (WebCore::CryptoKeyRSA::importSpki):
+        (WebCore::CryptoKeyRSA::importPkcs8):
+        (WebCore::CryptoKeyRSA::exportSpki const):
+        (WebCore::CryptoKeyRSA::exportPkcs8 const):
+        (WebCore::CryptoKeyRSA::algorithm const):
+        (WebCore::CryptoKeyRSA::exportData const):
+        * crypto/openssl/OpenSSLCryptoUniquePtr.h:
+        (WebCore::OpenSSLCryptoPtrDeleter<EVP_PKEY_CTX>::operator() const):
+        Added.
+        (WebCore::OpenSSLCryptoPtrDeleter<RSA>::operator() const): Added.
+        (WebCore::OpenSSLCryptoPtrDeleter<PKCS8_PRIV_KEY_INFO>::operator() const): Added.
+        (WebCore::OpenSSLCryptoPtrDeleter<BIGNUM>::operator() const): Added.
+        (WebCore::OpenSSLCryptoPtrDeleter<BN_CTX>::operator() const): Added.
+        * crypto/openssl/OpenSSLUtilities.cpp:
+        (WebCore::digestAlgorithm): Added.
+        (WebCore::calculateDigest): Added.
+        * crypto/openssl/OpenSSLUtilities.h: 
+        * platform/OpenSSL.cmake:
+
 2021-05-06  Eric Carlson  <[email protected]>
 
         r277122 caused a crash in GPU Process

Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h (277141 => 277142)


--- trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h	2021-05-07 00:17:05 UTC (rev 277142)
@@ -51,8 +51,9 @@
 #endif
 
 #if USE(OPENSSL)
-typedef void* PlatformRSAKey;
-typedef std::unique_ptr<PlatformRSAKey> PlatformRSAKeyContainer;
+#include "crypto/openssl/OpenSSLCryptoUniquePtr.h"
+typedef EVP_PKEY* PlatformRSAKey;
+typedef WebCore::EvpPKeyPtr PlatformRSAKeyContainer;
 #endif
 
 namespace WebCore {

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmHMACOpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmHMACOpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmHMACOpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -30,29 +30,12 @@
 
 #include "CryptoKeyHMAC.h"
 #include "OpenSSLCryptoUniquePtr.h"
+#include "OpenSSLUtilities.h"
 #include <openssl/evp.h>
 #include <wtf/CryptographicUtilities.h>
 
 namespace WebCore {
 
-static const EVP_MD* HMACAlgorithm(CryptoAlgorithmIdentifier hashFunction)
-{
-    switch (hashFunction) {
-    case CryptoAlgorithmIdentifier::SHA_1:
-        return EVP_sha1();
-    case CryptoAlgorithmIdentifier::SHA_224:
-        return EVP_sha224();
-    case CryptoAlgorithmIdentifier::SHA_256:
-        return EVP_sha256();
-    case CryptoAlgorithmIdentifier::SHA_384:
-        return EVP_sha384();
-    case CryptoAlgorithmIdentifier::SHA_512:
-        return EVP_sha512();
-    default:
-        return nullptr;
-    }
-}
-
 static Optional<Vector<uint8_t>> calculateSignature(const EVP_MD* algorithm, const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength)
 {
     // Create the Message Digest Context
@@ -87,7 +70,7 @@
 
 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHMAC::platformSign(const CryptoKeyHMAC& key, const Vector<uint8_t>& data)
 {
-    auto algorithm = HMACAlgorithm(key.hashAlgorithmIdentifier());
+    auto algorithm = digestAlgorithm(key.hashAlgorithmIdentifier());
     if (!algorithm)
         return Exception { OperationError };
 
@@ -99,7 +82,7 @@
 
 ExceptionOr<bool> CryptoAlgorithmHMAC::platformVerify(const CryptoKeyHMAC& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
-    auto algorithm = HMACAlgorithm(key.hashAlgorithmIdentifier());
+    auto algorithm = digestAlgorithm(key.hashAlgorithmIdentifier());
     if (!algorithm)
         return Exception { OperationError };
 

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,20 +29,56 @@
 #if ENABLE(WEB_CRYPTO)
 
 #include "CryptoKeyRSA.h"
-#include "NotImplemented.h"
+#include "OpenSSLUtilities.h"
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_encrypt_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PADDING) <= 0)
+        return Exception { OperationError };
+
+    size_t cipherTextLen;
+    if (EVP_PKEY_encrypt(ctx.get(), nullptr, &cipherTextLen, plainText.data(), plainText.size()) <= 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> cipherText(cipherTextLen);
+    if (EVP_PKEY_encrypt(ctx.get(), cipherText.data(), &cipherTextLen, plainText.data(), plainText.size()) <= 0)
+        return Exception { OperationError };
+    cipherText.shrink(cipherTextLen);
+
+    return cipherText;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKeyRSA&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_decrypt_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PADDING) <= 0)
+        return Exception { OperationError };
+
+    size_t plainTextLen;
+    if (EVP_PKEY_decrypt(ctx.get(), nullptr, &plainTextLen, cipherText.data(), cipherText.size()) <= 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> plainText(plainTextLen);
+    if (EVP_PKEY_decrypt(ctx.get(), plainText.data(), &plainTextLen, cipherText.data(), cipherText.size()) <= 0)
+        return Exception { OperationError };
+    plainText.shrink(plainTextLen);
+
+    return plainText;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSASSA_PKCS1_v1_5OpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSASSA_PKCS1_v1_5OpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSASSA_PKCS1_v1_5OpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,20 +29,71 @@
 #if ENABLE(WEB_CRYPTO)
 
 #include "CryptoKeyRSA.h"
-#include "NotImplemented.h"
+#include "OpenSSLUtilities.h"
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKeyRSA&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKeyRSA& key, const Vector<uint8_t>& data)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    const EVP_MD* md = digestAlgorithm(key.hashAlgorithmIdentifier());
+    if (!md)
+        return Exception { NotSupportedError };
+
+    Optional<Vector<uint8_t>> digest = calculateDigest(md, data);
+    if (!digest)
+        return Exception { OperationError };
+
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_sign_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PADDING) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_signature_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    size_t signatureLen;
+    if (EVP_PKEY_sign(ctx.get(), nullptr, &signatureLen, digest->data(), digest->size()) <= 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> signature(signatureLen);
+    if (EVP_PKEY_sign(ctx.get(), signature.data(), &signatureLen, digest->data(), digest->size()) <= 0)
+        return Exception { OperationError };
+    signature.shrink(signatureLen);
+
+    return signature;
 }
 
-ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKeyRSA&, const Vector<uint8_t>&, const Vector<uint8_t>&)
+ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKeyRSA& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    const EVP_MD* md = digestAlgorithm(key.hashAlgorithmIdentifier());
+    if (!md)
+        return Exception { NotSupportedError };
+
+    Optional<Vector<uint8_t>> digest = calculateDigest(md, data);
+    if (!digest)
+        return Exception { OperationError };
+
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_verify_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PADDING) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_signature_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    int ret = EVP_PKEY_verify(ctx.get(), signature.data(), signature.size(), digest->data(), digest->size());
+
+    return ret == 1;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_OAEPOpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_OAEPOpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_OAEPOpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,20 +30,106 @@
 
 #include "CryptoAlgorithmRsaOaepParams.h"
 #include "CryptoKeyRSA.h"
-#include "NotImplemented.h"
+#include "OpenSSLUtilities.h"
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParams&, const CryptoKeyRSA&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
 {
-    notImplemented();
+#if defined(EVP_PKEY_CTX_set_rsa_oaep_md) && defined(EVP_PKEY_CTX_set_rsa_mgf1_md) && defined(EVP_PKEY_CTX_set0_rsa_oaep_label)
+    const EVP_MD* md = digestAlgorithm(key.hashAlgorithmIdentifier());
+    if (!md)
+        return Exception { NotSupportedError };
+
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_encrypt_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_OAEP_PADDING) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    if (!parameters.labelVector().isEmpty()) {
+        size_t labelSize = parameters.labelVector().size();
+        // The library takes ownership of the label so the caller should not free the original memory pointed to by label.
+        auto label = OPENSSL_malloc(labelSize);
+        memcpy(label, parameters.labelVector().data(), labelSize);
+        if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, labelSize) <= 0) {
+            OPENSSL_free(label);
+            return Exception { OperationError };
+        }
+    }
+
+    size_t cipherTextLen;
+    if (EVP_PKEY_encrypt(ctx.get(), nullptr, &cipherTextLen, plainText.data(), plainText.size()) <= 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> cipherText(cipherTextLen);
+    if (EVP_PKEY_encrypt(ctx.get(), cipherText.data(), &cipherTextLen, plainText.data(), plainText.size()) <= 0)
+        return Exception { OperationError };
+    cipherText.shrink(cipherTextLen);
+
+    return cipherText;
+#else
     return Exception { NotSupportedError };
+#endif
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParams&, const CryptoKeyRSA&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
 {
-    notImplemented();
+#if defined(EVP_PKEY_CTX_set_rsa_oaep_md) && defined(EVP_PKEY_CTX_set_rsa_mgf1_md) && defined(EVP_PKEY_CTX_set0_rsa_oaep_label)
+    const EVP_MD* md = digestAlgorithm(key.hashAlgorithmIdentifier());
+    if (!md)
+        return Exception { NotSupportedError };
+
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_decrypt_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_OAEP_PADDING) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    if (!parameters.labelVector().isEmpty()) {
+        size_t labelSize = parameters.labelVector().size();
+        // The library takes ownership of the label so the caller should not free the original memory pointed to by label.
+        auto label = OPENSSL_malloc(labelSize);
+        memcpy(label, parameters.labelVector().data(), labelSize);
+        if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, labelSize) <= 0) {
+            OPENSSL_free(label);
+            return Exception { OperationError };
+        }
+    }
+
+    size_t plainTextLen;
+    if (EVP_PKEY_decrypt(ctx.get(), nullptr, &plainTextLen, cipherText.data(), cipherText.size()) <= 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> plainText(plainTextLen);
+    if (EVP_PKEY_decrypt(ctx.get(), plainText.data(), &plainTextLen, cipherText.data(), cipherText.size()) <= 0)
+        return Exception { OperationError };
+    plainText.shrink(plainTextLen);
+
+    return plainText;
+#else
     return Exception { NotSupportedError };
+#endif
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_PSSOpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_PSSOpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_PSSOpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,20 +30,91 @@
 
 #include "CryptoAlgorithmRsaPssParams.h"
 #include "CryptoKeyRSA.h"
-#include "NotImplemented.h"
+#include "OpenSSLUtilities.h"
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(const CryptoAlgorithmRsaPssParams&, const CryptoKeyRSA&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(const CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& data)
 {
-    notImplemented();
+#if defined(EVP_PKEY_CTX_set_rsa_pss_saltlen) && defined(EVP_PKEY_CTX_set_rsa_mgf1_md)
+    const EVP_MD* md = digestAlgorithm(key.hashAlgorithmIdentifier());
+    if (!md)
+        return Exception { NotSupportedError };
+
+    Optional<Vector<uint8_t>> digest = calculateDigest(md, data);
+    if (!digest)
+        return Exception { OperationError };
+
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_sign_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PSS_PADDING ) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx.get(), parameters.saltLength) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_signature_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    size_t signatureLen;
+    if (EVP_PKEY_sign(ctx.get(), nullptr, &signatureLen, digest->data(), digest->size()) <= 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> signature(signatureLen);
+    if (EVP_PKEY_sign(ctx.get(), signature.data(), &signatureLen, digest->data(), digest->size()) <= 0)
+        return Exception { OperationError };
+    signature.shrink(signatureLen);
+
+    return signature;
+#else
     return Exception { NotSupportedError };
+#endif
 }
 
-ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(const CryptoAlgorithmRsaPssParams&, const CryptoKeyRSA&, const Vector<uint8_t>&, const Vector<uint8_t>&)
+ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(const CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
-    notImplemented();
+#if defined(EVP_PKEY_CTX_set_rsa_pss_saltlen) && defined(EVP_PKEY_CTX_set_rsa_mgf1_md)
+    const EVP_MD* md = digestAlgorithm(key.hashAlgorithmIdentifier());
+    if (!md)
+        return Exception { NotSupportedError };
+
+    Optional<Vector<uint8_t>> digest = calculateDigest(md, data);
+    if (!digest)
+        return Exception { OperationError };
+
+    auto ctx = EvpPKeyCtxPtr(EVP_PKEY_CTX_new(key.platformKey(), nullptr));
+    if (!ctx)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_verify_init(ctx.get()) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PSS_PADDING ) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx.get(), parameters.saltLength) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_signature_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    if (EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), md) <= 0)
+        return Exception { OperationError };
+
+    int ret = EVP_PKEY_verify(ctx.get(), signature.data(), signature.size(), digest->data(), digest->size());
+
+    return ret == 1;
+#else
     return Exception { NotSupportedError };
+#endif
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -34,6 +34,10 @@
 #include "CryptoAlgorithmAES_GCM.h"
 #include "CryptoAlgorithmAES_KW.h"
 #include "CryptoAlgorithmHMAC.h"
+#include "CryptoAlgorithmRSAES_PKCS1_v1_5.h"
+#include "CryptoAlgorithmRSASSA_PKCS1_v1_5.h"
+#include "CryptoAlgorithmRSA_OAEP.h"
+#include "CryptoAlgorithmRSA_PSS.h"
 #include "CryptoAlgorithmSHA1.h"
 #include "CryptoAlgorithmSHA224.h"
 #include "CryptoAlgorithmSHA256.h"
@@ -50,6 +54,10 @@
     registerAlgorithm<CryptoAlgorithmAES_GCM>();
     registerAlgorithm<CryptoAlgorithmAES_KW>();
     registerAlgorithm<CryptoAlgorithmHMAC>();
+    registerAlgorithm<CryptoAlgorithmRSAES_PKCS1_v1_5>();
+    registerAlgorithm<CryptoAlgorithmRSASSA_PKCS1_v1_5>();
+    registerAlgorithm<CryptoAlgorithmRSA_OAEP>();
+    registerAlgorithm<CryptoAlgorithmRSA_PSS>();
     registerAlgorithm<CryptoAlgorithmSHA1>();
     registerAlgorithm<CryptoAlgorithmSHA224>();
     registerAlgorithm<CryptoAlgorithmSHA256>();

Modified: trunk/Source/WebCore/crypto/openssl/CryptoKeyRSAOpenSSL.cpp (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/CryptoKeyRSAOpenSSL.cpp	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/CryptoKeyRSAOpenSSL.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,71 +28,338 @@
 
 #if ENABLE(WEB_CRYPTO)
 
+#include "CryptoAlgorithmRegistry.h"
+#include "CryptoKeyPair.h"
 #include "CryptoKeyRSAComponents.h"
-#include "NotImplemented.h"
+#include <openssl/X509.h>
+#include <openssl/evp.h>
 
 namespace WebCore {
 
-RefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier, bool hasHash, const CryptoKeyRSAComponents&, bool extractable, CryptoKeyUsageBitmap)
+static size_t getRSAModulusLength(RSA* rsa)
 {
-    UNUSED_PARAM(hasHash);
-    UNUSED_PARAM(extractable);
-    notImplemented();
-    return nullptr;
+    if (!rsa)
+        return 0;
+    return BN_num_bytes(rsa->n) * 8;
 }
 
-bool CryptoKeyRSA::isRestrictedToHash(CryptoAlgorithmIdentifier&) const
+static Vector<uint8_t> convertToBytes(BIGNUM* bignum)
 {
-    notImplemented();
+    Vector<uint8_t> bytes(BN_num_bytes(bignum));
+    BN_bn2bin(bignum, bytes.data());
+    return bytes;
+}
+
+static BIGNUM* convertToBigNumber(BIGNUM* bignum, const Vector<uint8_t>& bytes)
+{
+    return BN_bin2bn(bytes.data(), bytes.size(), bignum);
+}
+
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, const CryptoKeyRSAComponents& keyData, bool extractable, CryptoKeyUsageBitmap usages)
+{
+    CryptoKeyType keyType;
+    switch (keyData.type()) {
+    case CryptoKeyRSAComponents::Type::Public:
+        keyType = CryptoKeyType::Public;
+        break;
+    case CryptoKeyRSAComponents::Type::Private:
+        keyType = CryptoKeyType::Private;
+        break;
+    default:
+        return nullptr;
+    }
+
+    // When creating a private key, we require the p and q prime information.
+    if (keyType == CryptoKeyType::Private && !keyData.hasAdditionalPrivateKeyParameters())
+        return nullptr;
+
+    // But we don't currently support creating keys with any additional prime information.
+    if (!keyData.otherPrimeInfos().isEmpty())
+        return nullptr;
+
+    // For both public and private keys, we need the public modulus and exponent.
+    if (keyData.modulus().isEmpty() || keyData.exponent().isEmpty())
+        return nullptr;
+
+    // For private keys, we require the private exponent, as well as p and q prime information.
+    if (keyType == CryptoKeyType::Private) {
+        if (keyData.privateExponent().isEmpty() || keyData.firstPrimeInfo().primeFactor.isEmpty() || keyData.secondPrimeInfo().primeFactor.isEmpty())
+            return nullptr;
+    }
+
+    auto rsa = RSAPtr(RSA_new());
+    if (!rsa)
+        return nullptr;
+
+    rsa->n = convertToBigNumber(rsa->n, keyData.modulus());
+    rsa->e = convertToBigNumber(rsa->e, keyData.exponent());
+    if (!rsa->n || !rsa->e)
+        return nullptr;
+
+    if (keyType == CryptoKeyType::Private) {
+        rsa->d = convertToBigNumber(rsa->d, keyData.privateExponent());
+        rsa->p = convertToBigNumber(rsa->p, keyData.firstPrimeInfo().primeFactor);
+        rsa->q = convertToBigNumber(rsa->q, keyData.secondPrimeInfo().primeFactor);
+        if (!rsa->d || !rsa->p || !rsa->q)
+            return nullptr;
+
+        // We set dmp1, dmpq1, and iqmp member of the RSA struct if the keyData has corresponding data.
+
+        // dmp1 -- d mod (p - 1)
+        if (!keyData.firstPrimeInfo().factorCRTExponent.isEmpty())
+            rsa->dmp1 = convertToBigNumber(rsa->dmp1, keyData.firstPrimeInfo().factorCRTExponent);
+        // dmq1 -- d mod (q - 1)
+        if (!keyData.secondPrimeInfo().factorCRTExponent.isEmpty())
+            rsa->dmq1 = convertToBigNumber(rsa->dmq1, keyData.secondPrimeInfo().factorCRTExponent);
+        // iqmp -- q^(-1) mod p
+        if (!keyData.secondPrimeInfo().factorCRTCoefficient.isEmpty())
+            rsa->iqmp = convertToBigNumber(rsa->iqmp, keyData.secondPrimeInfo().factorCRTCoefficient);
+    }
+
+    auto pkey = EvpPKeyPtr(EVP_PKEY_new());
+    if (!pkey)
+        return nullptr;
+
+    if (EVP_PKEY_set1_RSA(pkey.get(), rsa.get()) != 1)
+        return nullptr;
+
+    return adoptRef(new CryptoKeyRSA(identifier, hash, hasHash, keyType, WTFMove(pkey), extractable, usages));
+}
+
+CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKeyContainer&& platformKey, bool extractable, CryptoKeyUsageBitmap usages)
+    : CryptoKey(identifier, type, extractable, usages)
+    , m_platformKey(WTFMove(platformKey))
+    , m_restrictedToSpecificHash(hasHash)
+    , m_hash(hash)
+{
+}
+
+bool CryptoKeyRSA::isRestrictedToHash(CryptoAlgorithmIdentifier& identifier) const
+{
+    if (!m_restrictedToSpecificHash)
+        return false;
+
+    identifier = m_hash;
     return true;
 }
 
 size_t CryptoKeyRSA::keySizeInBits() const
 {
-    notImplemented();
-    return 0;
+    RSA* rsa = EVP_PKEY_get0_RSA(m_platformKey.get());
+    if (!rsa)
+        return 0;
+
+    return getRSAModulusLength(rsa);
 }
 
-void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsageBitmap, KeyPairCallback&&, VoidCallback&& failureCallback, ScriptExecutionContext*)
+// Convert the exponent vector to a 32-bit value, if possible.
+static Optional<uint32_t> exponentVectorToUInt32(const Vector<uint8_t>& exponent)
 {
-    UNUSED_PARAM(hasHash);
-    UNUSED_PARAM(modulusLength);
-    UNUSED_PARAM(publicExponent);
-    UNUSED_PARAM(extractable);
-    UNUSED_PARAM(failureCallback);
-    notImplemented();
+    if (exponent.size() > 4) {
+        if (std::any_of(exponent.begin(), exponent.end() - 4, [](uint8_t element) { return !!element; }))
+            return WTF::nullopt;
+    }
+
+    uint32_t result = 0;
+    for (size_t size = exponent.size(), i = std::min<size_t>(4, size); i > 0; --i) {
+        result <<= 8;
+        result += exponent[size - i];
+    }
+
+    return result;
 }
 
-RefPtr<CryptoKeyRSA> CryptoKeyRSA::importSpki(CryptoAlgorithmIdentifier, Optional<CryptoAlgorithmIdentifier>, Vector<uint8_t>&&, bool extractable, CryptoKeyUsageBitmap)
+void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsageBitmap usages, KeyPairCallback&& callback, VoidCallback&& failureCallback, ScriptExecutionContext*)
 {
-    UNUSED_PARAM(extractable);
-    notImplemented();
-    return nullptr;
+    // OpenSSL doesn't report an error if the exponent is smaller than three or even.
+    auto e = exponentVectorToUInt32(publicExponent);
+    if (!e || *e < 3 || !(*e & 0x1)) {
+        failureCallback();
+        return;
+    }
+
+    auto exponent = BIGNUMPtr(convertToBigNumber(nullptr, publicExponent));
+    auto privateRSA = RSAPtr(RSA_new());
+    if (!exponent || RSA_generate_key_ex(privateRSA.get(), modulusLength, exponent.get(), nullptr) <= 0) {
+        failureCallback();
+        return;
+    }
+
+    auto publicRSA = RSAPtr(RSAPublicKey_dup(privateRSA.get()));
+    if (!publicRSA) {
+        failureCallback();
+        return;
+    }
+
+    auto privatePKey = EvpPKeyPtr(EVP_PKEY_new());
+    if (EVP_PKEY_set1_RSA(privatePKey.get(), privateRSA.get()) <= 0) {
+        failureCallback();
+        return;
+    }
+
+    auto publicPKey = EvpPKeyPtr(EVP_PKEY_new());
+    if (EVP_PKEY_set1_RSA(publicPKey.get(), publicRSA.get()) <= 0) {
+        failureCallback();
+        return;
+    }
+
+    auto publicKey = CryptoKeyRSA::create(algorithm, hash, hasHash, CryptoKeyType::Public, WTFMove(publicPKey), true, usages);
+    auto privateKey = CryptoKeyRSA::create(algorithm, hash, hasHash, CryptoKeyType::Private, WTFMove(privatePKey), extractable, usages);
+    callback(CryptoKeyPair { WTFMove(publicKey), WTFMove(privateKey) });
 }
 
-RefPtr<CryptoKeyRSA> CryptoKeyRSA::importPkcs8(CryptoAlgorithmIdentifier, Optional<CryptoAlgorithmIdentifier>, Vector<uint8_t>&&, bool extractable, CryptoKeyUsageBitmap)
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::importSpki(CryptoAlgorithmIdentifier identifier, Optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&& keyData, bool extractable, CryptoKeyUsageBitmap usages)
 {
-    UNUSED_PARAM(extractable);
-    notImplemented();
-    return nullptr;
+    // We need a local pointer variable to pass to d2i (DER to internal) functions().
+    const uint8_t* ptr = keyData.data();
+
+    // We use d2i_PUBKEY() to import a public key.
+    auto pkey = EvpPKeyPtr(d2i_PUBKEY(nullptr, &ptr, keyData.size()));
+    if (!pkey)
+        return nullptr;
+
+    return adoptRef(new CryptoKeyRSA(identifier, hash.valueOr(CryptoAlgorithmIdentifier::SHA_1), !!hash, CryptoKeyType::Public, WTFMove(pkey), extractable, usages));
 }
 
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::importPkcs8(CryptoAlgorithmIdentifier identifier, Optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&& keyData, bool extractable, CryptoKeyUsageBitmap usages)
+{
+    // We need a local pointer variable to pass to d2i (DER to internal) functions().
+    const uint8_t* ptr = keyData.data();
+
+    // We use d2i_PKCS8_PRIV_KEY_INFO() to import a private key.
+    auto p8inf = PKCS8PrivKeyInfoPtr(d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, keyData.size()));
+    if (!p8inf)
+        return nullptr;
+
+    auto pkey = EvpPKeyPtr(EVP_PKCS82PKEY(p8inf.get()));
+    if (!pkey)
+        return nullptr;
+
+    return adoptRef(new CryptoKeyRSA(identifier, hash.valueOr(CryptoAlgorithmIdentifier::SHA_1), !!hash, CryptoKeyType::Private, WTFMove(pkey), extractable, usages));
+}
+
 ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportSpki() const
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    if (type() != CryptoKeyType::Public)
+        return Exception { InvalidAccessError };
+
+    int len = i2d_PUBKEY(m_platformKey.get(), nullptr);
+    if (len < 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> keyData(len);
+    auto ptr = keyData.data();
+    if (i2d_PUBKEY(m_platformKey.get(), &ptr) < 0)
+        return Exception { OperationError };
+
+    return keyData;
 }
 
 ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportPkcs8() const
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    if (type() != CryptoKeyType::Private)
+        return Exception { InvalidAccessError };
+
+    auto p8inf = PKCS8PrivKeyInfoPtr(EVP_PKEY2PKCS8(m_platformKey.get()));
+    if (!p8inf)
+        return Exception { OperationError };
+
+    int len = i2d_PKCS8_PRIV_KEY_INFO(p8inf.get(), nullptr);
+    if (len < 0)
+        return Exception { OperationError };
+
+    Vector<uint8_t> keyData(len);
+    auto ptr = keyData.data();
+    if (i2d_PKCS8_PRIV_KEY_INFO(p8inf.get(), &ptr) < 0)
+        return Exception { OperationError };
+
+    return keyData;
 }
 
+auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
+{
+    RSA* rsa = EVP_PKEY_get0_RSA(m_platformKey.get());
+
+    auto modulusLength = getRSAModulusLength(rsa);
+    auto publicExponent = rsa ? convertToBytes(rsa->e) : Vector<uint8_t> { };
+
+    if (m_restrictedToSpecificHash) {
+        CryptoRsaHashedKeyAlgorithm result;
+        result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+        result.modulusLength = modulusLength;
+        result.publicExponent = Uint8Array::tryCreate(publicExponent.data(), publicExponent.size());
+        result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash);
+        return result;
+    }
+
+    CryptoRsaKeyAlgorithm result;
+    result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+    result.modulusLength = modulusLength;
+    result.publicExponent = Uint8Array::tryCreate(publicExponent.data(), publicExponent.size());
+    return result;
+}
+
 std::unique_ptr<CryptoKeyRSAComponents> CryptoKeyRSA::exportData() const
 {
-    notImplemented();
-    return nullptr;
+    RSA* rsa = EVP_PKEY_get0_RSA(m_platformKey.get());
+    if (!rsa)
+        return nullptr;
+
+    switch (type()) {
+    case CryptoKeyType::Public:
+        // We need the public modulus and exponent for the public key.
+        if (!rsa->n || !rsa->e)
+            return nullptr;
+        return CryptoKeyRSAComponents::createPublic(convertToBytes(rsa->n), convertToBytes(rsa->e));
+    case CryptoKeyType::Private: {
+        // We need the public modulus, exponent, and private exponent, as well as p and q prime information.
+        if (!rsa->n || !rsa->e || !rsa->d || !rsa->p || !rsa->q)
+            return nullptr;
+
+        CryptoKeyRSAComponents::PrimeInfo firstPrimeInfo;
+        firstPrimeInfo.primeFactor = convertToBytes(rsa->p);
+
+        CryptoKeyRSAComponents::PrimeInfo secondPrimeInfo;
+        secondPrimeInfo.primeFactor = convertToBytes(rsa->q);
+
+        auto context = BNCtxPtr(BN_CTX_new());
+        // dmp1 -- d mod (p - 1)
+        if (rsa->dmp1)
+            firstPrimeInfo.factorCRTExponent = convertToBytes(rsa->dmp1);
+        else {
+            auto dmp1 = BIGNUMPtr(BN_new());
+            auto pm1 = BIGNUMPtr(BN_dup(rsa->p));
+            if (BN_sub_word(pm1.get(), 1) == 1 && BN_mod(dmp1.get(), rsa->d, pm1.get(), context.get()) == 1)
+                firstPrimeInfo.factorCRTExponent = convertToBytes(dmp1.get());
+        }
+
+        // dmq1 -- d mod (q - 1)
+        if (rsa->dmq1)
+            secondPrimeInfo.factorCRTExponent = convertToBytes(rsa->dmq1);
+        else {
+            auto dmq1 = BIGNUMPtr(BN_new());
+            auto qm1 = BIGNUMPtr(BN_dup(rsa->q));
+            if (BN_sub_word(qm1.get(), 1) == 1 && BN_mod(dmq1.get(), rsa->d, qm1.get(), context.get()) == 1)
+                secondPrimeInfo.factorCRTExponent = convertToBytes(dmq1.get());
+        }
+
+        // iqmp -- q^(-1) mod p
+        if (rsa->iqmp)
+            secondPrimeInfo.factorCRTCoefficient = convertToBytes(rsa->iqmp);
+        else {
+            auto iqmp = BIGNUMPtr(BN_mod_inverse(nullptr, rsa->q, rsa->p, context.get()));
+            if (iqmp)
+                secondPrimeInfo.factorCRTCoefficient = convertToBytes(iqmp.get());
+        }
+
+        return CryptoKeyRSAComponents::createPrivateWithAdditionalData(
+            convertToBytes(rsa->n), convertToBytes(rsa->e), convertToBytes(rsa->d),
+            WTFMove(firstPrimeInfo), WTFMove(secondPrimeInfo), Vector<CryptoKeyRSAComponents::PrimeInfo> { });
+    }
+    default:
+        ASSERT_NOT_REACHED();
+        return nullptr;
+    }
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/openssl/OpenSSLCryptoUniquePtr.h (277141 => 277142)


--- trunk/Source/WebCore/crypto/openssl/OpenSSLCryptoUniquePtr.h	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/crypto/openssl/OpenSSLCryptoUniquePtr.h	2021-05-07 00:17:05 UTC (rev 277142)
@@ -27,7 +27,7 @@
 #pragma once
 
 #include <memory>
-#include <openssl/evp.h>
+#include <openssl/X509.h>
 
 namespace WebCore {
 
@@ -69,4 +69,55 @@
 
 using EvpPKeyPtr = OpenSSLCryptoPtr<EVP_PKEY>;
 
+template <>
+struct OpenSSLCryptoPtrDeleter<EVP_PKEY_CTX> {
+    void operator()(EVP_PKEY_CTX* ptr) const
+    {
+        EVP_PKEY_CTX_free(ptr);
+    }
+};
+
+using EvpPKeyCtxPtr = OpenSSLCryptoPtr<EVP_PKEY_CTX>;
+
+template <>
+struct OpenSSLCryptoPtrDeleter<RSA> {
+    void operator()(RSA* ptr) const
+    {
+        RSA_free(ptr);
+    }
+};
+
+using RSAPtr = OpenSSLCryptoPtr<RSA>;
+
+template <>
+struct OpenSSLCryptoPtrDeleter<PKCS8_PRIV_KEY_INFO> {
+    void operator()(PKCS8_PRIV_KEY_INFO* ptr) const
+    {
+        PKCS8_PRIV_KEY_INFO_free(ptr);
+    }
+};
+
+using PKCS8PrivKeyInfoPtr = OpenSSLCryptoPtr<PKCS8_PRIV_KEY_INFO>;
+
+template <>
+struct OpenSSLCryptoPtrDeleter<BIGNUM> {
+    void operator()(BIGNUM* ptr) const
+    {
+        BN_clear_free(ptr);
+    }
+};
+
+using BIGNUMPtr = OpenSSLCryptoPtr<BIGNUM>;
+
+template <>
+struct OpenSSLCryptoPtrDeleter<BN_CTX> {
+    void operator()(BN_CTX* ptr) const
+    {
+        BN_CTX_free(ptr);
+    }
+};
+
+using BNCtxPtr = OpenSSLCryptoPtr<BN_CTX>;
+
+
 } // namespace WebCore

Copied: trunk/Source/WebCore/crypto/openssl/OpenSSLUtilities.cpp (from rev 277141, trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSA_OAEPOpenSSL.cpp) (0 => 277142)


--- trunk/Source/WebCore/crypto/openssl/OpenSSLUtilities.cpp	                        (rev 0)
+++ trunk/Source/WebCore/crypto/openssl/OpenSSLUtilities.cpp	2021-05-07 00:17:05 UTC (rev 277142)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "OpenSSLUtilities.h"
+
+#if ENABLE(WEB_CRYPTO)
+
+#include "OpenSSLCryptoUniquePtr.h"
+
+namespace WebCore {
+
+const EVP_MD* digestAlgorithm(CryptoAlgorithmIdentifier hashFunction)
+{
+    switch (hashFunction) {
+    case CryptoAlgorithmIdentifier::SHA_1:
+        return EVP_sha1();
+    case CryptoAlgorithmIdentifier::SHA_224:
+        return EVP_sha224();
+    case CryptoAlgorithmIdentifier::SHA_256:
+        return EVP_sha256();
+    case CryptoAlgorithmIdentifier::SHA_384:
+        return EVP_sha384();
+    case CryptoAlgorithmIdentifier::SHA_512:
+        return EVP_sha512();
+    default:
+        return nullptr;
+    }
+}
+
+Optional<Vector<uint8_t>> calculateDigest(const EVP_MD* algorithm, const Vector<uint8_t>& message)
+{
+    EvpDigestCtxPtr ctx;
+    if (!(ctx = EvpDigestCtxPtr(EVP_MD_CTX_create())))
+        return WTF::nullopt;
+
+    int digestLength = EVP_MD_size(algorithm);
+    if (digestLength <= 0)
+        return WTF::nullopt;
+    Vector<uint8_t> digest(digestLength);
+
+    if (EVP_DigestInit_ex(ctx.get(), algorithm, nullptr) != 1)
+        return WTF::nullopt;
+
+    if (EVP_DigestUpdate(ctx.get(), message.data(), message.size()) != 1)
+        return WTF::nullopt;
+
+    if (EVP_DigestFinal_ex(ctx.get(), digest.data(), nullptr) != 1)
+        return WTF::nullopt;
+
+    return digest;
+}
+
+} // namespace WebCore
+
+
+#endif // ENABLE(WEB_CRYPTO)

Copied: trunk/Source/WebCore/crypto/openssl/OpenSSLUtilities.h (from rev 277141, trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp) (0 => 277142)


--- trunk/Source/WebCore/crypto/openssl/OpenSSLUtilities.h	                        (rev 0)
+++ trunk/Source/WebCore/crypto/openssl/OpenSSLUtilities.h	2021-05-07 00:17:05 UTC (rev 277142)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CryptoAlgorithmIdentifier.h"
+#include <openssl/evp.h>
+#include <stdint.h>
+#include <wtf/Optional.h>
+#include <wtf/Vector.h>
+
+#if ENABLE(WEB_CRYPTO)
+
+namespace WebCore {
+
+const EVP_MD* digestAlgorithm(CryptoAlgorithmIdentifier hashFunction);
+
+Optional<Vector<uint8_t>> calculateDigest(const EVP_MD* algorithm, const Vector<uint8_t>& message);
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_CRYPTO)

Modified: trunk/Source/WebCore/platform/OpenSSL.cmake (277141 => 277142)


--- trunk/Source/WebCore/platform/OpenSSL.cmake	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/WebCore/platform/OpenSSL.cmake	2021-05-07 00:17:05 UTC (rev 277142)
@@ -17,6 +17,7 @@
         crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp
         crypto/openssl/CryptoKeyECOpenSSL.cpp
         crypto/openssl/CryptoKeyRSAOpenSSL.cpp
+        crypto/openssl/OpenSSLUtilities.cpp
         crypto/openssl/SerializedCryptoKeyWrapOpenSSL.cpp
     )
 endif ()

Modified: trunk/Source/cmake/OptionsPlayStation.cmake (277141 => 277142)


--- trunk/Source/cmake/OptionsPlayStation.cmake	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/cmake/OptionsPlayStation.cmake	2021-05-07 00:17:05 UTC (rev 277142)
@@ -145,9 +145,6 @@
     "${CMAKE_CXX_STANDARD_LIBRARIES} ${C_STD_LIBRARY}"
   )
 
-# TODO: Add a check for HAVE_RSA_PSS for support of CryptoAlgorithmRSA_PSS
-# https://bugs.webkit.org/show_bug.cgi?id=206635
-
 SET_AND_EXPOSE_TO_BUILD(HAVE_PTHREAD_SETNAME_NP ON)
 
 SET_AND_EXPOSE_TO_BUILD(USE_CAIRO ON)

Modified: trunk/Source/cmake/OptionsWinCairo.cmake (277141 => 277142)


--- trunk/Source/cmake/OptionsWinCairo.cmake	2021-05-07 00:14:55 UTC (rev 277141)
+++ trunk/Source/cmake/OptionsWinCairo.cmake	2021-05-07 00:17:05 UTC (rev 277142)
@@ -41,9 +41,6 @@
     SET_AND_EXPOSE_TO_BUILD(USE_WEBP ON)
 endif ()
 
-# TODO: Add a check for HAVE_RSA_PSS for support of CryptoAlgorithmRSA_PSS
-# https://bugs.webkit.org/show_bug.cgi?id=206635
-
 set(USE_ANGLE_EGL ON)
 set(USE_ANGLE_WEBGL ON)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to