This is only needed to fail early during the handshake, if protocol
negotiation doesn't succeed. With older GnuTLS, if there's a protocol
mismatch, the data won't be understood and the connection will close
later on.
Mandatory ALPN doesn't affect clients that don't use the ALPN extension.
proto.data = (unsigned char *)"h2";
proto.size = 2;
}
- ret = gnutls_alpn_set_protocols(ctx->c.tls_session, &proto, 1, GNUTLS_ALPN_MANDATORY);
+ unsigned int flags = 0;
+#if GNUTLS_VERSION_NUMBER >= 0x030500
+ /* Mandatory ALPN means the protocol must match if and
+ * only if ALPN extension is used by the client. */
+ flags |= GNUTLS_ALPN_MANDATORY;
+#endif
+ ret = gnutls_alpn_set_protocols(ctx->c.tls_session, &proto, 1, flags);
if (ret != GNUTLS_E_SUCCESS) {
session_close(s);
return;