sync/devicegroup.fsm
author Edouard Tisserant <edouard@pep-project.org>
Wed, 14 Sep 2016 01:54:05 +0200
branchkeysync
changeset 1161 9a1f9ec6561a
parent 1097 6248fe9519df
child 1216 76e7a6748913
permissions -rw-r--r--
Added keysync acceptHandshake action, fixed typo in fsm definitions
vb@563
     1
// DeviceGroup protocol for p≡p
vb@563
     2
vb@563
     3
// Copyleft (c) 2016, p≡p foundation
vb@563
     4
vb@563
     5
// Written by Volker Birk
vb@563
     6
vb@563
     7
include ./fsm.yml2
vb@563
     8
vb@563
     9
protocol DeviceGroup {
vb@563
    10
    // all messages have a timestamp, time out and are removed after timeout
vb@563
    11
vb@1047
    12
    broadcast sendBeacon;
vb@1097
    13
    unencrypted sendBeacon;
vb@1047
    14
vb@807
    15
    fsm DeviceState filename=sync {
vb@951
    16
        condition storedGroupKeys();
vb@951
    17
        condition keyElectionWon(Identity partner);
vb@951
    18
vb@624
    19
        state InitState {
vb@624
    20
            on Init {
vb@951
    21
                if storedGroupKeys()
vb@624
    22
                    go Grouped;
vb@624
    23
                go Sole;
vb@624
    24
            }
vb@563
    25
        }
vb@563
    26
vb@563
    27
        state Sole {
vb@944
    28
            on KeyGen // injected by generate_keypair()
vb@1097
    29
                do sendBeacon;
vb@563
    30
            on CannotDecrypt
vb@566
    31
                do sendBeacon;  // cry, baby
Edouard@594
    32
            on Beacon(Identity partner) // this event will not happen for already
vb@571
    33
                                        // rejected partners
vb@582
    34
                do sendHandshakeRequest(partner);
Edouard@594
    35
            on HandshakeRequest(Identity partner) {
vb@582
    36
                do sendHandshakeRequest(partner);
vb@563
    37
                go HandshakingSole(partner);
vb@563
    38
            }
vb@563
    39
        }
vb@563
    40
Edouard@594
    41
        state HandshakingSole(Identity partner) {
vb@582
    42
            on Init
vb@563
    43
                do showHandshake(partner);
Edouard@594
    44
            on HandshakeRejected(Identity partner) {
edouard@1161
    45
                do rejectHandshake(partner);             // stores rejection of partner
vb@563
    46
                go Sole;
vb@563
    47
            }
Edouard@594
    48
            on HandshakeAccepted(Identity partner) {
edouard@1161
    49
                do acceptHandshake(partner); 
vb@567
    50
                if keyElectionWon(partner) {    // an already existing group
vb@567
    51
                                                // always wins
edouard@1161
    52
                    do sendGroupKeys(partner);
vb@563
    53
                    go Grouped;
vb@563
    54
                }
Edouard@594
    55
                go WaitForGroupKeys(Identity partner);
vb@563
    56
            }
vb@563
    57
        }
vb@563
    58
    
Edouard@594
    59
        state WaitForGroupKeys(Identity partner) {
vb@711
    60
            on GroupKeys(Identity partner, Stringlist keys) {
Edouard@605
    61
                do storeGroupKeys(partner, keys);
vb@563
    62
                go Grouped;
vb@563
    63
            }
vb@568
    64
            on Cancel go Sole;
Edouard@594
    65
            on Reject(Identity partner) {
edouard@1161
    66
                do rejectHandshake(partner);
vb@569
    67
                go Sole;
vb@569
    68
            }
vb@563
    69
        }
vb@563
    70
vb@563
    71
        state Grouped {
vb@563
    72
            on KeyGen
vb@711
    73
                do sendGroupKeys; // always send all keys
Edouard@594
    74
            on HandshakeRequest(Identity partner) {
vb@582
    75
                do sendHandshakeRequest(partner);
vb@563
    76
                do showHandshake(partner);
vb@563
    77
            }
Edouard@594
    78
            on HandshakeRejected(Identity partner)
edouard@1161
    79
                do rejectHandshake(partner);
edouard@1161
    80
            on HandshakeAccepted(Identity partner){
edouard@1161
    81
                do acceptHandshake(partner); 
vb@711
    82
                do sendGroupKeys(partner);
edouard@1161
    83
            }
Edouard@594
    84
            on Reject(Identity partner)
edouard@1161
    85
                do rejectHandshake partner;
vb@563
    86
        }
Edouard@613
    87
vb@951
    88
        tag Init 1;
vb@951
    89
        tag Beacon 2;
vb@951
    90
        tag HandshakeRequest 3;
vb@951
    91
        tag GroupKeys 4;
Edouard@613
    92
    }
vb@563
    93
}
vb@563
    94