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

Add Using Certificates to Documentation #2910

Open
ashtum opened this issue Jul 29, 2024 · 1 comment
Open

Add Using Certificates to Documentation #2910

ashtum opened this issue Jul 29, 2024 · 1 comment
Assignees
Labels
Doc A documentation specific issue

Comments

@ashtum
Copy link
Collaborator

ashtum commented Jul 29, 2024

We need to provide an explanation on using certificates and certificate authorities for client and server roles. Additionally, we should include a subsection that addresses common pitfalls and troubleshooting.

@ashtum ashtum added the Doc A documentation specific issue label Jul 29, 2024
@Zen0x7
Copy link

Zen0x7 commented Aug 10, 2024

I'll leave this as a suggested input resource:

In order to use SSL on TCP communications then you should use a SSL Context like the following code:

boost::asio::ssl::context ssl_context{boost::asio::ssl::context::tlsv12};
ssl_context.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::single_dh_use);
ssl_context.use_certificate_chain_file("certificates/public.pem");
ssl_context.use_private_key_file("certificates/private.key", boost::asio::ssl::context::pem);
ssl_context.use_tmp_dh_file("certificates/dh-params.pem");

If you don't know how to how to get the public and private keys, you could use OpenSSL to generate them:

openssl genpkey -algorithm RSA -out private.key
openssl req -newkey rsa:2048 -key private.key -nodes -out server.csr -subj "/CN=*.company.com"
openssl x509 -req -in server.csr -signkey private.key -out public.pem -days 365000
openssl dhparam -out dh-params.pem 2048

Of course, those certificates will be not trusted by in-market browsers as they're not signed by a trusted authority.

If you're interested about how to use those certificates in the client, you could generate another public certificate using the third line of previous command, to get and use it on the clients context.

IMHO, when you're using those certificates in IoT implementations, use the highest quantity of days as possible, as expired certificates can raise handshake exceptions.

Be aware that using SSL will increase the CPU usage and network bandwidth in a directly proportional way to the encryption size (see this tool and compare the base64 result of "abc" being encrypted with 2048 bit key).

@ashtum ashtum added this to the Boost 1.87 beta milestone Aug 11, 2024
@ashtum ashtum self-assigned this Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Doc A documentation specific issue
Projects
None yet
Development

No branches or pull requests

2 participants