127 SocketClient tlsClient(
129 [](SocketConnection* socketConnection) {
130 VLOG(1) <<
"OnConnect";
132 VLOG(1) <<
"\tServer: " << socketConnection->getRemoteAddress().toString();
133 VLOG(1) <<
"\tClient: " << socketConnection->getLocalAddress().toString();
144 [](SocketConnection* socketConnection) {
145 VLOG(1) <<
"OnConnected";
147 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
148 if (server_cert !=
nullptr) {
149 const long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
151 VLOG(1) <<
" Server certificate: " + std::string(X509_verify_cert_error_string(verifyErr));
153 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert),
nullptr, 0);
154 VLOG(1) <<
" Subject: " + std::string(str);
157 str = X509_NAME_oneline(X509_get_issuer_name(server_cert),
nullptr, 0);
158 VLOG(1) <<
" Issuer: " + std::string(str);
163 GENERAL_NAMES* subjectAltNames =
164 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name,
nullptr,
nullptr));
166#pragma GCC diagnostic push
168#if __has_warning
("-Wused-but-marked-unused")
169#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
173 const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
175#pragma GCC diagnostic pop
177 VLOG(1) <<
"\t Subject alternative name count: " << altNameCount;
178 for (int32_t i = 0; i < altNameCount; ++i) {
180#pragma GCC diagnostic push
182#if __has_warning
("-Wused-but-marked-unused")
183#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
187 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
189#pragma GCC diagnostic pop
191 if (generalName->type == GEN_URI) {
192 const std::string subjectAltName =
193 std::string(
reinterpret_cast<
const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
194 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
195 VLOG(1) <<
"\t SAN (URI): '" + subjectAltName;
196 }
else if (generalName->type == GEN_DNS) {
197 const std::string subjectAltName =
198 std::string(
reinterpret_cast<
const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
199 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
200 VLOG(1) <<
"\t SAN (DNS): '" + subjectAltName;
202 VLOG(1) <<
"\t SAN (Type): '" + std::to_string(generalName->type);
206#pragma GCC diagnostic push
208#if __has_warning
("-Wused-but-marked-unused")
209#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
213 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
215#pragma GCC diagnostic pop
217 X509_free(server_cert);
219 VLOG(1) <<
" Server certificate: no certificate";
222 socketConnection->sendToPeer(
"GET /index.html HTTP/1.1\r\nConnection: close\r\n\r\n");
224 [](SocketConnection* socketConnection) {
225 VLOG(1) <<
"OnDisconnect";
227 VLOG(1) <<
"\tServer: " + socketConnection->getRemoteAddress().toString();
228 VLOG(1) <<
"\tClient: " + socketConnection->getLocalAddress().toString();
232 const SocketAddress remoteAddress(
"localhost", 8088);
234 tlsClient.connect(remoteAddress,
235 [instanceName = tlsClient.getConfig().getInstanceName()](
236 const SocketAddress& socketAddress,
237 const core::socket::State& state) {
239 case core::socket::State::OK:
240 VLOG(1) << instanceName <<
": connected to '" << socketAddress.toString() <<
"'";
242 case core::socket::State::DISABLED:
243 VLOG(1) << instanceName <<
": disabled";
245 case core::socket::State::ERROR:
246 LOG(ERROR) << instanceName <<
": " << socketAddress.toString() <<
": " << state.what();
248 case core::socket::State::FATAL:
249 LOG(FATAL) << instanceName <<
": " << socketAddress.toString() <<
": " << state.what();