Commit 62f7d5d6 authored by Marios Choudary's avatar Marios Choudary
Browse files

Added record structure for SMKEX messages

parent e20d0ed1
......@@ -51,7 +51,7 @@ public:
* buddys are identified by their serial
*/
static map<MpString, SmkexSessionInfo *> smkexKeychain;
static map<MpString, SmkexSessionInfo *> smkexKeychain;
/**
......
#include <stdint.h>
#include <iostream>
#include<cstring>
#include <stdint.h>
#include<string>
#define SMKEX_T4M_PROTOCOL_VERSION 0x01
enum SMKEX_T4M_Type : uint8_t
{
handshake,
alert,
application_data
};
struct SMKEXT4MRecord {
SMKEX_T4M_Type type;
uint8_t version;
uint16_t length;
unsigned char* data;
};
/*
* Initialize a SMKEXT4MRecord object
* Note: this function (as for now, does not copy the data, but just points to it, so the caller
* is responsible for managing the memory of the data sent here as parameter)
*/
SMKEXT4MRecord* GetSMKEXT4MRecord(SMKEX_T4M_Type type, uint8_t version, unsigned char *data, unsigned int length);
/*
* Serialize a SMKEXT4MRecord object
*/
unsigned char* SerializeSMKEXT4MRecord(SMKEXT4MRecord *rec);
......@@ -11,6 +11,7 @@
#include<algorithm>
#include "SmkexSessionInfo.h"
#include "Smkex.h"
#include "smkexrecord.h"
#include "crypto.h"
#define THIS_TAG "Smkex"
......@@ -80,9 +81,19 @@ int Smkex::sendKeyOrNonce(unsigned char *pointer, unsigned int length, MpString
}
cout<<"Smkex::sendKeyOrNonce: sending key or nonce:\n";
Smkex::print_key(pointer,length);
MpBuffer payloadSmkex((uint8_t*) pointer, length);
// Encode SMKEX data
SMKEXT4MRecord* rec = GetSMKEXT4MRecord(SMKEX_T4M_Type::handshake, SMKEX_T4M_PROTOCOL_VERSION, pointer, length);
//MpBuffer payloadSmkex((uint8_t*) pointer, length);
MpBuffer payloadSmkex((uint8_t*) rec, length);
MpMsgPayload messageSmkex(buddy, payloadSmkex, 1, 5, 1, /*int creationDate,*/ MP_TYPE_MESSAGE, false);
MpService::instance()->getAutoResend()->addMessage(messageSmkex);
// Erase SMKEX structure (we assume that addMessage copies the data)
free(rec);
return 1; // seems successful
}
......@@ -227,6 +238,11 @@ void Smkex::onMsgReceived(MpString const& serial, const uint8_t* msg, uint32_t m
std::cout << " Smkex: Message (read as char*) is exactly ----" <<message<< "---- and its length is ---"<<msgLen<<"---\n\n\n\n\n";
// decapsulate SMKEX
SMKEXT4MRecord *rec = (SMKEXT4MRecord*)msg;
// print stuff about rec, e.g. rec->len, etc.
std::cout << " SMKEX Record type: " << rec->type << endl;
if(msgLen==SESSION_NONCE_LENGTH+1 || msgLen==SESSION_NONCE_LENGTH){
// it is likely a nonce
......
#include <iostream>
#include<string.h>
#include<cstring>
#include<vector>
#include <map>
#include<algorithm>
#include "smkexrecord.h"
SMKEXT4MRecord* GetSMKEXT4MRecord(SMKEX_T4M_Type type, uint8_t version, unsigned char *data, unsigned int length)
{
SMKEXT4MRecord* rec = (SMKEXT4MRecord*)malloc(sizeof(SMKEXT4MRecord));
if (rec == NULL)
return NULL;
rec->type = type;
rec->version = version;
rec->length = length;
rec->data = data;
return rec;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment