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