src/sync_send_actions.c
author Volker Birk <vb@pep.foundation>
Thu, 01 Sep 2016 17:55:03 +0200
branchkeysync
changeset 1111 3c46dc58096d
parent 1098 737031f6f0b3
child 1161 9a1f9ec6561a
permissions -rw-r--r--
merging
vb@883
     1
// Send Actions for DeviceState state machine
vb@883
     2
vb@883
     3
#include <assert.h>
vb@883
     4
#include "pEp_internal.h"
vb@883
     5
#include "keymanagement.h"
vb@883
     6
#include "message.h"
vb@883
     7
#include "sync_fsm.h"
vb@883
     8
#include "baseprotocol.h"
vb@883
     9
#include "map_asn1.h"
vb@985
    10
#include "../asn.1/DeviceGroup-Protocol.h"
vb@1047
    11
#include "sync_impl.h"
vb@883
    12
#include "../asn.1/Beacon.h"
vb@883
    13
#include "../asn.1/HandshakeRequest.h"
vb@883
    14
#include "../asn.1/GroupKeys.h"
vb@883
    15
vb@883
    16
vb@883
    17
// sendBeacon() - send Beacon message
vb@883
    18
//
vb@883
    19
//  params:
vb@883
    20
//      session (in)        session handle
vb@883
    21
//      state (in)          state the state machine is in
vb@883
    22
//      partner (in)        (must be NULL)
vb@883
    23
//
vb@883
    24
//  returns:
vb@883
    25
//      PEP_STATUS_OK or any other value on error
vb@883
    26
vb@883
    27
PEP_STATUS sendBeacon(
vb@883
    28
        PEP_SESSION session,
vb@883
    29
        DeviceState_state state,
vb@939
    30
        Identity partner,
vb@939
    31
        void *extra
vb@883
    32
    )
vb@883
    33
{
vb@1060
    34
    assert(session && state);
vb@1060
    35
    if (!(session && state))
vb@1060
    36
        return PEP_ILLEGAL_VALUE;
vb@1060
    37
vb@883
    38
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    39
vb@1058
    40
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
vb@883
    41
    if (!msg)
vb@883
    42
        goto enomem;
vb@883
    43
vb@1098
    44
    bool encrypted = false;
vb@1097
    45
    status = multicast_self_msg(session, state, msg, encrypted);
vb@883
    46
    if (status != PEP_STATUS_OK)
vb@883
    47
        goto error;
vb@883
    48
vb@1066
    49
    free_DeviceGroup_Protocol_msg(msg);
vb@1091
    50
    free_identity(partner);
vb@1058
    51
    return PEP_STATUS_OK;
vb@883
    52
vb@883
    53
enomem:
vb@883
    54
    status = PEP_OUT_OF_MEMORY;
vb@883
    55
error:
vb@1091
    56
    free_identity(partner);
vb@1058
    57
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    58
    return status;
vb@883
    59
}
vb@883
    60
vb@883
    61
vb@883
    62
// sendHandshakeRequest() - send HandshakeRequest message
vb@883
    63
//
vb@883
    64
//  params:
vb@883
    65
//      session (in)        session handle
vb@883
    66
//      state (in)          state the state machine is in
vb@883
    67
//      partner (in)        partner to communicate with
vb@883
    68
//
vb@883
    69
//  returns:
vb@883
    70
//      PEP_STATUS_OK or any other value on error
vb@883
    71
vb@883
    72
PEP_STATUS sendHandshakeRequest(
vb@883
    73
        PEP_SESSION session,
vb@883
    74
        DeviceState_state state,
vb@939
    75
        Identity partner,
vb@939
    76
        void *extra
vb@883
    77
    )
vb@883
    78
{
vb@1060
    79
    assert(session && state);
vb@1060
    80
    if (!(session && state))
vb@1060
    81
        return PEP_ILLEGAL_VALUE;
vb@1060
    82
vb@883
    83
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    84
vb@1058
    85
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
vb@883
    86
    if (!msg)
vb@883
    87
        goto enomem;
vb@883
    88
vb@1098
    89
    bool encrypted = true;
vb@1097
    90
    status = unicast_msg(session, partner, state, msg, encrypted);
vb@883
    91
    if (status != PEP_STATUS_OK)
vb@883
    92
        goto error;
vb@883
    93
vb@1066
    94
    free_DeviceGroup_Protocol_msg(msg);
vb@1091
    95
    free_identity(partner);
vb@1058
    96
    return PEP_STATUS_OK;
vb@883
    97
vb@883
    98
enomem:
vb@883
    99
    status = PEP_OUT_OF_MEMORY;
vb@883
   100
error:
vb@1091
   101
    free_identity(partner);
vb@1058
   102
    free_DeviceGroup_Protocol_msg(msg);
vb@883
   103
    return status;
vb@883
   104
}
vb@883
   105
vb@883
   106
vb@883
   107
// sendGroupKeys() - send GroupKeys message
vb@883
   108
//
vb@883
   109
//  params:
vb@883
   110
//      session (in)        session handle
vb@883
   111
//      state (in)          state the state machine is in
vb@883
   112
//      partner (in)        (must be NULL)
vb@883
   113
//
vb@883
   114
//  returns:
vb@883
   115
//      PEP_STATUS_OK or any other value on error
vb@883
   116
vb@883
   117
PEP_STATUS sendGroupKeys(
vb@883
   118
        PEP_SESSION session,
vb@883
   119
        DeviceState_state state,
vb@939
   120
        Identity partner,
vb@939
   121
        void *extra
vb@883
   122
    )
vb@883
   123
{
vb@1060
   124
    assert(session && state);
vb@1060
   125
    if (!(session && state))
vb@1060
   126
        return PEP_ILLEGAL_VALUE;
vb@1060
   127
vb@883
   128
    PEP_STATUS status = PEP_STATUS_OK;
vb@1058
   129
    identity_list *kl = new_identity_list(NULL);
vb@883
   130
vb@1058
   131
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
vb@1058
   132
    if (!msg)
vb@883
   133
        goto enomem;
vb@883
   134
vb@955
   135
    status = own_identities_retrieve(session, &kl);
vb@955
   136
    if (status != PEP_STATUS_OK)
vb@955
   137
        goto error;
vb@1058
   138
    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
vb@955
   139
        goto enomem;
vb@955
   140
vb@1098
   141
    bool encrypted = true;
vb@1097
   142
    status = unicast_msg(session, partner, state, msg, encrypted);
vb@883
   143
    if (status != PEP_STATUS_OK)
vb@883
   144
        goto error;
vb@883
   145
vb@955
   146
    free_identity_list(kl);
vb@1066
   147
    free_DeviceGroup_Protocol_msg(msg);
vb@1091
   148
    free_identity(partner);
vb@1058
   149
    return PEP_STATUS_OK;
vb@883
   150
vb@883
   151
enomem:
vb@883
   152
    status = PEP_OUT_OF_MEMORY;
vb@883
   153
error:
vb@1091
   154
    free_identity(partner);
vb@1058
   155
    free_DeviceGroup_Protocol_msg(msg);
vb@955
   156
    free_identity_list(kl);
vb@883
   157
    return status;
vb@883
   158
}
vb@883
   159