src/HOL/Auth/NS_Public_Bad.ML
author paulson
Thu Sep 23 13:06:31 1999 +0200 (1999-09-23)
changeset 7584 5be4bb8e4e3f
parent 5434 9b4bed3f394c
child 8054 2ce57ef2a4aa
permissions -rw-r--r--
tidied; added lemma restrict_to_left
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@4556
    14
AddEs spies_partsEs;
paulson@4556
    15
AddDs [impOfSubs analz_subset_parts];
paulson@4556
    16
AddDs [impOfSubs Fake_parts_insert];
paulson@4556
    17
paulson@3683
    18
AddIffs [Spy_in_bad];
paulson@2318
    19
paulson@2318
    20
(*A "possibility property": there are traces that reach the end*)
paulson@5434
    21
Goal
paulson@5434
    22
  "EX NB. EX evs: ns_public. Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
paulson@2318
    23
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@2318
    24
by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
paulson@2516
    25
by possibility_tac;
paulson@2318
    26
result();
paulson@2318
    27
paulson@2318
    28
paulson@2318
    29
(**** Inductive proofs about ns_public ****)
paulson@2318
    30
paulson@3519
    31
(*Induction for regularity theorems.  If induction formula has the form
paulson@3683
    32
   X ~: analz (spies evs) --> ... then it shortens the proof by discarding
paulson@3683
    33
   needless information about analz (insert X (spies evs))  *)
paulson@3519
    34
fun parts_induct_tac i = 
paulson@3519
    35
    etac ns_public.induct i
paulson@3519
    36
    THEN 
paulson@3519
    37
    REPEAT (FIRSTGOAL analz_mono_contra_tac)
paulson@3519
    38
    THEN 
paulson@3519
    39
    prove_simple_subgoals_tac i;
paulson@3519
    40
paulson@3519
    41
paulson@3683
    42
(** Theorems of the form X ~: parts (spies evs) imply that NOBODY
paulson@2318
    43
    sends messages containing X! **)
paulson@2318
    44
paulson@3683
    45
(*Spy never sees another agent's private key! (unless it's bad at start)*)
paulson@5114
    46
Goal "evs: ns_public ==> (Key (priK A) : parts (spies evs)) = (A : bad)";
paulson@3519
    47
by (parts_induct_tac 1);
paulson@4556
    48
by (Blast_tac 1);
paulson@2318
    49
qed "Spy_see_priK";
paulson@2318
    50
Addsimps [Spy_see_priK];
paulson@2318
    51
paulson@5114
    52
Goal "evs: ns_public ==> (Key (priK A) : analz (spies evs)) = (A : bad)";
paulson@4556
    53
by Auto_tac;
paulson@2318
    54
qed "Spy_analz_priK";
paulson@2318
    55
Addsimps [Spy_analz_priK];
paulson@2318
    56
paulson@4476
    57
AddSDs [Spy_see_priK RSN (2, rev_iffD1), 
paulson@4476
    58
	Spy_analz_priK RSN (2, rev_iffD1)];
paulson@2318
    59
paulson@2318
    60
paulson@3519
    61
(**** Authenticity properties obtained from NS2 ****)
paulson@3519
    62
paulson@3519
    63
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@3519
    64
  is secret.  (Honest users generate fresh nonces.)*)
paulson@5114
    65
Goal "[| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
paulson@5114
    66
\        Nonce NA ~: analz (spies evs);   evs : ns_public |]       \
paulson@3683
    67
\ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies evs)";
paulson@3519
    68
by (etac rev_mp 1);
paulson@3519
    69
by (etac rev_mp 1);
paulson@3519
    70
by (parts_induct_tac 1);
paulson@4556
    71
by (ALLGOALS Blast_tac);
paulson@3519
    72
qed "no_nonce_NS1_NS2";
paulson@3519
    73
paulson@4556
    74
(*Adding it to the claset slows down proofs...*)
paulson@4556
    75
val nonce_NS1_NS2_E = no_nonce_NS1_NS2 RSN (2, rev_notE);
paulson@4556
    76
paulson@3519
    77
paulson@3519
    78
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@5114
    79
Goal "[| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
paulson@3709
    80
\ ==> EX A' B'. ALL A B.                                            \
paulson@5114
    81
\   Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
paulson@5114
    82
\   A=A' & B=B'";
paulson@3519
    83
by (etac rev_mp 1);
paulson@3519
    84
by (parts_induct_tac 1);
paulson@4556
    85
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@3519
    86
(*NS1*)
paulson@4556
    87
by (expand_case_tac "NA = ?y" 2 THEN Blast_tac 2);
paulson@3519
    88
(*Fake*)
paulson@3709
    89
by (Clarify_tac 1);
paulson@4556
    90
by (Blast_tac 1);
paulson@3519
    91
val lemma = result();
paulson@3519
    92
paulson@5114
    93
Goal "[| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
paulson@5114
    94
\        Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
paulson@5114
    95
\        Nonce NA ~: analz (spies evs);                            \
paulson@5114
    96
\        evs : ns_public |]                                        \
paulson@5114
    97
\     ==> A=A' & B=B'";
paulson@3519
    98
by (prove_unique_tac lemma 1);
paulson@3519
    99
qed "unique_NA";
paulson@3519
   100
paulson@3519
   101
paulson@3519
   102
(*Tactic for proving secrecy theorems*)
paulson@2418
   103
fun analz_induct_tac i = 
paulson@3121
   104
    etac ns_public.induct i   THEN
nipkow@4686
   105
    ALLGOALS Asm_simp_tac;
paulson@2418
   106
paulson@2318
   107
paulson@2318
   108
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
paulson@5114
   109
Goal "[| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;   \
paulson@5114
   110
\        A ~: bad;  B ~: bad;  evs : ns_public |]                    \
paulson@5114
   111
\     ==>  Nonce NA ~: analz (spies evs)";
paulson@2536
   112
by (etac rev_mp 1);
paulson@2418
   113
by (analz_induct_tac 1);
paulson@2318
   114
(*NS3*)
paulson@4556
   115
by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 4);
paulson@2536
   116
(*NS2*)
paulson@4556
   117
by (blast_tac (claset() addDs [unique_NA]) 3);
paulson@2318
   118
(*NS1*)
paulson@4556
   119
by (Blast_tac 2);
paulson@2318
   120
(*Fake*)
paulson@2497
   121
by (spy_analz_tac 1);
paulson@2536
   122
qed "Spy_not_see_NA";
paulson@2318
   123
paulson@2318
   124
paulson@2318
   125
(*Authentication for A: if she receives message 2 and has used NA
paulson@2318
   126
  to start a run, then B has sent message 2.*)
paulson@5114
   127
Goal "[| Says A  B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;  \
paulson@5114
   128
\        Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
paulson@5114
   129
\        A ~: bad;  B ~: bad;  evs : ns_public |]                    \
paulson@5114
   130
\     ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
paulson@2536
   131
by (etac rev_mp 1);
paulson@2536
   132
(*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
paulson@3683
   133
by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
paulson@2536
   134
by (etac ns_public.induct 1);
paulson@2318
   135
by (ALLGOALS Asm_simp_tac);
paulson@3709
   136
by (ALLGOALS Clarify_tac);
paulson@3709
   137
(*NS2*)
paulson@4556
   138
by (blast_tac (claset() addDs [Spy_not_see_NA, unique_NA]) 3);
paulson@2318
   139
(*NS1*)
paulson@4556
   140
by (Blast_tac 2);
paulson@2318
   141
(*Fake*)
paulson@4556
   142
by (blast_tac (claset() addDs [Spy_not_see_NA]) 1);
paulson@2318
   143
qed "A_trusts_NS2";
paulson@2318
   144
paulson@4556
   145
paulson@2318
   146
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@5114
   147
Goal "[| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
paulson@5114
   148
\        Nonce NA ~: analz (spies evs);                            \
paulson@5114
   149
\        evs : ns_public |]                                        \
paulson@5114
   150
\==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   151
by (etac rev_mp 1);
paulson@2536
   152
by (etac rev_mp 1);
paulson@3519
   153
by (parts_induct_tac 1);
paulson@4556
   154
by (Blast_tac 1);
paulson@3121
   155
qed "B_trusts_NS1";
paulson@2318
   156
paulson@2318
   157
paulson@2318
   158
paulson@2318
   159
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
   160
paulson@4556
   161
(*Unicity for NS2: nonce NB identifies nonce NA and agent A
paulson@2318
   162
  [proof closely follows that for unique_NA] *)
paulson@5114
   163
Goal "[| Nonce NB ~: analz (spies evs);  evs : ns_public |]            \
paulson@4556
   164
\ ==> EX A' NA'. ALL A NA.                                                \
paulson@5114
   165
\   Crypt (pubK A) {|Nonce NA, Nonce NB|} : parts (spies evs)          \
paulson@5114
   166
\      -->  A=A' & NA=NA'";
paulson@2536
   167
by (etac rev_mp 1);
paulson@3519
   168
by (parts_induct_tac 1);
paulson@4556
   169
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@2318
   170
(*NS2*)
paulson@4556
   171
by (expand_case_tac "NB = ?y" 2 THEN Blast_tac 2);
paulson@2318
   172
(*Fake*)
paulson@4556
   173
by (Blast_tac 1);
paulson@2318
   174
val lemma = result();
paulson@2318
   175
paulson@5114
   176
Goal "[| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies evs); \
paulson@5114
   177
\        Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies evs); \
paulson@5114
   178
\        Nonce NB ~: analz (spies evs);                            \
paulson@5114
   179
\        evs : ns_public |]                                        \
paulson@5114
   180
\     ==> A=A' & NA=NA'";
paulson@2418
   181
by (prove_unique_tac lemma 1);
paulson@2318
   182
qed "unique_NB";
paulson@2318
   183
paulson@2318
   184
paulson@2318
   185
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@5114
   186
Goal "[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
paulson@5114
   187
\       ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs;      \
paulson@5114
   188
\       A ~: bad;  B ~: bad;  evs : ns_public |]                     \
paulson@5114
   189
\    ==> Nonce NB ~: analz (spies evs)";
paulson@2536
   190
by (etac rev_mp 1);
paulson@2536
   191
by (etac rev_mp 1);
paulson@2418
   192
by (analz_induct_tac 1);
wenzelm@4091
   193
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@3709
   194
by (ALLGOALS Clarify_tac);
paulson@3703
   195
(*NS3: because NB determines A*)
paulson@4556
   196
by (blast_tac (claset() addDs [unique_NB]) 4);
paulson@3703
   197
(*NS2: by freshness and unicity of NB*)
paulson@4556
   198
by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
paulson@3703
   199
(*NS1: by freshness*)
paulson@4556
   200
by (Blast_tac 2);
paulson@2318
   201
(*Fake*)
paulson@2497
   202
by (spy_analz_tac 1);
paulson@2536
   203
qed "Spy_not_see_NB";
paulson@2318
   204
paulson@2318
   205
paulson@2318
   206
paulson@2318
   207
(*Authentication for B: if he receives message 3 and has used NB
paulson@2536
   208
  in message 2, then A has sent message 3--to somebody....*)
paulson@5114
   209
Goal "[| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs; \
paulson@5114
   210
\        Says A' B (Crypt (pubK B) (Nonce NB)): set evs;              \
paulson@5114
   211
\        A ~: bad;  B ~: bad;  evs : ns_public |]                   \
paulson@5114
   212
\     ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
paulson@2536
   213
by (etac rev_mp 1);
paulson@2536
   214
(*prepare induction over Crypt (pubK B) NB : parts H*)
paulson@3683
   215
by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
paulson@3519
   216
by (parts_induct_tac 1);
wenzelm@4091
   217
by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
paulson@3709
   218
by (ALLGOALS Clarify_tac);
paulson@4197
   219
(*NS3: because NB determines A (this use of unique_NB is more robust) *)
paulson@4556
   220
by (blast_tac (claset() addDs [Spy_not_see_NB]
paulson@4197
   221
			addIs [unique_NB RS conjunct1]) 3);
paulson@3703
   222
(*NS1: by freshness*)
paulson@4556
   223
by (Blast_tac 2);
paulson@2318
   224
(*Fake*)
paulson@4556
   225
by (blast_tac (claset() addDs [Spy_not_see_NB]) 1);
paulson@2318
   226
qed "B_trusts_NS3";
paulson@2318
   227
paulson@2318
   228
paulson@2318
   229
(*Can we strengthen the secrecy theorem?  NO*)
paulson@5114
   230
Goal "[| A ~: bad;  B ~: bad;  evs : ns_public |]           \
nipkow@3465
   231
\ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
paulson@5114
   232
\  --> Nonce NB ~: analz (spies evs)";
paulson@2418
   233
by (analz_induct_tac 1);
paulson@3709
   234
by (ALLGOALS Clarify_tac);
paulson@3703
   235
(*NS2: by freshness and unicity of NB*)
paulson@4556
   236
by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
paulson@3703
   237
(*NS1: by freshness*)
paulson@4556
   238
by (Blast_tac 2);
paulson@2318
   239
(*Fake*)
paulson@2497
   240
by (spy_analz_tac 1);
paulson@3703
   241
(*NS3: unicity of NB identifies A and NA, but not B*)
paulson@3683
   242
by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
paulson@3683
   243
    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
paulson@4477
   244
by Auto_tac;
paulson@3703
   245
by (rename_tac "C B' evs3" 1);
paulson@2318
   246
paulson@2318
   247
(*
paulson@2318
   248
THIS IS THE ATTACK!
paulson@3703
   249
Level 8
paulson@3683
   250
!!evs. [| A ~: bad; B ~: bad; evs : ns_public |]
paulson@3703
   251
       ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs -->
paulson@3683
   252
           Nonce NB ~: analz (spies evs)
paulson@3703
   253
 1. !!C B' evs3.
paulson@3703
   254
       [| A ~: bad; B ~: bad; evs3 : ns_public;
paulson@3703
   255
          Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set evs3;
paulson@3703
   256
          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3; C : bad;
paulson@3703
   257
          Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3;
paulson@3703
   258
          Nonce NB ~: analz (spies evs3) |]
paulson@2318
   259
       ==> False
paulson@2318
   260
*)