src/HOL/Auth/Event.thy
author paulson
Tue Aug 20 17:46:24 1996 +0200 (1996-08-20)
changeset 1929 f0839bab4b00
parent 1913 2809adb15eb0
child 1930 cdf9bcd53749
permissions -rw-r--r--
Working version of NS, messages 1-3, WITH INTERLEAVING
     1 (*  Title:      HOL/Auth/Message
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 
     6 Datatype of events;
     7 inductive relation "traces" for Needham-Schroeder (shared keys)
     8 
     9 INTERLEAVING?  See defn of "traces"
    10 
    11 WHAT ABOUT ASYMMETRIC KEYS?  NOBODY'S PRIVATE KEY CAN EQUAL SOMEBODY ELSE'S
    12   PUBLIC KEY...
    13 *)
    14 
    15 Event = Message + List + 
    16 
    17 consts
    18   publicKey    :: agent => key
    19   serverKey    :: agent => key  (*symmetric keys*)
    20 
    21 rules
    22   isSym_serverKey "isSymKey (serverKey A)"
    23 
    24 consts  (*Initial states of agents -- parameter of the construction*)
    25   initState :: agent => msg set
    26 
    27 primrec initState agent
    28         (*Server knows all keys; other agents know only their own*)
    29   initState_Server  "initState Server     = Key `` range serverKey"
    30   initState_Friend  "initState (Friend i) = {Key (serverKey (Friend i))}"
    31   initState_Enemy   "initState Enemy  = {Key (serverKey Enemy)}"
    32 
    33 (**
    34 For asymmetric keys: server knows all public and private keys,
    35   others know their private key and perhaps all public keys  
    36 **)
    37 
    38 datatype  (*Messages, and components of agent stores*)
    39   event = Says agent agent msg
    40         | Notes agent msg
    41 
    42 consts  
    43   sees1 :: [agent, event] => msg set
    44 
    45 primrec sees1 event
    46            (*First agent recalls all that it says, but NOT everything
    47              that is sent to it; it must note such things if/when received*)
    48   sees1_Says  "sees1 A (Says A' B X)  = (if A:{A',Enemy} then {X} else {})"
    49           (*part of A's internal state*)
    50   sees1_Notes "sees1 A (Notes A' X)   = (if A=A' then {X} else {})"
    51 
    52 consts  
    53   sees :: [agent, event list] => msg set
    54 
    55 primrec sees list
    56         (*Initial knowledge includes all public keys and own private key*)
    57   sees_Nil  "sees A []       = initState A"
    58   sees_Cons "sees A (ev#evs) = sees1 A ev Un sees A evs"
    59 
    60 
    61 constdefs
    62   knownBy :: [event list, msg] => agent set
    63   "knownBy evs X == {A. X: analz (sees A evs)}"
    64 
    65 
    66 (*Agents generate "random" nonces.  Different traces always yield
    67   different nonces.  Same applies for keys.*)
    68 (*newK NEEDS AN ARGUMENT TO ALLOW ASYMMETRIC KEYS.
    69   NEED AXIOM SAYING THAT NEW KEYS CANNOT EQUAL THE INVERSE OF A PREVIOUS KEY*)
    70 consts
    71   newN :: "event list => nat"
    72   newK :: "event list => key"
    73 
    74 rules
    75   inj_serverKey "inj serverKey"
    76 
    77   inj_newN   "inj(newN)"
    78   fresh_newN "Nonce (newN evs) ~: parts (initState B)" 
    79 
    80   inj_newK   "inj(newK)"
    81   fresh_newK "Key (newK evs) ~: parts (initState B)" 
    82   isSym_newK "isSymKey (newK evs)"
    83 
    84 
    85 (*NS3 DOESN'T ALLOW INTERLEAVING -- that is, it only responds to the
    86   MOST RECENT message.*)
    87 
    88 consts  traces   :: "event list set"
    89 inductive traces
    90   intrs 
    91     Nil  "[]: traces"
    92 
    93     (*The enemy MAY say anything he CAN say.  We do not expect him to
    94       invent new nonces here, but he can also use NS1.*)
    95     Fake "[| evs: traces;  B ~= Enemy;  
    96              X: synth(analz(sees Enemy evs))
    97           |] ==> (Says Enemy B X) # evs : traces"
    98 
    99     NS1  "[| evs: traces;  A ~= Server
   100           |] ==> (Says A Server {|Agent A, Agent B, Nonce (newN evs)|}) 
   101                  # evs : traces"
   102 
   103           (*We can't trust the sender field, hence the A' in it.
   104             This allows the Server to respond more than once to A's
   105             request...*)
   106     NS2  "[| evs: traces;  A ~= B;  A ~= Server;
   107              (Says A' Server {|Agent A, Agent B, Nonce NA|}) : set_of_list evs
   108           |] ==> (Says Server A 
   109                   (Crypt {|Nonce NA, Agent B, Key (newK evs),   
   110                            (Crypt {|Key (newK evs), Agent A|} (serverKey B))|}
   111                    (serverKey A))) # evs : traces"
   112 
   113            (*We can't assume S=Server.  Agent A "remembers" her nonce.
   114              May assume WLOG that she is NOT the Enemy: the Fake rule
   115              covers this case.  Can inductively show A ~= Server*)
   116     NS3  "[| evs: traces;  A ~= B;
   117              (Says S A (Crypt {|Nonce NA, Agent B, Key K, X|} (serverKey A))) 
   118                : set_of_list evs;
   119              A = Friend i;
   120              (Says A Server {|Agent A, Agent B, Nonce NA|}) : set_of_list evs
   121           |] ==> (Says A B X) # evs : traces"
   122 
   123 (*Initial version of NS2 had 
   124 
   125         {|Agent A, Agent B, Key (newK evs), Nonce NA|}
   126 
   127   for the encrypted part; the version above is LESS explicit, hence
   128   HARDER to prove.  Also it is precisely as in the BAN paper.
   129 *)
   130 
   131 end