OpenSSL Boost context.use_private_key_file and context.use_rsa_private_key_file terminate the program without exception

My code is mostly based on the boost ssl client example, but I made it completely synchronous, but the example from boost will still do the same.

After loading server.pem sslContext.load_verify_file("server.pem");

I am trying to download the client key and crt to be verified by the server for a two way handshake.

context_.use_private_key_file("client.key",boost::asio::ssl::context_base::file_format::pem); // also tried use_rsa_private_key_file
context_.use_certificate_file("client.crt",boost::asio::ssl::context_base::file_format::pem);

      

When use_private_key_file or use_rsa_private_key_file is called, the password is requested upon login, the program exits. Why is this? - My password is correct. I checked it withopenssl rsa -check -in client.key

The constructor will be the only change to the boost example since I will be using it for normal SSL handshaking.

    server(boost::asio::io_service& io_service, unsigned short port)
        : io_service_(io_service),
                acceptor_(io_service,
                boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)),
                context_(boost::asio::ssl::context::sslv23)
                {
                        context_.load_verify_file("server.pem");
                        start_accept();
                }

      

For two-way communication.

    server(boost::asio::io_service& io_service, unsigned short port)
        : io_service_(io_service),
                acceptor_(io_service,
                boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)),
                context_(boost::asio::ssl::context::sslv23)
                {

                        context_.load_verify_file("server.pem");
                        context_.use_private_key_file("client.key",boost::asio::ssl::context_base::file_format::pem); // also tried use_rsa_private_key_file
                        context_.use_certificate_file("client.crt",boost::asio::ssl::context_base::file_format::pem);
                        start_accept();
                }

      

+3


source to share


1 answer


It failed with everyone when entering the password using the console. However it was fine when I used the callback set_password_callback(boost::bind(&get_password, this));

it worked fine.



+4


source







All Articles