long asn1_generalizedtime_to_epoch(ASN1_GENERALIZEDTIME *d);
const char *x509_get_notbefore(X509 *cert);
const char *x509_get_notafter(X509 *cert);
-int alpn_remove_token(char *alpn, int *len, const struct ist token);
+int alpn_remove_token(char *alpn, int *len, const struct ist token, int prefix);
#ifdef HAVE_ASN1_TIME_TO_TM
time_t ASN1_to_time_t(ASN1_TIME *asn1_time);
time_t x509_get_notafter_time_t(X509 *cert);
if (ret)
memprintf(err, "'%s' : %s", args[cur_arg], *err);
else if (global.tune.options2 & GTUNE2_DISABLE_H2_FE)
- alpn_remove_token(conf->alpn_str, &conf->alpn_len, ist("h2"));
+ alpn_remove_token(conf->alpn_str, &conf->alpn_len, ist("h2"), 0);
return ret;
#else
memprintf(err, "'%s' : library does not support TLS ALPN extension", args[cur_arg]);
#endif /* TLSEXT_TYPE_application_layer_protocol_negotiation */
if ((global.tune.options2 & GTUNE2_DISABLE_H2_FE) && px->mode == PR_MODE_HTTP && bind_conf->ssl_conf.alpn_str)
- alpn_remove_token(bind_conf->ssl_conf.alpn_str, &bind_conf->ssl_conf.alpn_len, ist("h2"));
+ alpn_remove_token(bind_conf->ssl_conf.alpn_str, &bind_conf->ssl_conf.alpn_len, ist("h2"), 0);
if (px->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
#ifdef OPENSSL_NPN_NEGOTIATED
/* Removes all occurrences of protocol <token> from the ALPN string <alpn>
* whose length is <*len>, in the binary format produced by
- * ssl_sock_parse_alpn() (each name preceded by its length byte). The string
- * is modified in place, remains zero-terminated and <*len> is updated. It may
- * end up empty, which is then equivalent to "no-alpn". Returns the number of
- * entries removed.
+ * ssl_sock_parse_alpn() (each name preceded by its length byte).
+ *
+ * If <prefix> is true, all tokens which begin with the searched value are
+ * considered as matching.
+ *
+ * The string is modified in place, remains zero-terminated and <*len> is
+ * updated. It may end up empty, which is then equivalent to "no-alpn".
+ *
+ * Returns the number of entries removed.
*/
-int alpn_remove_token(char *alpn, int *len, const struct ist token)
+int alpn_remove_token(char *alpn, int *len, const struct ist token, int prefix)
{
int pos = 0, removed = 0;
int next;
if (next > *len)
break;
- if ((uchar)alpn[pos] == istlen(token) &&
+ if (((uchar)alpn[pos] == istlen(token) ||
+ (prefix && (uchar)alpn[pos] > istlen(token))) &&
memcmp(alpn + pos + 1, istptr(token), istlen(token)) == 0) {
memmove(alpn + pos, alpn + next, *len - next);
*len -= next - pos;