Changeset 214825 in webkit
- Timestamp:
- Apr 3, 2017 11:40:54 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r214823 r214825 1 2017-04-03 Zan Dobersek <zdobersek@igalia.com> 2 3 [GCrypt] Implement CryptoKeyEC::keySizeInBits(), ::platformGeneratePair() 4 https://bugs.webkit.org/show_bug.cgi?id=170345 5 6 Reviewed by Michael Catanzaro. 7 8 Start implementing the libgcrypt-based platform bits of CryptoKeyEC. 9 10 Implement keySizeInBits() by returning the appropriate size for this 11 object's curve type. An assertion is added to ensure that this size 12 matches the one that's returned by gcry_pk_get_nbits() for this 13 object's EC key as represented by the m_platformKey gcry_sexp_t object. 14 15 Implement platformGeneratePair() by constructing a genkey s-expression 16 that requests a generation of an EC key for the specified curve type. 17 The s-expression is then passed to gcry_pk_genkey(), and the public 18 and private key data is then retrieved from the returned s-expression 19 upon success and used to create the public and private CryptoKeyEC 20 objects. 21 22 The PlatformECKey type alias is changed to match gcry_sexp_t. The 23 CryptoKeyEC destructor releases the gcry_sexp_t object through 24 a PAL::GCrypt::HandleDeleter<gcry_sexp_t> instance. 25 26 The method definitions in the CryptoKeyECGCrypt.cpp file are also 27 sorted to match the declaration order in the header. 28 29 No new tests -- current ones cover this sufficiently, but are not yet 30 enabled due to other missing platform-specific SUBTLE_CRYPTO 31 implementations. 32 33 * crypto/gcrypt/CryptoKeyECGCrypt.cpp: 34 (WebCore::curveSize): 35 (WebCore::curveName): 36 (WebCore::CryptoKeyEC::~CryptoKeyEC): 37 (WebCore::CryptoKeyEC::keySizeInBits): 38 (WebCore::CryptoKeyEC::platformGeneratePair): 39 (WebCore::CryptoKeyEC::platformImportSpki): 40 (WebCore::CryptoKeyEC::platformImportPkcs8): 41 (WebCore::CryptoKeyEC::platformExportRaw): 42 (WebCore::CryptoKeyEC::platformAddFieldElements): 43 (WebCore::CryptoKeyEC::platformExportSpki): 44 * crypto/keys/CryptoKeyEC.h: 45 1 46 2017-04-03 Zan Dobersek <zdobersek@igalia.com> 2 47 -
trunk/Source/WebCore/PAL/ChangeLog
r214822 r214825 1 2017-04-03 Zan Dobersek <zdobersek@igalia.com> 2 3 [GCrypt] Implement CryptoKeyEC::keySizeInBits(), ::platformGeneratePair() 4 https://bugs.webkit.org/show_bug.cgi?id=170345 5 6 Reviewed by Michael Catanzaro. 7 8 * pal/crypto/gcrypt/Handle.h: 9 (PAL::GCrypt::HandleDeleter<gcry_sexp_t>::operator()): Add a HandleDeleter 10 specialization for the gcry_sexp_t type. 11 1 12 2017-04-03 Zan Dobersek <zdobersek@igalia.com> 2 13 -
trunk/Source/WebCore/PAL/pal/crypto/gcrypt/Handle.h
r214822 r214825 99 99 }; 100 100 101 template<> 102 struct HandleDeleter<gcry_sexp_t> { 103 void operator()(gcry_sexp_t handle) 104 { 105 gcry_sexp_release(handle); 106 } 107 }; 108 101 109 } // namespace GCrypt 102 110 } // namespace PAL -
trunk/Source/WebCore/crypto/gcrypt/CryptoKeyECGCrypt.cpp
r214538 r214825 31 31 #include "CryptoKeyPair.h" 32 32 #include "NotImplemented.h" 33 #include <pal/crypto/gcrypt/Handle.h> 34 #include <pal/crypto/gcrypt/Utilities.h> 33 35 34 36 namespace WebCore { 35 37 36 struct _PlatformECKeyGnuTLS { 37 }; 38 static size_t curveSize(CryptoKeyEC::NamedCurve curve) 39 { 40 switch (curve) { 41 case CryptoKeyEC::NamedCurve::P256: 42 return 256; 43 case CryptoKeyEC::NamedCurve::P384: 44 return 384; 45 } 46 } 47 48 static const char* curveName(CryptoKeyEC::NamedCurve curve) 49 { 50 switch (curve) { 51 case CryptoKeyEC::NamedCurve::P256: 52 return "NIST P-256"; 53 case CryptoKeyEC::NamedCurve::P384: 54 return "NIST P-384"; 55 } 56 } 38 57 39 58 CryptoKeyEC::~CryptoKeyEC() 40 59 { 41 notImplemented(); 60 if (m_platformKey) 61 PAL::GCrypt::HandleDeleter<gcry_sexp_t>()(m_platformKey); 42 62 } 43 63 44 64 size_t CryptoKeyEC::keySizeInBits() const 45 65 { 46 notImplemented();47 48 return 0;66 size_t size = curveSize(m_curve); 67 ASSERT(size == gcry_pk_get_nbits(m_platformKey)); 68 return size; 49 69 } 50 70 51 Vector<uint8_t> CryptoKeyEC::platformExportRaw() const 71 std::optional<CryptoKeyPair> CryptoKeyEC::platformGeneratePair(CryptoAlgorithmIdentifier identifier, NamedCurve curve, bool extractable, CryptoKeyUsageBitmap usages) 52 72 { 53 notImplemented(); 73 PAL::GCrypt::Handle<gcry_sexp_t> genkeySexp; 74 gcry_error_t error = gcry_sexp_build(&genkeySexp, nullptr, "(genkey(ecc(curve %s)))", curveName(curve)); 75 if (error != GPG_ERR_NO_ERROR) { 76 PAL::GCrypt::logError(error); 77 return std::nullopt; 78 } 54 79 55 return { }; 56 } 80 PAL::GCrypt::Handle<gcry_sexp_t> keyPairSexp; 81 error = gcry_pk_genkey(&keyPairSexp, genkeySexp); 82 if (error != GPG_ERR_NO_ERROR) { 83 PAL::GCrypt::logError(error); 84 return std::nullopt; 85 } 57 86 58 std::optional<CryptoKeyPair> CryptoKeyEC::platformGeneratePair(CryptoAlgorithmIdentifier, NamedCurve, bool, CryptoKeyUsageBitmap) 59 { 60 notImplemented(); 87 PAL::GCrypt::Handle<gcry_sexp_t> publicKeySexp(gcry_sexp_find_token(keyPairSexp, "public-key", 0)); 88 PAL::GCrypt::Handle<gcry_sexp_t> privateKeySexp(gcry_sexp_find_token(keyPairSexp, "private-key", 0)); 89 if (!publicKeySexp || !privateKeySexp) 90 return std::nullopt; 61 91 62 return std::nullopt; 92 auto publicKey = CryptoKeyEC::create(identifier, curve, CryptoKeyType::Public, publicKeySexp.release(), true, usages); 93 auto privateKey = CryptoKeyEC::create(identifier, curve, CryptoKeyType::Private, privateKeySexp.release(), extractable, usages); 94 return CryptoKeyPair { WTFMove(publicKey), WTFMove(privateKey) }; 63 95 } 64 96 … … 84 116 } 85 117 86 void CryptoKeyEC::platformAddFieldElements(JsonWebKey&) const87 {88 notImplemented();89 }90 91 118 RefPtr<CryptoKeyEC> CryptoKeyEC::platformImportSpki(CryptoAlgorithmIdentifier, NamedCurve, Vector<uint8_t>&&, bool, CryptoKeyUsageBitmap) 92 119 { … … 96 123 } 97 124 98 Vector<uint8_t> CryptoKeyEC::platformExportSpki() const 125 RefPtr<CryptoKeyEC> CryptoKeyEC::platformImportPkcs8(CryptoAlgorithmIdentifier, NamedCurve, Vector<uint8_t>&&, bool, CryptoKeyUsageBitmap) 126 { 127 notImplemented(); 128 129 return nullptr; 130 } 131 132 Vector<uint8_t> CryptoKeyEC::platformExportRaw() const 99 133 { 100 134 notImplemented(); … … 103 137 } 104 138 105 RefPtr<CryptoKeyEC> CryptoKeyEC::platformImportPkcs8(CryptoAlgorithmIdentifier, NamedCurve, Vector<uint8_t>&&, bool, CryptoKeyUsageBitmap) 139 void CryptoKeyEC::platformAddFieldElements(JsonWebKey&) const 140 { 141 notImplemented(); 142 } 143 144 Vector<uint8_t> CryptoKeyEC::platformExportSpki() const 106 145 { 107 146 notImplemented(); 108 147 109 return nullptr;148 return { }; 110 149 } 111 150 -
trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h
r214122 r214825 38 38 39 39 #if PLATFORM(GTK) 40 typedef struct _PlatformECKeyGnuTLS PlatformECKeyGnuTLS; 41 typedef PlatformECKeyGnuTLS *PlatformECKey; 40 // gcry_sexp* equates gcry_sexp_t. 41 struct gcry_sexp; 42 typedef gcry_sexp* PlatformECKey; 42 43 #endif 43 44
Note: See TracChangeset
for help on using the changeset viewer.