src/HOL/Auth/TLS.thy
author wenzelm
Wed Oct 03 20:54:16 2001 +0200 (2001-10-03)
changeset 11655 923e4d0d36d5
parent 11287 0103ee3082bf
child 13507 febb8e5d2a9d
permissions -rw-r--r--
tuned parentheses in relational expressions;
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@3759
     6
Inductive relation "tls" for the TLS (Transport Layer Security) protocol.
paulson@3672
     7
This protocol is essentially the same as SSL 3.0.
paulson@3672
     8
paulson@3672
     9
Abstracted from "The TLS Protocol, Version 1.0" by Tim Dierks and Christopher
paulson@3672
    10
Allen, Transport Layer Security Working Group, 21 May 1997,
paulson@3672
    11
INTERNET-DRAFT draft-ietf-tls-protocol-03.txt.  Section numbers below refer
paulson@3672
    12
to that memo.
paulson@3474
    13
paulson@3474
    14
An RSA cryptosystem is assumed, and X.509v3 certificates are abstracted down
paulson@3474
    15
to the trivial form {A, publicKey(A)}privateKey(Server), where Server is a
paulson@3474
    16
global signing authority.
paulson@3474
    17
paulson@3474
    18
A is the client and B is the server, not to be confused with the constant
paulson@3474
    19
Server, who is in charge of all public keys.
paulson@3474
    20
paulson@3480
    21
The model assumes that no fraudulent certificates are present, but it does
paulson@3519
    22
assume that some private keys are to the spy.
paulson@3474
    23
paulson@3745
    24
REMARK.  The event "Notes A {|Agent B, Nonce PMS|}" appears in ClientKeyExch,
paulson@3515
    25
CertVerify, ClientFinished to record that A knows M.  It is a note from A to
paulson@3745
    26
herself.  Nobody else can see it.  In ClientKeyExch, the Spy can substitute
paulson@3515
    27
his own certificate for A's, but he cannot replace A's note by one for himself.
paulson@3515
    28
paulson@3672
    29
The Note event avoids a weakness in the public-key model.  Each
paulson@3515
    30
agent's state is recorded as the trace of messages.  When the true client (A)
paulson@3672
    31
invents PMS, he encrypts PMS with B's public key before sending it.  The model
paulson@3515
    32
does not distinguish the original occurrence of such a message from a replay.
paulson@3515
    33
In the shared-key model, the ability to encrypt implies the ability to
paulson@3515
    34
decrypt, so the problem does not arise.
paulson@3685
    35
paulson@3745
    36
Proofs would be simpler if ClientKeyExch included A's name within
paulson@3685
    37
Crypt KB (Nonce PMS).  As things stand, there is much overlap between proofs
paulson@3685
    38
about that message (which B receives) and the stronger event
paulson@3685
    39
	Notes A {|Agent B, Nonce PMS|}.
paulson@3474
    40
*)
paulson@3474
    41
paulson@11287
    42
theory TLS = Public:
paulson@3474
    43
paulson@5653
    44
constdefs
paulson@5653
    45
  certificate      :: "[agent,key] => msg"
paulson@5653
    46
    "certificate A KA == Crypt (priK Server) {|Agent A, Key KA|}"
paulson@5653
    47
paulson@6284
    48
datatype role = ClientRole | ServerRole
paulson@6284
    49
paulson@3474
    50
consts
paulson@3672
    51
  (*Pseudo-random function of Section 5*)
paulson@3672
    52
  PRF  :: "nat*nat*nat => nat"
paulson@3672
    53
paulson@3704
    54
  (*Client, server write keys are generated uniformly by function sessionK
paulson@5653
    55
    to avoid duplicating their properties.  They are distinguished by a
paulson@5653
    56
    tag (not a bool, to avoid the peculiarities of if-and-only-if).
paulson@3704
    57
    Session keys implicitly include MAC secrets.*)
paulson@6284
    58
  sessionK :: "(nat*nat*nat) * role => key"
paulson@3474
    59
paulson@3677
    60
syntax
paulson@11287
    61
    clientK :: "nat*nat*nat => key"
paulson@11287
    62
    serverK :: "nat*nat*nat => key"
paulson@3677
    63
paulson@3677
    64
translations
paulson@6284
    65
  "clientK X" == "sessionK(X, ClientRole)"
paulson@6284
    66
  "serverK X" == "sessionK(X, ServerRole)"
paulson@3677
    67
paulson@11287
    68
axioms
paulson@3745
    69
  (*the pseudo-random function is collision-free*)
paulson@11287
    70
  inj_PRF:       "inj PRF"
paulson@3672
    71
paulson@3745
    72
  (*sessionK is collision-free; also, no clientK clashes with any serverK.*)
paulson@11287
    73
  inj_sessionK:  "inj sessionK"	
paulson@3677
    74
paulson@3745
    75
  (*sessionK makes symmetric keys*)
paulson@11287
    76
  isSym_sessionK: "sessionK nonces \<in> symKeys"
paulson@3474
    77
paulson@3474
    78
paulson@11287
    79
consts    tls :: "event list set"
paulson@3474
    80
inductive tls
paulson@11287
    81
  intros
paulson@11287
    82
   Nil:  (*Initial trace is empty*)
paulson@11287
    83
         "[] \<in> tls"
paulson@3474
    84
paulson@11287
    85
   Fake: (*The spy, an active attacker, MAY say anything he CAN say.*)
paulson@11287
    86
         "[| evsf \<in> tls;  X \<in> synth (analz (spies evsf)) |]
paulson@11287
    87
          ==> Says Spy B X # evsf \<in> tls"
paulson@3480
    88
paulson@11287
    89
   SpyKeys: (*The spy may apply PRF & sessionK to available nonces*)
paulson@11287
    90
         "[| evsSK \<in> tls;
paulson@5359
    91
	     {Nonce NA, Nonce NB, Nonce M} <= analz (spies evsSK) |]
paulson@4421
    92
          ==> Notes Spy {| Nonce (PRF(M,NA,NB)),
paulson@11287
    93
			   Key (sessionK((NA,NB,M),role)) |} # evsSK \<in> tls"
paulson@3474
    94
paulson@11287
    95
   ClientHello:
paulson@3672
    96
	 (*(7.4.1.2)
paulson@3729
    97
	   PA represents CLIENT_VERSION, CIPHER_SUITES and COMPRESSION_METHODS.
paulson@3474
    98
	   It is uninterpreted but will be confirmed in the FINISHED messages.
paulson@3676
    99
	   NA is CLIENT RANDOM, while SID is SESSION_ID.
paulson@3676
   100
           UNIX TIME is omitted because the protocol doesn't use it.
paulson@11287
   101
           May assume NA \<notin> range PRF because CLIENT RANDOM is 28 bytes
paulson@4198
   102
	   while MASTER SECRET is 48 bytes*)
paulson@11287
   103
         "[| evsCH \<in> tls;  Nonce NA \<notin> used evsCH;  NA \<notin> range PRF |]
paulson@3729
   104
          ==> Says A B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@11287
   105
	        # evsCH  \<in>  tls"
paulson@3474
   106
paulson@11287
   107
   ServerHello:
paulson@3672
   108
         (*7.4.1.3 of the TLS Internet-Draft
paulson@3729
   109
	   PB represents CLIENT_VERSION, CIPHER_SUITE and COMPRESSION_METHOD.
paulson@3672
   110
           SERVER CERTIFICATE (7.4.2) is always present.
paulson@3672
   111
           CERTIFICATE_REQUEST (7.4.4) is implied.*)
paulson@11287
   112
         "[| evsSH \<in> tls;  Nonce NB \<notin> used evsSH;  NB \<notin> range PRF;
paulson@3729
   113
             Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@11287
   114
	       \<in> set evsSH |]
paulson@11287
   115
          ==> Says B A {|Nonce NB, Number SID, Number PB|} # evsSH  \<in>  tls"
paulson@3474
   116
paulson@11287
   117
   Certificate:
paulson@3745
   118
         (*SERVER (7.4.2) or CLIENT (7.4.6) CERTIFICATE.*)
paulson@11287
   119
         "evsC \<in> tls ==> Says B A (certificate B (pubK B)) # evsC  \<in>  tls"
paulson@3745
   120
paulson@11287
   121
   ClientKeyExch:
paulson@3745
   122
         (*CLIENT KEY EXCHANGE (7.4.7).
paulson@3672
   123
           The client, A, chooses PMS, the PREMASTER SECRET.
paulson@3672
   124
           She encrypts PMS using the supplied KB, which ought to be pubK B.
paulson@11287
   125
           We assume PMS \<notin> range PRF because a clash betweem the PMS
paulson@3672
   126
           and another MASTER SECRET is highly unlikely (even though
paulson@3672
   127
	   both items have the same length, 48 bytes).
paulson@3672
   128
           The Note event records in the trace that she knows PMS
paulson@3685
   129
               (see REMARK at top). *)
paulson@11287
   130
         "[| evsCX \<in> tls;  Nonce PMS \<notin> used evsCX;  PMS \<notin> range PRF;
paulson@11287
   131
             Says B' A (certificate B KB) \<in> set evsCX |]
paulson@3745
   132
          ==> Says A B (Crypt KB (Nonce PMS))
paulson@3672
   133
	      # Notes A {|Agent B, Nonce PMS|}
paulson@11287
   134
	      # evsCX  \<in>  tls"
paulson@3474
   135
paulson@11287
   136
   CertVerify:
paulson@3685
   137
	(*The optional Certificate Verify (7.4.8) message contains the
paulson@3672
   138
          specific components listed in the security analysis, F.1.1.2.
paulson@3672
   139
          It adds the pre-master-secret, which is also essential!
paulson@3672
   140
          Checking the signature, which is the only use of A's certificate,
paulson@3672
   141
          assures B of A's presence*)
paulson@11287
   142
         "[| evsCV \<in> tls;
paulson@11287
   143
             Says B' A {|Nonce NB, Number SID, Number PB|} \<in> set evsCV;
paulson@11287
   144
	     Notes A {|Agent B, Nonce PMS|} \<in> set evsCV |]
paulson@3729
   145
          ==> Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|}))
paulson@11287
   146
              # evsCV  \<in>  tls"
paulson@3474
   147
paulson@3729
   148
	(*Finally come the FINISHED messages (7.4.8), confirming PA and PB
paulson@3672
   149
          among other things.  The master-secret is PRF(PMS,NA,NB).
paulson@11287
   150
          Either party may send its message first.*)
paulson@3474
   151
paulson@11287
   152
   ClientFinished:
paulson@11287
   153
        (*The occurrence of Notes A {|Agent B, Nonce PMS|} stops the
paulson@3515
   154
          rule's applying when the Spy has satisfied the "Says A B" by
paulson@3515
   155
          repaying messages sent by the true client; in that case, the
paulson@6284
   156
          Spy does not know PMS and could not send ClientFinished.  One
paulson@11287
   157
          could simply put A\<noteq>Spy into the rule, but one should not
paulson@3515
   158
          expect the spy to be well-behaved.*)
paulson@11287
   159
         "[| evsCF \<in> tls;
paulson@3729
   160
	     Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@11287
   161
	       \<in> set evsCF;
paulson@11287
   162
             Says B' A {|Nonce NB, Number SID, Number PB|} \<in> set evsCF;
paulson@11287
   163
             Notes A {|Agent B, Nonce PMS|} \<in> set evsCF;
paulson@3672
   164
	     M = PRF(PMS,NA,NB) |]
paulson@3474
   165
          ==> Says A B (Crypt (clientK(NA,NB,M))
paulson@3757
   166
			(Hash{|Number SID, Nonce M,
paulson@11287
   167
			       Nonce NA, Number PA, Agent A,
paulson@3729
   168
			       Nonce NB, Number PB, Agent B|}))
paulson@11287
   169
              # evsCF  \<in>  tls"
paulson@3474
   170
paulson@11287
   171
   ServerFinished:
paulson@3474
   172
	(*Keeping A' and A'' distinct means B cannot even check that the
paulson@3672
   173
          two messages originate from the same source. *)
paulson@11287
   174
         "[| evsSF \<in> tls;
paulson@3729
   175
	     Says A' B  {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@11287
   176
	       \<in> set evsSF;
paulson@11287
   177
	     Says B  A  {|Nonce NB, Number SID, Number PB|} \<in> set evsSF;
paulson@11287
   178
	     Says A'' B (Crypt (pubK B) (Nonce PMS)) \<in> set evsSF;
paulson@3672
   179
	     M = PRF(PMS,NA,NB) |]
paulson@3474
   180
          ==> Says B A (Crypt (serverK(NA,NB,M))
paulson@3757
   181
			(Hash{|Number SID, Nonce M,
paulson@11287
   182
			       Nonce NA, Number PA, Agent A,
paulson@3729
   183
			       Nonce NB, Number PB, Agent B|}))
paulson@11287
   184
              # evsSF  \<in>  tls"
paulson@3474
   185
paulson@11287
   186
   ClientAccepts:
paulson@3685
   187
	(*Having transmitted ClientFinished and received an identical
paulson@3677
   188
          message encrypted with serverK, the client stores the parameters
paulson@3687
   189
          needed to resume this session.  The "Notes A ..." premise is
paulson@3687
   190
          used to prove Notes_master_imp_Crypt_PMS.*)
paulson@11287
   191
         "[| evsCA \<in> tls;
paulson@11287
   192
	     Notes A {|Agent B, Nonce PMS|} \<in> set evsCA;
paulson@11287
   193
	     M = PRF(PMS,NA,NB);
paulson@3757
   194
	     X = Hash{|Number SID, Nonce M,
paulson@11287
   195
	               Nonce NA, Number PA, Agent A,
paulson@3729
   196
		       Nonce NB, Number PB, Agent B|};
paulson@11287
   197
             Says A  B (Crypt (clientK(NA,NB,M)) X) \<in> set evsCA;
paulson@11287
   198
             Says B' A (Crypt (serverK(NA,NB,M)) X) \<in> set evsCA |]
paulson@11287
   199
          ==>
paulson@11287
   200
             Notes A {|Number SID, Agent A, Agent B, Nonce M|} # evsCA  \<in>  tls"
paulson@3677
   201
paulson@11287
   202
   ServerAccepts:
paulson@3685
   203
	(*Having transmitted ServerFinished and received an identical
paulson@3677
   204
          message encrypted with clientK, the server stores the parameters
paulson@3687
   205
          needed to resume this session.  The "Says A'' B ..." premise is
paulson@3687
   206
          used to prove Notes_master_imp_Crypt_PMS.*)
paulson@11287
   207
         "[| evsSA \<in> tls;
paulson@11287
   208
	     A \<noteq> B;
paulson@11287
   209
             Says A'' B (Crypt (pubK B) (Nonce PMS)) \<in> set evsSA;
paulson@11287
   210
	     M = PRF(PMS,NA,NB);
paulson@3757
   211
	     X = Hash{|Number SID, Nonce M,
paulson@11287
   212
	               Nonce NA, Number PA, Agent A,
paulson@3729
   213
		       Nonce NB, Number PB, Agent B|};
paulson@11287
   214
             Says B  A (Crypt (serverK(NA,NB,M)) X) \<in> set evsSA;
paulson@11287
   215
             Says A' B (Crypt (clientK(NA,NB,M)) X) \<in> set evsSA |]
paulson@11287
   216
          ==>
paulson@11287
   217
             Notes B {|Number SID, Agent A, Agent B, Nonce M|} # evsSA  \<in>  tls"
paulson@3677
   218
paulson@11287
   219
   ClientResume:
paulson@3745
   220
         (*If A recalls the SESSION_ID, then she sends a FINISHED message
paulson@3745
   221
           using the new nonces and stored MASTER SECRET.*)
paulson@11287
   222
         "[| evsCR \<in> tls;
paulson@3759
   223
	     Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}: set evsCR;
paulson@11287
   224
             Says B' A {|Nonce NB, Number SID, Number PB|} \<in> set evsCR;
paulson@11287
   225
             Notes A {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evsCR |]
paulson@3685
   226
          ==> Says A B (Crypt (clientK(NA,NB,M))
paulson@3757
   227
			(Hash{|Number SID, Nonce M,
paulson@11287
   228
			       Nonce NA, Number PA, Agent A,
paulson@3729
   229
			       Nonce NB, Number PB, Agent B|}))
paulson@11287
   230
              # evsCR  \<in>  tls"
paulson@3685
   231
paulson@11287
   232
   ServerResume:
paulson@3759
   233
         (*Resumption (7.3):  If B finds the SESSION_ID then he can send
paulson@3759
   234
           a FINISHED message using the recovered MASTER SECRET*)
paulson@11287
   235
         "[| evsSR \<in> tls;
paulson@3759
   236
	     Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}: set evsSR;
paulson@11287
   237
	     Says B  A {|Nonce NB, Number SID, Number PB|} \<in> set evsSR;
paulson@11287
   238
             Notes B {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evsSR |]
paulson@3759
   239
          ==> Says B A (Crypt (serverK(NA,NB,M))
paulson@3759
   240
			(Hash{|Number SID, Nonce M,
paulson@11287
   241
			       Nonce NA, Number PA, Agent A,
paulson@3759
   242
			       Nonce NB, Number PB, Agent B|})) # evsSR
paulson@11287
   243
	        \<in>  tls"
paulson@3759
   244
paulson@11287
   245
   Oops:
paulson@3686
   246
         (*The most plausible compromise is of an old session key.  Losing
paulson@3686
   247
           the MASTER SECRET or PREMASTER SECRET is more serious but
paulson@11287
   248
           rather unlikely.  The assumption A \<noteq> Spy is essential: otherwise
paulson@5434
   249
           the Spy could learn session keys merely by replaying messages!*)
paulson@11287
   250
         "[| evso \<in> tls;  A \<noteq> Spy;
paulson@11287
   251
	     Says A B (Crypt (sessionK((NA,NB,M),role)) X) \<in> set evso |]
paulson@11287
   252
          ==> Says A Spy (Key (sessionK((NA,NB,M),role))) # evso  \<in>  tls"
paulson@11287
   253
paulson@11287
   254
(*
paulson@11287
   255
Protocol goals:
paulson@11287
   256
* M, serverK(NA,NB,M) and clientK(NA,NB,M) will be known only to the two
paulson@11287
   257
     parties (though A is not necessarily authenticated).
paulson@11287
   258
paulson@11287
   259
* B upon receiving CertVerify knows that A is present (But this
paulson@11287
   260
    message is optional!)
paulson@11287
   261
paulson@11287
   262
* A upon receiving ServerFinished knows that B is present
paulson@11287
   263
paulson@11287
   264
* Each party who has received a FINISHED message can trust that the other
paulson@11287
   265
  party agrees on all message components, including PA and PB (thus foiling
paulson@11287
   266
  rollback attacks).
paulson@11287
   267
*)
paulson@11287
   268
paulson@11287
   269
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11287
   270
declare parts.Body  [dest]
paulson@11287
   271
declare analz_into_parts [dest]
paulson@11287
   272
declare Fake_parts_insert_in_Un  [dest]
paulson@11287
   273
paulson@11287
   274
paulson@11287
   275
(*Automatically unfold the definition of "certificate"*)
paulson@11287
   276
declare certificate_def [simp]
paulson@11287
   277
paulson@11287
   278
(*Injectiveness of key-generating functions*)
paulson@11287
   279
declare inj_PRF [THEN inj_eq, iff]
paulson@11287
   280
declare inj_sessionK [THEN inj_eq, iff]
paulson@11287
   281
declare isSym_sessionK [simp]
paulson@11287
   282
paulson@11287
   283
paulson@11287
   284
(*** clientK and serverK make symmetric keys; no clashes with pubK or priK ***)
paulson@11287
   285
paulson@11287
   286
lemma pubK_neq_sessionK [iff]: "pubK A \<noteq> sessionK arg"
paulson@11287
   287
by (simp add: symKeys_neq_imp_neq)
paulson@11287
   288
paulson@11287
   289
declare pubK_neq_sessionK [THEN not_sym, iff]
paulson@11287
   290
paulson@11287
   291
lemma priK_neq_sessionK [iff]: "priK A \<noteq> sessionK arg"
paulson@11287
   292
by (simp add: symKeys_neq_imp_neq)
paulson@11287
   293
paulson@11287
   294
declare priK_neq_sessionK [THEN not_sym, iff]
paulson@11287
   295
paulson@11287
   296
lemmas keys_distinct = pubK_neq_sessionK priK_neq_sessionK
paulson@11287
   297
paulson@11287
   298
paulson@11287
   299
(**** Protocol Proofs ****)
paulson@11287
   300
paulson@11287
   301
(*Possibility properties state that some traces run the protocol to the end.
paulson@11287
   302
  Four paths and 12 rules are considered.*)
paulson@11287
   303
paulson@11287
   304
paulson@11287
   305
(** These proofs assume that the Nonce_supply nonces
paulson@11287
   306
	(which have the form  @ N. Nonce N \<notin> used evs)
paulson@11287
   307
    lie outside the range of PRF.  It seems reasonable, but as it is needed
paulson@11287
   308
    only for the possibility theorems, it is not taken as an axiom.
paulson@11287
   309
**)
paulson@11287
   310
paulson@11287
   311
paulson@11287
   312
(*Possibility property ending with ClientAccepts.*)
paulson@11287
   313
lemma "[| \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF;  A \<noteq> B |]
paulson@11287
   314
      ==> \<exists>SID M. \<exists>evs \<in> tls.
paulson@11287
   315
            Notes A {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs"
paulson@11287
   316
apply (intro exI bexI)
paulson@11287
   317
apply (rule_tac [2] tls.Nil
paulson@11287
   318
                    [THEN tls.ClientHello, THEN tls.ServerHello,
paulson@11287
   319
                     THEN tls.Certificate, THEN tls.ClientKeyExch,
paulson@11287
   320
                     THEN tls.ClientFinished, THEN tls.ServerFinished,
paulson@11287
   321
                     THEN tls.ClientAccepts])
paulson@11287
   322
apply possibility
paulson@11287
   323
apply blast+
paulson@11287
   324
done
paulson@11287
   325
paulson@11287
   326
paulson@11287
   327
(*And one for ServerAccepts.  Either FINISHED message may come first.*)
paulson@11287
   328
lemma "[| \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF; A \<noteq> B |]
paulson@11287
   329
      ==> \<exists>SID NA PA NB PB M. \<exists>evs \<in> tls.
paulson@11287
   330
           Notes B {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs"
paulson@11287
   331
apply (intro exI bexI)
paulson@11287
   332
apply (rule_tac [2] tls.Nil
paulson@11287
   333
                    [THEN tls.ClientHello, THEN tls.ServerHello,
paulson@11287
   334
                     THEN tls.Certificate, THEN tls.ClientKeyExch,
paulson@11287
   335
                     THEN tls.ServerFinished, THEN tls.ClientFinished, 
paulson@11287
   336
                     THEN tls.ServerAccepts])
paulson@11287
   337
apply possibility
paulson@11287
   338
apply blast+
paulson@11287
   339
done
paulson@11287
   340
paulson@11287
   341
paulson@11287
   342
(*Another one, for CertVerify (which is optional)*)
paulson@11287
   343
lemma "[| \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF;  A \<noteq> B |]
paulson@11287
   344
       ==> \<exists>NB PMS. \<exists>evs \<in> tls.
paulson@11287
   345
              Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|})) 
paulson@11287
   346
                \<in> set evs"
paulson@11287
   347
apply (intro exI bexI)
paulson@11287
   348
apply (rule_tac [2] tls.Nil
paulson@11287
   349
                    [THEN tls.ClientHello, THEN tls.ServerHello,
paulson@11287
   350
                     THEN tls.Certificate, THEN tls.ClientKeyExch,
paulson@11287
   351
                     THEN tls.CertVerify])
paulson@11287
   352
apply possibility
paulson@11287
   353
apply blast+
paulson@11287
   354
done
paulson@11287
   355
paulson@11287
   356
paulson@11287
   357
(*Another one, for session resumption (both ServerResume and ClientResume).
paulson@11287
   358
  NO tls.Nil here: we refer to a previous session, not the empty trace.*)
paulson@11287
   359
lemma "[| evs0 \<in> tls;
paulson@11287
   360
          Notes A {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs0;
paulson@11287
   361
          Notes B {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs0;
paulson@11287
   362
          \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF;
paulson@11287
   363
          A \<noteq> B |]
paulson@11287
   364
      ==> \<exists>NA PA NB PB X. \<exists>evs \<in> tls.
paulson@11287
   365
		X = Hash{|Number SID, Nonce M,
paulson@11287
   366
			  Nonce NA, Number PA, Agent A,
paulson@11287
   367
			  Nonce NB, Number PB, Agent B|}  &
paulson@11287
   368
		Says A B (Crypt (clientK(NA,NB,M)) X) \<in> set evs  &
paulson@11287
   369
		Says B A (Crypt (serverK(NA,NB,M)) X) \<in> set evs"
paulson@11287
   370
apply (intro exI bexI)
paulson@11287
   371
apply (rule_tac [2] tls.ClientHello
paulson@11287
   372
                    [THEN tls.ServerHello,
paulson@11287
   373
                     THEN tls.ServerResume, THEN tls.ClientResume])
paulson@11287
   374
apply possibility
paulson@11287
   375
apply blast+
paulson@11287
   376
done
paulson@11287
   377
paulson@11287
   378
paulson@11287
   379
(**** Inductive proofs about tls ****)
paulson@11287
   380
paulson@11287
   381
paulson@11287
   382
(*Induction for regularity theorems.  If induction formula has the form
paulson@11287
   383
   X \<notin> analz (spies evs) --> ... then it shortens the proof by discarding
paulson@11287
   384
   needless information about analz (insert X (spies evs))  
paulson@11287
   385
fun parts_induct_tac i =
paulson@11287
   386
    etac tls.induct i
paulson@11287
   387
    THEN REPEAT (FIRSTGOAL analz_mono_contra_tac)
paulson@11287
   388
    THEN Force_tac i THEN
paulson@11287
   389
    ALLGOALS Asm_simp_tac
paulson@11287
   390
*)
paulson@11287
   391
paulson@11287
   392
(** Theorems of the form X \<notin> parts (spies evs) imply that NOBODY
paulson@11287
   393
    sends messages containing X! **)
paulson@11287
   394
paulson@11287
   395
(*Spy never sees a good agent's private key!*)
paulson@11287
   396
lemma Spy_see_priK [simp]:
paulson@11287
   397
     "evs \<in> tls ==> (Key (priK A) \<in> parts (spies evs)) = (A \<in> bad)"
paulson@11287
   398
apply (erule tls.induct, force, simp_all)
paulson@11287
   399
apply blast
paulson@11287
   400
done
paulson@11287
   401
paulson@11287
   402
lemma Spy_analz_priK [simp]:
paulson@11287
   403
     "evs \<in> tls ==> (Key (priK A) \<in> analz (spies evs)) = (A \<in> bad)"
paulson@11287
   404
by auto
paulson@11287
   405
paulson@11287
   406
lemma Spy_see_priK_D [dest!]:
paulson@11287
   407
     "[|Key (priK A) \<in> parts (knows Spy evs);  evs \<in> tls|] ==> A \<in> bad"
paulson@11287
   408
by (blast dest: Spy_see_priK)
paulson@11287
   409
paulson@11287
   410
paulson@11287
   411
(*This lemma says that no false certificates exist.  One might extend the
paulson@11287
   412
  model to include bogus certificates for the agents, but there seems
paulson@11287
   413
  little point in doing so: the loss of their private keys is a worse
paulson@11287
   414
  breach of security.*)
paulson@11287
   415
lemma certificate_valid:
paulson@11287
   416
    "[| certificate B KB \<in> parts (spies evs);  evs \<in> tls |] ==> KB = pubK B"
paulson@11287
   417
apply (erule rev_mp)
paulson@11287
   418
apply (erule tls.induct, force, simp_all)
paulson@11287
   419
apply blast 
paulson@11287
   420
done
paulson@11287
   421
paulson@11287
   422
lemmas CX_KB_is_pubKB = Says_imp_spies [THEN parts.Inj, THEN certificate_valid]
paulson@11287
   423
paulson@11287
   424
paulson@11287
   425
(*** Properties of items found in Notes ***)
paulson@11287
   426
paulson@11287
   427
lemma Notes_Crypt_parts_spies:
paulson@11287
   428
     "[| Notes A {|Agent B, X|} \<in> set evs;  evs \<in> tls |]
paulson@11287
   429
      ==> Crypt (pubK B) X \<in> parts (spies evs)"
paulson@11287
   430
apply (erule rev_mp)
paulson@11287
   431
apply (erule tls.induct, 
paulson@11287
   432
       frule_tac [7] CX_KB_is_pubKB, force, simp_all)
paulson@11287
   433
apply (blast intro: parts_insertI)
paulson@11287
   434
done
paulson@11287
   435
paulson@11287
   436
(*C may be either A or B*)
paulson@11287
   437
lemma Notes_master_imp_Crypt_PMS:
paulson@11287
   438
     "[| Notes C {|s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))|} \<in> set evs;
paulson@11287
   439
         evs \<in> tls |]
paulson@11287
   440
      ==> Crypt (pubK B) (Nonce PMS) \<in> parts (spies evs)"
paulson@11287
   441
apply (erule rev_mp)
paulson@11287
   442
apply (erule tls.induct, force, simp_all)
paulson@11287
   443
(*Fake*)
paulson@11287
   444
apply (blast intro: parts_insertI)
paulson@11287
   445
(*Client, Server Accept*)
paulson@11287
   446
apply (blast dest!: Notes_Crypt_parts_spies)+
paulson@11287
   447
done
paulson@11287
   448
paulson@11287
   449
(*Compared with the theorem above, both premise and conclusion are stronger*)
paulson@11287
   450
lemma Notes_master_imp_Notes_PMS:
paulson@11287
   451
     "[| Notes A {|s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))|} \<in> set evs;
paulson@11287
   452
         evs \<in> tls |]
paulson@11287
   453
      ==> Notes A {|Agent B, Nonce PMS|} \<in> set evs"
paulson@11287
   454
apply (erule rev_mp)
paulson@11287
   455
apply (erule tls.induct, force, simp_all)
paulson@11287
   456
(*ServerAccepts*)
paulson@11287
   457
apply blast
paulson@11287
   458
done
paulson@11287
   459
paulson@11287
   460
paulson@11287
   461
(*** Protocol goal: if B receives CertVerify, then A sent it ***)
paulson@11287
   462
paulson@11287
   463
(*B can check A's signature if he has received A's certificate.*)
paulson@11287
   464
lemma TrustCertVerify_lemma:
paulson@11287
   465
     "[| X \<in> parts (spies evs);
paulson@11287
   466
         X = Crypt (priK A) (Hash{|nb, Agent B, pms|});
paulson@11287
   467
         evs \<in> tls;  A \<notin> bad |]
paulson@11287
   468
      ==> Says A B X \<in> set evs"
paulson@11287
   469
apply (erule rev_mp, erule ssubst)
paulson@11287
   470
apply (erule tls.induct, force, simp_all)
paulson@11287
   471
apply blast
paulson@11287
   472
done
paulson@11287
   473
paulson@11287
   474
(*Final version: B checks X using the distributed KA instead of priK A*)
paulson@11287
   475
lemma TrustCertVerify:
paulson@11287
   476
     "[| X \<in> parts (spies evs);
paulson@11287
   477
         X = Crypt (invKey KA) (Hash{|nb, Agent B, pms|});
paulson@11287
   478
         certificate A KA \<in> parts (spies evs);
paulson@11287
   479
         evs \<in> tls;  A \<notin> bad |]
paulson@11287
   480
      ==> Says A B X \<in> set evs"
paulson@11287
   481
by (blast dest!: certificate_valid intro!: TrustCertVerify_lemma)
paulson@11287
   482
paulson@11287
   483
paulson@11287
   484
(*If CertVerify is present then A has chosen PMS.*)
paulson@11287
   485
lemma UseCertVerify_lemma:
paulson@11287
   486
     "[| Crypt (priK A) (Hash{|nb, Agent B, Nonce PMS|}) \<in> parts (spies evs);
paulson@11287
   487
         evs \<in> tls;  A \<notin> bad |]
paulson@11287
   488
      ==> Notes A {|Agent B, Nonce PMS|} \<in> set evs"
paulson@11287
   489
apply (erule rev_mp)
paulson@11287
   490
apply (erule tls.induct, force, simp_all)
paulson@11287
   491
apply blast
paulson@11287
   492
done
paulson@11287
   493
paulson@11287
   494
(*Final version using the distributed KA instead of priK A*)
paulson@11287
   495
lemma UseCertVerify:
paulson@11287
   496
     "[| Crypt (invKey KA) (Hash{|nb, Agent B, Nonce PMS|})
paulson@11287
   497
           \<in> parts (spies evs);
paulson@11287
   498
         certificate A KA \<in> parts (spies evs);
paulson@11287
   499
         evs \<in> tls;  A \<notin> bad |]
paulson@11287
   500
      ==> Notes A {|Agent B, Nonce PMS|} \<in> set evs"
paulson@11287
   501
by (blast dest!: certificate_valid intro!: UseCertVerify_lemma)
paulson@11287
   502
paulson@11287
   503
paulson@11287
   504
lemma no_Notes_A_PRF [simp]:
paulson@11287
   505
     "evs \<in> tls ==> Notes A {|Agent B, Nonce (PRF x)|} \<notin> set evs"
paulson@11287
   506
apply (erule tls.induct, force, simp_all)
paulson@11287
   507
(*ClientKeyExch: PMS is assumed to differ from any PRF.*)
paulson@11287
   508
apply blast
paulson@11287
   509
done
paulson@11287
   510
paulson@11287
   511
paulson@11287
   512
lemma MS_imp_PMS [dest!]:
paulson@11287
   513
     "[| Nonce (PRF (PMS,NA,NB)) \<in> parts (spies evs);  evs \<in> tls |]
paulson@11287
   514
      ==> Nonce PMS \<in> parts (spies evs)"
paulson@11287
   515
apply (erule rev_mp)
paulson@11287
   516
apply (erule tls.induct, force, simp_all)
paulson@11287
   517
(*Fake*)
paulson@11287
   518
apply (blast intro: parts_insertI)
paulson@11287
   519
(*Easy, e.g. by freshness*)
paulson@11287
   520
apply (blast dest: Notes_Crypt_parts_spies)+
paulson@11287
   521
done
paulson@11287
   522
paulson@11287
   523
paulson@11287
   524
paulson@11287
   525
paulson@11287
   526
(*** Unicity results for PMS, the pre-master-secret ***)
paulson@11287
   527
paulson@11287
   528
(*PMS determines B.*)
paulson@11287
   529
lemma Crypt_unique_PMS:
paulson@11287
   530
     "[| Crypt(pubK B)  (Nonce PMS) \<in> parts (spies evs);
paulson@11287
   531
         Crypt(pubK B') (Nonce PMS) \<in> parts (spies evs);
paulson@11287
   532
         Nonce PMS \<notin> analz (spies evs);
paulson@11287
   533
         evs \<in> tls |]
paulson@11287
   534
      ==> B=B'"
paulson@11287
   535
apply (erule rev_mp, erule rev_mp, erule rev_mp)
paulson@11287
   536
apply (erule tls.induct, analz_mono_contra, force, simp_all (no_asm_simp))
paulson@11287
   537
(*Fake, ClientKeyExch*)
paulson@11287
   538
apply blast+
paulson@11287
   539
done
paulson@11287
   540
paulson@11287
   541
paulson@11287
   542
(** It is frustrating that we need two versions of the unicity results.
paulson@11287
   543
    But Notes A {|Agent B, Nonce PMS|} determines both A and B.  Sometimes
paulson@11287
   544
    we have only the weaker assertion Crypt(pubK B) (Nonce PMS), which
paulson@11287
   545
    determines B alone, and only if PMS is secret.
paulson@11287
   546
**)
paulson@11287
   547
paulson@11287
   548
(*In A's internal Note, PMS determines A and B.*)
paulson@11287
   549
lemma Notes_unique_PMS:
paulson@11287
   550
     "[| Notes A  {|Agent B,  Nonce PMS|} \<in> set evs;
paulson@11287
   551
         Notes A' {|Agent B', Nonce PMS|} \<in> set evs;
paulson@11287
   552
         evs \<in> tls |]
paulson@11287
   553
      ==> A=A' & B=B'"
paulson@11287
   554
apply (erule rev_mp, erule rev_mp)
paulson@11287
   555
apply (erule tls.induct, force, simp_all)
paulson@11287
   556
(*ClientKeyExch*)
paulson@11287
   557
apply (blast dest!: Notes_Crypt_parts_spies)
paulson@11287
   558
done
paulson@11287
   559
paulson@11287
   560
paulson@11287
   561
(**** Secrecy Theorems ****)
paulson@11287
   562
paulson@11287
   563
(*Key compromise lemma needed to prove analz_image_keys.
paulson@11287
   564
  No collection of keys can help the spy get new private keys.*)
paulson@11287
   565
lemma analz_image_priK [rule_format]:
paulson@11287
   566
     "evs \<in> tls
paulson@11287
   567
      ==> \<forall>KK. (Key(priK B) \<in> analz (Key`KK Un (spies evs))) =
paulson@11287
   568
          (priK B \<in> KK | B \<in> bad)"
paulson@11287
   569
apply (erule tls.induct)
paulson@11287
   570
apply (simp_all (no_asm_simp)
paulson@11287
   571
		del: image_insert
paulson@11287
   572
                add: image_Un [THEN sym]
paulson@11287
   573
                     insert_Key_image Un_assoc [THEN sym])
paulson@11287
   574
(*Fake*)
paulson@11287
   575
apply spy_analz
paulson@11287
   576
done
paulson@11287
   577
paulson@11287
   578
paulson@11287
   579
(*slightly speeds up the big simplification below*)
paulson@11287
   580
lemma range_sessionkeys_not_priK:
paulson@11287
   581
     "KK <= range sessionK ==> priK B \<notin> KK"
paulson@11287
   582
by blast
paulson@11287
   583
paulson@11287
   584
paulson@11287
   585
(*Lemma for the trivial direction of the if-and-only-if*)
paulson@11287
   586
lemma analz_image_keys_lemma:
paulson@11287
   587
     "(X \<in> analz (G Un H)) --> (X \<in> analz H)  ==>
paulson@11287
   588
      (X \<in> analz (G Un H))  =  (X \<in> analz H)"
paulson@11287
   589
by (blast intro: analz_mono [THEN subsetD])
paulson@11287
   590
paulson@11287
   591
(** Strangely, the following version doesn't work:
paulson@11287
   592
\<forall>Z. (Nonce N \<in> analz (Key`(sessionK`Z) Un (spies evs))) =
paulson@11287
   593
    (Nonce N \<in> analz (spies evs))"
paulson@11287
   594
**)
paulson@11287
   595
paulson@11287
   596
lemma analz_image_keys [rule_format]:
paulson@11287
   597
     "evs \<in> tls ==>
paulson@11287
   598
      \<forall>KK. KK <= range sessionK -->
paulson@11287
   599
	      (Nonce N \<in> analz (Key`KK Un (spies evs))) =
paulson@11287
   600
	      (Nonce N \<in> analz (spies evs))"
paulson@11287
   601
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   602
apply (safe del: iffI)
paulson@11287
   603
apply (safe del: impI iffI intro!: analz_image_keys_lemma)
paulson@11287
   604
apply (simp_all (no_asm_simp)               (*faster*)
paulson@11287
   605
                del: image_insert imp_disjL (*reduces blow-up*)
paulson@11287
   606
		add: image_Un [THEN sym]  Un_assoc [THEN sym]
paulson@11287
   607
		     insert_Key_singleton
paulson@11287
   608
		     range_sessionkeys_not_priK analz_image_priK)
paulson@11287
   609
apply (simp_all add: insert_absorb)
paulson@11287
   610
(*Fake*)
paulson@11287
   611
apply spy_analz
paulson@11287
   612
done
paulson@11287
   613
paulson@11287
   614
(*Knowing some session keys is no help in getting new nonces*)
paulson@11287
   615
lemma analz_insert_key [simp]:
paulson@11287
   616
     "evs \<in> tls ==>
wenzelm@11655
   617
      (Nonce N \<in> analz (insert (Key (sessionK z)) (spies evs))) =
paulson@11287
   618
      (Nonce N \<in> analz (spies evs))"
paulson@11287
   619
by (simp del: image_insert
paulson@11287
   620
         add: insert_Key_singleton analz_image_keys)
paulson@11287
   621
paulson@11287
   622
paulson@11287
   623
(*** Protocol goal: serverK(Na,Nb,M) and clientK(Na,Nb,M) remain secure ***)
paulson@11287
   624
paulson@11287
   625
(** Some lemmas about session keys, comprising clientK and serverK **)
paulson@11287
   626
paulson@11287
   627
paulson@11287
   628
(*Lemma: session keys are never used if PMS is fresh.
paulson@11287
   629
  Nonces don't have to agree, allowing session resumption.
paulson@11287
   630
  Converse doesn't hold; revealing PMS doesn't force the keys to be sent.
paulson@11287
   631
  THEY ARE NOT SUITABLE AS SAFE ELIM RULES.*)
paulson@11287
   632
lemma PMS_lemma:
paulson@11287
   633
     "[| Nonce PMS \<notin> parts (spies evs);
paulson@11287
   634
         K = sessionK((Na, Nb, PRF(PMS,NA,NB)), role);
paulson@11287
   635
         evs \<in> tls |]
paulson@11287
   636
   ==> Key K \<notin> parts (spies evs) & (\<forall>Y. Crypt K Y \<notin> parts (spies evs))"
paulson@11287
   637
apply (erule rev_mp, erule ssubst)
paulson@11287
   638
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   639
apply (force, simp_all (no_asm_simp))
paulson@11287
   640
(*Fake*)
paulson@11287
   641
apply (blast intro: parts_insertI)
paulson@11287
   642
(*SpyKeys*)
paulson@11287
   643
apply blast
paulson@11287
   644
(*Many others*)
paulson@11287
   645
apply (force dest!: Notes_Crypt_parts_spies Notes_master_imp_Crypt_PMS)+
paulson@11287
   646
done
paulson@11287
   647
paulson@11287
   648
lemma PMS_sessionK_not_spied:
paulson@11287
   649
     "[| Key (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) \<in> parts (spies evs);
paulson@11287
   650
         evs \<in> tls |]
paulson@11287
   651
      ==> Nonce PMS \<in> parts (spies evs)"
paulson@11287
   652
by (blast dest: PMS_lemma)
paulson@11287
   653
paulson@11287
   654
lemma PMS_Crypt_sessionK_not_spied:
paulson@11287
   655
     "[| Crypt (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) Y
paulson@11287
   656
           \<in> parts (spies evs);  evs \<in> tls |]
paulson@11287
   657
      ==> Nonce PMS \<in> parts (spies evs)"
paulson@11287
   658
by (blast dest: PMS_lemma)
paulson@11287
   659
paulson@11287
   660
(*Write keys are never sent if M (MASTER SECRET) is secure.
paulson@11287
   661
  Converse fails; betraying M doesn't force the keys to be sent!
paulson@11287
   662
  The strong Oops condition can be weakened later by unicity reasoning,
paulson@11287
   663
  with some effort.
paulson@11287
   664
  NO LONGER USED: see clientK_not_spied and serverK_not_spied*)
paulson@11287
   665
lemma sessionK_not_spied:
paulson@11287
   666
     "[| \<forall>A. Says A Spy (Key (sessionK((NA,NB,M),role))) \<notin> set evs;
paulson@11287
   667
         Nonce M \<notin> analz (spies evs);  evs \<in> tls |]
paulson@11287
   668
      ==> Key (sessionK((NA,NB,M),role)) \<notin> parts (spies evs)"
paulson@11287
   669
apply (erule rev_mp, erule rev_mp)
paulson@11287
   670
apply (erule tls.induct, analz_mono_contra)
paulson@11287
   671
apply (force, simp_all (no_asm_simp))
paulson@11287
   672
(*Fake, SpyKeys*)
paulson@11287
   673
apply blast+
paulson@11287
   674
done
paulson@11287
   675
paulson@11287
   676
paulson@11287
   677
(*If A sends ClientKeyExch to an honest B, then the PMS will stay secret.*)
paulson@11287
   678
lemma Spy_not_see_PMS:
paulson@11287
   679
     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
paulson@11287
   680
         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
paulson@11287
   681
      ==> Nonce PMS \<notin> analz (spies evs)"
paulson@11287
   682
apply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   683
apply (force, simp_all (no_asm_simp))
paulson@11287
   684
(*Fake*)
paulson@11287
   685
apply spy_analz
paulson@11287
   686
(*SpyKeys*)
paulson@11287
   687
apply force
paulson@11287
   688
apply (simp_all add: insert_absorb) 
paulson@11287
   689
(*ClientHello, ServerHello, ClientKeyExch: mostly freshness reasoning*)
paulson@11287
   690
apply (blast dest: Notes_Crypt_parts_spies)
paulson@11287
   691
apply (blast dest: Notes_Crypt_parts_spies)
paulson@11287
   692
apply (blast dest: Notes_Crypt_parts_spies)
paulson@11287
   693
(*ClientAccepts and ServerAccepts: because PMS \<notin> range PRF*)
paulson@11287
   694
apply force+
paulson@11287
   695
done
paulson@11287
   696
paulson@11287
   697
paulson@11287
   698
(*If A sends ClientKeyExch to an honest B, then the MASTER SECRET
paulson@11287
   699
  will stay secret.*)
paulson@11287
   700
lemma Spy_not_see_MS:
paulson@11287
   701
     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
paulson@11287
   702
         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
paulson@11287
   703
      ==> Nonce (PRF(PMS,NA,NB)) \<notin> analz (spies evs)"
paulson@11287
   704
apply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   705
apply (force, simp_all (no_asm_simp))
paulson@11287
   706
(*Fake*)
paulson@11287
   707
apply spy_analz
paulson@11287
   708
(*SpyKeys: by secrecy of the PMS, Spy cannot make the MS*)
paulson@11287
   709
apply (blast dest!: Spy_not_see_PMS)
paulson@11287
   710
apply (simp_all add: insert_absorb)
paulson@11287
   711
(*ClientAccepts and ServerAccepts: because PMS was already visible;
paulson@11287
   712
  others, freshness etc.*)
paulson@11287
   713
apply (blast dest: Notes_Crypt_parts_spies Spy_not_see_PMS 
paulson@11287
   714
                   Notes_imp_knows_Spy [THEN analz.Inj])+
paulson@11287
   715
done
paulson@11287
   716
paulson@11287
   717
paulson@11287
   718
paulson@11287
   719
(*** Weakening the Oops conditions for leakage of clientK ***)
paulson@11287
   720
paulson@11287
   721
(*If A created PMS then nobody else (except the Spy in replays)
paulson@11287
   722
  would send a message using a clientK generated from that PMS.*)
paulson@11287
   723
lemma Says_clientK_unique:
paulson@11287
   724
     "[| Says A' B' (Crypt (clientK(Na,Nb,PRF(PMS,NA,NB))) Y) \<in> set evs;
paulson@11287
   725
         Notes A {|Agent B, Nonce PMS|} \<in> set evs;
paulson@11287
   726
         evs \<in> tls;  A' \<noteq> Spy |]
paulson@11287
   727
      ==> A = A'"
paulson@11287
   728
apply (erule rev_mp, erule rev_mp)
paulson@11287
   729
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   730
apply (force, simp_all)
paulson@11287
   731
(*ClientKeyExch*)
paulson@11287
   732
apply (blast dest!: PMS_Crypt_sessionK_not_spied)
paulson@11287
   733
(*ClientFinished, ClientResume: by unicity of PMS*)
paulson@11287
   734
apply (blast dest!: Notes_master_imp_Notes_PMS 
paulson@11287
   735
             intro: Notes_unique_PMS [THEN conjunct1])+
paulson@11287
   736
done
paulson@11287
   737
paulson@11287
   738
paulson@11287
   739
(*If A created PMS and has not leaked her clientK to the Spy,
paulson@11287
   740
  then it is completely secure: not even in parts!*)
paulson@11287
   741
lemma clientK_not_spied:
paulson@11287
   742
     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
paulson@11287
   743
         Says A Spy (Key (clientK(Na,Nb,PRF(PMS,NA,NB)))) \<notin> set evs;
paulson@11287
   744
         A \<notin> bad;  B \<notin> bad;
paulson@11287
   745
         evs \<in> tls |]
paulson@11287
   746
      ==> Key (clientK(Na,Nb,PRF(PMS,NA,NB))) \<notin> parts (spies evs)"
paulson@11287
   747
apply (erule rev_mp, erule rev_mp)
paulson@11287
   748
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   749
apply (force, simp_all (no_asm_simp))
paulson@11287
   750
(*ClientKeyExch*)
paulson@11287
   751
apply blast 
paulson@11287
   752
(*SpyKeys*)
paulson@11287
   753
apply (blast dest!: Spy_not_see_MS)
paulson@11287
   754
(*ClientKeyExch*)
paulson@11287
   755
apply (blast dest!: PMS_sessionK_not_spied)
paulson@11287
   756
(*Oops*)
paulson@11287
   757
apply (blast intro: Says_clientK_unique)
paulson@11287
   758
done
paulson@11287
   759
paulson@11287
   760
paulson@11287
   761
(*** Weakening the Oops conditions for leakage of serverK ***)
paulson@11287
   762
paulson@11287
   763
(*If A created PMS for B, then nobody other than B or the Spy would
paulson@11287
   764
  send a message using a serverK generated from that PMS.*)
paulson@11287
   765
lemma Says_serverK_unique:
paulson@11287
   766
     "[| Says B' A' (Crypt (serverK(Na,Nb,PRF(PMS,NA,NB))) Y) \<in> set evs;
paulson@11287
   767
         Notes A {|Agent B, Nonce PMS|} \<in> set evs;
paulson@11287
   768
         evs \<in> tls;  A \<notin> bad;  B \<notin> bad;  B' \<noteq> Spy |]
paulson@11287
   769
      ==> B = B'"
paulson@11287
   770
apply (erule rev_mp, erule rev_mp)
paulson@11287
   771
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   772
apply (force, simp_all)
paulson@11287
   773
(*ClientKeyExch*)
paulson@11287
   774
apply (blast dest!: PMS_Crypt_sessionK_not_spied)
paulson@11287
   775
(*ServerResume, ServerFinished: by unicity of PMS*)
paulson@11287
   776
apply (blast dest!: Notes_master_imp_Crypt_PMS 
paulson@11287
   777
             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+
paulson@11287
   778
done
paulson@11287
   779
paulson@11287
   780
paulson@11287
   781
(*If A created PMS for B, and B has not leaked his serverK to the Spy,
paulson@11287
   782
  then it is completely secure: not even in parts!*)
paulson@11287
   783
lemma serverK_not_spied:
paulson@11287
   784
     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
paulson@11287
   785
         Says B Spy (Key(serverK(Na,Nb,PRF(PMS,NA,NB)))) \<notin> set evs;
paulson@11287
   786
         A \<notin> bad;  B \<notin> bad;  evs \<in> tls |]
paulson@11287
   787
      ==> Key (serverK(Na,Nb,PRF(PMS,NA,NB))) \<notin> parts (spies evs)"
paulson@11287
   788
apply (erule rev_mp, erule rev_mp)
paulson@11287
   789
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   790
apply (force, simp_all (no_asm_simp))
paulson@11287
   791
(*Fake*)
paulson@11287
   792
apply blast 
paulson@11287
   793
(*SpyKeys*)
paulson@11287
   794
apply (blast dest!: Spy_not_see_MS)
paulson@11287
   795
(*ClientKeyExch*)
paulson@11287
   796
apply (blast dest!: PMS_sessionK_not_spied)
paulson@11287
   797
(*Oops*)
paulson@11287
   798
apply (blast intro: Says_serverK_unique)
paulson@11287
   799
done
paulson@11287
   800
paulson@11287
   801
paulson@11287
   802
(*** Protocol goals: if A receives ServerFinished, then B is present
paulson@11287
   803
     and has used the quoted values PA, PB, etc.  Note that it is up to A
paulson@11287
   804
     to compare PA with what she originally sent.
paulson@11287
   805
***)
paulson@11287
   806
paulson@11287
   807
(*The mention of her name (A) in X assures A that B knows who she is.*)
paulson@11287
   808
lemma TrustServerFinished [rule_format]:
paulson@11287
   809
     "[| X = Crypt (serverK(Na,Nb,M))
paulson@11287
   810
               (Hash{|Number SID, Nonce M,
paulson@11287
   811
                      Nonce Na, Number PA, Agent A,
paulson@11287
   812
                      Nonce Nb, Number PB, Agent B|});
paulson@11287
   813
         M = PRF(PMS,NA,NB);
paulson@11287
   814
         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
paulson@11287
   815
      ==> Says B Spy (Key(serverK(Na,Nb,M))) \<notin> set evs -->
paulson@11287
   816
          Notes A {|Agent B, Nonce PMS|} \<in> set evs -->
paulson@11287
   817
          X \<in> parts (spies evs) --> Says B A X \<in> set evs"
paulson@11287
   818
apply (erule ssubst)+
paulson@11287
   819
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   820
apply (force, simp_all (no_asm_simp))
paulson@11287
   821
(*Fake: the Spy doesn't have the critical session key!*)
paulson@11287
   822
apply (blast dest: serverK_not_spied)
paulson@11287
   823
(*ClientKeyExch*)
paulson@11287
   824
apply (blast dest!: PMS_Crypt_sessionK_not_spied)
paulson@11287
   825
done
paulson@11287
   826
paulson@11287
   827
(*This version refers not to ServerFinished but to any message from B.
paulson@11287
   828
  We don't assume B has received CertVerify, and an intruder could
paulson@11287
   829
  have changed A's identity in all other messages, so we can't be sure
paulson@11287
   830
  that B sends his message to A.  If CLIENT KEY EXCHANGE were augmented
paulson@11287
   831
  to bind A's identity with PMS, then we could replace A' by A below.*)
paulson@11287
   832
lemma TrustServerMsg [rule_format]:
paulson@11287
   833
     "[| M = PRF(PMS,NA,NB);  evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
paulson@11287
   834
      ==> Says B Spy (Key(serverK(Na,Nb,M))) \<notin> set evs -->
paulson@11287
   835
          Notes A {|Agent B, Nonce PMS|} \<in> set evs -->
paulson@11287
   836
          Crypt (serverK(Na,Nb,M)) Y \<in> parts (spies evs)  -->
paulson@11287
   837
          (\<exists>A'. Says B A' (Crypt (serverK(Na,Nb,M)) Y) \<in> set evs)"
paulson@11287
   838
apply (erule ssubst)
paulson@11287
   839
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   840
apply (force, simp_all (no_asm_simp) add: ex_disj_distrib)
paulson@11287
   841
(*Fake: the Spy doesn't have the critical session key!*)
paulson@11287
   842
apply (blast dest: serverK_not_spied)
paulson@11287
   843
(*ClientKeyExch*)
paulson@11287
   844
apply (clarify, blast dest!: PMS_Crypt_sessionK_not_spied)
paulson@11287
   845
(*ServerResume, ServerFinished: by unicity of PMS*)
paulson@11287
   846
apply (blast dest!: Notes_master_imp_Crypt_PMS 
paulson@11287
   847
             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+
paulson@11287
   848
done
paulson@11287
   849
paulson@11287
   850
paulson@11287
   851
(*** Protocol goal: if B receives any message encrypted with clientK
paulson@11287
   852
     then A has sent it, ASSUMING that A chose PMS.  Authentication is
paulson@11287
   853
     assumed here; B cannot verify it.  But if the message is
paulson@11287
   854
     ClientFinished, then B can then check the quoted values PA, PB, etc.
paulson@11287
   855
***)
paulson@11287
   856
paulson@11287
   857
lemma TrustClientMsg [rule_format]:
paulson@11287
   858
     "[| M = PRF(PMS,NA,NB);  evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
paulson@11287
   859
      ==> Says A Spy (Key(clientK(Na,Nb,M))) \<notin> set evs -->
paulson@11287
   860
          Notes A {|Agent B, Nonce PMS|} \<in> set evs -->
paulson@11287
   861
          Crypt (clientK(Na,Nb,M)) Y \<in> parts (spies evs) -->
paulson@11287
   862
          Says A B (Crypt (clientK(Na,Nb,M)) Y) \<in> set evs"
paulson@11287
   863
apply (erule ssubst)
paulson@11287
   864
apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
paulson@11287
   865
apply (force, simp_all (no_asm_simp))
paulson@11287
   866
(*Fake: the Spy doesn't have the critical session key!*)
paulson@11287
   867
apply (blast dest: clientK_not_spied)
paulson@11287
   868
(*ClientKeyExch*)
paulson@11287
   869
apply (blast dest!: PMS_Crypt_sessionK_not_spied)
paulson@11287
   870
(*ClientFinished, ClientResume: by unicity of PMS*)
paulson@11287
   871
apply (blast dest!: Notes_master_imp_Notes_PMS dest: Notes_unique_PMS)+
paulson@11287
   872
done
paulson@11287
   873
paulson@11287
   874
paulson@11287
   875
(*** Protocol goal: if B receives ClientFinished, and if B is able to
paulson@11287
   876
     check a CertVerify from A, then A has used the quoted
paulson@11287
   877
     values PA, PB, etc.  Even this one requires A to be uncompromised.
paulson@11287
   878
 ***)
paulson@11287
   879
lemma AuthClientFinished:
paulson@11287
   880
     "[| M = PRF(PMS,NA,NB);
paulson@11287
   881
         Says A Spy (Key(clientK(Na,Nb,M))) \<notin> set evs;
paulson@11287
   882
         Says A' B (Crypt (clientK(Na,Nb,M)) Y) \<in> set evs;
paulson@11287
   883
         certificate A KA \<in> parts (spies evs);
paulson@11287
   884
         Says A'' B (Crypt (invKey KA) (Hash{|nb, Agent B, Nonce PMS|}))
paulson@11287
   885
           \<in> set evs;
paulson@11287
   886
         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
paulson@11287
   887
      ==> Says A B (Crypt (clientK(Na,Nb,M)) Y) \<in> set evs"
paulson@11287
   888
by (blast intro!: TrustClientMsg UseCertVerify)
paulson@11287
   889
paulson@11287
   890
(*22/9/97: loads in 622s, which is 10 minutes 22 seconds*)
paulson@11287
   891
(*24/9/97: loads in 672s, which is 11 minutes 12 seconds [stronger theorems]*)
paulson@11287
   892
(*29/9/97: loads in 481s, after removing Certificate from ClientKeyExch*)
paulson@11287
   893
(*30/9/97: loads in 476s, after removing unused theorems*)
paulson@11287
   894
(*30/9/97: loads in 448s, after fixing ServerResume*)
paulson@11287
   895
paulson@11287
   896
(*08/9/97: loads in 189s (pike), after much reorganization,
paulson@11287
   897
           back to 621s on albatross?*)
paulson@11287
   898
paulson@11287
   899
(*10/2/99: loads in 139s (pike)
paulson@11287
   900
           down to 433s on albatross*)
paulson@11287
   901
paulson@11287
   902
(*5/5/01: conversion to Isar script
paulson@11287
   903
	  loads in 137s (perch)
paulson@11287
   904
          the last ML version loaded in 122s on perch, a 600MHz machine:
paulson@11287
   905
		twice as fast as pike.  No idea why it's so much slower!
paulson@11287
   906
	  The Isar script is slower still, perhaps because simp_all simplifies
paulson@11287
   907
	  the assumptions be default.
paulson@11287
   908
*)
paulson@3474
   909
paulson@3474
   910
end