Changeset 160029 in webkit
- Timestamp:
- Dec 3, 2013, 12:18:14 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r160027 r160029 1 2013-12-03 Alexey Proskuryakov <ap@apple.com> 2 3 Support exporting private WebCrypto RSA keys 4 https://bugs.webkit.org/show_bug.cgi?id=124483 5 6 Reviewed by Anders Carlsson. 7 8 * crypto/subtle/rsa-export-private-key-expected.txt: Added. 9 * crypto/subtle/rsa-export-private-key.html: Added. 10 1 11 2013-12-03 Alexey Proskuryakov <ap@apple.com> 2 12 -
trunk/Source/WebCore/ChangeLog
r160024 r160029 1 2013-12-03 Alexey Proskuryakov <ap@apple.com> 2 3 Support exporting private WebCrypto RSA keys 4 https://bugs.webkit.org/show_bug.cgi?id=124483 5 6 Reviewed by Anders Carlsson. 7 8 Test: crypto/subtle/rsa-export-private-key.html 9 10 It might be better to have our own bignum implementation in WTF, but we currently 11 don't, and the need for this computation is Common Crypto specific anyway. 12 13 * crypto/CommonCryptoUtilities.h: 14 * crypto/CommonCryptoUtilities.cpp: 15 (WebCore::CCBigNum::CCBigNum): 16 (WebCore::CCBigNum::~CCBigNum): 17 (WebCore::CCBigNum::operator=): 18 (WebCore::CCBigNum::data): 19 (WebCore::CCBigNum::operator-): 20 (WebCore::CCBigNum::operator%): 21 (WebCore::CCBigNum::inverse): 22 Added a minimal wrapper around CommonCrypto BigNum. 23 24 * crypto/mac/CryptoKeyRSAMac.cpp: 25 (WebCore::getPrivateKeyComponents): Compute missing parts using CCBigNum. 26 (WebCore::CryptoKeyRSA::exportData): Implemented private key case. 27 1 28 2013-12-03 Ryosuke Niwa <rniwa@webkit.org> 2 29 -
trunk/Source/WebCore/crypto/CommonCryptoUtilities.cpp
r159944 r160029 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 30 31 #if defined(__has_include) 32 #if __has_include(<CommonCrypto/CommonBigNum.h>) 33 #include <CommonCrypto/CommonBigNum.h> 34 #endif 35 #endif 36 37 typedef CCCryptorStatus CCStatus; 38 extern "C" CCBigNumRef CCBigNumFromData(CCStatus *status, const void *s, size_t len); 39 extern "C" size_t CCBigNumToData(CCStatus *status, const CCBigNumRef bn, void *to); 40 extern "C" uint32_t CCBigNumByteCount(const CCBigNumRef bn); 41 extern "C" CCBigNumRef CCCreateBigNum(CCStatus *status); 42 extern "C" void CCBigNumFree(CCBigNumRef bn); 43 extern "C" CCBigNumRef CCBigNumCopy(CCStatus *status, const CCBigNumRef bn); 44 extern "C" CCStatus CCBigNumSubI(CCBigNumRef result, const CCBigNumRef a, const uint32_t b); 45 extern "C" CCStatus CCBigNumMod(CCBigNumRef result, CCBigNumRef dividend, CCBigNumRef modulus); 46 extern "C" CCStatus CCBigNumInverseMod(CCBigNumRef result, const CCBigNumRef a, const CCBigNumRef modulus); 47 31 48 namespace WebCore { 32 49 … … 54 71 } 55 72 73 CCBigNum::CCBigNum(CCBigNumRef number) 74 : m_number(number) 75 { 76 } 77 78 CCBigNum::CCBigNum(const uint8_t* data, size_t size) 79 { 80 CCStatus status = kCCSuccess; 81 m_number = CCBigNumFromData(&status, data, size); 82 RELEASE_ASSERT(!status); 83 } 84 85 CCBigNum::~CCBigNum() 86 { 87 CCBigNumFree(m_number); 88 } 89 90 CCBigNum::CCBigNum(const CCBigNum& other) 91 { 92 CCStatus status = kCCSuccess; 93 m_number = CCBigNumCopy(&status, other.m_number); 94 RELEASE_ASSERT(!status); 95 } 96 97 CCBigNum::CCBigNum(CCBigNum&& other) 98 { 99 m_number = other.m_number; 100 other.m_number = nullptr; 101 } 102 103 CCBigNum& CCBigNum::operator=(const CCBigNum& other) 104 { 105 if (this == &other) 106 return *this; 107 108 CCBigNumFree(m_number); 109 110 CCStatus status = kCCSuccess; 111 m_number = CCBigNumCopy(&status, other.m_number); 112 RELEASE_ASSERT(!status); 113 return *this; 114 } 115 116 CCBigNum& CCBigNum::operator=(CCBigNum&& other) 117 { 118 if (this == &other) 119 return *this; 120 121 m_number = other.m_number; 122 other.m_number = nullptr; 123 124 return *this; 125 } 126 127 Vector<uint8_t> CCBigNum::data() const 128 { 129 Vector<uint8_t> result(CCBigNumByteCount(m_number)); 130 CCStatus status = kCCSuccess; 131 CCBigNumToData(&status, m_number, result.data()); 132 RELEASE_ASSERT(!status); 133 134 return result; 135 } 136 137 CCBigNum CCBigNum::operator-(uint32_t b) const 138 { 139 CCStatus status = kCCSuccess; 140 CCBigNumRef result = CCCreateBigNum(&status); 141 RELEASE_ASSERT(!status); 142 143 status = CCBigNumSubI(result, m_number, b); 144 RELEASE_ASSERT(!status); 145 146 return result; 147 } 148 149 CCBigNum CCBigNum::operator%(const CCBigNum& modulus) const 150 { 151 CCStatus status = kCCSuccess; 152 CCBigNumRef result = CCCreateBigNum(&status); 153 RELEASE_ASSERT(!status); 154 155 status = CCBigNumMod(result, m_number, modulus.m_number); 156 RELEASE_ASSERT(!status); 157 158 return result; 159 } 160 161 CCBigNum CCBigNum::inverse(const CCBigNum& modulus) const 162 { 163 CCStatus status = kCCSuccess; 164 CCBigNumRef result = CCCreateBigNum(&status); 165 RELEASE_ASSERT(!status); 166 167 status = CCBigNumInverseMod(result, m_number, modulus.m_number); 168 RELEASE_ASSERT(!status); 169 170 return result; 171 } 172 56 173 } // namespace WebCore 57 174 -
trunk/Source/WebCore/crypto/CommonCryptoUtilities.h
r159951 r160029 30 30 31 31 #include "CryptoAlgorithmIdentifier.h" 32 33 32 #include <CommonCrypto/CommonCryptor.h> 33 #include <wtf/Vector.h> 34 34 35 35 #if defined(__has_include) … … 72 72 #endif 73 73 74 typedef struct _CCBigNumRef *CCBigNumRef; 75 74 76 typedef struct __CCRandom *CCRandomRef; 75 77 extern const CCRandomRef kCCRandomDefault; … … 90 92 namespace WebCore { 91 93 94 class CCBigNum { 95 public: 96 CCBigNum(const uint8_t*, size_t); 97 ~CCBigNum(); 98 99 CCBigNum(const CCBigNum&); 100 CCBigNum(CCBigNum&&); 101 CCBigNum& operator=(const CCBigNum&); 102 CCBigNum& operator=(CCBigNum&&); 103 104 Vector<uint8_t> data() const; 105 106 CCBigNum operator-(uint32_t) const; 107 CCBigNum operator%(const CCBigNum&) const; 108 CCBigNum inverse(const CCBigNum& modulus) const; 109 110 private: 111 CCBigNum(CCBigNumRef); 112 113 CCBigNumRef m_number; 114 }; 115 92 116 bool getCommonCryptoDigestAlgorithm(CryptoAlgorithmIdentifier, CCDigestAlgorithm&); 93 117 -
trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
r159951 r160029 60 60 } 61 61 62 static CCCryptorStatus getPrivateKeyComponents(CCRSACryptorRef rsaKey, Vector<uint8_t>& privateExponent, CryptoKeyDataRSAComponents::PrimeInfo& firstPrimeInfo, CryptoKeyDataRSAComponents::PrimeInfo& secondPrimeInfo) 63 { 64 ASSERT(CCRSAGetKeyType(rsaKey) == ccRSAKeyPrivate); 65 66 Vector<uint8_t> unusedModulus(16384); 67 size_t modulusLength = unusedModulus.size(); 68 privateExponent.resize(16384); 69 size_t exponentLength = privateExponent.size(); 70 firstPrimeInfo.primeFactor.resize(16384); 71 size_t pLength = firstPrimeInfo.primeFactor.size(); 72 secondPrimeInfo.primeFactor.resize(16384); 73 size_t qLength = secondPrimeInfo.primeFactor.size(); 74 75 CCCryptorStatus status = CCRSAGetKeyComponents(rsaKey, unusedModulus.data(), &modulusLength, privateExponent.data(), &exponentLength, firstPrimeInfo.primeFactor.data(), &pLength, secondPrimeInfo.primeFactor.data(), &qLength); 76 if (status) 77 return status; 78 79 privateExponent.shrink(exponentLength); 80 firstPrimeInfo.primeFactor.shrink(pLength); 81 secondPrimeInfo.primeFactor.shrink(qLength); 82 83 CCBigNum d(privateExponent.data(), privateExponent.size()); 84 CCBigNum p(firstPrimeInfo.primeFactor.data(), firstPrimeInfo.primeFactor.size()); 85 CCBigNum q(secondPrimeInfo.primeFactor.data(), secondPrimeInfo.primeFactor.size()); 86 87 CCBigNum dp = d % (p - 1); 88 CCBigNum dq = d % (q - 1); 89 CCBigNum qi = q.inverse(p); 90 91 firstPrimeInfo.factorCRTExponent = dp.data(); 92 secondPrimeInfo.factorCRTExponent = dq.data(); 93 secondPrimeInfo.factorCRTCoefficient = qi.data(); 94 95 return status; 96 } 97 62 98 CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage) 63 99 : CryptoKey(identifier, type, extractable, usage) … … 166 202 return CryptoKeyDataRSAComponents::createPublic(modulus, publicExponent); 167 203 } 168 case ccRSAKeyPrivate: 169 // Not supported yet. 204 case ccRSAKeyPrivate: { 205 Vector<uint8_t> modulus; 206 Vector<uint8_t> publicExponent; 207 CCCryptorStatus status = getPublicKeyComponents(m_platformKey, modulus, publicExponent); 208 if (status) { 209 WTFLogAlways("Couldn't get RSA key components, status %d", status); 210 return nullptr; 211 } 212 Vector<uint8_t> privateExponent; 213 CryptoKeyDataRSAComponents::PrimeInfo firstPrimeInfo; 214 CryptoKeyDataRSAComponents::PrimeInfo secondPrimeInfo; 215 Vector<CryptoKeyDataRSAComponents::PrimeInfo> otherPrimeInfos; // Always empty, CommonCrypto only supports two primes (cf. <rdar://problem/15444074>). 216 status = getPrivateKeyComponents(m_platformKey, privateExponent, firstPrimeInfo, secondPrimeInfo); 217 if (status) { 218 WTFLogAlways("Couldn't get RSA key components, status %d", status); 219 return nullptr; 220 } 221 return CryptoKeyDataRSAComponents::createPrivateWithAdditionalData(modulus, publicExponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos); 222 } 170 223 default: 171 224 return nullptr;
Note:
See TracChangeset
for help on using the changeset viewer.