| 83 | } |
| 84 | |
| 85 | int |
| 86 | main() |
| 87 | { |
| 88 | try |
| 89 | { |
| 90 | // The io_context is required for all I/O |
| 91 | net::io_context ioc; |
| 92 | |
| 93 | // The SSL context is required, and holds certificates, |
| 94 | // configurations and session related data |
| 95 | ssl::context ctx{ ssl::context::sslv23 }; |
| 96 | |
| 97 | // https://docs.openssl.org/3.4/man3/SSL_CTX_set_options/ |
| 98 | ctx.set_options( |
| 99 | ssl::context::no_sslv2 | ssl::context::default_workarounds | |
| 100 | ssl::context::single_dh_use); |
| 101 | |
| 102 | // set up the peer verification mode so that the TLS/SSL handshake fails |
| 103 | // if the certificate verification is unsuccessful |
| 104 | ctx.set_verify_mode(ssl::verify_peer); |
| 105 | |
| 106 | // The servers's certificate will be verified against this |
| 107 | // certificate authority. |
| 108 | ctx.load_verify_file("ca.crt"); |
| 109 | |
| 110 | // In a real application, the passphrase would be read from |
| 111 | // a secure place, such as a key vault. |
| 112 | ctx.set_password_callback([](auto, auto) { return "123456"; }); |
| 113 | |
| 114 | // Client certificate and private key (if server request for). |
| 115 | ctx.use_certificate_chain_file("client.crt"); |
| 116 | ctx.use_private_key_file("client.key", ssl::context::pem); |
| 117 | |
| 118 | net::co_spawn(ioc, request(ctx), print_exception); |
| 119 | |
| 120 | ioc.run(); |
| 121 | } |
| 122 | catch(std::exception& e) |
| 123 | { |
| 124 | std::cerr << e.what() << std::endl; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | #else |
| 129 | |