#pragma once #include "keys.hpp" #include #include #include #include #include #include #include #include namespace vanetza { namespace pki { template std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); template<> std::function openssl_deleter(); using OpenSslException = vanetza::security::openssl::Exception; template class OpenSslPointer { public: explicit OpenSslPointer(T* raw) : m_ptr(raw, openssl_deleter()) { if (raw == nullptr) { throw OpenSslException(ERR_get_error()); } } OpenSslPointer(T* raw, const char* errmsg) : m_ptr(raw, openssl_deleter()) { if (raw == nullptr) { throw OpenSslException(ERR_get_error(), errmsg); } } OpenSslPointer(T* raw, const std::string& errmsg) : OpenSslPointer(raw, errmsg.c_str()) { } T* raw() { assert(m_ptr); return m_ptr.get(); } const T* raw() const { assert(m_ptr); return m_ptr.get(); } private: std::unique_ptr> m_ptr; }; int openssl_nid(KeyType); KeyType openssl_nid2key(int); KeyType openssl_key_type_from_group_name(const char*); void openssl_result(int rc, const char*); OpenSslPointer make_ec_point(const PublicKey&); OpenSslPointer make_ec_key(const PublicKey&); OpenSslPointer make_ec_key(const PrivateKey&); OpenSslPointer make_bignum(const ByteBuffer&); PublicKey make_public_key(const EC_KEY*); ByteBuffer make_buffer(const BIGNUM*); ByteBuffer make_buffer(const BIGNUM*, std::size_t length); /** * \brief Open (truncate) a file as owner-only and wrap its descriptor in a BIO. * * Prevents that the file is ever momentarily readable by other users. * \param path file to create or truncate * \return BIO writing to the file; closing the BIO closes the descriptor * \throws std::runtime_error if the file cannot be created * \throws OpenSslException if the BIO cannot be allocated */ OpenSslPointer make_owner_only_bio(const std::filesystem::path& path); } // namespace pki } // namespace vanetza