Skip to content

[question] Example for onSecuring for SSL certficate? #527

@harsszegi

Description

@harsszegi

Hi,
I'm trying to use SSL and I fail to do so:

bool onSecuring(AMQP::TcpConnection* /* connection /, SSL ssl) override
{
auto* ssl_ctx = SSL_get_SSL_CTX(ssl);

if (!connection_parameters_.tls_params_.has_value())
{
  return false;
}

if (SSL_CTX_load_verify_locations(ssl_ctx, connection_parameters_.tls_params_->ca_cert_path_.c_str(), nullptr) != 1)
{
  std::cout << "Invalid ca cert" << std::endl;
  ERR_print_errors_fp(stderr);
  return false;
}

if (SSL_CTX_use_certificate_chain_file(ssl_ctx, connection_parameters_.tls_params_->client_cert_path_.c_str()) != 1)
{
  std::cout << "Invalid client cert" << std::endl;
  ERR_print_errors_fp(stderr);
  return false;
}

if (SSL_CTX_use_PrivateKey_file(ssl_ctx, connection_parameters_.tls_params_->client_key_path_.c_str(), SSL_FILETYPE_PEM) != 1)
{
  std::cout << "Invalid client private key" << std::endl;
  ERR_print_errors_fp(stderr);
  return false;
}

if (SSL_CTX_check_private_key(ssl_ctx) != 1)
{
  std::cout << "Check failed client private key" << std::endl;
  ERR_print_errors_fp(stderr);
  return false;
}

if (connection_parameters_.tls_params_->verify_peer_)
{
  SSL_set_verify(ssl, SSL_VERIFY_PEER, nullptr);
}
else
{
  SSL_set_verify(ssl, SSL_VERIFY_NONE, nullptr);
}

return true;

}

This works fine, context is configured, however the server rejects this with "no_client_certificate_provided".

The same set of certificates with SimpleAmqpClient work fine, e.g. I can connect to the same broker.
Any documentation / hint how to use SSL with amqp-cpp?
Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions