src/HOL/Auth/NS_Public_Bad.ML
author paulson
Fri Jun 27 10:47:13 1997 +0200 (1997-06-27)
changeset 3466 30791e5a69c4
parent 3465 e85c24717cad
child 3519 ab0a9fbed4c0
permissions -rw-r--r--
Corrected indentations and margins after the renaming of "set_of_list"
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@2318
    19
AddIffs [Spy_in_lost];
paulson@2318
    20
paulson@2318
    21
(*Replacing the variable by a constant improves search speed by 50%!*)
paulson@2318
    22
val Says_imp_sees_Spy' = 
paulson@2318
    23
    read_instantiate_sg (sign_of thy) [("lost","lost")] Says_imp_sees_Spy;
paulson@2318
    24
paulson@2318
    25
(*A "possibility property": there are traces that reach the end*)
paulson@2318
    26
goal thy 
paulson@2480
    27
 "!!A B. A ~= B ==> EX NB. EX evs: ns_public.               \
nipkow@3465
    28
\                     Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
paulson@2318
    29
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@2318
    30
by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
paulson@2516
    31
by possibility_tac;
paulson@2318
    32
result();
paulson@2318
    33
paulson@2318
    34
paulson@2318
    35
(**** Inductive proofs about ns_public ****)
paulson@2318
    36
paulson@2318
    37
(*Nobody sends themselves messages*)
nipkow@3465
    38
goal thy "!!evs. evs : ns_public ==> ALL A X. Says A A X ~: set evs";
paulson@2318
    39
by (etac ns_public.induct 1);
paulson@2318
    40
by (Auto_tac());
paulson@2318
    41
qed_spec_mp "not_Says_to_self";
paulson@2318
    42
Addsimps [not_Says_to_self];
paulson@2318
    43
AddSEs   [not_Says_to_self RSN (2, rev_notE)];
paulson@2318
    44
paulson@2318
    45
paulson@2318
    46
(** Theorems of the form X ~: parts (sees lost Spy evs) imply that NOBODY
paulson@2318
    47
    sends messages containing X! **)
paulson@2318
    48
paulson@2318
    49
(*Spy never sees another agent's private key! (unless it's lost at start)*)
paulson@2318
    50
goal thy 
paulson@2318
    51
 "!!evs. evs : ns_public \
paulson@2318
    52
\        ==> (Key (priK A) : parts (sees lost Spy evs)) = (A : lost)";
paulson@3121
    53
by (etac ns_public.induct 1);
paulson@3121
    54
by (prove_simple_subgoals_tac 1);
paulson@3121
    55
by (Fake_parts_insert_tac 1);
paulson@2318
    56
qed "Spy_see_priK";
paulson@2318
    57
Addsimps [Spy_see_priK];
paulson@2318
    58
paulson@2318
    59
goal thy 
paulson@2318
    60
 "!!evs. evs : ns_public \
paulson@2318
    61
\        ==> (Key (priK A) : analz (sees lost Spy evs)) = (A : lost)";
paulson@2318
    62
by (auto_tac(!claset addDs [impOfSubs analz_subset_parts], !simpset));
paulson@2318
    63
qed "Spy_analz_priK";
paulson@2318
    64
Addsimps [Spy_analz_priK];
paulson@2318
    65
paulson@2318
    66
goal thy  "!!A. [| Key (priK A) : parts (sees lost Spy evs);       \
paulson@2318
    67
\                  evs : ns_public |] ==> A:lost";
paulson@3121
    68
by (blast_tac (!claset addDs [Spy_see_priK]) 1);
paulson@2318
    69
qed "Spy_see_priK_D";
paulson@2318
    70
paulson@2318
    71
bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
paulson@2318
    72
AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
paulson@2318
    73
paulson@2318
    74
paulson@2418
    75
fun analz_induct_tac i = 
paulson@3121
    76
    etac ns_public.induct i   THEN
paulson@2418
    77
    ALLGOALS (asm_simp_tac 
paulson@2516
    78
              (!simpset addsimps [not_parts_not_analz]
paulson@2480
    79
                        setloop split_tac [expand_if]));
paulson@2418
    80
paulson@2318
    81
paulson@2318
    82
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
    83
paulson@2318
    84
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@2318
    85
  is secret.  (Honest users generate fresh nonces.)*)
paulson@2318
    86
goal thy 
paulson@2536
    87
 "!!evs. [| Nonce NA ~: analz (sees lost Spy evs);  \
paulson@2536
    88
\           Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs); \
paulson@2536
    89
\           evs : ns_public |]                      \
paulson@2536
    90
\ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (sees lost Spy evs)";
paulson@2536
    91
by (etac rev_mp 1);
paulson@2536
    92
by (etac rev_mp 1);
paulson@2418
    93
by (analz_induct_tac 1);
paulson@2318
    94
(*NS3*)
paulson@3121
    95
by (blast_tac (!claset addSEs partsEs) 4);
paulson@2318
    96
(*NS2*)
paulson@3121
    97
by (blast_tac (!claset addSEs partsEs) 3);
paulson@2318
    98
(*Fake*)
paulson@3121
    99
by (blast_tac (!claset addSIs [analz_insertI]
paulson@2536
   100
                        addDs [impOfSubs analz_subset_parts,
paulson@3121
   101
			       impOfSubs Fake_parts_insert]) 2);
paulson@2318
   102
(*Base*)
paulson@3121
   103
by (Blast_tac 1);
paulson@2536
   104
qed "no_nonce_NS1_NS2";
paulson@2318
   105
paulson@2318
   106
paulson@2480
   107
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@2318
   108
goal thy 
paulson@2536
   109
 "!!evs. [| Nonce NA ~: analz (sees lost Spy evs);  evs : ns_public |]      \
paulson@2536
   110
\ ==> EX A' B'. ALL A B.                                                    \
paulson@2318
   111
\      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs) --> \
paulson@2536
   112
\      A=A' & B=B'";
paulson@2536
   113
by (etac rev_mp 1);
paulson@2418
   114
by (analz_induct_tac 1);
paulson@2318
   115
(*NS1*)
paulson@2497
   116
by (simp_tac (!simpset addsimps [all_conj_distrib]) 3);
paulson@2318
   117
by (expand_case_tac "NA = ?y" 3 THEN
paulson@3121
   118
    REPEAT (blast_tac (!claset addSEs partsEs) 3));
paulson@2318
   119
(*Base*)
paulson@3121
   120
by (Blast_tac 1);
paulson@2318
   121
(*Fake*)
paulson@2497
   122
by (simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees]) 1);
paulson@2374
   123
by (step_tac (!claset addSIs [analz_insertI]) 1);
paulson@2318
   124
by (ex_strip_tac 1);
paulson@3121
   125
by (blast_tac (!claset delrules [conjI]
paulson@3440
   126
                       addSDs [impOfSubs Fake_parts_insert]
paulson@3440
   127
                       addDs  [impOfSubs analz_subset_parts]) 1);
paulson@2318
   128
val lemma = result();
paulson@2318
   129
paulson@2318
   130
goal thy 
paulson@2318
   131
 "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(sees lost Spy evs); \
paulson@2318
   132
\           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(sees lost Spy evs); \
paulson@2318
   133
\           Nonce NA ~: analz (sees lost Spy evs);                            \
paulson@2318
   134
\           evs : ns_public |]                                                \
paulson@2318
   135
\        ==> A=A' & B=B'";
paulson@2418
   136
by (prove_unique_tac lemma 1);
paulson@2318
   137
qed "unique_NA";
paulson@2318
   138
paulson@2318
   139
paulson@2318
   140
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
paulson@2318
   141
goal thy 
paulson@3466
   142
 "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;         \
paulson@2536
   143
\           A ~: lost;  B ~: lost;  evs : ns_public |]                        \
paulson@2536
   144
\        ==>  Nonce NA ~: analz (sees lost Spy evs)";
paulson@2536
   145
by (etac rev_mp 1);
paulson@2418
   146
by (analz_induct_tac 1);
paulson@2318
   147
(*NS3*)
paulson@3121
   148
by (blast_tac (!claset addDs  [Says_imp_sees_Spy' RS parts.Inj]
paulson@3121
   149
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
paulson@2536
   150
(*NS2*)
paulson@3121
   151
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3121
   152
		       addDs  [Says_imp_sees_Spy' RS parts.Inj,
paulson@3121
   153
			       parts.Body, unique_NA]) 3);
paulson@2318
   154
(*NS1*)
paulson@3121
   155
by (blast_tac (!claset addSEs sees_Spy_partsEs
paulson@3121
   156
                       addIs  [impOfSubs analz_subset_parts]) 2);
paulson@2318
   157
(*Fake*)
paulson@2497
   158
by (spy_analz_tac 1);
paulson@2536
   159
qed "Spy_not_see_NA";
paulson@2318
   160
paulson@2318
   161
paulson@2318
   162
(*Authentication for A: if she receives message 2 and has used NA
paulson@2318
   163
  to start a run, then B has sent message 2.*)
paulson@2318
   164
goal thy 
paulson@3466
   165
 "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
paulson@3466
   166
\           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
paulson@3466
   167
\           A ~: lost;  B ~: lost;  evs : ns_public |]                  \
nipkow@3465
   168
\        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
paulson@2536
   169
by (etac rev_mp 1);
paulson@2536
   170
(*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
paulson@2536
   171
by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
paulson@2536
   172
by (etac ns_public.induct 1);
paulson@2318
   173
by (ALLGOALS Asm_simp_tac);
paulson@2318
   174
(*NS1*)
paulson@3121
   175
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   176
(*Fake*)
paulson@3121
   177
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   178
                       addDs  [Spy_not_see_NA, 
paulson@3121
   179
			       impOfSubs analz_subset_parts]) 1);
paulson@3121
   180
(*NS2; not clear why blast_tac needs to be preceeded by Step_tac*)
paulson@2318
   181
by (Step_tac 1);
paulson@3121
   182
by (blast_tac (!claset addDs [Says_imp_sees_Spy' RS parts.Inj,
paulson@3121
   183
			      Spy_not_see_NA, unique_NA]) 1);
paulson@2318
   184
qed "A_trusts_NS2";
paulson@2318
   185
paulson@2318
   186
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@2318
   187
goal thy 
paulson@2536
   188
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs); \
paulson@2536
   189
\           Nonce NA ~: analz (sees lost Spy evs);                 \
paulson@2536
   190
\           evs : ns_public |]                                     \
nipkow@3465
   191
\   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   192
by (etac rev_mp 1);
paulson@2536
   193
by (etac rev_mp 1);
paulson@2418
   194
by (analz_induct_tac 1);
paulson@2318
   195
(*Fake*)
paulson@3121
   196
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   197
                       addIs  [analz_insertI]
paulson@3121
   198
                       addDs  [impOfSubs analz_subset_parts]) 2);
paulson@2318
   199
(*Base*)
paulson@3121
   200
by (Blast_tac 1);
paulson@3121
   201
qed "B_trusts_NS1";
paulson@2318
   202
paulson@2318
   203
paulson@2318
   204
paulson@2318
   205
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
   206
paulson@2480
   207
(*Unicity for NS2: nonce NB identifies agent A and nonce NA
paulson@2318
   208
  [proof closely follows that for unique_NA] *)
paulson@2318
   209
goal thy 
paulson@2536
   210
 "!!evs. [| Nonce NB ~: analz (sees lost Spy evs);  evs : ns_public |]      \
paulson@2536
   211
\ ==> EX A' NA'. ALL A NA.                                                  \
paulson@2536
   212
\      Crypt (pubK A) {|Nonce NA, Nonce NB|}                                \
paulson@2536
   213
\        : parts (sees lost Spy evs)  -->  A=A' & NA=NA'";
paulson@2536
   214
by (etac rev_mp 1);
paulson@2418
   215
by (analz_induct_tac 1);
paulson@2318
   216
(*NS2*)
paulson@2497
   217
by (simp_tac (!simpset addsimps [all_conj_distrib]) 3);
paulson@2318
   218
by (expand_case_tac "NB = ?y" 3 THEN
paulson@3121
   219
    REPEAT (blast_tac (!claset addSEs partsEs) 3));
paulson@2318
   220
(*Base*)
paulson@3121
   221
by (Blast_tac 1);
paulson@2318
   222
(*Fake*)
paulson@2497
   223
by (simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees]) 1);
paulson@2374
   224
by (step_tac (!claset addSIs [analz_insertI]) 1);
paulson@2318
   225
by (ex_strip_tac 1);
paulson@3121
   226
by (blast_tac (!claset delrules [conjI]
paulson@2516
   227
                      addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   228
                      addDs  [impOfSubs analz_subset_parts]) 1);
paulson@2318
   229
val lemma = result();
paulson@2318
   230
paulson@2318
   231
goal thy 
paulson@2318
   232
 "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(sees lost Spy evs); \
paulson@2318
   233
\           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(sees lost Spy evs); \
paulson@2318
   234
\           Nonce NB ~: analz (sees lost Spy evs);                            \
paulson@2318
   235
\           evs : ns_public |]                                                \
paulson@2318
   236
\        ==> A=A' & NA=NA'";
paulson@2418
   237
by (prove_unique_tac lemma 1);
paulson@2318
   238
qed "unique_NB";
paulson@2318
   239
paulson@2318
   240
paulson@2318
   241
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@2318
   242
goal thy 
paulson@3466
   243
 "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
paulson@3466
   244
\          (ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs);    \
paulson@3466
   245
\          A ~: lost;  B ~: lost;  evs : ns_public |]                   \
paulson@2536
   246
\       ==> Nonce NB ~: analz (sees lost Spy evs)";
paulson@2536
   247
by (etac rev_mp 1);
paulson@2536
   248
by (etac rev_mp 1);
paulson@2418
   249
by (analz_induct_tac 1);
paulson@2318
   250
(*NS1*)
paulson@3121
   251
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   252
(*Fake*)
paulson@2497
   253
by (spy_analz_tac 1);
paulson@2318
   254
(*NS2 and NS3*)
paulson@2536
   255
by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib])));
paulson@2536
   256
by (step_tac (!claset delrules [allI]) 1);
paulson@3121
   257
by (Blast_tac 5);
paulson@3121
   258
(*NS3*)
paulson@3440
   259
by (blast_tac (!claset addDs [Says_imp_sees_Spy' RS parts.Inj, unique_NB]) 4);
paulson@2318
   260
(*NS2*)
paulson@3121
   261
by (blast_tac (!claset addSEs sees_Spy_partsEs) 3);
paulson@3121
   262
by (blast_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
paulson@3121
   263
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 2);
paulson@3121
   264
by (blast_tac (!claset addSIs [impOfSubs analz_subset_parts]) 1);
paulson@2536
   265
qed "Spy_not_see_NB";
paulson@2318
   266
paulson@2318
   267
paulson@2318
   268
paulson@2318
   269
(*Authentication for B: if he receives message 3 and has used NB
paulson@2536
   270
  in message 2, then A has sent message 3--to somebody....*)
paulson@2318
   271
goal thy 
paulson@2536
   272
 "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|})          \
paulson@3466
   273
\             : set evs;                                               \
paulson@3466
   274
\           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;            \
paulson@2536
   275
\           A ~: lost;  B ~: lost;  evs : ns_public |]                 \
nipkow@3465
   276
\        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
paulson@2536
   277
by (etac rev_mp 1);
paulson@2536
   278
(*prepare induction over Crypt (pubK B) NB : parts H*)
paulson@2536
   279
by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
paulson@2418
   280
by (analz_induct_tac 1);
paulson@2318
   281
by (ALLGOALS (asm_simp_tac (!simpset addsimps [ex_disj_distrib])));
paulson@2318
   282
(*NS1*)
paulson@3121
   283
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   284
(*Fake*)
paulson@3121
   285
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   286
                       addDs  [Spy_not_see_NB, 
paulson@3121
   287
			       impOfSubs analz_subset_parts]) 1);
paulson@3121
   288
(*NS3; not clear why blast_tac needs to be preceeded by Step_tac*)
paulson@2318
   289
by (Step_tac 1);
paulson@3121
   290
by (blast_tac (!claset addDs [Says_imp_sees_Spy' RS parts.Inj,
paulson@3121
   291
			      Spy_not_see_NB, unique_NB]) 1);
paulson@2318
   292
qed "B_trusts_NS3";
paulson@2318
   293
paulson@2318
   294
paulson@2318
   295
(*Can we strengthen the secrecy theorem?  NO*)
paulson@2318
   296
goal thy 
paulson@3466
   297
 "!!evs. [| A ~: lost;  B ~: lost;  evs : ns_public |]           \
nipkow@3465
   298
\ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
paulson@2318
   299
\     --> Nonce NB ~: analz (sees lost Spy evs)";
paulson@2418
   300
by (analz_induct_tac 1);
paulson@2318
   301
(*NS1*)
paulson@3121
   302
by (blast_tac (!claset addSEs partsEs
paulson@3121
   303
                       addSDs [Says_imp_sees_Spy' RS parts.Inj]) 2);
paulson@2318
   304
(*Fake*)
paulson@2497
   305
by (spy_analz_tac 1);
paulson@2318
   306
(*NS2 and NS3*)
paulson@2318
   307
by (Step_tac 1);
paulson@3121
   308
by (blast_tac (!claset addSIs [impOfSubs analz_subset_parts, usedI]) 1);
paulson@2318
   309
(*NS2*)
paulson@3121
   310
by (blast_tac (!claset addSEs partsEs
paulson@3121
   311
                       addSDs [Says_imp_sees_Spy' RS parts.Inj]) 2);
paulson@3121
   312
by (blast_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
paulson@3121
   313
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 1);
paulson@2318
   314
(*NS3*)
paulson@2318
   315
by (forw_inst_tac [("A'","A")] (Says_imp_sees_Spy' RS parts.Inj RS unique_NB) 1
paulson@2318
   316
    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_sees_Spy' RS parts.Inj] 1));
paulson@2318
   317
by (Step_tac 1);
paulson@2318
   318
paulson@2318
   319
(*
paulson@2318
   320
THIS IS THE ATTACK!
paulson@2318
   321
Level 9
paulson@2318
   322
!!evs. [| A ~: lost; B ~: lost; evs : ns_public |]
paulson@2318
   323
       ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|})
nipkow@3465
   324
           : set evs -->
paulson@2318
   325
           Nonce NB ~: analz (sees lost Spy evs)
paulson@2318
   326
 1. !!evs Aa Ba B' NAa NBa evsa.
paulson@2318
   327
       [| A ~: lost; B ~: lost; evsa : ns_public; A ~= Ba;
nipkow@3465
   328
          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evsa;
nipkow@3465
   329
          Says A Ba (Crypt (pubK Ba) {|Nonce NA, Agent A|}) : set evsa;
paulson@2318
   330
          Ba : lost;
nipkow@3465
   331
          Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evsa;
paulson@2318
   332
          Nonce NB ~: analz (sees lost Spy evsa) |]
paulson@2318
   333
       ==> False
paulson@2318
   334
*)
paulson@2318
   335
paulson@2318
   336
paulson@2318
   337