src/sync_send_actions.c
author Volker Birk <vb@pep.foundation>
Tue, 23 Aug 2016 18:54:46 +0200
branchkeysync
changeset 1075 6ac3fd936e93
parent 1066 e6db6bb9d542
child 1091 0571ce4b97a2
permissions -rw-r--r--
BUGFIX: double free
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@1060
    44
    status = multicast_self_msg(session, state, msg);
vb@883
    45
    if (status != PEP_STATUS_OK)
vb@883
    46
        goto error;
vb@883
    47
vb@1066
    48
    free_DeviceGroup_Protocol_msg(msg);
vb@1058
    49
    return PEP_STATUS_OK;
vb@883
    50
vb@883
    51
enomem:
vb@883
    52
    status = PEP_OUT_OF_MEMORY;
vb@883
    53
error:
vb@1075
    54
    free(partner);
vb@1058
    55
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    56
    return status;
vb@883
    57
}
vb@883
    58
vb@883
    59
vb@883
    60
// sendHandshakeRequest() - send HandshakeRequest message
vb@883
    61
//
vb@883
    62
//  params:
vb@883
    63
//      session (in)        session handle
vb@883
    64
//      state (in)          state the state machine is in
vb@883
    65
//      partner (in)        partner to communicate with
vb@883
    66
//
vb@883
    67
//  returns:
vb@883
    68
//      PEP_STATUS_OK or any other value on error
vb@883
    69
vb@883
    70
PEP_STATUS sendHandshakeRequest(
vb@883
    71
        PEP_SESSION session,
vb@883
    72
        DeviceState_state state,
vb@939
    73
        Identity partner,
vb@939
    74
        void *extra
vb@883
    75
    )
vb@883
    76
{
vb@1060
    77
    assert(session && state);
vb@1060
    78
    if (!(session && state))
vb@1060
    79
        return PEP_ILLEGAL_VALUE;
vb@1060
    80
vb@883
    81
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    82
vb@1058
    83
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
vb@883
    84
    if (!msg)
vb@883
    85
        goto enomem;
vb@883
    86
vb@1058
    87
    status = unicast_msg(session, partner, state, msg);
vb@883
    88
    if (status != PEP_STATUS_OK)
vb@883
    89
        goto error;
vb@883
    90
vb@1066
    91
    free_DeviceGroup_Protocol_msg(msg);
vb@1058
    92
    return PEP_STATUS_OK;
vb@883
    93
vb@883
    94
enomem:
vb@883
    95
    status = PEP_OUT_OF_MEMORY;
vb@883
    96
error:
vb@1075
    97
    free(partner);
vb@1058
    98
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    99
    return status;
vb@883
   100
}
vb@883
   101
vb@883
   102
vb@883
   103
// sendGroupKeys() - send GroupKeys message
vb@883
   104
//
vb@883
   105
//  params:
vb@883
   106
//      session (in)        session handle
vb@883
   107
//      state (in)          state the state machine is in
vb@883
   108
//      partner (in)        (must be NULL)
vb@883
   109
//
vb@883
   110
//  returns:
vb@883
   111
//      PEP_STATUS_OK or any other value on error
vb@883
   112
vb@883
   113
PEP_STATUS sendGroupKeys(
vb@883
   114
        PEP_SESSION session,
vb@883
   115
        DeviceState_state state,
vb@939
   116
        Identity partner,
vb@939
   117
        void *extra
vb@883
   118
    )
vb@883
   119
{
vb@1060
   120
    assert(session && state);
vb@1060
   121
    if (!(session && state))
vb@1060
   122
        return PEP_ILLEGAL_VALUE;
vb@1060
   123
vb@883
   124
    PEP_STATUS status = PEP_STATUS_OK;
vb@1058
   125
    identity_list *kl = new_identity_list(NULL);
vb@883
   126
vb@1058
   127
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
vb@1058
   128
    if (!msg)
vb@883
   129
        goto enomem;
vb@883
   130
vb@955
   131
    status = own_identities_retrieve(session, &kl);
vb@955
   132
    if (status != PEP_STATUS_OK)
vb@955
   133
        goto error;
vb@1058
   134
    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
vb@955
   135
        goto enomem;
vb@955
   136
vb@1058
   137
    status = unicast_msg(session, partner, state, msg);
vb@883
   138
    if (status != PEP_STATUS_OK)
vb@883
   139
        goto error;
vb@883
   140
vb@955
   141
    free_identity_list(kl);
vb@1066
   142
    free_DeviceGroup_Protocol_msg(msg);
vb@1058
   143
    return PEP_STATUS_OK;
vb@883
   144
vb@883
   145
enomem:
vb@883
   146
    status = PEP_OUT_OF_MEMORY;
vb@883
   147
error:
vb@1075
   148
    free(partner);
vb@1058
   149
    free_DeviceGroup_Protocol_msg(msg);
vb@955
   150
    free_identity_list(kl);
vb@883
   151
    return status;
vb@883
   152
}
vb@883
   153