{"id":798,"date":"2009-12-08T11:52:02","date_gmt":"2009-12-08T11:52:02","guid":{"rendered":"http:\/\/pchero21.com\/?p=798"},"modified":"2009-12-08T11:52:02","modified_gmt":"2009-12-08T11:52:02","slug":"openlssl-ssl-%ed%86%b5%ec%8b%a0-%ec%84%9c%eb%b2%84","status":"publish","type":"post","link":"http:\/\/pchero21.com\/?p=798","title":{"rendered":"OpenlSSL &#8211; SSL \ud1b5\uc2e0 \uc11c\ubc84"},"content":{"rendered":"<p>\/\/ &nbsp; &nbsp;&nbsp; SSL_Server.c<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; Copyright 2009 Kim Sung-tae &lt;pchero21@gmail.com&gt;<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; This program is free software; you can redistribute it and\/or modify<br \/>\/\/ &nbsp; &nbsp;&nbsp; it under the terms of the GNU General Public License as published by<br \/>\/\/ &nbsp; &nbsp;&nbsp; the Free Software Foundation; either version 2 of the License, or<br \/>\/\/ &nbsp; &nbsp;&nbsp; (at your option) any later version.<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; This program is distributed in the hope that it will be useful,<br \/>\/\/ &nbsp; &nbsp;&nbsp; but WITHOUT ANY WARRANTY; without even the implied warranty of<br \/>\/\/ &nbsp; &nbsp;&nbsp; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the<br \/>\/\/ &nbsp; &nbsp;&nbsp; GNU General Public License for more details.<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; You should have received a copy of the GNU General Public License<br \/>\/\/ &nbsp; &nbsp;&nbsp; along with this program; if not, write to the Free Software<br \/>\/\/ &nbsp; &nbsp;&nbsp; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,<br \/>\/\/ &nbsp; &nbsp;&nbsp; MA 02110-1301, USA.<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>#include &lt;stdlib.h&gt;<br \/>#include &lt;string.h&gt;<\/p>\n<p>#include &lt;openssl\/bio.h&gt;<br \/>#include &lt;openssl\/err.h&gt;<br \/>#include &lt;openssl\/rand.h&gt;<br \/>#include &lt;openssl\/evp.h&gt;<br \/>#include &lt;openssl\/crypto.h&gt;<br \/>#include &lt;openssl\/ssl.h&gt;<\/p>\n<p>#include &lt;sys\/socket.h&gt;<br \/>#include &lt;arpa\/inet.h&gt;<br \/>#include &lt;sys\/types.h&gt;<\/p>\n<p>\/\/ \uc11c\ubc84 \ud3ec\ud2b8\uc640 IP \uc8fc\uc18c \uc815\uc758<br \/>#define PORT 7921<br \/>#define SERVER_ADDRESS &#8220;127.0.0.1&#8221;<\/p>\n<p>\/\/ \uc11c\ubc84 \uc778\uc99d\uc11c\uc640 \uac1c\uc778\ud0a4 \ud30c\uc77c \uc815\uc758<br \/>#define CERT_FILE &nbsp; &nbsp;&#8220;rootcert.pem&#8221;<br \/>#define PRIVKEY_FILE &nbsp; &nbsp;&#8220;rootkey.pem&#8221;<\/p>\n<p>\/\/ SSL \ud578\ub4dc\uc250\uc774\ud06c \uba54\uc2dc\uc9c0 \uad50\ud658 \uacfc\uc815\uc744 \uc54c\ub824\uc8fc\ub294 \ucf5c\ubc31\ud568\uc218<br \/>void ssl_info_callback(const SSL *s, int where, int ret);<\/p>\n<p>\/\/ \ud654\uba74\uc5d0 \ud45c\uc2dc\ud558\uae30 \uc704\ud55c \ud30c\uc77c BIO \uc0dd\uc131<br \/>BIO *errBIO;<\/p>\n<p>int main(int argc, char** argv)<br \/>{<br \/>&nbsp;&nbsp; &nbsp;unsigned short port = PORT;<br \/>&nbsp;&nbsp; &nbsp;char *serverAddress = SERVER_ADDRESS;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc11c\ubc84\uc758 \uc18c\ucf13 \ud0c0\uc785\uc740 TCP \uac19\uc740 \uc5f0\uacb0\ud615\uc774\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;int socket_type = SOCK_STREAM;<br \/>&nbsp;&nbsp; &nbsp;struct sockaddr_in server_add, client_add;<br \/>&nbsp;&nbsp; &nbsp;int server_socket, client_socket;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;socket_type = SOCK_STREAM;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ SSL \uad6c\uc870\uccb4 \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;SSL_METHOD *meth;<br \/>&nbsp;&nbsp; &nbsp;SSL_CTX *ctx;<br \/>&nbsp;&nbsp; &nbsp;SSL* ssl;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;int retval, client_addlen;<br \/>&nbsp;&nbsp; &nbsp;const char *currentCipher;<br \/>&nbsp;&nbsp; &nbsp;char inbuffer[1000];<br \/>&nbsp;&nbsp; &nbsp;char message[100] = &#8220;\uc774\uac83\uc740 \uc11c\ubc84\ub85c\ubd80\ud130\uc758 \uc751\ub2f5 \uba54\uc2dc\uc9c0\uc785\ub2c8\ub2e4.&#8221;;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud654\uba74 \ucd9c\ub825 BIO \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;if((errBIO = BIO_new(BIO_s_file())) != NULL)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_set_fp(errBIO, stderr, BIO_NOCLOSE|BIO_FP_TEXT);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ubaa8\ub4e0 \uc5d0\ub7ec \uc2a4\ud2b8\ub9c1 \ub85c\ub4dc<br \/>&nbsp;&nbsp; &nbsp;SSL_load_error_strings();<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ubaa8\ub4e0 \uc54c\uace0\ub9ac\uc998 \ub85c\ub4dc<br \/>&nbsp;&nbsp; &nbsp;SSLeay_add_ssl_algorithms();<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ SSL \ubc84\uc8043 \ud504\ub85c\ud1a0\ucf5c \uc0ac\uc6a9<br \/>&nbsp;&nbsp; &nbsp;meth = SSLv3_method();<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ SSL \ucee8\ud14d\uc2a4\ud2b8 \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;ctx = SSL_CTX_new(meth);<br \/>&nbsp;&nbsp; &nbsp;if(ctx == NULL) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;SSL_CTX \uc0dd\uc131 \uc5d0\ub7ec&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ SSL \ud578\ub4dc\uc250\uc774\ud06c \uba54\uc2dc\uc9c0\uad50\ud658 \uacfc\uc815\uc744 \uc54c\ub824\uc8fc\ub294 \ucf5c\ubc31\ud568\uc218\ub97c \uc14b\ud305<br \/>&nbsp;&nbsp; &nbsp;SSL_CTX_set_info_callback(ctx, ssl_info_callback);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc790\uc2e0\uc758 \uc778\uc99d\uc11c\ub97c \ud30c\uc77c\uc5d0\uc11c \ub85c\ub529\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;if(SSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) &lt;= 0) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc790\uc2e0\uc758 \uac1c\uc778\ud0a4\ub97c \ud30c\uc77c\uc5d0\uc11c \ub85c\ub529\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;if(SSL_CTX_use_PrivateKey_file(ctx, PRIVKEY_FILE, SSL_FILETYPE_PEM) &lt;= 0) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc77d\uc740 \uc778\uc99d\uc11c\uc640 \uac1c\uc778\ud0a4\uac00 \ub9de\ub294\uc9c0 \ud655\uc778\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;if(!SSL_CTX_check_private_key(ctx)) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;\uc778\uc99d\uc11c\uc640 \uac1c\uc778\ud0a4\uac00 \ub9de\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.n&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ sockaddr_in \uad6c\uc870\uccb4\uc758 \uc8fc\uc18c\uccb4\uacc4\ub97c \uc778\ud130\ub137 \uc8fc\uc18c\uccb4\uacc4\ub85c \ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;server_add.sin_family = AF_INET;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc11c\ubc84\uc758 \uc8fc\uc18c\ub97c \uc778\ud130\ub137 32\ube44\ud2b8 \uc8fc\uc18c\ub85c \ubcc0\ud658\ud558\uc5ec sockaddr_in \uc5d0 \ub123\ub294\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;server_add.sin_addr.s_addr = inet_addr(serverAddress);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ub124\ud2b8\uc6cc\ud06c \ud615\uc2dd\uc73c\ub85c \ud3ec\ud2b8\ubc88\ud638\ub97c \ubcc0\ud658\ud558\uc5ec sockaddr_in\uc5d0 \ub123\ub294\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;server_add.sin_port = htons(port);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc11c\ubc84\uc758 \uc18c\ucf13\uc744 \uc0dd\uc131\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;server_socket = socket(AF_INET, socket_type, 0); &nbsp; &nbsp;\/\/ TCP socket<br \/>&nbsp;&nbsp; &nbsp;if(server_socket == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fprintf(stderr, &#8220;\uc18c\ucf13 \uc0dd\uc131 \uc5d0\ub7ec n&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ bind\ub97c \uc2e4\ud589\ud558\uc5ec \uc11c\ubc84 \uc18c\ucf13\uacfc \uc11c\ubc84 \uc8fc\uc18c\ub97c \uc5f0\uacb0\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;retval = bind(server_socket, (struct sockaddr*)&amp;server_add, sizeof(server_add));<br \/>&nbsp;&nbsp; &nbsp;if(retval == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fprintf(stderr, &#8220;bind \uc5d0\ub7ec!n&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ listen \ud568\uc218\ub97c \uc2e4\ud589\ud558\uc5ec \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc811\uc18d\ud560 \uc218 \uc788\ub294 \ucd5c\ub300 \ubc84\ud37c\uc218\ub97c 5\ub85c \uc815\ud55c\ub2e4<br \/>&nbsp;&nbsp; &nbsp;retval = listen(server_socket, 5);<br \/>&nbsp;&nbsp; &nbsp;if(retval == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fprintf(stderr, &#8220;listen \uc5d0\ub7ec!n&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;printf(&#8220;\uc8fc\uc18c %s, \ud3ec\ud2b8 %d \uc5d0\uc11c \ud074\ub77c\uc774\uc5b8\ud2b8\uc758 \uc5f0\uacb0 \uae30\ub2e4\ub9bc&#8230;n&#8221;, serverAddress, port);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;client_addlen = sizeof(client_add);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ accept \ud568\uc218\ub97c \uc2e4\ud589 \ud558\uc5ec \ud074\ub77c\uc774\uc5b8\ud2b8\ub85c\ubd80\ud130\uc758 \uc811\uc18d\uc744 \uae30\ub2e4\ub9b0\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;client_socket = accept(server_socket, (struct sockaddr*)&amp;client_add, &amp;client_addlen);<br \/>&nbsp;&nbsp; &nbsp;if(client_socket == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fprintf(stderr, &#8220;accept \uc5d0\ub7ec!n&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\ub85c\ubd80\ud130\uc758 \uc811\uc18d, \uc5f0\uacb0<br \/>&nbsp;&nbsp; &nbsp;printf(&#8220;\ud074\ub77c\uc774\uc5b8\ud2b8 \uc5f0\uacb0, \uc8fc\uc18c: %s, \ud3ec\ud2b8 %dn&#8221;, inet_ntoa(client_add.sin_addr), htons(client_add.sin_port));<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ SSL \uad6c\uc870\uccb4 \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;ssl = SSL_new(ctx);<br \/>&nbsp;&nbsp; &nbsp;if(ssl == NULL) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;SSL \uc0dd\uc131 \uc5d0\ub7ec&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc5f0\uacb0\ub41c \uc18c\ucf13\uacfc SSL\uacfc\uc758 \uc5f0\uacb0<br \/>&nbsp;&nbsp; &nbsp;SSL_set_fd(ssl, client_socket);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uac00\uc7a5 \uc911\uc694\ud55c \ud568\uc218, \ud074\ub77c\uc774\uc5b8\ud2b8\uc640\uc758 \ucd08\uae30 \ud611\uc0c1\uacfc\uc815, \uc989 \ud578\ub4dc\uc250\uc774\ud06c \uacfc\uc815\uc744 \uc218\ud589<br \/>&nbsp;&nbsp; &nbsp;retval = SSL_accept(ssl);<br \/>&nbsp;&nbsp; &nbsp;if(retval == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;SSL accept \uc5d0\ub7ec&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud604\uc7ac \ud074\ub77c\uc774\uc5b8\ud2b8\uc640 \uc815\uc758\ub41c \uc554\ud638\ud654 \ud30c\ub77c\uba54\ud130\uc815\ubcf4\ub97c \uc5bb\uc74c<br \/>&nbsp;&nbsp; &nbsp;currentCipher = SSL_CIPHER_get_name(SSL_get_current_cipher(ssl));<br \/>&nbsp;&nbsp; &nbsp;printf(&#8220;SSL \uc5f0\uacb0, \uc0ac\uc6a9 \uc54c\uace0\ub9ac\uc998 \ud30c\ub77c\uba54\ud130 : [%s]n&#8221;, currentCipher);<\/p>\n<p>&nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\ub85c\ubd80\ud130 SSL \ud1b5\uc2e0\uc744 \ud1b5\ud574 \uba54\uc2dc\uc9c0 \ubc1b\uc74c<br \/>&nbsp;&nbsp; &nbsp;retval = SSL_read(ssl, inbuffer, sizeof(inbuffer) &#8211; 1);<br \/>&nbsp;&nbsp; &nbsp;if(retval == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;SSL read \uc5d0\ub7ec&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ubc1b\uc740 \ub370\uc774\ud130\ub97c \ud654\uba74\uc5d0 \ud45c\uc2dc<br \/>&nbsp;&nbsp; &nbsp;inbuffer[retval] = &#8216;\u0000&#8217;;<br \/>&nbsp;&nbsp; &nbsp;printf(&#8220;\ud074\ub77c\uc774\uc5b8\ud2b8\ub85c\ubd80\ud130 \ub370\uc774\ud130 \uc804\uc1a1: [%s], \uae38\uc774:[%d]n&#8221;, inbuffer, retval);<\/p>\n<p>&nbsp;&nbsp; &nbsp;\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\uc5d0\uac8c SSL \ud1b5\uc2e0\uc744 \ud1b5\ud574 \uba54\uc2dc\uc9c0 \ubcf4\ub0c4<br \/>&nbsp;&nbsp; &nbsp;retval = SSL_write(ssl, message, strlen(message));<br \/>&nbsp;&nbsp; &nbsp;if(retval == -1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;SSL write \uc5d0\ub7ec!n&#8221;);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc5f0\uacb0 \ud574\uc81c \ubc0f \uac1d\uccb4 \uc81c\uac70<br \/>&nbsp;&nbsp; &nbsp;printf(&#8220;\uc5f0\uacb0 \ud574\uc81cn&#8221;);<br \/>&nbsp;&nbsp; &nbsp;close(client_socket);<br \/>&nbsp;&nbsp; &nbsp;SSL_free(ssl);<br \/>&nbsp;&nbsp; &nbsp;SSL_CTX_free(ctx);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;sleep(20000);<\/p>\n<p>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;return 0;<br \/>}<\/p>\n<p>\/\/ SSL \ud578\ub4dc\uc250\uc774\ud06c \uba54\uc2dc\uc9c0 \uad50\ud658 \uacfc\uc815\uc744 \uc54c\ub824\uc8fc\ub294 \ucf5c\ubc31\ud568\uc218<br \/>void ssl_info_callback(const SSL *s, int where, int ret)<br \/>{<br \/>&nbsp;&nbsp; &nbsp;char *writeString;<br \/>&nbsp;&nbsp; &nbsp;int w;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud604\uc7ac \uc5b4\ub5a4 \uba54\uc2dc\uc9c0 \uad50\ud658 \uacfc\uc815\uc778\uc9c0\ub97c \ub098\ud0c0\ub0c4<br \/>&nbsp;&nbsp; &nbsp;w = where &amp; ~SSL_ST_MASK;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5f0\uacb0 \ud588\uc744 \ub54c<br \/>&nbsp;&nbsp; &nbsp;if(w &amp; SSL_ST_CONNECT)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;writeString = &#8220;SSL_connect&#8221;;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc11c\ubc84\uac00 \uc5f0\uacb0\uc744 \ubc1b\uc558\uc744 \ub54c<br \/>&nbsp;&nbsp; &nbsp;else if (w &amp; SSL_ST_ACCEPT)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;writeString = &#8220;SSL_accept&#8221;;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc54c \uc218 \uc5c6\ub294 \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp;else<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;writeString = &#8220;undefined&#8221;;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc77c\ubc18\uc801\uc778 \ud578\ub4dc\uc250\uc774\ud06c \ud504\ub85c\ud1a0\ucf5c \uba54\uc2dc\uc9c0\uc77c \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp;if(where &amp; SSL_CB_LOOP) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ SSL_state_string_long(s) \ud568\uc218\ub85c\ubd80\ud130 \ud604\uc7ac \uc9c4\ud589\ub418\ub294 \uba54\uc2dc\uc9c0\uac00 \ubb34\uc5c7\uc778\uc9c0 \ud45c\uc2dc<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;%s:%sn&#8221;, writeString, SSL_state_string_long(s));<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;\/\/ alert \ud504\ub85c\ud1a0\ucf5c\uc77c \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp;else if(where &amp; SSL_CB_ALERT) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;writeString = (where &amp; SSL_CB_READ)? &#8220;read&#8221;:&#8221;write&#8221;;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;SSL3 alert %s:%s:%sn&#8221;, writeString, SSL_alert_type_string_long(ret), SSL_alert_desc_string_long(ret));<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;else if(where &amp; SSL_CB_EXIT) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc885\ub8cc \uacfc\uc815\uc77c \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(ret == 0)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;%s:failed in %sn&#8221;, writeString, SSL_state_string_long(s));<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else if(ret &lt; 0)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;%s:error in %sn&#8221;, writeString, SSL_state_string_long(s));<br \/>&nbsp;&nbsp; &nbsp;}<br \/>}<\/p>\n<p><a href=\"http:\/\/pchero21.com\/wp-content\/uploads\/1\/XUI3H1XICP.pem\" class=\"aligncenter\"  \/>XUI3H1XICP.pem<\/a><a href=\"http:\/\/pchero21.com\/wp-content\/uploads\/1\/XQCYwl3nVb.pem\" class=\"aligncenter\"  \/>XQCYwl3nVb.pem<\/a><a href=\"http:\/\/pchero21.com\/wp-content\/uploads\/1\/XGXvAcHioM.c\" class=\"aligncenter\"  \/>XGXvAcHioM.c<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ &nbsp; &nbsp;&nbsp; SSL_Server.c\/\/ &nbsp; &nbsp; &nbsp;\/\/ &nbsp; &nbsp;&nbsp; Copyright 2009 Kim Sung-tae &lt;pchero21@gmail.com&gt;\/\/ &nbsp; &nbsp; &nbsp;\/\/ &nbsp; &nbsp;&nbsp; This program is free software; you can redistribute it and\/or modify\/\/ &nbsp; &nbsp;&nbsp; it under the terms of the GNU General &hellip; <a href=\"http:\/\/pchero21.com\/?p=798\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[297,364],"_links":{"self":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/798"}],"collection":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=798"}],"version-history":[{"count":0,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/798\/revisions"}],"wp:attachment":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}