examples/protocols/https_server/simple/main/certs/README.md
This directory contains certificates for the HTTPS server example. This guide explains how to generate new server and client certificates signed by the existing CA certificate.
cacert.pem) and CA private key (cakey.pem)server_cert.conf and client_cert.conf)Follow these steps to create a new server certificate signed by the CA:
openssl genpkey -algorithm RSA -out new_server.key -pkeyopt rsa_keygen_bits:2048
This creates a 2048-bit RSA private key for the server.
openssl req -new -key new_server.key -out new_server.csr -config server_cert.conf
This generates a CSR using the server's private key and the configuration specified in server_cert.conf.
openssl x509 -req -in new_server.csr -CA cacert.pem -CAkey cakey.pem -CAcreateserial -out new_server.pem -days 3650 -extensions v3_req -extfile server_cert.conf
This creates the server certificate (new_server.pem) valid for 10 years (3650 days), signed by the CA certificate.
Follow these steps to create a new client certificate signed by the CA:
openssl genpkey -algorithm RSA -out new_client.key -pkeyopt rsa_keygen_bits:2048
This creates a 2048-bit RSA private key for the client.
openssl req -new -key new_client.key -out new_client.csr -config client_cert.conf
This generates a CSR using the client's private key and the configuration specified in client_cert.conf.
openssl x509 -req -in new_client.csr -CA cacert.pem -CAkey cakey.pem -CAcreateserial -out new_client.pem -days 3650 -extensions v3_req -extfile client_cert.conf
This creates the client certificate (new_client.pem) valid for 10 years (3650 days), signed by the CA certificate.
cp new_server.pem servercert.pem && \
cp new_server.key prvtkey.pem && \
cp new_client.pem client_cert.pem && \
cp new_client.key client_key.pem
This copies the newly generated certificates and keys to the filenames expected by the example application.
The example application expects the following files:
servercert.pem - Server certificateprvtkey.pem - Server private keyclient_cert.pem - Client certificateclient_key.pem - Client private keycacert.pem - CA certificate (for verification)⚠️ Important Security Considerations:
prvtkey.pem, client_key.pem, cakey.pem) should be kept secure. As these are for demonstration purposes, they are included here, but in a production environment, ensure they are stored securely and access is restricted.chmod 600)You can verify the generated certificates using:
# Verify server certificate
openssl x509 -in servercert.pem -text -noout
# Verify client certificate
openssl x509 -in client_cert.pem -text -noout
# Verify certificate chain
openssl verify -CAfile cacert.pem servercert.pem
openssl verify -CAfile cacert.pem client_cert.pem
server_cert.conf, client_cert.conf) contain appropriate Subject Alternative Names (SANs) and extensions