sync/devicegroup.fsm
author Krista Grothoff <krista@pep-project.org>
Tue, 13 Dec 2016 14:54:00 +0100
branchENGINE-152
changeset 1483 65bf8eef6d70
parent 1409 e9bcd6142d54
child 1445 5d233bcdde76
permissions -rw-r--r--
ENGINE-152 ENGINE-153 ENGINE-74 ENGINE-118: commits held in ENGINE-152 until Patrick gives the OK. REQUIRES UPDATE TO LIBETPAN.
     1 // DeviceGroup protocol for p≡p
     2 
     3 // Copyleft (c) 2016, p≡p foundation
     4 
     5 // Written by Volker Birk
     6 
     7 include ./fsm.yml2
     8 
     9 protocol DeviceGroup {
    10     // all messages have a timestamp, time out and are removed after timeout
    11 
    12     broadcast sendBeacon;
    13     broadcast sendGroupUpdate;
    14     broadcast sendUpdateRequest;
    15     unencrypted sendBeacon;
    16 
    17     fsm DeviceState filename=sync {
    18         condition storedGroupKeys();
    19         condition keyElectionWon(Identity partner);
    20 
    21         state InitState {
    22             on Init {
    23                 if storedGroupKeys()
    24                     go Grouped;
    25                 go Sole;
    26             }
    27         }
    28 
    29         state Sole end=1 {
    30             on KeyGen // injected by generate_keypair()
    31                 do sendBeacon;
    32             on CannotDecrypt
    33                 do sendBeacon;  // cry, baby
    34             on Beacon(Identity partner) // this event will not happen for already
    35                                         // rejected partners
    36                 do sendHandshakeRequest(partner);
    37             on HandshakeRequest(Identity partner) {
    38                 do sendHandshakeRequest(partner);
    39                 go HandshakingSole(partner);
    40             }
    41         }
    42 
    43         state HandshakingSole(Identity partner) {
    44             on Init
    45                 do showHandshake(partner);
    46             on HandshakeRejected(Identity partner) {
    47                 do rejectHandshake(partner);             // stores rejection of partner
    48                 go Sole;
    49             }
    50             on HandshakeAccepted(Identity partner) {
    51                 do acceptHandshake(partner); 
    52                 if keyElectionWon(partner) {    // an already existing group
    53                                                 // always wins
    54                     do sendGroupKeys(partner);
    55                     go Grouped;
    56                 }
    57                 go WaitForGroupKeysSole(Identity partner);
    58             }
    59         }
    60     
    61         state WaitForGroupKeysSole(Identity partner) {
    62             on GroupKeys(Identity partner, Stringlist keys) {
    63                 do storeGroupKeys(partner, keys);
    64                 go Grouped;
    65             }
    66             on Cancel go Sole;
    67             on Reject(Identity partner) {
    68                 do rejectHandshake(partner);
    69                 go Sole;
    70             }
    71         }
    72 
    73         state Grouped end=1 {
    74             on Init 
    75                 do enterGroup;
    76             on KeyGen
    77                 do sendGroupUpdate;
    78             on CannotDecrypt
    79                 do sendUpdateRequest; // TODO: narrow request to missing key
    80             on UpdateRequest
    81                 do sendGroupUpdate;
    82             on Beacon(Identity partner)
    83                 do sendHandshakeRequest(partner);
    84             on HandshakeRequest(Identity partner) {
    85                 do sendHandshakeRequest(partner);
    86                 go HandshakingGrouped(partner);
    87             }
    88             on GroupUpdate(Identity partner, Stringlist keys)
    89                 do storeGroupKeys(partner, keys);
    90         }
    91 
    92         state HandshakingGrouped(Identity partner) {
    93             on Init
    94                 do showHandshake(partner);
    95             on HandshakeRejected(Identity partner) {
    96                 do rejectHandshake(partner);             // stores rejection of partner
    97                 go Grouped;
    98             }
    99             on HandshakeAccepted(Identity partner) {
   100                 do acceptHandshake(partner); 
   101 
   102                 // an already existing group always wins
   103                 do sendGroupKeys(partner);
   104                 go Grouped;
   105             }
   106         }
   107     
   108 
   109         tag Init 1;
   110         tag Beacon 2;
   111         tag HandshakeRequest 3;
   112         tag GroupKeys 4;
   113     }
   114 }
   115