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

Typedefs

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

Functions

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

Typedef Documentation

◆ Client

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

Definition at line 498 of file clients.h.

◆ MasterRequest

using apps::http::tls::MasterRequest = Client::MasterRequest

Definition at line 499 of file clients.h.

◆ Request

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

Definition at line 500 of file clients.h.

◆ Response

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

Definition at line 501 of file clients.h.

◆ SocketConnection

typedef WebApp::SocketConnection apps::http::tls::SocketConnection = Client::SocketConnection

Definition at line 502 of file clients.h.

◆ WebApp

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

Definition at line 93 of file servers.h.

Function Documentation

◆ getClient()

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

Definition at line 504 of file clients.h.

504 {
505 Client client(
506 "httpclient",
507 [](const std::shared_ptr<MasterRequest>& req) {
508 VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart";
509
510 req->url = "/";
511 req->set("Connection", "keep-alive");
512 req->end(
513 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
514 logResponse(req, res);
515 },
516 [](const std::shared_ptr<Request>&, const std::string&) {
517 });
518 req->url = "/";
519 req->set("Connection", "keep-alive");
520 req->end(
521 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
522 logResponse(req, res);
523 },
524 [](const std::shared_ptr<Request>&, const std::string&) {
525 });
526 req->url = "/index.html";
527 req->set("Connection", "keep-alive");
528 req->end(
529 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
530 logResponse(req, res);
531 },
532 [](const std::shared_ptr<Request>&, const std::string&) {
533 });
534 req->url = "/";
535 req->set("Connection", "keep-alive");
536 req->end(
537 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
538 logResponse(req, res);
539 },
540 [](const std::shared_ptr<Request>&, const std::string&) {
541 });
542 req->url = "/index.html";
543 req->set("Connection", "keep-alive");
544 req->end(
545 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
546 logResponse(req, res);
547 },
548 [](const std::shared_ptr<Request>&, const std::string&) {
549 });
550 req->url = "/";
551 req->set("Connection", "keep-alive");
552 req->end(
553 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
554 logResponse(req, res);
555 },
556 [](const std::shared_ptr<Request>&, const std::string&) {
557 });
558 req->url = "/index.html";
559 req->set("Connection", "keep-alive");
560 req->end(
561 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
562 logResponse(req, res);
563 },
564 [](const std::shared_ptr<Request>&, const std::string&) {
565 });
566 req->url = "/";
567 req->set("Connection", "keep-alive");
568 req->end(
569 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
570 logResponse(req, res);
571 },
572 [](const std::shared_ptr<Request>&, const std::string&) {
573 });
574 req->url = "/index.html";
575 req->set("Connection", "keep-alive");
576 req->end(
577 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
578 logResponse(req, res);
579 },
580 [](const std::shared_ptr<Request>&, const std::string&) {
581 });
582 req->url = "/";
583 req->set("Connection", "keep-alive");
584 req->end(
585 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
586 logResponse(req, res);
587 },
588 [](const std::shared_ptr<Request>&, const std::string&) {
589 });
590 req->url = "/index.html";
591 req->set("Connection", "keep-alive");
592 req->end(
593 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
594 logResponse(req, res);
595 },
596 [](const std::shared_ptr<Request>&, const std::string&) {
597 });
598 req->url = "/";
599 req->set("Connection", "keep-alive");
600 req->end(
601 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
602 logResponse(req, res);
603 },
604 [](const std::shared_ptr<Request>&, const std::string&) {
605 });
606 req->url = "/index.html";
607 req->set("Connection", "keep-alive");
608 req->end(
609 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
610 logResponse(req, res);
611 },
612 [](const std::shared_ptr<Request>&, const std::string&) {
613 });
614 req->url = "/";
615 req->set("Connection", "keep-alive");
616 req->end(
617 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
618 logResponse(req, res);
619 },
620 [](const std::shared_ptr<Request>&, const std::string&) {
621 });
622 req->url = "/index.html";
623 req->set("Connection", "keep-alive");
624 req->end(
625 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
626 logResponse(req, res);
627 },
628 [](const std::shared_ptr<Request>&, const std::string&) {
629 });
630 req->url = "/";
631 req->set("Connection", "keep-alive");
632 req->end(
633 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
634 logResponse(req, res);
635 },
636 [](const std::shared_ptr<Request>&, const std::string&) {
637 });
638 req->url = "/index.html";
639 req->set("Connection", "keep-alive");
640 req->end(
641 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
642 logResponse(req, res);
643 },
644 [](const std::shared_ptr<Request>&, const std::string&) {
645 });
646 req->url = "/";
647 req->set("Connection", "close");
648 req->end(
649 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
650 logResponse(req, res);
651 },
652 [](const std::shared_ptr<Request>&, const std::string&) {
653 });
654 },
655 []([[maybe_unused]] const std::shared_ptr<Request>& req) {
656 VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestEnd";
657 });
658
659 client.setOnConnect([](SocketConnection* socketConnection) { // onConnect
660 VLOG(1) << "OnConnect " << socketConnection->getConnectionName();
661
662 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
663 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
664
665 /* Enable automatic hostname checks */
666 // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL());
667
668 // X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
669 // if (!X509_VERIFY_PARAM_set1_host(param, "localhost", sizeof("localhost") - 1)) {
670 // // handle error
671 // socketConnection->close();
672 // }
673 });
674
675 client.setOnConnected([](SocketConnection* socketConnection) { // onConnected
676 VLOG(1) << socketConnection->getConnectionName() << ": OnConnected";
677 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
678 if (server_cert != nullptr) {
679 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
680
681 VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " +
682 std::string(X509_verify_cert_error_string(verifyErr));
683
684 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0);
685 VLOG(1) << "\t Subject: " + std::string(str);
686 OPENSSL_free(str);
687
688 str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0);
689 VLOG(1) << "\t Issuer: " + std::string(str);
690 OPENSSL_free(str);
691
692 // We could do all sorts of certificate verification stuff here before deallocating the certificate.
693
694 GENERAL_NAMES* subjectAltNames =
695 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr));
696
697 int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
698
699 VLOG(1) << "\t Subject alternative name count: " << altNameCount;
700 for (int32_t i = 0; i < altNameCount; ++i) {
701 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
702 if (generalName->type == GEN_URI) {
703 std::string subjectAltName =
704 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
705 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
706 VLOG(1) << "\t SAN (URI): '" + subjectAltName;
707 } else if (generalName->type == GEN_DNS) {
708 std::string subjectAltName =
709 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
710 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
711 VLOG(1) << "\t SAN (DNS): '" + subjectAltName;
712 } else {
713 VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type);
714 }
715 }
716
717 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
718
719 X509_free(server_cert);
720 } else {
721 VLOG(1) << "\tPeer certificate: no certificate";
722 }
723 });
724
725 client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect
726 VLOG(1) << socketConnection->getConnectionName() << ": OnDisconnect";
727
728 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
729 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
730 });
731
732 return client;
733 }
#define VLOG(level)
Definition Logger.h:164
static void logResponse(const std::shared_ptr< web::http::client::Request > &req, const std::shared_ptr< web::http::client::Response > &res)
Definition clients.h:71
Client::SocketConnection SocketConnection
Definition clients.h:502
web::http::tls::NET::Client Client
Definition clients.h:498

References logger::LogMessage::LogMessage().

Here is the call graph for this function:

◆ getWebApp()

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 const std::string& instanceName = webApp.getConfig().getInstanceName();
100
101 webApp.setOnConnect([instanceName](SocketConnection* socketConnection) { // onConnect
102 VLOG(1) << "OnConnect " << instanceName;
103
104 VLOG(1) << " Local: " << socketConnection->getLocalAddress().toString();
105 VLOG(1) << " Peer: " << socketConnection->getRemoteAddress().toString();
106
107 /* Enable automatic hostname checks */
108 // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL());
109
110 // X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
111 // if (!X509_VERIFY_PARAM_set1_host(param, "localhost", sizeof("localhost") - 1)) {
112 // // handle error
113 // socketConnection->close();
114 // }
115 });
116
117 webApp.setOnConnected([instanceName](SocketConnection* socketConnection) { // onConnected
118 VLOG(1) << "OnConnected " << instanceName;
119
120 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
121 if (server_cert != nullptr) {
122 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
123
124 VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " +
125 std::string(X509_verify_cert_error_string(verifyErr));
126
127 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0);
128 VLOG(1) << "\t Subject: " + std::string(str);
129 OPENSSL_free(str);
130
131 str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0);
132 VLOG(1) << "\t Issuer: " + std::string(str);
133 OPENSSL_free(str);
134
135 // We could do all sorts of certificate verification stuff here before deallocating the certificate.
136
137 GENERAL_NAMES* subjectAltNames =
138 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr));
139
140 int32_t altNameCount = OPENSSL_sk_num(reinterpret_cast<const OPENSSL_STACK*>(subjectAltNames));
141
142 VLOG(1) << "\t Subject alternative name count: " << altNameCount;
143 for (int32_t i = 0; i < altNameCount; ++i) {
144 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
145
146 if (generalName->type == GEN_URI) {
147 std::string subjectAltName =
148 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
149 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
150 VLOG(1) << "\t SAN (URI): '" + subjectAltName;
151 } else if (generalName->type == GEN_DNS) {
152 std::string subjectAltName =
153 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
154 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
155 VLOG(1) << "\t SAN (DNS): '" + subjectAltName;
156 } else {
157 VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type);
158 }
159 }
160
161 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
162
163 X509_free(server_cert);
164 } else {
165 LOG(WARNING) << "\tPeer certificate: no certificate";
166 }
167 });
168
169 webApp.setOnDisconnect([instanceName](SocketConnection* socketConnection) { // onDisconnect
170 VLOG(1) << "OnDisconnect " << instanceName;
171
172 VLOG(2) << " Local: " << socketConnection->getLocalAddress().toString(false);
173 VLOG(2) << " Peer: " << socketConnection->getRemoteAddress().toString(false);
174
175 VLOG(2) << " Online Since: " << socketConnection->getOnlineSince();
176 VLOG(2) << " Online Duration: " << socketConnection->getOnlineDuration();
177
178 VLOG(2) << " Total Queued: " << socketConnection->getTotalQueued();
179 VLOG(2) << " Total Sent: " << socketConnection->getTotalSent();
180 VLOG(2) << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent();
181 VLOG(2) << " Total Read: " << socketConnection->getTotalRead();
182 VLOG(2) << " Total Processed: " << socketConnection->getTotalProcessed();
183 VLOG(2) << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed();
184 });
185
186 return webApp;
187 }
#define LOG(level)
Definition Logger.h:148
static express::Router getRouter()
Definition servers.h:68
express::tls::NET::WebApp WebApp
Definition servers.h:93

References getRouter(), logger::LogMessage::LogMessage(), and logger::WARNING.

Here is the call graph for this function: