75 WebApp webApp(name, getRouter());
77 webApp.setOnConnect([webApp](SocketConnection* socketConnection) {
78 VLOG(1) <<
"OnConnect " << webApp.getConfig().getInstanceName();
80 VLOG(1) <<
"\tLocal: " << socketConnection->getLocalAddress().toString();
81 VLOG(1) <<
"\tPeer: " << socketConnection->getRemoteAddress().toString();
93 webApp.setOnConnected([webApp](SocketConnection* socketConnection) {
94 VLOG(1) <<
"OnConnected " << webApp.getConfig().getInstanceName();
96 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
97 if (server_cert !=
nullptr) {
98 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
100 VLOG(1) <<
"\tPeer certificate verifyErr = " + std::to_string(verifyErr) +
": " +
101 std::string(X509_verify_cert_error_string(verifyErr));
103 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert),
nullptr, 0);
104 VLOG(1) <<
"\t Subject: " + std::string(str);
107 str = X509_NAME_oneline(X509_get_issuer_name(server_cert),
nullptr, 0);
108 VLOG(1) <<
"\t Issuer: " + std::string(str);
113 GENERAL_NAMES* subjectAltNames =
114 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name,
nullptr,
nullptr));
116#pragma GCC diagnostic push
118#if __has_warning
("-Wused-but-marked-unused")
119#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
123 int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
125#pragma GCC diagnostic pop
127 VLOG(1) <<
"\t Subject alternative name count: " << altNameCount;
128 for (int32_t i = 0; i < altNameCount; ++i) {
130#pragma GCC diagnostic push
132#if __has_warning
("-Wused-but-marked-unused")
133#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
137 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
139#pragma GCC diagnostic pop
141 if (generalName->type == GEN_URI) {
142 std::string subjectAltName =
143 std::string(
reinterpret_cast<
const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
144 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
145 VLOG(1) <<
"\t SAN (URI): '" + subjectAltName;
146 }
else if (generalName->type == GEN_DNS) {
147 std::string subjectAltName =
148 std::string(
reinterpret_cast<
const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
149 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
150 VLOG(1) <<
"\t SAN (DNS): '" + subjectAltName;
152 VLOG(1) <<
"\t SAN (Type): '" + std::to_string(generalName->type);
156#pragma GCC diagnostic push
158#if __has_warning
("-Wused-but-marked-unused")
159#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
163 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
165#pragma GCC diagnostic pop
167 X509_free(server_cert);
169 LOG(WARNING) <<
"\tPeer certificate: no certificate";
173 webApp.setOnDisconnect([webApp](SocketConnection* socketConnection) {
174 VLOG(1) <<
"OnDisconnect " << webApp.getConfig().getInstanceName();
176 VLOG(1) <<
"\tLocal: " << socketConnection->getLocalAddress().toString();
177 VLOG(1) <<
"\tPeer: " << socketConnection->getRemoteAddress().toString();