gtls: make it possible to enable ALPN/NPN without HTTP2

This commit is contained in:
Alessandro Ghedini
2015-02-19 16:22:07 +01:00
committed by Daniel Stenberg
parent 2e9494b15d
commit 870a67e01f

View File

@@ -90,11 +90,8 @@ static bool gtls_inited = FALSE;
# define GNUTLS_MAPS_WINSOCK_ERRORS 1 # define GNUTLS_MAPS_WINSOCK_ERRORS 1
# endif # endif
# ifdef USE_NGHTTP2 # if (GNUTLS_VERSION_NUMBER >= 0x030200)
# undef HAS_ALPN # define HAS_ALPN
# if (GNUTLS_VERSION_NUMBER >= 0x030200)
# define HAS_ALPN
# endif
# endif # endif
# if (GNUTLS_VERSION_NUMBER >= 0x03020d) # if (GNUTLS_VERSION_NUMBER >= 0x03020d)
@@ -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) { int cur = 0;
protocols[0].data = NGHTTP2_PROTO_VERSION_ID; gnutls_datum_t protocols[2];
protocols[0].size = NGHTTP2_PROTO_VERSION_ID_LEN;
protocols[1].data = ALPN_HTTP_1_1; #ifdef USE_NGHTTP2
protocols[1].size = ALPN_HTTP_1_1_LENGTH; if(data->set.httpversion == CURL_HTTP_VERSION_2_0) {
gnutls_alpn_set_protocols(session, protocols, protocols_size, 0); protocols[cur].data = NGHTTP2_PROTO_VERSION_ID;
infof(data, "ALPN, offering %s, %s\n", NGHTTP2_PROTO_VERSION_ID, protocols[cur].size = NGHTTP2_PROTO_VERSION_ID_LEN;
ALPN_HTTP_1_1); cur++;
conn->ssl[sockindex].asked_for_h2 = TRUE; 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,19 +1069,21 @@ 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