src/HOL/Auth/NS_Public_Bad.ML
author paulson
Mon Jul 14 12:47:21 1997 +0200 (1997-07-14)
changeset 3519 ab0a9fbed4c0
parent 3466 30791e5a69c4
child 3545 4336eb0486bc
permissions -rw-r--r--
Changing "lost" from a parameter of protocol definitions to a constant.

Advantages: no "lost" argument everywhere; fewer Vars in subgoals;
less need for specially instantiated rules
Disadvantage: can no longer prove "Agent_not_see_encrypted_key", but this
theorem was never used, and its original proof was also broken
the introduction of the "Notes" constructor.
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
(*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@3519
    43
   X ~: analz (sees Spy evs) --> ... then it shortens the proof by discarding
paulson@3519
    44
   needless information about analz (insert X (sees Spy 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@3519
    53
(** Theorems of the form X ~: parts (sees Spy evs) imply that NOBODY
paulson@2318
    54
    sends messages containing X! **)
paulson@2318
    55
paulson@2318
    56
(*Spy never sees another agent's private key! (unless it's lost at start)*)
paulson@2318
    57
goal thy 
paulson@3519
    58
 "!!A. evs: ns_public ==> (Key (priK A) : parts (sees Spy evs)) = (A : lost)";
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@3519
    65
 "!!A. evs: ns_public ==> (Key (priK A) : analz (sees Spy evs)) = (A : lost)";
paulson@2318
    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@3519
    70
goal thy  "!!A. [| Key (priK A) : parts (sees Spy evs);       \
paulson@2318
    71
\                  evs : ns_public |] ==> A:lost";
paulson@3121
    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@3519
    84
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees Spy evs); \
paulson@3519
    85
\           Nonce NA ~: analz (sees Spy evs);       \
paulson@3519
    86
\           evs : ns_public |]                      \
paulson@3519
    87
\ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (sees Spy evs)";
paulson@3519
    88
by (etac rev_mp 1);
paulson@3519
    89
by (etac rev_mp 1);
paulson@3519
    90
by (parts_induct_tac 1);
paulson@3519
    91
(*NS3*)
paulson@3519
    92
by (blast_tac (!claset addSEs partsEs) 3);
paulson@3519
    93
(*NS2*)
paulson@3519
    94
by (blast_tac (!claset addSEs partsEs) 2);
paulson@3519
    95
by (Fake_parts_insert_tac 1);
paulson@3519
    96
qed "no_nonce_NS1_NS2";
paulson@3519
    97
paulson@3519
    98
paulson@3519
    99
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@3519
   100
goal thy 
paulson@3519
   101
 "!!evs. [| Nonce NA ~: analz (sees Spy evs);  evs : ns_public |]      \
paulson@3519
   102
\ ==> EX A' B'. ALL A B.                                               \
paulson@3519
   103
\      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees Spy evs) --> \
paulson@3519
   104
\      A=A' & B=B'";
paulson@3519
   105
by (etac rev_mp 1);
paulson@3519
   106
by (parts_induct_tac 1);
paulson@3519
   107
by (ALLGOALS
paulson@3519
   108
    (asm_simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees])));
paulson@3519
   109
(*NS1*)
paulson@3519
   110
by (expand_case_tac "NA = ?y" 2 THEN blast_tac (!claset addSEs partsEs) 2);
paulson@3519
   111
(*Fake*)
paulson@3519
   112
by (step_tac (!claset addSIs [analz_insertI]) 1);
paulson@3519
   113
by (ex_strip_tac 1);
paulson@3519
   114
by (Fake_parts_insert_tac 1);
paulson@3519
   115
val lemma = result();
paulson@3519
   116
paulson@3519
   117
goal thy 
paulson@3519
   118
 "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(sees Spy evs); \
paulson@3519
   119
\           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(sees Spy evs); \
paulson@3519
   120
\           Nonce NA ~: analz (sees Spy evs);                            \
paulson@3519
   121
\           evs : ns_public |]                                                \
paulson@3519
   122
\        ==> A=A' & B=B'";
paulson@3519
   123
by (prove_unique_tac lemma 1);
paulson@3519
   124
qed "unique_NA";
paulson@3519
   125
paulson@3519
   126
paulson@3519
   127
(*Tactic for proving secrecy theorems*)
paulson@2418
   128
fun analz_induct_tac i = 
paulson@3121
   129
    etac ns_public.induct i   THEN
paulson@2418
   130
    ALLGOALS (asm_simp_tac 
paulson@2516
   131
              (!simpset addsimps [not_parts_not_analz]
paulson@2480
   132
                        setloop split_tac [expand_if]));
paulson@2418
   133
paulson@2318
   134
paulson@2318
   135
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
paulson@2318
   136
goal thy 
paulson@3466
   137
 "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;         \
paulson@2536
   138
\           A ~: lost;  B ~: lost;  evs : ns_public |]                        \
paulson@3519
   139
\        ==>  Nonce NA ~: analz (sees Spy evs)";
paulson@2536
   140
by (etac rev_mp 1);
paulson@2418
   141
by (analz_induct_tac 1);
paulson@2318
   142
(*NS3*)
paulson@3519
   143
by (blast_tac (!claset addDs  [Says_imp_sees_Spy RS parts.Inj]
paulson@3121
   144
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
paulson@2536
   145
(*NS2*)
paulson@3121
   146
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3519
   147
		       addDs  [Says_imp_sees_Spy RS parts.Inj,
paulson@3121
   148
			       parts.Body, unique_NA]) 3);
paulson@2318
   149
(*NS1*)
paulson@3121
   150
by (blast_tac (!claset addSEs sees_Spy_partsEs
paulson@3121
   151
                       addIs  [impOfSubs analz_subset_parts]) 2);
paulson@2318
   152
(*Fake*)
paulson@2497
   153
by (spy_analz_tac 1);
paulson@2536
   154
qed "Spy_not_see_NA";
paulson@2318
   155
paulson@2318
   156
paulson@2318
   157
(*Authentication for A: if she receives message 2 and has used NA
paulson@2318
   158
  to start a run, then B has sent message 2.*)
paulson@2318
   159
goal thy 
paulson@3466
   160
 "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
paulson@3466
   161
\           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
paulson@3466
   162
\           A ~: lost;  B ~: lost;  evs : ns_public |]                  \
nipkow@3465
   163
\        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
paulson@2536
   164
by (etac rev_mp 1);
paulson@2536
   165
(*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
paulson@3519
   166
by (etac (Says_imp_sees_Spy RS parts.Inj RS rev_mp) 1);
paulson@2536
   167
by (etac ns_public.induct 1);
paulson@2318
   168
by (ALLGOALS Asm_simp_tac);
paulson@2318
   169
(*NS1*)
paulson@3121
   170
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   171
(*Fake*)
paulson@3121
   172
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   173
                       addDs  [Spy_not_see_NA, 
paulson@3121
   174
			       impOfSubs analz_subset_parts]) 1);
paulson@3121
   175
(*NS2; not clear why blast_tac needs to be preceeded by Step_tac*)
paulson@2318
   176
by (Step_tac 1);
paulson@3519
   177
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj,
paulson@3121
   178
			      Spy_not_see_NA, unique_NA]) 1);
paulson@2318
   179
qed "A_trusts_NS2";
paulson@2318
   180
paulson@2318
   181
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@2318
   182
goal thy 
paulson@3519
   183
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees Spy evs); \
paulson@3519
   184
\           Nonce NA ~: analz (sees Spy evs);                 \
paulson@2536
   185
\           evs : ns_public |]                                     \
nipkow@3465
   186
\   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   187
by (etac rev_mp 1);
paulson@2536
   188
by (etac rev_mp 1);
paulson@3519
   189
by (parts_induct_tac 1);
paulson@3519
   190
by (Fake_parts_insert_tac 1);
paulson@3121
   191
qed "B_trusts_NS1";
paulson@2318
   192
paulson@2318
   193
paulson@2318
   194
paulson@2318
   195
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
   196
paulson@2480
   197
(*Unicity for NS2: nonce NB identifies agent A and nonce NA
paulson@2318
   198
  [proof closely follows that for unique_NA] *)
paulson@2318
   199
goal thy 
paulson@3519
   200
 "!!evs. [| Nonce NB ~: analz (sees Spy evs);  evs : ns_public |]      \
paulson@2536
   201
\ ==> EX A' NA'. ALL A NA.                                                  \
paulson@2536
   202
\      Crypt (pubK A) {|Nonce NA, Nonce NB|}                                \
paulson@3519
   203
\        : parts (sees Spy evs)  -->  A=A' & NA=NA'";
paulson@2536
   204
by (etac rev_mp 1);
paulson@3519
   205
by (parts_induct_tac 1);
paulson@3519
   206
by (ALLGOALS
paulson@3519
   207
    (asm_simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees])));
paulson@2318
   208
(*NS2*)
paulson@3519
   209
by (expand_case_tac "NB = ?y" 2 THEN blast_tac (!claset addSEs partsEs) 2);
paulson@2318
   210
(*Fake*)
paulson@2374
   211
by (step_tac (!claset addSIs [analz_insertI]) 1);
paulson@2318
   212
by (ex_strip_tac 1);
paulson@3519
   213
by (Fake_parts_insert_tac 1);
paulson@2318
   214
val lemma = result();
paulson@2318
   215
paulson@2318
   216
goal thy 
paulson@3519
   217
 "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(sees Spy evs); \
paulson@3519
   218
\           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(sees Spy evs); \
paulson@3519
   219
\           Nonce NB ~: analz (sees Spy evs);                            \
paulson@2318
   220
\           evs : ns_public |]                                                \
paulson@2318
   221
\        ==> A=A' & NA=NA'";
paulson@2418
   222
by (prove_unique_tac lemma 1);
paulson@2318
   223
qed "unique_NB";
paulson@2318
   224
paulson@2318
   225
paulson@2318
   226
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@2318
   227
goal thy 
paulson@3466
   228
 "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
paulson@3466
   229
\          (ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs);    \
paulson@3466
   230
\          A ~: lost;  B ~: lost;  evs : ns_public |]                   \
paulson@3519
   231
\       ==> Nonce NB ~: analz (sees Spy evs)";
paulson@2536
   232
by (etac rev_mp 1);
paulson@2536
   233
by (etac rev_mp 1);
paulson@2418
   234
by (analz_induct_tac 1);
paulson@2318
   235
(*NS1*)
paulson@3121
   236
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   237
(*Fake*)
paulson@2497
   238
by (spy_analz_tac 1);
paulson@2318
   239
(*NS2 and NS3*)
paulson@2536
   240
by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib])));
paulson@2536
   241
by (step_tac (!claset delrules [allI]) 1);
paulson@3121
   242
by (Blast_tac 5);
paulson@3121
   243
(*NS3*)
paulson@3519
   244
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj, unique_NB]) 4);
paulson@2318
   245
(*NS2*)
paulson@3121
   246
by (blast_tac (!claset addSEs sees_Spy_partsEs) 3);
paulson@3519
   247
by (blast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
paulson@3121
   248
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 2);
paulson@3121
   249
by (blast_tac (!claset addSIs [impOfSubs analz_subset_parts]) 1);
paulson@2536
   250
qed "Spy_not_see_NB";
paulson@2318
   251
paulson@2318
   252
paulson@2318
   253
paulson@2318
   254
(*Authentication for B: if he receives message 3 and has used NB
paulson@2536
   255
  in message 2, then A has sent message 3--to somebody....*)
paulson@2318
   256
goal thy 
paulson@2536
   257
 "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|})          \
paulson@3466
   258
\             : set evs;                                               \
paulson@3466
   259
\           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;            \
paulson@2536
   260
\           A ~: lost;  B ~: lost;  evs : ns_public |]                 \
nipkow@3465
   261
\        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
paulson@2536
   262
by (etac rev_mp 1);
paulson@2536
   263
(*prepare induction over Crypt (pubK B) NB : parts H*)
paulson@3519
   264
by (etac (Says_imp_sees_Spy RS parts.Inj RS rev_mp) 1);
paulson@3519
   265
by (parts_induct_tac 1);
paulson@2318
   266
by (ALLGOALS (asm_simp_tac (!simpset addsimps [ex_disj_distrib])));
paulson@2318
   267
(*NS1*)
paulson@3121
   268
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   269
(*Fake*)
paulson@3121
   270
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   271
                       addDs  [Spy_not_see_NB, 
paulson@3121
   272
			       impOfSubs analz_subset_parts]) 1);
paulson@3121
   273
(*NS3; not clear why blast_tac needs to be preceeded by Step_tac*)
paulson@2318
   274
by (Step_tac 1);
paulson@3519
   275
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj,
paulson@3121
   276
			      Spy_not_see_NB, unique_NB]) 1);
paulson@2318
   277
qed "B_trusts_NS3";
paulson@2318
   278
paulson@2318
   279
paulson@2318
   280
(*Can we strengthen the secrecy theorem?  NO*)
paulson@2318
   281
goal thy 
paulson@3466
   282
 "!!evs. [| A ~: lost;  B ~: lost;  evs : ns_public |]           \
nipkow@3465
   283
\ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
paulson@3519
   284
\     --> Nonce NB ~: analz (sees Spy evs)";
paulson@2418
   285
by (analz_induct_tac 1);
paulson@2318
   286
(*NS1*)
paulson@3121
   287
by (blast_tac (!claset addSEs partsEs
paulson@3519
   288
                       addSDs [Says_imp_sees_Spy RS parts.Inj]) 2);
paulson@2318
   289
(*Fake*)
paulson@2497
   290
by (spy_analz_tac 1);
paulson@2318
   291
(*NS2 and NS3*)
paulson@2318
   292
by (Step_tac 1);
paulson@3121
   293
by (blast_tac (!claset addSIs [impOfSubs analz_subset_parts, usedI]) 1);
paulson@2318
   294
(*NS2*)
paulson@3121
   295
by (blast_tac (!claset addSEs partsEs
paulson@3519
   296
                       addSDs [Says_imp_sees_Spy RS parts.Inj]) 2);
paulson@3519
   297
by (blast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
paulson@3121
   298
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 1);
paulson@2318
   299
(*NS3*)
paulson@3519
   300
by (forw_inst_tac [("A'","A")] (Says_imp_sees_Spy RS parts.Inj RS unique_NB) 1
paulson@3519
   301
    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_sees_Spy RS parts.Inj] 1));
paulson@2318
   302
by (Step_tac 1);
paulson@2318
   303
paulson@2318
   304
(*
paulson@2318
   305
THIS IS THE ATTACK!
paulson@2318
   306
Level 9
paulson@2318
   307
!!evs. [| A ~: lost; B ~: lost; evs : ns_public |]
paulson@2318
   308
       ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|})
nipkow@3465
   309
           : set evs -->
paulson@3519
   310
           Nonce NB ~: analz (sees Spy evs)
paulson@2318
   311
 1. !!evs Aa Ba B' NAa NBa evsa.
paulson@2318
   312
       [| A ~: lost; B ~: lost; evsa : ns_public; A ~= Ba;
nipkow@3465
   313
          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evsa;
nipkow@3465
   314
          Says A Ba (Crypt (pubK Ba) {|Nonce NA, Agent A|}) : set evsa;
paulson@2318
   315
          Ba : lost;
nipkow@3465
   316
          Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evsa;
paulson@3519
   317
          Nonce NB ~: analz (sees Spy evsa) |]
paulson@2318
   318
       ==> False
paulson@2318
   319
*)
paulson@2318
   320
paulson@2318
   321
paulson@2318
   322