You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2014/02/12 02:02:08 UTC
[1/4] git commit: TS-2239: support the ALPN TLS extension
Updated Branches:
refs/heads/master da9a84da8 -> 5deb1b5a9
TS-2239: support the ALPN TLS extension
Add support the for TLS Application Layer Protocol Negotiation
extension. This uses the same infrastructure as NPN, so a consistent
protocol advertisement is created. Any plugin that registers to
accept a named protocol will automatically gain NPN and ALPN support.
This requires a very recent OpenSSL, probably 1.2 or something like
that.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/9225250f
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/9225250f
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/9225250f
Branch: refs/heads/master
Commit: 9225250fa19a87082643b1d0f12f25e7adfd0da3
Parents: a49330c
Author: James Peach <jp...@apache.org>
Authored: Mon Feb 10 16:46:05 2014 -0800
Committer: James Peach <jp...@apache.org>
Committed: Tue Feb 11 16:35:13 2014 -0800
----------------------------------------------------------------------
iocore/net/P_SSLNetVConnection.h | 3 +-
iocore/net/SSLNetVConnection.cc | 60 ++++++++++++++++++++++++++++++----
iocore/net/SSLUtils.cc | 11 +++++++
proxy/http/HttpProxyServerMain.cc | 4 ++-
4 files changed, 69 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9225250f/iocore/net/P_SSLNetVConnection.h
----------------------------------------------------------------------
diff --git a/iocore/net/P_SSLNetVConnection.h b/iocore/net/P_SSLNetVConnection.h
index e4734b2..fcb0e8c 100644
--- a/iocore/net/P_SSLNetVConnection.h
+++ b/iocore/net/P_SSLNetVConnection.h
@@ -104,7 +104,8 @@ public:
X509 *client_cert;
X509 *server_cert;
- static int advertise_next_protocol(SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg);
+ static int advertise_next_protocol(SSL * ssl, const unsigned char ** out, unsigned * outlen, void *);
+ static int select_next_protocol(SSL * ssl, const unsigned char ** out, unsigned char * outlen, const unsigned char * in, unsigned inlen, void *);
Continuation * endpoint() const {
return npnEndpoint;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9225250f/iocore/net/SSLNetVConnection.cc
----------------------------------------------------------------------
diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc
index b04de64..00e7fa0 100644
--- a/iocore/net/SSLNetVConnection.cc
+++ b/iocore/net/SSLNetVConnection.cc
@@ -545,23 +545,38 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err)
}
sslHandShakeComplete = 1;
-#if TS_USE_TLS_NPN
{
const unsigned char * proto = NULL;
unsigned len = 0;
- SSL_get0_next_proto_negotiated(ssl, &proto, &len);
+ // If it's possible to negotiate both NPN and ALPN, then ALPN
+ // is preferred since it is the server's preference. The server
+ // preference would not be meaningful if we let the client
+ // preference have priority.
+
+#if TS_USE_TLS_ALPN
+ SSL_get0_alpn_selected(ssl, &proto, &len);
+#endif /* TS_USE_TLS_ALPN */
+
+#if TS_USE_TLS_NPN
+ if (len == 0) {
+ SSL_get0_next_proto_negotiated(ssl, &proto, &len);
+ }
+#endif /* TS_USE_TLS_NPN */
+
if (len) {
- if (this->npnSet) {
- this->npnEndpoint = this->npnSet->findEndpoint(proto, len);
- this->npnSet = NULL;
- }
+ // If there's no NPN set, we should not have done this negotiation.
+ ink_assert(this->npnSet != NULL);
+
+ this->npnEndpoint = this->npnSet->findEndpoint(proto, len);
+ this->npnSet = NULL;
+
+ ink_assert(this->npnEndpoint != NULL);
Debug("ssl", "client selected next protocol %.*s", len, proto);
} else {
Debug("ssl", "client did not select a next protocol");
}
}
-#endif /* TS_USE_TLS_NPN */
return EVENT_DONE;
@@ -661,6 +676,9 @@ SSLNetVConnection::registerNextProtocolSet(const SSLNextProtocolSet * s)
this->npnSet = s;
}
+// NextProtocolNegotiation TLS extension callback. The NPN extension
+// allows the client to select a preferred protocol, so all we have
+// to do here is tell them what out protocol set is.
int
SSLNetVConnection::advertise_next_protocol(SSL *ssl, const unsigned char **out, unsigned int *outlen,
void * /*arg ATS_UNUSED */)
@@ -676,3 +694,31 @@ SSLNetVConnection::advertise_next_protocol(SSL *ssl, const unsigned char **out,
return SSL_TLSEXT_ERR_NOACK;
}
+
+// ALPN TLS extension callback. Given the client's set of offered
+// protocols, we have to select a protocol to use for this session.
+int
+SSLNetVConnection::select_next_protocol(SSL * ssl, const unsigned char ** out, unsigned char * outlen, const unsigned char * in, unsigned inlen, void *)
+{
+ SSLNetVConnection * netvc = (SSLNetVConnection *)SSL_get_app_data(ssl);
+ const unsigned char * npn = NULL;
+ unsigned npnsz = 0;
+
+ ink_release_assert(netvc != NULL);
+
+ if (netvc->npnSet && netvc->npnSet->advertiseProtocols(&npn, &npnsz)) {
+ // SSL_select_next_proto chooses the first server-offered protocol that appears in the clients protocol set, ie. the
+ // server selects the protocol. This is a n^2 search, so it's preferable to keep the protocol set short.
+
+#if HAVE_SSL_SELECT_NEXT_PROTO
+ if (SSL_select_next_proto((unsigned char **)out, outlen, npn, npnsz, in, inlen) == OPENSSL_NPN_NEGOTIATED) {
+ Debug("ssl", "selected ALPN protocol %.*s", (int)(*outlen), *out);
+ return SSL_TLSEXT_ERR_OK;
+ }
+#endif /* HAVE_SSL_SELECT_NEXT_PROTO */
+ }
+
+ *out = NULL;
+ *outlen = 0;
+ return SSL_TLSEXT_ERR_NOACK;
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9225250f/iocore/net/SSLUtils.cc
----------------------------------------------------------------------
diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc
index 4b1b646..474f456 100644
--- a/iocore/net/SSLUtils.cc
+++ b/iocore/net/SSLUtils.cc
@@ -718,6 +718,10 @@ ssl_store_ssl_context(
SSL_CTX_set_next_protos_advertised_cb(ctx, SSLNetVConnection::advertise_next_protocol, NULL);
#endif /* TS_USE_TLS_NPN */
+#if TS_USE_TLS_ALPN
+ SSL_CTX_set_alpn_select_cb(ctx, SSLNetVConnection::select_next_protocol, NULL);
+#endif /* TS_USE_TLS_ALPN */
+
certpath = Layout::relative_to(params->serverCertPathOnly, cert);
// Index this certificate by the specified IP(v6) address. If the address is "*", make it the default context.
@@ -896,6 +900,13 @@ SSLParseCertificateConfiguration(
// context.
if (lookup->ssl_default == NULL) {
lookup->ssl_default = ssl_context_enable_sni(SSLDefaultServerContext(), lookup);
+
+ // The ALPN negotiation happens before certificate selection, so we need to install the ALPN callback
+ // on the default SSL context.
+#if TS_USE_TLS_ALPN
+ SSL_CTX_set_alpn_select_cb(lookup->ssl_default, SSLNetVConnection::select_next_protocol, NULL);
+#endif /* TS_USE_TLS_ALPN */
+
lookup->insert(lookup->ssl_default, "*");
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9225250f/proxy/http/HttpProxyServerMain.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpProxyServerMain.cc b/proxy/http/HttpProxyServerMain.cc
index 7c9b49d..662856a 100644
--- a/proxy/http/HttpProxyServerMain.cc
+++ b/proxy/http/HttpProxyServerMain.cc
@@ -163,8 +163,10 @@ MakeHttpProxyAcceptor(HttpProxyAcceptor& acceptor, HttpProxyPort& port, unsigned
if (port.isSSL()) {
HttpAccept * accept = NEW(new HttpAccept(accept_opt));
SSLNextProtocolAccept * ssl = NEW(new SSLNextProtocolAccept(accept));
- ssl->registerEndpoint(TS_NPN_PROTOCOL_HTTP_1_0, accept);
+
+ // ALPN selects the first server-offered protocol, so make sure that we offer HTTP/1.1 first.
ssl->registerEndpoint(TS_NPN_PROTOCOL_HTTP_1_1, accept);
+ ssl->registerEndpoint(TS_NPN_PROTOCOL_HTTP_1_0, accept);
ink_scoped_mutex lock(ssl_plugin_mutex);
ssl_plugin_acceptors.push(ssl);
[3/4] git commit: TS-2239: use full TLS extension names in the
configure log
Posted by jp...@apache.org.
TS-2239: use full TLS extension names in the configure log
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/777bff37
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/777bff37
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/777bff37
Branch: refs/heads/master
Commit: 777bff373fe2c22f86ab8ab85616391c25d70651
Parents: 9225250
Author: James Peach <jp...@apache.org>
Authored: Tue Feb 11 08:22:43 2014 -0800
Committer: James Peach <jp...@apache.org>
Committed: Tue Feb 11 16:36:02 2014 -0800
----------------------------------------------------------------------
build/crypto.m4 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/777bff37/build/crypto.m4
----------------------------------------------------------------------
diff --git a/build/crypto.m4 b/build/crypto.m4
index 2c37163..f8ad19f 100644
--- a/build/crypto.m4
+++ b/build/crypto.m4
@@ -62,7 +62,7 @@ AC_DEFUN([TS_CHECK_CRYPTO_NEXTPROTONEG], [
)
LIBS=$_npn_saved_LIBS
- AC_MSG_CHECKING(whether to enable NextProtocolNegotiation TLS extension support)
+ AC_MSG_CHECKING(whether to enable Next Protocol Negotiation TLS extension support)
AC_MSG_RESULT([$enable_tls_npn])
TS_ARG_ENABLE_VAR([use], [tls-npn])
AC_SUBST(use_tls_npn)
@@ -77,7 +77,7 @@ AC_DEFUN([TS_CHECK_CRYPTO_ALPN], [
)
LIBS=$_alpn_saved_LIBS
- AC_MSG_CHECKING(whether to enable ALPN TLS extension support)
+ AC_MSG_CHECKING(whether to enable Application Layer Protocol Negotiation TLS extension support)
AC_MSG_RESULT([$enable_tls_alpn])
TS_ARG_ENABLE_VAR([use], [tls-alpn])
AC_SUBST(use_tls_alpn)
[2/4] git commit: TS-2239: detect OpenSSL ALPN support
Posted by jp...@apache.org.
TS-2239: detect OpenSSL ALPN support
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/a49330c1
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/a49330c1
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/a49330c1
Branch: refs/heads/master
Commit: a49330c1b2c3628be9ff5aca3fd20522146ec1d9
Parents: da9a84d
Author: James Peach <jp...@apache.org>
Authored: Sat Feb 8 21:17:24 2014 -0800
Committer: James Peach <jp...@apache.org>
Committed: Tue Feb 11 16:35:13 2014 -0800
----------------------------------------------------------------------
build/crypto.m4 | 15 +++++++++++++++
configure.ac | 3 +++
lib/ts/ink_config.h.in | 1 +
3 files changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a49330c1/build/crypto.m4
----------------------------------------------------------------------
diff --git a/build/crypto.m4 b/build/crypto.m4
index 4c5f8eb..2c37163 100644
--- a/build/crypto.m4
+++ b/build/crypto.m4
@@ -68,6 +68,21 @@ AC_DEFUN([TS_CHECK_CRYPTO_NEXTPROTONEG], [
AC_SUBST(use_tls_npn)
])
+AC_DEFUN([TS_CHECK_CRYPTO_ALPN], [
+ enable_tls_alpn=yes
+ _alpn_saved_LIBS=$LIBS
+ TS_ADDTO(LIBS, [$OPENSSL_LIBS])
+ AC_CHECK_FUNCS(SSL_CTX_set_alpn_protos SSL_CTX_set_alpn_select_cb SSL_get0_alpn_selected SSL_select_next_proto,
+ [], [enable_tls_alpn=no]
+ )
+ LIBS=$_alpn_saved_LIBS
+
+ AC_MSG_CHECKING(whether to enable ALPN TLS extension support)
+ AC_MSG_RESULT([$enable_tls_alpn])
+ TS_ARG_ENABLE_VAR([use], [tls-alpn])
+ AC_SUBST(use_tls_alpn)
+])
+
AC_DEFUN([TS_CHECK_CRYPTO_SNI], [
_sni_saved_LIBS=$LIBS
enable_tls_sni=yes
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a49330c1/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 7be8bf7..db3996f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1145,6 +1145,9 @@ TS_CHECK_CRYPTO
TS_CHECK_CRYPTO_NEXTPROTONEG
#
+# Check for ALPN TLS extension support.
+TS_CHECK_CRYPTO_ALPN
+#
# Check for EC key support.
TS_CHECK_CRYPTO_EC_KEYS
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a49330c1/lib/ts/ink_config.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/ink_config.h.in b/lib/ts/ink_config.h.in
index 8268c5d..455ec93 100644
--- a/lib/ts/ink_config.h.in
+++ b/lib/ts/ink_config.h.in
@@ -66,6 +66,7 @@
#define TS_USE_FREELIST @use_freelist@
#define TS_USE_RECLAIMABLE_FREELIST @use_reclaimable_freelist@
#define TS_USE_TLS_NPN @use_tls_npn@
+#define TS_USE_TLS_ALPN @use_tls_alpn@
#define TS_USE_TLS_SNI @use_tls_sni@
#define TS_USE_TLS_ECKEY @use_tls_eckey@
#define TS_USE_LINUX_NATIVE_AIO @use_linux_native_aio@
[4/4] git commit: TS-2239: CHANGES
Posted by jp...@apache.org.
TS-2239: CHANGES
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/5deb1b5a
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/5deb1b5a
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/5deb1b5a
Branch: refs/heads/master
Commit: 5deb1b5a968c6318f9ded795538bf4f78ba80f8a
Parents: 777bff3
Author: James Peach <jp...@apache.org>
Authored: Tue Feb 11 16:35:53 2014 -0800
Committer: James Peach <jp...@apache.org>
Committed: Tue Feb 11 16:36:10 2014 -0800
----------------------------------------------------------------------
CHANGES | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5deb1b5a/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 8d42036..a39bc32 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
-*- coding: utf-8 -*-
Changes with Apache Traffic Server 5.0.0
+ *) [TS-2239] Initial ALPN TLS extension support.
+
*) [TS-2568] Better template messages.
*) [TS-2567] Add --install-test-tools configure option.