src/HOL/Auth/TLS.thy
author paulson
Fri Apr 25 11:18:14 2003 +0200 (2003-04-25)
changeset 13922 75ae4244a596
parent 13507 febb8e5d2a9d
child 13956 8fe7e12290e1
permissions -rw-r--r--
Changes required by the certified email protocol

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