协议介绍
ALPN (Application Layer Protocol Negotiation)是TLS的扩展,允许在安全连接的基础上进行应用层协议的协商。ALPN支持任意应用层协议的协商,目前应用最多是HTTP2的协商。在2016年,ALPN已经完全替代NPN了。
ALPN allows the application layer to negotiate which protocol to use over the secure connection. Any protocol can be negotiated by ALPN within a TLS connection. The protocols that are most commonly negotiated are HTTP/2 (for browsers that support it) and, historically, SPDY. The ALPN implementation is therefore not HTTP/2 or SPDY specific in any way.
协商原理
在TLS的Say Hello阶段增加应用层协议的协商,如下图所示:
ALPN实现
实现一:Jetty
Jetty以独立JAR包形式提供了ALPN实现,但是需要依赖OpenJDK 7或者OpenJDK 8,具体配置和API使用请参考这里。
实现二:OpenSSL
需要将版本升级到1.0.2 以上,具体查看这里。
参考: