SNode.C
Loading...
Searching...
No Matches
apps::http::tls Namespace Reference

Typedefs

using Client = web::http::tls::NET::Client
 
using Request = Client::Request
 
using Response = Client::Response
 
using SocketConnection = Client::SocketConnection
 
using WebApp = express::tls::NET::WebApp
 

Functions

static Client getClient ()
 
static WebApp getWebApp (const std::string &name)
 

Typedef Documentation

◆ Client

using apps::http::tls::Client = typedef web::http::tls::NET::Client

Definition at line 355 of file clients.h.

◆ Request

using apps::http::tls::Request = typedef Client::Request

Definition at line 356 of file clients.h.

◆ Response

using apps::http::tls::Response = typedef Client::Response

Definition at line 357 of file clients.h.

◆ SocketConnection

typedef WebApp::SocketConnection apps::http::tls::SocketConnection

Definition at line 358 of file clients.h.

◆ WebApp

using apps::http::tls::WebApp = typedef express::tls::NET::WebApp

Definition at line 93 of file servers.h.

Function Documentation

◆ getClient()

static Client apps::http::tls::getClient ( )
static

Definition at line 360 of file clients.h.

360 {
361 Client client(
362 "httpclient",
363 [](const std::shared_ptr<Request>& req) {
364 VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart";
365
366 req->url = "/";
367 req->set("Connection", "keep-alive");
368 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
369 logResponse(req, res);
370 });
371 req->url = "/";
372 req->set("Connection", "keep-alive");
373 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
374 logResponse(req, res);
375 });
376 req->url = "/index.html";
377 req->set("Connection", "keep-alive");
378 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
379 logResponse(req, res);
380 });
381 req->url = "/";
382 req->set("Connection", "keep-alive");
383 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
384 logResponse(req, res);
385 });
386 req->url = "/index.html";
387 req->set("Connection", "keep-alive");
388 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
389 logResponse(req, res);
390 });
391 req->url = "/";
392 req->set("Connection", "keep-alive");
393 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
394 logResponse(req, res);
395 });
396 req->url = "/index.html";
397 req->set("Connection", "keep-alive");
398 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
399 logResponse(req, res);
400 });
401 req->url = "/";
402 req->set("Connection", "keep-alive");
403 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
404 logResponse(req, res);
405 });
406 req->url = "/index.html";
407 req->set("Connection", "keep-alive");
408 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
409 logResponse(req, res);
410 });
411 req->url = "/";
412 req->set("Connection", "keep-alive");
413 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
414 logResponse(req, res);
415 });
416 req->url = "/index.html";
417 req->set("Connection", "keep-alive");
418 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
419 logResponse(req, res);
420 });
421 req->url = "/";
422 req->set("Connection", "keep-alive");
423 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
424 logResponse(req, res);
425 });
426 req->url = "/index.html";
427 req->set("Connection", "keep-alive");
428 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
429 logResponse(req, res);
430 });
431 req->url = "/";
432 req->set("Connection", "keep-alive");
433 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
434 logResponse(req, res);
435 });
436 req->url = "/index.html";
437 req->set("Connection", "keep-alive");
438 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
439 logResponse(req, res);
440 });
441 req->url = "/";
442 req->set("Connection", "keep-alive");
443 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
444 logResponse(req, res);
445 });
446 req->url = "/index.html";
447 req->set("Connection", "keep-alive");
448 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
449 logResponse(req, res);
450 });
451 req->url = "/";
452 req->set("Connection", "close");
453 req->end([](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
454 logResponse(req, res);
455 });
456 },
457 []([[maybe_unused]] const std::shared_ptr<Request>& req) {
458 VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestEnd";
459 });
460
461 client.setOnConnect([](SocketConnection* socketConnection) { // onConnect
462 VLOG(1) << "OnConnect " << socketConnection->getConnectionName();
463
464 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
465 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
466
467 /* Enable automatic hostname checks */
468 // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL());
469
470 // X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
471 // if (!X509_VERIFY_PARAM_set1_host(param, "localhost", sizeof("localhost") - 1)) {
472 // // handle error
473 // socketConnection->close();
474 // }
475 });
476
477 client.setOnConnected([](SocketConnection* socketConnection) { // onConnected
478 VLOG(1) << socketConnection->getConnectionName() << ": OnConnected";
479 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
480 if (server_cert != nullptr) {
481 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
482
483 VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " +
484 std::string(X509_verify_cert_error_string(verifyErr));
485
486 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0);
487 VLOG(1) << "\t Subject: " + std::string(str);
488 OPENSSL_free(str);
489
490 str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0);
491 VLOG(1) << "\t Issuer: " + std::string(str);
492 OPENSSL_free(str);
493
494 // We could do all sorts of certificate verification stuff here before deallocating the certificate.
495
496 GENERAL_NAMES* subjectAltNames =
497 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr));
498#ifdef __GNUC__
499#pragma GCC diagnostic push
500#ifdef __has_warning
501#if __has_warning("-Wused-but-marked-unused")
502#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
503#endif
504#endif
505#endif
506 int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
507#ifdef __GNUC_
508#pragma GCC diagnostic pop
509#endif
510 VLOG(1) << "\t Subject alternative name count: " << altNameCount;
511 for (int32_t i = 0; i < altNameCount; ++i) {
512#ifdef __GNUC__
513#pragma GCC diagnostic push
514#ifdef __has_warning
515#if __has_warning("-Wused-but-marked-unused")
516#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
517#endif
518#endif
519#endif
520 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
521#ifdef __GNUC_
522#pragma GCC diagnostic pop
523#endif
524 if (generalName->type == GEN_URI) {
525 std::string subjectAltName =
526 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
527 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
528 VLOG(1) << "\t SAN (URI): '" + subjectAltName;
529 } else if (generalName->type == GEN_DNS) {
530 std::string subjectAltName =
531 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
532 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
533 VLOG(1) << "\t SAN (DNS): '" + subjectAltName;
534 } else {
535 VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type);
536 }
537 }
538#ifdef __GNUC__
539#pragma GCC diagnostic push
540#ifdef __has_warning
541#if __has_warning("-Wused-but-marked-unused")
542#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
543#endif
544#endif
545#endif
546 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
547#ifdef __GNUC_
548#pragma GCC diagnostic pop
549#endif
550 X509_free(server_cert);
551 } else {
552 VLOG(1) << "\tPeer certificate: no certificate";
553 }
554 });
555
556 client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect
557 VLOG(1) << socketConnection->getConnectionName() << ": OnDisconnect";
558
559 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
560 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
561 });
562
563 return client;
564 }
static void logResponse(const std::shared_ptr< web::http::client::Request > &req, const std::shared_ptr< web::http::client::Response > &res)
Definition clients.h:67
web::http::tls::NET::Client Client
Definition clients.h:355

◆ getWebApp()

static WebApp apps::http::tls::getWebApp ( const std::string &  name)
static

Definition at line 96 of file servers.h.

96 {
97 WebApp webApp(name, getRouter());
98
99 webApp.setOnConnect([webApp](SocketConnection* socketConnection) { // onConnect
100 VLOG(1) << "OnConnect " << webApp.getConfig().getInstanceName();
101
102 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
103 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
104
105 /* Enable automatic hostname checks */
106 // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL());
107
108 // X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
109 // if (!X509_VERIFY_PARAM_set1_host(param, "localhost", sizeof("localhost") - 1)) {
110 // // handle error
111 // socketConnection->close();
112 // }
113 });
114
115 webApp.setOnConnected([webApp](SocketConnection* socketConnection) { // onConnected
116 VLOG(1) << "OnConnected " << webApp.getConfig().getInstanceName();
117
118 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
119 if (server_cert != nullptr) {
120 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
121
122 VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " +
123 std::string(X509_verify_cert_error_string(verifyErr));
124
125 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0);
126 VLOG(1) << "\t Subject: " + std::string(str);
127 OPENSSL_free(str);
128
129 str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0);
130 VLOG(1) << "\t Issuer: " + std::string(str);
131 OPENSSL_free(str);
132
133 // We could do all sorts of certificate verification stuff here before deallocating the certificate.
134
135 GENERAL_NAMES* subjectAltNames =
136 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr));
137#ifdef __GNUC__
138#pragma GCC diagnostic push
139#ifdef __has_warning
140#if __has_warning("-Wused-but-marked-unused")
141#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
142#endif
143#endif
144#endif
145 int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
146#ifdef __GNUC_
147#pragma GCC diagnostic pop
148#endif
149 VLOG(1) << "\t Subject alternative name count: " << altNameCount;
150 for (int32_t i = 0; i < altNameCount; ++i) {
151#ifdef __GNUC__
152#pragma GCC diagnostic push
153#ifdef __has_warning
154#if __has_warning("-Wused-but-marked-unused")
155#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
156#endif
157#endif
158#endif
159 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
160#ifdef __GNUC_
161#pragma GCC diagnostic pop
162#endif
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;
173 } else {
174 VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type);
175 }
176 }
177#ifdef __GNUC__
178#pragma GCC diagnostic push
179#ifdef __has_warning
180#if __has_warning("-Wused-but-marked-unused")
181#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
182#endif
183#endif
184#endif
185 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
186#ifdef __GNUC_
187#pragma GCC diagnostic pop
188#endif
189 X509_free(server_cert);
190 } else {
191 LOG(WARNING) << "\tPeer certificate: no certificate";
192 }
193 });
194
195 webApp.setOnDisconnect([webApp](SocketConnection* socketConnection) { // onDisconnect
196 VLOG(1) << "OnDisconnect " << webApp.getConfig().getInstanceName();
197
198 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
199 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
200 });
201
202 return webApp;
203 }
static express::Router getRouter()
Definition servers.h:68
Client::SocketConnection SocketConnection
Definition clients.h:358
express::tls::NET::WebApp WebApp
Definition servers.h:93

References getRouter().

Here is the call graph for this function: