src/HOL/Auth/TLS.thy
author paulson
Mon Sep 29 11:46:33 1997 +0200 (1997-09-29)
changeset 3729 6be7cf5086ab
parent 3710 ea830f6e3c2d
child 3745 4c5d3b1ddc75
permissions -rw-r--r--
Renamed XA, XB to PA, PB and removed the certificate from Client Verify
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@3474
     6
Inductive relation "tls" for the baby 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@3672
    24
REMARK.  The event "Notes A {|Agent B, Nonce PMS|}" appears in ClientCertKeyEx,
paulson@3515
    25
CertVerify, ClientFinished to record that A knows M.  It is a note from A to
paulson@3515
    26
herself.  Nobody else can see it.  In ClientCertKeyEx, 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@3685
    36
Proofs would be simpler if ClientCertKeyEx 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@3474
    42
TLS = Public + 
paulson@3474
    43
paulson@3474
    44
consts
paulson@3672
    45
  (*Pseudo-random function of Section 5*)
paulson@3672
    46
  PRF  :: "nat*nat*nat => nat"
paulson@3672
    47
paulson@3704
    48
  (*Client, server write keys are generated uniformly by function sessionK
paulson@3704
    49
    to avoid duplicating their properties.  They are indexed by a further
paulson@3704
    50
    natural number, not a bool, to avoid the peculiarities of if-and-only-if.
paulson@3704
    51
    Session keys implicitly include MAC secrets.*)
paulson@3704
    52
  sessionK :: "(nat*nat*nat)*nat => key"
paulson@3672
    53
paulson@3500
    54
  certificate      :: "[agent,key] => msg"
paulson@3500
    55
paulson@3500
    56
defs
paulson@3500
    57
  certificate_def
paulson@3500
    58
    "certificate A KA == Crypt (priK Server) {|Agent A, Key KA|}"
paulson@3474
    59
paulson@3677
    60
syntax
paulson@3677
    61
    clientK, serverK :: "nat*nat*nat => key"
paulson@3677
    62
paulson@3677
    63
translations
paulson@3704
    64
  "clientK (x)"	== "sessionK(x,0)"
paulson@3704
    65
  "serverK (x)"	== "sessionK(x,1)"
paulson@3677
    66
paulson@3474
    67
rules
paulson@3672
    68
  inj_PRF       "inj PRF"	
paulson@3672
    69
paulson@3687
    70
  (*sessionK is collision-free and makes symmetric keys.  Also, no clientK
paulson@3687
    71
    clashes with any serverK.*)
paulson@3677
    72
  inj_sessionK  "inj sessionK"	
paulson@3677
    73
paulson@3677
    74
  isSym_sessionK "isSymKey (sessionK x)"
paulson@3474
    75
paulson@3474
    76
paulson@3519
    77
consts    tls :: event list set
paulson@3474
    78
inductive tls
paulson@3474
    79
  intrs 
paulson@3474
    80
    Nil  (*Initial trace is empty*)
paulson@3474
    81
         "[]: tls"
paulson@3474
    82
paulson@3474
    83
    Fake (*The spy, an active attacker, MAY say anything he CAN say.*)
paulson@3474
    84
         "[| evs: tls;  B ~= Spy;  
paulson@3683
    85
             X: synth (analz (spies evs)) |]
paulson@3480
    86
          ==> Says Spy B X # evs : tls"
paulson@3480
    87
paulson@3687
    88
    SpyKeys (*The spy may apply PRF & sessionK to available nonces*)
paulson@3672
    89
         "[| evsSK: tls;
paulson@3672
    90
	     Says Spy B {|Nonce NA, Nonce NB, Nonce M|} : set evsSK |]
paulson@3672
    91
          ==> Says Spy B {| Nonce (PRF(M,NA,NB)),
paulson@3687
    92
			    Key (sessionK((NA,NB,M),b)) |} # evsSK : tls"
paulson@3474
    93
paulson@3474
    94
    ClientHello
paulson@3672
    95
	 (*(7.4.1.2)
paulson@3729
    96
	   PA represents CLIENT_VERSION, CIPHER_SUITES and COMPRESSION_METHODS.
paulson@3474
    97
	   It is uninterpreted but will be confirmed in the FINISHED messages.
paulson@3676
    98
	   NA is CLIENT RANDOM, while SID is SESSION_ID.
paulson@3676
    99
           UNIX TIME is omitted because the protocol doesn't use it.
paulson@3676
   100
           May assume NA ~: range PRF because CLIENT RANDOM is 28 bytes
paulson@3676
   101
	   while MASTER SECRET is 48 byptes*)
paulson@3672
   102
         "[| evsCH: tls;  A ~= B;  Nonce NA ~: used evsCH;  NA ~: range PRF |]
paulson@3729
   103
          ==> Says A B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@3676
   104
	        # evsCH  :  tls"
paulson@3474
   105
paulson@3474
   106
    ServerHello
paulson@3672
   107
         (*7.4.1.3 of the TLS Internet-Draft
paulson@3729
   108
	   PB represents CLIENT_VERSION, CIPHER_SUITE and COMPRESSION_METHOD.
paulson@3672
   109
           SERVER CERTIFICATE (7.4.2) is always present.
paulson@3672
   110
           CERTIFICATE_REQUEST (7.4.4) is implied.*)
paulson@3672
   111
         "[| evsSH: tls;  A ~= B;  Nonce NB ~: used evsSH;  NB ~: range PRF;
paulson@3729
   112
             Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@3676
   113
	       : set evsSH |]
paulson@3729
   114
          ==> Says B A {|Nonce NB, Number SID, Number PB,
paulson@3500
   115
			 certificate B (pubK B)|}
paulson@3672
   116
                # evsSH  :  tls"
paulson@3474
   117
paulson@3474
   118
    ClientCertKeyEx
paulson@3672
   119
         (*CLIENT CERTIFICATE (7.4.6) and KEY EXCHANGE (7.4.7).
paulson@3672
   120
           The client, A, chooses PMS, the PREMASTER SECRET.
paulson@3672
   121
           She encrypts PMS using the supplied KB, which ought to be pubK B.
paulson@3672
   122
           We assume PMS ~: range PRF because a clash betweem the PMS
paulson@3672
   123
           and another MASTER SECRET is highly unlikely (even though
paulson@3672
   124
	   both items have the same length, 48 bytes).
paulson@3672
   125
           The Note event records in the trace that she knows PMS
paulson@3685
   126
               (see REMARK at top). *)
paulson@3672
   127
         "[| evsCX: tls;  A ~= B;  Nonce PMS ~: used evsCX;  PMS ~: range PRF;
paulson@3729
   128
             Says B' A {|Nonce NB, Number SID, Number PB, certificate B KB|}
paulson@3672
   129
	       : set evsCX |]
paulson@3672
   130
          ==> Says A B {|certificate A (pubK A), Crypt KB (Nonce PMS)|}
paulson@3672
   131
	      # Notes A {|Agent B, Nonce PMS|}
paulson@3672
   132
	      # evsCX  :  tls"
paulson@3474
   133
paulson@3474
   134
    CertVerify
paulson@3685
   135
	(*The optional Certificate Verify (7.4.8) message contains the
paulson@3672
   136
          specific components listed in the security analysis, F.1.1.2.
paulson@3672
   137
          It adds the pre-master-secret, which is also essential!
paulson@3672
   138
          Checking the signature, which is the only use of A's certificate,
paulson@3672
   139
          assures B of A's presence*)
paulson@3672
   140
         "[| evsCV: tls;  A ~= B;  
paulson@3729
   141
             Says B' A {|Nonce NB, Number SID, Number PB, certificate B KB|}
paulson@3672
   142
	       : set evsCV;
paulson@3672
   143
	     Notes A {|Agent B, Nonce PMS|} : set evsCV |]
paulson@3729
   144
          ==> Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|}))
paulson@3676
   145
              # evsCV  :  tls"
paulson@3474
   146
paulson@3729
   147
	(*Finally come the FINISHED messages (7.4.8), confirming PA and PB
paulson@3672
   148
          among other things.  The master-secret is PRF(PMS,NA,NB).
paulson@3474
   149
          Either party may sent its message first.*)
paulson@3474
   150
paulson@3685
   151
    ClientFinished
paulson@3672
   152
        (*The occurrence of Notes A {|Agent B, Nonce PMS|} stops the 
paulson@3515
   153
          rule's applying when the Spy has satisfied the "Says A B" by
paulson@3515
   154
          repaying messages sent by the true client; in that case, the
paulson@3685
   155
          Spy does not know PMS and could not sent ClientFinished.  One
paulson@3515
   156
          could simply put A~=Spy into the rule, but one should not
paulson@3515
   157
          expect the spy to be well-behaved.*)
paulson@3672
   158
         "[| evsCF: tls;  
paulson@3729
   159
	     Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@3676
   160
	       : set evsCF;
paulson@3729
   161
             Says B' A {|Nonce NB, Number SID, Number PB, certificate B KB|}
paulson@3672
   162
	       : set evsCF;
paulson@3672
   163
             Notes A {|Agent B, Nonce PMS|} : set evsCF;
paulson@3672
   164
	     M = PRF(PMS,NA,NB) |]
paulson@3474
   165
          ==> Says A B (Crypt (clientK(NA,NB,M))
paulson@3676
   166
			(Hash{|Nonce M, Number SID,
paulson@3729
   167
			       Nonce NA, Number PA, Agent A, 
paulson@3729
   168
			       Nonce NB, Number PB, Agent B|}))
paulson@3676
   169
              # evsCF  :  tls"
paulson@3474
   170
paulson@3685
   171
    ServerFinished
paulson@3474
   172
	(*Keeping A' and A'' distinct means B cannot even check that the
paulson@3672
   173
          two messages originate from the same source. *)
paulson@3672
   174
         "[| evsSF: tls;
paulson@3729
   175
	     Says A' B  {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@3676
   176
	       : set evsSF;
paulson@3729
   177
	     Says B  A  {|Nonce NB, Number SID, Number PB,
paulson@3500
   178
		 	  certificate B (pubK B)|}
paulson@3672
   179
	       : set evsSF;
paulson@3672
   180
	     Says A'' B {|certificate A KA, Crypt (pubK B) (Nonce PMS)|}
paulson@3672
   181
	       : set evsSF;
paulson@3672
   182
	     M = PRF(PMS,NA,NB) |]
paulson@3474
   183
          ==> Says B A (Crypt (serverK(NA,NB,M))
paulson@3676
   184
			(Hash{|Nonce M, Number SID,
paulson@3729
   185
			       Nonce NA, Number PA, Agent A, 
paulson@3729
   186
			       Nonce NB, Number PB, Agent B|}))
paulson@3676
   187
              # evsSF  :  tls"
paulson@3474
   188
paulson@3685
   189
    ClientAccepts
paulson@3685
   190
	(*Having transmitted ClientFinished and received an identical
paulson@3677
   191
          message encrypted with serverK, the client stores the parameters
paulson@3687
   192
          needed to resume this session.  The "Notes A ..." premise is
paulson@3687
   193
          used to prove Notes_master_imp_Crypt_PMS.*)
paulson@3677
   194
         "[| evsCA: tls;
paulson@3685
   195
	     Notes A {|Agent B, Nonce PMS|} : set evsCA;
paulson@3677
   196
	     M = PRF(PMS,NA,NB);  
paulson@3677
   197
	     X = Hash{|Nonce M, Number SID,
paulson@3729
   198
	               Nonce NA, Number PA, Agent A, 
paulson@3729
   199
		       Nonce NB, Number PB, Agent B|};
paulson@3677
   200
             Says A  B (Crypt (clientK(NA,NB,M)) X) : set evsCA;
paulson@3677
   201
             Says B' A (Crypt (serverK(NA,NB,M)) X) : set evsCA |]
paulson@3677
   202
          ==> 
paulson@3677
   203
             Notes A {|Number SID, Agent A, Agent B, Nonce M|} # evsCA  :  tls"
paulson@3677
   204
paulson@3685
   205
    ServerAccepts
paulson@3685
   206
	(*Having transmitted ServerFinished and received an identical
paulson@3677
   207
          message encrypted with clientK, the server stores the parameters
paulson@3687
   208
          needed to resume this session.  The "Says A'' B ..." premise is
paulson@3687
   209
          used to prove Notes_master_imp_Crypt_PMS.*)
paulson@3677
   210
         "[| evsSA: tls;
paulson@3677
   211
             Says A'' B {|certificate A KA, Crypt (pubK B) (Nonce PMS)|}
paulson@3677
   212
	       : set evsSA;
paulson@3677
   213
	     M = PRF(PMS,NA,NB);  
paulson@3677
   214
	     X = Hash{|Nonce M, Number SID,
paulson@3729
   215
	               Nonce NA, Number PA, Agent A, 
paulson@3729
   216
		       Nonce NB, Number PB, Agent B|};
paulson@3677
   217
             Says B  A (Crypt (serverK(NA,NB,M)) X) : set evsSA;
paulson@3677
   218
             Says A' B (Crypt (clientK(NA,NB,M)) X) : set evsSA |]
paulson@3677
   219
          ==> 
paulson@3677
   220
             Notes B {|Number SID, Agent A, Agent B, Nonce M|} # evsSA  :  tls"
paulson@3677
   221
paulson@3685
   222
    ServerResume
paulson@3685
   223
         (*Resumption is described in 7.3.  If B finds the SESSION_ID
paulson@3685
   224
           then he sends HELLO and FINISHED messages, using the
paulson@3685
   225
           previously stored MASTER SECRET*)
paulson@3685
   226
         "[| evsSR: tls;  A ~= B;  Nonce NB ~: used evsSR;  NB ~: range PRF;
paulson@3685
   227
             Notes B {|Number SID, Agent A, Agent B, Nonce M|} : set evsSR;
paulson@3729
   228
	     Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@3685
   229
	       : set evsSR |]
paulson@3685
   230
          ==> Says B A (Crypt (serverK(NA,NB,M))
paulson@3685
   231
			(Hash{|Nonce M, Number SID,
paulson@3729
   232
			       Nonce NA, Number PA, Agent A, 
paulson@3729
   233
			       Nonce NB, Number PB, Agent B|}))
paulson@3729
   234
              # Says B A {|Nonce NB, Number SID, Number PB|} # evsSR  :  tls"
paulson@3685
   235
paulson@3685
   236
    ClientResume
paulson@3685
   237
         (*If the response to ClientHello is ServerResume then send
paulson@3685
   238
           a FINISHED message using the new nonces and stored MASTER SECRET.*)
paulson@3685
   239
         "[| evsCR: tls;  
paulson@3729
   240
	     Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}
paulson@3685
   241
	       : set evsCR;
paulson@3729
   242
             Says B' A {|Nonce NB, Number SID, Number PB|} : set evsCR;
paulson@3685
   243
             Notes A {|Number SID, Agent A, Agent B, Nonce M|} : set evsCR |]
paulson@3685
   244
          ==> Says A B (Crypt (clientK(NA,NB,M))
paulson@3685
   245
			(Hash{|Nonce M, Number SID,
paulson@3729
   246
			       Nonce NA, Number PA, Agent A, 
paulson@3729
   247
			       Nonce NB, Number PB, Agent B|}))
paulson@3685
   248
              # evsCR  :  tls"
paulson@3685
   249
paulson@3686
   250
    Oops 
paulson@3686
   251
         (*The most plausible compromise is of an old session key.  Losing
paulson@3686
   252
           the MASTER SECRET or PREMASTER SECRET is more serious but
paulson@3686
   253
           rather unlikely.*)
paulson@3686
   254
         "[| evso: tls;  A ~= Spy;  
paulson@3686
   255
	     Says A B (Crypt (sessionK((NA,NB,M),b)) X) : set evso |]
paulson@3686
   256
          ==> Says A Spy (Key (sessionK((NA,NB,M),b))) # evso  :  tls"
paulson@3474
   257
paulson@3474
   258
end