src/HOL/Auth/CertifiedEmail.thy
author wenzelm
Mon Aug 31 21:28:08 2015 +0200 (2015-08-31)
changeset 61070 b72a990adfe2
parent 58889 5b7a9633cfa8
child 61830 4f5ab843cf5b
permissions -rw-r--r--
prefer symbols;
wenzelm@37936
     1
(*  Title:      HOL/Auth/CertifiedEmail.thy
paulson@13922
     2
    Author:     Giampaolo Bella, Christiano Longo and Lawrence C Paulson
paulson@13956
     3
*)
paulson@13922
     4
wenzelm@58889
     5
section{*The Certified Electronic Mail Protocol by Abadi et al.*}
paulson@13922
     6
haftmann@16417
     7
theory CertifiedEmail imports Public begin
paulson@13922
     8
wenzelm@20768
     9
abbreviation
wenzelm@21404
    10
  TTP :: agent where
wenzelm@20768
    11
  "TTP == Server"
paulson@13922
    12
wenzelm@21404
    13
abbreviation
wenzelm@21404
    14
  RPwd :: "agent => key" where
wenzelm@20768
    15
  "RPwd == shrK"
paulson@13922
    16
paulson@13922
    17
 
paulson@13922
    18
(*FIXME: the four options should be represented by pairs of 0 or 1.
paulson@13922
    19
  Right now only BothAuth is modelled.*)
paulson@13922
    20
consts
paulson@13922
    21
  NoAuth   :: nat
paulson@13922
    22
  TTPAuth  :: nat
paulson@13922
    23
  SAuth    :: nat
paulson@13922
    24
  BothAuth :: nat
paulson@13922
    25
paulson@13922
    26
text{*We formalize a fixed way of computing responses.  Could be better.*}
haftmann@35416
    27
definition "response" :: "agent => agent => nat => msg" where
paulson@13922
    28
   "response S R q == Hash {|Agent S, Key (shrK R), Nonce q|}"
paulson@13922
    29
paulson@13922
    30
berghofe@23746
    31
inductive_set certified_mail :: "event list set"
berghofe@23746
    32
  where
paulson@13922
    33
berghofe@23746
    34
  Nil: --{*The empty trace*}
paulson@13922
    35
     "[] \<in> certified_mail"
paulson@13922
    36
berghofe@23746
    37
| Fake: --{*The Spy may say anything he can say.  The sender field is correct,
paulson@13922
    38
          but agents don't use that information.*}
paulson@14145
    39
      "[| evsf \<in> certified_mail; X \<in> synth(analz(spies evsf))|] 
paulson@13956
    40
       ==> Says Spy B X # evsf \<in> certified_mail"
paulson@13922
    41
berghofe@23746
    42
| FakeSSL: --{*The Spy may open SSL sessions with TTP, who is the only agent
paulson@13922
    43
    equipped with the necessary credentials to serve as an SSL server.*}
wenzelm@32960
    44
         "[| evsfssl \<in> certified_mail; X \<in> synth(analz(spies evsfssl))|]
paulson@13922
    45
          ==> Notes TTP {|Agent Spy, Agent TTP, X|} # evsfssl \<in> certified_mail"
paulson@13922
    46
berghofe@23746
    47
| CM1: --{*The sender approaches the recipient.  The message is a number.*}
paulson@15068
    48
 "[|evs1 \<in> certified_mail;
paulson@15068
    49
    Key K \<notin> used evs1;
paulson@15068
    50
    K \<in> symKeys;
paulson@15068
    51
    Nonce q \<notin> used evs1;
paulson@15068
    52
    hs = Hash{|Number cleartext, Nonce q, response S R q, Crypt K (Number m)|};
paulson@15068
    53
    S2TTP = Crypt(pubEK TTP) {|Agent S, Number BothAuth, Key K, Agent R, hs|}|]
paulson@15068
    54
  ==> Says S R {|Agent S, Agent TTP, Crypt K (Number m), Number BothAuth, 
wenzelm@32960
    55
                 Number cleartext, Nonce q, S2TTP|} # evs1 
wenzelm@32960
    56
        \<in> certified_mail"
paulson@13922
    57
berghofe@23746
    58
| CM2: --{*The recipient records @{term S2TTP} while transmitting it and her
paulson@13922
    59
     password to @{term TTP} over an SSL channel.*}
paulson@15068
    60
 "[|evs2 \<in> certified_mail;
paulson@15068
    61
    Gets R {|Agent S, Agent TTP, em, Number BothAuth, Number cleartext, 
wenzelm@32960
    62
             Nonce q, S2TTP|} \<in> set evs2;
paulson@15068
    63
    TTP \<noteq> R;  
paulson@15068
    64
    hr = Hash {|Number cleartext, Nonce q, response S R q, em|} |]
paulson@15068
    65
  ==> 
paulson@15068
    66
   Notes TTP {|Agent R, Agent TTP, S2TTP, Key(RPwd R), hr|} # evs2
paulson@15068
    67
      \<in> certified_mail"
paulson@13922
    68
berghofe@23746
    69
| CM3: --{*@{term TTP} simultaneously reveals the key to the recipient and gives
paulson@13922
    70
         a receipt to the sender.  The SSL channel does not authenticate 
paulson@14735
    71
         the client (@{term R}), but @{term TTP} accepts the message only 
paulson@14735
    72
         if the given password is that of the claimed sender, @{term R}.
paulson@13922
    73
         He replies over the established SSL channel.*}
paulson@13922
    74
 "[|evs3 \<in> certified_mail;
paulson@14735
    75
    Notes TTP {|Agent R, Agent TTP, S2TTP, Key(RPwd R), hr|} \<in> set evs3;
paulson@14735
    76
    S2TTP = Crypt (pubEK TTP) 
paulson@14735
    77
                     {|Agent S, Number BothAuth, Key k, Agent R, hs|};
paulson@14735
    78
    TTP \<noteq> R;  hs = hr;  k \<in> symKeys|]
paulson@15068
    79
  ==> 
paulson@15068
    80
   Notes R {|Agent TTP, Agent R, Key k, hr|} # 
paulson@15068
    81
   Gets S (Crypt (priSK TTP) S2TTP) # 
paulson@15068
    82
   Says TTP S (Crypt (priSK TTP) S2TTP) # evs3 \<in> certified_mail"
paulson@13922
    83
berghofe@23746
    84
| Reception:
paulson@13922
    85
 "[|evsr \<in> certified_mail; Says A B X \<in> set evsr|]
paulson@13922
    86
  ==> Gets B X#evsr \<in> certified_mail"
paulson@13922
    87
paulson@13922
    88
paulson@14145
    89
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@14145
    90
declare analz_into_parts [dest]
paulson@14145
    91
paulson@13922
    92
(*A "possibility property": there are traces that reach the end*)
paulson@14200
    93
lemma "[| Key K \<notin> used []; K \<in> symKeys |] ==> 
paulson@14200
    94
       \<exists>S2TTP. \<exists>evs \<in> certified_mail.
paulson@13956
    95
           Says TTP S (Crypt (priSK TTP) S2TTP) \<in> set evs"
paulson@13922
    96
apply (intro exI bexI)
paulson@13922
    97
apply (rule_tac [2] certified_mail.Nil
paulson@13922
    98
                    [THEN certified_mail.CM1, THEN certified_mail.Reception,
paulson@13922
    99
                     THEN certified_mail.CM2, 
paulson@14200
   100
                     THEN certified_mail.CM3]) 
paulson@14200
   101
apply (possibility, auto) 
paulson@13922
   102
done
paulson@13922
   103
paulson@13922
   104
paulson@13922
   105
lemma Gets_imp_Says:
paulson@13922
   106
 "[| Gets B X \<in> set evs; evs \<in> certified_mail |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@13922
   107
apply (erule rev_mp)
paulson@13922
   108
apply (erule certified_mail.induct, auto)
paulson@13922
   109
done
paulson@13922
   110
paulson@13922
   111
paulson@13922
   112
lemma Gets_imp_parts_knows_Spy:
paulson@13922
   113
     "[|Gets A X \<in> set evs; evs \<in> certified_mail|] ==> X \<in> parts(spies evs)"
paulson@13922
   114
apply (drule Gets_imp_Says, simp)
paulson@13922
   115
apply (blast dest: Says_imp_knows_Spy parts.Inj) 
paulson@13922
   116
done
paulson@13922
   117
paulson@13922
   118
lemma CM2_S2TTP_analz_knows_Spy:
paulson@13922
   119
 "[|Gets R {|Agent A, Agent B, em, Number AO, Number cleartext, 
paulson@13922
   120
              Nonce q, S2TTP|} \<in> set evs;
paulson@13922
   121
    evs \<in> certified_mail|] 
paulson@14145
   122
  ==> S2TTP \<in> analz(spies evs)"
paulson@13922
   123
apply (drule Gets_imp_Says, simp) 
paulson@13922
   124
apply (blast dest: Says_imp_knows_Spy analz.Inj) 
paulson@13922
   125
done
paulson@13922
   126
paulson@13922
   127
lemmas CM2_S2TTP_parts_knows_Spy = 
paulson@13922
   128
    CM2_S2TTP_analz_knows_Spy [THEN analz_subset_parts [THEN subsetD]]
paulson@13922
   129
paulson@13922
   130
lemma hr_form_lemma [rule_format]:
paulson@13922
   131
 "evs \<in> certified_mail
paulson@14145
   132
  ==> hr \<notin> synth (analz (spies evs)) --> 
paulson@13922
   133
      (\<forall>S2TTP. Notes TTP {|Agent R, Agent TTP, S2TTP, pwd, hr|}
paulson@13922
   134
          \<in> set evs --> 
paulson@13922
   135
      (\<exists>clt q S em. hr = Hash {|Number clt, Nonce q, response S R q, em|}))"
paulson@13922
   136
apply (erule certified_mail.induct)
paulson@13922
   137
apply (synth_analz_mono_contra, simp_all, blast+)
paulson@13922
   138
done 
paulson@13922
   139
paulson@13922
   140
text{*Cannot strengthen the first disjunct to @{term "R\<noteq>Spy"} because
paulson@13922
   141
the fakessl rule allows Spy to spoof the sender's name.  Maybe can
paulson@13922
   142
strengthen the second disjunct with @{term "R\<noteq>Spy"}.*}
paulson@13922
   143
lemma hr_form:
paulson@13922
   144
 "[|Notes TTP {|Agent R, Agent TTP, S2TTP, pwd, hr|} \<in> set evs;
paulson@13922
   145
    evs \<in> certified_mail|]
paulson@14145
   146
  ==> hr \<in> synth (analz (spies evs)) | 
paulson@13922
   147
      (\<exists>clt q S em. hr = Hash {|Number clt, Nonce q, response S R q, em|})"
paulson@13922
   148
by (blast intro: hr_form_lemma) 
paulson@13922
   149
paulson@14145
   150
lemma Spy_dont_know_private_keys [dest!]:
paulson@14145
   151
    "[|Key (privateKey b A) \<in> parts (spies evs); evs \<in> certified_mail|]
paulson@14145
   152
     ==> A \<in> bad"
paulson@14145
   153
apply (erule rev_mp) 
paulson@13922
   154
apply (erule certified_mail.induct, simp_all)
paulson@13922
   155
txt{*Fake*}
paulson@14207
   156
apply (blast dest: Fake_parts_insert_in_Un) 
paulson@13922
   157
txt{*Message 1*}
paulson@13922
   158
apply blast  
paulson@13922
   159
txt{*Message 3*}
paulson@13922
   160
apply (frule_tac hr_form, assumption)
paulson@13922
   161
apply (elim disjE exE) 
paulson@13922
   162
apply (simp_all add: parts_insert2) 
paulson@14145
   163
 apply (force dest!: parts_insert_subset_Un [THEN [2] rev_subsetD] 
paulson@14145
   164
                     analz_subset_parts [THEN subsetD], blast) 
paulson@13922
   165
done
paulson@13922
   166
paulson@13922
   167
lemma Spy_know_private_keys_iff [simp]:
paulson@13922
   168
    "evs \<in> certified_mail
paulson@13922
   169
     ==> (Key (privateKey b A) \<in> parts (spies evs)) = (A \<in> bad)"
paulson@14207
   170
by blast 
paulson@13922
   171
paulson@13956
   172
lemma Spy_dont_know_TTPKey_parts [simp]:
paulson@14145
   173
     "evs \<in> certified_mail ==> Key (privateKey b TTP) \<notin> parts(spies evs)" 
paulson@13956
   174
by simp
paulson@13934
   175
paulson@13956
   176
lemma Spy_dont_know_TTPKey_analz [simp]:
paulson@14145
   177
     "evs \<in> certified_mail ==> Key (privateKey b TTP) \<notin> analz(spies evs)"
paulson@14145
   178
by auto
paulson@13934
   179
paulson@13934
   180
text{*Thus, prove any goal that assumes that @{term Spy} knows a private key
paulson@13934
   181
belonging to @{term TTP}*}
paulson@13956
   182
declare Spy_dont_know_TTPKey_parts [THEN [2] rev_notE, elim!]
paulson@13934
   183
paulson@13922
   184
paulson@13922
   185
lemma CM3_k_parts_knows_Spy:
paulson@13922
   186
 "[| evs \<in> certified_mail;
paulson@13922
   187
     Notes TTP {|Agent A, Agent TTP,
paulson@13956
   188
                 Crypt (pubEK TTP) {|Agent S, Number AO, Key K, 
paulson@13922
   189
                 Agent R, hs|}, Key (RPwd R), hs|} \<in> set evs|]
paulson@13922
   190
  ==> Key K \<in> parts(spies evs)"
paulson@13922
   191
apply (rotate_tac 1)
paulson@13922
   192
apply (erule rev_mp)
paulson@13922
   193
apply (erule certified_mail.induct, simp_all)
paulson@13922
   194
   apply (blast  intro:parts_insertI)
paulson@13922
   195
txt{*Fake SSL*}
paulson@14145
   196
apply (blast dest: parts.Body) 
paulson@13922
   197
txt{*Message 2*}
paulson@14145
   198
apply (blast dest!: Gets_imp_Says elim!: knows_Spy_partsEs)
paulson@13922
   199
txt{*Message 3*}
paulson@43584
   200
apply (metis parts_insertI)
paulson@13922
   201
done
paulson@13922
   202
paulson@13922
   203
lemma Spy_dont_know_RPwd [rule_format]:
paulson@13922
   204
    "evs \<in> certified_mail ==> Key (RPwd A) \<in> parts(spies evs) --> A \<in> bad"
paulson@13922
   205
apply (erule certified_mail.induct, simp_all) 
paulson@13922
   206
txt{*Fake*}
paulson@14207
   207
apply (blast dest: Fake_parts_insert_in_Un) 
paulson@13922
   208
txt{*Message 1*}
paulson@13922
   209
apply blast  
paulson@13922
   210
txt{*Message 3*}
paulson@13922
   211
apply (frule CM3_k_parts_knows_Spy, assumption)
paulson@13922
   212
apply (frule_tac hr_form, assumption)
paulson@13922
   213
apply (elim disjE exE) 
paulson@13922
   214
apply (simp_all add: parts_insert2) 
paulson@14145
   215
apply (force dest!: parts_insert_subset_Un [THEN [2] rev_subsetD]
paulson@14145
   216
                    analz_subset_parts [THEN subsetD])
paulson@13922
   217
done
paulson@13922
   218
paulson@13922
   219
paulson@13922
   220
lemma Spy_know_RPwd_iff [simp]:
paulson@14145
   221
    "evs \<in> certified_mail ==> (Key (RPwd A) \<in> parts(spies evs)) = (A\<in>bad)"
paulson@13922
   222
by (auto simp add: Spy_dont_know_RPwd) 
paulson@13922
   223
paulson@13922
   224
lemma Spy_analz_RPwd_iff [simp]:
paulson@14145
   225
    "evs \<in> certified_mail ==> (Key (RPwd A) \<in> analz(spies evs)) = (A\<in>bad)"
paulson@43584
   226
by (metis Spy_know_RPwd_iff Spy_spies_bad_shrK analz.Inj analz_into_parts)
paulson@13922
   227
paulson@13922
   228
text{*Unused, but a guarantee of sorts*}
paulson@13922
   229
theorem CertAutenticity:
paulson@13956
   230
     "[|Crypt (priSK TTP) X \<in> parts (spies evs); evs \<in> certified_mail|] 
paulson@13956
   231
      ==> \<exists>A. Says TTP A (Crypt (priSK TTP) X) \<in> set evs"
paulson@13922
   232
apply (erule rev_mp)
paulson@13922
   233
apply (erule certified_mail.induct, simp_all) 
paulson@13922
   234
txt{*Fake*}
paulson@14145
   235
apply (blast dest: Spy_dont_know_private_keys Fake_parts_insert_in_Un)
paulson@13922
   236
txt{*Message 1*}
paulson@13922
   237
apply blast 
paulson@13922
   238
txt{*Message 3*}
paulson@13922
   239
apply (frule_tac hr_form, assumption)
paulson@13922
   240
apply (elim disjE exE) 
paulson@14145
   241
apply (simp_all add: parts_insert2 parts_insert_knows_A) 
paulson@14207
   242
 apply (blast dest!: Fake_parts_sing_imp_Un, blast)
paulson@13922
   243
done
paulson@13922
   244
paulson@13922
   245
paulson@13922
   246
subsection{*Proving Confidentiality Results*}
paulson@13922
   247
paulson@13922
   248
lemma analz_image_freshK [rule_format]:
paulson@13922
   249
 "evs \<in> certified_mail ==>
paulson@13956
   250
   \<forall>K KK. invKey (pubEK TTP) \<notin> KK -->
paulson@14145
   251
          (Key K \<in> analz (Key`KK Un (spies evs))) =
paulson@14145
   252
          (K \<in> KK | Key K \<in> analz (spies evs))"
paulson@13922
   253
apply (erule certified_mail.induct)
paulson@13922
   254
apply (drule_tac [6] A=TTP in symKey_neq_priEK) 
paulson@13922
   255
apply (erule_tac [6] disjE [OF hr_form]) 
paulson@13922
   256
apply (drule_tac [5] CM2_S2TTP_analz_knows_Spy) 
paulson@13922
   257
prefer 9
paulson@13922
   258
apply (elim exE)
paulson@13922
   259
apply (simp_all add: synth_analz_insert_eq
paulson@13922
   260
                     subset_trans [OF _ subset_insertI]
paulson@13922
   261
                     subset_trans [OF _ Un_upper2] 
paulson@13922
   262
                del: image_insert image_Un add: analz_image_freshK_simps)
paulson@13922
   263
done
paulson@13922
   264
paulson@13922
   265
paulson@13922
   266
lemma analz_insert_freshK:
paulson@13956
   267
  "[| evs \<in> certified_mail;  KAB \<noteq> invKey (pubEK TTP) |] ==>
paulson@14145
   268
      (Key K \<in> analz (insert (Key KAB) (spies evs))) =
paulson@14145
   269
      (K = KAB | Key K \<in> analz (spies evs))"
paulson@13922
   270
by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@13922
   271
paulson@13922
   272
text{*@{term S2TTP} must have originated from a valid sender
paulson@13922
   273
    provided @{term K} is secure.  Proof is surprisingly hard.*}
paulson@13922
   274
paulson@13922
   275
lemma Notes_SSL_imp_used:
paulson@13922
   276
     "[|Notes B {|Agent A, Agent B, X|} \<in> set evs|] ==> X \<in> used evs"
paulson@13922
   277
by (blast dest!: Notes_imp_used)
paulson@13922
   278
paulson@13922
   279
paulson@14145
   280
(*The weaker version, replacing "used evs" by "parts (spies evs)", 
paulson@13922
   281
   isn't inductive: message 3 case can't be proved *)
paulson@13922
   282
lemma S2TTP_sender_lemma [rule_format]:
paulson@13922
   283
 "evs \<in> certified_mail ==>
paulson@14145
   284
    Key K \<notin> analz (spies evs) -->
paulson@13956
   285
    (\<forall>AO. Crypt (pubEK TTP)
wenzelm@32960
   286
           {|Agent S, Number AO, Key K, Agent R, hs|} \<in> used evs -->
paulson@13922
   287
    (\<exists>m ctxt q. 
paulson@13922
   288
        hs = Hash{|Number ctxt, Nonce q, response S R q, Crypt K (Number m)|} &
wenzelm@32960
   289
        Says S R
wenzelm@32960
   290
           {|Agent S, Agent TTP, Crypt K (Number m), Number AO,
wenzelm@32960
   291
             Number ctxt, Nonce q,
wenzelm@32960
   292
             Crypt (pubEK TTP)
wenzelm@32960
   293
              {|Agent S, Number AO, Key K, Agent R, hs |}|} \<in> set evs))" 
paulson@13922
   294
apply (erule certified_mail.induct, analz_mono_contra)
paulson@13922
   295
apply (drule_tac [5] CM2_S2TTP_parts_knows_Spy, simp)
paulson@13922
   296
apply (simp add: used_Nil Crypt_notin_initState, simp_all)
paulson@13922
   297
txt{*Fake*}
paulson@14145
   298
apply (blast dest: Fake_parts_sing [THEN subsetD]
paulson@14145
   299
             dest!: analz_subset_parts [THEN subsetD])  
paulson@13922
   300
txt{*Fake SSL*}
paulson@14145
   301
apply (blast dest: Fake_parts_sing [THEN subsetD]
paulson@14145
   302
             dest: analz_subset_parts [THEN subsetD])  
paulson@13922
   303
txt{*Message 1*}
paulson@13956
   304
apply (clarsimp, blast)
paulson@13922
   305
txt{*Message 2*}
paulson@13922
   306
apply (simp add: parts_insert2, clarify) 
paulson@43584
   307
apply (metis parts_cut Un_empty_left usedI)
paulson@13922
   308
txt{*Message 3*} 
paulson@13922
   309
apply (blast dest: Notes_SSL_imp_used used_parts_subset_parts) 
paulson@13922
   310
done 
paulson@13922
   311
paulson@13922
   312
lemma S2TTP_sender:
paulson@13956
   313
 "[|Crypt (pubEK TTP) {|Agent S, Number AO, Key K, Agent R, hs|} \<in> used evs;
paulson@14145
   314
    Key K \<notin> analz (spies evs);
paulson@13922
   315
    evs \<in> certified_mail|]
paulson@13922
   316
  ==> \<exists>m ctxt q. 
paulson@13922
   317
        hs = Hash{|Number ctxt, Nonce q, response S R q, Crypt K (Number m)|} &
wenzelm@32960
   318
        Says S R
wenzelm@32960
   319
           {|Agent S, Agent TTP, Crypt K (Number m), Number AO,
wenzelm@32960
   320
             Number ctxt, Nonce q,
wenzelm@32960
   321
             Crypt (pubEK TTP)
wenzelm@32960
   322
              {|Agent S, Number AO, Key K, Agent R, hs |}|} \<in> set evs" 
paulson@13922
   323
by (blast intro: S2TTP_sender_lemma) 
paulson@13922
   324
paulson@13922
   325
paulson@13922
   326
text{*Nobody can have used non-existent keys!*}
paulson@14207
   327
lemma new_keys_not_used [simp]:
paulson@13922
   328
    "[|Key K \<notin> used evs; K \<in> symKeys; evs \<in> certified_mail|]
paulson@13922
   329
     ==> K \<notin> keysFor (parts (spies evs))"
paulson@13922
   330
apply (erule rev_mp) 
paulson@13922
   331
apply (erule certified_mail.induct, simp_all) 
paulson@13922
   332
txt{*Fake*}
paulson@13922
   333
apply (force dest!: keysFor_parts_insert) 
paulson@13922
   334
txt{*Message 1*}
paulson@13922
   335
apply blast 
paulson@13922
   336
txt{*Message 3*}
paulson@13922
   337
apply (frule CM3_k_parts_knows_Spy, assumption)
paulson@13922
   338
apply (frule_tac hr_form, assumption) 
paulson@13922
   339
apply (force dest!: keysFor_parts_insert)
paulson@13922
   340
done
paulson@13922
   341
paulson@13922
   342
paulson@13922
   343
text{*Less easy to prove @{term "m'=m"}.  Maybe needs a separate unicity
paulson@13926
   344
theorem for ciphertexts of the form @{term "Crypt K (Number m)"}, 
paulson@13922
   345
where @{term K} is secure.*}
paulson@13922
   346
lemma Key_unique_lemma [rule_format]:
paulson@13922
   347
     "evs \<in> certified_mail ==>
paulson@14145
   348
       Key K \<notin> analz (spies evs) -->
paulson@13922
   349
       (\<forall>m cleartext q hs.
paulson@13922
   350
        Says S R
paulson@13922
   351
           {|Agent S, Agent TTP, Crypt K (Number m), Number AO,
paulson@13922
   352
             Number cleartext, Nonce q,
paulson@13956
   353
             Crypt (pubEK TTP) {|Agent S, Number AO, Key K, Agent R, hs|}|}
paulson@13922
   354
          \<in> set evs -->
paulson@13922
   355
       (\<forall>m' cleartext' q' hs'.
paulson@13922
   356
       Says S' R'
paulson@13922
   357
           {|Agent S', Agent TTP, Crypt K (Number m'), Number AO',
paulson@13922
   358
             Number cleartext', Nonce q',
paulson@13956
   359
             Crypt (pubEK TTP) {|Agent S', Number AO', Key K, Agent R', hs'|}|}
paulson@13922
   360
          \<in> set evs --> R' = R & S' = S & AO' = AO & hs' = hs))" 
paulson@13922
   361
apply (erule certified_mail.induct, analz_mono_contra, simp_all)
paulson@14145
   362
 prefer 2
paulson@14145
   363
 txt{*Message 1*}
paulson@14145
   364
 apply (blast dest!: Says_imp_knows_Spy [THEN parts.Inj] new_keys_not_used Crypt_imp_keysFor)
paulson@14145
   365
txt{*Fake*}
paulson@14145
   366
apply (auto dest!: usedI S2TTP_sender analz_subset_parts [THEN subsetD]) 
paulson@13922
   367
done
paulson@13922
   368
paulson@13922
   369
text{*The key determines the sender, recipient and protocol options.*}
paulson@13926
   370
lemma Key_unique:
paulson@13922
   371
      "[|Says S R
paulson@13922
   372
           {|Agent S, Agent TTP, Crypt K (Number m), Number AO,
paulson@13922
   373
             Number cleartext, Nonce q,
paulson@13956
   374
             Crypt (pubEK TTP) {|Agent S, Number AO, Key K, Agent R, hs|}|}
paulson@13922
   375
          \<in> set evs;
paulson@13922
   376
         Says S' R'
paulson@13922
   377
           {|Agent S', Agent TTP, Crypt K (Number m'), Number AO',
paulson@13922
   378
             Number cleartext', Nonce q',
paulson@13956
   379
             Crypt (pubEK TTP) {|Agent S', Number AO', Key K, Agent R', hs'|}|}
paulson@13922
   380
          \<in> set evs;
paulson@14145
   381
         Key K \<notin> analz (spies evs);
paulson@13922
   382
         evs \<in> certified_mail|]
paulson@13922
   383
       ==> R' = R & S' = S & AO' = AO & hs' = hs"
paulson@13922
   384
by (rule Key_unique_lemma, assumption+)
paulson@13922
   385
paulson@13934
   386
paulson@13926
   387
subsection{*The Guarantees for Sender and Recipient*}
paulson@13926
   388
paulson@13934
   389
text{*A Sender's guarantee:
paulson@13934
   390
      If Spy gets the key then @{term R} is bad and @{term S} moreover
paulson@13922
   391
      gets his return receipt (and therefore has no grounds for complaint).*}
paulson@17689
   392
theorem S_fairness_bad_R:
paulson@13922
   393
      "[|Says S R {|Agent S, Agent TTP, Crypt K (Number m), Number AO, 
paulson@13922
   394
                     Number cleartext, Nonce q, S2TTP|} \<in> set evs;
paulson@13956
   395
         S2TTP = Crypt (pubEK TTP) {|Agent S, Number AO, Key K, Agent R, hs|};
paulson@17689
   396
         Key K \<in> analz (spies evs);
wenzelm@32960
   397
         evs \<in> certified_mail;
paulson@13922
   398
         S\<noteq>Spy|]
paulson@13956
   399
      ==> R \<in> bad & Gets S (Crypt (priSK TTP) S2TTP) \<in> set evs"
paulson@13922
   400
apply (erule rev_mp)
paulson@13922
   401
apply (erule ssubst)
paulson@13956
   402
apply (erule rev_mp)
paulson@13922
   403
apply (erule certified_mail.induct, simp_all)
paulson@13922
   404
txt{*Fake*}
paulson@13922
   405
apply spy_analz
paulson@13922
   406
txt{*Fake SSL*}
paulson@13922
   407
apply spy_analz
paulson@13922
   408
txt{*Message 3*}
paulson@13922
   409
apply (frule_tac hr_form, assumption)
paulson@13922
   410
apply (elim disjE exE) 
paulson@13922
   411
apply (simp_all add: synth_analz_insert_eq  
paulson@13922
   412
                     subset_trans [OF _ subset_insertI]
paulson@13922
   413
                     subset_trans [OF _ Un_upper2] 
paulson@13922
   414
                del: image_insert image_Un add: analz_image_freshK_simps) 
paulson@13922
   415
apply (simp_all add: symKey_neq_priEK analz_insert_freshK)
paulson@13922
   416
apply (blast dest: Notes_SSL_imp_used S2TTP_sender Key_unique)+
paulson@13922
   417
done
paulson@13922
   418
paulson@13922
   419
text{*Confidentially for the symmetric key*}
paulson@13922
   420
theorem Spy_not_see_encrypted_key:
paulson@13922
   421
      "[|Says S R {|Agent S, Agent TTP, Crypt K (Number m), Number AO, 
paulson@13922
   422
                     Number cleartext, Nonce q, S2TTP|} \<in> set evs;
paulson@13956
   423
         S2TTP = Crypt (pubEK TTP) {|Agent S, Number AO, Key K, Agent R, hs|};
wenzelm@32960
   424
         evs \<in> certified_mail;
paulson@13922
   425
         S\<noteq>Spy; R \<notin> bad|]
paulson@14145
   426
      ==> Key K \<notin> analz(spies evs)"
paulson@17689
   427
by (blast dest: S_fairness_bad_R) 
paulson@13922
   428
paulson@13922
   429
paulson@13922
   430
text{*Agent @{term R}, who may be the Spy, doesn't receive the key
paulson@13922
   431
 until @{term S} has access to the return receipt.*} 
paulson@13922
   432
theorem S_guarantee:
paulson@17689
   433
     "[|Says S R {|Agent S, Agent TTP, Crypt K (Number m), Number AO, 
wenzelm@32960
   434
                    Number cleartext, Nonce q, S2TTP|} \<in> set evs;
wenzelm@32960
   435
        S2TTP = Crypt (pubEK TTP) {|Agent S, Number AO, Key K, Agent R, hs|};
wenzelm@32960
   436
        Notes R {|Agent TTP, Agent R, Key K, hs|} \<in> set evs;
wenzelm@32960
   437
        S\<noteq>Spy;  evs \<in> certified_mail|]
paulson@17689
   438
     ==> Gets S (Crypt (priSK TTP) S2TTP) \<in> set evs"
paulson@13922
   439
apply (erule rev_mp)
paulson@13922
   440
apply (erule ssubst)
paulson@13956
   441
apply (erule rev_mp)
paulson@13922
   442
apply (erule certified_mail.induct, simp_all)
paulson@13922
   443
txt{*Message 1*}
paulson@13922
   444
apply (blast dest: Notes_imp_used) 
paulson@17689
   445
txt{*Message 3*}
paulson@17689
   446
apply (blast dest: Notes_SSL_imp_used S2TTP_sender Key_unique S_fairness_bad_R) 
paulson@13922
   447
done
paulson@13922
   448
paulson@13922
   449
paulson@17689
   450
text{*If @{term R} sends message 2, and a delivery certificate exists, 
paulson@17689
   451
 then @{term R} receives the necessary key.  This result is also important
paulson@17689
   452
 to @{term S}, as it confirms the validity of the return receipt.*}
paulson@17689
   453
theorem RR_validity:
paulson@13956
   454
  "[|Crypt (priSK TTP) S2TTP \<in> used evs;
paulson@13956
   455
     S2TTP = Crypt (pubEK TTP)
paulson@13934
   456
               {|Agent S, Number AO, Key K, Agent R, 
paulson@13934
   457
                 Hash {|Number cleartext, Nonce q, r, em|}|};
paulson@13922
   458
     hr = Hash {|Number cleartext, Nonce q, r, em|};
paulson@13922
   459
     R\<noteq>Spy;  evs \<in> certified_mail|]
paulson@13922
   460
  ==> Notes R {|Agent TTP, Agent R, Key K, hr|} \<in> set evs"
paulson@13922
   461
apply (erule rev_mp)
paulson@13922
   462
apply (erule ssubst)
paulson@13922
   463
apply (erule ssubst)
paulson@13922
   464
apply (erule certified_mail.induct, simp_all)
paulson@13934
   465
txt{*Fake*} 
paulson@14145
   466
apply (blast dest: Fake_parts_sing [THEN subsetD]
paulson@14145
   467
             dest!: analz_subset_parts [THEN subsetD])  
paulson@13934
   468
txt{*Fake SSL*}
paulson@14145
   469
apply (blast dest: Fake_parts_sing [THEN subsetD]
paulson@14145
   470
            dest!: analz_subset_parts [THEN subsetD])  
paulson@13922
   471
txt{*Message 2*}
paulson@13934
   472
apply (drule CM2_S2TTP_parts_knows_Spy, assumption)
paulson@13934
   473
apply (force dest: parts_cut)
paulson@13934
   474
txt{*Message 3*}
paulson@13934
   475
apply (frule_tac hr_form, assumption)
paulson@13934
   476
apply (elim disjE exE, simp_all) 
paulson@14145
   477
apply (blast dest: Fake_parts_sing [THEN subsetD]
paulson@14145
   478
             dest!: analz_subset_parts [THEN subsetD]) 
paulson@13922
   479
done
paulson@13922
   480
paulson@13922
   481
end