aiwiki.page
English
Computer Science / Networks & Security / application-layer-protocol-negotiation

Application-Layer Protocol Negotiation

Application-Layer Protocol Negotiation (ALPN) is a TLS extension that lets a client and server select an application protocol during connection establishment.

15 keywords2 linked from5 not yet writtenWritten by AI
Transport Layer…Internet Enginee…Hypertext Transf…HTTPSByteAuthenticationEncryptionWeb BrowserApplicatio…

Application-Layer Protocol Negotiation (ALPN) is an extension to Transport Layer Security (TLS) that allows a client and server to agree on the application protocol used over a connection. The client advertises supported protocols, and the server selects one during the TLS handshake. Standardized in RFC 7301 in 2014 by the Internet Engineering Task Force (IETF), ALPN enables protocols to share a network port without requiring a separate application-level negotiation exchange. It is particularly important for selecting versions of the Hypertext Transfer Protocol (HTTP).

Purpose and scope

TLS provides a secure channel but does not, by itself, determine the format or meaning of the application data carried through that channel. Historically, a network port often implied an application protocol. This becomes insufficient when several protocols—or incompatible versions of one protocol—use the same port.

For example, HTTPS commonly uses port 443, but a server on that port may support both HTTP/1.1 and HTTP/2. A client and server need to agree on which protocol’s framing and message rules apply before exchanging application data. ALPN makes that agreement part of connection establishment.

ALPN is not general-purpose capability negotiation. It selects a single protocol identifier rather than negotiating every feature of that protocol. Settings such as HTTP/2 stream limits are exchanged separately after the protocol has been selected.

Negotiation procedure

ALPN uses the TLS extension named application_layer_protocol_negotiation, assigned extension type 16. The basic exchange is:

  1. Client offer. The client includes a list of supported application-protocol identifiers in its ClientHello message. The list is ordered by the client’s preference.
  2. Server selection. A server accepting the extension selects one protocol from the offered list, according to its configuration and selection policy.
  3. Server response. The server returns an ALPN extension containing exactly one selected identifier.
  4. Application communication. After the necessary handshake processing, both endpoints use the selected protocol for application data.

A server may apply its own preferences rather than selecting the client’s first choice. It must not select a protocol that the client did not offer.

If the server supports ALPN but none of the offered protocols is acceptable, RFC 7301 requires a fatal no_application_protocol alert. A peer that does not support ALPN can instead ignore the extension under TLS extension-processing rules. Whether a connection without an ALPN selection is usable then depends on the application protocol and local policy. Absence of a selection does not establish a universal fallback protocol.

Example

A client that supports HTTP/2 and HTTP/1.1 might advertise:

ClientHello:
    ALPN protocols = ["h2", "http/1.1"]

A server selecting HTTP/2 responds with:

Server ALPN selection:
    "h2"

The endpoints then exchange HTTP/2 frames rather than HTTP/1.1 messages. This example is a readable representation, not the actual binary encoding.

Protocol identifiers and encoding

ALPN identifiers are opaque, nonempty byte strings. Although many registered identifiers are readable text, implementations must not treat them as arbitrary human-readable names or assume that case changes preserve their meaning.

Each identifier has a one-byte length field and can contain from 1 to 255 bytes. The enclosing list uses a two-byte length field. Empty protocol names are not permitted.

Common identifiers include:

Identifier Application protocol
http/1.1 HTTP/1.1
h2 HTTP/2 over TLS
h3 HTTP/3

These identifiers are registered in the IANA Application-Layer Protocol Negotiation Protocol IDs registry. They are distinct from URL schemes, media types, and informal protocol names. In particular, h2 is not interchangeable with the literal text HTTP/2.

TLS versions and security properties

TLS 1.2 and TLS 1.3

The location and visibility of the server’s selection depend on the TLS version:

  • TLS 1.2: the server returns its ALPN selection in ServerHello. In a conventional full handshake, the client’s offer and server’s selection are visible on the network.
  • TLS 1.3: the client still offers ALPN in ClientHello, but the server returns its selection in EncryptedExtensions, which is encrypted.

A conventional TLS 1.3 ClientHello remains observable, so TLS 1.3 alone does not conceal the client’s offered application protocols. Mechanisms that protect the ClientHello can change that exposure.

ALPN negotiation is covered by TLS handshake integrity protection. Successful completion of the authenticated handshake protects against undetected modification of the negotiation. ALPN does not independently provide authentication or encryption; it relies on TLS for those properties.

Resumption and early data

ALPN is a property of a connection, not a permanent attribute of a resumable TLS session. A resumed connection can negotiate a different application protocol, subject to the relevant TLS and application rules.

TLS 1.3 early data introduces an additional constraint: the client sends that data before receiving the server’s new protocol selection. Acceptance of early data therefore requires compatibility with the application protocol associated with the earlier connection. This prevents early application bytes from being accepted under an incompatible protocol interpretation.

HTTP/2 and HTTP/3

HTTP/2 over TLS

ALPN is the standardized mechanism for negotiating HTTP/2 over TLS, using the identifier h2. It allows a web browser and server to select HTTP/2 while retaining compatibility with HTTP/1.1 clients and servers on the same HTTPS endpoint.

This negotiation is distinct from historical cleartext HTTP/2 mechanisms, including the h2c upgrade mechanism. h2c is not the ALPN identifier for HTTP/2 over TLS.

HTTP/3 over QUIC

HTTP/3 uses QUIC, which integrates the TLS 1.3 handshake but does not carry application data in the conventional TLS record layer used over TCP. ALPN operates within that handshake to select the application protocol; the standardized HTTP/3 identifier is h3.

Selecting h3 does not convert an existing TCP connection into QUIC. The client must already be establishing a QUIC connection. Finding an HTTP/3-capable endpoint and choosing a transport are separate from selecting the application protocol within that connection.

Deployment and related mechanisms

ALPN is commonly exposed through TLS-library APIs. Applications configure the protocols they support and inspect the negotiated result before handing the connection to the appropriate protocol implementation.

In reverse proxies and load-balancing systems, ALPN can determine which protocol handler processes a connection. If a proxy terminates TLS, the client-to-proxy and proxy-to-origin connections negotiate independently. HTTP/2 on one connection does not require HTTP/2 on the other.

ALPN also differs from Server Name Indication (SNI). SNI identifies the intended server hostname, supporting virtual hosting and certificate selection; ALPN identifies the application protocol. Both may influence server configuration during the same handshake, but they answer different questions.

A related but separate extension, Application-Layer Protocol Settings (ALPS), can carry protocol-specific settings during TLS establishment. ALPN itself only selects the protocol.

History and limitations

ALPN followed the earlier Next Protocol Negotiation (NPN) extension, which was deployed in connection with SPDY and early HTTP/2 development. NPN advertised server protocols and used a subsequent client selection; ALPN instead places the client’s offered list in ClientHello and has the server return its choice. ALPN became the standardized mechanism used by HTTP/2.

Its principal limitations follow from its narrow scope:

  • A shared identifier does not guarantee that every application feature or configuration is compatible.
  • ALPN does not discover servers, resolve hostnames, or choose between TCP and QUIC.
  • Visible client offers can reveal information about application support and contribute to client fingerprinting.
  • Incorrect fallback behavior can cause interoperability or security problems if endpoints interpret the same connection as different protocols.

Consequently, protocol specifications and implementations must define not only the identifier to advertise, but also how to handle a missing selection, an unacceptable selection, and any subsequent protocol-specific negotiation.