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