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 = typedef web::http::tls::NET::Client

Definition at line 521 of file clients.h.

◆ MasterRequest

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

Definition at line 522 of file clients.h.

◆ Request

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

Definition at line 523 of file clients.h.

◆ Response

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

Definition at line 524 of file clients.h.

◆ SocketConnection

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

Definition at line 525 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()

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

Definition at line 527 of file clients.h.

527 {
528 Client client(
529 "httpclient",
530 [](const std::shared_ptr<MasterRequest>& req) {
531 VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart";
532
533 req->url = "/";
534 req->set("Connection", "keep-alive");
535 req->end(
536 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
537 logResponse(req, res);
538 },
539 [](const std::shared_ptr<Request>&, const std::string&) {
540 });
541 req->url = "/";
542 req->set("Connection", "keep-alive");
543 req->end(
544 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
545 logResponse(req, res);
546 },
547 [](const std::shared_ptr<Request>&, const std::string&) {
548 });
549 req->url = "/index.html";
550 req->set("Connection", "keep-alive");
551 req->end(
552 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
553 logResponse(req, res);
554 },
555 [](const std::shared_ptr<Request>&, const std::string&) {
556 });
557 req->url = "/";
558 req->set("Connection", "keep-alive");
559 req->end(
560 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
561 logResponse(req, res);
562 },
563 [](const std::shared_ptr<Request>&, const std::string&) {
564 });
565 req->url = "/index.html";
566 req->set("Connection", "keep-alive");
567 req->end(
568 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
569 logResponse(req, res);
570 },
571 [](const std::shared_ptr<Request>&, const std::string&) {
572 });
573 req->url = "/";
574 req->set("Connection", "keep-alive");
575 req->end(
576 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
577 logResponse(req, res);
578 },
579 [](const std::shared_ptr<Request>&, const std::string&) {
580 });
581 req->url = "/index.html";
582 req->set("Connection", "keep-alive");
583 req->end(
584 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
585 logResponse(req, res);
586 },
587 [](const std::shared_ptr<Request>&, const std::string&) {
588 });
589 req->url = "/";
590 req->set("Connection", "keep-alive");
591 req->end(
592 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
593 logResponse(req, res);
594 },
595 [](const std::shared_ptr<Request>&, const std::string&) {
596 });
597 req->url = "/index.html";
598 req->set("Connection", "keep-alive");
599 req->end(
600 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
601 logResponse(req, res);
602 },
603 [](const std::shared_ptr<Request>&, const std::string&) {
604 });
605 req->url = "/";
606 req->set("Connection", "keep-alive");
607 req->end(
608 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
609 logResponse(req, res);
610 },
611 [](const std::shared_ptr<Request>&, const std::string&) {
612 });
613 req->url = "/index.html";
614 req->set("Connection", "keep-alive");
615 req->end(
616 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
617 logResponse(req, res);
618 },
619 [](const std::shared_ptr<Request>&, const std::string&) {
620 });
621 req->url = "/";
622 req->set("Connection", "keep-alive");
623 req->end(
624 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
625 logResponse(req, res);
626 },
627 [](const std::shared_ptr<Request>&, const std::string&) {
628 });
629 req->url = "/index.html";
630 req->set("Connection", "keep-alive");
631 req->end(
632 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
633 logResponse(req, res);
634 },
635 [](const std::shared_ptr<Request>&, const std::string&) {
636 });
637 req->url = "/";
638 req->set("Connection", "keep-alive");
639 req->end(
640 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
641 logResponse(req, res);
642 },
643 [](const std::shared_ptr<Request>&, const std::string&) {
644 });
645 req->url = "/index.html";
646 req->set("Connection", "keep-alive");
647 req->end(
648 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
649 logResponse(req, res);
650 },
651 [](const std::shared_ptr<Request>&, const std::string&) {
652 });
653 req->url = "/";
654 req->set("Connection", "keep-alive");
655 req->end(
656 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
657 logResponse(req, res);
658 },
659 [](const std::shared_ptr<Request>&, const std::string&) {
660 });
661 req->url = "/index.html";
662 req->set("Connection", "keep-alive");
663 req->end(
664 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
665 logResponse(req, res);
666 },
667 [](const std::shared_ptr<Request>&, const std::string&) {
668 });
669 req->url = "/";
670 req->set("Connection", "close");
671 req->end(
672 [](const std::shared_ptr<Request>& req, const std::shared_ptr<Response>& res) {
673 logResponse(req, res);
674 },
675 [](const std::shared_ptr<Request>&, const std::string&) {
676 });
677 },
678 []([[maybe_unused]] const std::shared_ptr<Request>& req) {
679 VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestEnd";
680 });
681
682 client.setOnConnect([](SocketConnection* socketConnection) { // onConnect
683 VLOG(1) << "OnConnect " << socketConnection->getConnectionName();
684
685 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
686 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
687
688 /* Enable automatic hostname checks */
689 // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL());
690
691 // X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
692 // if (!X509_VERIFY_PARAM_set1_host(param, "localhost", sizeof("localhost") - 1)) {
693 // // handle error
694 // socketConnection->close();
695 // }
696 });
697
698 client.setOnConnected([](SocketConnection* socketConnection) { // onConnected
699 VLOG(1) << socketConnection->getConnectionName() << ": OnConnected";
700 X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL());
701 if (server_cert != nullptr) {
702 long verifyErr = SSL_get_verify_result(socketConnection->getSSL());
703
704 VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " +
705 std::string(X509_verify_cert_error_string(verifyErr));
706
707 char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0);
708 VLOG(1) << "\t Subject: " + std::string(str);
709 OPENSSL_free(str);
710
711 str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0);
712 VLOG(1) << "\t Issuer: " + std::string(str);
713 OPENSSL_free(str);
714
715 // We could do all sorts of certificate verification stuff here before deallocating the certificate.
716
717 GENERAL_NAMES* subjectAltNames =
718 static_cast<GENERAL_NAMES*>(X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr));
719#ifdef __GNUC__
720#pragma GCC diagnostic push
721#ifdef __has_warning
722#if __has_warning("-Wused-but-marked-unused")
723#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
724#endif
725#endif
726#endif
727 int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
728#ifdef __GNUC_
729#pragma GCC diagnostic pop
730#endif
731 VLOG(1) << "\t Subject alternative name count: " << altNameCount;
732 for (int32_t i = 0; i < altNameCount; ++i) {
733#ifdef __GNUC__
734#pragma GCC diagnostic push
735#ifdef __has_warning
736#if __has_warning("-Wused-but-marked-unused")
737#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
738#endif
739#endif
740#endif
741 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
742#ifdef __GNUC_
743#pragma GCC diagnostic pop
744#endif
745 if (generalName->type == GEN_URI) {
746 std::string subjectAltName =
747 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
748 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
749 VLOG(1) << "\t SAN (URI): '" + subjectAltName;
750 } else if (generalName->type == GEN_DNS) {
751 std::string subjectAltName =
752 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
753 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
754 VLOG(1) << "\t SAN (DNS): '" + subjectAltName;
755 } else {
756 VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type);
757 }
758 }
759#ifdef __GNUC__
760#pragma GCC diagnostic push
761#ifdef __has_warning
762#if __has_warning("-Wused-but-marked-unused")
763#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
764#endif
765#endif
766#endif
767 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
768#ifdef __GNUC_
769#pragma GCC diagnostic pop
770#endif
771 X509_free(server_cert);
772 } else {
773 VLOG(1) << "\tPeer certificate: no certificate";
774 }
775 });
776
777 client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect
778 VLOG(1) << socketConnection->getConnectionName() << ": OnDisconnect";
779
780 VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString();
781 VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString();
782 });
783
784 return client;
785 }
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
web::http::tls::NET::Client Client
Definition clients.h:521

◆ 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) << " Local: " << socketConnection->getLocalAddress().toString();
103 VLOG(1) << " Peer: " << 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(2) << " Local: " << socketConnection->getLocalAddress().toString(false);
199 VLOG(2) << " Peer: " << socketConnection->getRemoteAddress().toString(false);
200
201 VLOG(2) << " Online Since: " << socketConnection->getOnlineSince();
202 VLOG(2) << " Online Duration: " << socketConnection->getOnlineDuration();
203
204 VLOG(2) << " Total Queued: " << socketConnection->getTotalQueued();
205 VLOG(2) << " Total Sent: " << socketConnection->getTotalSent();
206 VLOG(2) << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent();
207 VLOG(2) << " Total Read: " << socketConnection->getTotalRead();
208 VLOG(2) << " Total Processed: " << socketConnection->getTotalProcessed();
209 VLOG(2) << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed();
210 });
211
212 return webApp;
213 }
static express::Router getRouter()
Definition servers.h:68
Client::SocketConnection SocketConnection
Definition clients.h:525
express::tls::NET::WebApp WebApp
Definition servers.h:93

References getRouter().

Here is the call graph for this function: