Formal Verification of The Wireguard Protocol: 1 Background
Formal Verification of The Wireguard Protocol: 1 Background
www.wireguard.com
Abstract
WireGuard, the secure network tunnel, uses an interesting Diffie-
Hellman authenticated key exchange protocol based on NoiseIK, custom
tailored to suit its unique operational requirements. This paper enumerates
the security properties of this key exchange and then explores the formal
verification of such properties. The end result is a formally verified secure
network tunnel protocol.
1 Background
WireGuard is a secure network tunnel for transporting layer 3 packets, for some
definition of secure. This paper endeavors to determine exactly what that is, and
formally verify it as such. The WireGuard protocol is extensively detailed in [2],
which itself is based on the NoiseIK [3] handshake. The WireGuard protocol
consists of several mechanisms: an authenticated key exchange, a cookie MAC
system for mitigating denial of service attacks, an elegant timer state machine for
concealing state to system administrators, and several desirable design decisions
from an implementation security perspective. Notably, WireGuard aims to be
silent in the face of unauthenticated packets (“stealthiness”), avoid dynamic
memory allocation, only adjust state based on authenticated data in order to
maintain fixed size memory allocations, avoid parsers, not require any long
term storage, allow initiator and responder to swap roles, and have the state
machine handle all transitions automatically. These design requirements lead to
an interesting authenticated key exchange, around which the other aspects of
the protocol revolve.
Permanent ID of this document: d376f649d7f4b68f616e05e5f64d660e9b23d7af. Static link:
wireguard.com/papers/wireguard-formal-verification.pdf. Date: June 7, 2018. This is draft
revision b956944. Copyright © 2017 Jason A. Donenfeld & Kevin Milner. All Rights Reserved.
1
2 Key Exchange Review
While the WireGuard key exchange is extensively discussed in [2], we briefly
review the overall structure and import several variables and conventions. Leaving
aside the cookie MAC system, WireGuard consists of a 1-RTT handshake—from
initiator to responder, and responder back to initiator—after which the initiator
can then begin an exchange of transport data, depicted in figure 1. This initial
exchange of transport data from the initiator provides key confirmation, and
after, either initiator or responder may send transport data. Transport data is
encrypted using an AEAD, with a pair of symmetric keys, one for sending and
one for receiving, derived from the preceding two handshake messages, which
are referred to as the “session keys”, existing within a “session”.
Initiator—i Responder—r
Handshake Initiation
Handshake Response
Transport Data
Transport Data
The initiator, i, and the responder, r, both keep several values secret. They
each have a static long-term key, Si and Sr , as well as a random session ephemeral
key, Ei and Er . They may optionally also share a pre-shared symmetric key, Q;
when Q is in use, WireGuard is using what we call “pre-shared key mode“, and
otherwise WireGuard is using “normal mode“, and Q is considered to be 032 ,
the all zero 256-bit string. The initiator and responder exchange messages and
keep track of a shared secret, C.
3 Properties
We enumerate properties first in the case Si , Sr , Ei , and Er (and potentially Q)
are kept secret. Then we explore which properties still remain when one or more
of these secret values are compromised by an attacker. An attacker is posited to
be in an active man-in-the-middle position. As pre-shared key mode is meant
to merely augment the security properties, in the face of a quantum attacker
2
or possibly other circumstances, the security properties described herein first
discuss what is provided by normal mode, and then subsequently approach the
additional properties afforded by pre-shared key mode.
3
3.2 Key Secrecy
When there is key agreement, there is also key secrecy, when the resultant session
keys are only known the initiator and responder, and not to the attacker.
4
3.4 Identity Hiding
Sr is never transmitted in any form; it is secret from an attacker. Si is transmitted,
but encrypted; it is secret from an attacker.
5
from the world state at the timepoint they are used to execute a rule. This allows
us to efficiently model read-only memory or causal constraints using persistent
facts, and also allows us to represent linear constraints like non-monotonic agent
state, limited resources, and control flow.
Rules are labeled with actions, such that the execution of a rule at some time
point associates some action with that time point. Actions do not influence rule
execution directly, but instead incrementally construct a trace which represents
a sort of record of rule execution. When we prove that a protocol model has
some property, we reference these actions and are proving a property of the set
of all traces which can be generated by the protocol model.
Finally, there are a few special facts in Tamarin, to model the generation of
fresh terms (e.g. from a PRNG) and to interact with the network. The Fr(x)
fact can be used in the premises of a rule to model generating a fresh term x.
In( . . . ) and Out( . . . ) can be used in the premises and conclusions respectively
to model receiving from or sending to the adversary-controlled network.
decrypt(encrypt(m, k), k) = m,
even though the terms m and decrypt(encrypt(m, k), k) are not syntactically
identical. Tamarin includes built in definitions for a number of different crypto-
graphic primitives, and additional formulae and equations can be defined easily.
Notably, Tamarin includes support for a Diffie-Hellman equational theory, allow-
ing symbolic reasoning about key exchange protocols and adversary capability
in that setting.
6
and true/0, for an affirmative result of AEAD decryption verification. Here, /k
denotes k-arity. These formulae have the equations
decrypt(aead(k, p, a), k) → p
verify(aead(k, p, a), a, k) → true,
7
fact) and a generic term representing the current state machine state of the
agent (e.g. that a handshake is in progress with a particular ephemeral key
and hash chain). The invariants are contained instead in a persistent fact
StateInvariants(id, Q, Sipriv , Srpub , DH(Sipriv , Srpub )), containing the same identi-
fier, the relevant pre-shared symmetric key, initiator private key, and responder
public key, as well as the precomputed static-static Diffie-Hellman (included to
reduce the amount of computation done by Tamarin). Splitting up the state
in this way allows Tamarin to immediately link the terms in the invariant to
the point where the agents were set up—whereas solving a single linear fact
containing all state terms would only give the state transitions that could have
occurred immediately prior.
4.3.1 Agreement
The key agreement properties stated in Section 3.1 are covered by the following
three lemmas. First, from the initiator’s perspective, we prove that disagreement
implies that either Sr was compromised beforehand, or both Si and Ei were
compromised beforehand.
Lemma 1 (Unmatched initiator session requires Sr or (Si , Ei ) compromise, as
well as Q compromise).
∀Si , Sr , Ei , Er , Q, C, t1 . IKeys(Si , Sr , Ei , Er , Q, C) @ t1 ∧
¬ (∃t2 < t1 . RKeys(Si , Sr , Ei , Er , Q, C) @ t2 )
=⇒ ((∃t2 < t1 . Reveal(Sr ) @ t2 ) ∨
(∃t2 < t1 , t3 < t1 . Reveal(Si ) @ t2 ∧ Reveal(Ei ) @ t3 )) ∧
(∃t2 < t1 . Reveal(Q) @ t2 )
8
Lemma 2 (Unmatched responder session requires Si or (Sr , Er ) compromise,
as well as Q compromise).
∀Si , Sr , Ei , Er , Q, C, t1 . RConfirm(Si , Sr , Ei , Er , Q, C) @ t1 ∧
¬ (∃t2 < t1 . IKeys(Si , Sr , Ei , Er , Q, C) @ t2 )
=⇒ ((∃t2 < t1 . Reveal(Si ) @ t2 ) ∨
(∃t2 < t1 , t3 < t1 . Reveal(Sr ) @ t2 ∧ Reveal(Er ) @ t3 )) ∧
(∃t2 < t1 . Reveal(Q) @ t2 )
Finally, we show that if there is a session key, it necessarily came from the
same set of identity keys, thereby preventing an unknown key-share attack:
Lemma 3 (Session derivation implies key agreement).
4.3.2 Secrecy
For the secrecy properties in Section 3.2, we prove a secrecy property conditioned
on key agreement. Specifically, if I and R agree on their keys (even if R has
not yet confirmed them), then either the adversary never learns the key C they
derived, or the adversary compromised both the static and ephemeral of one of
the agents.
Lemma 4 (Key secrecy unless (Si , Ei ) or (Sr , Er ), as well as Q, are compro-
mised).
∀Si , Sr , Ei , Er , Q, C, t1 , t2 .
IKeys(Si , Sr , Ei , Er , Q, C) @ t1 ∧ RKeys(Si , Sr , Ei , Er , Q, C) @ t2
=⇒ ¬ (∃t3 . K(C) @ t3 ) ∨
((∃t3 . Reveal(Q) @ t3 ) ∧
((∃t3 , t4 . Reveal(Sr ) @ t3 ∧ Reveal(Er ) @ t4 ) ∨
(∃t3 , t4 . Reveal(Si ) @ t3 ∧ Reveal(Ei ) @ t4 )))
4.3.3 Uniqueness
Whereas uniqueness in Section 3.3 is stated in terms of whether terms are fresh,
in the Tamarin model any agent reaching an “agreement” action must have
generated at least their own ephemeral fresh; recall that we do not model a
broken randomness source that produces adversary-controlled values, just one
which can be revealed by the adversary. Thus, we prove that an agent who
negotiated a particular key can only do so once, even using different ephemeral
and pre-shared keys, with no restriction on adversary compromise rules.
9
Lemma 5 (Initiator session uniqueness).
∀Si , Sr , Ei , Er , Q, C, t1 . IKeys(Si , Sr , Ei , Er , Q, C) @ t1
=⇒ ¬ (∃Ei0 , Er0 , Q0 , t2 . IKeys(Si , Sr , Ei0 , Er0 , Q0 , C) @ t2 )
∀Si , Sr , Ei , Er , Q, C, t1 . RConfirm(Si , Sr , Ei , Er , Q, C) @ t1
=⇒ ¬ (∃Ei0 , Er0 , Q0 , t2 . RConfirm(Si , Sr , Ei0 , Er0 , Q0 , C) @ t2 )
∀σ, Si , Sr , Ei , Er , Q, C, t1 .
RKeys(Si , Sr , Ei , Er , Q, C) @ t1 ∧ σ @ t1
=⇒ (∃t2 . Reveal(Sr ) @ t2 ) ∨ (∃t2 . Reveal(Si ) @ t2 ) ∨
(∃t2 . Reveal(Ei ) @ t2 )
References
[1] Danny Dolev and Andrew Yao. “On the security of public key protocols”. In:
IEEE Transactions on information theory 29.2 (1983), pp. 198–208 (cit. on
p. 6).
[2] Jason A. Donenfeld. “WireGuard: Next Generation Kernel Network Tunnel”.
In: Proceedings of the 2017 Network and Distributed System Security Sym-
posium. NDSS’17. Document ID: 4846ada1492f5d92198df154f48c3d54205
657bc. San Diego, CA, Feb. 2017. isbn: 1-891562-46-0. doi: 10.14722/ndss.
2017.23160. url: https://www.wireguard.com/papers/wireguard.pdf
(cit. on pp. 1, 2).
10
[3] Trevor Perrin. The Noise Protocol Framework. 2016. url: http://noiseprotocol.
org/noise.pdf (cit. on p. 1).
[4] Benedikt Schmidt. “Formal analysis of key exchange protocols and physical
protocols”. Doctoral Thesis. ETH Zürich, 2012. doi: 10 . 3929 / ethz - a -
009898924 (cit. on p. 5).
[5] Benedikt Schmidt et al. “Automated Analysis of Diffie-Hellman Protocols
and Advanced Security Properties”. In: CSF. June 2012, pp. 78–94. doi:
10.1109/CSF.2012.25 (cit. on pp. 5, 6).
[6] Tamarin Prover Manual. url: https://tamarin-prover.github.io/manual/
(cit. on p. 5).
11