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