2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#ifndef APPS_HTTP_MODEL_SERVERS_H
43#define APPS_HTTP_MODEL_SERVERS_H
46#define STR_INCLUDE(a) #a
52#include WEBAPP_INCLUDE
54#include "express/middleware/VerboseRequest.h"
56#ifndef DOXYGEN_SHOULD_SKIP_THIS
58#include "log/Logger.h"
60#if (STREAM_TYPE == TLS)
62#include <openssl/ssl.h>
63#include <openssl/x509v3.h>
72#if (STREAM_TYPE == LEGACY)
74namespace apps::http::
legacy {
89#if (STREAM_TYPE == TLS)
91namespace apps::http::
tls {
99 webApp.setOnConnect([webApp](SocketConnection* socketConnection) {
100 VLOG(1) <<
"OnConnect " << webApp.getConfig().getInstanceName();
102 VLOG(1) <<
"\tLocal: " << socketConnection->getLocalAddress().toString();
103 VLOG(1) <<
"\tPeer: " << socketConnection->getRemoteAddress().toString();
115 webApp.setOnConnected([webApp](SocketConnection* socketConnection) {
116 VLOG(1) <<
"OnConnected " << webApp.getConfig().getInstanceName();
118 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
119 if (server_cert !=
nullptr) {
120 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
122 VLOG(1) <<
"\tPeer certificate verifyErr = " + std::to_string(verifyErr) +
": " +
123 std::string(X509_verify_cert_error_string(verifyErr));
125 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert),
nullptr, 0);
126 VLOG(1) <<
"\t Subject: " + std::string(str);
129 str = X509_NAME_oneline(X509_get_issuer_name(server_cert),
nullptr, 0);
130 VLOG(1) <<
"\t Issuer: " + std::string(str);
135 GENERAL_NAMES* subjectAltNames =
136 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name,
nullptr,
nullptr));
138#pragma GCC diagnostic push
140#if __has_warning
("-Wused-but-marked-unused")
141#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
145 int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
147#pragma GCC diagnostic pop
149 VLOG(1) <<
"\t Subject alternative name count: " << altNameCount;
150 for (int32_t i = 0; i < altNameCount; ++i) {
152#pragma GCC diagnostic push
154#if __has_warning
("-Wused-but-marked-unused")
155#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
159 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
161#pragma GCC diagnostic pop
163 if (generalName->type == GEN_URI) {
164 std::string subjectAltName =
165 std::string(
reinterpret_cast<
const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
166 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
167 VLOG(1) <<
"\t SAN (URI): '" + subjectAltName;
168 }
else if (generalName->type == GEN_DNS) {
169 std::string subjectAltName =
170 std::string(
reinterpret_cast<
const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
171 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
172 VLOG(1) <<
"\t SAN (DNS): '" + subjectAltName;
174 VLOG(1) <<
"\t SAN (Type): '" + std::to_string(generalName->type);
178#pragma GCC diagnostic push
180#if __has_warning
("-Wused-but-marked-unused")
181#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
185 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
187#pragma GCC diagnostic pop
189 X509_free(server_cert);
191 LOG(WARNING) <<
"\tPeer certificate: no certificate";
195 webApp.setOnDisconnect([webApp](SocketConnection* socketConnection) {
196 VLOG(1) <<
"OnDisconnect " << webApp.getConfig().getInstanceName();
198 VLOG(1) <<
"\tLocal: " << socketConnection->getLocalAddress().toString();
199 VLOG(1) <<
"\tPeer: " << socketConnection->getRemoteAddress().toString();
static express::Router getRouter()
static WebApp getWebApp(const std::string &name)
static WebApp getWebApp(const std::string &name)
int main(int argc, char *argv[])