Open DragonOsman opened 3 years ago
It works perfectly if I do it like this:
#ifndef SERVER_CERTIFICATE_H
#define SERVER_CERTIFICATE_H
#include <boost/asio/buffer.hpp>
#include <boost/asio/ssl/context.hpp>
#include <cstddef>
#include <fstream>
/*
Load a signed certificate into the ssl context, and configure
the context for use with a server.
*/
inline void load_server_certificate(boost::asio::ssl::context &ctx)
{
const std::string cert_filename = "C:/Users/Osman/.acme.sh/dragonosman.dynu.net/fullchain.cer";
const std::string key_filename = "C:/Users/Osman/.acme.sh/dragonosman.dynu.net/dragonosman.dynu.net.key";
ctx.use_certificate_file(cert_filename, boost::asio::ssl::context_base::file_format::pem);
const std::string dh =
"-----BEGIN DH PARAMETERS-----\n"
"MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz\n"
"+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a\n"
"87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7\n"
"YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi\n"
"7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD\n"
"ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==\n"
"-----END DH PARAMETERS-----\n";
ctx.set_password_callback(
[](std::size_t, boost::asio::ssl::context::password_purpose)
{
return "test";
});
ctx.set_options(boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::single_dh_use);
std::ifstream ifs2{ key_filename };
std::string key{ (std::istreambuf_iterator<char>(ifs2)),
(std::istreambuf_iterator<char>()) };
ctx.use_rsa_private_key(boost::asio::buffer(key.data(), key.size()), boost::asio::ssl::context::file_format::pem);
ctx.use_tmp_dh(boost::asio::buffer(dh.data(), dh.size()));
}
#endif
But what could be causing that error to occur when I try to extract the certificate from the store?
Is this still an open issue? I am getting the same error.
It appears that there is an issue with the X509_NAME
definition.
In my case, the problem was resolved by changing #include
order.
For instance:
#include <boost/asio.hpp>
#include <openssl/ssl.h>
#include <windows.h>
#include <wincrypt.h>
#include <boost/asio/ssl/rfc2818_verification.hpp>
This code fails with the error C2065: 'name': undeclared identifier
.
However when the #include
order is adjusted as follows:
#include <boost/asio.hpp>
#include <boost/asio/ssl/rfc2818_verification.hpp>
#include <openssl/ssl.h>
#include <windows.h>
#include <wincrypt.h>
This code compiles successfully.
I don't know if this is a bug or what, but even though up until I could compile my code just fine, all of a sudden I'm getting this error.
It seems to have happened when I installed my server certificate to the Windows CA store, then tried to extract it using the wincrypt.h function
CertFindCertificateInStore
. I put the server certificate from my .cer file on disc into astd::string
, put it into aCERT_INFO
object and used that as the search criteria to match my cert file to the certs in the store.The error says:
Is this some sort of bug? Please look into this. Thanks.
Edit: This is the full file that I'm doing this in: