src/HOL/Auth/TLS.ML
author paulson
Mon Jul 14 12:47:21 1997 +0200 (1997-07-14)
changeset 3519 ab0a9fbed4c0
parent 3515 d8a71f6eaf40
child 3672 56e4365a0c99
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@3474
     1
(*  Title:      HOL/Auth/TLS
paulson@3474
     2
    ID:         $Id$
paulson@3474
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@3474
     4
    Copyright   1997  University of Cambridge
paulson@3474
     5
paulson@3480
     6
Protocol goals: 
paulson@3480
     7
* M, serverK(NA,NB,M) and clientK(NA,NB,M) will be known only to the two
paulson@3480
     8
     parties (though A is not necessarily authenticated).
paulson@3480
     9
paulson@3480
    10
* B upon receiving CERTIFICATE VERIFY knows that A is present (But this
paulson@3480
    11
    message is optional!)
paulson@3474
    12
paulson@3480
    13
* A upon receiving SERVER FINISHED knows that B is present
paulson@3480
    14
paulson@3480
    15
* Each party who has received a FINISHED message can trust that the other
paulson@3480
    16
  party agrees on all message components, including XA and XB (thus foiling
paulson@3480
    17
  rollback attacks).
paulson@3474
    18
*)
paulson@3474
    19
paulson@3474
    20
open TLS;
paulson@3474
    21
paulson@3474
    22
proof_timing:=true;
paulson@3474
    23
HOL_quantifiers := false;
paulson@3474
    24
paulson@3519
    25
(** We mostly DO NOT unfold the definition of "certificate".  The attached
paulson@3519
    26
    lemmas unfold it lazily, when "certificate B KB" occurs in appropriate
paulson@3519
    27
    contexts.
paulson@3519
    28
**)
paulson@3519
    29
paulson@3519
    30
goalw thy [certificate_def] 
paulson@3519
    31
    "parts (insert (certificate B KB) H) =  \
paulson@3519
    32
\    parts (insert (Crypt (priK Server) {|Agent B, Key KB|}) H)";
paulson@3519
    33
by (rtac refl 1);
paulson@3519
    34
qed "parts_insert_certificate";
paulson@3474
    35
paulson@3519
    36
goalw thy [certificate_def] 
paulson@3519
    37
    "analz (insert (certificate B KB) H) =  \
paulson@3519
    38
\    analz (insert (Crypt (priK Server) {|Agent B, Key KB|}) H)";
paulson@3519
    39
by (rtac refl 1);
paulson@3519
    40
qed "analz_insert_certificate";
paulson@3519
    41
Addsimps [parts_insert_certificate, analz_insert_certificate];
paulson@3519
    42
paulson@3519
    43
goalw thy [certificate_def] 
paulson@3519
    44
    "(X = certificate B KB) = (Crypt (priK Server) {|Agent B, Key KB|} = X)";
paulson@3480
    45
by (Blast_tac 1);
paulson@3519
    46
qed "eq_certificate_iff";
paulson@3519
    47
AddIffs [eq_certificate_iff];
paulson@3519
    48
paulson@3480
    49
paulson@3474
    50
(*Injectiveness of key-generating functions*)
paulson@3474
    51
AddIffs [inj_clientK RS inj_eq, inj_serverK RS inj_eq];
paulson@3474
    52
paulson@3474
    53
(* invKey(clientK x) = clientK x  and similarly for serverK*)
paulson@3474
    54
Addsimps [isSym_clientK, rewrite_rule [isSymKey_def] isSym_clientK,
paulson@3474
    55
	  isSym_serverK, rewrite_rule [isSymKey_def] isSym_serverK];
paulson@3480
    56
paulson@3474
    57
paulson@3474
    58
(*** clientK and serverK make symmetric keys; no clashes with pubK or priK ***)
paulson@3474
    59
paulson@3474
    60
goal thy "pubK A ~= clientK arg";
paulson@3474
    61
br notI 1;
paulson@3474
    62
by (dres_inst_tac [("f","isSymKey")] arg_cong 1);
paulson@3474
    63
by (Full_simp_tac 1);
paulson@3474
    64
qed "pubK_neq_clientK";
paulson@3474
    65
paulson@3474
    66
goal thy "pubK A ~= serverK arg";
paulson@3474
    67
br notI 1;
paulson@3474
    68
by (dres_inst_tac [("f","isSymKey")] arg_cong 1);
paulson@3474
    69
by (Full_simp_tac 1);
paulson@3474
    70
qed "pubK_neq_serverK";
paulson@3474
    71
paulson@3474
    72
goal thy "priK A ~= clientK arg";
paulson@3474
    73
br notI 1;
paulson@3474
    74
by (dres_inst_tac [("f","isSymKey")] arg_cong 1);
paulson@3474
    75
by (Full_simp_tac 1);
paulson@3474
    76
qed "priK_neq_clientK";
paulson@3474
    77
paulson@3474
    78
goal thy "priK A ~= serverK arg";
paulson@3474
    79
br notI 1;
paulson@3474
    80
by (dres_inst_tac [("f","isSymKey")] arg_cong 1);
paulson@3474
    81
by (Full_simp_tac 1);
paulson@3474
    82
qed "priK_neq_serverK";
paulson@3474
    83
paulson@3480
    84
(*clientK and serverK have disjoint ranges*)
paulson@3480
    85
goal thy "clientK arg ~= serverK arg'";
paulson@3480
    86
by (cut_facts_tac [rangeI RS impOfSubs clientK_range] 1);
paulson@3480
    87
by (Blast_tac 1);
paulson@3480
    88
qed "clientK_neq_serverK";
paulson@3480
    89
paulson@3515
    90
val keys_distinct = [pubK_neq_clientK, pubK_neq_serverK, 
paulson@3515
    91
		     priK_neq_clientK, priK_neq_serverK, clientK_neq_serverK];
paulson@3515
    92
AddIffs (keys_distinct @ (keys_distinct RL [not_sym]));
paulson@3474
    93
paulson@3474
    94
paulson@3474
    95
(**** Protocol Proofs ****)
paulson@3474
    96
paulson@3474
    97
(*A "possibility property": there are traces that reach the end.
paulson@3474
    98
  This protocol has three end points and six messages to consider.*)
paulson@3474
    99
paulson@3474
   100
(*Possibility property ending with ServerFinished.*)
paulson@3474
   101
goal thy 
paulson@3474
   102
 "!!A B. A ~= B ==> EX NA XA NB XB M. EX evs: tls.    \
paulson@3474
   103
\  Says B A (Crypt (serverK(NA,NB,M))                 \
paulson@3474
   104
\            (Hash{|Hash{|Nonce NA, Nonce NB, Nonce M|}, \
paulson@3474
   105
\                   Nonce NA, Agent XA, Agent A,      \
paulson@3474
   106
\                   Nonce NB, Agent XB,               \
paulson@3500
   107
\                   certificate B (pubK B)|})) \
paulson@3474
   108
\    : set evs";
paulson@3474
   109
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@3474
   110
by (rtac (tls.Nil RS tls.ClientHello RS tls.ServerHello RS tls.ClientCertKeyEx
paulson@3474
   111
	  RS tls.ServerFinished) 2);
paulson@3474
   112
by possibility_tac;
paulson@3474
   113
result();
paulson@3474
   114
paulson@3474
   115
(*And one for ClientFinished.  Either FINISHED message may come first.*)
paulson@3474
   116
goal thy 
paulson@3519
   117
 "!!A B. A ~= B ==> EX NA XA NB XB M. EX evs: tls.              \
paulson@3519
   118
\  Says A B (Crypt (clientK(NA,NB,M))                           \
paulson@3519
   119
\            (Hash{|Hash{|Nonce NA, Nonce NB, Nonce M|},        \
paulson@3519
   120
\                   Nonce NA, Agent XA, certificate A (pubK A), \
paulson@3474
   121
\                   Nonce NB, Agent XB, Agent B|})) : set evs";
paulson@3474
   122
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@3474
   123
by (rtac (tls.Nil RS tls.ClientHello RS tls.ServerHello RS tls.ClientCertKeyEx
paulson@3474
   124
	  RS tls.ClientFinished) 2);
paulson@3474
   125
by possibility_tac;
paulson@3474
   126
result();
paulson@3474
   127
paulson@3474
   128
(*Another one, for CertVerify (which is optional)*)
paulson@3474
   129
goal thy 
paulson@3519
   130
 "!!A B. A ~= B ==> EX NB M. EX evs: tls.   \
paulson@3474
   131
\  Says A B (Crypt (priK A)                 \
paulson@3506
   132
\            (Hash{|Nonce NB, certificate B (pubK B), Nonce M|})) : set evs";
paulson@3474
   133
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@3506
   134
by (rtac (tls.Nil RS tls.ClientHello RS tls.ServerHello RS tls.ClientCertKeyEx
paulson@3506
   135
	  RS tls.CertVerify) 2);
paulson@3474
   136
by possibility_tac;
paulson@3474
   137
result();
paulson@3474
   138
paulson@3474
   139
paulson@3474
   140
(**** Inductive proofs about tls ****)
paulson@3474
   141
paulson@3474
   142
(*Nobody sends themselves messages*)
paulson@3474
   143
goal thy "!!evs. evs : tls ==> ALL A X. Says A A X ~: set evs";
paulson@3474
   144
by (etac tls.induct 1);
paulson@3474
   145
by (Auto_tac());
paulson@3474
   146
qed_spec_mp "not_Says_to_self";
paulson@3474
   147
Addsimps [not_Says_to_self];
paulson@3474
   148
AddSEs   [not_Says_to_self RSN (2, rev_notE)];
paulson@3474
   149
paulson@3474
   150
paulson@3519
   151
(*Induction for regularity theorems.  If induction formula has the form
paulson@3519
   152
   X ~: analz (sees Spy evs) --> ... then it shortens the proof by discarding
paulson@3519
   153
   needless information about analz (insert X (sees Spy evs))  *)
paulson@3519
   154
fun parts_induct_tac i = 
paulson@3519
   155
    etac tls.induct i
paulson@3519
   156
    THEN 
paulson@3519
   157
    REPEAT (FIRSTGOAL analz_mono_contra_tac)
paulson@3519
   158
    THEN 
paulson@3519
   159
    fast_tac (!claset addss (!simpset)) i THEN
paulson@3519
   160
    ALLGOALS (asm_full_simp_tac (!simpset setloop split_tac [expand_if]));
paulson@3519
   161
paulson@3519
   162
paulson@3519
   163
(** Theorems of the form X ~: parts (sees Spy evs) imply that NOBODY
paulson@3474
   164
    sends messages containing X! **)
paulson@3474
   165
paulson@3474
   166
(*Spy never sees another agent's private key! (unless it's lost at start)*)
paulson@3474
   167
goal thy 
paulson@3519
   168
 "!!evs. evs : tls ==> (Key (priK A) : parts (sees Spy evs)) = (A : lost)";
paulson@3519
   169
by (parts_induct_tac 1);
paulson@3474
   170
by (Fake_parts_insert_tac 1);
paulson@3474
   171
qed "Spy_see_priK";
paulson@3474
   172
Addsimps [Spy_see_priK];
paulson@3474
   173
paulson@3474
   174
goal thy 
paulson@3519
   175
 "!!evs. evs : tls ==> (Key (priK A) : analz (sees Spy evs)) = (A : lost)";
paulson@3474
   176
by (auto_tac(!claset addDs [impOfSubs analz_subset_parts], !simpset));
paulson@3474
   177
qed "Spy_analz_priK";
paulson@3474
   178
Addsimps [Spy_analz_priK];
paulson@3474
   179
paulson@3519
   180
goal thy  "!!A. [| Key (priK A) : parts (sees Spy evs);       \
paulson@3474
   181
\                  evs : tls |] ==> A:lost";
paulson@3474
   182
by (blast_tac (!claset addDs [Spy_see_priK]) 1);
paulson@3474
   183
qed "Spy_see_priK_D";
paulson@3474
   184
paulson@3474
   185
bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
paulson@3474
   186
AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
paulson@3474
   187
paulson@3474
   188
paulson@3515
   189
(*This lemma says that no false certificates exist.  One might extend the
paulson@3519
   190
  model to include bogus certificates for the agents, but there seems
paulson@3515
   191
  little point in doing so: the loss of their private keys is a worse
paulson@3515
   192
  breach of security.*)
paulson@3515
   193
goalw thy [certificate_def]
paulson@3515
   194
 "!!evs. evs : tls     \
paulson@3519
   195
\        ==> certificate B KB : parts (sees Spy evs) --> KB = pubK B";
paulson@3519
   196
by (parts_induct_tac 1);
paulson@3519
   197
by (Fake_parts_insert_tac 1);
paulson@3515
   198
bind_thm ("Server_cert_pubB", result() RSN (2, rev_mp));
paulson@3515
   199
paulson@3515
   200
paulson@3515
   201
(*Replace key KB in ClientCertKeyEx by (pubK B) *)
paulson@3515
   202
val ClientCertKeyEx_tac = 
paulson@3519
   203
    forward_tac [Says_imp_sees_Spy RS parts.Inj RS 
paulson@3515
   204
		 parts.Snd RS parts.Snd RS parts.Snd RS Server_cert_pubB]
paulson@3515
   205
    THEN' assume_tac
paulson@3515
   206
    THEN' hyp_subst_tac;
paulson@3515
   207
paulson@3515
   208
fun analz_induct_tac i = 
paulson@3515
   209
    etac tls.induct i   THEN
paulson@3515
   210
    ClientCertKeyEx_tac  (i+7)  THEN	(*ClientFinished*)
paulson@3515
   211
    ClientCertKeyEx_tac  (i+6)  THEN	(*CertVerify*)
paulson@3515
   212
    ClientCertKeyEx_tac  (i+5)  THEN	(*ClientCertKeyEx*)
paulson@3515
   213
    ALLGOALS (asm_simp_tac 
paulson@3515
   214
              (!simpset addsimps [not_parts_not_analz]
paulson@3515
   215
                        setloop split_tac [expand_if]))  THEN
paulson@3515
   216
    (*Remove instances of pubK B:  the Spy already knows all public keys.
paulson@3515
   217
      Combining the two simplifier calls makes them run extremely slowly.*)
paulson@3515
   218
    ALLGOALS (asm_simp_tac 
paulson@3515
   219
              (!simpset addsimps [insert_absorb]
paulson@3515
   220
                        setloop split_tac [expand_if]));
paulson@3515
   221
paulson@3515
   222
paulson@3515
   223
(*** Hashing of nonces ***)
paulson@3515
   224
paulson@3474
   225
(*Every Nonce that's hashed is already in past traffic. *)
paulson@3519
   226
goal thy "!!evs. [| Hash {|Nonce N, X|} : parts (sees Spy evs);  \
paulson@3474
   227
\                   evs : tls |]  \
paulson@3519
   228
\                ==> Nonce N : parts (sees Spy evs)";
paulson@3474
   229
by (etac rev_mp 1);
paulson@3519
   230
by (parts_induct_tac 1);
paulson@3519
   231
by (ALLGOALS (asm_simp_tac (!simpset addsimps [parts_insert_sees])));
paulson@3519
   232
by (Fake_parts_insert_tac 1);
paulson@3519
   233
by (blast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
paulson@3519
   234
	               addSEs partsEs) 1);
paulson@3474
   235
qed "Hash_imp_Nonce1";
paulson@3474
   236
paulson@3474
   237
(*Lemma needed to prove Hash_Hash_imp_Nonce*)
paulson@3474
   238
goal thy "!!evs. [| Hash{|Nonce NA, Nonce NB, Nonce M|}  \
paulson@3519
   239
\                       : parts (sees Spy evs);     \
paulson@3474
   240
\                   evs : tls |]  \
paulson@3519
   241
\                ==> Nonce M : parts (sees Spy evs)";
paulson@3474
   242
by (etac rev_mp 1);
paulson@3519
   243
by (parts_induct_tac 1);
paulson@3519
   244
by (asm_simp_tac (!simpset addsimps [parts_insert_sees]) 1);
paulson@3519
   245
by (Fake_parts_insert_tac 1);
paulson@3474
   246
qed "Hash_imp_Nonce2";
paulson@3474
   247
AddSDs [Hash_imp_Nonce2];
paulson@3474
   248
paulson@3515
   249
paulson@3515
   250
goal thy "!!evs. [| Notes A {|Agent B, X|} : set evs;  evs : tls |]  \
paulson@3519
   251
\                ==> Crypt (pubK B) X : parts (sees Spy evs)";
paulson@3515
   252
by (etac rev_mp 1);
paulson@3515
   253
by (analz_induct_tac 1);
paulson@3515
   254
by (blast_tac (!claset addIs [parts_insertI]) 1);
paulson@3515
   255
qed "Notes_Crypt_parts_sees";
paulson@3515
   256
paulson@3515
   257
paulson@3515
   258
(*NEEDED??*)
paulson@3474
   259
goal thy "!!evs. [| Hash {| Hash{|Nonce NA, Nonce NB, Nonce M|}, X |}  \
paulson@3519
   260
\                      : parts (sees Spy evs);      \
paulson@3474
   261
\                   evs : tls |]                         \
paulson@3519
   262
\                ==> Nonce M : parts (sees Spy evs)";
paulson@3474
   263
by (etac rev_mp 1);
paulson@3519
   264
by (parts_induct_tac 1);
paulson@3519
   265
by (ALLGOALS (asm_simp_tac (!simpset addsimps [parts_insert_sees])));
paulson@3519
   266
by (Fake_parts_insert_tac 1);
paulson@3519
   267
by (REPEAT (blast_tac (!claset addSDs [Notes_Crypt_parts_sees,
paulson@3519
   268
				       Says_imp_sees_Spy RS parts.Inj]
paulson@3519
   269
		               addSEs partsEs) 1));
paulson@3474
   270
qed "Hash_Hash_imp_Nonce";
paulson@3474
   271
paulson@3474
   272
paulson@3474
   273
(*NEEDED??
paulson@3474
   274
  Every Nonce that's hashed is already in past traffic. 
paulson@3474
   275
  This general formulation is tricky to prove and hard to use, since the
paulson@3474
   276
  2nd premise is typically proved by simplification.*)
paulson@3519
   277
goal thy "!!evs. [| Hash X : parts (sees Spy evs);  \
paulson@3474
   278
\                   Nonce N : parts {X};  evs : tls |]  \
paulson@3519
   279
\                ==> Nonce N : parts (sees Spy evs)";
paulson@3474
   280
by (etac rev_mp 1);
paulson@3519
   281
by (parts_induct_tac 1);
paulson@3515
   282
by (step_tac (!claset addSDs [Notes_Crypt_parts_sees,
paulson@3519
   283
			      Says_imp_sees_Spy RS parts.Inj]
paulson@3474
   284
		      addSEs partsEs) 1);
paulson@3474
   285
by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [parts_insert_sees])));
paulson@3474
   286
by (Fake_parts_insert_tac 1);
paulson@3506
   287
(*CertVerify, ClientFinished, ServerFinished (?)*)
paulson@3506
   288
by (REPEAT (Blast_tac 1));
paulson@3474
   289
qed "Hash_imp_Nonce_seen";
paulson@3474
   290
paulson@3474
   291
paulson@3474
   292
(*** Protocol goal: if B receives CERTIFICATE VERIFY, then A sent it ***)
paulson@3474
   293
paulson@3506
   294
(*B can check A's signature if he has received A's certificate.
paulson@3506
   295
  Perhaps B~=Spy is unnecessary, but there's no obvious proof if the first
paulson@3480
   296
  message is Fake.  We don't need guarantees for the Spy anyway.  We must
paulson@3480
   297
  assume A~:lost; otherwise, the Spy can forge A's signature.*)
paulson@3519
   298
goal thy
paulson@3506
   299
 "!!evs. [| X = Crypt (priK A)                                        \
paulson@3506
   300
\                 (Hash{|Nonce NB, certificate B KB, Nonce M|});      \
paulson@3506
   301
\           evs : tls;  A ~: lost;  B ~= Spy |]                       \
paulson@3506
   302
\    ==> Says B A {|Nonce NA, Nonce NB, Agent XB, certificate B KB|}  \
paulson@3506
   303
\          : set evs --> \
paulson@3519
   304
\        X : parts (sees Spy evs) --> Says A B X : set evs";
paulson@3480
   305
by (hyp_subst_tac 1);
paulson@3519
   306
by (parts_induct_tac 1);
paulson@3474
   307
by (Fake_parts_insert_tac 1);
paulson@3480
   308
(*ServerHello: nonce NB cannot be in X because it's fresh!*)
paulson@3474
   309
by (blast_tac (!claset addSDs [Hash_imp_Nonce1]
paulson@3474
   310
	               addSEs sees_Spy_partsEs) 1);
paulson@3474
   311
qed_spec_mp "TrustCertVerify";
paulson@3474
   312
paulson@3474
   313
paulson@3515
   314
(*If CERTIFICATE VERIFY is present then A has chosen M.*)
paulson@3506
   315
goal thy
paulson@3515
   316
 "!!evs. [| Crypt (priK A) (Hash{|Nonce NB, certificate B KB, Nonce M|})  \
paulson@3519
   317
\             : parts (sees Spy evs);                                \
paulson@3515
   318
\           evs : tls;  A ~: lost |]                                      \
paulson@3515
   319
\        ==> Notes A {|Agent B, Nonce M|} : set evs";
paulson@3515
   320
be rev_mp 1;
paulson@3519
   321
by (parts_induct_tac 1);
paulson@3519
   322
by (Fake_parts_insert_tac 1);
paulson@3515
   323
qed "UseCertVerify";
paulson@3474
   324
paulson@3480
   325
paulson@3480
   326
(*No collection of keys can help the spy get new private keys*)
paulson@3480
   327
goal thy  
paulson@3480
   328
 "!!evs. evs : tls ==>                                    \
paulson@3519
   329
\  ALL KK. (Key(priK B) : analz (Key``KK Un (sees Spy evs))) =  \
paulson@3480
   330
\            (priK B : KK | B : lost)";
paulson@3480
   331
by (etac tls.induct 1);
paulson@3515
   332
by (ALLGOALS
paulson@3519
   333
    (asm_simp_tac (analz_image_keys_ss
paulson@3515
   334
		   addsimps (certificate_def::keys_distinct))));
paulson@3480
   335
(*Fake*) 
paulson@3480
   336
by (spy_analz_tac 2);
paulson@3480
   337
(*Base*)
paulson@3480
   338
by (Blast_tac 1);
paulson@3480
   339
qed_spec_mp "analz_image_priK";
paulson@3480
   340
paulson@3480
   341
paulson@3480
   342
(*Lemma for the trivial direction of the if-and-only-if*)
paulson@3480
   343
goal thy  
paulson@3480
   344
 "!!evs. (X : analz (G Un H)) --> (X : analz H)  ==> \
paulson@3480
   345
\        (X : analz (G Un H))  =  (X : analz H)";
paulson@3480
   346
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 1);
paulson@3480
   347
val lemma = result();
paulson@3480
   348
paulson@3480
   349
(*Knowing some clientKs and serverKs is no help in getting new nonces*)
paulson@3480
   350
goal thy  
paulson@3480
   351
 "!!evs. evs : tls ==>                                 \
paulson@3480
   352
\    ALL KK. KK <= (range clientK Un range serverK) -->           \
paulson@3519
   353
\            (Nonce N : analz (Key``KK Un (sees Spy evs))) = \
paulson@3519
   354
\            (Nonce N : analz (sees Spy evs))";
paulson@3480
   355
by (etac tls.induct 1);
paulson@3480
   356
by (ClientCertKeyEx_tac 6);
paulson@3480
   357
by (REPEAT_FIRST (resolve_tac [allI, impI]));
paulson@3515
   358
by (REPEAT_FIRST (rtac lemma));
paulson@3515
   359
writeln"SLOW simplification: 50 secs!??";
paulson@3515
   360
by (ALLGOALS
paulson@3515
   361
    (asm_simp_tac (analz_image_keys_ss 
paulson@3519
   362
                   addsimps (analz_image_priK::certificate_def::
paulson@3519
   363
                             keys_distinct))));
paulson@3515
   364
by (ALLGOALS (asm_simp_tac (analz_image_keys_ss addsimps [analz_image_priK])));
paulson@3515
   365
by (ALLGOALS (asm_simp_tac (!simpset addsimps [insert_absorb])));
paulson@3480
   366
(*ClientCertKeyEx: a nonce is sent, but one needs a priK to read it.*)
paulson@3480
   367
by (Blast_tac 3);
paulson@3480
   368
(*Fake*) 
paulson@3480
   369
by (spy_analz_tac 2);
paulson@3480
   370
(*Base*)
paulson@3480
   371
by (Blast_tac 1);
paulson@3480
   372
qed_spec_mp "analz_image_keys";
paulson@3480
   373
paulson@3480
   374
paulson@3515
   375
(*If A sends ClientCertKeyEx to an uncompromised B, then M will stay secret.*)
paulson@3515
   376
goal thy
paulson@3515
   377
 "!!evs. [| evs : tls;  A ~: lost;  B ~: lost |]           \
paulson@3515
   378
\        ==> Notes A {|Agent B, Nonce M|} : set evs  -->   \
paulson@3519
   379
\            Nonce M ~: analz (sees Spy evs)";
paulson@3474
   380
by (analz_induct_tac 1);
paulson@3474
   381
(*ClientHello*)
paulson@3515
   382
by (blast_tac (!claset addSDs [Notes_Crypt_parts_sees]
paulson@3515
   383
                               addSEs sees_Spy_partsEs) 3);
paulson@3480
   384
(*SpyKeys*)
paulson@3480
   385
by (asm_simp_tac (analz_image_keys_ss addsimps [analz_image_keys]) 2);
paulson@3474
   386
(*Fake*)
paulson@3474
   387
by (spy_analz_tac 1);
paulson@3474
   388
(*ServerHello and ClientCertKeyEx: mostly freshness reasoning*)
paulson@3474
   389
by (REPEAT (blast_tac (!claset addSEs partsEs
paulson@3515
   390
			       addDs  [Notes_Crypt_parts_sees,
paulson@3515
   391
				       impOfSubs analz_subset_parts,
paulson@3519
   392
				       Says_imp_sees_Spy RS analz.Inj]) 1));
paulson@3474
   393
bind_thm ("Spy_not_see_premaster_secret", result() RSN (2, rev_mp));
paulson@3474
   394
paulson@3474
   395
paulson@3474
   396
(*** Protocol goal: serverK(NA,NB,M) and clientK(NA,NB,M) remain secure ***)
paulson@3474
   397
paulson@3515
   398
(** First, some lemmas about those write keys.  The proofs for serverK are 
paulson@3515
   399
    nearly identical to those for clientK. **)
paulson@3515
   400
paulson@3515
   401
(*Lemma: those write keys are never sent if M is secure.  
paulson@3515
   402
  Converse doesn't hold; betraying M doesn't force the keys to be sent!*)
paulson@3515
   403
paulson@3474
   404
goal thy 
paulson@3519
   405
 "!!evs. [| Nonce M ~: analz (sees Spy evs);  evs : tls |]   \
paulson@3519
   406
\        ==> Key (clientK(NA,NB,M)) ~: parts (sees Spy evs)";
paulson@3480
   407
by (etac rev_mp 1);
paulson@3480
   408
by (analz_induct_tac 1);
paulson@3480
   409
(*SpyKeys*)
paulson@3480
   410
by (asm_simp_tac (analz_image_keys_ss addsimps [analz_image_keys]) 3);
paulson@3519
   411
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS analz.Inj]) 3);
paulson@3480
   412
(*Fake*) 
paulson@3480
   413
by (spy_analz_tac 2);
paulson@3480
   414
(*Base*)
paulson@3480
   415
by (Blast_tac 1);
paulson@3474
   416
qed "clientK_notin_parts";
paulson@3474
   417
paulson@3515
   418
Addsimps [clientK_notin_parts];
paulson@3515
   419
AddSEs [clientK_notin_parts RSN (2, rev_notE)];
paulson@3515
   420
paulson@3474
   421
goal thy 
paulson@3519
   422
 "!!evs. [| Nonce M ~: analz (sees Spy evs);  evs : tls |]   \
paulson@3519
   423
\        ==> Key (serverK(NA,NB,M)) ~: parts (sees Spy evs)";
paulson@3480
   424
by (etac rev_mp 1);
paulson@3480
   425
by (analz_induct_tac 1);
paulson@3480
   426
(*SpyKeys*)
paulson@3480
   427
by (asm_simp_tac (analz_image_keys_ss addsimps [analz_image_keys]) 3);
paulson@3519
   428
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS analz.Inj]) 3);
paulson@3480
   429
(*Fake*) 
paulson@3480
   430
by (spy_analz_tac 2);
paulson@3480
   431
(*Base*)
paulson@3480
   432
by (Blast_tac 1);
paulson@3474
   433
qed "serverK_notin_parts";
paulson@3474
   434
paulson@3515
   435
Addsimps [serverK_notin_parts];
paulson@3515
   436
AddSEs [serverK_notin_parts RSN (2, rev_notE)];
paulson@3515
   437
paulson@3515
   438
(*Lemma: those write keys are never used if M is fresh.  
paulson@3515
   439
  Converse doesn't hold; betraying M doesn't force the keys to be sent!
paulson@3515
   440
  NOT suitable as safe elim rules.*)
paulson@3515
   441
paulson@3515
   442
goal thy 
paulson@3515
   443
 "!!evs. [| Nonce M ~: used evs;  evs : tls |]                           \
paulson@3519
   444
\        ==> Crypt (clientK(NA,NB,M)) Y ~: parts (sees Spy evs)";
paulson@3515
   445
by (etac rev_mp 1);
paulson@3515
   446
by (analz_induct_tac 1);
paulson@3515
   447
(*ClientFinished: since M is fresh, a different instance of clientK was used.*)
paulson@3515
   448
by (blast_tac (!claset addSDs [Notes_Crypt_parts_sees]
paulson@3515
   449
                               addSEs sees_Spy_partsEs) 3);
paulson@3515
   450
by (Fake_parts_insert_tac 2);
paulson@3515
   451
(*Base*)
paulson@3515
   452
by (Blast_tac 1);
paulson@3515
   453
qed "Crypt_clientK_notin_parts";
paulson@3515
   454
paulson@3515
   455
Addsimps [Crypt_clientK_notin_parts];
paulson@3515
   456
AddEs [Crypt_clientK_notin_parts RSN (2, rev_notE)];
paulson@3515
   457
paulson@3515
   458
goal thy 
paulson@3515
   459
 "!!evs. [| Nonce M ~: used evs;  evs : tls |]                           \
paulson@3519
   460
\        ==> Crypt (serverK(NA,NB,M)) Y ~: parts (sees Spy evs)";
paulson@3515
   461
by (etac rev_mp 1);
paulson@3515
   462
by (analz_induct_tac 1);
paulson@3515
   463
(*ServerFinished: since M is fresh, a different instance of serverK was used.*)
paulson@3515
   464
by (blast_tac (!claset addSDs [Notes_Crypt_parts_sees]
paulson@3515
   465
                               addSEs sees_Spy_partsEs) 3);
paulson@3515
   466
by (Fake_parts_insert_tac 2);
paulson@3515
   467
(*Base*)
paulson@3515
   468
by (Blast_tac 1);
paulson@3515
   469
qed "Crypt_serverK_notin_parts";
paulson@3515
   470
paulson@3515
   471
Addsimps [Crypt_serverK_notin_parts];
paulson@3515
   472
AddEs [Crypt_serverK_notin_parts RSN (2, rev_notE)];
paulson@3515
   473
paulson@3515
   474
paulson@3519
   475
(*NEEDED??*)
paulson@3515
   476
goal thy
paulson@3515
   477
 "!!evs. [| Says A B {|certA, Crypt KB (Nonce M)|} : set evs;   \
paulson@3519
   478
\           A ~= Spy;  evs : tls |] ==> KB = pubK B";
paulson@3515
   479
be rev_mp 1;
paulson@3515
   480
by (analz_induct_tac 1);
paulson@3515
   481
qed "A_Crypt_pubB";
paulson@3515
   482
paulson@3515
   483
paulson@3515
   484
(*** Unicity results for M, the pre-master-secret ***)
paulson@3515
   485
paulson@3515
   486
(*M determines B.  Proof borrowed from NS_Public/unique_NA and from Yahalom*)
paulson@3515
   487
goal thy 
paulson@3519
   488
 "!!evs. [| Nonce M ~: analz (sees Spy evs);  evs : tls |]   \
paulson@3515
   489
\        ==> EX B'. ALL B.   \
paulson@3519
   490
\              Crypt (pubK B) (Nonce M) : parts (sees Spy evs) --> B=B'";
paulson@3515
   491
by (etac rev_mp 1);
paulson@3519
   492
by (parts_induct_tac 1);
paulson@3519
   493
by (Fake_parts_insert_tac 1);
paulson@3515
   494
(*ClientCertKeyEx*)
paulson@3519
   495
by (ClientCertKeyEx_tac 1);
paulson@3519
   496
by (asm_simp_tac (!simpset addsimps [all_conj_distrib]) 1);
paulson@3519
   497
by (expand_case_tac "M = ?y" 1 THEN
paulson@3519
   498
    blast_tac (!claset addSEs partsEs) 1);
paulson@3515
   499
val lemma = result();
paulson@3515
   500
paulson@3515
   501
goal thy 
paulson@3519
   502
 "!!evs. [| Crypt(pubK B)  (Nonce M) : parts (sees Spy evs); \
paulson@3519
   503
\           Crypt(pubK B') (Nonce M) : parts (sees Spy evs); \
paulson@3519
   504
\           Nonce M ~: analz (sees Spy evs);                 \
paulson@3515
   505
\           evs : tls |]                                          \
paulson@3515
   506
\        ==> B=B'";
paulson@3515
   507
by (prove_unique_tac lemma 1);
paulson@3515
   508
qed "unique_M";
paulson@3515
   509
paulson@3515
   510
paulson@3515
   511
(*In A's note to herself, M determines A and B.*)
paulson@3515
   512
goal thy 
paulson@3519
   513
 "!!evs. [| Nonce M ~: analz (sees Spy evs);  evs : tls |]            \
paulson@3515
   514
\ ==> EX A' B'. ALL A B.                                                   \
paulson@3515
   515
\        Notes A {|Agent B, Nonce M|} : set evs --> A=A' & B=B'";
paulson@3515
   516
by (etac rev_mp 1);
paulson@3519
   517
by (parts_induct_tac 1);
paulson@3515
   518
by (asm_simp_tac (!simpset addsimps [all_conj_distrib]) 1);
paulson@3515
   519
(*ClientCertKeyEx: if M is fresh, then it can't appear in Notes A X.*)
paulson@3515
   520
by (expand_case_tac "M = ?y" 1 THEN
paulson@3515
   521
    blast_tac (!claset addSDs [Notes_Crypt_parts_sees] addSEs partsEs) 1);
paulson@3515
   522
val lemma = result();
paulson@3515
   523
paulson@3515
   524
goal thy 
paulson@3515
   525
 "!!evs. [| Notes A  {|Agent B,  Nonce M|} : set evs;  \
paulson@3515
   526
\           Notes A' {|Agent B', Nonce M|} : set evs;  \
paulson@3519
   527
\           Nonce M ~: analz (sees Spy evs);      \
paulson@3515
   528
\           evs : tls |]                               \
paulson@3515
   529
\        ==> A=A' & B=B'";
paulson@3515
   530
by (prove_unique_tac lemma 1);
paulson@3515
   531
qed "Notes_unique_M";
paulson@3515
   532
paulson@3515
   533
paulson@3474
   534
paulson@3474
   535
(*** Protocol goals: if A receives SERVER FINISHED, then B is present 
paulson@3474
   536
     and has used the quoted values XA, XB, etc.  Note that it is up to A
paulson@3474
   537
     to compare XA with what she originally sent.
paulson@3474
   538
***)
paulson@3474
   539
paulson@3515
   540
(*The mention of her name (A) in X assumes A that B knows who she is.*)
paulson@3515
   541
goal thy
paulson@3515
   542
 "!!evs. [| X = Crypt (serverK(NA,NB,M))                                \
paulson@3515
   543
\                 (Hash{|Hash{|Nonce NA, Nonce NB, Nonce M|},           \
paulson@3515
   544
\                        Nonce NA, Agent XA, Agent A,                   \
paulson@3506
   545
\                        Nonce NB, Agent XB, certificate B (pubK B)|}); \
paulson@3515
   546
\           evs : tls;  A ~: lost;  B ~: lost |]                        \
paulson@3515
   547
\        ==> Notes A {|Agent B, Nonce M|} : set evs -->                 \
paulson@3519
   548
\        X : parts (sees Spy evs) --> Says B A X : set evs";
paulson@3480
   549
by (hyp_subst_tac 1);
paulson@3515
   550
by (analz_induct_tac 1);
paulson@3515
   551
by (REPEAT_FIRST (rtac impI));
paulson@3480
   552
(*Fake: the Spy doesn't have the critical session key!*)
paulson@3480
   553
by (REPEAT (rtac impI 1));
paulson@3519
   554
by (subgoal_tac "Key (serverK(NA,NB,M)) ~: analz (sees Spy evsa)" 1);
paulson@3480
   555
by (asm_simp_tac (!simpset addsimps [Spy_not_see_premaster_secret, 
paulson@3480
   556
				     not_parts_not_analz]) 2);
paulson@3474
   557
by (Fake_parts_insert_tac 1);
paulson@3474
   558
qed_spec_mp "TrustServerFinished";
paulson@3474
   559
paulson@3474
   560
paulson@3515
   561
(*This version refers not to SERVER FINISHED but to any message from B.
paulson@3515
   562
  We don't assume B has received CERTIFICATE VERIFY, and an intruder could
paulson@3515
   563
  have changed A's identity in all other messages, so we can't be sure
paulson@3519
   564
  that B sends his message to A.  If CLIENT KEY EXCHANGE were augmented
paulson@3519
   565
  to bind A's identify with M, then we could replace A' by A below.*)
paulson@3515
   566
goal thy
paulson@3519
   567
 "!!evs. [| evs : tls;  A ~: lost;  B ~: lost |]                     \
paulson@3519
   568
\        ==> Notes A {|Agent B, Nonce M|} : set evs -->              \
paulson@3519
   569
\            Crypt (serverK(NA,NB,M)) Y : parts (sees Spy evs)  -->  \
paulson@3515
   570
\            (EX A'. Says B A' (Crypt (serverK(NA,NB,M)) Y) : set evs)";
paulson@3515
   571
by (analz_induct_tac 1);
paulson@3515
   572
by (REPEAT_FIRST (rtac impI));
paulson@3515
   573
(*Fake: the Spy doesn't have the critical session key!*)
paulson@3519
   574
by (subgoal_tac "Key (serverK(NA,NB,M)) ~: analz (sees Spy evsa)" 1);
paulson@3515
   575
by (asm_simp_tac (!simpset addsimps [Spy_not_see_premaster_secret, 
paulson@3515
   576
				     not_parts_not_analz]) 2);
paulson@3515
   577
by (Fake_parts_insert_tac 1);
paulson@3515
   578
(*ServerFinished.  If the message is old then apply induction hypothesis...*)
paulson@3515
   579
by (rtac conjI 1 THEN Blast_tac 2);
paulson@3515
   580
(*...otherwise delete induction hyp and use unicity of M.*)
paulson@3515
   581
by (thin_tac "?PP-->?QQ" 1);
paulson@3515
   582
by (Step_tac 1);
paulson@3519
   583
by (subgoal_tac "Nonce M ~: analz (sees Spy evsa)" 1);
paulson@3515
   584
by (asm_simp_tac (!simpset addsimps [Spy_not_see_premaster_secret]) 2);
paulson@3515
   585
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3515
   586
		       addDs  [Notes_Crypt_parts_sees,
paulson@3519
   587
			       Says_imp_sees_Spy RS parts.Inj,
paulson@3515
   588
			       unique_M]) 1);
paulson@3515
   589
qed_spec_mp "TrustServerMsg";
paulson@3515
   590
paulson@3515
   591
paulson@3515
   592
(*** Protocol goal: if B receives any message encrypted with clientK
paulson@3515
   593
     then A has sent it, ASSUMING that A chose M.  Authentication is
paulson@3515
   594
     assumed here; B cannot verify it.  But if the message is
paulson@3515
   595
     CLIENT FINISHED, then B can then check the quoted values XA, XB, etc.
paulson@3506
   596
***)
paulson@3515
   597
goal thy
paulson@3515
   598
 "!!evs. [| evs : tls;  A ~: lost;  B ~: lost |]                         \
paulson@3515
   599
\        ==> Notes A {|Agent B, Nonce M|} : set evs -->                  \
paulson@3519
   600
\            Crypt (clientK(NA,NB,M)) Y : parts (sees Spy evs) -->  \
paulson@3515
   601
\            Says A B (Crypt (clientK(NA,NB,M)) Y) : set evs";
paulson@3515
   602
by (analz_induct_tac 1);
paulson@3515
   603
by (REPEAT_FIRST (rtac impI));
paulson@3480
   604
(*Fake: the Spy doesn't have the critical session key!*)
paulson@3519
   605
by (subgoal_tac "Key (clientK(NA,NB,M)) ~: analz (sees Spy evsa)" 1);
paulson@3480
   606
by (asm_simp_tac (!simpset addsimps [Spy_not_see_premaster_secret, 
paulson@3480
   607
				     not_parts_not_analz]) 2);
paulson@3474
   608
by (Fake_parts_insert_tac 1);
paulson@3515
   609
(*ClientFinished.  If the message is old then apply induction hypothesis...*)
paulson@3515
   610
by (step_tac (!claset delrules [conjI]) 1);
paulson@3519
   611
by (subgoal_tac "Nonce M ~: analz (sees Spy evsa)" 1);
paulson@3515
   612
by (asm_simp_tac (!simpset addsimps [Spy_not_see_premaster_secret]) 2);
paulson@3515
   613
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3515
   614
		       addDs  [Notes_unique_M]) 1);
paulson@3515
   615
qed_spec_mp "TrustClientMsg";
paulson@3506
   616
paulson@3506
   617
paulson@3506
   618
(*** Protocol goal: if B receives CLIENT FINISHED, and if B is able to
paulson@3506
   619
     check a CERTIFICATE VERIFY from A, then A has used the quoted
paulson@3506
   620
     values XA, XB, etc.  Even this one requires A to be uncompromised.
paulson@3506
   621
 ***)
paulson@3506
   622
goal thy
paulson@3515
   623
 "!!evs. [| Says A' B (Crypt (clientK(NA,NB,M)) Y) : set evs;             \
paulson@3515
   624
\           Says B  A {|Nonce NA, Nonce NB, Agent XB, certificate B KB|}  \
paulson@3515
   625
\             : set evs;                                                  \
paulson@3515
   626
\           Says A'' B (Crypt (priK A)                                    \
paulson@3515
   627
\                       (Hash{|Nonce NB, certificate B KB, Nonce M|}))    \
paulson@3515
   628
\             : set evs;                                                  \
paulson@3515
   629
\        evs : tls;  A ~: lost;  B ~: lost |]                             \
paulson@3515
   630
\     ==> Says A B (Crypt (clientK(NA,NB,M)) Y) : set evs";
paulson@3515
   631
by (blast_tac (!claset addSIs [TrustClientMsg, UseCertVerify]
paulson@3515
   632
                       addDs  [Says_imp_sees_Spy RS parts.Inj]) 1);
paulson@3515
   633
qed "AuthClientFinished";