samedi 31 août 2019

TLS simplified Client Random decrypt

I have got from my teacher some code, and i have to work on it. The code represents a simplified TLS implementation for Linux. The problem is that i have some blank functions, like Client Random generate or decryptRandom, and i don't really know what to do in those functions.

I tried some code, from mainstream implementation of TLS, but nothing really works, and my client session goes like "Segmentation fault."

#include <iostream>
#include <arpa/inet.h>      // for inet_ntoa
#include <string.h>         // for memset
#include <sys/socket.h>
#include <unistd.h>         // for close() on sockets
#include <netinet/in.h>
#include <time.h>

#include "sTlsHshake.h"

using namespace std;

//  ====================================================================
//  GLOBAL VARIABLES

fd_set  rset;
ClientHello cliHello;

//  ====================================================================
//  handshake (sub)functions

//  --------------------------------------------------------------------
//  decrypt the client random
int
decryptRandom(u_char * rand, u_char * key) {
    return 1;
}

//  --------------------------------------------------------------------
//  process client's hello message
int
processClientHello(char * cliMsg) {
    return 1;
}

//  --------------------------------------------------------------------
//  create random
int
createRandom(u_char * sR) {
    return 28;
}

//  --------------------------------------------------------------------
//  create premaster
int
createPremaster(u_char * cR, u_char* sR) {
    return strlen("ENCREPTED_PREMASTER");
}

//  --------------------------------------------------------------------
//  process client nessage, whatever that is
int
processClientMsg(u_char * cliMsg) {
    return 1;
}

//  --------------------------------------------------------------------
//  generate master secret
u_char * genMaster(char * preMas, u_char * cR, u_char * sR) {
    u_char master[28];
    return master;
}

//  --------------------------------------------------------------------
//  create session key
void
genSessionKey(char * preMas) {
    // return sessionKey;
}

//  --------------------------------------------------------------------
//  encrypt message using session key
int
encryptMessage(char * msg, u_char * key) {
    strcpy(msg, "FIRST_ENCRYPTED_MESSAGE");
    return strlen(msg);
}

//  --------------------------------------------------------------------
//  encrypt message using session key
int
encryptPreMaster(char * msg, u_char * key) {
    strcpy(msg, "ENCRYPTED_PREMASTER");
    return strlen(msg);
}

//  ====================================================================
//  the handshake function itself

the expected result is that i can introduce an input and, after that the client and server should send eachother the TLS information, like the cipher_suite, Server Random, CLient Random, pre-master and so on.




Aucun commentaire:

Enregistrer un commentaire