doc-src/TutorialI/Protocol/protocol.tex
author paulson
Tue, 24 Apr 2001 17:54:49 +0200
changeset 11267 f9506f60aa7b
parent 11262 9fde0021e1af
child 11428 332347b9b942
permissions -rw-r--r--
revisions to Protocols chapter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     1
% $Id$
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     2
\chapter{Case Study: Verifying a Cryptographic Protocol}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     3
\label{chap:crypto}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     4
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
     5
%crypto primitives 
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     6
\def\lbb{\mathopen{\{\kern-.30em|}}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     7
\def\rbb{\mathclose{|\kern-.32em\}}}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     8
\def\comp#1{\lbb#1\rbb}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
     9
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    10
Communications security is an ancient art.  Julius Caesar is said to have
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    11
encrypted his messages, shifting each letter three places along the
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    12
alphabet.  Mary Queen of Scots was convicted of treason after a cipher used
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    13
in her letters was broken.  Today's postal system
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    14
incorporates security features.  The envelope provides a degree of
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    15
\emph{secrecy}.  The signature provides \emph{authenticity} (proof of
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    16
origin), as do departmental stamps and letterheads.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    17
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    18
Networks are vulnerable: messages pass through many computers, any of which
11262
9fde0021e1af *** empty log message ***
nipkow
parents: 11248
diff changeset
    19
might be controlled by an adversary, who thus can capture or redirect
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    20
messages.  People who wish to communicate securely over such a network can
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    21
use cryptography, but if they are to understand each other, they need to
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    22
follow a
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    23
\emph{protocol}: a pre-arranged sequence of message formats. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    24
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    25
Protocols can be attacked in many ways, even if encryption is unbreakable. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    26
A \emph{splicing attack} involves an adversary's sending a message composed
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    27
of parts of several old messages.  This fake message may have the correct
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    28
format, fooling an honest party.  The adversary might be able to masquerade
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    29
as somebody else, or he might obtain a secret key.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    30
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    31
\emph{Nonces} help prevent splicing attacks. A typical nonce is a 20-byte
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    32
random number. Each message that requires a reply incorporates a nonce. The
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    33
reply must include a copy of that nonce, to prove that it is not a replay of
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    34
a past message.  The nonce in the reply must be cryptographically
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    35
protected, since otherwise an adversary could easily replace it by a
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    36
different one. You should be starting to see that protocol design is
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    37
tricky!
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    38
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    39
Researchers are developing methods for proving the correctness of security
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    40
protocols.  The Needham-Schroeder public-key
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    41
protocol~\cite{needham-schroeder} has become a standard test case. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    42
Proposed in 1978, it was found to be defective nearly two decades
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    43
later~\cite{lowe-fdr}.  This toy protocol will be useful in demonstrating
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    44
how to verify protocols using Isabelle.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    45
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    46
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    47
\section{The Needham-Schroeder Public-Key Protocol}\label{sec:ns-protocol}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    48
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    49
This protocol uses public-key cryptography. Each person has a private key, known only to
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    50
himself, and a public key, known to everybody. If Alice wants to send Bob a secret message, she
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    51
encrypts it using Bob's public key (which everybody knows), and sends it to Bob. Only Bob has the
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    52
matching private key, which is needed in order to decrypt Alice's message.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    53
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    54
The core of the Needham-Schroeder protocol consists of three messages:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    55
\begin{alignat*}{2}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    56
  &1.&\quad  A\to B  &: \comp{Na,A}\sb{Kb} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    57
  &2.&\quad  B\to A  &: \comp{Na,Nb}\sb{Ka} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    58
  &3.&\quad  A\to B  &: \comp{Nb}\sb{Kb}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    59
\end{alignat*}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    60
First, let's understand the notation. In the first message, Alice
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    61
sends Bob a message consisting of a nonce generated by Alice~($Na$)
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    62
paired  with Alice's name~($A$) and encrypted using Bob's public
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    63
key~($Kb$). In the second message, Bob sends Alice a message
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    64
consisting of $Na$ paired with a nonce generated by Bob~($Nb$), 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    65
encrypted using Alice's public key~($Ka$). In the last message, Alice
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    66
returns $Nb$ to Bob, encrypted using his public key.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    67
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    68
When Alice receives Message~2, she knows that Bob has acted on her
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    69
message, since only he could have decrypted
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    70
$\comp{Na,A}\sb{Kb}$ and extracted~$Na$.  That is precisely what
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    71
nonces are for.  Similarly, message~3 assures Bob that Alice is
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    72
active.  But the protocol was widely believed~\cite{ban89} to satisfy a
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    73
further property: that
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    74
$Na$ and~$Nb$ were secrets shared by Alice and Bob.  (Many
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    75
protocols generate such shared secrets, which can be used
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    76
to lessen the reliance on slow public-key operations.)  Lowe found this
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    77
claim to be false: if Alice runs the protocol with someone untrustworthy
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    78
(Charlie say), then he can start a new run with another agent (Bob say). 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    79
Charlie uses Alice as an oracle, masquerading as
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    80
Alice to Bob~\cite{lowe-fdr}.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    81
\begin{alignat*}{4}
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    82
  &1.&\quad  A\to C  &: \comp{Na,A}\sb{Kc}   &&
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    83
      \qquad 1'.&\quad  C\to B  &: \comp{Na,A}\sb{Kb} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    84
  &2.&\quad  B\to A  &: \comp{Na,Nb}\sb{Ka} \\
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    85
  &3.&\quad  A\to C  &: \comp{Nb}\sb{Kc}  &&
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    86
      \qquad 3'.&\quad  C\to B  &: \comp{Nb}\sb{Kb}
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    87
\end{alignat*}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    88
In messages~1 and~3, Charlie removes the encryption using his private
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    89
key and re-encrypts Alice's messages using Bob's public key. Bob is
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    90
left thinking he has run the protocol with Alice, which was not
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    91
Alice's intention, and Bob is unaware that the ``secret'' nonces are
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    92
known to Charlie.  This is a typical man-in-the-middle attack launched
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    93
by an insider.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
    94
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    95
Whether this counts as an attack has been disputed.  In protocols of this
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    96
type, we normally assume that the other party is honest.  To be honest
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    97
means to obey the protocol rules, so Alice's running the protocol with
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    98
Charlie does not make her dishonest, just careless.  After Lowe's
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
    99
attack, Alice has no grounds for complaint: this protocol does not have to
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   100
guarantee anything if you run it with a bad person.  Bob does have
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   101
grounds for complaint, however: the protocol tells him that he is
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   102
communicating with Alice (who is honest) but it does not guarantee
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   103
secrecy of the nonces.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   104
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   105
Lowe also suggested a correction, namely to include Bob's name in
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   106
message~2:
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   107
\begin{alignat*}{2}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   108
  &1.&\quad  A\to B  &: \comp{Na,A}\sb{Kb} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   109
  &2.&\quad  B\to A  &: \comp{Na,Nb,B}\sb{Ka} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   110
  &3.&\quad  A\to B  &: \comp{Nb}\sb{Kb}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   111
\end{alignat*}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   112
If Charlie tries the same attack, Alice will receive the message
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   113
$\comp{Na,Nb,B}\sb{Ka}$ when she was expecting to receive
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   114
$\comp{Na,Nb,C}\sb{Ka}$.  She will abandon the run, and eventually so
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   115
will Bob.  Below, we shall look at parts of this protocol's correctness
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   116
proof. 
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   117
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   118
In ground-breaking work, Lowe~\cite{lowe-fdr} showed how such attacks
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   119
could be found automatically using a model checker.  An alternative,
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   120
which we shall examine below, is to prove protocols correct.  Proofs
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   121
can be done under more realistic assumptions because our model does
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   122
not have to be finite.  The strategy is to formalize the operational
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   123
semantics of the system and to prove security properties using rule
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   124
induction.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   125
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   126
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   127
\section{Agents and Messages}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   128
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   129
All protocol specifications refer to a syntactic theory of messages. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   130
Datatype
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   131
\isa{agent} introduces the constant \isa{Server} (a trusted central
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   132
machine, needed for some protocols), an infinite population of
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   133
friendly agents, and the~\isa{Spy}:
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   134
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   135
\isacommand{datatype}\ agent\ =\ Server\ |\ Friend\ nat\ |\ Spy
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   136
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   137
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   138
Keys are just natural numbers.  Function \isa{invKey} maps a public key to
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   139
the matching private key, and vice versa:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   140
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   141
\isacommand{types}\ key\ =\ nat\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   142
\isacommand{consts}\ invKey\ ::\ "key=>key"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   143
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   144
Datatype
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   145
\isa{msg} introduces the message forms, which include agent names, nonces,
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   146
keys, compound messages, and encryptions.  
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   147
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   148
\isacommand{datatype}\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   149
\ \ \ \ \ msg\ =\ Agent\ \ agent\ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   150
\ \ \ \ \ \ \ \ \ |\ Nonce\ \ nat\ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   151
\ \ \ \ \ \ \ \ \ |\ Key\ \ \ \ key\ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   152
\ \ \ \ \ \ \ \ \ |\ MPair\ \ msg\ msg\ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   153
\ \ \ \ \ \ \ \ \ |\ Crypt\ \ key\ msg\ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   154
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   155
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   156
The notation $\comp{X\sb 1,\ldots X\sb{n-1},X\sb n}$
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   157
abbreviates
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   158
$\isa{MPair}\,X\sb 1\,\ldots\allowbreak(\isa{MPair}\,X\sb{n-1}\,X\sb n)$.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   159
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   160
Since datatype constructors are injective, we have the theorem
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   161
\begin{isabelle}
11262
9fde0021e1af *** empty log message ***
nipkow
parents: 11248
diff changeset
   162
Crypt K X = Crypt K' X' \isasymLongrightarrow\ K=K' \isasymand\ X=X'.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   163
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   164
A ciphertext can be decrypted using only one key and
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   165
can yield only one plaintext.  In the real world, decryption with the
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   166
wrong key succeeds but yields garbage.  Our model of encryption is
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   167
realistic if encryption adds some redundancy to the plaintext, such as a
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   168
checksum, so that garbage can be detected.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   169
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   170
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   171
\section{Modelling the Adversary}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   172
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   173
The spy is part of the system and must be built into the model.  He is
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   174
a malicious user who does not have to follow the protocol.  He
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   175
watches the network and uses any keys he knows to decrypt messages.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   176
Thus he accumulates additional keys and nonces.  These he can use to
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   177
compose new messages, which he may send to anybody.  
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   178
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   179
Two functions enable us to formalize this behaviour: \isa{analz} and
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   180
\isa{synth}.  Each function maps a sets of messages to another set of
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   181
messages. The set \isa{analz H} formalizes what the adversary can learn
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   182
from the set of messages~$H$.  The closure properties of this set are
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   183
defined inductively.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   184
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   185
\isacommand{consts}\ \ analz\ \ \ ::\ "msg\ set\ =>\ msg\ set"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   186
\isacommand{inductive}\ "analz\ H"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   187
\ \ \isakeyword{intros}\ \isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   188
\ \ \ \ Inj\ [intro,simp]\ :\ "X\ \isasymin \ H\
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   189
\isasymLongrightarrow\ X\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   190
\isasymin
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   191
\ analz\ H"\isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   192
\ \ \ \ Fst:\ \ \ \ \ "{\isasymlbrace}X,Y\isasymrbrace \ \isasymin \
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   193
analz\ H\
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   194
\isasymLongrightarrow\ X\ \isasymin \ analz\ H"\isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   195
\ \ \ \ Snd:\ \ \ \ \ "{\isasymlbrace}X,Y\isasymrbrace \ \isasymin \ analz\ H\
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   196
\isasymLongrightarrow\ Y\ \isasymin \ analz\ H"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   197
\ \ \ \ Decrypt\ [dest]:\ \isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   198
\ \ \ \ \ \ \ \ \ \ \ \ \ "{\isasymlbrakk}Crypt\ K\ X\ \isasymin \ analz\ H;\ Key(invKey\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   199
K):\ analz\ H\isasymrbrakk\isanewline
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   200
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow\ X\ \isasymin \ analz\ H"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   201
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   202
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   203
Note the \isa{Decrypt} rule: the spy can decrypt a
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   204
message encrypted with key~$K$ if he has the matching key,~$K^{-1}$. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   205
Properties proved by rule induction include the following:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   206
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   207
G\isasymsubseteq H\ \isasymLongrightarrow\ analz(G)\ \isasymsubseteq\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   208
analz(H)
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   209
\rulename{analz_mono}\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   210
analz (analz H) = analz H
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   211
\rulename{analz_idem} 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   212
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   213
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   214
The set of fake messages that an intruder could invent
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   215
starting from~\isa{H} is \isa{synth(analz~H)}, where \isa{synth H}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   216
formalizes what the adversary can build from the set of messages~$H$.  
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   217
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   218
\isacommand{consts}\ \ synth\ \ \ ::\ "msg\ set\ =>\ msg\ set"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   219
\isacommand{inductive}\ "synth\ H"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   220
\ \ \isakeyword{intros}\ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   221
\ \ \ \ Inj\ \ \ [intro]:\ "X\ \isasymin \ H\ \isasymLongrightarrow\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   222
X\ \isasymin \ synth\ H"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   223
\ \ \ \ Agent\ [intro]:\ "Agent\ agt\ \isasymin \ synth\ H"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   224
\ \ \ \ MPair\ [intro]:\isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   225
\ \ \ \ \ \ \ \ \ \ \ \ \ "{\isasymlbrakk}X\ \isasymin \ synth\ H;\ \ Y\ \isasymin
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   226
\ synth\ H\isasymrbrakk\ \isasymLongrightarrow\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   227
{\isasymlbrace}X,Y\isasymrbrace \ \isasymin \ synth\ H"\isanewline
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   228
\ \ \ \ Crypt\ [intro]:\isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   229
\ \ \ \ \ \ \ \ \ \ \ \ \ "{\isasymlbrakk}X\ \isasymin \ synth\ H;\ \ Key K\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   230
\isasymin \ H\isasymrbrakk\ \isasymLongrightarrow\ Crypt\ K\ X\
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   231
\isasymin \ synth\ H"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   232
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   233
The set includes all agent names.  Nonces and keys are assumed to be
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   234
unguessable, so none are included beyond those already in~$H$.   Two
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   235
elements of \isa{synth H} can be combined, and an element can be encrypted
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   236
using a key present in~$H$.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   237
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   238
Like \isa{analz}, this set operator is monotone and idempotent.  It also
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   239
satisfies an interesting equation involving \isa{analz}:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   240
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   241
analz (synth H)\ =\ analz H\ \isasymunion\ synth H
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   242
\rulename{analz_synth} 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   243
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   244
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   245
Rule inversion plays a major role in reasoning about \isa{synth}, through
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   246
declarations such as this one:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   247
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   248
\isacommand{inductive\_cases}\ Nonce_synth\ [elim!]:\ "Nonce\ n\ \isasymin
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   249
\ synth\ H"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   250
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   251
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   252
The resulting elimination rule replaces every assumption of the form
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   253
\isa{Nonce\ n\ \isasymin \ synth\ H} by \isa{Nonce\ n\ 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   254
\isasymin \ H}, expressing that a nonce cannot be guessed.  
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   255
%The theory also uses rule inversion with constructors \isa{Key}, \isa{Crypt}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   256
%and \isa{MPair} (message pairing).
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   257
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   258
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   259
A third operator, \isa{parts}, is useful for stating correctness
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   260
properties.  The set
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   261
\isa{parts H} consists of the components of elements of~$H$.  This set
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   262
includes~\isa{H} and is closed under the projections from a compound
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   263
message to its immediate parts. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   264
Its definition resembles that of \isa{analz} except in the rule
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   265
corresponding to the constructor \isa{Crypt}: 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   266
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   267
\ \ \ \ \ Crypt\ K\ X\ \isasymin \ parts\ H\ \isasymLongrightarrow\ X\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   268
\isasymin \ parts\ H
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   269
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   270
The body of an encrypted message is always regarded as part of it.  We can
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   271
use \isa{parts} to express general well-formedness properties of a protocol,
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   272
for example, that an uncompromised agent's private key will never be
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   273
included as a component of any message.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   274
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   275
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   276
\section{Event Traces}\label{sec:events}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   277
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   278
The system's behaviour is formalized as a set of traces of
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   279
\emph{events}.  The most important event, \isa{Says~A~B~X}, expresses
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   280
$A\to B : X$, which is the attempt by~$A$ to send~$B$ the message~$X$.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   281
A trace is simply a list, constructed in reverse
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   282
using~\isa{\#}.  Other event types include reception of messages (when
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   283
we want to make it explicit) and an agent's storing a fact.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   284
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   285
Sometimes the protocol requires an agent to generate a new nonce. The
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   286
probability that a 20-byte random number has appeared before is effectively
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   287
zero.  To formalize this important property, the set \isa{used evs}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   288
denotes the set of all items mentioned in the trace~\isa{evs}.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   289
The function \isa{used} has a straightforward
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   290
recursive definition.  Here is the case for \isa{Says} event:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   291
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   292
\ \ \ \ \ used\ ((Says\ A\ B\ X)\ \#\ evs)\ =\ parts\ \isacharbraceleft
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   293
X\isacharbraceright \ \isasymunion\ (used\ evs)
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   294
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   295
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   296
The function \isa{knows} formalizes an agent's knowledge.  Mostly we only
11262
9fde0021e1af *** empty log message ***
nipkow
parents: 11248
diff changeset
   297
care about the spy's knowledge, and \isa{knows Spy evs} is the set of items
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   298
available to the spy in the trace~\isa{evs}.  Already in the empty trace,
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   299
the spy starts with some secrets at his disposal, such as the private keys
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   300
of compromised users.  After each \isa{Says} event, the spy learns the
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   301
message that was sent:
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   302
\begin{isabelle}
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   303
\ \ \ \ \ knows\ Spy\ ((Says\ A\ B\ X)\ \#\ evs)\ =\ parts\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   304
\isacharbraceleft X\isacharbraceright \ \isasymunion\ (knows\ Spy\ evs)
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   305
\end{isabelle}
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   306
%
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   307
Combinations of functions express other important
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   308
sets of messages derived from~\isa{evs}:
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   309
\begin{itemize}
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   310
\item \isa{analz (knows Spy evs)} is everything that the spy could
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   311
learn by decryption
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   312
\item \isa{synth (analz (knows Spy evs))} is everything that the spy
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   313
could generate
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   314
\end{itemize}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   315
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   316
The function
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   317
\isa{pubK} maps agents to their public keys.  The function
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   318
\isa{priK} maps agents to their private keys.  It is defined in terms of
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   319
\isa{invKey} and \isa{pubK} by a translation; therefore \isa{priK} is
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   320
not a proper constant, so we declare it using \isacommand{syntax}
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   321
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   322
\isacommand{consts}\ \,pubK\ \ \ \ ::\ "agent\ =>\ key"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   323
\isacommand{syntax}\ priK\ \ \ \ ::\ "agent\ =>\ key"\isanewline
11262
9fde0021e1af *** empty log message ***
nipkow
parents: 11248
diff changeset
   324
\isacommand{translations}\ \ \ \ "priK\ x"\ \ \isasymrightleftharpoons\ \ "invKey(pubK\ x)"
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   325
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   326
The set \isa{bad} consists of those agents whose private keys are known to
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   327
the spy.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   328
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   329
Two axioms are asserted about the public-key cryptosystem. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   330
No two agents have the same public key, and no private key equals
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   331
any public key.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   332
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   333
\isacommand{axioms}\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   334
\ \ inj_pubK:\ \ \ \ \ \ \ \ "inj\ pubK"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   335
\ \ priK_neq_pubK:\ \ \ "priK\ A\ \isasymnoteq\ pubK\ B"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   336
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   337
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   338
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   339
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   340
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   341
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   342
\section{Modelling the Protocol}\label{sec:modelling}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   343
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   344
Let us formalize the Needham-Schroeder public-key protocol, as corrected by
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   345
Lowe:
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   346
\begin{alignat*}{2}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   347
  &1.&\quad  A\to B  &: \comp{Na,A}\sb{Kb} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   348
  &2.&\quad  B\to A  &: \comp{Na,Nb,B}\sb{Ka} \\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   349
  &3.&\quad  A\to B  &: \comp{Nb}\sb{Kb}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   350
\end{alignat*}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   351
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   352
Each protocol step is specified by a rule of an inductive definition.  An
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   353
event trace has type \isa{event list}, so we declare the constant
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   354
\isa{ns_public} to be a set of such traces.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   355
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   356
\isacommand{consts}\ \ ns_public\ \ ::\ "event\ list\ set"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   357
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   358
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   359
\begin{figure}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   360
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   361
\isacommand{inductive}\ ns_public\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   362
\ \ \isakeyword{intros}\ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   363
\ \ \ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   364
\ \ \ Nil:\ \ "[]\ \isasymin \ ns_public"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   365
\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   366
\ \ \ \ \ \ \ \ \ \isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   367
\ \ \ Fake:\ "\isasymlbrakk evsf\ \isasymin \ ns_public;\ \ X\ \isasymin \ synth\ (analz\ (knows\ Spy\ evsf))\isasymrbrakk \isanewline
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   368
\ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ Says\ Spy\ B\ X\ \ \#\ evsf\ \isasymin \ ns_public"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   369
\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   370
\ \ \ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   371
\ \ \ NS1:\ \ "\isasymlbrakk evs1\ \isasymin \ ns_public;\ \ Nonce\ NA\ \isasymnotin \ used\ evs1\isasymrbrakk \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   372
\ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ Says\ A\ B\ (Crypt\ (pubK\ B)\ \isasymlbrace Nonce\ NA,\ Agent\ A\isasymrbrace )\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   373
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ evs1\ \ \isasymin \ \ ns_public"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   374
\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   375
\ \ \ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   376
\ \ \ NS2:\ \ "\isasymlbrakk evs2\ \isasymin \ ns_public;\ \ Nonce\ NB\ \isasymnotin \ used\ evs2;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   377
\ \ \ \ \ \ \ \ \ \ \ Says\ A'\ B\ (Crypt\ (pubK\ B)\ \isasymlbrace Nonce\ NA,\ Agent\ A\isasymrbrace )\ \isasymin \ set\ evs2\isasymrbrakk \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   378
\ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ Says\ B\ A\ (Crypt\ (pubK\ A)\ \isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace )\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   379
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ evs2\ \ \isasymin \ \ ns_public"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   380
\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   381
\ \ \ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   382
\ \ \ NS3:\ \ "\isasymlbrakk evs3\ \isasymin \ ns_public;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   383
\ \ \ \ \ \ \ \ \ \ \ Says\ A\ \ B\ (Crypt\ (pubK\ B)\ \isasymlbrace Nonce\ NA,\ Agent\ A\isasymrbrace )\ \isasymin \ set\ evs3;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   384
\ \ \ \ \ \ \ \ \ \ \ Says\ B'\ A\ (Crypt\ (pubK\ A)\ \isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace )\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   385
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymin \ set\ evs3\isasymrbrakk \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   386
\ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ Says\ A\ B\ (Crypt\ (pubK\ B)\ (Nonce\ NB))\ \#\ evs3\ \isasymin \
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   387
ns_public"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   388
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   389
\caption{An Inductive Protocol Definition}\label{fig:ns_public}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   390
\end{figure}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   391
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   392
Figure~\ref{fig:ns_public} presents the inductive definition.  The
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   393
\isa{Nil} rule introduces the empty trace.  The \isa{Fake} rule models the
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   394
adversary's sending a message built from components taken from past
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   395
traffic, expressed using the functions \isa{synth} and
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   396
\isa{analz}. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   397
The next three rules model how honest agents would perform the three
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   398
protocol steps.  
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   399
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   400
Here is a detailed explanation of rule \isa{NS2}.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   401
A trace containing an event of the form
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   402
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   403
\ \ \ \ \ Says\ A'\ B\ (Crypt\ (pubK\ B)\ \isasymlbrace Nonce\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   404
NA,\ Agent\ A\isasymrbrace)
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   405
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   406
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   407
may be extended by an event of the form
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   408
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   409
\ \ \ \ \ Says\ B\ A\ (Crypt\ (pubK\ A)\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   410
\isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace)
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   411
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   412
where \isa{NB} is a fresh nonce: \isa{Nonce\ NB\ \isasymnotin \ used\ evs2}.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   413
Writing the sender as \isa{A'} indicates that \isa{B} does not 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   414
know who sent the message.  Calling the trace variable \isa{evs2} rather
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   415
than simply \isa{evs} helps us know where we are in a proof after many
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   416
case-splits: every subgoal mentioning \isa{evs2} involves message~2 of the
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   417
protocol.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   418
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   419
Benefits of this approach are simplicity and clarity.  The semantic model
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   420
is set theory, proofs are by induction and the translation from the informal
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   421
notation to the inductive rules is straightforward. 
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   422
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   423
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   424
\section{Proving Elementary Properties}\label{sec:regularity}
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   425
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   426
Secrecy properties can be hard to prove.  The conclusion of a typical
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   427
secrecy theorem is 
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   428
\isa{X\ \isasymnotin\ analz (knows Spy evs)}.  The difficulty arises from
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   429
having to reason about \isa{analz}, or less formally, showing that the spy
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   430
can never learn~\isa{X}.  Much easier is to prove that \isa{X} can never
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   431
occur at all.  Such \emph{regularity} properties are typically expressed
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   432
using \isa{parts} rather than \isa{analz}.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   433
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   434
The following lemma states that \isa{A}'s private key is potentially
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   435
known to the spy if and only if \isa{A} belongs to the set \isa{bad} of
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   436
compromised agents.  The statement uses \isa{parts}: the very presence of
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   437
\isa{A}'s private key in a message, whether protected by encryption or
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   438
not, is enough to confirm that \isa{A} is compromised.  The proof, like
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   439
nearly all protocol proofs, is by induction over traces.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   440
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   441
\isacommand{lemma}\ Spy_see_priK\ [simp]:\ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   442
\ \ \ \ \ \ "evs\ \isasymin \ ns_public\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   443
\ \ \ \ \ \ \ \isasymLongrightarrow \
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   444
(Key\ (priK\ A)\ \isasymin \ parts\ (knows\ Spy\ evs))\ =\ (A\ \isasymin \
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   445
bad)"\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   446
\isacommand{apply}\ (erule\ ns_public.induct,\ simp_all)
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   447
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   448
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   449
The induction yields five subgoals, one for each rule in the definition of
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   450
\isa{ns_public}.  The idea is to prove that
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   451
the protocol property holds initially (rule
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   452
\isa{Nil}), is preserved by each of the legitimate protocol steps (rules
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   453
\isa{NS1}--\isa{3}), and even is preserved in the face of anything the
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   454
spy can do (rule
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   455
\isa{Fake}).  
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   456
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   457
The proof is trivial.  No legitimate protocol rule sends any keys
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   458
at all, so only \isa{Fake} is relevant.  Indeed,
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   459
simplification leaves only the \isa{Fake} case, as indicated by the
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   460
variable name
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   461
\isa{evsf}:
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   462
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   463
\ 1.\ \isasymAnd X\ evsf.\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   464
\isaindent{\ 1.\ \ \ \ }\isasymlbrakk evsf\ \isasymin \ ns_public;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   465
\isaindent{\ 1.\ \ \ \ \ \ \ }(Key\ (priK\ A)\ \isasymin \ parts\ (knows\ Spy\ evsf))\ =\ (A\ \isasymin \ bad);\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   466
\isaindent{\ 1.\ \ \ \ \ \ \ }X\ \isasymin \ synth\ (analz\ (knows\ Spy\ evsf))\isasymrbrakk \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   467
\isaindent{\ 1.\ \ \ \ }\isasymLongrightarrow \ (Key\ (priK\ A)\ \isasymin \ parts\ (insert\ X\ (knows\ Spy\ evsf)))\ =\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   468
\isaindent{\ 1.\ \ \ \ \isasymLongrightarrow \ }(A\ \isasymin \
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   469
bad)\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   470
\isacommand{by}\ blast
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   471
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   472
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   473
The \isa{Fake} case is proved automatically.  If
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   474
\isa{priK~A} is in the extended trace then either (1) it was already in the
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   475
original trace or (2) it was
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   476
generated by the spy, who must have known this key already. 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   477
Either way, the induction hypothesis applies.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   478
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   479
\emph{Unicity} lemmas are regularity lemmas stating that specified items
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   480
can occur only once in a trace.  The following lemma states that a nonce
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   481
cannot be used both as $Na$ and as $Nb$ unless
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   482
it is known to the spy.  Intuitively, it holds because honest agents
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   483
always choose fresh values as nonces; only the spy might reuse a value,
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   484
and he doesn't know this particular value.  The proof script is short:
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   485
induction, simplification, \isa{blast}.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   486
\begin{isabelle}
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   487
\isacommand{lemma}\ no_nonce_NS1_NS2:\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   488
\ \ \ \ "\isasymlbrakk Crypt\ (pubK\ C)\ \isasymlbrace NA',\ Nonce\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   489
NA,\ Agent\ D\isasymrbrace \ \isasymin \ parts\ (knows\ Spy\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   490
evs);\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   491
\ \ \ \ \ \ Crypt\ (pubK\ B)\ \isasymlbrace Nonce\ NA,\ Agent\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   492
A\isasymrbrace \ \isasymin \ parts\ (knows\ Spy\ evs);\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   493
\ \ \ \ \ \ evs\ \isasymin \ ns_public\isasymrbrakk \isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   494
\ \ \ \ \ \isasymLongrightarrow \ Nonce\ NA\ \isasymin \ analz\ (knows\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   495
Spy\ evs)"\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   496
\isacommand{apply}\ (erule\ rev_mp,\ erule\ rev_mp)\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   497
\isacommand{apply}\ (erule\ ns_public.induct,\ simp_all)\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   498
\isacommand{apply}\ (blast\ intro:\ analz_insertI)+\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   499
\isacommand{done}
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   500
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   501
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   502
The following unicity lemma states that, if \isa{NA} is secret, then its
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   503
appearance in any instance of message~1 determines the other components. 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   504
The proof is similar to the previous one.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   505
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   506
\isacommand{lemma}\ unique_NA:\ \isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   507
\ \ \ \ \ "\isasymlbrakk Crypt(pubK\ B)\ \ \isasymlbrace Nonce\ NA,\ Agent\ A\ \isasymrbrace \ \isasymin \ parts(knows\ Spy\ evs);\ \ \isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   508
\ \ \ \ \ \ \ Crypt(pubK\ B')\ \isasymlbrace Nonce\ NA,\ Agent\ A'\isasymrbrace \ \isasymin \ parts(knows\ Spy\ evs);\ \ \isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   509
\ \ \ \ \ \ \ Nonce\ NA\ \isasymnotin \ analz\ (knows\ Spy\ evs);\ evs\ \isasymin \ ns_public\isasymrbrakk \isanewline
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   510
\ \ \ \ \ \ \isasymLongrightarrow \ A=A'\ \isasymand \ B=B'"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   511
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   512
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   513
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   514
\section{Proving Secrecy Theorems}\label{sec:secrecy}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   515
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   516
The secrecy theorems for Bob (the second participant) are especially
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   517
important because they fail for the original protocol.  The following
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   518
theorem states that if Bob sends message~2 to Alice, and both agents are
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   519
uncompromised, then Bob's nonce will never reach the spy.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   520
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   521
\isacommand{theorem}\ Spy_not_see_NB\ [dest]:\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   522
\ "\isasymlbrakk Says\ B\ A\ (Crypt\ (pubK\ A)\ \isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace )\ \isasymin \ set\ evs;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   523
\ \ \ A\ \isasymnotin \ bad;\ \ B\ \isasymnotin \ bad;\ \ evs\ \isasymin \ ns_public\isasymrbrakk \isanewline
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   524
\ \ \isasymLongrightarrow \ Nonce\ NB\ \isasymnotin \ analz\ (knows\ Spy\ evs)"
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   525
\end{isabelle}
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   526
%
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   527
To prove it, we must formulate the induction properly (one of the
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   528
assumptions mentions~\isa{evs}), apply induction, and simplify:
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   529
\begin{isabelle}
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   530
\isacommand{apply}\ (erule\ rev_mp,\ erule\ ns_public.induct,\ simp_all)
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   531
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   532
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   533
The proof states are too complicated to present in full.  
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   534
Let's examine the simplest subgoal, that for message~1.  The following
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   535
event has just occurred:
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   536
\[ 1.\quad  A'\to B'  : \comp{Na',A'}\sb{Kb'} \]
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   537
The variables above have been primed because this step
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   538
belongs to a different run from that referred to in the theorem
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   539
statement --- the theorem
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   540
refers to a past instance of message~2, while this subgoal
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   541
concerns message~1 being sent just now.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   542
In the Isabelle subgoal, instead of primed variables like $B'$ and $Na'$
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   543
we have \isa{Ba} and~\isa{NAa}:
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   544
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   545
\ 1.\ \isasymAnd Ba\ NAa\ evs1.\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   546
\isaindent{\ 1.\ \ \ \ }\isasymlbrakk A\ \isasymnotin \ bad;\ B\ \isasymnotin \ bad;\ evs1\ \isasymin \ ns_public;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   547
\isaindent{\ 1.\ \ \ \ \ \ \ }Says\ B\ A\ (Crypt\ (pubK\ A)\ \isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace )\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   548
\isaindent{\ 1.\ \ \ \ \ \ \ }\isasymin \ set\ evs1\ \isasymlongrightarrow \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   549
\isaindent{\ 1.\ \ \ \ \ \ \ }Nonce\ NB\ \isasymnotin \ analz\ (knows\ Spy\ evs1);\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   550
\isaindent{\ 1.\ \ \ \ \ \ \ }Nonce\ NAa\ \isasymnotin \ used\ evs1\isasymrbrakk \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   551
\isaindent{\ 1.\ \ \ \ }\isasymLongrightarrow \ Ba\ \isasymin \ bad\ \isasymlongrightarrow \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   552
\isaindent{\ 1.\ \ \ \ \isasymLongrightarrow \ }Says\ B\ A\ (Crypt\ (pubK\ A)\ \isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace )\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   553
\isaindent{\ 1.\ \ \ \ \isasymLongrightarrow \ }\isasymin \ set\ evs1\ \isasymlongrightarrow \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   554
\isaindent{\ 1.\ \ \ \ \isasymLongrightarrow \ }NB\ \isasymnoteq \ NAa
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   555
\end{isabelle}
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   556
%
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   557
The simplifier has used a 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   558
default simplification rule that does a case
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   559
analysis for each encrypted message on whether or not the decryption key
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   560
is compromised.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   561
\begin{isabelle} 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   562
analz\ (insert\ (Crypt\ K\ X)\ H)\ =\isanewline 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   563
\ (if\ Key\ (invKey\ K)\ \isasymin \ analz\ H\isanewline
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   564
\ \ then\ insert\
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   565
(Crypt\ K\ X)\ (anal\ z\ (insert\ X\ H))\isanewline 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   566
\ \ else\ insert\ (Crypt\ K\ X)\ (analz\ H)) 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   567
\rulename{analz_Crypt_if} 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   568
\end{isabelle} 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   569
The simplifier has also used \isa{Spy_see_priK}, proved in
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   570
\S\ref{sec:regularity}) above, to yield \isa{Ba\ \isasymin \ bad}.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   571
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   572
Recall that this subgoal concerns the case
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   573
where the last message to be sent was
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   574
\[ 1.\quad  A'\to B'  : \comp{Na',A'}\sb{Kb'}. \]
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   575
This message can compromise $Nb$ only if $Nb=Na'$ and $B'$ is compromised,
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   576
allowing the spy to decrypt the message.  The Isabelle subgoal says
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   577
precisely this, if we allow for its choice of variable names.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   578
Proving \isa{NB\ \isasymnoteq \ NAa} is easy: \isa{NB} was
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   579
sent earlier, while \isa{NAa} is fresh; formally, we have
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   580
the assumption
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   581
\isa{Nonce\ NAa\ \isasymnotin \ used\ evs1}. 
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   582
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   583
Note that our reasoning concerned \isa{B}'s participation in another
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   584
run.  Agents may engage in several runs concurrently, and some attacks work
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   585
by interleaving the messages of two runs.  With model checking, this
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   586
possibility can cause a state-space explosion, and for us it
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   587
certainly complicates proofs.  The biggest subgoal concerns message~2.  It
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   588
splits into several cases, such as whether or not the message just sent is
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   589
the very message mentioned in the theorem statement.
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   590
Some of the cases are proved by unicity, others by
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   591
the induction hypothesis.  For all those complications, the proofs are
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   592
automatic by \isa{blast} with the theorem \isa{no_nonce_NS1_NS2}.
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   593
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   594
The remaining theorems about the protocol are not hard to prove.  The
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   595
following one asserts a form of \emph{authenticity}: if
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   596
\isa{B} has sent an instance of message~2 to~\isa{A} and has received the
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   597
expected reply, then that reply really originated with~\isa{A}.  The
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   598
proof is a simple induction.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   599
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   600
\isacommand{theorem}\ B_trusts_NS3:\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   601
\ "\isasymlbrakk Says\ B\ A\ \ (Crypt\ (pubK\ A)\ \isasymlbrace Nonce\ NA,\ Nonce\ NB,\ Agent\ B\isasymrbrace )\ \isasymin \ set\ evs;\isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   602
\ \ \ Says\ A'\ B\ (Crypt\ (pubK\ B)\ (Nonce\ NB))\ \isasymin \ set\ evs;\ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   603
\ \ \ A\ \isasymnotin \ bad;\ \ B\ \isasymnotin \ bad;\ \ evs\ \isasymin \ ns_public\isasymrbrakk \ \ \ \ \ \ \ \ \isanewline
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   604
\ \ \isasymLongrightarrow \ Says\ A\ B\ (Crypt\ (pubK\ B)\ (Nonce\ NB))\ \isasymin \ set\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   605
evs"
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   606
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   607
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   608
From similar assumptions, we can prove that \isa{A} started the protocol
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   609
run by sending an instance of message~1 involving the nonce~\isa{NA}\@. 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   610
For this theorem, the conclusion is 
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   611
\begin{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   612
\ \ \ \ \ Says\ A\ B\ (Crypt\ (pubK\ B)\ \isasymlbrace Nonce\ NA,\ Agent\
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   613
A\isasymrbrace )\ \isasymin \ set\ evs
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   614
\end{isabelle}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   615
%
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   616
Analogous theorems can be proved for~\isa{A}, stating that nonce~\isa{NA}
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   617
remains secret and that message~2 really originates with~\isa{B}.  Even the
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   618
flawed protocol establishes these properties for~\isa{A};
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   619
the flaw only harms the second participant.
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   620
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   621
\medskip
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   622
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   623
Detailed information on this protocol verification technique can be found
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   624
elsewhere~\cite{paulson-jcs}, including proofs of an Internet
11267
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   625
protocol~\cite{paulson-tls}.  We must stress that the protocol discussed
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   626
in this chapter is trivial.  There are only three messages; no keys are
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   627
exchanged; we merely have to prove that encrypted data remains secret. 
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   628
Real world protocols are much longer and distribute many secrets to their
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   629
participants.  To be realistic, the model has to include the possibility
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   630
of keys being lost dynamically due to carelessness.  If those keys have
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   631
been used to encrypt other sensitive information, there may be cascading
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   632
losses.  We may still be able to establish a bound on the losses and to
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   633
prove that other protocol runs function
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   634
correctly~\cite{paulson-yahalom}.  Proofs of real-world protocols follow
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   635
the strategy illustrated above, but the subgoals can
f9506f60aa7b revisions to Protocols chapter
paulson
parents: 11262
diff changeset
   636
be much bigger and there are more of them.
11248
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   637
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   638
7a696a130de2 back to Unix format...
paulson
parents: 11247
diff changeset
   639
\endinput