Commit f8e231ef authored by Liliana GRIGORIU (106898)'s avatar Liliana GRIGORIU (106898)
Browse files

test: the same secret key is computed for both users

parent 033d351c
......@@ -248,8 +248,9 @@ int Smkex::computeAndStoreSessionKey(SmkexSessionInfo *session,MpString const& b
}
cout <<" Smkex::computeAndStoreSessionKey: creating a secret key; it has length 64, then exiting\n";
//TODO determine length of session key properly (find function from EC_GROUP)
int rc = ECDH_compute_key(session->session_key, KDF_KEY_LENGTH, (const EC_POINT*) session->ec_local_pub_key,
(const EC_KEY*) session->ec_key, nist_800_kdf);
int rc = ECDH_compute_key(session->session_key, KDF_KEY_LENGTH,
remote_pub_key_point,
(const EC_KEY*) session->ec_key, nist_800_kdf);
print_key(session->session_key, 64);
// sugestie web de lucru cu cheile https://stackoverflow.com/questions/58832662/elliptic-curve-diffie-hellman-public-key-size
......@@ -258,6 +259,8 @@ int Smkex::computeAndStoreSessionKey(SmkexSessionInfo *session,MpString const& b
// encry
//
return 1;
......@@ -289,30 +292,32 @@ int Smkex::processSmkexMessageSip(unsigned char * msg, uint32_t msgLen, MpString
cout<<"Smkex::processSmkexMsgSip: received handshakeKey\n";
switch(session->status){ // maybe eliminate all wrong states and send an error message first??
case notConnected:
{cout<<"Smkex::processSmkexMsgSip: status is notConnected\n";
memcpy(session->remote_pub_key,rec->data,rec->length);
{
cout<<"Smkex::processSmkexMsgSip: received handshakeKey; status is notConnected\n";
memcpy(session->remote_pub_key,rec->data,rec->length);
session->remote_pub_key_length=rec->length; // TODO remove
session->remote_pub_key_len=rec->length;
//session->remote_pub_key=(unsigned char *) malloc(session->remote_pub_key_len);
print_key(session->remote_pub_key, session->remote_pub_key_len);
//exit(1);
//send my public Key
if(computeAndStoreSessionKey(session,buddy)){
cout<<"Smkex::processSmkexMsgSip: computed session key\n";
print_key(session->session_key,session->session_key_len);
//exit(1);
}
// now send my public key
SmkexT4mRecord *rec1= getSmkexT4mRecord2(0,buddy,Smkex::getClientId(), handshakeKey, SMKEX_T4M_PROTOCOL_VERSION, session->local_pub_key_length,session->local_pub_key);
printRecord(rec1);
cout<<"Smkex::processMsgSip: sending public key and exiting\n";
unsigned int len; // now serialize
unsigned char *recordSerial=SerializeSmkexT4mRecord(&len,rec1);
sendKeyOrNonce(recordSerial,len, buddy,1);
session->status=waitNonceInit;
exit(1);
session->remote_pub_key_length=rec->length; // TODO remove
session->remote_pub_key_len=rec->length;
//session->remote_pub_key=(unsigned char *) malloc(session->remote_pub_key_len);
print_key(session->remote_pub_key, session->remote_pub_key_len);
//send my public Key
if(computeAndStoreSessionKey(session,buddy)){
cout<<"Smkex::processSmkexMsgSip: computed session key\n";
print_key(session->session_key,session->session_key_len);
//exit(1);
// now send my public key
SmkexT4mRecord *rec1= getSmkexT4mRecord2(0,buddy,Smkex::getClientId(), handshakeKey, SMKEX_T4M_PROTOCOL_VERSION, session->local_pub_key_length,session->local_pub_key);
printRecord(rec1);
cout<<"Smkex::processMsgSip: sending public key and exiting\n";
unsigned int len; // now serialize
unsigned char *recordSerial=SerializeSmkexT4mRecord(&len,rec1);
sendKeyOrNonce(recordSerial,len, buddy,1);
session->status=waitNonceInit;
exit(1);
}
}
break;
case waitKeyNonceHDest:
......@@ -324,9 +329,10 @@ int Smkex::processSmkexMessageSip(unsigned char * msg, uint32_t msgLen, MpString
cout<<"Smkex::processSmkexMsgSip: computed session key\n";
print_key(session->session_key,session->session_key_len);
exit(1);
session->status=waitNonceHDest;
break;
}
session->status=waitNonceHDest;
break;
case waitKeyDest:{
session->remote_pub_key_length=rec->length; // TODO remove
session->remote_pub_key_len=rec->length;
......@@ -345,8 +351,9 @@ int Smkex::processSmkexMessageSip(unsigned char * msg, uint32_t msgLen, MpString
session->status=notConnected;
sendAlert(buddy);// send an error message
}
break;
}
break;
case connected:
memcpy(session->remote_pub_key,rec->data,PUB_KEY_LEN);
session->status=waitNonceInit;
......
......@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
cout<<"Buddy serial for created buddy is "<<buddy.getBuddySerial()<<"\n\n";
//exit(1);
MpString buddySerial=buddy.getBuddySerial();
MpService::instance()->getBuddyList()->addBuddy(buddy);
......@@ -119,21 +119,7 @@ int main(int argc, char *argv[]) {
//Smkex::testRecord(buddy.getBuddySerial(), MpString(clientId), initialSessionInfo);
Smkex::initSession(MpString(myBuddy));
/*
cout<<"\n\ninit SMKEX pattern \nSending public Key\n\n";
// send message "please start SMKEX" (prefer, totul la un loc intr-un fisier, nu in main, poate fi schimbat usor)
// varianta actuala: send message diect cu cheie1: la inceput
unsigned char *smkex_start=//(char*) malloc(initialSessionInfo.local_pub_key_length);
//smkex_start
initialSessionInfo.local_pub_key;
initialSessionInfo.iAmSessionInitiator=1;
MpBuffer payloadSmkex0((uint8_t*) smkex_start,initialSessionInfo.local_pub_key_length) ;
MpMsgPayload messageSmkex0(myBuddy, payloadSmkex0, 1, 5, 1, MP_TYPE_MESSAGE, false);
MpService::instance()->getAutoResend()->addMessage(messageSmkex0);
initialSessionInfo.sent_local_pub_key=1;
initialSessionInfo.status=Smkex::waitKeyNonceHDest; // the status of the session
*/
}
}
......@@ -170,9 +156,6 @@ int main(int argc, char *argv[]) {
// on message received confirm reception with a message
return 0;
}
Markdown is supported
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