10 #include <openssl/pem.h> 11 #include "../OpenSSL_legacy.h" 42 using namespace CommonUtilities;
61 ACE_TEXT(
"(%P|%t) SSL::PrivateKey::load: WARNING: Unsupported URI scheme in cert path '%C'\n"),
71 : private_key(pkey), md_ctx(0), pkey_ctx(0)
82 int operator()(
const std::vector<const DDS::OctetSeq*>& src,
85 if (!private_key)
return 1;
87 std::vector<const DDS::OctetSeq*>::const_iterator i, n;
96 EVP_MD_CTX_init(md_ctx);
98 if (1 != EVP_DigestSignInit(md_ctx, &pkey_ctx, EVP_sha256(), 0,
105 int pk_id = EVP_PKEY_id(private_key);
107 if (pk_id == EVP_PKEY_RSA) {
109 EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)) {
114 if (1 != EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha256())) {
121 for (i = src.begin(); i != n; ++i) {
122 if ((*i)->length() > 0) {
123 if (1 != EVP_DigestSignUpdate(md_ctx, (*i)->get_buffer(),
132 if (1 != EVP_DigestSignFinal(md_ctx, 0, &len)) {
138 dst.length(static_cast<unsigned int>(len));
139 if (1 != EVP_DigestSignFinal(md_ctx, dst.get_buffer(), &len)) {
146 dst.length(static_cast<unsigned int>(len));
161 return sign(src, dst);
165 const std::string& password)
169 BIO* filebuf = BIO_new_file(path.c_str(),
"r");
171 result = PEM_read_bio_PrivateKey(filebuf, 0, 0,
172 password.empty() ? 0 : (
void*)password.c_str());
180 std::stringstream errmsg;
181 errmsg <<
"failed to read file '" << path <<
"' using BIO_new_file";
189 const std::string& password)
195 original_bytes.length(static_cast<unsigned int>(data.size() - 1));
196 std::memcpy(original_bytes.get_buffer(), &data[1],
197 original_bytes.length());
201 original_bytes.length(original_bytes.length() + 1);
202 original_bytes[original_bytes.length() - 1] = 0;
205 BIO* filebuf = BIO_new(BIO_s_mem());
208 if (0 >= BIO_write(filebuf, original_bytes.get_buffer(),
209 original_bytes.length())) {
213 result = PEM_read_bio_PrivateKey(filebuf, 0, 0,
214 password.empty() ? 0 : (
void*)password.c_str());
223 std::stringstream errmsg;
224 errmsg <<
"failed to create data '" << data <<
"' using BIO_new";
233 if (lhs.
k_ && rhs.
k_) {
235 return 1 == EVP_PKEY_eq(lhs.
k_, rhs.
k_);
237 return 1 == EVP_PKEY_cmp(lhs.
k_, rhs.
k_);
240 return lhs.
k_ == rhs.
k_;
This URI abstraction is currently naive and only separates the URI scheme on the LHS from the "everyt...
void load(const std::string &uri, const std::string &password="")
friend OpenDDS_Security_Export bool operator==(const PrivateKey &lhs, const PrivateKey &rhs)
struct evp_pkey_st EVP_PKEY
static EVP_PKEY * EVP_PKEY_from_pem(const std::string &path, const std::string &password="")
std::string everything_else
sequence< octet > OctetSeq
int sign(const std::vector< const DDS::OctetSeq *> &src, DDS::OctetSeq &dst) const
int operator()(const std::vector< const DDS::OctetSeq *> &src, DDS::OctetSeq &dst)
static EVP_PKEY * EVP_PKEY_from_pem_data(const std::string &data, const std::string &password)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
sign_implementation(EVP_PKEY *pkey)
The Internal API and Implementation of OpenDDS.
#define OPENDDS_SSL_LOG_ERR(MSG)