{"id":5679,"date":"2026-05-11T08:08:26","date_gmt":"2026-05-10T23:08:26","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5679"},"modified":"2026-05-11T08:15:11","modified_gmt":"2026-05-10T23:15:11","slug":"webserver-miniwebserver-https-9","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/05\/11\/webserver-miniwebserver-https-9\/","title":{"rendered":"[Webserver]miniWebserver+https-(9)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc8fc\uc694 \ubcc0\uacbd\uc0ac\ud56d\uc740 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<br>The major changes are as follows.<\/p>\n\n\n\n<p>\u2714\ufe0f \u2757\ufe0f \ud45c\uc2dc\ub41c \ubd80\ubd84\uc774 \ubcc0\uacbd\uc0ac\ud56d\uc785\ub2c8\ub2e4.<br>The parts marked with \u2757\ufe0f are the changes.<\/p>\n\n\n\n<p>\u2714\ufe0f http,https \ub124\uc784\uc2a4\ud398\uc774\uc2a4 \uc801\uc6a9<br>Apply http, https namespaces<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Server.h\nnamespace http{\n    class Server { ... };\n}\n\n# HttpsServer.cpp\nnamespace https {\n    class Server { ... };\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f https\ud504\ub85c\ud1a0\ucf5c \uc801\uc6a9 \/ Apply HTTPS protocol<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb openssl \uc801\uc6a9\ud558\uae30 \/ Apply openssl<\/p>\n\n\n\n<p>\u2714\ufe0f openssl \uc124\uce58 \/ install openssl<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install openssl<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f openssl \uc124\uce58 \uacbd\ub85c \ud655\uc778 \/ Check the openssl installation path<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MacBookAir build % <strong>brew --prefix openssl<\/strong>\n\/opt\/homebrew\/opt\/openssl@3<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f CMakeLists.txt \ud30c\uc77c\uc5d0 openssl \uc801\uc6a9<br>Apply openssl to the CMakeLists.txt file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># cmake\ucd5c\uc18c\ubc84\uc804\uc9c0\uc815 \/ Specify minimum CMake version\ncmake_minimum_required(VERSION 3.10)\n\n# \ud504\ub85c\uc81d\ud2b8 \uc774\ub984\uacfc \ubc84\uc804 \uc124\uc815 \/ Project name and version settings\nproject(mini_webserver_9 VERSION 1.0)\n\n# C++ \ud45c\uc900 \ubc84\uc804 \uc9c0\uc815(c++20) \/ C++ Standard Version Specification (C++20)\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED True)\n\n# Openssl\u2757\ufe0f\n<strong>include_directories(\/opt\/homebrew\/opt\/openssl@3\/include)\nlink_directories(\/opt\/homebrew\/opt\/openssl@3\/lib)<\/strong>\n\n# \u2757\ufe0f \uc2e4\ud589 \ud30c\uc77c \uc0dd\uc131 \ub300\uc0c1 \uc18c\uc2a4 \ud30c\uc77c \ub098\uc5f4 \/ List source files to be used for creating executable files\nadd_executable(main\n    Main.cpp\n    Router.cpp\n    Server.cpp\n   <strong> HttpsServer.cpp <\/strong>\n)\n\n# Openssl + main \ub9c1\ud06c \/ link\u2757\ufe0f\n<strong>target_link_libraries(main ssl crypto)<\/strong>\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ud14c\uc2a4\ud2b8\uc6a9 \uc778\uc99d\uc11c \uc0dd\uc131 (key.pem, cert.pem)<br>Generate a certificate for testing(key.pem, cert.pem)<\/p>\n\n\n\n<p>&#8212; \uc778\uc99d\uc11c \uc0dd\uc131 \uba85\ub839 \/ Certificate creation command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">- req : \uc790\uccb4 \uc11c\uba85 \uc778\uc99d\uc11c\ub97c \uc0dd\uc131 \/ Generate a self-signed certificate<br>- x509 : x.509\ud615\uc2dd\uc73c\ub85c \uc0dd\uc131 \/ Created in x.509 format<br>- newkey rsa:4096 : <br>  \uc0c8 4096\ube44\ud2b8 RSA \uac1c\uc778\ud0a4\uc640 \uc778\uc99d\uc11c \uc694\uccad\uc744 \ud568\uaed8 \uc0dd\uc131<br>  Generate a new 4096-bit RSA private key and a certificate request together<br>- keyout key.pem : \uac1c\uc778\ud0a4\uac00 \uc800\uc7a5\ub420 \ud30c\uc77c\uba85 \/ filename where the private key will be stored<br>- out cert.pem : \uc0dd\uc131\ub420 \uc778\uc99d\uc11c \ud30c\uc77c\uba85 \/ Certificate filename to be generated<br>- days 365 : \uc778\uc99d\uc11c \uc720\ud6a8\uae30\uac04 \/ Certificate validity period<br>- nodes: \uc554\ud638\ud654\ud558\uc9c0\uc54a\uc74c(\ube44\ubc00\ubc88\ud638 \uc5c6\uc774 \uc0ac\uc6a9\uac00\ub2a5) \/ Unencrypted (can be used without a password)<\/pre>\n\n\n\n<p>&#8212; \uc9c8\ubb38\uc5d0 \uadf8\ub0e5 \uae30\ubcf8 \uac12\uc73c\ub85c \ubaa8\ub450 \uc5d4\ud130\ub97c \uc785\ub825\ud569\ub2c8\ub2e4.<br>For the questions, just press Enter for all default values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MacBookAir cert % <strong>openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes<\/strong>\n..+.........+.+.....+...+.+..+..........+.....+....+++++++++++++++++++++++++++++++++++++++++++++*.....+.....+............+.+..............+...+...+++++++++++++++++++++++++++++++++++++++++++++*...........+.....+.+......\n\n... \uc911\ub7b5\/skipping the middle ...\n\nYou are about to be asked to enter information that will be incorporated\ninto your certificate request.\nWhat you are about to enter is what is called a Distinguished Name or a DN.\nThere are quite a few fields but you can leave some blank\nFor some fields there will be a default value,\nIf you enter '.', the field will be left blank.\n-----\nCountry Name (2 letter code) &#91;AU]:\nState or Province Name (full name) &#91;Some-State]:\nLocality Name (eg, city) &#91;]:\nOrganization Name (eg, company) &#91;Internet Widgits Pty Ltd]:\nOrganizational Unit Name (eg, section) &#91;]:\nCommon Name (e.g. server FQDN or YOUR name) &#91;]:\nEmail Address &#91;]:\nMacBookAir cert % \n<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ucf54\ub4dc \/ Code<\/p>\n\n\n\n<p>\u2714\ufe0f httpsServer.h ,httpsServer.cpp\ud30c\uc77c\uc774 \ucd94\uac00\ub418\uc5c8\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p>\u2714\ufe0f\uc778\uc99d\uc11c \uac80\uc0ac \ubc0f \ub4f1\ub85d(httpsServer.cpp,main.cpp)<\/p>\n\n\n\n<p>&#8212; httpsServer.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bool https::Server::initialize_ssl(const std::string&amp; cert_file, const std::string&amp; key_file) { ... } <\/code><\/pre>\n\n\n\n<p>&#8212; main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    if (!server3.initialize_ssl(\"..\/cert\/cert.pem\", \"..\/cert\/key.pem\")) {\n        std::cerr &lt;&lt; \"SSL initialization failed. Exiting.\\n\";\n        return -1;\n    }<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc18c\ucf13\uc5d0 \uc801\uc6a9 \/ Apply to socket<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void https::Server::handle_client(int client_socket) {\n    \/\/ https\uc124\uc815 \ucd94\uac00 \/ Add https settings\u2757\ufe0f\n    SSL* ssl = SSL_new(ssl_ctx);\n    if (!ssl) {\n        std::cerr &lt;&lt; \"&#91;SSL] SSL_new() failed\\n\";\n        close(client_socket);\n        return;\n    }\n    \/\/ client_socket\uc5d0 ssl\uc801\uc6a9 \/ Apply SSL to client_socket\u2757\ufe0f\n    SSL_set_fd(ssl, client_socket);\n    if (SSL_accept(ssl) &lt;= 0) {\n        ERR_print_errors_fp(stderr);\n        SSL_free(ssl);\n        close(client_socket);\n        return;\n    }\n... \uc911\ub7b5 \/ skipping the middle...\n\n        \/\/ http\uc124\uc815 \/ http setting\n        \/\/write(client_socket, response.c_str(), response.size());\n        \/\/\n        \/\/ https\uc124\uc815.  https setting \u2757\ufe0f\n        SSL_write(ssl, response.c_str(), static_cast&lt;int&gt;(response.size()));\n\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f stop\ud568\uc218\uc5d0\uc11c \uc18c\ucf13,SSL\/TLS&nbsp;,openssl \uc885\ub8cc<br>Terminate socket, SSL\/TLS, and openssl in the stop function<\/p>\n\n\n\n<p>&#8212; httpsServer.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void https::Server::stop() {\n\n    if (running.load() &amp;&amp; server_fd != -1) { \/\/\n        \/\/ \ud50c\ub798\uadf8\ub97c false\ub85c \uc124\uc815\ud558\uc5ec \ub8e8\ud504 \uc885\ub8cc \uc2e0\ud638 \uc804\uc1a1\n        \/\/ Set flag to false to send loop termination signal\n        running.store(false);\n        \/\/close(server_fd); \/\/\u2757\ufe0f -\n\n        \/\/ \uc2e4\uc81c\ub85c\ub294 \uc5ec\uae30\uc11c \uc18c\ucf13\uc744 \ub2eb\uac70\ub098 \ub9ac\uc18c\uc2a4 \ud574\uc81c\ub97c \uc218\ud589\ud569\ub2c8\ub2e4.\n        \/\/ In practice, close the socket or release resources here.\n        \/\/server_fd = -1; \/\/ \ub2eb\uc558\uc73c\ubbc0\ub85c \ucd08\uae30\ud654 \/ Initialize to -1 after closing\n\n        \/\/  \u2757\ufe0f -&gt; \ubcc0\uacbd\ub41c \ucf54\ub4dc \/ changed code\n        \/\/ \uc11c\ubc84 \uc18c\ucf13 \ub2eb\uae30 (\uc5f4\ub824\uc788\ub2e4\uba74) \/ Close server socket (if open)\n        if (server_fd != -1) {\n            close(server_fd);\n            server_fd = -1;\n        }\n\n        \/\/ SSL \ucee8\ud14d\uc2a4\ud2b8 \ud574\uc81c (\uc874\uc7ac\ud55c\ub2e4\uba74) Release SSL context (if any) \u2757\ufe0f\n        if (ssl_ctx) {\n            SSL_CTX_free(ssl_ctx);\n            ssl_ctx = nullptr;\n        }\n\n        \/\/ OpenSSL \ub77c\uc774\ube0c\ub7ec\ub9ac \uc815\ub9ac \/ OpenSSL Library Cleanup \u2757\ufe0f\n        EVP_cleanup();\n\n        std::cout &lt;&lt; \"&#91;Server] Shutdown initiated.\" &lt;&lt; std::endl;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ube4c\ub4dc \/ Build<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd build\ncmake ..\nmake<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/main<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ube0c\ub77c\uc6b0\uc800 \uc811\uc18d \/ Access Browser<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;localhost:6443\/<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc8fc\uc694 \ubcc0\uacbd\uc0ac\ud56d\uc740 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.The major changes are as follows. \u2714\ufe0f \u2757\ufe0f \ud45c\uc2dc\ub41c \ubd80\ubd84\uc774 \ubcc0\uacbd\uc0ac\ud56d\uc785\ub2c8\ub2e4.The parts marked with \u2757\ufe0f are the changes. \u2714\ufe0f http,https \ub124\uc784\uc2a4\ud398\uc774\uc2a4 \uc801\uc6a9Apply http, https namespaces \u2714\ufe0f https\ud504\ub85c\ud1a0\ucf5c \uc801\uc6a9 \/ Apply HTTPS protocol \ud83d\udc49\ud83c\udffb openssl \uc801\uc6a9\ud558\uae30 \/ Apply openssl \u2714\ufe0f openssl \uc124\uce58 \/ install openssl \u2714\ufe0f openssl \uc124\uce58 \uacbd\ub85c \ud655\uc778 \/ Check [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5679","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5679"}],"version-history":[{"count":5,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5679\/revisions"}],"predecessor-version":[{"id":5684,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5679\/revisions\/5684"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}