Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several steps when using OpenSSL. You must have an SSL certificate made which can contain the certificate with the private key be sure to specify the exact location of the certificate (this example has it in the root). There are a lot of good tutorials out there.</p> <ul> <li><a href="http://h41379.www4.hpe.com/doc/83final/ba554_90007/ch04s03.html" rel="noreferrer">And one from HP</a></li> </ul> <p>Some includes:</p> <pre><code>#include &lt;openssl/applink.c&gt; #include &lt;openssl/bio.h&gt; #include &lt;openssl/ssl.h&gt; #include &lt;openssl/err.h&gt; </code></pre> <p>You will need to initialize OpenSSL:</p> <pre><code>void InitializeSSL() { SSL_load_error_strings(); SSL_library_init(); OpenSSL_add_all_algorithms(); } void DestroySSL() { ERR_free_strings(); EVP_cleanup(); } void ShutdownSSL() { SSL_shutdown(cSSL); SSL_free(cSSL); } </code></pre> <p>Now for the bulk of the functionality. You may want to add a while loop on connections.</p> <pre><code>int sockfd, newsockfd; SSL_CTX *sslctx; SSL *cSSL; InitializeSSL(); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd&lt; 0) { //Log and Error return; } struct sockaddr_in saiServerAddress; bzero((char *) &amp;saiServerAddress, sizeof(saiServerAddress)); saiServerAddress.sin_family = AF_INET; saiServerAddress.sin_addr.s_addr = serv_addr; saiServerAddress.sin_port = htons(aPortNumber); bind(sockfd, (struct sockaddr *) &amp;serv_addr, sizeof(serv_addr)); listen(sockfd,5); newsockfd = accept(sockfd, (struct sockaddr *) &amp;cli_addr, &amp;clilen); sslctx = SSL_CTX_new( SSLv23_server_method()); SSL_CTX_set_options(sslctx, SSL_OP_SINGLE_DH_USE); int use_cert = SSL_CTX_use_certificate_file(sslctx, "/serverCertificate.pem" , SSL_FILETYPE_PEM); int use_prv = SSL_CTX_use_PrivateKey_file(sslctx, "/serverCertificate.pem", SSL_FILETYPE_PEM); cSSL = SSL_new(sslctx); SSL_set_fd(cSSL, newsockfd ); //Here is the SSL Accept portion. Now all reads and writes must use SSL ssl_err = SSL_accept(cSSL); if(ssl_err &lt;= 0) { //Error occurred, log and close down ssl ShutdownSSL(); } </code></pre> <p>You are then able read or write using:</p> <pre><code>SSL_read(cSSL, (char *)charBuffer, nBytesToRead); SSL_write(cSSL, "Hi :3\n", 6); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload