src/HOL/Auth/NS_Public.ML
author paulson
Fri Jul 04 17:34:55 1997 +0200 (1997-07-04)
changeset 3500 0d8ad2f192d8
parent 3466 30791e5a69c4
child 3516 470626799511
permissions -rw-r--r--
New constant "certificate"--just an abbreviation
paulson@2318
     1
(*  Title:      HOL/Auth/NS_Public
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
Version incorporating Lowe's fix (inclusion of B's identify in round 2).
paulson@2318
     8
*)
paulson@2318
     9
paulson@2318
    10
open NS_Public;
paulson@2318
    11
paulson@2318
    12
proof_timing:=true;
paulson@2318
    13
HOL_quantifiers := false;
paulson@2318
    14
paulson@2318
    15
AddIffs [Spy_in_lost];
paulson@2318
    16
paulson@2318
    17
(*Replacing the variable by a constant improves search speed by 50%!*)
paulson@2318
    18
val Says_imp_sees_Spy' = 
paulson@2318
    19
    read_instantiate_sg (sign_of thy) [("lost","lost")] Says_imp_sees_Spy;
paulson@2318
    20
paulson@2318
    21
(*A "possibility property": there are traces that reach the end*)
paulson@2318
    22
goal thy 
paulson@2318
    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@2318
    42
(** Theorems of the form X ~: parts (sees lost Spy evs) imply that NOBODY
paulson@2318
    43
    sends messages containing X! **)
paulson@2318
    44
paulson@2318
    45
(*Spy never sees another agent's private key! (unless it's lost at start)*)
paulson@2318
    46
goal thy 
paulson@2318
    47
 "!!evs. evs : ns_public \
paulson@2318
    48
\        ==> (Key (priK A) : parts (sees lost Spy evs)) = (A : lost)";
paulson@3121
    49
by (etac ns_public.induct 1);
paulson@3121
    50
by (prove_simple_subgoals_tac 1);
paulson@3121
    51
by (Fake_parts_insert_tac 1);
paulson@2318
    52
qed "Spy_see_priK";
paulson@2318
    53
Addsimps [Spy_see_priK];
paulson@2318
    54
paulson@2318
    55
goal thy 
paulson@2318
    56
 "!!evs. evs : ns_public \
paulson@2318
    57
\        ==> (Key (priK A) : analz (sees lost Spy evs)) = (A : lost)";
paulson@2318
    58
by (auto_tac(!claset addDs [impOfSubs analz_subset_parts], !simpset));
paulson@2318
    59
qed "Spy_analz_priK";
paulson@2318
    60
Addsimps [Spy_analz_priK];
paulson@2318
    61
paulson@2318
    62
goal thy  "!!A. [| Key (priK A) : parts (sees lost Spy evs);       \
paulson@2318
    63
\                  evs : ns_public |] ==> A:lost";
paulson@3121
    64
by (blast_tac (!claset addDs [Spy_see_priK]) 1);
paulson@2318
    65
qed "Spy_see_priK_D";
paulson@2318
    66
paulson@2318
    67
bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
paulson@2318
    68
AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
paulson@2318
    69
paulson@2318
    70
paulson@2418
    71
fun analz_induct_tac i = 
paulson@3121
    72
    etac ns_public.induct i   THEN
paulson@2418
    73
    ALLGOALS (asm_simp_tac 
paulson@2516
    74
              (!simpset addsimps [not_parts_not_analz]
paulson@2451
    75
                        setloop split_tac [expand_if]));
paulson@2318
    76
paulson@2318
    77
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
    78
paulson@2318
    79
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@2318
    80
  is secret.  (Honest users generate fresh nonces.)*)
paulson@2318
    81
goal thy 
paulson@2536
    82
 "!!evs. [| Nonce NA ~: analz (sees lost Spy evs);  \
paulson@2536
    83
\           Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs); \
paulson@2536
    84
\           evs : ns_public |]                      \
paulson@2536
    85
\ ==> Crypt (pubK C) {|NA', Nonce NA, Agent D|} ~: parts (sees lost Spy evs)";
paulson@2536
    86
by (etac rev_mp 1);
paulson@2536
    87
by (etac rev_mp 1);
paulson@2418
    88
by (analz_induct_tac 1);
paulson@2318
    89
(*NS3*)
paulson@3121
    90
by (blast_tac (!claset addSEs partsEs) 4);
paulson@2318
    91
(*NS2*)
paulson@3121
    92
by (blast_tac (!claset addSEs partsEs) 3);
paulson@2318
    93
(*Fake*)
paulson@3121
    94
by (blast_tac (!claset addSIs [analz_insertI]
paulson@2536
    95
                        addDs [impOfSubs analz_subset_parts,
paulson@3121
    96
			       impOfSubs Fake_parts_insert]) 2);
paulson@2318
    97
(*Base*)
paulson@3121
    98
by (Blast_tac 1);
paulson@2536
    99
qed "no_nonce_NS1_NS2";
paulson@2318
   100
paulson@2318
   101
paulson@2480
   102
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@2318
   103
goal thy 
paulson@2536
   104
 "!!evs. [| Nonce NA ~: analz (sees lost Spy evs);  evs : ns_public |]      \
paulson@2536
   105
\ ==> EX A' B'. ALL A B.                                                    \
paulson@2318
   106
\      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs) --> \
paulson@2536
   107
\      A=A' & B=B'";
paulson@2536
   108
by (etac rev_mp 1);
paulson@2418
   109
by (analz_induct_tac 1);
paulson@2318
   110
(*NS1*)
paulson@2497
   111
by (simp_tac (!simpset addsimps [all_conj_distrib]) 3);
paulson@2318
   112
by (expand_case_tac "NA = ?y" 3 THEN
paulson@3121
   113
    REPEAT (blast_tac (!claset addSEs partsEs) 3));
paulson@2318
   114
(*Base*)
paulson@3121
   115
by (Blast_tac 1);
paulson@2318
   116
(*Fake*)
paulson@2497
   117
by (simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees]) 1);
paulson@2374
   118
by (step_tac (!claset addSIs [analz_insertI]) 1);
paulson@2318
   119
by (ex_strip_tac 1);
paulson@3121
   120
by (blast_tac (!claset delrules [conjI]
paulson@2516
   121
                      addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   122
                      addDs  [impOfSubs analz_subset_parts]) 1);
paulson@2318
   123
val lemma = result();
paulson@2318
   124
paulson@2318
   125
goal thy 
paulson@2318
   126
 "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(sees lost Spy evs); \
paulson@2318
   127
\           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(sees lost Spy evs); \
paulson@2318
   128
\           Nonce NA ~: analz (sees lost Spy evs);                            \
paulson@2318
   129
\           evs : ns_public |]                                                \
paulson@2318
   130
\        ==> A=A' & B=B'";
paulson@2480
   131
by (prove_unique_tac lemma 1);
paulson@2318
   132
qed "unique_NA";
paulson@2318
   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@2536
   139
\        ==>  Nonce NA ~: analz (sees lost Spy evs)";
paulson@2536
   140
by (etac rev_mp 1);
paulson@2418
   141
by (analz_induct_tac 1);
paulson@2318
   142
(*NS3*)
paulson@3121
   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@3121
   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@2497
   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, Agent B|})  \
paulson@3466
   162
\             : set evs;                                               \
paulson@3466
   163
\           A ~: lost;  B ~: lost;  evs : ns_public |]                 \
paulson@3466
   164
\        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB, Agent B|})  \
nipkow@3465
   165
\              : set evs";
paulson@2536
   166
by (etac rev_mp 1);
paulson@2536
   167
(*prepare induction over Crypt (pubK A) {|NA,NB,B|} : parts H*)
paulson@2536
   168
by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
paulson@2318
   169
by (etac ns_public.induct 1);
paulson@2318
   170
by (ALLGOALS Asm_simp_tac);
paulson@2318
   171
(*NS1*)
paulson@3121
   172
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   173
(*Fake*)
paulson@3121
   174
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   175
                       addDs  [Spy_not_see_NA, 
paulson@3121
   176
			       impOfSubs analz_subset_parts]) 1);
paulson@2318
   177
qed "A_trusts_NS2";
paulson@2318
   178
paulson@2318
   179
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@2318
   180
goal thy 
paulson@2536
   181
 "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs); \
paulson@2536
   182
\           Nonce NA ~: analz (sees lost Spy evs);                 \
paulson@2536
   183
\           evs : ns_public |]                                     \
nipkow@3465
   184
\   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   185
by (etac rev_mp 1);
paulson@2536
   186
by (etac rev_mp 1);
paulson@2480
   187
by (analz_induct_tac 1);
paulson@2318
   188
(*Fake*)
paulson@3121
   189
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   190
                       addIs  [analz_insertI]
paulson@3121
   191
                       addDs  [impOfSubs analz_subset_parts]) 2);
paulson@2318
   192
(*Base*)
paulson@3121
   193
by (Blast_tac 1);
paulson@2536
   194
qed "B_trusts_NS1";
paulson@2318
   195
paulson@2318
   196
paulson@2318
   197
paulson@2318
   198
(**** Authenticity properties obtained from NS2 ****)
paulson@2318
   199
paulson@2480
   200
(*Unicity for NS2: nonce NB identifies nonce NA and agents A, B 
paulson@2318
   201
  [unicity of B makes Lowe's fix work]
paulson@2318
   202
  [proof closely follows that for unique_NA] *)
paulson@2318
   203
goal thy 
paulson@2536
   204
 "!!evs. [| Nonce NB ~: analz (sees lost Spy evs);  evs : ns_public |]      \
paulson@2536
   205
\ ==> EX A' NA' B'. ALL A NA B.                                             \
paulson@2536
   206
\      Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}                       \
paulson@2536
   207
\        : parts (sees lost Spy evs)  -->  A=A' & NA=NA' & B=B'";
paulson@2536
   208
by (etac rev_mp 1);
paulson@2418
   209
by (analz_induct_tac 1);
paulson@2318
   210
(*NS2*)
paulson@2497
   211
by (simp_tac (!simpset addsimps [all_conj_distrib]) 3);
paulson@2318
   212
by (expand_case_tac "NB = ?y" 3 THEN
paulson@3121
   213
    REPEAT (blast_tac (!claset addSEs partsEs) 3));
paulson@2318
   214
(*Base*)
paulson@3121
   215
by (Blast_tac 1);
paulson@2318
   216
(*Fake*)
paulson@2497
   217
by (simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees]) 1);
paulson@2374
   218
by (step_tac (!claset addSIs [analz_insertI]) 1);
paulson@2318
   219
by (ex_strip_tac 1);
paulson@3121
   220
by (blast_tac (!claset delrules [conjI]
paulson@2516
   221
                      addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   222
                      addDs  [impOfSubs analz_subset_parts]) 1);
paulson@2318
   223
val lemma = result();
paulson@2318
   224
paulson@2318
   225
goal thy 
paulson@2318
   226
 "!!evs. [| Crypt(pubK A)  {|Nonce NA, Nonce NB, Agent B|}   \
paulson@2318
   227
\             : parts(sees lost Spy evs);                    \
paulson@2318
   228
\           Crypt(pubK A') {|Nonce NA', Nonce NB, Agent B'|} \
paulson@2318
   229
\             : parts(sees lost Spy evs);                    \
paulson@2318
   230
\           Nonce NB ~: analz (sees lost Spy evs);           \
paulson@2318
   231
\           evs : ns_public |]                               \
paulson@2318
   232
\        ==> A=A' & NA=NA' & B=B'";
paulson@2418
   233
by (prove_unique_tac lemma 1);
paulson@2318
   234
qed "unique_NB";
paulson@2318
   235
paulson@2318
   236
paulson@2318
   237
(*Secrecy: Spy does not see the nonce sent in msg NS2 if A and B are secure*)
paulson@2318
   238
goal thy 
paulson@2536
   239
 "!!evs. [| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}) \
paulson@3466
   240
\             : set evs;                                              \
paulson@2536
   241
\           A ~: lost;  B ~: lost;  evs : ns_public |]                \
paulson@2536
   242
\ ==> Nonce NB ~: analz (sees lost Spy evs)";
paulson@2536
   243
by (etac rev_mp 1);
paulson@2418
   244
by (analz_induct_tac 1);
paulson@2318
   245
(*NS3*)
paulson@3121
   246
by (blast_tac (!claset addDs [Says_imp_sees_Spy' RS parts.Inj,
paulson@3121
   247
			      unique_NB]) 4);
paulson@2318
   248
(*NS1*)
paulson@3121
   249
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   250
(*Fake*)
paulson@2497
   251
by (spy_analz_tac 1);
paulson@2318
   252
(*NS2*)
paulson@2318
   253
by (Step_tac 1);
paulson@3121
   254
by (blast_tac (!claset addSEs sees_Spy_partsEs) 3);
paulson@3121
   255
by (blast_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
paulson@3121
   256
                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 2);
paulson@3121
   257
by (blast_tac (!claset addSIs [impOfSubs analz_subset_parts]) 1);
paulson@2536
   258
qed "Spy_not_see_NB";
paulson@2318
   259
paulson@2318
   260
paulson@2318
   261
(*Authentication for B: if he receives message 3 and has used NB
paulson@2318
   262
  in message 2, then A has sent message 3.*)
paulson@2318
   263
goal thy 
paulson@2536
   264
 "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}) \
paulson@3466
   265
\             : set evs;                                               \
paulson@3466
   266
\           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;            \
paulson@2536
   267
\           A ~: lost;  B ~: lost;  evs : ns_public |]                 \
nipkow@3465
   268
\        ==> Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
paulson@2536
   269
by (etac rev_mp 1);
paulson@2536
   270
(*prepare induction over Crypt (pubK B) NB : parts H*)
paulson@2536
   271
by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
paulson@3121
   272
by (analz_induct_tac 1);
paulson@2318
   273
(*NS1*)
paulson@3121
   274
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   275
(*Fake*)
paulson@3121
   276
by (blast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@3121
   277
                       addDs  [Spy_not_see_NB, 
paulson@3121
   278
			       impOfSubs analz_subset_parts]) 1);
paulson@3121
   279
(*NS3; not clear why blast_tac needs to be preceeded by Step_tac*)
paulson@2318
   280
by (Step_tac 1);
paulson@3121
   281
by (blast_tac (!claset addDs [Says_imp_sees_Spy' RS parts.Inj,
paulson@3121
   282
			      Spy_not_see_NB, unique_NB]) 1);
paulson@2318
   283
qed "B_trusts_NS3";
paulson@2318
   284
paulson@2318
   285
paulson@2318
   286
(**** Overall guarantee for B*)
paulson@2318
   287
paulson@3121
   288
(*Matches only NS2, not NS1 (or NS3)*)
paulson@3121
   289
val Says_imp_sees_Spy'' = 
paulson@3121
   290
    read_instantiate [("X","Crypt ?K {|?XX,?YY,?ZZ|}")] Says_imp_sees_Spy';
paulson@3121
   291
paulson@3121
   292
paulson@2318
   293
(*If B receives NS3 and the nonce NB agrees with the nonce he joined with
paulson@2536
   294
  NA, then A initiated the run using NA.  SAME proof as B_trusts_NS3!*)
paulson@2318
   295
goal thy 
paulson@2536
   296
 "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}) \
paulson@3466
   297
\             : set evs;                                               \
paulson@3466
   298
\           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;            \
paulson@2536
   299
\           A ~: lost;  B ~: lost;  evs : ns_public |]                 \
nipkow@3465
   300
\    ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
paulson@2536
   301
by (etac rev_mp 1);
paulson@2536
   302
(*prepare induction over Crypt (pubK B) {|NB|} : parts H*)
paulson@2536
   303
by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
paulson@2318
   304
by (etac ns_public.induct 1);
paulson@2318
   305
by (ALLGOALS Asm_simp_tac);
paulson@2318
   306
(*Fake, NS2, NS3*)
paulson@2318
   307
(*NS1*)
paulson@3121
   308
by (blast_tac (!claset addSEs sees_Spy_partsEs) 2);
paulson@2318
   309
(*Fake*)
paulson@2318
   310
by (REPEAT_FIRST (resolve_tac [impI, conjI]));
paulson@3121
   311
by (Blast_tac 1);
paulson@2318
   312
by (forward_tac [Spy_not_see_NB] 1 THEN REPEAT (assume_tac 1));
paulson@3121
   313
by (blast_tac (!claset addSIs [disjI2]
paulson@2516
   314
                      addDs [impOfSubs analz_subset_parts,
paulson@3121
   315
                             impOfSubs Fake_parts_insert]) 1);
paulson@2318
   316
(*NS3*)
paulson@2318
   317
by (Step_tac 1);
paulson@2318
   318
by (forward_tac [Spy_not_see_NB] 1 THEN REPEAT (assume_tac 1));
paulson@3121
   319
by (blast_tac (!claset addSDs [Says_imp_sees_Spy'' RS parts.Inj]
paulson@3121
   320
                       addDs  [unique_NB]) 1);
paulson@2536
   321
qed "B_trusts_protocol";
paulson@2318
   322