Lab 3 - Secue Comunication Using TLS
Lab 3 - Secue Comunication Using TLS
Initialize OpenSSL
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
method = TLS_server_method();
ctx = SSL_CTX_new(method);
if (!ctx) {
perror("Unable to create SSL context");
ERR_print_errors_fp(stderr);
exit(EXIT_FAILURE);
}
SSL_CTX_use_certificate_file(ctx, "/path/to/cert.pem",
SSL_FILETYPE_PEM);
SSL_CTX_use_PrivateKey_file(ctx, "/path/to/key.pem",
SSL_FILETYPE_PEM);
ssl = SSL_new(ctx);
SSL_set_fd(ssl, server);
if (SSL_accept(ssl) <= 0) {
ERR_print_errors_fp(stderr);
} else {
printf("Connection using TLS 1.3\n");
// Handle communication here
}
SSL_shutdown(ssl);
SSL_free(ssl);
close(server);
SSL_CTX_free(ctx);
EVP_cleanup();
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
SSLProtocol -all +TLSv1.3
SSLCipherSuite
TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
</VirtualHost>
SSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION);
SSL_CTX_set_max_proto_version(ctx, TLS1_3_VERSION);
int server;
SSL *ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, server);
if (SSL_connect(ssl) <= 0) {
ERR_print_errors_fp(stderr);
} else {
printf("Connected with TLS 1.3\n");
}