src/HOL/Auth/NS_Public.thy
author paulson
Tue Feb 13 13:16:27 2001 +0100 (2001-02-13)
changeset 11104 f2024fed9f0c
parent 5434 9b4bed3f394c
child 11230 756c5034f08b
permissions -rw-r--r--
partial conversion to Isar script style
simplified unicity proofs
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@11104
    10
theory NS_Public = Public:
paulson@2318
    11
paulson@11104
    12
consts  ns_public  :: "event list set"
paulson@2549
    13
paulson@2318
    14
inductive ns_public
paulson@11104
    15
  intros 
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.*)
paulson@11104
    22
   Fake: "\<lbrakk>evs \<in> ns_public;  X \<in> synth (analz (spies evs))\<rbrakk>
paulson@11104
    23
          \<Longrightarrow> Says Spy B X  # evs \<in> ns_public"
paulson@2318
    24
paulson@2318
    25
         (*Alice initiates a protocol run, sending a nonce to Bob*)
paulson@11104
    26
   NS1:  "\<lbrakk>evs1 \<in> ns_public;  Nonce NA \<notin> used evs1\<rbrakk>
paulson@11104
    27
          \<Longrightarrow> Says A B (Crypt (pubK 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*)
paulson@11104
    31
   NS2:  "\<lbrakk>evs2 \<in> ns_public;  Nonce NB \<notin> used evs2;
paulson@11104
    32
           Says A' B (Crypt (pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs2\<rbrakk>
paulson@11104
    33
          \<Longrightarrow> Says B A (Crypt (pubK 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.*)
paulson@11104
    37
   NS3:  "\<lbrakk>evs3 \<in> ns_public;
paulson@11104
    38
           Says A  B (Crypt (pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs3;
paulson@11104
    39
           Says B' A (Crypt (pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>)
paulson@11104
    40
              \<in> set evs3\<rbrakk>
paulson@11104
    41
          \<Longrightarrow> Says A B (Crypt (pubK B) (Nonce NB)) # evs3 \<in> ns_public"
paulson@11104
    42
paulson@11104
    43
  (*No Oops message.  Should there be one?*)
paulson@11104
    44
paulson@11104
    45
declare knows_Spy_partsEs [elim]
paulson@11104
    46
declare analz_subset_parts [THEN subsetD, dest]
paulson@11104
    47
declare Fake_parts_insert [THEN subsetD, dest]
paulson@11104
    48
declare image_eq_UN [simp]  (*accelerates proofs involving nested images*)
paulson@11104
    49
paulson@11104
    50
(*A "possibility property": there are traces that reach the end*)
paulson@11104
    51
lemma "\<exists>NB. \<exists>evs \<in> ns_public. Says A B (Crypt (pubK B) (Nonce NB)) \<in> set evs"
paulson@11104
    52
apply (intro exI bexI)
paulson@11104
    53
apply (rule_tac [2] ns_public.Nil [THEN ns_public.NS1, THEN ns_public.NS2, 
paulson@11104
    54
                                   THEN ns_public.NS3])
paulson@11104
    55
by possibility
paulson@11104
    56
paulson@11104
    57
paulson@11104
    58
(**** Inductive proofs about ns_public ****)
paulson@11104
    59
paulson@11104
    60
(** Theorems of the form X \<notin> parts (spies evs) imply that NOBODY
paulson@11104
    61
    sends messages containing X! **)
paulson@11104
    62
paulson@11104
    63
(*Spy never sees another agent's private key! (unless it's bad at start)*)
paulson@11104
    64
lemma Spy_see_priK [simp]: 
paulson@11104
    65
      "evs \<in> ns_public \<Longrightarrow> (Key (priK A) \<in> parts (spies evs)) = (A \<in> bad)"
paulson@11104
    66
by (erule ns_public.induct, auto)
paulson@11104
    67
paulson@11104
    68
lemma Spy_analz_priK [simp]: 
paulson@11104
    69
      "evs \<in> ns_public \<Longrightarrow> (Key (priK A) \<in> analz (spies evs)) = (A \<in> bad)"
paulson@11104
    70
by auto
paulson@11104
    71
paulson@11104
    72
paulson@11104
    73
(*** Authenticity properties obtained from NS2 ***)
paulson@11104
    74
paulson@11104
    75
paulson@11104
    76
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@11104
    77
  is secret.  (Honest users generate fresh nonces.)*)
paulson@11104
    78
lemma no_nonce_NS1_NS2 [rule_format]: 
paulson@11104
    79
      "evs \<in> ns_public 
paulson@11104
    80
       \<Longrightarrow> Crypt (pubK C) \<lbrace>NA', Nonce NA, Agent D\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@11104
    81
           Crypt (pubK B) \<lbrace>Nonce NA, Agent A\<rbrace> \<in> parts (spies evs) \<longrightarrow>  
paulson@11104
    82
           Nonce NA \<in> analz (spies evs)"
paulson@11104
    83
apply (erule ns_public.induct, simp_all)
paulson@11104
    84
apply (blast intro: analz_insertI)+
paulson@11104
    85
done
paulson@11104
    86
paulson@11104
    87
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@11104
    88
lemma unique_NA: 
paulson@11104
    89
     "\<lbrakk>Crypt(pubK B)  \<lbrace>Nonce NA, Agent A \<rbrace> \<in> parts(spies evs);  
paulson@11104
    90
       Crypt(pubK B') \<lbrace>Nonce NA, Agent A'\<rbrace> \<in> parts(spies evs);  
paulson@11104
    91
       Nonce NA \<notin> analz (spies evs); evs \<in> ns_public\<rbrakk>
paulson@11104
    92
      \<Longrightarrow> A=A' \<and> B=B'"
paulson@11104
    93
apply (erule rev_mp, erule rev_mp, erule rev_mp)   
paulson@11104
    94
apply (erule ns_public.induct, simp_all)
paulson@11104
    95
(*Fake, NS1*)
paulson@11104
    96
apply (blast intro: analz_insertI)+
paulson@11104
    97
done
paulson@11104
    98
paulson@11104
    99
paulson@11104
   100
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure
paulson@11104
   101
  The major premise "Says A B ..." makes it a dest-rule, so we use
paulson@11104
   102
  (erule rev_mp) rather than rule_format. *)
paulson@11104
   103
theorem Spy_not_see_NA: 
paulson@11104
   104
      "\<lbrakk>Says A B (Crypt(pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs;
paulson@11104
   105
        A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@11104
   106
       \<Longrightarrow> Nonce NA \<notin> analz (spies evs)"
paulson@11104
   107
apply (erule rev_mp)   
paulson@11104
   108
apply (erule ns_public.induct, simp_all)
paulson@11104
   109
apply spy_analz
paulson@11104
   110
apply (blast dest: unique_NA intro: no_nonce_NS1_NS2)+
paulson@11104
   111
done
paulson@11104
   112
paulson@2318
   113
paulson@11104
   114
(*Authentication for A: if she receives message 2 and has used NA
paulson@11104
   115
  to start a run, then B has sent message 2.*)
paulson@11104
   116
lemma A_trusts_NS2_lemma [rule_format]: 
paulson@11104
   117
   "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@11104
   118
    \<Longrightarrow> Crypt (pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@11104
   119
	Says A B (Crypt(pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs \<longrightarrow>
paulson@11104
   120
	Says B A (Crypt(pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs"
paulson@11104
   121
apply (erule ns_public.induct, simp_all)
paulson@11104
   122
(*Fake, NS1*)
paulson@11104
   123
apply (blast dest: Spy_not_see_NA)+
paulson@11104
   124
done
paulson@11104
   125
paulson@11104
   126
theorem A_trusts_NS2: 
paulson@11104
   127
     "\<lbrakk>Says A  B (Crypt(pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs;   
paulson@11104
   128
       Says B' A (Crypt(pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs;
paulson@11104
   129
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@11104
   130
      \<Longrightarrow> Says B A (Crypt(pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs"
paulson@11104
   131
by (blast intro: A_trusts_NS2_lemma)
paulson@11104
   132
paulson@11104
   133
paulson@11104
   134
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@11104
   135
lemma B_trusts_NS1 [rule_format]:
paulson@11104
   136
     "evs \<in> ns_public                                         
paulson@11104
   137
      \<Longrightarrow> Crypt (pubK B) \<lbrace>Nonce NA, Agent A\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@11104
   138
	  Nonce NA \<notin> analz (spies evs) \<longrightarrow>
paulson@11104
   139
	  Says A B (Crypt (pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs"
paulson@11104
   140
apply (erule ns_public.induct, simp_all)
paulson@11104
   141
(*Fake*)
paulson@11104
   142
apply (blast intro!: analz_insertI)
paulson@11104
   143
done
paulson@11104
   144
paulson@11104
   145
paulson@11104
   146
paulson@11104
   147
(*** Authenticity properties obtained from NS2 ***)
paulson@11104
   148
paulson@11104
   149
(*Unicity for NS2: nonce NB identifies nonce NA and agents A, B 
paulson@11104
   150
  [unicity of B makes Lowe's fix work]
paulson@11104
   151
  [proof closely follows that for unique_NA] *)
paulson@11104
   152
paulson@11104
   153
lemma unique_NB [dest]: 
paulson@11104
   154
     "\<lbrakk>Crypt(pubK A)  \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace> \<in> parts(spies evs);
paulson@11104
   155
       Crypt(pubK A') \<lbrace>Nonce NA', Nonce NB, Agent B'\<rbrace> \<in> parts(spies evs);
paulson@11104
   156
       Nonce NB \<notin> analz (spies evs); evs \<in> ns_public\<rbrakk>
paulson@11104
   157
      \<Longrightarrow> A=A' \<and> NA=NA' \<and> B=B'"
paulson@11104
   158
apply (erule rev_mp, erule rev_mp, erule rev_mp)   
paulson@11104
   159
apply (erule ns_public.induct, simp_all)
paulson@11104
   160
(*Fake, NS2*)
paulson@11104
   161
apply (blast intro: analz_insertI)+
paulson@11104
   162
done
paulson@11104
   163
paulson@11104
   164
paulson@11104
   165
(*Secrecy: Spy does not see the nonce sent in msg NS2 if A and B are secure*)
paulson@11104
   166
theorem Spy_not_see_NB [dest]:
paulson@11104
   167
     "\<lbrakk>Says B A (Crypt (pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs;
paulson@11104
   168
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>
paulson@11104
   169
      \<Longrightarrow> Nonce NB \<notin> analz (spies evs)"
paulson@11104
   170
apply (erule rev_mp)
paulson@11104
   171
apply (erule ns_public.induct, simp_all)
paulson@11104
   172
apply spy_analz
paulson@11104
   173
apply (blast intro: no_nonce_NS1_NS2)+
paulson@11104
   174
done
paulson@11104
   175
paulson@11104
   176
paulson@11104
   177
(*Authentication for B: if he receives message 3 and has used NB
paulson@11104
   178
  in message 2, then A has sent message 3.*)
paulson@11104
   179
lemma B_trusts_NS3_lemma [rule_format]:
paulson@11104
   180
     "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk> \<Longrightarrow>
paulson@11104
   181
      Crypt (pubK B) (Nonce NB) \<in> parts (spies evs) \<longrightarrow>
paulson@11104
   182
      Says B A (Crypt (pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs \<longrightarrow>
paulson@11104
   183
      Says A B (Crypt (pubK B) (Nonce NB)) \<in> set evs"
paulson@11104
   184
by (erule ns_public.induct, auto)
paulson@11104
   185
paulson@11104
   186
theorem B_trusts_NS3:
paulson@11104
   187
     "\<lbrakk>Says B A  (Crypt (pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs;
paulson@11104
   188
       Says A' B (Crypt (pubK B) (Nonce NB)) \<in> set evs;             
paulson@11104
   189
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                    
paulson@11104
   190
      \<Longrightarrow> Says A B (Crypt (pubK B) (Nonce NB)) \<in> set evs"
paulson@11104
   191
by (blast intro: B_trusts_NS3_lemma)
paulson@11104
   192
paulson@11104
   193
(*** Overall guarantee for B ***)
paulson@11104
   194
paulson@11104
   195
paulson@11104
   196
(*If NS3 has been sent and the nonce NB agrees with the nonce B joined with
paulson@11104
   197
  NA, then A initiated the run using NA.*)
paulson@11104
   198
theorem B_trusts_protocol:
paulson@11104
   199
     "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk> \<Longrightarrow>
paulson@11104
   200
      Crypt (pubK B) (Nonce NB) \<in> parts (spies evs) \<longrightarrow>
paulson@11104
   201
      Says B A  (Crypt (pubK A) \<lbrace>Nonce NA, Nonce NB, Agent B\<rbrace>) \<in> set evs \<longrightarrow>
paulson@11104
   202
      Says A B (Crypt (pubK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs"
paulson@11104
   203
by (erule ns_public.induct, auto)
paulson@2318
   204
paulson@2318
   205
end