Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] How can i create a connection with mutual authentication ? #19

Open
MateusDornelles opened this issue May 6, 2023 · 1 comment

Comments

@MateusDornelles
Copy link

Basic what the title says, how can i create a connection with mutual authentication ?

Thanks.

@fwh-dc
Copy link
Contributor

fwh-dc commented Jun 1, 2023

Hi,

Given that you have your ca, client cert, etc setup already you can achieve this by:

Server

auto config = oatpp::openssl::Config::createShared();
config->addContextConfigurer(std::make_shared<oatpp::openssl::configurer::CertificateFile>("path/to/server.pem"));
config->addContextConfigurer(std::make_shared<oatpp::openssl::configurer::PrivateKeyFile>("path/to/server.key"));
config->addContextConfigurer(std::make_shared<oatpp::openssl::configurer::PeerCertificateVerification>(oatpp::openssl::configurer::CertificateVerificationMode::EnabledStrong)));
auto connectionProvider = oatpp::openssl::server::ConnectionProvider::createShared(config, {"localhost", 8443});

Client

auto config = oatpp::openssl::Config::createShared();
config->addContextConfigurer(std::make_shared<oatpp::openssl::configurer::CertificateFile>("path/to/client.pem"));
config->addContextConfigurer(std::make_shared<oatpp::openssl::configurer::PrivateKeyFile>("path/to/client.key"));
config->addContextConfigurer(std::make_shared<oatpp::openssl::configurer::PeerCertificateVerification>(oatpp::openssl::configurer::CertificateVerificationMode::EnabledStrong)));
auto connectionProvider = oatpp::openssl::client::ConnectionProvider::createShared(config, {"httpbin.org", 443});

oatpp::openssl::configurer::CertificateVerificationMode::EnabledStrong is important because this forces the opposite side to send a valid certificate.

Please have a look at the different configuration options under src/oatpp-openssl/configurer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants