| 76 | } |
| 77 | |
| 78 | int |
| 79 | main() |
| 80 | { |
| 81 | try |
| 82 | { |
| 83 | // The io_context is required for all I/O |
| 84 | net::io_context ioc; |
| 85 | |
| 86 | // The SSL context is required, and holds certificates, |
| 87 | // configurations and session related data |
| 88 | ssl::context ctx{ ssl::context::sslv23 }; |
| 89 | |
| 90 | // https://docs.openssl.org/3.4/man3/SSL_CTX_set_options/ |
| 91 | ctx.set_options( |
| 92 | ssl::context::no_sslv2 | ssl::context::default_workarounds | |
| 93 | ssl::context::single_dh_use); |
| 94 | |
| 95 | // Comment this line to disable client certificate request. |
| 96 | ctx.set_verify_mode( |
| 97 | ssl::verify_peer | ssl::verify_fail_if_no_peer_cert); |
| 98 | |
| 99 | // The client's certificate will be verified against this |
| 100 | // certificate authority. |
| 101 | ctx.load_verify_file("ca.crt"); |
| 102 | |
| 103 | // In a real application, the passphrase would be read from |
| 104 | // a secure place, such as a key vault. |
| 105 | ctx.set_password_callback([](auto, auto) { return "123456"; }); |
| 106 | |
| 107 | // Server certificate and private key. |
| 108 | ctx.use_certificate_chain_file("server.crt"); |
| 109 | ctx.use_private_key_file("server.key", ssl::context::pem); |
| 110 | |
| 111 | // DH parameters for DHE-based cipher suites |
| 112 | ctx.use_tmp_dh_file("dh4096.pem"); |
| 113 | |
| 114 | net::co_spawn(ioc, acceptor(ctx), print_exception); |
| 115 | |
| 116 | ioc.run(); |
| 117 | } |
| 118 | catch(std::exception& e) |
| 119 | { |
| 120 | std::cerr << e.what() << std::endl; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | #else |
| 125 | |