2017-02-01 12:52:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-01 17:14:52 +00:00
|
|
|
#include "libp2p/crypto/key.h"
|
2017-02-02 19:10:12 +00:00
|
|
|
#include "libp2p/crypto/rsa.h"
|
2017-02-01 17:14:52 +00:00
|
|
|
|
2017-02-01 12:52:09 +00:00
|
|
|
/**
|
|
|
|
* A secure connection
|
|
|
|
*/
|
|
|
|
|
2017-02-02 19:10:12 +00:00
|
|
|
enum IPTrafficType { TCP, UDP };
|
|
|
|
|
2017-02-01 12:52:09 +00:00
|
|
|
struct SecureSession {
|
2017-02-02 19:10:12 +00:00
|
|
|
// to get the connection started
|
|
|
|
char* host;
|
|
|
|
int port;
|
|
|
|
enum IPTrafficType traffic_type;
|
|
|
|
// once the connection is established
|
2017-03-09 15:00:45 +00:00
|
|
|
struct Stream* insecure_stream;
|
|
|
|
struct Stream* secure_stream;
|
|
|
|
struct Stream* default_stream;
|
2017-02-06 22:11:22 +00:00
|
|
|
// filled in during negotiations
|
|
|
|
char* chosen_curve;
|
|
|
|
char* chosen_cipher;
|
|
|
|
char* chosen_hash;
|
2017-02-06 22:28:11 +00:00
|
|
|
unsigned char* shared_key; // a shared key based off of the ephemeral private key
|
2017-02-06 22:11:22 +00:00
|
|
|
size_t shared_key_size;
|
2017-03-02 21:14:52 +00:00
|
|
|
unsigned char* mac;
|
|
|
|
size_t mac_size;
|
2017-03-09 05:12:04 +00:00
|
|
|
/**
|
|
|
|
* The mac function to use
|
|
|
|
* @param 1 the incoming data bytes
|
|
|
|
* @param 2 the size of the incoming array
|
|
|
|
* @param 3 the results. Must be allocated to correct size (or larger)
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
2017-03-07 00:03:04 +00:00
|
|
|
int (*mac_function)(const unsigned char*, size_t, unsigned char*);
|
|
|
|
// local only stuff
|
|
|
|
char local_nonce[16];
|
2017-03-08 17:18:29 +00:00
|
|
|
struct EphemeralPrivateKey* ephemeral_private_key;
|
2017-03-07 00:03:04 +00:00
|
|
|
struct StretchedKey* local_stretched_key;
|
|
|
|
// remote stuff
|
|
|
|
char remote_nonce[16];
|
|
|
|
struct PublicKey remote_key;
|
|
|
|
char* remote_peer_id;
|
2017-03-08 17:18:29 +00:00
|
|
|
struct StretchedKey* remote_stretched_key;
|
2017-03-07 00:03:04 +00:00
|
|
|
unsigned char* remote_ephemeral_public_key;
|
|
|
|
size_t remote_ephemeral_public_key_size;
|
2017-02-01 12:52:09 +00:00
|
|
|
};
|
2017-02-02 19:10:12 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* performs initial communication over an insecure channel to share
|
|
|
|
* keys, IDs, and initiate connection. This is a framed messaging system
|
|
|
|
* @param session the secure session to be filled
|
2017-03-07 00:03:04 +00:00
|
|
|
* @param private_key the local private key to use
|
|
|
|
* @param remote_requested the other side is who asked for the upgrade
|
2017-02-02 19:10:12 +00:00
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
2017-03-07 00:03:04 +00:00
|
|
|
int libp2p_secio_handshake(struct SecureSession* session, struct RsaPrivateKey* private_key, int remote_requested);
|