]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
TLS: add an internal function isc__nmhandle_get_selected_alpn()
authorArtem Boldariev <artem@boldariev.com>
Wed, 3 Aug 2022 11:46:33 +0000 (14:46 +0300)
committerArtem Boldariev <artem@boldariev.com>
Tue, 20 Dec 2022 19:24:44 +0000 (21:24 +0200)
The added function provides the interface for getting an ALPN tag
negotiated during TLS connection establishment.

The new function can be used by higher level transports.

lib/isc/netmgr/http.c
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tlsstream.c

index 7cb69b5f97ee609d352afb596e651b75584e4047..962a5b4386c6cbca04cace5f772e1659c2575d9b 100644 (file)
@@ -1399,8 +1399,7 @@ transport_connect_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
 
                INSIST(transp_sock->type == isc_nm_tlssocket);
 
-               isc_tls_get_selected_alpn(transp_sock->tlsstream.tls, &alpn,
-                                         &alpnlen);
+               isc__nmhandle_get_selected_alpn(handle, &alpn, &alpnlen);
                if (alpn == NULL || alpnlen != NGHTTP2_PROTO_VERSION_ID_LEN ||
                    memcmp(NGHTTP2_PROTO_VERSION_ID, alpn,
                           NGHTTP2_PROTO_VERSION_ID_LEN) != 0)
index 274aec9a688c2f5fb568b265fd4d5dd9c0c8e609..fe99e3a1253284b2cbdc024d3332d2f3ae7bd6dc 100644 (file)
@@ -1603,6 +1603,11 @@ void
 isc__nm_tls_failed_read_cb(isc_nmsocket_t *sock, isc_result_t result,
                           bool async);
 
+void
+isc__nmhandle_tls_get_selected_alpn(isc_nmhandle_t *handle,
+                                   const unsigned char **alpn,
+                                   unsigned int *alpnlen);
+
 void
 isc__nm_http_stoplistening(isc_nmsocket_t *sock);
 
@@ -2022,3 +2027,15 @@ isc__nmhandle_set_manual_timer(isc_nmhandle_t *handle, const bool manual);
  * Set manual read timer control mode - so that it will not get reset
  * automatically on read nor get started when read is initiated.
  */
+
+void
+isc__nmhandle_get_selected_alpn(isc_nmhandle_t *handle,
+                               const unsigned char **alpn,
+                               unsigned int *alpnlen);
+/*
+ * Returns a non zero terminated ALPN identifier via 'alpn'. The
+ * length of the identifier is returned via 'alpnlen'. If after the
+ * call either 'alpn == NULL' or 'alpnlen == 0', then identifier was
+ * not negotiated of the underlying protocol of the connection
+ * represented via the given handle does not support ALPN.
+ */
index 4c3c3107f367d6fdcae578b545711d9c4f11f44f..bca6f3c76bf04ac3c78f76676da3b87df74b28f9 100644 (file)
@@ -2922,6 +2922,27 @@ isc__nmhandle_set_manual_timer(isc_nmhandle_t *handle, const bool manual) {
        UNREACHABLE();
 }
 
+void
+isc__nmhandle_get_selected_alpn(isc_nmhandle_t *handle,
+                               const unsigned char **alpn,
+                               unsigned int *alpnlen) {
+       isc_nmsocket_t *sock;
+
+       REQUIRE(VALID_NMHANDLE(handle));
+       sock = handle->sock;
+       REQUIRE(VALID_NMSOCK(sock));
+
+       switch (sock->type) {
+#if HAVE_LIBNGHTTP2
+       case isc_nm_tlssocket:
+               isc__nmhandle_tls_get_selected_alpn(handle, alpn, alpnlen);
+               return;
+#endif /* HAVE_LIBNGHTTP2 */
+       default:
+               break;
+       };
+}
+
 #ifdef NETMGR_TRACE
 /*
  * Dump all active sockets in netmgr. We output to stderr
index e99b03b4bb53051e4a67cc706226fb282ac72833..834a386ce6b8b0396085b4e496684f6a7c352c4d 100644 (file)
@@ -1402,3 +1402,18 @@ isc__nmhandle_tls_set_manual_timer(isc_nmhandle_t *handle, const bool manual) {
 
        sock->manual_read_timer = manual;
 }
+
+void
+isc__nmhandle_tls_get_selected_alpn(isc_nmhandle_t *handle,
+                                   const unsigned char **alpn,
+                                   unsigned int *alpnlen) {
+       isc_nmsocket_t *sock;
+
+       REQUIRE(VALID_NMHANDLE(handle));
+       sock = handle->sock;
+       REQUIRE(VALID_NMSOCK(sock));
+       REQUIRE(sock->type == isc_nm_tlssocket);
+       REQUIRE(sock->tid == isc_tid());
+
+       isc_tls_get_selected_alpn(sock->tlsstream.tls, alpn, alpnlen);
+}