[WebCrypto][Mac] Replace CCECCryptorGetKeyComponents with CCECCryptorExportKey for...
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Aug 2017 21:30:45 +0000 (21:30 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Aug 2017 21:30:45 +0000 (21:30 +0000)
commita66b4c8c610fb960f7bb0eebc8eef8df9c215635
treecd440c08f415ccc4d5cd8ece37b78c5a599f537e
parente9b2899c7ff211a35e97a54f693d82489461245b
[WebCrypto][Mac] Replace CCECCryptorGetKeyComponents with CCECCryptorExportKey for exporting ECC JWKs
https://bugs.webkit.org/show_bug.cgi?id=175657
<rdar://problem/33797150>

Reviewed by Brent Fulgham.

Source/WebCore:

CCECCryptorGetKeyComponents returns components in unpadded formats. In some minor cases, the ECC components
do need padding. Therefore, we occasionally see some corrupted outputs in JWKs. To overcome that, this patch
replaces CCECCryptorGetKeyComponents with CCECCryptorExportKey which does padding all the time.

In the meantime, this patch also makes export* methods return OperationError if any error occur in the
underlying operations though very unlikely.

Test: crypto/subtle/ecdsa-generate-export-import-jwk-sign-verify.html

* crypto/algorithms/CryptoAlgorithmECDH.cpp:
(WebCore::CryptoAlgorithmECDH::exportKey):
* crypto/algorithms/CryptoAlgorithmECDSA.cpp:
(WebCore::CryptoAlgorithmECDSA::exportKey):
* crypto/gcrypt/CryptoKeyECGCrypt.cpp:
(WebCore::CryptoKeyEC::platformAddFieldElements const):
* crypto/keys/CryptoKeyEC.cpp:
(WebCore::CryptoKeyEC::exportRaw const):
(WebCore::CryptoKeyEC::exportJwk const):
(WebCore::CryptoKeyEC::exportSpki const):
(WebCore::CryptoKeyEC::exportPkcs8 const):
* crypto/keys/CryptoKeyEC.h:
* crypto/mac/CryptoKeyECMac.cpp:
(WebCore::CryptoKeyEC::platformExportRaw const):
(WebCore::CryptoKeyEC::platformAddFieldElements const):
(WebCore::CryptoKeyEC::platformExportSpki const):
(WebCore::CryptoKeyEC::platformExportPkcs8 const):

LayoutTests:

* crypto/subtle/ecdsa-generate-export-import-jwk-sign-verify-expected.txt: Added.
* crypto/subtle/ecdsa-generate-export-import-jwk-sign-verify.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220933 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/ecdsa-generate-export-import-jwk-sign-verify-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-import-jwk-sign-verify.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.cpp
Source/WebCore/crypto/gcrypt/CryptoKeyECGCrypt.cpp
Source/WebCore/crypto/keys/CryptoKeyEC.cpp
Source/WebCore/crypto/keys/CryptoKeyEC.h
Source/WebCore/crypto/mac/CryptoKeyECMac.cpp