src/HOL/UNITY/Simple/NSP_Bad.ML
author paulson
Sat Feb 08 16:05:33 2003 +0100 (2003-02-08)
changeset 13812 91713a1915ee
parent 13797 baefae13ad37
permissions -rw-r--r--
converting HOL/UNITY to use unconditional fairness
paulson@11195
     1
(*  Title:      HOL/Auth/NSP_Bad
paulson@11195
     2
    ID:         $Id$
paulson@11195
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@11195
     4
    Copyright   1996  University of Cambridge
paulson@11195
     5
paulson@11195
     6
Inductive relation "ns_public" for the Needham-Schroeder Public-Key protocol.
paulson@11195
     7
Flawed version, vulnerable to Lowe's attack.
paulson@11195
     8
paulson@11195
     9
From page 260 of
paulson@11195
    10
  Burrows, Abadi and Needham.  A Logic of Authentication.
paulson@11195
    11
  Proc. Royal Soc. 426 (1989)
paulson@11195
    12
*)
paulson@11195
    13
paulson@11195
    14
fun impOfAlways th =
wenzelm@11782
    15
  ObjectLogic.rulify (th RS Always_includes_reachable RS subsetD RS CollectD);
paulson@11195
    16
paulson@11195
    17
AddEs spies_partsEs;
paulson@11195
    18
AddDs [impOfSubs analz_subset_parts];
paulson@11195
    19
AddDs [impOfSubs Fake_parts_insert];
paulson@11195
    20
paulson@11195
    21
(*For other theories, e.g. Mutex and Lift, using AddIffs slows proofs down.
paulson@11195
    22
  Here, it facilitates re-use of the Auth proofs.*)
paulson@11195
    23
paulson@11195
    24
AddIffs (map simp_of_act [Fake_def, NS1_def, NS2_def, NS3_def]);
paulson@13812
    25
Addsimps [Nprg_def RS def_prg_Init];
paulson@11195
    26
paulson@11195
    27
paulson@11195
    28
(*A "possibility property": there are traces that reach the end.
paulson@11195
    29
  Replace by LEADSTO proof!*)
paulson@11195
    30
Goal "A ~= B ==> EX NB. EX s: reachable Nprg.                \
paulson@11195
    31
\                  Says A B (Crypt (pubK B) (Nonce NB)) : set s";
paulson@11195
    32
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@13812
    33
by (res_inst_tac [("act", "totalize_act NS3")] reachable_Acts 2);
paulson@13812
    34
by (res_inst_tac [("act", "totalize_act NS2")] reachable_Acts 3);
paulson@13812
    35
by (res_inst_tac [("act", "totalize_act NS1")] reachable_Acts 4);
paulson@13797
    36
by (rtac reachable_Init 5);
paulson@13812
    37
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Nprg_def, totalize_act_def])));
paulson@13812
    38
  (*Now ignore the possibility of identity transitions*)
paulson@13812
    39
by (REPEAT_FIRST (resolve_tac [disjI1, exI]));
paulson@11195
    40
by possibility_tac;
paulson@11195
    41
result();
paulson@11195
    42
paulson@11195
    43
paulson@11195
    44
(**** Inductive proofs about ns_public ****)
paulson@11195
    45
paulson@11195
    46
(*can be used to simulate analz_mono_contra_tac
paulson@11195
    47
val analz_impI = read_instantiate_sg (sign_of thy)
paulson@11195
    48
                [("P", "?Y ~: analz (spies ?evs)")] impI;
paulson@11195
    49
paulson@11195
    50
val spies_Says_analz_contraD = 
paulson@11195
    51
    spies_subset_spies_Says RS analz_mono RS contra_subsetD;
paulson@11195
    52
paulson@11195
    53
by (rtac analz_impI 2);
paulson@11195
    54
by (auto_tac (claset() addSDs [spies_Says_analz_contraD], simpset()));
paulson@11195
    55
*)
paulson@11195
    56
paulson@13812
    57
val [prem] = 
paulson@13812
    58
Goal "(!!act s s'. [| act: {Id, Fake, NS1, NS2, NS3};  \
paulson@13812
    59
\                     (s,s') \\<in> act;  s \\<in> A |] ==> s': A')  \
paulson@13812
    60
\     ==> Nprg \\<in> A co A'";
paulson@13812
    61
by (asm_full_simp_tac (simpset() addsimps [Nprg_def, mk_total_program_def]) 1);
paulson@13812
    62
by (rtac constrainsI 1); 
paulson@13812
    63
by (rtac prem 1); 
paulson@13812
    64
by Auto_tac; 
paulson@13812
    65
qed "ns_constrainsI";
paulson@13812
    66
paulson@13812
    67
paulson@11195
    68
fun ns_constrains_tac i = 
paulson@11195
    69
   SELECT_GOAL
paulson@11195
    70
      (EVERY [REPEAT (etac Always_ConstrainsI 1),
paulson@11195
    71
	      REPEAT (resolve_tac [StableI, stableI,
paulson@11195
    72
				   constrains_imp_Constrains] 1),
paulson@13812
    73
	      rtac ns_constrainsI 1,
paulson@11195
    74
	      Full_simp_tac 1,
paulson@11195
    75
	      REPEAT (FIRSTGOAL (etac disjE)),
paulson@11195
    76
	      ALLGOALS (clarify_tac (claset() delrules [impI,impCE])),
paulson@11195
    77
	      REPEAT (FIRSTGOAL analz_mono_contra_tac),
paulson@11195
    78
	      ALLGOALS Asm_simp_tac]) i;
paulson@11195
    79
paulson@11195
    80
(*Tactic for proving secrecy theorems*)
paulson@11195
    81
val ns_induct_tac = 
paulson@11195
    82
  (SELECT_GOAL o EVERY)
paulson@11195
    83
     [rtac AlwaysI 1,
paulson@11195
    84
      Force_tac 1,
paulson@11195
    85
      (*"reachable" gets in here*)
paulson@11195
    86
      rtac (Always_reachable RS Always_ConstrainsI RS StableI) 1,
paulson@11195
    87
      ns_constrains_tac 1];
paulson@11195
    88
paulson@11195
    89
paulson@11195
    90
(** Theorems of the form X ~: parts (spies evs) imply that NOBODY
paulson@11195
    91
    sends messages containing X! **)
paulson@11195
    92
paulson@11195
    93
(*Spy never sees another agent's private key! (unless it's bad at start)*)
paulson@11195
    94
Goal "Nprg : Always {s. (Key (priK A) : parts (spies s)) = (A : bad)}";
paulson@11195
    95
by (ns_induct_tac 1);
paulson@11195
    96
by (Blast_tac 1);
paulson@11195
    97
qed "Spy_see_priK";
paulson@11195
    98
Addsimps [impOfAlways Spy_see_priK];
paulson@11195
    99
paulson@11195
   100
Goal "Nprg : Always {s. (Key (priK A) : analz (spies s)) = (A : bad)}";
paulson@11195
   101
by (rtac (Always_reachable RS Always_weaken) 1);
paulson@11195
   102
by Auto_tac;
paulson@11195
   103
qed "Spy_analz_priK";
paulson@11195
   104
Addsimps [impOfAlways Spy_analz_priK];
paulson@11195
   105
paulson@11195
   106
(**
paulson@11195
   107
AddSDs [Spy_see_priK RSN (2, rev_iffD1), 
paulson@11195
   108
	Spy_analz_priK RSN (2, rev_iffD1)];
paulson@11195
   109
**)
paulson@11195
   110
paulson@11195
   111
paulson@11195
   112
(**** Authenticity properties obtained from NS2 ****)
paulson@11195
   113
paulson@11195
   114
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@11195
   115
  is secret.  (Honest users generate fresh nonces.)*)
paulson@11195
   116
Goal
paulson@11195
   117
 "Nprg \
paulson@11195
   118
\  : Always {s. Nonce NA ~: analz (spies s) -->  \
paulson@11195
   119
\               Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies s) --> \
paulson@11195
   120
\               Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies s)}";
paulson@11195
   121
by (ns_induct_tac 1);
paulson@11195
   122
by (ALLGOALS Blast_tac);
paulson@11195
   123
qed "no_nonce_NS1_NS2";
paulson@11195
   124
paulson@11195
   125
(*Adding it to the claset slows down proofs...*)
paulson@11195
   126
val nonce_NS1_NS2_E = impOfAlways no_nonce_NS1_NS2 RSN (2, rev_notE);
paulson@11195
   127
paulson@11195
   128
paulson@11195
   129
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@11195
   130
Goal "Nprg \
paulson@11195
   131
\  : Always {s. Nonce NA ~: analz (spies s) --> \
paulson@11195
   132
\               Crypt(pubK B) {|Nonce NA, Agent A|} : parts(spies s) --> \
paulson@11195
   133
\               Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies s) --> \
paulson@11195
   134
\               A=A' & B=B'}";
paulson@11195
   135
by (ns_induct_tac 1);
paulson@11195
   136
by Auto_tac;  
paulson@11195
   137
(*Fake, NS1 are non-trivial*)
paulson@11195
   138
val unique_NA_lemma = result();
paulson@11195
   139
paulson@11195
   140
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@11195
   141
Goal "[| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies s); \
paulson@11195
   142
\        Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies s); \
paulson@11195
   143
\        Nonce NA ~: analz (spies s);                            \
paulson@11195
   144
\        s : reachable Nprg |]                                   \
paulson@11195
   145
\     ==> A=A' & B=B'";
paulson@11195
   146
by (blast_tac (claset() addDs [impOfAlways unique_NA_lemma]) 1); 
paulson@11195
   147
qed "unique_NA";
paulson@11195
   148
paulson@11195
   149
paulson@11195
   150
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
paulson@11195
   151
Goal "[| A ~: bad;  B ~: bad |]                     \
paulson@11195
   152
\ ==> Nprg : Always \
paulson@11195
   153
\             {s. Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set s \
paulson@11195
   154
\                 --> Nonce NA ~: analz (spies s)}";
paulson@11195
   155
by (ns_induct_tac 1);
paulson@11195
   156
(*NS3*)
paulson@11195
   157
by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 4);
paulson@11195
   158
(*NS2*)
paulson@11195
   159
by (blast_tac (claset() addDs [unique_NA]) 3);
paulson@11195
   160
(*NS1*)
paulson@11195
   161
by (Blast_tac 2);
paulson@11195
   162
(*Fake*)
paulson@11195
   163
by (spy_analz_tac 1);
paulson@11195
   164
qed "Spy_not_see_NA";
paulson@11195
   165
paulson@11195
   166
paulson@11195
   167
(*Authentication for A: if she receives message 2 and has used NA
paulson@11195
   168
  to start a run, then B has sent message 2.*)
paulson@11195
   169
val prems =
paulson@11195
   170
goal thy "[| A ~: bad;  B ~: bad |]                     \
paulson@11195
   171
\ ==> Nprg : Always \
paulson@11195
   172
\             {s. Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set s &  \
paulson@11195
   173
\                 Crypt(pubK A) {|Nonce NA, Nonce NB|} : parts (knows Spy s) \
paulson@11195
   174
\        --> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set s}";
paulson@11195
   175
  (*insert an invariant for use in some of the subgoals*)
paulson@11195
   176
by (cut_facts_tac ([prems MRS Spy_not_see_NA] @ prems) 1);
paulson@11195
   177
by (ns_induct_tac 1);
paulson@11195
   178
by (ALLGOALS Clarify_tac);
paulson@11195
   179
(*NS2*)
paulson@11195
   180
by (blast_tac (claset() addDs [unique_NA]) 3);
paulson@11195
   181
(*NS1*)
paulson@11195
   182
by (Blast_tac 2);
paulson@11195
   183
(*Fake*)
paulson@11195
   184
by (Blast_tac 1);
paulson@11195
   185
qed "A_trusts_NS2";
paulson@11195
   186
paulson@11195
   187
paulson@11195
   188
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@11195
   189
Goal "Nprg : Always \
paulson@11195
   190
\             {s. Nonce NA ~: analz (spies s) --> \
paulson@11195
   191
\                 Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies s) \
paulson@11195
   192
\        --> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set s}";
paulson@11195
   193
by (ns_induct_tac 1);
paulson@11195
   194
by (Blast_tac 1);
paulson@11195
   195
qed "B_trusts_NS1";
paulson@11195
   196
paulson@11195
   197
paulson@11195
   198
paulson@11195
   199
(**** Authenticity properties obtained from NS2 ****)
paulson@11195
   200
paulson@11195
   201
(*Unicity for NS2: nonce NB identifies nonce NA and agent A
paulson@11195
   202
  [proof closely follows that for unique_NA] *)
paulson@11195
   203
Goal
paulson@11195
   204
 "Nprg \
paulson@11195
   205
\  : Always {s. Nonce NB ~: analz (spies s)  --> \
paulson@11195
   206
\               Crypt (pubK A) {|Nonce NA, Nonce NB|} : parts (spies s) -->  \
paulson@11195
   207
\               Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies s) -->  \
paulson@11195
   208
\               A=A' & NA=NA'}";
paulson@11195
   209
by (ns_induct_tac 1);
paulson@11195
   210
by Auto_tac;  
paulson@11195
   211
(*Fake, NS2 are non-trivial*)
paulson@11195
   212
val unique_NB_lemma = result();
paulson@11195
   213
paulson@11195
   214
Goal "[| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies s); \
paulson@11195
   215
\        Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies s); \
paulson@11195
   216
\        Nonce NB ~: analz (spies s);                            \
paulson@11195
   217
\        s : reachable Nprg |]                                        \
paulson@11195
   218
\     ==> A=A' & NA=NA'";
paulson@11195
   219
by (blast_tac (claset() addDs [impOfAlways unique_NB_lemma]) 1); 
paulson@11195
   220
qed "unique_NB";
paulson@11195
   221
paulson@11195
   222
paulson@11195
   223
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@11195
   224
Goal "[| A ~: bad;  B ~: bad |]                     \
paulson@11195
   225
\ ==> Nprg : Always \
paulson@11195
   226
\             {s. Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s &  \
paulson@11195
   227
\                 (ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set s) \
paulson@11195
   228
\                 --> Nonce NB ~: analz (spies s)}";
paulson@11195
   229
by (ns_induct_tac 1);
paulson@11195
   230
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@11195
   231
by (ALLGOALS Clarify_tac);
paulson@11195
   232
(*NS3: because NB determines A*)
paulson@11195
   233
by (blast_tac (claset() addDs [unique_NB]) 4);
paulson@11195
   234
(*NS2: by freshness and unicity of NB*)
paulson@11195
   235
by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
paulson@11195
   236
(*NS1: by freshness*)
paulson@11195
   237
by (Blast_tac 2);
paulson@11195
   238
(*Fake*)
paulson@11195
   239
by (spy_analz_tac 1);
paulson@11195
   240
qed "Spy_not_see_NB";
paulson@11195
   241
paulson@11195
   242
paulson@11195
   243
paulson@11195
   244
(*Authentication for B: if he receives message 3 and has used NB
paulson@11195
   245
  in message 2, then A has sent message 3--to somebody....*)
paulson@11195
   246
val prems =
paulson@11195
   247
goal thy "[| A ~: bad;  B ~: bad |]                     \
paulson@11195
   248
\ ==> Nprg : Always \
paulson@11195
   249
\             {s. Crypt (pubK B) (Nonce NB) : parts (spies s) &  \
paulson@11195
   250
\                 Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s \
paulson@11195
   251
\                 --> (EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set s)}";
paulson@11195
   252
  (*insert an invariant for use in some of the subgoals*)
paulson@11195
   253
by (cut_facts_tac ([prems MRS Spy_not_see_NB] @ prems) 1);
paulson@11195
   254
by (ns_induct_tac 1);
paulson@11195
   255
by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
paulson@11195
   256
by (ALLGOALS Clarify_tac);
paulson@11195
   257
(*NS3: because NB determines A (this use of unique_NB is more robust) *)
paulson@11195
   258
by (blast_tac (claset() addIs [unique_NB RS conjunct1]) 3);
paulson@11195
   259
(*NS1: by freshness*)
paulson@11195
   260
by (Blast_tac 2);
paulson@11195
   261
(*Fake*)
paulson@11195
   262
by (Blast_tac 1);
paulson@11195
   263
qed "B_trusts_NS3";
paulson@11195
   264
paulson@11195
   265
paulson@11195
   266
(*Can we strengthen the secrecy theorem?  NO*)
paulson@11195
   267
Goal "[| A ~: bad;  B ~: bad |]                     \
paulson@11195
   268
\ ==> Nprg : Always \
paulson@11195
   269
\             {s. Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s  \
paulson@11195
   270
\                 --> Nonce NB ~: analz (spies s)}";
paulson@11195
   271
by (ns_induct_tac 1);
paulson@11195
   272
by (ALLGOALS Clarify_tac);
paulson@11195
   273
(*NS2: by freshness and unicity of NB*)
paulson@11195
   274
by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
paulson@11195
   275
(*NS1: by freshness*)
paulson@11195
   276
by (Blast_tac 2);
paulson@11195
   277
(*Fake*)
paulson@11195
   278
by (spy_analz_tac 1);
paulson@11195
   279
(*NS3: unicity of NB identifies A and NA, but not B*)
paulson@11195
   280
by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
paulson@11195
   281
    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
paulson@11195
   282
by Auto_tac;
paulson@11195
   283
by (rename_tac "s B' C" 1);
paulson@11195
   284
paulson@11195
   285
(*
paulson@11195
   286
THIS IS THE ATTACK!
paulson@11195
   287
[| A ~: bad; B ~: bad |]
paulson@11195
   288
==> Nprg
paulson@11195
   289
    : Always
paulson@11195
   290
       {s. Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s -->
paulson@11195
   291
           Nonce NB ~: analz (knows Spy s)}
paulson@11195
   292
 1. !!s B' C.
paulson@11195
   293
       [| A ~: bad; B ~: bad; s : reachable Nprg;
paulson@11195
   294
          Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set s;
paulson@11195
   295
          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s;
paulson@11195
   296
          C : bad; Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s;
paulson@11195
   297
          Nonce NB ~: analz (knows Spy s) |]
paulson@11195
   298
       ==> False
paulson@11195
   299
*)