
wenzelm@37936: (*  Title:      HOL/Auth/OtwayRees_AN.thy
paulson@2090:     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2090:     Copyright   1996  University of Cambridge
paulson@14207: *)
paulson@2090: 
wenzelm@58889: section{*The Otway-Rees Protocol as Modified by Abadi and Needham*}
paulson@2090: 
haftmann@16417: theory OtwayRees_AN imports Public begin
paulson@14207: 
paulson@14207: text{*
paulson@14207: This simplified version has minimal encryption and explicit messages.
paulson@2090: 
paulson@2516: Note that the formalization does not even assume that nonces are fresh.
paulson@2516: This is because the protocol does not rely on uniqueness of nonces for
paulson@2516: security, only for freshness, and the proof script does not prove freshness
paulson@2516: properties.
paulson@2516: 
paulson@2090: From page 11 of
paulson@14207:   Abadi and Needham (1996).  
paulson@14207:   Prudent Engineering Practice for Cryptographic Protocols.
paulson@14207:   IEEE Trans. SE 22 (1)
paulson@14207: *}
paulson@2090: 
berghofe@23746: inductive_set otway :: "event list set"
berghofe@23746:   where
paulson@14238:    Nil: --{*The empty trace*}
paulson@14238:         "[] \<in> otway"
paulson@2090: 
berghofe@23746:  | Fake: --{*The Spy may say anything he can say.  The sender field is correct,
paulson@14238:             but agents don't use that information.*}
paulson@14238:          "[| evsf \<in> otway;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251:           ==> Says Spy B X  # evsf \<in> otway"
paulson@2090: 
paulson@14238:         
berghofe@23746:  | Reception: --{*A message that has been sent can be received by the
paulson@14238:                   intended recipient.*}
wenzelm@32960:               "[| evsr \<in> otway;  Says A B X \<in>set evsr |]
paulson@11251:                ==> Gets B X # evsr \<in> otway"
paulson@6308: 
berghofe@23746:  | OR1:  --{*Alice initiates a protocol run*}
paulson@14238:          "evs1 \<in> otway
paulson@11251:           ==> Says A B {|Agent A, Agent B, Nonce NA|} # evs1 \<in> otway"
paulson@2090: 
berghofe@23746:  | OR2:  --{*Bob's response to Alice's message.*}
wenzelm@32960:          "[| evs2 \<in> otway;
paulson@11251:              Gets B {|Agent A, Agent B, Nonce NA|} \<in>set evs2 |]
paulson@2516:           ==> Says B Server {|Agent A, Agent B, Nonce NA, Nonce NB|}
paulson@11251:                  # evs2 \<in> otway"
paulson@2090: 
berghofe@23746:  | OR3:  --{*The Server receives Bob's message.  Then he sends a new
paulson@14238:            session key to Bob with a packet for forwarding to Alice.*}
wenzelm@32960:          "[| evs3 \<in> otway;  Key KAB \<notin> used evs3;
paulson@6308:              Gets Server {|Agent A, Agent B, Nonce NA, Nonce NB|}
paulson@11251:                \<in>set evs3 |]
paulson@11251:           ==> Says Server B
paulson@2516:                {|Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key KAB|},
paulson@2516:                  Crypt (shrK B) {|Nonce NB, Agent A, Agent B, Key KAB|}|}
paulson@11251:               # evs3 \<in> otway"
paulson@2090: 
berghofe@23746:  | OR4:  --{*Bob receives the Server's (?) message and compares the Nonces with
wenzelm@32960:              those in the message he previously sent the Server.
paulson@14238:              Need @{term "B \<noteq> Server"} because we allow messages to self.*}
wenzelm@32960:          "[| evs4 \<in> otway;  B \<noteq> Server;
paulson@11251:              Says B Server {|Agent A, Agent B, Nonce NA, Nonce NB|} \<in>set evs4;
paulson@6308:              Gets B {|X, Crypt(shrK B){|Nonce NB,Agent A,Agent B,Key K|}|}
paulson@11251:                \<in>set evs4 |]
paulson@11251:           ==> Says B A X # evs4 \<in> otway"
paulson@2090: 
berghofe@23746:  | Oops: --{*This message models possible leaks of session keys.  The nonces
paulson@14238:              identify the protocol run.*}
wenzelm@32960:          "[| evso \<in> otway;
paulson@11251:              Says Server B
paulson@11251:                       {|Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|},
paulson@2284:                         Crypt (shrK B) {|Nonce NB, Agent A, Agent B, Key K|}|}
paulson@11251:                \<in>set evso |]
paulson@11251:           ==> Notes Spy {|Nonce NA, Nonce NB, Key K|} # evso \<in> otway"
paulson@11251: 
paulson@11251: 
paulson@11251: declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251: declare parts.Body  [dest]
paulson@11251: declare analz_into_parts [dest]
paulson@11251: declare Fake_parts_insert_in_Un  [dest]
paulson@11251: 
paulson@11251: 
paulson@14238: text{*A "possibility property": there are traces that reach the end*}
paulson@14200: lemma "[| B \<noteq> Server; Key K \<notin> used [] |]
paulson@14200:       ==> \<exists>evs \<in> otway.
paulson@11251:            Says B A (Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|})
paulson@11251:              \<in> set evs"
paulson@11251: apply (intro exI bexI)
paulson@11251: apply (rule_tac [2] otway.Nil
paulson@11251:                     [THEN otway.OR1, THEN otway.Reception,
paulson@11251:                      THEN otway.OR2, THEN otway.Reception,
paulson@14200:                      THEN otway.OR3, THEN otway.Reception, THEN otway.OR4])
paulson@14200: apply (possibility, simp add: used_Cons) 
paulson@11251: done
paulson@11251: 
paulson@11251: lemma Gets_imp_Says [dest!]:
paulson@11251:      "[| Gets B X \<in> set evs; evs \<in> otway |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251: by (erule rev_mp, erule otway.induct, auto)
paulson@11251: 
paulson@11251: 
paulson@11251: 
paulson@14238: text{* For reasoning about the encrypted portion of messages *}
paulson@11251: 
paulson@11251: lemma OR4_analz_knows_Spy:
paulson@11251:      "[| Gets B {|X, Crypt(shrK B) X'|} \<in> set evs;  evs \<in> otway |]
paulson@11251:       ==> X \<in> analz (knows Spy evs)"
paulson@11251: by blast
paulson@11251: 
paulson@11251: 
paulson@14238: text{*Theorems of the form @{term "X \<notin> parts (spies evs)"} imply that
paulson@14238: NOBODY sends messages containing X! *}
paulson@11251: 
paulson@14238: text{*Spy never sees a good agent's shared key!*}
paulson@11251: lemma Spy_see_shrK [simp]:
paulson@11251:      "evs \<in> otway ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@14238: by (erule otway.induct, simp_all, blast+)
paulson@11251: 
paulson@11251: lemma Spy_analz_shrK [simp]:
paulson@11251:      "evs \<in> otway ==> (Key (shrK A) \<in> analz (knows Spy evs)) = (A \<in> bad)"
paulson@11251: by auto
paulson@11251: 
paulson@11251: lemma Spy_see_shrK_D [dest!]:
paulson@11251:      "[|Key (shrK A) \<in> parts (knows Spy evs);  evs \<in> otway|] ==> A \<in> bad"
paulson@11251: by (blast dest: Spy_see_shrK)
paulson@11251: 
paulson@11251: 
paulson@14238: subsection{*Proofs involving analz *}
paulson@11251: 
paulson@14238: text{*Describes the form of K and NA when the Server sends this message.*}
paulson@11251: lemma Says_Server_message_form:
paulson@11251:      "[| Says Server B
paulson@11251:             {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:               Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:            \<in> set evs;
paulson@11251:          evs \<in> otway |]
paulson@11251:       ==> K \<notin> range shrK & (\<exists>i. NA = Nonce i) & (\<exists>j. NB = Nonce j)"
paulson@11251: apply (erule rev_mp)
paulson@14207: apply (erule otway.induct, auto)
paulson@11251: done
paulson@11251: 
paulson@11251: 
paulson@11251: 
paulson@11251: (****
paulson@11251:  The following is to prove theorems of the form
paulson@11251: 
paulson@11251:   Key K \<in> analz (insert (Key KAB) (knows Spy evs)) ==>
paulson@11251:   Key K \<in> analz (knows Spy evs)
paulson@11251: 
paulson@11251:  A more general formula must be proved inductively.
paulson@11251: ****)
paulson@11251: 
paulson@11251: 
paulson@14238: text{* Session keys are not used to encrypt other session keys *}
paulson@11251: 
paulson@14238: text{*The equality makes the induction hypothesis easier to apply*}
paulson@11251: lemma analz_image_freshK [rule_format]:
paulson@11251:  "evs \<in> otway ==>
paulson@11251:    \<forall>K KK. KK <= -(range shrK) -->
paulson@11251:           (Key K \<in> analz (Key`KK Un (knows Spy evs))) =
paulson@11251:           (K \<in> KK | Key K \<in> analz (knows Spy evs))"
paulson@14207: apply (erule otway.induct) 
paulson@14207: apply (frule_tac [8] Says_Server_message_form)
paulson@14207: apply (drule_tac [7] OR4_analz_knows_Spy, analz_freshK, spy_analz, auto) 
paulson@11251: done
paulson@11251: 
paulson@11251: lemma analz_insert_freshK:
paulson@11251:   "[| evs \<in> otway;  KAB \<notin> range shrK |] ==>
wenzelm@11655:       (Key K \<in> analz (insert (Key KAB) (knows Spy evs))) =
paulson@11251:       (K = KAB | Key K \<in> analz (knows Spy evs))"
paulson@11251: by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@11251: 
paulson@11251: 
paulson@14238: text{*The Key K uniquely identifies the Server's message.*}
paulson@11251: lemma unique_session_keys:
paulson@11251:      "[| Says Server B
paulson@11251:           {|Crypt (shrK A) {|NA, Agent A, Agent B, K|},
paulson@11251:             Crypt (shrK B) {|NB, Agent A, Agent B, K|}|}
paulson@11251:          \<in> set evs;
paulson@11251:         Says Server B'
paulson@11251:           {|Crypt (shrK A') {|NA', Agent A', Agent B', K|},
paulson@11251:             Crypt (shrK B') {|NB', Agent A', Agent B', K|}|}
paulson@11251:          \<in> set evs;
paulson@11251:         evs \<in> otway |]
paulson@11251:      ==> A=A' & B=B' & NA=NA' & NB=NB'"
paulson@13507: apply (erule rev_mp, erule rev_mp, erule otway.induct, simp_all)
paulson@14238: apply blast+  --{*OR3 and OR4*}
paulson@11251: done
paulson@11251: 
paulson@11251: 
paulson@14238: subsection{*Authenticity properties relating to NA*}
paulson@11251: 
paulson@14238: text{*If the encrypted message appears then it originated with the Server!*}
paulson@11251: lemma NA_Crypt_imp_Server_msg [rule_format]:
paulson@11251:     "[| A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251:      ==> Crypt (shrK A) {|NA, Agent A, Agent B, Key K|} \<in> parts (knows Spy evs)
paulson@11251:        --> (\<exists>NB. Says Server B
paulson@11251:                     {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:                       Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:                     \<in> set evs)"
paulson@11251: apply (erule otway.induct, force)
paulson@11251: apply (simp_all add: ex_disj_distrib)
paulson@14238: apply blast+  --{*Fake, OR3*}
paulson@11251: done
paulson@11251: 
paulson@11251: 
paulson@14238: text{*Corollary: if A receives B's OR4 message then it originated with the
paulson@14238:       Server. Freshness may be inferred from nonce NA.*}
paulson@11251: lemma A_trusts_OR4:
paulson@11251:      "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|}) \<in> set evs;
paulson@11251:          A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251:       ==> \<exists>NB. Says Server B
paulson@11251:                   {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:                     Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:                  \<in> set evs"
paulson@11251: by (blast intro!: NA_Crypt_imp_Server_msg)
paulson@11251: 
paulson@11251: 
paulson@14238: text{*Crucial secrecy property: Spy does not see the keys sent in msg OR3
paulson@11251:     Does not in itself guarantee security: an attack could violate
paulson@14238:     the premises, e.g. by having @{term "A=Spy"}*}
paulson@11251: lemma secrecy_lemma:
paulson@11251:      "[| A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251:       ==> Says Server B
paulson@11251:            {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:              Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:           \<in> set evs -->
paulson@11251:           Notes Spy {|NA, NB, Key K|} \<notin> set evs -->
paulson@11251:           Key K \<notin> analz (knows Spy evs)"
paulson@11251: apply (erule otway.induct, force)
paulson@11251: apply (frule_tac [7] Says_Server_message_form)
paulson@11251: apply (drule_tac [6] OR4_analz_knows_Spy)
paulson@14238: apply (simp_all add: analz_insert_eq analz_insert_freshK pushes)
paulson@14238: apply spy_analz  --{*Fake*}
paulson@14238: apply (blast dest: unique_session_keys)+  --{*OR3, OR4, Oops*}
paulson@11251: done
paulson@11251: 
paulson@11251: 
paulson@11251: lemma Spy_not_see_encrypted_key:
paulson@11251:      "[| Says Server B
paulson@11251:             {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:               Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:            \<in> set evs;
paulson@11251:          Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251:          A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251:       ==> Key K \<notin> analz (knows Spy evs)"
paulson@32366:   by (metis secrecy_lemma)
paulson@11251: 
paulson@11251: 
paulson@14238: text{*A's guarantee.  The Oops premise quantifies over NB because A cannot know
paulson@14238:   what it is.*}
paulson@11251: lemma A_gets_good_key:
paulson@11251:      "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|}) \<in> set evs;
paulson@11251:          \<forall>NB. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251:          A \<notin> bad;  B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251:       ==> Key K \<notin> analz (knows Spy evs)"
paulson@32366:   by (metis A_trusts_OR4 secrecy_lemma)
paulson@11251: 
paulson@11251: 
paulson@11251: 
paulson@14238: subsection{*Authenticity properties relating to NB*}
paulson@11251: 
paulson@14238: text{*If the encrypted message appears then it originated with the Server!*}
paulson@11251: lemma NB_Crypt_imp_Server_msg [rule_format]:
paulson@11251:  "[| B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251:   ==> Crypt (shrK B) {|NB, Agent A, Agent B, Key K|} \<in> parts (knows Spy evs)
paulson@11251:       --> (\<exists>NA. Says Server B
paulson@11251:                    {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:                      Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:                    \<in> set evs)"
paulson@11251: apply (erule otway.induct, force, simp_all add: ex_disj_distrib)
paulson@14238: apply blast+  --{*Fake, OR3*}
paulson@11251: done
paulson@11251: 
paulson@11251: 
paulson@11251: 
paulson@14238: text{*Guarantee for B: if it gets a well-formed certificate then the Server
paulson@14238:   has sent the correct message in round 3.*}
paulson@11251: lemma B_trusts_OR3:
paulson@11251:      "[| Says S B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:            \<in> set evs;
paulson@11251:          B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251:       ==> \<exists>NA. Says Server B
paulson@11251:                    {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251:                      Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:                    \<in> set evs"
paulson@11251: by (blast intro!: NB_Crypt_imp_Server_msg)
paulson@11251: 
paulson@11251: 
paulson@14238: text{*The obvious combination of @{text B_trusts_OR3} with 
paulson@14238:       @{text Spy_not_see_encrypted_key}*}
paulson@11251: lemma B_gets_good_key:
paulson@11251:      "[| Gets B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251:           \<in> set evs;
paulson@11251:          \<forall>NA. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251:          A \<notin> bad;  B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251:       ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251: by (blast dest: B_trusts_OR3 Spy_not_see_encrypted_key)
paulson@2090: 
paulson@2090: end




