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