src/HOL/Auth/TLS.thy
author paulson
Tue Sep 16 13:32:22 1997 +0200 (1997-09-16)
changeset 3672 56e4365a0c99
parent 3519 ab0a9fbed4c0
child 3676 cbaec955056b
permissions -rw-r--r--
TLS now with a distinction between premaster secret and master secret
     1 (*  Title:      HOL/Auth/TLS
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1997  University of Cambridge
     5 
     6 Inductive relation "tls" for the baby TLS (Transport Layer Security) protocol.
     7 This protocol is essentially the same as SSL 3.0.
     8 
     9 Abstracted from "The TLS Protocol, Version 1.0" by Tim Dierks and Christopher
    10 Allen, Transport Layer Security Working Group, 21 May 1997,
    11 INTERNET-DRAFT draft-ietf-tls-protocol-03.txt.  Section numbers below refer
    12 to that memo.
    13 
    14 An RSA cryptosystem is assumed, and X.509v3 certificates are abstracted down
    15 to the trivial form {A, publicKey(A)}privateKey(Server), where Server is a
    16 global signing authority.
    17 
    18 A is the client and B is the server, not to be confused with the constant
    19 Server, who is in charge of all public keys.
    20 
    21 The model assumes that no fraudulent certificates are present, but it does
    22 assume that some private keys are to the spy.
    23 
    24 REMARK.  The event "Notes A {|Agent B, Nonce PMS|}" appears in ClientCertKeyEx,
    25 CertVerify, ClientFinished to record that A knows M.  It is a note from A to
    26 herself.  Nobody else can see it.  In ClientCertKeyEx, the Spy can substitute
    27 his own certificate for A's, but he cannot replace A's note by one for himself.
    28 
    29 The Note event avoids a weakness in the public-key model.  Each
    30 agent's state is recorded as the trace of messages.  When the true client (A)
    31 invents PMS, he encrypts PMS with B's public key before sending it.  The model
    32 does not distinguish the original occurrence of such a message from a replay.
    33 
    34 In the shared-key model, the ability to encrypt implies the ability to
    35 decrypt, so the problem does not arise.
    36 *)
    37 
    38 TLS = Public + 
    39 
    40 consts
    41   (*Pseudo-random function of Section 5*)
    42   PRF  :: "nat*nat*nat => nat"
    43 
    44   (*Client, server write keys implicitly include the MAC secrets.*)
    45   clientK, serverK :: "nat*nat*nat => key"
    46 
    47   certificate      :: "[agent,key] => msg"
    48 
    49 defs
    50   certificate_def
    51     "certificate A KA == Crypt (priK Server) {|Agent A, Key KA|}"
    52 
    53 rules
    54   inj_PRF       "inj PRF"	
    55 
    56   (*clientK is collision-free and makes symmetric keys*)
    57   inj_clientK   "inj clientK"	
    58   isSym_clientK "isSymKey (clientK x)"	(*client write keys are symmetric*)
    59 
    60   (*serverK is similar*)
    61   inj_serverK   "inj serverK"	
    62   isSym_serverK "isSymKey (serverK x)"	(*server write keys are symmetric*)
    63 
    64   (*Clashes with pubK and priK are impossible, but this axiom is needed.*)
    65   clientK_range "range clientK <= Compl (range serverK)"
    66 
    67 
    68 consts    tls :: event list set
    69 inductive tls
    70   intrs 
    71     Nil  (*Initial trace is empty*)
    72          "[]: tls"
    73 
    74     Fake (*The spy, an active attacker, MAY say anything he CAN say.*)
    75          "[| evs: tls;  B ~= Spy;  
    76              X: synth (analz (sees Spy evs)) |]
    77           ==> Says Spy B X # evs : tls"
    78 
    79     SpyKeys (*The spy may apply PRF, clientK & serverK to available nonces*)
    80          "[| evsSK: tls;
    81 	     Says Spy B {|Nonce NA, Nonce NB, Nonce M|} : set evsSK |]
    82           ==> Says Spy B {| Nonce (PRF(M,NA,NB)),
    83 			    Key (clientK(NA,NB,M)),
    84 			    Key (serverK(NA,NB,M)) |} # evsSK : tls"
    85 
    86     ClientHello
    87 	 (*(7.4.1.2)
    88 	   XA represents CLIENT_VERSION, CIPHER_SUITES and COMPRESSION_METHODS.
    89 	   It is uninterpreted but will be confirmed in the FINISHED messages.
    90 	   As an initial simplification, SESSION_ID is identified with NA
    91            and reuse of sessions is not supported.
    92            May assume NA ~: range PRF because CLIENT RANDOM is 32 bytes
    93 	   while MASTER SECRET is 48 byptes (6.1)*)
    94          "[| evsCH: tls;  A ~= B;  Nonce NA ~: used evsCH;  NA ~: range PRF |]
    95           ==> Says A B {|Agent A, Nonce NA, Number XA|} # evsCH  :  tls"
    96 
    97     ServerHello
    98          (*7.4.1.3 of the TLS Internet-Draft
    99 	   XB represents CLIENT_VERSION, CIPHER_SUITE and COMPRESSION_METHOD.
   100 	   NA is returned in its role as SESSION_ID.
   101            SERVER CERTIFICATE (7.4.2) is always present.
   102            CERTIFICATE_REQUEST (7.4.4) is implied.*)
   103          "[| evsSH: tls;  A ~= B;  Nonce NB ~: used evsSH;  NB ~: range PRF;
   104              Says A' B {|Agent A, Nonce NA, Number XA|} : set evsSH |]
   105           ==> Says B A {|Nonce NA, Nonce NB, Number XB,
   106 			 certificate B (pubK B)|}
   107                 # evsSH  :  tls"
   108 
   109     ClientCertKeyEx
   110          (*CLIENT CERTIFICATE (7.4.6) and KEY EXCHANGE (7.4.7).
   111            The client, A, chooses PMS, the PREMASTER SECRET.
   112            She encrypts PMS using the supplied KB, which ought to be pubK B.
   113            We assume PMS ~: range PRF because a clash betweem the PMS
   114            and another MASTER SECRET is highly unlikely (even though
   115 	   both items have the same length, 48 bytes).
   116            The Note event records in the trace that she knows PMS
   117                (see REMARK at top).*)
   118          "[| evsCX: tls;  A ~= B;  Nonce PMS ~: used evsCX;  PMS ~: range PRF;
   119              Says B' A {|Nonce NA, Nonce NB, Number XB, certificate B KB|}
   120 	       : set evsCX |]
   121           ==> Says A B {|certificate A (pubK A), Crypt KB (Nonce PMS)|}
   122 	      # Notes A {|Agent B, Nonce PMS|}
   123 	      # evsCX  :  tls"
   124 
   125     CertVerify
   126 	(*The optional CERTIFICATE VERIFY (7.4.8) message contains the
   127           specific components listed in the security analysis, F.1.1.2.
   128           It adds the pre-master-secret, which is also essential!
   129           Checking the signature, which is the only use of A's certificate,
   130           assures B of A's presence*)
   131          "[| evsCV: tls;  A ~= B;  
   132              Says B' A {|Nonce NA, Nonce NB, Number XB, certificate B KB|}
   133 	       : set evsCV;
   134 	     Notes A {|Agent B, Nonce PMS|} : set evsCV |]
   135           ==> Says A B (Crypt (priK A)
   136 			(Hash{|Nonce NB, certificate B KB, Nonce PMS|}))
   137                 # evsCV  :  tls"
   138 
   139 	(*Finally come the FINISHED messages (7.4.8), confirming XA and XB
   140           among other things.  The master-secret is PRF(PMS,NA,NB).
   141           Either party may sent its message first.*)
   142 
   143         (*The occurrence of Notes A {|Agent B, Nonce PMS|} stops the 
   144           rule's applying when the Spy has satisfied the "Says A B" by
   145           repaying messages sent by the true client; in that case, the
   146           Spy does not know PMS and could not sent CLIENT FINISHED.  One
   147           could simply put A~=Spy into the rule, but one should not
   148           expect the spy to be well-behaved.*)
   149     ClientFinished
   150          "[| evsCF: tls;  
   151 	     Says A  B {|Agent A, Nonce NA, Number XA|} : set evsCF;
   152              Says B' A {|Nonce NA, Nonce NB, Number XB, certificate B KB|}
   153 	       : set evsCF;
   154              Notes A {|Agent B, Nonce PMS|} : set evsCF;
   155 	     M = PRF(PMS,NA,NB) |]
   156           ==> Says A B (Crypt (clientK(NA,NB,M))
   157 			(Hash{|Nonce M,
   158 			       Nonce NA, Number XA, Agent A, 
   159 			       Nonce NB, Number XB, Agent B|}))
   160                 # evsCF  :  tls"
   161 
   162 	(*Keeping A' and A'' distinct means B cannot even check that the
   163           two messages originate from the same source. *)
   164     ServerFinished
   165          "[| evsSF: tls;
   166 	     Says A' B  {|Agent A, Nonce NA, Number XA|} : set evsSF;
   167 	     Says B  A  {|Nonce NA, Nonce NB, Number XB,
   168 		 	  certificate B (pubK B)|}
   169 	       : set evsSF;
   170 	     Says A'' B {|certificate A KA, Crypt (pubK B) (Nonce PMS)|}
   171 	       : set evsSF;
   172 	     M = PRF(PMS,NA,NB) |]
   173           ==> Says B A (Crypt (serverK(NA,NB,M))
   174 			(Hash{|Nonce M,
   175 			       Nonce NA, Number XA, Agent A, 
   176 			       Nonce NB, Number XB, Agent B|}))
   177                 # evsSF  :  tls"
   178 
   179   (**Oops message??**)
   180 
   181 end