src/HOL/Auth/NS_Public.thy
author huffman
Sat Jun 06 09:11:12 2009 -0700 (2009-06-06)
changeset 31488 5691ccb8d6b5
parent 23746 a455e69c31cc
child 32960 69916a850301
permissions -rw-r--r--
generalize tendsto to class topological_space
paulson@2318
     1
(*  Title:      HOL/Auth/NS_Public
paulson@2318
     2
    ID:         $Id$
paulson@2318
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2318
     4
    Copyright   1996  University of Cambridge
paulson@2318
     5
paulson@2318
     6
Inductive relation "ns_public" for the Needham-Schroeder Public-Key protocol.
paulson@2538
     7
Version incorporating Lowe's fix (inclusion of B's identity in round 2).
paulson@2318
     8
*)
paulson@2318
     9
paulson@13956
    10
header{*Verifying the Needham-Schroeder-Lowe Public-Key Protocol*}
paulson@13956
    11
haftmann@16417
    12
theory NS_Public imports Public begin
paulson@2318
    13
berghofe@23746
    14
inductive_set ns_public :: "event list set"
berghofe@23746
    15
  where 
paulson@2318
    16
         (*Initial trace is empty*)
paulson@11104
    17
   Nil:  "[] \<in> ns_public"
paulson@2318
    18
paulson@2318
    19
         (*The spy MAY say anything he CAN say.  We do not expect him to
paulson@2318
    20
           invent new nonces here, but he can also use NS1.  Common to
paulson@2318
    21
           all similar protocols.*)
berghofe@23746
    22
 | Fake: "\<lbrakk>evsf \<in> ns_public;  X \<in> synth (analz (spies evsf))\<rbrakk>
paulson@11366
    23
          \<Longrightarrow> Says Spy B X  # evsf \<in> ns_public"
paulson@2318
    24
paulson@2318
    25
         (*Alice initiates a protocol run, sending a nonce to Bob*)
berghofe@23746
    26
 | NS1:  "\<lbrakk>evs1 \<in> ns_public;  Nonce NA \<notin> used evs1\<rbrakk>
paulson@13922
    27
          \<Longrightarrow> Says A B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>)
paulson@11104
    28
                 # evs1  \<in>  ns_public"
paulson@2318
    29
paulson@2318
    30
         (*Bob responds to Alice's message with a further nonce*)
berghofe@23746
    31
 | NS2:  "\<lbrakk>evs2 \<in> ns_public;  Nonce NB \<notin> used evs2;
paulson@13922
    32
           Says A' B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs2\<rbrakk>
paulson@13922
    33
          \<Longrightarrow> Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>)
paulson@11104
    34
                # evs2  \<in>  ns_public"
paulson@2318
    35
paulson@2318
    36
         (*Alice proves her existence by sending NB back to Bob.*)
berghofe@23746
    37
 | NS3:  "\<lbrakk>evs3 \<in> ns_public;
paulson@13922
    38
           Says A  B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs3;
paulson@13922
    39
           Says B' A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>)
paulson@11104
    40
              \<in> set evs3\<rbrakk>
paulson@13922
    41
          \<Longrightarrow> Says A B (Crypt (pubEK B) (Nonce NB)) # evs3 \<in> ns_public"
paulson@11104
    42
paulson@11104
    43
declare knows_Spy_partsEs [elim]
paulson@14200
    44
declare knows_Spy_partsEs [elim]
paulson@14200
    45
declare analz_into_parts [dest]
paulson@14200
    46
declare Fake_parts_insert_in_Un  [dest]
paulson@11104
    47
declare image_eq_UN [simp]  (*accelerates proofs involving nested images*)
paulson@11104
    48
paulson@11104
    49
(*A "possibility property": there are traces that reach the end*)
paulson@13922
    50
lemma "\<exists>NB. \<exists>evs \<in> ns_public. Says A B (Crypt (pubEK B) (Nonce NB)) \<in> set evs"
paulson@11104
    51
apply (intro exI bexI)
paulson@11104
    52
apply (rule_tac [2] ns_public.Nil [THEN ns_public.NS1, THEN ns_public.NS2, 
paulson@14207
    53
                                   THEN ns_public.NS3], possibility)
paulson@13926
    54
done
paulson@11104
    55
paulson@11104
    56
(** Theorems of the form X \<notin> parts (spies evs) imply that NOBODY
paulson@11104
    57
    sends messages containing X! **)
paulson@11104
    58
paulson@11104
    59
(*Spy never sees another agent's private key! (unless it's bad at start)*)
paulson@13922
    60
lemma Spy_see_priEK [simp]: 
paulson@13922
    61
      "evs \<in> ns_public \<Longrightarrow> (Key (priEK A) \<in> parts (spies evs)) = (A \<in> bad)"
paulson@11104
    62
by (erule ns_public.induct, auto)
paulson@11104
    63
paulson@13922
    64
lemma Spy_analz_priEK [simp]: 
paulson@13922
    65
      "evs \<in> ns_public \<Longrightarrow> (Key (priEK A) \<in> analz (spies evs)) = (A \<in> bad)"
paulson@11104
    66
by auto
paulson@11104
    67
paulson@14200
    68
subsection{*Authenticity properties obtained from NS2*}
paulson@11104
    69
paulson@11104
    70
paulson@11104
    71
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@11104
    72
  is secret.  (Honest users generate fresh nonces.)*)
paulson@11104
    73
lemma no_nonce_NS1_NS2 [rule_format]: 
paulson@11104
    74
      "evs \<in> ns_public 
paulson@13922
    75
       \<Longrightarrow> Crypt (pubEK C) \<lbrace>NA', Nonce NA, Agent D\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@13922
    76
           Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace> \<in> parts (spies evs) \<longrightarrow>  
paulson@11104
    77
           Nonce NA \<in> analz (spies evs)"
paulson@11104
    78
apply (erule ns_public.induct, simp_all)
paulson@11104
    79
apply (blast intro: analz_insertI)+
paulson@11104
    80
done
paulson@11104
    81
paulson@11104
    82
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@11104
    83
lemma unique_NA: 
paulson@13922
    84
     "\<lbrakk>Crypt(pubEK B)  \<lbrace>Nonce NA, Agent A \<rbrace> \<in> parts(spies evs);  
paulson@13922
    85
       Crypt(pubEK B') \<lbrace>Nonce NA, Agent A'\<rbrace> \<in> parts(spies evs);  
paulson@11104
    86
       Nonce NA \<notin> analz (spies evs); evs \<in> ns_public\<rbrakk>
paulson@11104
    87
      \<Longrightarrow> A=A' \<and> B=B'"
paulson@11104
    88
apply (erule rev_mp, erule rev_mp, erule rev_mp)   
paulson@11104
    89
apply (erule ns_public.induct, simp_all)
paulson@11104
    90
(*Fake, NS1*)
paulson@11104
    91
apply (blast intro: analz_insertI)+
paulson@11104
    92
done
paulson@11104
    93
paulson@11104
    94
paulson@11104
    95
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure
paulson@11104
    96
  The major premise "Says A B ..." makes it a dest-rule, so we use
paulson@11104
    97
  (erule rev_mp) rather than rule_format. *)
paulson@11104
    98
theorem Spy_not_see_NA: 
paulson@13922
    99
      "\<lbrakk>Says A B (Crypt(pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs;
paulson@11104
   100
        A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@11104
   101
       \<Longrightarrow> Nonce NA \<notin> analz (spies evs)"
paulson@11104
   102
apply (erule rev_mp)   
paulson@13507
   103
apply (erule ns_public.induct, simp_all, spy_analz)
paulson@11104
   104
apply (blast dest: unique_NA intro: no_nonce_NS1_NS2)+
paulson@11104
   105
done
paulson@11104
   106
paulson@2318
   107
paulson@11104
   108
(*Authentication for A: if she receives message 2 and has used NA
paulson@11104
   109
  to start a run, then B has sent message 2.*)
paulson@11104
   110
lemma A_trusts_NS2_lemma [rule_format]: 
paulson@11104
   111
   "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@13922
   112
    \<Longrightarrow> Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@13922
   113
	Says A B (Crypt(pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs \<longrightarrow>
paulson@13922
   114
	Says B A (Crypt(pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs"
paulson@11104
   115
apply (erule ns_public.induct, simp_all)
paulson@11104
   116
(*Fake, NS1*)
paulson@11104
   117
apply (blast dest: Spy_not_see_NA)+
paulson@11104
   118
done
paulson@11104
   119
paulson@11104
   120
theorem A_trusts_NS2: 
paulson@13922
   121
     "\<lbrakk>Says A  B (Crypt(pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs;   
paulson@13922
   122
       Says B' A (Crypt(pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs;
paulson@11104
   123
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@13922
   124
      \<Longrightarrow> Says B A (Crypt(pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs"
paulson@11104
   125
by (blast intro: A_trusts_NS2_lemma)
paulson@11104
   126
paulson@11104
   127
paulson@11104
   128
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@11104
   129
lemma B_trusts_NS1 [rule_format]:
paulson@11104
   130
     "evs \<in> ns_public                                         
paulson@13922
   131
      \<Longrightarrow> Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@11104
   132
	  Nonce NA \<notin> analz (spies evs) \<longrightarrow>
paulson@13922
   133
	  Says A B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs"
paulson@11104
   134
apply (erule ns_public.induct, simp_all)
paulson@11104
   135
(*Fake*)
paulson@11104
   136
apply (blast intro!: analz_insertI)
paulson@11104
   137
done
paulson@11104
   138
paulson@11104
   139
paulson@14200
   140
subsection{*Authenticity properties obtained from NS2*}
paulson@11104
   141
paulson@11104
   142
(*Unicity for NS2: nonce NB identifies nonce NA and agents A, B 
paulson@11104
   143
  [unicity of B makes Lowe's fix work]
paulson@11104
   144
  [proof closely follows that for unique_NA] *)
paulson@11104
   145
paulson@11104
   146
lemma unique_NB [dest]: 
paulson@13922
   147
     "\<lbrakk>Crypt(pubEK A)  \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace> \<in> parts(spies evs);
paulson@13922
   148
       Crypt(pubEK A') \<lbrace>Nonce NA', Nonce NB, Agent B'\<rbrace> \<in> parts(spies evs);
paulson@11104
   149
       Nonce NB \<notin> analz (spies evs); evs \<in> ns_public\<rbrakk>
paulson@11104
   150
      \<Longrightarrow> A=A' \<and> NA=NA' \<and> B=B'"
paulson@11104
   151
apply (erule rev_mp, erule rev_mp, erule rev_mp)   
paulson@11104
   152
apply (erule ns_public.induct, simp_all)
paulson@11104
   153
(*Fake, NS2*)
paulson@11104
   154
apply (blast intro: analz_insertI)+
paulson@11104
   155
done
paulson@11104
   156
paulson@11104
   157
paulson@11104
   158
(*Secrecy: Spy does not see the nonce sent in msg NS2 if A and B are secure*)
paulson@11104
   159
theorem Spy_not_see_NB [dest]:
paulson@13922
   160
     "\<lbrakk>Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs;
paulson@11104
   161
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>
paulson@11104
   162
      \<Longrightarrow> Nonce NB \<notin> analz (spies evs)"
paulson@11104
   163
apply (erule rev_mp)
paulson@13507
   164
apply (erule ns_public.induct, simp_all, spy_analz)
paulson@11104
   165
apply (blast intro: no_nonce_NS1_NS2)+
paulson@11104
   166
done
paulson@11104
   167
paulson@11104
   168
paulson@11104
   169
(*Authentication for B: if he receives message 3 and has used NB
paulson@11104
   170
  in message 2, then A has sent message 3.*)
paulson@11104
   171
lemma B_trusts_NS3_lemma [rule_format]:
paulson@11104
   172
     "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk> \<Longrightarrow>
paulson@13922
   173
      Crypt (pubEK B) (Nonce NB) \<in> parts (spies evs) \<longrightarrow>
paulson@13922
   174
      Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs \<longrightarrow>
paulson@13922
   175
      Says A B (Crypt (pubEK B) (Nonce NB)) \<in> set evs"
paulson@11104
   176
by (erule ns_public.induct, auto)
paulson@11104
   177
paulson@11104
   178
theorem B_trusts_NS3:
paulson@13922
   179
     "\<lbrakk>Says B A  (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs;
paulson@13922
   180
       Says A' B (Crypt (pubEK B) (Nonce NB)) \<in> set evs;             
paulson@11104
   181
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                    
paulson@13922
   182
      \<Longrightarrow> Says A B (Crypt (pubEK B) (Nonce NB)) \<in> set evs"
paulson@11104
   183
by (blast intro: B_trusts_NS3_lemma)
paulson@11104
   184
paulson@14200
   185
subsection{*Overall guarantee for B*}
paulson@11104
   186
paulson@11104
   187
(*If NS3 has been sent and the nonce NB agrees with the nonce B joined with
paulson@11104
   188
  NA, then A initiated the run using NA.*)
paulson@11104
   189
theorem B_trusts_protocol:
paulson@11104
   190
     "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk> \<Longrightarrow>
paulson@13922
   191
      Crypt (pubEK B) (Nonce NB) \<in> parts (spies evs) \<longrightarrow>
paulson@13922
   192
      Says B A  (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs \<longrightarrow>
paulson@13922
   193
      Says A B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs"
paulson@11104
   194
by (erule ns_public.induct, auto)
paulson@2318
   195
paulson@2318
   196
end