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 531 of file clients.h.

◆ MasterRequest

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

Definition at line 532 of file clients.h.

◆ Request

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

Definition at line 533 of file clients.h.

◆ Response

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

Definition at line 534 of file clients.h.

◆ SocketConnection

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

Definition at line 535 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 537 of file clients.h.

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

◆ 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 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
138 int32_t altNameCount = OPENSSL_sk_num(reinterpret_cast<const OPENSSL_STACK*>(subjectAltNames));
139
140 VLOG(1) << "\t Subject alternative name count: " << altNameCount;
141 for (int32_t i = 0; i < altNameCount; ++i) {
142 GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
143
144 if (generalName->type == GEN_URI) {
145 std::string subjectAltName =
146 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)),
147 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.uniformResourceIdentifier)));
148 VLOG(1) << "\t SAN (URI): '" + subjectAltName;
149 } else if (generalName->type == GEN_DNS) {
150 std::string subjectAltName =
151 std::string(reinterpret_cast<const char*>(ASN1_STRING_get0_data(generalName->d.dNSName)),
152 static_cast<std::size_t>(ASN1_STRING_length(generalName->d.dNSName)));
153 VLOG(1) << "\t SAN (DNS): '" + subjectAltName;
154 } else {
155 VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type);
156 }
157 }
158
159 sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
160
161 X509_free(server_cert);
162 } else {
163 LOG(WARNING) << "\tPeer certificate: no certificate";
164 }
165 });
166
167 webApp.setOnDisconnect([webApp](SocketConnection* socketConnection) { // onDisconnect
168 VLOG(1) << "OnDisconnect " << webApp.getConfig().getInstanceName();
169
170 VLOG(2) << " Local: " << socketConnection->getLocalAddress().toString(false);
171 VLOG(2) << " Peer: " << socketConnection->getRemoteAddress().toString(false);
172
173 VLOG(2) << " Online Since: " << socketConnection->getOnlineSince();
174 VLOG(2) << " Online Duration: " << socketConnection->getOnlineDuration();
175
176 VLOG(2) << " Total Queued: " << socketConnection->getTotalQueued();
177 VLOG(2) << " Total Sent: " << socketConnection->getTotalSent();
178 VLOG(2) << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent();
179 VLOG(2) << " Total Read: " << socketConnection->getTotalRead();
180 VLOG(2) << " Total Processed: " << socketConnection->getTotalProcessed();
181 VLOG(2) << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed();
182 });
183
184 return webApp;
185 }
static express::Router getRouter()
Definition servers.h:68
express::tls::NET::WebApp WebApp
Definition servers.h:93

References getRouter().

Here is the call graph for this function: