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