src/sync_actions.c
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 13:59:30 +0200
changeset 655 8413f45947e8
parent 654 0aa96447e38f
child 656 bf63654b3a39
permissions -rw-r--r--
...
vb@623
     1
// Actions for DeviceState state machine
vb@623
     2
vb@623
     3
#include <assert.h>
vb@654
     4
#include "keymanagement.h"
vb@623
     5
#include "sync_fsm.h"
vb@650
     6
#include "map_asn1.h"
vb@650
     7
#include "../asn.1/Beacon.h"
vb@650
     8
#include "../asn.1/HandshakeRequest.h"
vb@650
     9
#include "../asn.1/OwnKeys.h"
vb@623
    10
vb@623
    11
vb@650
    12
// sendBeacon() - send Beacon message
vb@623
    13
//
vb@623
    14
//  params:
vb@627
    15
//      session (in)        session handle
vb@623
    16
//      partner (in)        (must be NULL)
vb@623
    17
//
vb@623
    18
//  returns:
vb@623
    19
//      PEP_STATUS_OK or any other value on error
vb@623
    20
vb@627
    21
PEP_STATUS sendBeacon(PEP_SESSION session, const Identity partner)
vb@623
    22
{
vb@623
    23
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    24
vb@650
    25
    assert(session);
vb@650
    26
    assert(!partner);
vb@650
    27
    if (!(session && !partner))
vb@623
    28
        return PEP_ILLEGAL_VALUE;
vb@623
    29
vb@650
    30
    Beacon_t *msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
vb@650
    31
    assert(msg);
vb@650
    32
    if (!msg)
vb@650
    33
        goto enomem;
vb@623
    34
vb@652
    35
    int32_t seq;
vb@652
    36
    status = sequence_value(session, "DeviceGroup", &seq);
vb@652
    37
    if (status != PEP_STATUS_OK)
vb@652
    38
        goto error;
vb@654
    39
    msg->header.sequence = (long) seq;
vb@652
    40
vb@654
    41
    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
vb@654
    42
    if (!me)
vb@654
    43
        goto enomem;
vb@654
    44
    status = myself(session, me);
vb@654
    45
    if (status != PEP_STATUS_OK)
vb@654
    46
        goto error;
vb@655
    47
    if (Identity_from_Struct(me, &msg->me) == NULL)
vb@655
    48
        goto enomem;
vb@655
    49
vb@650
    50
    return status;
vb@623
    51
vb@650
    52
enomem:
vb@650
    53
    status = PEP_OUT_OF_MEMORY;
vb@650
    54
error:
vb@650
    55
    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
vb@623
    56
    return status;
vb@623
    57
}
vb@623
    58
vb@650
    59
vb@650
    60
// sendHandshakeRequest() - send HandshakeRequest message
vb@623
    61
//
vb@623
    62
//  params:
vb@627
    63
//      session (in)        session handle
vb@623
    64
//      partner (in)        partner in sync
vb@623
    65
//
vb@623
    66
//  returns:
vb@623
    67
//      PEP_STATUS_OK or any other value on error
vb@623
    68
vb@627
    69
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, const Identity partner)
vb@623
    70
{
vb@623
    71
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    72
vb@650
    73
    assert(session);
vb@623
    74
    assert(partner);
vb@650
    75
    if (!(session && partner))
vb@623
    76
        return PEP_ILLEGAL_VALUE;
vb@623
    77
vb@650
    78
    HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
vb@650
    79
    assert(msg);
vb@650
    80
    if (!msg)
vb@650
    81
        goto enomem;
vb@623
    82
vb@652
    83
    int32_t seq;
vb@652
    84
    status = sequence_value(session, "DeviceGroup", &seq);
vb@652
    85
    if (status != PEP_STATUS_OK)
vb@652
    86
        goto error;
vb@654
    87
    msg->header.sequence = (long) seq;
vb@652
    88
vb@654
    89
    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
vb@654
    90
    if (!me)
vb@654
    91
        goto enomem;
vb@654
    92
    status = myself(session, me);
vb@654
    93
    if (status != PEP_STATUS_OK)
vb@654
    94
        goto error;
vb@655
    95
    if (Identity_from_Struct(me, &msg->me) == NULL)
vb@655
    96
        goto enomem;
vb@655
    97
vb@655
    98
    if (Identity_from_Struct(partner, &msg->partner) == NULL)
vb@655
    99
        goto enomem;
vb@655
   100
vb@650
   101
    return status;
vb@623
   102
vb@650
   103
enomem:
vb@650
   104
    status = PEP_OUT_OF_MEMORY;
vb@650
   105
error:
vb@650
   106
    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
vb@623
   107
    return status;
vb@623
   108
}
vb@623
   109
vb@650
   110
vb@650
   111
// showHandshake() - send
vb@623
   112
//
vb@623
   113
//  params:
vb@627
   114
//      session (in)        session handle
vb@623
   115
//      partner (in)        partner in sync
vb@623
   116
//
vb@623
   117
//  returns:
vb@623
   118
//      PEP_STATUS_OK or any other value on error
vb@623
   119
vb@627
   120
PEP_STATUS showHandshake(PEP_SESSION session, const Identity partner)
vb@623
   121
{
vb@623
   122
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   123
vb@650
   124
    assert(session);
vb@623
   125
    assert(partner);
vb@650
   126
    if (!(session && partner))
vb@623
   127
        return PEP_ILLEGAL_VALUE;
vb@623
   128
vb@623
   129
    // working code
vb@623
   130
vb@623
   131
vb@623
   132
    return status;
vb@650
   133
vb@650
   134
enomem:
vb@650
   135
    status = PEP_OUT_OF_MEMORY;
vb@650
   136
error:
vb@650
   137
    // free...
vb@650
   138
    return status;
vb@623
   139
}
vb@623
   140
vb@650
   141
vb@650
   142
// reject() - send
vb@623
   143
//
vb@623
   144
//  params:
vb@627
   145
//      session (in)        session handle
vb@623
   146
//      partner (in)        partner in sync
vb@623
   147
//
vb@623
   148
//  returns:
vb@623
   149
//      PEP_STATUS_OK or any other value on error
vb@623
   150
vb@627
   151
PEP_STATUS reject(PEP_SESSION session, const Identity partner)
vb@623
   152
{
vb@623
   153
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   154
vb@650
   155
    assert(session);
vb@623
   156
    assert(partner);
vb@650
   157
    if (!(session && partner))
vb@623
   158
        return PEP_ILLEGAL_VALUE;
vb@623
   159
vb@623
   160
    // working code
vb@623
   161
vb@623
   162
vb@623
   163
    return status;
vb@650
   164
vb@650
   165
enomem:
vb@650
   166
    status = PEP_OUT_OF_MEMORY;
vb@650
   167
error:
vb@650
   168
    // free...
vb@650
   169
    return status;
vb@623
   170
}
vb@623
   171
vb@650
   172
vb@650
   173
// storeGroupKeys() - send
vb@623
   174
//
vb@623
   175
//  params:
vb@627
   176
//      session (in)        session handle
vb@623
   177
//      partner (in)        partner in sync
vb@623
   178
//
vb@623
   179
//  returns:
vb@623
   180
//      PEP_STATUS_OK or any other value on error
vb@623
   181
vb@627
   182
PEP_STATUS storeGroupKeys(PEP_SESSION session, const Identity partner)
vb@623
   183
{
vb@623
   184
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   185
vb@650
   186
    assert(session);
vb@623
   187
    assert(partner);
vb@650
   188
    if (!(session && partner))
vb@623
   189
        return PEP_ILLEGAL_VALUE;
vb@623
   190
vb@623
   191
    // working code
vb@623
   192
vb@623
   193
vb@623
   194
    return status;
vb@650
   195
vb@650
   196
enomem:
vb@650
   197
    status = PEP_OUT_OF_MEMORY;
vb@650
   198
error:
vb@650
   199
    // free...
vb@650
   200
    return status;
vb@623
   201
}
vb@623
   202
vb@650
   203
vb@650
   204
// sendOwnKeys() - send OwnKeys message
vb@623
   205
//
vb@623
   206
//  params:
vb@627
   207
//      session (in)        session handle
vb@623
   208
//      partner (in)        (must be NULL)
vb@623
   209
//
vb@623
   210
//  returns:
vb@623
   211
//      PEP_STATUS_OK or any other value on error
vb@623
   212
vb@627
   213
PEP_STATUS sendOwnKeys(PEP_SESSION session, const Identity partner)
vb@623
   214
{
vb@623
   215
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   216
vb@650
   217
    assert(session);
vb@650
   218
    assert(!partner);
vb@650
   219
    if (!(session && !partner))
vb@623
   220
        return PEP_ILLEGAL_VALUE;
vb@623
   221
vb@650
   222
    OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
vb@650
   223
    assert(msg);
vb@650
   224
    if (!msg)
vb@650
   225
        goto enomem;
vb@623
   226
vb@652
   227
    int32_t seq;
vb@652
   228
    status = sequence_value(session, "DeviceGroup", &seq);
vb@652
   229
    if (status != PEP_STATUS_OK)
vb@652
   230
        goto error;
vb@654
   231
    msg->header.sequence = (long) seq;
vb@652
   232
vb@654
   233
    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
vb@654
   234
    if (!me)
vb@654
   235
        goto enomem;
vb@654
   236
    status = myself(session, me);
vb@654
   237
    if (status != PEP_STATUS_OK)
vb@654
   238
        goto error;
vb@655
   239
    if (Identity_from_Struct(me, &msg->me) == NULL)
vb@655
   240
        goto enomem;
vb@655
   241
vb@655
   242
    stringlist_t *sl;
vb@655
   243
    status = own_key_retrieve(session, &sl);
vb@655
   244
    if (status != PEP_STATUS_OK)
vb@655
   245
        goto error;
vb@655
   246
    if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
vb@655
   247
        goto enomem;
vb@650
   248
    return status;
vb@623
   249
vb@650
   250
enomem:
vb@650
   251
    status = PEP_OUT_OF_MEMORY;
vb@650
   252
error:
vb@650
   253
    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
vb@623
   254
    return status;
vb@623
   255
}
vb@623
   256
vb@650
   257
vb@650
   258
// transmitGroupKeys() - send
vb@623
   259
//
vb@623
   260
//  params:
vb@627
   261
//      session (in)        session handle
vb@623
   262
//      partner (in)        partner in sync
vb@623
   263
//
vb@623
   264
//  returns:
vb@623
   265
//      PEP_STATUS_OK or any other value on error
vb@623
   266
vb@627
   267
PEP_STATUS transmitGroupKeys(PEP_SESSION session, const Identity partner)
vb@623
   268
{
vb@623
   269
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   270
vb@650
   271
    assert(session);
vb@623
   272
    assert(partner);
vb@650
   273
    if (!(session && partner))
vb@623
   274
        return PEP_ILLEGAL_VALUE;
vb@623
   275
vb@623
   276
    // working code
vb@623
   277
vb@623
   278
vb@623
   279
    return status;
vb@650
   280
vb@650
   281
enomem:
vb@650
   282
    status = PEP_OUT_OF_MEMORY;
vb@650
   283
error:
vb@650
   284
    // free...
vb@650
   285
    return status;
vb@623
   286
}
vb@623
   287