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