src/HOL/Auth/TLS.thy
changeset 11287 0103ee3082bf
parent 11230 756c5034f08b
child 11655 923e4d0d36d5
     1.1 --- a/src/HOL/Auth/TLS.thy	Mon May 07 19:19:41 2001 +0200
     1.2 +++ b/src/HOL/Auth/TLS.thy	Tue May 08 15:56:57 2001 +0200
     1.3 @@ -39,7 +39,7 @@
     1.4  	Notes A {|Agent B, Nonce PMS|}.
     1.5  *)
     1.6  
     1.7 -TLS = Public + 
     1.8 +theory TLS = Public:
     1.9  
    1.10  constdefs
    1.11    certificate      :: "[agent,key] => msg"
    1.12 @@ -58,196 +58,853 @@
    1.13    sessionK :: "(nat*nat*nat) * role => key"
    1.14  
    1.15  syntax
    1.16 -    clientK, serverK :: "nat*nat*nat => key"
    1.17 +    clientK :: "nat*nat*nat => key"
    1.18 +    serverK :: "nat*nat*nat => key"
    1.19  
    1.20  translations
    1.21    "clientK X" == "sessionK(X, ClientRole)"
    1.22    "serverK X" == "sessionK(X, ServerRole)"
    1.23  
    1.24 -rules
    1.25 +axioms
    1.26    (*the pseudo-random function is collision-free*)
    1.27 -  inj_PRF       "inj PRF"	
    1.28 +  inj_PRF:       "inj PRF"
    1.29  
    1.30    (*sessionK is collision-free; also, no clientK clashes with any serverK.*)
    1.31 -  inj_sessionK  "inj sessionK"	
    1.32 +  inj_sessionK:  "inj sessionK"	
    1.33  
    1.34    (*sessionK makes symmetric keys*)
    1.35 -  isSym_sessionK "sessionK nonces \\<in> symKeys"
    1.36 +  isSym_sessionK: "sessionK nonces \<in> symKeys"
    1.37  
    1.38  
    1.39 -consts    tls :: event list set
    1.40 +consts    tls :: "event list set"
    1.41  inductive tls
    1.42 -  intrs 
    1.43 -    Nil  (*Initial trace is empty*)
    1.44 -         "[]: tls"
    1.45 +  intros
    1.46 +   Nil:  (*Initial trace is empty*)
    1.47 +         "[] \<in> tls"
    1.48  
    1.49 -    Fake (*The spy, an active attacker, MAY say anything he CAN say.*)
    1.50 -         "[| evsf \\<in> tls;  X \\<in> synth (analz (spies evsf)) |]
    1.51 -          ==> Says Spy B X # evsf \\<in> tls"
    1.52 +   Fake: (*The spy, an active attacker, MAY say anything he CAN say.*)
    1.53 +         "[| evsf \<in> tls;  X \<in> synth (analz (spies evsf)) |]
    1.54 +          ==> Says Spy B X # evsf \<in> tls"
    1.55  
    1.56 -    SpyKeys (*The spy may apply PRF & sessionK to available nonces*)
    1.57 -         "[| evsSK \\<in> tls;
    1.58 +   SpyKeys: (*The spy may apply PRF & sessionK to available nonces*)
    1.59 +         "[| evsSK \<in> tls;
    1.60  	     {Nonce NA, Nonce NB, Nonce M} <= analz (spies evsSK) |]
    1.61            ==> Notes Spy {| Nonce (PRF(M,NA,NB)),
    1.62 -			   Key (sessionK((NA,NB,M),role)) |} # evsSK \\<in> tls"
    1.63 +			   Key (sessionK((NA,NB,M),role)) |} # evsSK \<in> tls"
    1.64  
    1.65 -    ClientHello
    1.66 +   ClientHello:
    1.67  	 (*(7.4.1.2)
    1.68  	   PA represents CLIENT_VERSION, CIPHER_SUITES and COMPRESSION_METHODS.
    1.69  	   It is uninterpreted but will be confirmed in the FINISHED messages.
    1.70  	   NA is CLIENT RANDOM, while SID is SESSION_ID.
    1.71             UNIX TIME is omitted because the protocol doesn't use it.
    1.72 -           May assume NA \\<notin> range PRF because CLIENT RANDOM is 28 bytes
    1.73 +           May assume NA \<notin> range PRF because CLIENT RANDOM is 28 bytes
    1.74  	   while MASTER SECRET is 48 bytes*)
    1.75 -         "[| evsCH \\<in> tls;  Nonce NA \\<notin> used evsCH;  NA \\<notin> range PRF |]
    1.76 +         "[| evsCH \<in> tls;  Nonce NA \<notin> used evsCH;  NA \<notin> range PRF |]
    1.77            ==> Says A B {|Agent A, Nonce NA, Number SID, Number PA|}
    1.78 -	        # evsCH  \\<in>  tls"
    1.79 +	        # evsCH  \<in>  tls"
    1.80  
    1.81 -    ServerHello
    1.82 +   ServerHello:
    1.83           (*7.4.1.3 of the TLS Internet-Draft
    1.84  	   PB represents CLIENT_VERSION, CIPHER_SUITE and COMPRESSION_METHOD.
    1.85             SERVER CERTIFICATE (7.4.2) is always present.
    1.86             CERTIFICATE_REQUEST (7.4.4) is implied.*)
    1.87 -         "[| evsSH \\<in> tls;  Nonce NB \\<notin> used evsSH;  NB \\<notin> range PRF;
    1.88 +         "[| evsSH \<in> tls;  Nonce NB \<notin> used evsSH;  NB \<notin> range PRF;
    1.89               Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}
    1.90 -	       \\<in> set evsSH |]
    1.91 -          ==> Says B A {|Nonce NB, Number SID, Number PB|} # evsSH  \\<in>  tls"
    1.92 +	       \<in> set evsSH |]
    1.93 +          ==> Says B A {|Nonce NB, Number SID, Number PB|} # evsSH  \<in>  tls"
    1.94  
    1.95 -    Certificate
    1.96 +   Certificate:
    1.97           (*SERVER (7.4.2) or CLIENT (7.4.6) CERTIFICATE.*)
    1.98 -         "evsC \\<in> tls ==> Says B A (certificate B (pubK B)) # evsC  \\<in>  tls"
    1.99 +         "evsC \<in> tls ==> Says B A (certificate B (pubK B)) # evsC  \<in>  tls"
   1.100  
   1.101 -    ClientKeyExch
   1.102 +   ClientKeyExch:
   1.103           (*CLIENT KEY EXCHANGE (7.4.7).
   1.104             The client, A, chooses PMS, the PREMASTER SECRET.
   1.105             She encrypts PMS using the supplied KB, which ought to be pubK B.
   1.106 -           We assume PMS \\<notin> range PRF because a clash betweem the PMS
   1.107 +           We assume PMS \<notin> range PRF because a clash betweem the PMS
   1.108             and another MASTER SECRET is highly unlikely (even though
   1.109  	   both items have the same length, 48 bytes).
   1.110             The Note event records in the trace that she knows PMS
   1.111                 (see REMARK at top). *)
   1.112 -         "[| evsCX \\<in> tls;  Nonce PMS \\<notin> used evsCX;  PMS \\<notin> range PRF;
   1.113 -             Says B' A (certificate B KB) \\<in> set evsCX |]
   1.114 +         "[| evsCX \<in> tls;  Nonce PMS \<notin> used evsCX;  PMS \<notin> range PRF;
   1.115 +             Says B' A (certificate B KB) \<in> set evsCX |]
   1.116            ==> Says A B (Crypt KB (Nonce PMS))
   1.117  	      # Notes A {|Agent B, Nonce PMS|}
   1.118 -	      # evsCX  \\<in>  tls"
   1.119 +	      # evsCX  \<in>  tls"
   1.120  
   1.121 -    CertVerify
   1.122 +   CertVerify:
   1.123  	(*The optional Certificate Verify (7.4.8) message contains the
   1.124            specific components listed in the security analysis, F.1.1.2.
   1.125            It adds the pre-master-secret, which is also essential!
   1.126            Checking the signature, which is the only use of A's certificate,
   1.127            assures B of A's presence*)
   1.128 -         "[| evsCV \\<in> tls;  
   1.129 -             Says B' A {|Nonce NB, Number SID, Number PB|} \\<in> set evsCV;
   1.130 -	     Notes A {|Agent B, Nonce PMS|} \\<in> set evsCV |]
   1.131 +         "[| evsCV \<in> tls;
   1.132 +             Says B' A {|Nonce NB, Number SID, Number PB|} \<in> set evsCV;
   1.133 +	     Notes A {|Agent B, Nonce PMS|} \<in> set evsCV |]
   1.134            ==> Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|}))
   1.135 -              # evsCV  \\<in>  tls"
   1.136 +              # evsCV  \<in>  tls"
   1.137  
   1.138  	(*Finally come the FINISHED messages (7.4.8), confirming PA and PB
   1.139            among other things.  The master-secret is PRF(PMS,NA,NB).
   1.140 -          Either party may sent its message first.*)
   1.141 +          Either party may send its message first.*)
   1.142  
   1.143 -    ClientFinished
   1.144 -        (*The occurrence of Notes A {|Agent B, Nonce PMS|} stops the 
   1.145 +   ClientFinished:
   1.146 +        (*The occurrence of Notes A {|Agent B, Nonce PMS|} stops the
   1.147            rule's applying when the Spy has satisfied the "Says A B" by
   1.148            repaying messages sent by the true client; in that case, the
   1.149            Spy does not know PMS and could not send ClientFinished.  One
   1.150 -          could simply put A\\<noteq>Spy into the rule, but one should not
   1.151 +          could simply put A\<noteq>Spy into the rule, but one should not
   1.152            expect the spy to be well-behaved.*)
   1.153 -         "[| evsCF \\<in> tls;  
   1.154 +         "[| evsCF \<in> tls;
   1.155  	     Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}
   1.156 -	       \\<in> set evsCF;
   1.157 -             Says B' A {|Nonce NB, Number SID, Number PB|} \\<in> set evsCF;
   1.158 -             Notes A {|Agent B, Nonce PMS|} \\<in> set evsCF;
   1.159 +	       \<in> set evsCF;
   1.160 +             Says B' A {|Nonce NB, Number SID, Number PB|} \<in> set evsCF;
   1.161 +             Notes A {|Agent B, Nonce PMS|} \<in> set evsCF;
   1.162  	     M = PRF(PMS,NA,NB) |]
   1.163            ==> Says A B (Crypt (clientK(NA,NB,M))
   1.164  			(Hash{|Number SID, Nonce M,
   1.165 -			       Nonce NA, Number PA, Agent A, 
   1.166 +			       Nonce NA, Number PA, Agent A,
   1.167  			       Nonce NB, Number PB, Agent B|}))
   1.168 -              # evsCF  \\<in>  tls"
   1.169 +              # evsCF  \<in>  tls"
   1.170  
   1.171 -    ServerFinished
   1.172 +   ServerFinished:
   1.173  	(*Keeping A' and A'' distinct means B cannot even check that the
   1.174            two messages originate from the same source. *)
   1.175 -         "[| evsSF \\<in> tls;
   1.176 +         "[| evsSF \<in> tls;
   1.177  	     Says A' B  {|Agent A, Nonce NA, Number SID, Number PA|}
   1.178 -	       \\<in> set evsSF;
   1.179 -	     Says B  A  {|Nonce NB, Number SID, Number PB|} \\<in> set evsSF;
   1.180 -	     Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSF;
   1.181 +	       \<in> set evsSF;
   1.182 +	     Says B  A  {|Nonce NB, Number SID, Number PB|} \<in> set evsSF;
   1.183 +	     Says A'' B (Crypt (pubK B) (Nonce PMS)) \<in> set evsSF;
   1.184  	     M = PRF(PMS,NA,NB) |]
   1.185            ==> Says B A (Crypt (serverK(NA,NB,M))
   1.186  			(Hash{|Number SID, Nonce M,
   1.187 -			       Nonce NA, Number PA, Agent A, 
   1.188 +			       Nonce NA, Number PA, Agent A,
   1.189  			       Nonce NB, Number PB, Agent B|}))
   1.190 -              # evsSF  \\<in>  tls"
   1.191 +              # evsSF  \<in>  tls"
   1.192  
   1.193 -    ClientAccepts
   1.194 +   ClientAccepts:
   1.195  	(*Having transmitted ClientFinished and received an identical
   1.196            message encrypted with serverK, the client stores the parameters
   1.197            needed to resume this session.  The "Notes A ..." premise is
   1.198            used to prove Notes_master_imp_Crypt_PMS.*)
   1.199 -         "[| evsCA \\<in> tls;
   1.200 -	     Notes A {|Agent B, Nonce PMS|} \\<in> set evsCA;
   1.201 -	     M = PRF(PMS,NA,NB);  
   1.202 +         "[| evsCA \<in> tls;
   1.203 +	     Notes A {|Agent B, Nonce PMS|} \<in> set evsCA;
   1.204 +	     M = PRF(PMS,NA,NB);
   1.205  	     X = Hash{|Number SID, Nonce M,
   1.206 -	               Nonce NA, Number PA, Agent A, 
   1.207 +	               Nonce NA, Number PA, Agent A,
   1.208  		       Nonce NB, Number PB, Agent B|};
   1.209 -             Says A  B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsCA;
   1.210 -             Says B' A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsCA |]
   1.211 -          ==> 
   1.212 -             Notes A {|Number SID, Agent A, Agent B, Nonce M|} # evsCA  \\<in>  tls"
   1.213 +             Says A  B (Crypt (clientK(NA,NB,M)) X) \<in> set evsCA;
   1.214 +             Says B' A (Crypt (serverK(NA,NB,M)) X) \<in> set evsCA |]
   1.215 +          ==>
   1.216 +             Notes A {|Number SID, Agent A, Agent B, Nonce M|} # evsCA  \<in>  tls"
   1.217  
   1.218 -    ServerAccepts
   1.219 +   ServerAccepts:
   1.220  	(*Having transmitted ServerFinished and received an identical
   1.221            message encrypted with clientK, the server stores the parameters
   1.222            needed to resume this session.  The "Says A'' B ..." premise is
   1.223            used to prove Notes_master_imp_Crypt_PMS.*)
   1.224 -         "[| evsSA \\<in> tls;
   1.225 -	     A \\<noteq> B;
   1.226 -             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSA;
   1.227 -	     M = PRF(PMS,NA,NB);  
   1.228 +         "[| evsSA \<in> tls;
   1.229 +	     A \<noteq> B;
   1.230 +             Says A'' B (Crypt (pubK B) (Nonce PMS)) \<in> set evsSA;
   1.231 +	     M = PRF(PMS,NA,NB);
   1.232  	     X = Hash{|Number SID, Nonce M,
   1.233 -	               Nonce NA, Number PA, Agent A, 
   1.234 +	               Nonce NA, Number PA, Agent A,
   1.235  		       Nonce NB, Number PB, Agent B|};
   1.236 -             Says B  A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsSA;
   1.237 -             Says A' B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsSA |]
   1.238 -          ==> 
   1.239 -             Notes B {|Number SID, Agent A, Agent B, Nonce M|} # evsSA  \\<in>  tls"
   1.240 +             Says B  A (Crypt (serverK(NA,NB,M)) X) \<in> set evsSA;
   1.241 +             Says A' B (Crypt (clientK(NA,NB,M)) X) \<in> set evsSA |]
   1.242 +          ==>
   1.243 +             Notes B {|Number SID, Agent A, Agent B, Nonce M|} # evsSA  \<in>  tls"
   1.244  
   1.245 -    ClientResume
   1.246 +   ClientResume:
   1.247           (*If A recalls the SESSION_ID, then she sends a FINISHED message
   1.248             using the new nonces and stored MASTER SECRET.*)
   1.249 -         "[| evsCR \\<in> tls;  
   1.250 +         "[| evsCR \<in> tls;
   1.251  	     Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}: set evsCR;
   1.252 -             Says B' A {|Nonce NB, Number SID, Number PB|} \\<in> set evsCR;
   1.253 -             Notes A {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evsCR |]
   1.254 +             Says B' A {|Nonce NB, Number SID, Number PB|} \<in> set evsCR;
   1.255 +             Notes A {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evsCR |]
   1.256            ==> Says A B (Crypt (clientK(NA,NB,M))
   1.257  			(Hash{|Number SID, Nonce M,
   1.258 -			       Nonce NA, Number PA, Agent A, 
   1.259 +			       Nonce NA, Number PA, Agent A,
   1.260  			       Nonce NB, Number PB, Agent B|}))
   1.261 -              # evsCR  \\<in>  tls"
   1.262 +              # evsCR  \<in>  tls"
   1.263  
   1.264 -    ServerResume
   1.265 +   ServerResume:
   1.266           (*Resumption (7.3):  If B finds the SESSION_ID then he can send
   1.267             a FINISHED message using the recovered MASTER SECRET*)
   1.268 -         "[| evsSR \\<in> tls;
   1.269 +         "[| evsSR \<in> tls;
   1.270  	     Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}: set evsSR;
   1.271 -	     Says B  A {|Nonce NB, Number SID, Number PB|} \\<in> set evsSR;  
   1.272 -             Notes B {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evsSR |]
   1.273 +	     Says B  A {|Nonce NB, Number SID, Number PB|} \<in> set evsSR;
   1.274 +             Notes B {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evsSR |]
   1.275            ==> Says B A (Crypt (serverK(NA,NB,M))
   1.276  			(Hash{|Number SID, Nonce M,
   1.277 -			       Nonce NA, Number PA, Agent A, 
   1.278 +			       Nonce NA, Number PA, Agent A,
   1.279  			       Nonce NB, Number PB, Agent B|})) # evsSR
   1.280 -	        \\<in>  tls"
   1.281 +	        \<in>  tls"
   1.282  
   1.283 -    Oops 
   1.284 +   Oops:
   1.285           (*The most plausible compromise is of an old session key.  Losing
   1.286             the MASTER SECRET or PREMASTER SECRET is more serious but
   1.287 -           rather unlikely.  The assumption A \\<noteq> Spy is essential: otherwise
   1.288 +           rather unlikely.  The assumption A \<noteq> Spy is essential: otherwise
   1.289             the Spy could learn session keys merely by replaying messages!*)
   1.290 -         "[| evso \\<in> tls;  A \\<noteq> Spy;
   1.291 -	     Says A B (Crypt (sessionK((NA,NB,M),role)) X) \\<in> set evso |]
   1.292 -          ==> Says A Spy (Key (sessionK((NA,NB,M),role))) # evso  \\<in>  tls"
   1.293 +         "[| evso \<in> tls;  A \<noteq> Spy;
   1.294 +	     Says A B (Crypt (sessionK((NA,NB,M),role)) X) \<in> set evso |]
   1.295 +          ==> Says A Spy (Key (sessionK((NA,NB,M),role))) # evso  \<in>  tls"
   1.296 +
   1.297 +(*
   1.298 +Protocol goals:
   1.299 +* M, serverK(NA,NB,M) and clientK(NA,NB,M) will be known only to the two
   1.300 +     parties (though A is not necessarily authenticated).
   1.301 +
   1.302 +* B upon receiving CertVerify knows that A is present (But this
   1.303 +    message is optional!)
   1.304 +
   1.305 +* A upon receiving ServerFinished knows that B is present
   1.306 +
   1.307 +* Each party who has received a FINISHED message can trust that the other
   1.308 +  party agrees on all message components, including PA and PB (thus foiling
   1.309 +  rollback attacks).
   1.310 +*)
   1.311 +
   1.312 +declare Says_imp_knows_Spy [THEN analz.Inj, dest]
   1.313 +declare parts.Body  [dest]
   1.314 +declare analz_into_parts [dest]
   1.315 +declare Fake_parts_insert_in_Un  [dest]
   1.316 +
   1.317 +
   1.318 +(*Automatically unfold the definition of "certificate"*)
   1.319 +declare certificate_def [simp]
   1.320 +
   1.321 +(*Injectiveness of key-generating functions*)
   1.322 +declare inj_PRF [THEN inj_eq, iff]
   1.323 +declare inj_sessionK [THEN inj_eq, iff]
   1.324 +declare isSym_sessionK [simp]
   1.325 +
   1.326 +
   1.327 +(*** clientK and serverK make symmetric keys; no clashes with pubK or priK ***)
   1.328 +
   1.329 +lemma pubK_neq_sessionK [iff]: "pubK A \<noteq> sessionK arg"
   1.330 +by (simp add: symKeys_neq_imp_neq)
   1.331 +
   1.332 +declare pubK_neq_sessionK [THEN not_sym, iff]
   1.333 +
   1.334 +lemma priK_neq_sessionK [iff]: "priK A \<noteq> sessionK arg"
   1.335 +by (simp add: symKeys_neq_imp_neq)
   1.336 +
   1.337 +declare priK_neq_sessionK [THEN not_sym, iff]
   1.338 +
   1.339 +lemmas keys_distinct = pubK_neq_sessionK priK_neq_sessionK
   1.340 +
   1.341 +
   1.342 +(**** Protocol Proofs ****)
   1.343 +
   1.344 +(*Possibility properties state that some traces run the protocol to the end.
   1.345 +  Four paths and 12 rules are considered.*)
   1.346 +
   1.347 +
   1.348 +(** These proofs assume that the Nonce_supply nonces
   1.349 +	(which have the form  @ N. Nonce N \<notin> used evs)
   1.350 +    lie outside the range of PRF.  It seems reasonable, but as it is needed
   1.351 +    only for the possibility theorems, it is not taken as an axiom.
   1.352 +**)
   1.353 +
   1.354 +
   1.355 +(*Possibility property ending with ClientAccepts.*)
   1.356 +lemma "[| \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF;  A \<noteq> B |]
   1.357 +      ==> \<exists>SID M. \<exists>evs \<in> tls.
   1.358 +            Notes A {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs"
   1.359 +apply (intro exI bexI)
   1.360 +apply (rule_tac [2] tls.Nil
   1.361 +                    [THEN tls.ClientHello, THEN tls.ServerHello,
   1.362 +                     THEN tls.Certificate, THEN tls.ClientKeyExch,
   1.363 +                     THEN tls.ClientFinished, THEN tls.ServerFinished,
   1.364 +                     THEN tls.ClientAccepts])
   1.365 +apply possibility
   1.366 +apply blast+
   1.367 +done
   1.368 +
   1.369 +
   1.370 +(*And one for ServerAccepts.  Either FINISHED message may come first.*)
   1.371 +lemma "[| \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF; A \<noteq> B |]
   1.372 +      ==> \<exists>SID NA PA NB PB M. \<exists>evs \<in> tls.
   1.373 +           Notes B {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs"
   1.374 +apply (intro exI bexI)
   1.375 +apply (rule_tac [2] tls.Nil
   1.376 +                    [THEN tls.ClientHello, THEN tls.ServerHello,
   1.377 +                     THEN tls.Certificate, THEN tls.ClientKeyExch,
   1.378 +                     THEN tls.ServerFinished, THEN tls.ClientFinished, 
   1.379 +                     THEN tls.ServerAccepts])
   1.380 +apply possibility
   1.381 +apply blast+
   1.382 +done
   1.383 +
   1.384 +
   1.385 +(*Another one, for CertVerify (which is optional)*)
   1.386 +lemma "[| \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF;  A \<noteq> B |]
   1.387 +       ==> \<exists>NB PMS. \<exists>evs \<in> tls.
   1.388 +              Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|})) 
   1.389 +                \<in> set evs"
   1.390 +apply (intro exI bexI)
   1.391 +apply (rule_tac [2] tls.Nil
   1.392 +                    [THEN tls.ClientHello, THEN tls.ServerHello,
   1.393 +                     THEN tls.Certificate, THEN tls.ClientKeyExch,
   1.394 +                     THEN tls.CertVerify])
   1.395 +apply possibility
   1.396 +apply blast+
   1.397 +done
   1.398 +
   1.399 +
   1.400 +(*Another one, for session resumption (both ServerResume and ClientResume).
   1.401 +  NO tls.Nil here: we refer to a previous session, not the empty trace.*)
   1.402 +lemma "[| evs0 \<in> tls;
   1.403 +          Notes A {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs0;
   1.404 +          Notes B {|Number SID, Agent A, Agent B, Nonce M|} \<in> set evs0;
   1.405 +          \<forall>evs. (@ N. Nonce N \<notin> used evs) \<notin> range PRF;
   1.406 +          A \<noteq> B |]
   1.407 +      ==> \<exists>NA PA NB PB X. \<exists>evs \<in> tls.
   1.408 +		X = Hash{|Number SID, Nonce M,
   1.409 +			  Nonce NA, Number PA, Agent A,
   1.410 +			  Nonce NB, Number PB, Agent B|}  &
   1.411 +		Says A B (Crypt (clientK(NA,NB,M)) X) \<in> set evs  &
   1.412 +		Says B A (Crypt (serverK(NA,NB,M)) X) \<in> set evs"
   1.413 +apply (intro exI bexI)
   1.414 +apply (rule_tac [2] tls.ClientHello
   1.415 +                    [THEN tls.ServerHello,
   1.416 +                     THEN tls.ServerResume, THEN tls.ClientResume])
   1.417 +apply possibility
   1.418 +apply blast+
   1.419 +done
   1.420 +
   1.421 +
   1.422 +(**** Inductive proofs about tls ****)
   1.423 +
   1.424 +
   1.425 +(*Induction for regularity theorems.  If induction formula has the form
   1.426 +   X \<notin> analz (spies evs) --> ... then it shortens the proof by discarding
   1.427 +   needless information about analz (insert X (spies evs))  
   1.428 +fun parts_induct_tac i =
   1.429 +    etac tls.induct i
   1.430 +    THEN REPEAT (FIRSTGOAL analz_mono_contra_tac)
   1.431 +    THEN Force_tac i THEN
   1.432 +    ALLGOALS Asm_simp_tac
   1.433 +*)
   1.434 +
   1.435 +(** Theorems of the form X \<notin> parts (spies evs) imply that NOBODY
   1.436 +    sends messages containing X! **)
   1.437 +
   1.438 +(*Spy never sees a good agent's private key!*)
   1.439 +lemma Spy_see_priK [simp]:
   1.440 +     "evs \<in> tls ==> (Key (priK A) \<in> parts (spies evs)) = (A \<in> bad)"
   1.441 +apply (erule tls.induct, force, simp_all)
   1.442 +apply blast
   1.443 +done
   1.444 +
   1.445 +lemma Spy_analz_priK [simp]:
   1.446 +     "evs \<in> tls ==> (Key (priK A) \<in> analz (spies evs)) = (A \<in> bad)"
   1.447 +by auto
   1.448 +
   1.449 +lemma Spy_see_priK_D [dest!]:
   1.450 +     "[|Key (priK A) \<in> parts (knows Spy evs);  evs \<in> tls|] ==> A \<in> bad"
   1.451 +by (blast dest: Spy_see_priK)
   1.452 +
   1.453 +
   1.454 +(*This lemma says that no false certificates exist.  One might extend the
   1.455 +  model to include bogus certificates for the agents, but there seems
   1.456 +  little point in doing so: the loss of their private keys is a worse
   1.457 +  breach of security.*)
   1.458 +lemma certificate_valid:
   1.459 +    "[| certificate B KB \<in> parts (spies evs);  evs \<in> tls |] ==> KB = pubK B"
   1.460 +apply (erule rev_mp)
   1.461 +apply (erule tls.induct, force, simp_all)
   1.462 +apply blast 
   1.463 +done
   1.464 +
   1.465 +lemmas CX_KB_is_pubKB = Says_imp_spies [THEN parts.Inj, THEN certificate_valid]
   1.466 +
   1.467 +
   1.468 +(*** Properties of items found in Notes ***)
   1.469 +
   1.470 +lemma Notes_Crypt_parts_spies:
   1.471 +     "[| Notes A {|Agent B, X|} \<in> set evs;  evs \<in> tls |]
   1.472 +      ==> Crypt (pubK B) X \<in> parts (spies evs)"
   1.473 +apply (erule rev_mp)
   1.474 +apply (erule tls.induct, 
   1.475 +       frule_tac [7] CX_KB_is_pubKB, force, simp_all)
   1.476 +apply (blast intro: parts_insertI)
   1.477 +done
   1.478 +
   1.479 +(*C may be either A or B*)
   1.480 +lemma Notes_master_imp_Crypt_PMS:
   1.481 +     "[| Notes C {|s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))|} \<in> set evs;
   1.482 +         evs \<in> tls |]
   1.483 +      ==> Crypt (pubK B) (Nonce PMS) \<in> parts (spies evs)"
   1.484 +apply (erule rev_mp)
   1.485 +apply (erule tls.induct, force, simp_all)
   1.486 +(*Fake*)
   1.487 +apply (blast intro: parts_insertI)
   1.488 +(*Client, Server Accept*)
   1.489 +apply (blast dest!: Notes_Crypt_parts_spies)+
   1.490 +done
   1.491 +
   1.492 +(*Compared with the theorem above, both premise and conclusion are stronger*)
   1.493 +lemma Notes_master_imp_Notes_PMS:
   1.494 +     "[| Notes A {|s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))|} \<in> set evs;
   1.495 +         evs \<in> tls |]
   1.496 +      ==> Notes A {|Agent B, Nonce PMS|} \<in> set evs"
   1.497 +apply (erule rev_mp)
   1.498 +apply (erule tls.induct, force, simp_all)
   1.499 +(*ServerAccepts*)
   1.500 +apply blast
   1.501 +done
   1.502 +
   1.503 +
   1.504 +(*** Protocol goal: if B receives CertVerify, then A sent it ***)
   1.505 +
   1.506 +(*B can check A's signature if he has received A's certificate.*)
   1.507 +lemma TrustCertVerify_lemma:
   1.508 +     "[| X \<in> parts (spies evs);
   1.509 +         X = Crypt (priK A) (Hash{|nb, Agent B, pms|});
   1.510 +         evs \<in> tls;  A \<notin> bad |]
   1.511 +      ==> Says A B X \<in> set evs"
   1.512 +apply (erule rev_mp, erule ssubst)
   1.513 +apply (erule tls.induct, force, simp_all)
   1.514 +apply blast
   1.515 +done
   1.516 +
   1.517 +(*Final version: B checks X using the distributed KA instead of priK A*)
   1.518 +lemma TrustCertVerify:
   1.519 +     "[| X \<in> parts (spies evs);
   1.520 +         X = Crypt (invKey KA) (Hash{|nb, Agent B, pms|});
   1.521 +         certificate A KA \<in> parts (spies evs);
   1.522 +         evs \<in> tls;  A \<notin> bad |]
   1.523 +      ==> Says A B X \<in> set evs"
   1.524 +by (blast dest!: certificate_valid intro!: TrustCertVerify_lemma)
   1.525 +
   1.526 +
   1.527 +(*If CertVerify is present then A has chosen PMS.*)
   1.528 +lemma UseCertVerify_lemma:
   1.529 +     "[| Crypt (priK A) (Hash{|nb, Agent B, Nonce PMS|}) \<in> parts (spies evs);
   1.530 +         evs \<in> tls;  A \<notin> bad |]
   1.531 +      ==> Notes A {|Agent B, Nonce PMS|} \<in> set evs"
   1.532 +apply (erule rev_mp)
   1.533 +apply (erule tls.induct, force, simp_all)
   1.534 +apply blast
   1.535 +done
   1.536 +
   1.537 +(*Final version using the distributed KA instead of priK A*)
   1.538 +lemma UseCertVerify:
   1.539 +     "[| Crypt (invKey KA) (Hash{|nb, Agent B, Nonce PMS|})
   1.540 +           \<in> parts (spies evs);
   1.541 +         certificate A KA \<in> parts (spies evs);
   1.542 +         evs \<in> tls;  A \<notin> bad |]
   1.543 +      ==> Notes A {|Agent B, Nonce PMS|} \<in> set evs"
   1.544 +by (blast dest!: certificate_valid intro!: UseCertVerify_lemma)
   1.545 +
   1.546 +
   1.547 +lemma no_Notes_A_PRF [simp]:
   1.548 +     "evs \<in> tls ==> Notes A {|Agent B, Nonce (PRF x)|} \<notin> set evs"
   1.549 +apply (erule tls.induct, force, simp_all)
   1.550 +(*ClientKeyExch: PMS is assumed to differ from any PRF.*)
   1.551 +apply blast
   1.552 +done
   1.553 +
   1.554 +
   1.555 +lemma MS_imp_PMS [dest!]:
   1.556 +     "[| Nonce (PRF (PMS,NA,NB)) \<in> parts (spies evs);  evs \<in> tls |]
   1.557 +      ==> Nonce PMS \<in> parts (spies evs)"
   1.558 +apply (erule rev_mp)
   1.559 +apply (erule tls.induct, force, simp_all)
   1.560 +(*Fake*)
   1.561 +apply (blast intro: parts_insertI)
   1.562 +(*Easy, e.g. by freshness*)
   1.563 +apply (blast dest: Notes_Crypt_parts_spies)+
   1.564 +done
   1.565 +
   1.566 +
   1.567 +
   1.568 +
   1.569 +(*** Unicity results for PMS, the pre-master-secret ***)
   1.570 +
   1.571 +(*PMS determines B.*)
   1.572 +lemma Crypt_unique_PMS:
   1.573 +     "[| Crypt(pubK B)  (Nonce PMS) \<in> parts (spies evs);
   1.574 +         Crypt(pubK B') (Nonce PMS) \<in> parts (spies evs);
   1.575 +         Nonce PMS \<notin> analz (spies evs);
   1.576 +         evs \<in> tls |]
   1.577 +      ==> B=B'"
   1.578 +apply (erule rev_mp, erule rev_mp, erule rev_mp)
   1.579 +apply (erule tls.induct, analz_mono_contra, force, simp_all (no_asm_simp))
   1.580 +(*Fake, ClientKeyExch*)
   1.581 +apply blast+
   1.582 +done
   1.583 +
   1.584 +
   1.585 +(** It is frustrating that we need two versions of the unicity results.
   1.586 +    But Notes A {|Agent B, Nonce PMS|} determines both A and B.  Sometimes
   1.587 +    we have only the weaker assertion Crypt(pubK B) (Nonce PMS), which
   1.588 +    determines B alone, and only if PMS is secret.
   1.589 +**)
   1.590 +
   1.591 +(*In A's internal Note, PMS determines A and B.*)
   1.592 +lemma Notes_unique_PMS:
   1.593 +     "[| Notes A  {|Agent B,  Nonce PMS|} \<in> set evs;
   1.594 +         Notes A' {|Agent B', Nonce PMS|} \<in> set evs;
   1.595 +         evs \<in> tls |]
   1.596 +      ==> A=A' & B=B'"
   1.597 +apply (erule rev_mp, erule rev_mp)
   1.598 +apply (erule tls.induct, force, simp_all)
   1.599 +(*ClientKeyExch*)
   1.600 +apply (blast dest!: Notes_Crypt_parts_spies)
   1.601 +done
   1.602 +
   1.603 +
   1.604 +(**** Secrecy Theorems ****)
   1.605 +
   1.606 +(*Key compromise lemma needed to prove analz_image_keys.
   1.607 +  No collection of keys can help the spy get new private keys.*)
   1.608 +lemma analz_image_priK [rule_format]:
   1.609 +     "evs \<in> tls
   1.610 +      ==> \<forall>KK. (Key(priK B) \<in> analz (Key`KK Un (spies evs))) =
   1.611 +          (priK B \<in> KK | B \<in> bad)"
   1.612 +apply (erule tls.induct)
   1.613 +apply (simp_all (no_asm_simp)
   1.614 +		del: image_insert
   1.615 +                add: image_Un [THEN sym]
   1.616 +                     insert_Key_image Un_assoc [THEN sym])
   1.617 +(*Fake*)
   1.618 +apply spy_analz
   1.619 +done
   1.620 +
   1.621 +
   1.622 +(*slightly speeds up the big simplification below*)
   1.623 +lemma range_sessionkeys_not_priK:
   1.624 +     "KK <= range sessionK ==> priK B \<notin> KK"
   1.625 +by blast
   1.626 +
   1.627 +
   1.628 +(*Lemma for the trivial direction of the if-and-only-if*)
   1.629 +lemma analz_image_keys_lemma:
   1.630 +     "(X \<in> analz (G Un H)) --> (X \<in> analz H)  ==>
   1.631 +      (X \<in> analz (G Un H))  =  (X \<in> analz H)"
   1.632 +by (blast intro: analz_mono [THEN subsetD])
   1.633 +
   1.634 +(** Strangely, the following version doesn't work:
   1.635 +\<forall>Z. (Nonce N \<in> analz (Key`(sessionK`Z) Un (spies evs))) =
   1.636 +    (Nonce N \<in> analz (spies evs))"
   1.637 +**)
   1.638 +
   1.639 +lemma analz_image_keys [rule_format]:
   1.640 +     "evs \<in> tls ==>
   1.641 +      \<forall>KK. KK <= range sessionK -->
   1.642 +	      (Nonce N \<in> analz (Key`KK Un (spies evs))) =
   1.643 +	      (Nonce N \<in> analz (spies evs))"
   1.644 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.645 +apply (safe del: iffI)
   1.646 +apply (safe del: impI iffI intro!: analz_image_keys_lemma)
   1.647 +apply (simp_all (no_asm_simp)               (*faster*)
   1.648 +                del: image_insert imp_disjL (*reduces blow-up*)
   1.649 +		add: image_Un [THEN sym]  Un_assoc [THEN sym]
   1.650 +		     insert_Key_singleton
   1.651 +		     range_sessionkeys_not_priK analz_image_priK)
   1.652 +apply (simp_all add: insert_absorb)
   1.653 +(*Fake*)
   1.654 +apply spy_analz
   1.655 +done
   1.656 +
   1.657 +(*Knowing some session keys is no help in getting new nonces*)
   1.658 +lemma analz_insert_key [simp]:
   1.659 +     "evs \<in> tls ==>
   1.660 +      Nonce N \<in> analz (insert (Key (sessionK z)) (spies evs)) =
   1.661 +      (Nonce N \<in> analz (spies evs))"
   1.662 +by (simp del: image_insert
   1.663 +         add: insert_Key_singleton analz_image_keys)
   1.664 +
   1.665 +
   1.666 +(*** Protocol goal: serverK(Na,Nb,M) and clientK(Na,Nb,M) remain secure ***)
   1.667 +
   1.668 +(** Some lemmas about session keys, comprising clientK and serverK **)
   1.669 +
   1.670 +
   1.671 +(*Lemma: session keys are never used if PMS is fresh.
   1.672 +  Nonces don't have to agree, allowing session resumption.
   1.673 +  Converse doesn't hold; revealing PMS doesn't force the keys to be sent.
   1.674 +  THEY ARE NOT SUITABLE AS SAFE ELIM RULES.*)
   1.675 +lemma PMS_lemma:
   1.676 +     "[| Nonce PMS \<notin> parts (spies evs);
   1.677 +         K = sessionK((Na, Nb, PRF(PMS,NA,NB)), role);
   1.678 +         evs \<in> tls |]
   1.679 +   ==> Key K \<notin> parts (spies evs) & (\<forall>Y. Crypt K Y \<notin> parts (spies evs))"
   1.680 +apply (erule rev_mp, erule ssubst)
   1.681 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.682 +apply (force, simp_all (no_asm_simp))
   1.683 +(*Fake*)
   1.684 +apply (blast intro: parts_insertI)
   1.685 +(*SpyKeys*)
   1.686 +apply blast
   1.687 +(*Many others*)
   1.688 +apply (force dest!: Notes_Crypt_parts_spies Notes_master_imp_Crypt_PMS)+
   1.689 +done
   1.690 +
   1.691 +lemma PMS_sessionK_not_spied:
   1.692 +     "[| Key (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) \<in> parts (spies evs);
   1.693 +         evs \<in> tls |]
   1.694 +      ==> Nonce PMS \<in> parts (spies evs)"
   1.695 +by (blast dest: PMS_lemma)
   1.696 +
   1.697 +lemma PMS_Crypt_sessionK_not_spied:
   1.698 +     "[| Crypt (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) Y
   1.699 +           \<in> parts (spies evs);  evs \<in> tls |]
   1.700 +      ==> Nonce PMS \<in> parts (spies evs)"
   1.701 +by (blast dest: PMS_lemma)
   1.702 +
   1.703 +(*Write keys are never sent if M (MASTER SECRET) is secure.
   1.704 +  Converse fails; betraying M doesn't force the keys to be sent!
   1.705 +  The strong Oops condition can be weakened later by unicity reasoning,
   1.706 +  with some effort.
   1.707 +  NO LONGER USED: see clientK_not_spied and serverK_not_spied*)
   1.708 +lemma sessionK_not_spied:
   1.709 +     "[| \<forall>A. Says A Spy (Key (sessionK((NA,NB,M),role))) \<notin> set evs;
   1.710 +         Nonce M \<notin> analz (spies evs);  evs \<in> tls |]
   1.711 +      ==> Key (sessionK((NA,NB,M),role)) \<notin> parts (spies evs)"
   1.712 +apply (erule rev_mp, erule rev_mp)
   1.713 +apply (erule tls.induct, analz_mono_contra)
   1.714 +apply (force, simp_all (no_asm_simp))
   1.715 +(*Fake, SpyKeys*)
   1.716 +apply blast+
   1.717 +done
   1.718 +
   1.719 +
   1.720 +(*If A sends ClientKeyExch to an honest B, then the PMS will stay secret.*)
   1.721 +lemma Spy_not_see_PMS:
   1.722 +     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
   1.723 +         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
   1.724 +      ==> Nonce PMS \<notin> analz (spies evs)"
   1.725 +apply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.726 +apply (force, simp_all (no_asm_simp))
   1.727 +(*Fake*)
   1.728 +apply spy_analz
   1.729 +(*SpyKeys*)
   1.730 +apply force
   1.731 +apply (simp_all add: insert_absorb) 
   1.732 +(*ClientHello, ServerHello, ClientKeyExch: mostly freshness reasoning*)
   1.733 +apply (blast dest: Notes_Crypt_parts_spies)
   1.734 +apply (blast dest: Notes_Crypt_parts_spies)
   1.735 +apply (blast dest: Notes_Crypt_parts_spies)
   1.736 +(*ClientAccepts and ServerAccepts: because PMS \<notin> range PRF*)
   1.737 +apply force+
   1.738 +done
   1.739 +
   1.740 +
   1.741 +(*If A sends ClientKeyExch to an honest B, then the MASTER SECRET
   1.742 +  will stay secret.*)
   1.743 +lemma Spy_not_see_MS:
   1.744 +     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
   1.745 +         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
   1.746 +      ==> Nonce (PRF(PMS,NA,NB)) \<notin> analz (spies evs)"
   1.747 +apply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.748 +apply (force, simp_all (no_asm_simp))
   1.749 +(*Fake*)
   1.750 +apply spy_analz
   1.751 +(*SpyKeys: by secrecy of the PMS, Spy cannot make the MS*)
   1.752 +apply (blast dest!: Spy_not_see_PMS)
   1.753 +apply (simp_all add: insert_absorb)
   1.754 +(*ClientAccepts and ServerAccepts: because PMS was already visible;
   1.755 +  others, freshness etc.*)
   1.756 +apply (blast dest: Notes_Crypt_parts_spies Spy_not_see_PMS 
   1.757 +                   Notes_imp_knows_Spy [THEN analz.Inj])+
   1.758 +done
   1.759 +
   1.760 +
   1.761 +
   1.762 +(*** Weakening the Oops conditions for leakage of clientK ***)
   1.763 +
   1.764 +(*If A created PMS then nobody else (except the Spy in replays)
   1.765 +  would send a message using a clientK generated from that PMS.*)
   1.766 +lemma Says_clientK_unique:
   1.767 +     "[| Says A' B' (Crypt (clientK(Na,Nb,PRF(PMS,NA,NB))) Y) \<in> set evs;
   1.768 +         Notes A {|Agent B, Nonce PMS|} \<in> set evs;
   1.769 +         evs \<in> tls;  A' \<noteq> Spy |]
   1.770 +      ==> A = A'"
   1.771 +apply (erule rev_mp, erule rev_mp)
   1.772 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.773 +apply (force, simp_all)
   1.774 +(*ClientKeyExch*)
   1.775 +apply (blast dest!: PMS_Crypt_sessionK_not_spied)
   1.776 +(*ClientFinished, ClientResume: by unicity of PMS*)
   1.777 +apply (blast dest!: Notes_master_imp_Notes_PMS 
   1.778 +             intro: Notes_unique_PMS [THEN conjunct1])+
   1.779 +done
   1.780 +
   1.781 +
   1.782 +(*If A created PMS and has not leaked her clientK to the Spy,
   1.783 +  then it is completely secure: not even in parts!*)
   1.784 +lemma clientK_not_spied:
   1.785 +     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
   1.786 +         Says A Spy (Key (clientK(Na,Nb,PRF(PMS,NA,NB)))) \<notin> set evs;
   1.787 +         A \<notin> bad;  B \<notin> bad;
   1.788 +         evs \<in> tls |]
   1.789 +      ==> Key (clientK(Na,Nb,PRF(PMS,NA,NB))) \<notin> parts (spies evs)"
   1.790 +apply (erule rev_mp, erule rev_mp)
   1.791 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.792 +apply (force, simp_all (no_asm_simp))
   1.793 +(*ClientKeyExch*)
   1.794 +apply blast 
   1.795 +(*SpyKeys*)
   1.796 +apply (blast dest!: Spy_not_see_MS)
   1.797 +(*ClientKeyExch*)
   1.798 +apply (blast dest!: PMS_sessionK_not_spied)
   1.799 +(*Oops*)
   1.800 +apply (blast intro: Says_clientK_unique)
   1.801 +done
   1.802 +
   1.803 +
   1.804 +(*** Weakening the Oops conditions for leakage of serverK ***)
   1.805 +
   1.806 +(*If A created PMS for B, then nobody other than B or the Spy would
   1.807 +  send a message using a serverK generated from that PMS.*)
   1.808 +lemma Says_serverK_unique:
   1.809 +     "[| Says B' A' (Crypt (serverK(Na,Nb,PRF(PMS,NA,NB))) Y) \<in> set evs;
   1.810 +         Notes A {|Agent B, Nonce PMS|} \<in> set evs;
   1.811 +         evs \<in> tls;  A \<notin> bad;  B \<notin> bad;  B' \<noteq> Spy |]
   1.812 +      ==> B = B'"
   1.813 +apply (erule rev_mp, erule rev_mp)
   1.814 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.815 +apply (force, simp_all)
   1.816 +(*ClientKeyExch*)
   1.817 +apply (blast dest!: PMS_Crypt_sessionK_not_spied)
   1.818 +(*ServerResume, ServerFinished: by unicity of PMS*)
   1.819 +apply (blast dest!: Notes_master_imp_Crypt_PMS 
   1.820 +             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+
   1.821 +done
   1.822 +
   1.823 +
   1.824 +(*If A created PMS for B, and B has not leaked his serverK to the Spy,
   1.825 +  then it is completely secure: not even in parts!*)
   1.826 +lemma serverK_not_spied:
   1.827 +     "[| Notes A {|Agent B, Nonce PMS|} \<in> set evs;
   1.828 +         Says B Spy (Key(serverK(Na,Nb,PRF(PMS,NA,NB)))) \<notin> set evs;
   1.829 +         A \<notin> bad;  B \<notin> bad;  evs \<in> tls |]
   1.830 +      ==> Key (serverK(Na,Nb,PRF(PMS,NA,NB))) \<notin> parts (spies evs)"
   1.831 +apply (erule rev_mp, erule rev_mp)
   1.832 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.833 +apply (force, simp_all (no_asm_simp))
   1.834 +(*Fake*)
   1.835 +apply blast 
   1.836 +(*SpyKeys*)
   1.837 +apply (blast dest!: Spy_not_see_MS)
   1.838 +(*ClientKeyExch*)
   1.839 +apply (blast dest!: PMS_sessionK_not_spied)
   1.840 +(*Oops*)
   1.841 +apply (blast intro: Says_serverK_unique)
   1.842 +done
   1.843 +
   1.844 +
   1.845 +(*** Protocol goals: if A receives ServerFinished, then B is present
   1.846 +     and has used the quoted values PA, PB, etc.  Note that it is up to A
   1.847 +     to compare PA with what she originally sent.
   1.848 +***)
   1.849 +
   1.850 +(*The mention of her name (A) in X assures A that B knows who she is.*)
   1.851 +lemma TrustServerFinished [rule_format]:
   1.852 +     "[| X = Crypt (serverK(Na,Nb,M))
   1.853 +               (Hash{|Number SID, Nonce M,
   1.854 +                      Nonce Na, Number PA, Agent A,
   1.855 +                      Nonce Nb, Number PB, Agent B|});
   1.856 +         M = PRF(PMS,NA,NB);
   1.857 +         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
   1.858 +      ==> Says B Spy (Key(serverK(Na,Nb,M))) \<notin> set evs -->
   1.859 +          Notes A {|Agent B, Nonce PMS|} \<in> set evs -->
   1.860 +          X \<in> parts (spies evs) --> Says B A X \<in> set evs"
   1.861 +apply (erule ssubst)+
   1.862 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.863 +apply (force, simp_all (no_asm_simp))
   1.864 +(*Fake: the Spy doesn't have the critical session key!*)
   1.865 +apply (blast dest: serverK_not_spied)
   1.866 +(*ClientKeyExch*)
   1.867 +apply (blast dest!: PMS_Crypt_sessionK_not_spied)
   1.868 +done
   1.869 +
   1.870 +(*This version refers not to ServerFinished but to any message from B.
   1.871 +  We don't assume B has received CertVerify, and an intruder could
   1.872 +  have changed A's identity in all other messages, so we can't be sure
   1.873 +  that B sends his message to A.  If CLIENT KEY EXCHANGE were augmented
   1.874 +  to bind A's identity with PMS, then we could replace A' by A below.*)
   1.875 +lemma TrustServerMsg [rule_format]:
   1.876 +     "[| M = PRF(PMS,NA,NB);  evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
   1.877 +      ==> Says B Spy (Key(serverK(Na,Nb,M))) \<notin> set evs -->
   1.878 +          Notes A {|Agent B, Nonce PMS|} \<in> set evs -->
   1.879 +          Crypt (serverK(Na,Nb,M)) Y \<in> parts (spies evs)  -->
   1.880 +          (\<exists>A'. Says B A' (Crypt (serverK(Na,Nb,M)) Y) \<in> set evs)"
   1.881 +apply (erule ssubst)
   1.882 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.883 +apply (force, simp_all (no_asm_simp) add: ex_disj_distrib)
   1.884 +(*Fake: the Spy doesn't have the critical session key!*)
   1.885 +apply (blast dest: serverK_not_spied)
   1.886 +(*ClientKeyExch*)
   1.887 +apply (clarify, blast dest!: PMS_Crypt_sessionK_not_spied)
   1.888 +(*ServerResume, ServerFinished: by unicity of PMS*)
   1.889 +apply (blast dest!: Notes_master_imp_Crypt_PMS 
   1.890 +             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+
   1.891 +done
   1.892 +
   1.893 +
   1.894 +(*** Protocol goal: if B receives any message encrypted with clientK
   1.895 +     then A has sent it, ASSUMING that A chose PMS.  Authentication is
   1.896 +     assumed here; B cannot verify it.  But if the message is
   1.897 +     ClientFinished, then B can then check the quoted values PA, PB, etc.
   1.898 +***)
   1.899 +
   1.900 +lemma TrustClientMsg [rule_format]:
   1.901 +     "[| M = PRF(PMS,NA,NB);  evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
   1.902 +      ==> Says A Spy (Key(clientK(Na,Nb,M))) \<notin> set evs -->
   1.903 +          Notes A {|Agent B, Nonce PMS|} \<in> set evs -->
   1.904 +          Crypt (clientK(Na,Nb,M)) Y \<in> parts (spies evs) -->
   1.905 +          Says A B (Crypt (clientK(Na,Nb,M)) Y) \<in> set evs"
   1.906 +apply (erule ssubst)
   1.907 +apply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)
   1.908 +apply (force, simp_all (no_asm_simp))
   1.909 +(*Fake: the Spy doesn't have the critical session key!*)
   1.910 +apply (blast dest: clientK_not_spied)
   1.911 +(*ClientKeyExch*)
   1.912 +apply (blast dest!: PMS_Crypt_sessionK_not_spied)
   1.913 +(*ClientFinished, ClientResume: by unicity of PMS*)
   1.914 +apply (blast dest!: Notes_master_imp_Notes_PMS dest: Notes_unique_PMS)+
   1.915 +done
   1.916 +
   1.917 +
   1.918 +(*** Protocol goal: if B receives ClientFinished, and if B is able to
   1.919 +     check a CertVerify from A, then A has used the quoted
   1.920 +     values PA, PB, etc.  Even this one requires A to be uncompromised.
   1.921 + ***)
   1.922 +lemma AuthClientFinished:
   1.923 +     "[| M = PRF(PMS,NA,NB);
   1.924 +         Says A Spy (Key(clientK(Na,Nb,M))) \<notin> set evs;
   1.925 +         Says A' B (Crypt (clientK(Na,Nb,M)) Y) \<in> set evs;
   1.926 +         certificate A KA \<in> parts (spies evs);
   1.927 +         Says A'' B (Crypt (invKey KA) (Hash{|nb, Agent B, Nonce PMS|}))
   1.928 +           \<in> set evs;
   1.929 +         evs \<in> tls;  A \<notin> bad;  B \<notin> bad |]
   1.930 +      ==> Says A B (Crypt (clientK(Na,Nb,M)) Y) \<in> set evs"
   1.931 +by (blast intro!: TrustClientMsg UseCertVerify)
   1.932 +
   1.933 +(*22/9/97: loads in 622s, which is 10 minutes 22 seconds*)
   1.934 +(*24/9/97: loads in 672s, which is 11 minutes 12 seconds [stronger theorems]*)
   1.935 +(*29/9/97: loads in 481s, after removing Certificate from ClientKeyExch*)
   1.936 +(*30/9/97: loads in 476s, after removing unused theorems*)
   1.937 +(*30/9/97: loads in 448s, after fixing ServerResume*)
   1.938 +
   1.939 +(*08/9/97: loads in 189s (pike), after much reorganization,
   1.940 +           back to 621s on albatross?*)
   1.941 +
   1.942 +(*10/2/99: loads in 139s (pike)
   1.943 +           down to 433s on albatross*)
   1.944 +
   1.945 +(*5/5/01: conversion to Isar script
   1.946 +	  loads in 137s (perch)
   1.947 +          the last ML version loaded in 122s on perch, a 600MHz machine:
   1.948 +		twice as fast as pike.  No idea why it's so much slower!
   1.949 +	  The Isar script is slower still, perhaps because simp_all simplifies
   1.950 +	  the assumptions be default.
   1.951 +*)
   1.952  
   1.953  end