sync/devicegroup.fsm
author Volker Birk <vb@pep.foundation>
Wed, 31 Aug 2016 08:59:35 +0200
branchkeysync
changeset 1097 6248fe9519df
parent 1047 2a4a2ec1340b
child 1161 9a1f9ec6561a
permissions -rw-r--r--
don't encrypt Beacons
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) {
vb@907
    45
                do reject(partner);             // stores rejection of partner
vb@563
    46
                go Sole;
vb@563
    47
            }
Edouard@594
    48
            on HandshakeAccepted(Identity partner) {
vb@567
    49
                if keyElectionWon(partner) {    // an already existing group
vb@567
    50
                                                // always wins
vb@711
    51
                    ownGroupKeys;
vb@711
    52
                    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) {
vb@569
    66
                do reject(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)
vb@563
    79
                do reject(partner);
vb@939
    80
            on Hand
vb@939
    81
                hakeAccepted(Identity partner)
vb@711
    82
                do sendGroupKeys(partner);
Edouard@594
    83
            on Reject(Identity partner)
vb@570
    84
                do reject partner;
vb@563
    85
        }
Edouard@613
    86
vb@951
    87
        tag Init 1;
vb@951
    88
        tag Beacon 2;
vb@951
    89
        tag HandshakeRequest 3;
vb@951
    90
        tag GroupKeys 4;
Edouard@613
    91
    }
vb@563
    92
}
vb@563
    93