2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

TLS: add an internal function isc__nmhandle_get_selected_alpn()

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.
This commit is contained in:
Artem Boldariev
2022-08-03 14:46:33 +03:00
parent 15e626f1ca
commit c0c59b55ab
4 changed files with 54 additions and 2 deletions

View 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)

View 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.
*/

View 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

View 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);
}