Commit 35526eea authored by Greg Williams's avatar Greg Williams
Browse files

Adding hmac and identity/key support for security

parent 01c88edb
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -24,11 +24,19 @@
void KineticExchange_Init(
    KineticExchange* const exchange,
    int64_t identity,
    uint8_t* key,
    size_t keyLength,
    int64_t connectionID,
    KineticConnection* const connection)
{
    memset(exchange, 0, sizeof(KineticExchange));
    exchange->identity = identity;
    if (key != NULL && keyLength > 0)
    {
        memcpy(&exchange->key, key, keyLength);
        exchange->keyLength = keyLength;
        exchange->has_key = true;
    }
    exchange->connectionID = connectionID;
    exchange->connection = connection;
}
+9 −0
Original line number Diff line number Diff line
@@ -42,6 +42,13 @@ typedef struct _KineticExchange
    // HMAC key (shared secret) to verify the HMAC.
    int64_t identity;

    // Required field
    // This is the identity's HMAC Key. This is a shared secret between the
    // client and the device, used to sign requests.
    bool has_key;
    size_t keyLength;
    uint8_t key[KINETIC_MAX_KEY_LEN];

    // Required field
    // A unique number for this connection between the source and target.
    // On the first request to the drive, this should be the time of day in
@@ -61,6 +68,8 @@ typedef struct _KineticExchange
void KineticExchange_Init(
    KineticExchange* const exchange,
    int64_t identity,
    uint8_t* key,
    size_t keyLength,
    int64_t connectionID,
    KineticConnection* const connection);

+3 −13
Original line number Diff line number Diff line
@@ -20,22 +20,12 @@

#include "kinetic_types.h"
#include "kinetic_message.h"
#include "kinetic_hmac.h"

void KineticMessage_Init(KineticMessage* const message)
{
    // Initialize protobuf fields
    KineticProto_init(&message->proto);
    KineticProto_command_init(&message->command);
    KineticProto_header_init(&message->header);
    KineticProto_body_init(&message->body);
    KineticProto_status_init(&message->status);

    // Assemble the message
    message->proto.hmac.data = message->hmacData;
    message->command.header = &message->header;
    message->command.body = &message->body;
    message->command.status = &message->status;
    message->proto.command = &message->command;
    // Initialize protobuf fields and ssemble the message
    KINETIC_MESSSAGE_INIT(message);
}

void KineticMessage_BuildNoop(KineticMessage* const message)
+8 −9
Original line number Diff line number Diff line
@@ -24,9 +24,6 @@
#include "kinetic_proto.h"
#include <openssl/sha.h>

// #define KINETIC_HMAC_SHA1_LEN   (SHA_DIGEST_LENGTH)


typedef struct _KineticMessage
{
    // Kinetic Protocol Buffer Elements
@@ -35,6 +32,8 @@ typedef struct _KineticMessage
    KineticProto_Header         header;
    KineticProto_Body           body;
    KineticProto_Status         status;
    KineticProto_Security       security;
    KineticProto_Security_ACL   acl;
    uint8_t                     hmacData[SHA_DIGEST_LENGTH];
} KineticMessage;

+25 −1
Original line number Diff line number Diff line
@@ -26,12 +26,15 @@
#include <stdbool.h>
#endif
#include <stdint.h>
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <limits.h>

#include <netinet/in.h>
#include <ifaddrs.h>

// Windows doesn't use <unistd.h> nor does it define HOST_NAME_MAX.
#if defined(WIN32)
    #include <windows.h>
@@ -69,4 +72,25 @@ typedef struct _KineticConnection
    char    Host[HOST_NAME_MAX];
} KineticConnection;

#include <protobuf-c/protobuf-c.h>
#include "kinetic_proto.h"
#include "kinetic_message.h"

#define KINETIC_MAX_KEY_LEN 128

#define KINETIC_MESSSAGE_INIT(msg) \
    msg->proto = KINETIC_PROTO_INIT; \
    msg->command = KINETICPROTO_COMMAND_INIT; \
    msg->header = KINETIC_PROTO_HEADER_INIT; \
    msg->body = KINETIC_PROTO_BODY_INIT; \
    msg->status = KINETIC_PROTO_STATUS_INIT; \
    msg->security = KINETIC_PROTO_SECURITY_INIT; \
    msg->acl = KINETIC_PROTO_SECURITY_ACL_INIT; \
    msg->proto.hmac.data = msg->hmacData; \
    msg->command.header = &msg->header; \
    msg->command.body = &msg->body; \
    msg->command.status = &msg->status; \
    msg->proto.command = &msg->command; \
    msmset(msg->hmac_data, 0, SHA_DIGEST_LENGTH);

#endif // _KINETIC_TYPES_H
Loading