mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 19:10:20 +01:00
fix incomplete EC key creation from curve name; make sure tests use curves that exist; add validation checks on EC key creation
This commit is contained in:
@@ -78,7 +78,16 @@ public:
|
||||
|
||||
ECKeyImpl::Ptr impl() const;
|
||||
/// Returns the impl object.
|
||||
|
||||
|
||||
static std::string getCurveName(int nid = -1);
|
||||
/// Returns elliptical curve name corresponding to
|
||||
/// the given nid; if nid is not found, returns
|
||||
/// empty string.
|
||||
///
|
||||
/// If nid is -1, returns first curve name.
|
||||
///
|
||||
/// If no curves are found, returns empty string;
|
||||
|
||||
private:
|
||||
ECKeyImpl::Ptr _pImpl;
|
||||
};
|
||||
@@ -93,6 +102,12 @@ inline ECKeyImpl::Ptr ECKey::impl() const
|
||||
}
|
||||
|
||||
|
||||
inline std::string ECKey::getCurveName(int nid)
|
||||
{
|
||||
return ECKeyImpl::getCurveName(nid);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
|
||||
@@ -104,7 +104,17 @@ public:
|
||||
/// If a null pointer is passed for a stream, the corresponding
|
||||
/// key is not exported.
|
||||
|
||||
static std::string getCurveName(int nid = -1);
|
||||
/// Returns elliptical curve name corresponding to
|
||||
/// the given nid; if nid is not found, returns
|
||||
/// empty string.
|
||||
///
|
||||
/// If nid is -1, returns first curve name.
|
||||
///
|
||||
/// If no curves are found, returns empty string;
|
||||
|
||||
private:
|
||||
void checkEC(const std::string& method, const std::string& func) const;
|
||||
void freeEC();
|
||||
|
||||
EC_KEY* _pEC;
|
||||
|
||||
@@ -194,7 +194,11 @@ private:
|
||||
*ppKey = (K*)getFunc(pKey);
|
||||
EVP_PKEY_free(pKey);
|
||||
}
|
||||
else *ppKey = (K*)pKey;
|
||||
else
|
||||
{
|
||||
poco_assert_dbg (typeid(K*) == typeid(EVP_PKEY*));
|
||||
*ppKey = (K*)pKey;
|
||||
}
|
||||
if(!*ppKey) goto error;
|
||||
return true;
|
||||
}
|
||||
@@ -250,7 +254,11 @@ private:
|
||||
*ppKey = (K*)getFunc(pKey);
|
||||
EVP_PKEY_free(pKey);
|
||||
}
|
||||
else *ppKey = (K*)pKey;
|
||||
else
|
||||
{
|
||||
poco_assert_dbg (typeid(K*) == typeid(EVP_PKEY*));
|
||||
*ppKey = (K*)pKey;
|
||||
}
|
||||
if (!*ppKey) goto error;
|
||||
return true;
|
||||
}
|
||||
@@ -278,12 +286,12 @@ private:
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline bool EVPPKey::operator == (const EVPPKey& other) const
|
||||
{
|
||||
poco_assert_dbg(other._pEVPPKey && _pEVPPKey);
|
||||
int r = EVP_PKEY_cmp(_pEVPPKey, other._pEVPPKey);
|
||||
if (r < 0) throw OpenSSLException("EVPPKey::operator ==()");
|
||||
return (1 == r);
|
||||
poco_check_ptr (other._pEVPPKey);
|
||||
poco_check_ptr (_pEVPPKey);
|
||||
return (1 == EVP_PKEY_cmp(_pEVPPKey, other._pEVPPKey));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user