src/HOL/Auth/NS_Public_Bad.ML
author paulson
Tue Nov 11 11:16:18 1997 +0100 (1997-11-11)
changeset 4198 c63639beeff1
parent 4197 1547bc6daa5a
child 4449 df30e75f670f
permissions -rw-r--r--
Fixed spelling error
paulson@2318
     1
(*  Title:      HOL/Auth/NS_Public_Bad
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@2318
     7
Flawed version, vulnerable to Lowe's attack.
paulson@2318
     8
paulson@2318
     9
From page 260 of
paulson@2318
    10
  Burrows, Abadi and Needham.  A Logic of Authentication.
paulson@2318
    11
  Proc. Royal Soc. 426 (1989)
paulson@2318
    12
*)
paulson@2318
    13
paulson@2318
    14
open NS_Public_Bad;
paulson@2318
    15
paulson@2318
    16
proof_timing:=true;
paulson@2318
    17
HOL_quantifiers := false;
paulson@2318
    18
paulson@3683
    19
AddIffs [Spy_in_bad];
paulson@2318
    20
paulson@2318
    21
(*A "possibility property": there are traces that reach the end*)
paulson@2318
    22
goal thy 
paulson@2480
    23
 "!!A B. A ~= B ==> EX NB. EX evs: ns_public.               \
nipkow@3465
    24
\                     Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
paulson@2318
    25
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@2318
    26
by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
paulson@2516
    27
by possibility_tac;
paulson@2318
    28
result();
paulson@2318
    29
paulson@2318
    30
paulson@2318
    31
(**** Inductive proofs about ns_public ****)
paulson@2318
    32
paulson@2318
    33
(*Nobody sends themselves messages*)
nipkow@3465
    34
goal thy "!!evs. evs : ns_public ==> ALL A X. Says A A X ~: set evs";
paulson@2318
    35
by (etac ns_public.induct 1);
paulson@2318
    36
by (Auto_tac());
paulson@2318
    37
qed_spec_mp "not_Says_to_self";
paulson@2318
    38
Addsimps [not_Says_to_self];
paulson@2318
    39
AddSEs   [not_Says_to_self RSN (2, rev_notE)];
paulson@2318
    40
paulson@2318
    41
paulson@3519
    42
(*Induction for regularity theorems.  If induction formula has the form
paulson@3683
    43
   X ~: analz (spies evs) --> ... then it shortens the proof by discarding
paulson@3683
    44
   needless information about analz (insert X (spies evs))  *)
paulson@3519
    45
fun parts_induct_tac i = 
paulson@3519
    46
    etac ns_public.induct i
paulson@3519
    47
    THEN 
paulson@3519
    48
    REPEAT (FIRSTGOAL analz_mono_contra_tac)
paulson@3519
    49
    THEN 
paulson@3519
    50
    prove_simple_subgoals_tac i;
paulson@3519
    51
paulson@3519
    52
paulson@3683
    53
(** Theorems of the form X ~: parts (spies evs) imply that NOBODY
paulson@2318
    54
    sends messages containing X! **)
paulson@2318
    55
paulson@3683
    56
(*Spy never sees another agent's private key! (unless it's bad at start)*)
paulson@2318
    57
goal thy 
paulson@3683
    58
 "!!A. evs: ns_public ==> (Key (priK A) : parts (spies evs)) = (A : bad)";
paulson@3519
    59
by (parts_induct_tac 1);
paulson@3121
    60
by (Fake_parts_insert_tac 1);
paulson@2318
    61
qed "Spy_see_priK";
paulson@2318
    62
Addsimps [Spy_see_priK];
paulson@2318
    63
paulson@2318
    64
goal thy 
paulson@3683
    65
 "!!A. evs: ns_public ==> (Key (priK A) : analz (spies evs)) = (A : bad)";
wenzelm@4091
    66
by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
paulson@2318
    67
qed "Spy_analz_priK";
paulson@2318
    68
Addsimps [Spy_analz_priK];
paulson@2318
    69
paulson@3683
    70
goal thy  "!!A. [| Key (priK A) : parts (spies evs);       \
paulson@3683
    71
\                  evs : ns_public |] ==> A:bad";
wenzelm@4091
    72
by (blast_tac (claset() addDs [Spy_see_priK]) 1);
paulson@2318
    73
qed "Spy_see_priK_D";
paulson@2318
    74
paulson@2318
    75
bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
paulson@2318
    76
AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
paulson@2318
    77
paulson@2318
    78
paulson@3519
    79
(**** Authenticity properties obtained from NS2 ****)
paulson@3519
    80
paulson@3519
    81
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@3519
    82
  is secret.  (Honest users generate fresh nonces.)*)
paulson@3519
    83
goal thy 
paulson@3683
    84
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
paulson@3683
    85
\           Nonce NA ~: analz (spies evs);   evs : ns_public |]       \
paulson@3683
    86
\ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies evs)";
paulson@3519
    87
by (etac rev_mp 1);
paulson@3519
    88
by (etac rev_mp 1);
paulson@3519
    89
by (parts_induct_tac 1);
paulson@3519
    90
(*NS3*)
wenzelm@4091
    91
by (blast_tac (claset() addSEs partsEs) 3);
paulson@3519
    92
(*NS2*)
wenzelm@4091
    93
by (blast_tac (claset() addSEs partsEs) 2);
paulson@3519
    94
by (Fake_parts_insert_tac 1);
paulson@3519
    95
qed "no_nonce_NS1_NS2";
paulson@3519
    96
paulson@3519
    97
paulson@3519
    98
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@3519
    99
goal thy 
paulson@3683
   100
 "!!evs. [| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
paulson@3709
   101
\ ==> EX A' B'. ALL A B.                                            \
paulson@3683
   102
\      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
paulson@3519
   103
\      A=A' & B=B'";
paulson@3519
   104
by (etac rev_mp 1);
paulson@3519
   105
by (parts_induct_tac 1);
paulson@3519
   106
by (ALLGOALS
wenzelm@4091
   107
    (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
paulson@3519
   108
(*NS1*)
wenzelm@4091
   109
by (expand_case_tac "NA = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
paulson@3519
   110
(*Fake*)
paulson@3709
   111
by (Clarify_tac 1);
paulson@3519
   112
by (ex_strip_tac 1);
paulson@3519
   113
by (Fake_parts_insert_tac 1);
paulson@3519
   114
val lemma = result();
paulson@3519
   115
paulson@3519
   116
goal thy 
paulson@3683
   117
 "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
paulson@3683
   118
\           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
paulson@3683
   119
\           Nonce NA ~: analz (spies evs);                            \
paulson@3709
   120
\           evs : ns_public |]                                        \
paulson@3519
   121
\        ==> A=A' & B=B'";
paulson@3519
   122
by (prove_unique_tac lemma 1);
paulson@3519
   123
qed "unique_NA";
paulson@3519
   124
paulson@3519
   125
paulson@3519
   126
(*Tactic for proving secrecy theorems*)
paulson@2418
   127
fun analz_induct_tac i = 
paulson@3121
   128
    etac ns_public.induct i   THEN
wenzelm@4091
   129
    ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if]));
paulson@2418
   130
paulson@2318
   131
paulson@2318
   132
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
paulson@2318
   133
goal thy 
paulson@3709
   134
 "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;   \
paulson@3683
   135
\           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
paulson@3683
   136
\        ==>  Nonce NA ~: analz (spies evs)";
paulson@2536
   137
by (etac rev_mp 1);
paulson@2418
   138
by (analz_induct_tac 1);
paulson@2318
   139
(*NS3*)
wenzelm@4091
   140
by (blast_tac (claset() addDs  [Says_imp_spies RS parts.Inj]
paulson@3121
   141
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
paulson@2536
   142
(*NS2*)
wenzelm@4091
   143
by (blast_tac (claset() addSEs [MPair_parts]
paulson@3683
   144
		       addDs  [Says_imp_spies RS parts.Inj,
paulson@3121
   145
			       parts.Body, unique_NA]) 3);
paulson@2318
   146
(*NS1*)
wenzelm@4091
   147
by (blast_tac (claset() addSEs spies_partsEs
paulson@3121
   148
                       addIs  [impOfSubs analz_subset_parts]) 2);
paulson@2318
   149
(*Fake*)
paulson@2497
   150
by (spy_analz_tac 1);
paulson@2536
   151
qed "Spy_not_see_NA";
paulson@2318
   152
paulson@2318
   153
paulson@2318
   154
(*Authentication for A: if she receives message 2 and has used NA
paulson@2318
   155
  to start a run, then B has sent message 2.*)
paulson@2318
   156
goal thy 
paulson@3466
   157
 "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
paulson@3466
   158
\           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
paulson@3709
   159
\           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
nipkow@3465
   160
\        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
paulson@2536
   161
by (etac rev_mp 1);
paulson@2536
   162
(*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
paulson@3683
   163
by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
paulson@2536
   164
by (etac ns_public.induct 1);
paulson@2318
   165
by (ALLGOALS Asm_simp_tac);
paulson@3709
   166
by (ALLGOALS Clarify_tac);
paulson@3709
   167
(*NS2*)
wenzelm@4091
   168
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj,
paulson@3709
   169
			      Spy_not_see_NA, unique_NA]) 3);
paulson@2318
   170
(*NS1*)
wenzelm@4091
   171
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   172
(*Fake*)
wenzelm@4091
   173
by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   174
                       addDs  [Spy_not_see_NA, 
paulson@3121
   175
			       impOfSubs analz_subset_parts]) 1);
paulson@2318
   176
qed "A_trusts_NS2";
paulson@2318
   177
paulson@2318
   178
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@2318
   179
goal thy 
paulson@3683
   180
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
paulson@3683
   181
\           Nonce NA ~: analz (spies evs);                            \
paulson@3709
   182
\           evs : ns_public |]                                        \
nipkow@3465
   183
\   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   184
by (etac rev_mp 1);
paulson@2536
   185
by (etac rev_mp 1);
paulson@3519
   186
by (parts_induct_tac 1);
paulson@3519
   187
by (Fake_parts_insert_tac 1);
paulson@3121
   188
qed "B_trusts_NS1";
paulson@2318
   189
paulson@2318
   190
paulson@2318
   191
paulson@2318
   192
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
   193
paulson@2480
   194
(*Unicity for NS2: nonce NB identifies agent A and nonce NA
paulson@2318
   195
  [proof closely follows that for unique_NA] *)
paulson@2318
   196
goal thy 
paulson@3683
   197
 "!!evs. [| Nonce NB ~: analz (spies evs);  evs : ns_public |]  \
paulson@3709
   198
\ ==> EX A' NA'. ALL A NA.                                      \
paulson@3709
   199
\      Crypt (pubK A) {|Nonce NA, Nonce NB|}                    \
paulson@3683
   200
\        : parts (spies evs)  -->  A=A' & NA=NA'";
paulson@2536
   201
by (etac rev_mp 1);
paulson@3519
   202
by (parts_induct_tac 1);
paulson@3519
   203
by (ALLGOALS
wenzelm@4091
   204
    (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
paulson@2318
   205
(*NS2*)
wenzelm@4091
   206
by (expand_case_tac "NB = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
paulson@2318
   207
(*Fake*)
paulson@3709
   208
by (Clarify_tac 1);
paulson@2318
   209
by (ex_strip_tac 1);
paulson@3519
   210
by (Fake_parts_insert_tac 1);
paulson@2318
   211
val lemma = result();
paulson@2318
   212
paulson@2318
   213
goal thy 
paulson@3683
   214
 "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies evs); \
paulson@3683
   215
\           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies evs); \
paulson@3683
   216
\           Nonce NB ~: analz (spies evs);                            \
paulson@3709
   217
\           evs : ns_public |]                                        \
paulson@2318
   218
\        ==> A=A' & NA=NA'";
paulson@2418
   219
by (prove_unique_tac lemma 1);
paulson@2318
   220
qed "unique_NB";
paulson@2318
   221
paulson@2318
   222
paulson@2318
   223
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@2318
   224
goal thy 
paulson@3466
   225
 "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
paulson@3703
   226
\          ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs;      \
paulson@3703
   227
\          A ~: bad;  B ~: bad;  evs : ns_public |]                     \
paulson@3683
   228
\       ==> Nonce NB ~: analz (spies evs)";
paulson@2536
   229
by (etac rev_mp 1);
paulson@2536
   230
by (etac rev_mp 1);
paulson@2418
   231
by (analz_induct_tac 1);
wenzelm@4091
   232
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@3709
   233
by (ALLGOALS Clarify_tac);
paulson@3703
   234
(*NS3: because NB determines A*)
wenzelm@4091
   235
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, unique_NB]) 4);
paulson@3703
   236
(*NS2: by freshness and unicity of NB*)
wenzelm@4091
   237
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
paulson@3703
   238
                       addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
paulson@3703
   239
                       addEs partsEs
paulson@3703
   240
		       addIs [impOfSubs analz_subset_parts]) 3);
paulson@3703
   241
(*NS1: by freshness*)
wenzelm@4091
   242
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   243
(*Fake*)
paulson@2497
   244
by (spy_analz_tac 1);
paulson@2536
   245
qed "Spy_not_see_NB";
paulson@2318
   246
paulson@2318
   247
paulson@2318
   248
paulson@2318
   249
(*Authentication for B: if he receives message 3 and has used NB
paulson@2536
   250
  in message 2, then A has sent message 3--to somebody....*)
paulson@2318
   251
goal thy 
paulson@3545
   252
 "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs; \
paulson@3545
   253
\           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;              \
paulson@3683
   254
\           A ~: bad;  B ~: bad;  evs : ns_public |]                   \
nipkow@3465
   255
\        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
paulson@2536
   256
by (etac rev_mp 1);
paulson@2536
   257
(*prepare induction over Crypt (pubK B) NB : parts H*)
paulson@3683
   258
by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
paulson@3519
   259
by (parts_induct_tac 1);
wenzelm@4091
   260
by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
paulson@3709
   261
by (ALLGOALS Clarify_tac);
paulson@4197
   262
(*NS3: because NB determines A (this use of unique_NB is more robust) *)
paulson@4197
   263
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, Spy_not_see_NB]
paulson@4197
   264
			addIs [unique_NB RS conjunct1]) 3);
paulson@3703
   265
(*NS1: by freshness*)
wenzelm@4091
   266
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   267
(*Fake*)
wenzelm@4091
   268
by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   269
                       addDs  [Spy_not_see_NB, 
paulson@3121
   270
			       impOfSubs analz_subset_parts]) 1);
paulson@2318
   271
qed "B_trusts_NS3";
paulson@2318
   272
paulson@2318
   273
paulson@2318
   274
(*Can we strengthen the secrecy theorem?  NO*)
paulson@2318
   275
goal thy 
paulson@3683
   276
 "!!evs. [| A ~: bad;  B ~: bad;  evs : ns_public |]           \
nipkow@3465
   277
\ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
paulson@3683
   278
\     --> Nonce NB ~: analz (spies evs)";
paulson@2418
   279
by (analz_induct_tac 1);
paulson@3709
   280
by (ALLGOALS Clarify_tac);
paulson@3703
   281
(*NS2: by freshness and unicity of NB*)
wenzelm@4091
   282
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
paulson@3703
   283
                       addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
paulson@3703
   284
                       addEs partsEs
paulson@3703
   285
		       addIs [impOfSubs analz_subset_parts]) 3);
paulson@3703
   286
(*NS1: by freshness*)
wenzelm@4091
   287
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   288
(*Fake*)
paulson@2497
   289
by (spy_analz_tac 1);
paulson@3703
   290
(*NS3: unicity of NB identifies A and NA, but not B*)
paulson@3683
   291
by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
paulson@3683
   292
    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
paulson@3703
   293
by (Auto_tac());
paulson@3703
   294
by (rename_tac "C B' evs3" 1);
paulson@2318
   295
paulson@2318
   296
(*
paulson@2318
   297
THIS IS THE ATTACK!
paulson@3703
   298
Level 8
paulson@3683
   299
!!evs. [| A ~: bad; B ~: bad; evs : ns_public |]
paulson@3703
   300
       ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs -->
paulson@3683
   301
           Nonce NB ~: analz (spies evs)
paulson@3703
   302
 1. !!C B' evs3.
paulson@3703
   303
       [| A ~: bad; B ~: bad; evs3 : ns_public;
paulson@3703
   304
          Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set evs3;
paulson@3703
   305
          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3; C : bad;
paulson@3703
   306
          Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3;
paulson@3703
   307
          Nonce NB ~: analz (spies evs3) |]
paulson@2318
   308
       ==> False
paulson@2318
   309
*)