8.1.2 What is ALPN and why is it needed

TheHost HTTP2 Banner

ALPN (abbreviated Application-Layer Protocol Negotiation) is an extension of Transport Layer Security (TLS) that allows the application network layer to negotiate which protocol should be used over a secure connection, thus avoiding additional two-way requests. At the same time, ALPN is independent of other application layer protocols.

ALPN was described in RFC 7301 and is a direct evolution of NPN (Next Protocol Negotiation) developed by Google for use in their experimental SPDY protocol.

In practice, ALPN is primarily needed for secure connections via the HTTP/2 protocol, which improves the compression of web pages and reduces their latency compared with the previous generation HTTP/1.1 and HTTP/1.0. Without a library that supports ALPN on the server, work via the HTTP/2 protocol is impossible.

Details: how ALPN works in practice

At the beginning of the process of establishing a secure connection between the client and the server, a TLS Handshake process occurs. During this process, the client and server agree on encryption, authentication, and other security settings.

The first step in TLS Handshake is to send a ClientHello message from the client to the server. ClientHello includes a list of supported application layer protocols, including those supported by ALPN. The server responds with a ServerHello message, which contains the selected connection parameters, including application layer protocols.

If the server and client support ALPN, the client includes an ALPN extension in the ClientHello listing the supported application layer protocols, such as HTTP/1.1, HTTP/2, etc. The server can either select one of the proposed protocols, or select an alternative protocol.

The server analyzes the application layer protocols proposed by the client and selects the most suitable protocol. He can choose the protocol that is most efficiently supported by the server and client, for example, HTTP/2 instead of HTTP/1.1, which will improve the speed and performance of the connection.

After selecting an application layer protocol, the server sends a ServerHello message with the selected protocol. The TLS Handshake process then completes and the client and server can begin communicating over the selected application layer protocol.

ALPN is supported since TLS 1.2. For earlier versions of TLS, NPN is used.

Currently, ALPN support is implemented by the following libraries:

  • OpenSSL from version 1.0.2
  • GnuTLS since version 3.2.0,
  • MatrixSSL: since version 3.7.1
  • Network Security Services: from version 3.15.5,
  • LibreSSL: since version 2.1.3,
  • mbedTLS/PolarSSL: since version 1.3.6
  • s2n: all versions
  • wolfSSL/CyaSSL: since version 3.7.0
  • BearSSL: since version 0.3
  • Win32 SSPI: starting with Windows 8.1 / Windows Server 2012 R2
  • SChannel: running Windows 8.1 / Windows Server 2012 R2