gtls: make it possible to enable ALPN/NPN without HTTP2
This commit is contained in:
committed by
Daniel Stenberg
parent
2e9494b15d
commit
870a67e01f
@@ -90,12 +90,9 @@ static bool gtls_inited = FALSE;
|
|||||||
# define GNUTLS_MAPS_WINSOCK_ERRORS 1
|
# define GNUTLS_MAPS_WINSOCK_ERRORS 1
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifdef USE_NGHTTP2
|
|
||||||
# undef HAS_ALPN
|
|
||||||
# if (GNUTLS_VERSION_NUMBER >= 0x030200)
|
# if (GNUTLS_VERSION_NUMBER >= 0x030200)
|
||||||
# define HAS_ALPN
|
# define HAS_ALPN
|
||||||
# endif
|
# endif
|
||||||
# endif
|
|
||||||
|
|
||||||
# if (GNUTLS_VERSION_NUMBER >= 0x03020d)
|
# if (GNUTLS_VERSION_NUMBER >= 0x03020d)
|
||||||
# define HAS_OCSP
|
# define HAS_OCSP
|
||||||
@@ -398,10 +395,6 @@ gtls_connect_step1(struct connectdata *conn,
|
|||||||
const char* prioritylist;
|
const char* prioritylist;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAS_ALPN
|
|
||||||
int protocols_size = 2;
|
|
||||||
gnutls_datum_t protocols[2];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(conn->ssl[sockindex].state == ssl_connection_complete)
|
if(conn->ssl[sockindex].state == ssl_connection_complete)
|
||||||
/* to make us tolerant against being called more than once for the
|
/* to make us tolerant against being called more than once for the
|
||||||
@@ -615,20 +608,25 @@ gtls_connect_step1(struct connectdata *conn,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_ALPN
|
#ifdef HAS_ALPN
|
||||||
if(data->set.httpversion == CURL_HTTP_VERSION_2_0) {
|
|
||||||
if(data->set.ssl_enable_alpn) {
|
if(data->set.ssl_enable_alpn) {
|
||||||
protocols[0].data = NGHTTP2_PROTO_VERSION_ID;
|
int cur = 0;
|
||||||
protocols[0].size = NGHTTP2_PROTO_VERSION_ID_LEN;
|
gnutls_datum_t protocols[2];
|
||||||
protocols[1].data = ALPN_HTTP_1_1;
|
|
||||||
protocols[1].size = ALPN_HTTP_1_1_LENGTH;
|
#ifdef USE_NGHTTP2
|
||||||
gnutls_alpn_set_protocols(session, protocols, protocols_size, 0);
|
if(data->set.httpversion == CURL_HTTP_VERSION_2_0) {
|
||||||
infof(data, "ALPN, offering %s, %s\n", NGHTTP2_PROTO_VERSION_ID,
|
protocols[cur].data = NGHTTP2_PROTO_VERSION_ID;
|
||||||
ALPN_HTTP_1_1);
|
protocols[cur].size = NGHTTP2_PROTO_VERSION_ID_LEN;
|
||||||
conn->ssl[sockindex].asked_for_h2 = TRUE;
|
cur++;
|
||||||
}
|
infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID);
|
||||||
else {
|
|
||||||
infof(data, "SSL, can't negotiate HTTP/2.0 without ALPN\n");
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protocols[cur].data = ALPN_HTTP_1_1;
|
||||||
|
protocols[cur].size = ALPN_HTTP_1_1_LENGTH;
|
||||||
|
cur++;
|
||||||
|
infof(data, "ALPN, offering %s\n", ALPN_HTTP_1_1);
|
||||||
|
|
||||||
|
gnutls_alpn_set_protocols(session, protocols, cur, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1071,20 +1069,22 @@ gtls_connect_step3(struct connectdata *conn,
|
|||||||
infof(data, "ALPN, server accepted to use %.*s\n", proto.size,
|
infof(data, "ALPN, server accepted to use %.*s\n", proto.size,
|
||||||
proto.data);
|
proto.data);
|
||||||
|
|
||||||
|
#ifdef USE_NGHTTP2
|
||||||
if(proto.size == NGHTTP2_PROTO_VERSION_ID_LEN &&
|
if(proto.size == NGHTTP2_PROTO_VERSION_ID_LEN &&
|
||||||
memcmp(NGHTTP2_PROTO_VERSION_ID, proto.data,
|
!memcmp(NGHTTP2_PROTO_VERSION_ID, proto.data,
|
||||||
NGHTTP2_PROTO_VERSION_ID_LEN) == 0) {
|
NGHTTP2_PROTO_VERSION_ID_LEN)) {
|
||||||
conn->negnpn = NPN_HTTP2;
|
conn->negnpn = NPN_HTTP2;
|
||||||
}
|
}
|
||||||
else if(proto.size == ALPN_HTTP_1_1_LENGTH && memcmp(ALPN_HTTP_1_1,
|
else
|
||||||
proto.data, ALPN_HTTP_1_1_LENGTH) == 0) {
|
#endif
|
||||||
|
if(proto.size == ALPN_HTTP_1_1_LENGTH &&
|
||||||
|
!memcmp(ALPN_HTTP_1_1, proto.data, ALPN_HTTP_1_1_LENGTH)) {
|
||||||
conn->negnpn = NPN_HTTP1_1;
|
conn->negnpn = NPN_HTTP1_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(conn->ssl[sockindex].asked_for_h2) {
|
else
|
||||||
infof(data, "ALPN, server did not agree to a protocol\n");
|
infof(data, "ALPN, server did not agree to a protocol\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
conn->ssl[sockindex].state = ssl_connection_complete;
|
conn->ssl[sockindex].state = ssl_connection_complete;
|
||||||
|
|||||||
Reference in New Issue
Block a user