src/HOL/Auth/NS_Public_Bad.ML
author paulson
Wed Dec 24 10:02:30 1997 +0100 (1997-12-24)
changeset 4477 b3e5857d8d99
parent 4476 fbdc87f8ac7e
child 4551 41fa62c229c3
permissions -rw-r--r--
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
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
wenzelm@4449
    16
set proof_timing;
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@4477
    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@4476
    70
AddSDs [Spy_see_priK RSN (2, rev_iffD1), 
paulson@4476
    71
	Spy_analz_priK RSN (2, rev_iffD1)];
paulson@2318
    72
paulson@2318
    73
paulson@3519
    74
(**** Authenticity properties obtained from NS2 ****)
paulson@3519
    75
paulson@3519
    76
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@3519
    77
  is secret.  (Honest users generate fresh nonces.)*)
paulson@3519
    78
goal thy 
paulson@3683
    79
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
paulson@3683
    80
\           Nonce NA ~: analz (spies evs);   evs : ns_public |]       \
paulson@3683
    81
\ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies evs)";
paulson@3519
    82
by (etac rev_mp 1);
paulson@3519
    83
by (etac rev_mp 1);
paulson@3519
    84
by (parts_induct_tac 1);
paulson@3519
    85
(*NS3*)
wenzelm@4091
    86
by (blast_tac (claset() addSEs partsEs) 3);
paulson@3519
    87
(*NS2*)
wenzelm@4091
    88
by (blast_tac (claset() addSEs partsEs) 2);
paulson@3519
    89
by (Fake_parts_insert_tac 1);
paulson@3519
    90
qed "no_nonce_NS1_NS2";
paulson@3519
    91
paulson@3519
    92
paulson@3519
    93
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@3519
    94
goal thy 
paulson@3683
    95
 "!!evs. [| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
paulson@3709
    96
\ ==> EX A' B'. ALL A B.                                            \
paulson@3683
    97
\      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
paulson@3519
    98
\      A=A' & B=B'";
paulson@3519
    99
by (etac rev_mp 1);
paulson@3519
   100
by (parts_induct_tac 1);
paulson@3519
   101
by (ALLGOALS
paulson@4476
   102
    (asm_simp_tac (simpset() addsimps [all_conj_distrib, 
paulson@4476
   103
				       parts_insert_spies])));
paulson@3519
   104
(*NS1*)
wenzelm@4091
   105
by (expand_case_tac "NA = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
paulson@3519
   106
(*Fake*)
paulson@3709
   107
by (Clarify_tac 1);
paulson@3519
   108
by (ex_strip_tac 1);
paulson@3519
   109
by (Fake_parts_insert_tac 1);
paulson@3519
   110
val lemma = result();
paulson@3519
   111
paulson@3519
   112
goal thy 
paulson@3683
   113
 "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
paulson@3683
   114
\           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
paulson@3683
   115
\           Nonce NA ~: analz (spies evs);                            \
paulson@3709
   116
\           evs : ns_public |]                                        \
paulson@3519
   117
\        ==> A=A' & B=B'";
paulson@3519
   118
by (prove_unique_tac lemma 1);
paulson@3519
   119
qed "unique_NA";
paulson@3519
   120
paulson@3519
   121
paulson@3519
   122
(*Tactic for proving secrecy theorems*)
paulson@2418
   123
fun analz_induct_tac i = 
paulson@3121
   124
    etac ns_public.induct i   THEN
wenzelm@4091
   125
    ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if]));
paulson@2418
   126
paulson@2318
   127
paulson@2318
   128
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
paulson@2318
   129
goal thy 
paulson@3709
   130
 "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;   \
paulson@3683
   131
\           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
paulson@3683
   132
\        ==>  Nonce NA ~: analz (spies evs)";
paulson@2536
   133
by (etac rev_mp 1);
paulson@2418
   134
by (analz_induct_tac 1);
paulson@2318
   135
(*NS3*)
wenzelm@4091
   136
by (blast_tac (claset() addDs  [Says_imp_spies RS parts.Inj]
paulson@4476
   137
                        addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
paulson@2536
   138
(*NS2*)
wenzelm@4091
   139
by (blast_tac (claset() addSEs [MPair_parts]
paulson@3683
   140
		       addDs  [Says_imp_spies RS parts.Inj,
paulson@3121
   141
			       parts.Body, unique_NA]) 3);
paulson@2318
   142
(*NS1*)
wenzelm@4091
   143
by (blast_tac (claset() addSEs spies_partsEs
paulson@3121
   144
                       addIs  [impOfSubs analz_subset_parts]) 2);
paulson@2318
   145
(*Fake*)
paulson@2497
   146
by (spy_analz_tac 1);
paulson@2536
   147
qed "Spy_not_see_NA";
paulson@2318
   148
paulson@2318
   149
paulson@2318
   150
(*Authentication for A: if she receives message 2 and has used NA
paulson@2318
   151
  to start a run, then B has sent message 2.*)
paulson@2318
   152
goal thy 
paulson@3466
   153
 "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
paulson@3466
   154
\           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
paulson@3709
   155
\           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
nipkow@3465
   156
\        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
paulson@2536
   157
by (etac rev_mp 1);
paulson@2536
   158
(*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
paulson@3683
   159
by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
paulson@2536
   160
by (etac ns_public.induct 1);
paulson@2318
   161
by (ALLGOALS Asm_simp_tac);
paulson@3709
   162
by (ALLGOALS Clarify_tac);
paulson@3709
   163
(*NS2*)
wenzelm@4091
   164
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj,
paulson@3709
   165
			      Spy_not_see_NA, unique_NA]) 3);
paulson@2318
   166
(*NS1*)
wenzelm@4091
   167
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   168
(*Fake*)
wenzelm@4091
   169
by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   170
                       addDs  [Spy_not_see_NA, 
paulson@3121
   171
			       impOfSubs analz_subset_parts]) 1);
paulson@2318
   172
qed "A_trusts_NS2";
paulson@2318
   173
paulson@2318
   174
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@2318
   175
goal thy 
paulson@3683
   176
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
paulson@3683
   177
\           Nonce NA ~: analz (spies evs);                            \
paulson@3709
   178
\           evs : ns_public |]                                        \
nipkow@3465
   179
\   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   180
by (etac rev_mp 1);
paulson@2536
   181
by (etac rev_mp 1);
paulson@3519
   182
by (parts_induct_tac 1);
paulson@3519
   183
by (Fake_parts_insert_tac 1);
paulson@3121
   184
qed "B_trusts_NS1";
paulson@2318
   185
paulson@2318
   186
paulson@2318
   187
paulson@2318
   188
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
   189
paulson@2480
   190
(*Unicity for NS2: nonce NB identifies agent A and nonce NA
paulson@2318
   191
  [proof closely follows that for unique_NA] *)
paulson@2318
   192
goal thy 
paulson@3683
   193
 "!!evs. [| Nonce NB ~: analz (spies evs);  evs : ns_public |]  \
paulson@3709
   194
\ ==> EX A' NA'. ALL A NA.                                      \
paulson@3709
   195
\      Crypt (pubK A) {|Nonce NA, Nonce NB|}                    \
paulson@3683
   196
\        : parts (spies evs)  -->  A=A' & NA=NA'";
paulson@2536
   197
by (etac rev_mp 1);
paulson@3519
   198
by (parts_induct_tac 1);
paulson@3519
   199
by (ALLGOALS
wenzelm@4091
   200
    (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
paulson@2318
   201
(*NS2*)
wenzelm@4091
   202
by (expand_case_tac "NB = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
paulson@2318
   203
(*Fake*)
paulson@3709
   204
by (Clarify_tac 1);
paulson@2318
   205
by (ex_strip_tac 1);
paulson@3519
   206
by (Fake_parts_insert_tac 1);
paulson@2318
   207
val lemma = result();
paulson@2318
   208
paulson@2318
   209
goal thy 
paulson@3683
   210
 "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies evs); \
paulson@3683
   211
\           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies evs); \
paulson@3683
   212
\           Nonce NB ~: analz (spies evs);                            \
paulson@3709
   213
\           evs : ns_public |]                                        \
paulson@2318
   214
\        ==> A=A' & NA=NA'";
paulson@2418
   215
by (prove_unique_tac lemma 1);
paulson@2318
   216
qed "unique_NB";
paulson@2318
   217
paulson@2318
   218
paulson@2318
   219
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@2318
   220
goal thy 
paulson@3466
   221
 "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
paulson@3703
   222
\          ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs;      \
paulson@3703
   223
\          A ~: bad;  B ~: bad;  evs : ns_public |]                     \
paulson@3683
   224
\       ==> Nonce NB ~: analz (spies evs)";
paulson@2536
   225
by (etac rev_mp 1);
paulson@2536
   226
by (etac rev_mp 1);
paulson@2418
   227
by (analz_induct_tac 1);
wenzelm@4091
   228
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@3709
   229
by (ALLGOALS Clarify_tac);
paulson@3703
   230
(*NS3: because NB determines A*)
wenzelm@4091
   231
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, unique_NB]) 4);
paulson@3703
   232
(*NS2: by freshness and unicity of NB*)
wenzelm@4091
   233
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
paulson@3703
   234
                       addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
paulson@3703
   235
                       addEs partsEs
paulson@3703
   236
		       addIs [impOfSubs analz_subset_parts]) 3);
paulson@3703
   237
(*NS1: by freshness*)
wenzelm@4091
   238
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   239
(*Fake*)
paulson@2497
   240
by (spy_analz_tac 1);
paulson@2536
   241
qed "Spy_not_see_NB";
paulson@2318
   242
paulson@2318
   243
paulson@2318
   244
paulson@2318
   245
(*Authentication for B: if he receives message 3 and has used NB
paulson@2536
   246
  in message 2, then A has sent message 3--to somebody....*)
paulson@2318
   247
goal thy 
paulson@3545
   248
 "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs; \
paulson@3545
   249
\           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;              \
paulson@3683
   250
\           A ~: bad;  B ~: bad;  evs : ns_public |]                   \
nipkow@3465
   251
\        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
paulson@2536
   252
by (etac rev_mp 1);
paulson@2536
   253
(*prepare induction over Crypt (pubK B) NB : parts H*)
paulson@3683
   254
by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
paulson@3519
   255
by (parts_induct_tac 1);
wenzelm@4091
   256
by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
paulson@3709
   257
by (ALLGOALS Clarify_tac);
paulson@4197
   258
(*NS3: because NB determines A (this use of unique_NB is more robust) *)
paulson@4197
   259
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, Spy_not_see_NB]
paulson@4197
   260
			addIs [unique_NB RS conjunct1]) 3);
paulson@3703
   261
(*NS1: by freshness*)
wenzelm@4091
   262
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   263
(*Fake*)
wenzelm@4091
   264
by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   265
                       addDs  [Spy_not_see_NB, 
paulson@3121
   266
			       impOfSubs analz_subset_parts]) 1);
paulson@2318
   267
qed "B_trusts_NS3";
paulson@2318
   268
paulson@2318
   269
paulson@2318
   270
(*Can we strengthen the secrecy theorem?  NO*)
paulson@2318
   271
goal thy 
paulson@3683
   272
 "!!evs. [| A ~: bad;  B ~: bad;  evs : ns_public |]           \
nipkow@3465
   273
\ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
paulson@3683
   274
\     --> Nonce NB ~: analz (spies evs)";
paulson@2418
   275
by (analz_induct_tac 1);
paulson@3709
   276
by (ALLGOALS Clarify_tac);
paulson@3703
   277
(*NS2: by freshness and unicity of NB*)
wenzelm@4091
   278
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
paulson@3703
   279
                       addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
paulson@3703
   280
                       addEs partsEs
paulson@3703
   281
		       addIs [impOfSubs analz_subset_parts]) 3);
paulson@3703
   282
(*NS1: by freshness*)
wenzelm@4091
   283
by (blast_tac (claset() addSEs spies_partsEs) 2);
paulson@2318
   284
(*Fake*)
paulson@2497
   285
by (spy_analz_tac 1);
paulson@3703
   286
(*NS3: unicity of NB identifies A and NA, but not B*)
paulson@3683
   287
by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
paulson@3683
   288
    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
paulson@4477
   289
by Auto_tac;
paulson@3703
   290
by (rename_tac "C B' evs3" 1);
paulson@2318
   291
paulson@2318
   292
(*
paulson@2318
   293
THIS IS THE ATTACK!
paulson@3703
   294
Level 8
paulson@3683
   295
!!evs. [| A ~: bad; B ~: bad; evs : ns_public |]
paulson@3703
   296
       ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs -->
paulson@3683
   297
           Nonce NB ~: analz (spies evs)
paulson@3703
   298
 1. !!C B' evs3.
paulson@3703
   299
       [| A ~: bad; B ~: bad; evs3 : ns_public;
paulson@3703
   300
          Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set evs3;
paulson@3703
   301
          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3; C : bad;
paulson@3703
   302
          Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3;
paulson@3703
   303
          Nonce NB ~: analz (spies evs3) |]
paulson@2318
   304
       ==> False
paulson@2318
   305
*)