Commit 356a4a39 authored by jan.koester's avatar jan.koester
Browse files

test

parent 1c7f51ac
Loading
Loading
Loading
Loading
+4 −0
Changes for src/socket.h: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -558,6 +558,10 @@ namespace netplus {
		std::string _requested_hostname;  // Hostname from client SNI extension
		CertificateBundle* _selected_cert_bundle = nullptr;  // Pointer to selected bundle from map

		// --- ALPN (Application-Layer Protocol Negotiation) Support ---
		std::string _client_alpn_protocols;  // Client's offered ALPN protocols (comma-separated or raw)
		std::string _selected_alpn;  // Server's selected ALPN protocol (e.g., "h2")

		std::unique_ptr<netplus::aes> _aes = nullptr;
		std::unique_ptr<netplus::aes> _aes_recv = nullptr;

+39 −0
Changes for src/ssl.cpp: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2046,6 +2046,45 @@ void netplus::ssl::handshake_after_accept(){
                    }
                }

                // ALPN (Application-Layer Protocol Negotiation)
                if (et == 0x0010 && el >= 2) {
                    // ALPN extension format:
                    // - 2 bytes: list length
                    // - For each protocol: 1 byte length + protocol string
                    size_t ap = ep;
                    uint16_t alpn_list_len = (uint16_t(ch[ap]) << 8) | ch[ap+1];
                    ap += 2;

                    if (2 + alpn_list_len != el)
                        throwSSL(NetException::Error, "ALPN listLen mismatch");

                    size_t aend = ap + alpn_list_len;
                    _selected_alpn.clear();

                    // Parse ALPN list and prefer h2, then http/1.1
                    while (ap < aend && ap + 1 <= aend) {
                        uint8_t plen = ch[ap];
                        ap += 1;

                        if (ap + plen > aend)
                            throwSSL(NetException::Error, "ALPN protocol truncated");

                        std::string protocol(ch.begin() + ap, ch.begin() + ap + plen);
                        ap += plen;

                        // Prefer h2 (HTTP/2) over others
                        if (protocol == "h2" && _selected_alpn.empty()) {
                            _selected_alpn = protocol;
                            std::cerr << "[SSL] Selected ALPN: " << protocol << std::endl;
                            break;  // h2 is preferred, stop searching
                        }
                        // Otherwise accept http/1.1 or h2c if no h2 found yet
                        else if (_selected_alpn.empty() && (protocol == "http/1.1" || protocol == "http/1.0")) {
                            _selected_alpn = protocol;
                            std::cerr << "[SSL] Fallback ALPN: " << protocol << std::endl;
                        }
                    }
                }


                ep += el;