wickr-crypto-c
transport_ctx.h
1 /*
2  * Copyright © 2012-2018 Wickr Inc. All rights reserved.
3  *
4  * This code is being released for EDUCATIONAL, ACADEMIC, AND CODE REVIEW PURPOSES
5  * ONLY. COMMERCIAL USE OF THE CODE IS EXPRESSLY PROHIBITED. For additional details,
6  * please see LICENSE
7  *
8  * THE CODE IS MADE AVAILABLE "AS-IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED GUARANTEES AS TO FITNESS, MERCHANTABILITY, NON-
10  * INFRINGEMENT OR OTHERWISE. IT IS NOT BEING PROVIDED IN TRADE BUT ON
11  * A VOLUNTARY BASIS ON BEHALF OF THE AUTHOR’S PART FOR THE BENEFIT
12  * OF THE LICENSEE AND IS NOT MADE AVAILABLE FOR CONSUMER USE OR ANY
13  * OTHER USE OUTSIDE THE TERMS OF THIS LICENSE. ANYONE ACCESSING THE
14  * CODE SHOULD HAVE THE REQUISITE EXPERTISE TO SECURE THEIR SYSTEM
15  * AND DEVICES AND TO ACCESS AND USE THE CODE FOR REVIEW PURPOSES
16  * ONLY. LICENSEE BEARS THE RISK OF ACCESSING AND USING THE CODE. IN
17  * PARTICULAR, AUTHOR BEARS NO LIABILITY FOR ANY INTERFERENCE WITH OR
18  * ADVERSE EFFECT THAT MAY OCCUR AS A RESULT OF THE LICENSEE
19  * ACCESSING AND/OR USING THE CODE ON LICENSEE’S SYSTEM.
20  */
21 
22 #ifndef transport_h
23 #define transport_h
24 
25 #include "crypto_engine.h"
26 #include "node.h"
27 #include "stream_ctx.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
48 struct wickr_transport_ctx;
50 
51 typedef enum {
52  TRANSPORT_STATUS_NONE, /* Transport has not been initialized */
53  TRANSPORT_STATUS_SEEDED, /* Transport has generated and sent a seed handshake packet */
54  TRANSPORT_STATUS_TX_INIT, /* Transport has processed an incoming seed handshake packet and responded */
55  TRANSPORT_STATUS_ACTIVE, /* Transport has both rx and tx streams initialized and is able to send encrypted packets */
56  TRANSPORT_STATUS_ERROR /* Transport has encountered an error, and communication is no longer possible */
57 } wickr_transport_status;
58 
59 typedef enum {
60  TRANSPORT_DATA_FLOW_BIDIRECTIONAL, /* Data flow can happen in both directions */
61  TRANSPORT_DATA_FLOW_READ_ONLY, /* Non handshake packets can only flow in the rx direction */
62  TRANSPORT_DATA_FLOW_WRITE_ONLY /* Non handshake packets can only flow in the tx direction */
63 } wickr_transport_data_flow;
64 
65 typedef enum {
66  TRANSPORT_PAYLOAD_TYPE_HANDSHAKE, /* Payload is a handshake control packet */
67  TRANSPORT_PAYLOAD_TYPE_CIPHERTEXT /* Payload contains encrypted application data */
68 } wickr_transport_payload_type;
69 
70 /* Function callback to handle sending / receiving / errors via an actual transport, eg socket */
71 typedef void (*wickr_transport_tx_func)(const wickr_transport_ctx_t *ctx, const wickr_buffer_t *data, wickr_transport_payload_type pkt_type, void *user);
72 typedef void (*wickr_transport_rx_func)(const wickr_transport_ctx_t *ctx, const wickr_buffer_t *data, void *user);
73 typedef void (*wickr_transport_state_change_func)(const wickr_transport_ctx_t *ctx, wickr_transport_status status, void *user);
74 typedef bool (*wickr_transport_validate_identity_func)(const wickr_transport_ctx_t *ctx, wickr_identity_chain_t *identity, void *user);
75 typedef wickr_buffer_t *(*wickr_transport_psk_func) (const wickr_transport_ctx_t *ctx, void *user);
76 typedef wickr_stream_ctx_t *(*wickr_transport_tx_stream_func) (const wickr_transport_ctx_t *ctx, wickr_stream_ctx_t *tx_stream, void *user);
99  wickr_transport_tx_func tx;
100  wickr_transport_rx_func rx;
101  wickr_transport_state_change_func on_state;
102  wickr_transport_validate_identity_func on_identity_verify;
103  wickr_transport_psk_func on_psk_required;
104  wickr_transport_tx_stream_func on_tx_stream_gen;
105 };
106 
108 
128  wickr_node_t *local_identity,
129  wickr_node_t *remote_identity,
130  uint32_t evo_count,
131  wickr_transport_callbacks_t callbacks,
132  void *user);
133 
143 
152 
174 
190 
202 
203 
204 /* GETTERS AND SETTERS */
205 
215 wickr_transport_status wickr_transport_ctx_get_status(const wickr_transport_ctx_t *ctx);
216 
226 
236 
246 
256 
266 
276 
285 wickr_transport_data_flow wickr_transport_ctx_get_data_flow_mode(const wickr_transport_ctx_t *ctx);
286 
298 void wickr_transport_ctx_set_data_flow_mode(wickr_transport_ctx_t *ctx , wickr_transport_data_flow flow_mode);
299 
309 
319 
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif /* transport_h */
wickr_transport_rx_func rx
Definition: transport_ctx.h:100
void wickr_transport_ctx_set_data_flow_mode(wickr_transport_ctx_t *ctx, wickr_transport_data_flow flow_mode)
const wickr_buffer_t * wickr_transport_ctx_get_user_psk(const wickr_transport_ctx_t *ctx)
Represents an array of bytes and the length of the allocation associated with those bytes.
Definition: buffer.h:51
const wickr_node_t * wickr_transport_ctx_get_remote_node_ptr(const wickr_transport_ctx_t *ctx)
A context that is used for encrypting or decrypting a sequenced stream of data packets The stream con...
Definition: stream_ctx.h:67
Represents a message destination at a point in time.
Definition: node.h:85
wickr_transport_psk_func on_psk_required
Definition: transport_ctx.h:103
void wickr_transport_ctx_destroy(wickr_transport_ctx_t **ctx)
wickr_transport_status wickr_transport_ctx_get_status(const wickr_transport_ctx_t *ctx)
void wickr_transport_ctx_set_callbacks(wickr_transport_ctx_t *ctx, const wickr_transport_callbacks_t *callbacks)
wickr_transport_ctx_t * wickr_transport_ctx_copy(const wickr_transport_ctx_t *ctx)
const void * wickr_transport_ctx_get_user_ctx(const wickr_transport_ctx_t *ctx)
wickr_transport_tx_stream_func on_tx_stream_gen
Definition: transport_ctx.h:104
wickr_transport_ctx_t * wickr_transport_ctx_create(const wickr_crypto_engine_t engine, wickr_node_t *local_identity, wickr_node_t *remote_identity, uint32_t evo_count, wickr_transport_callbacks_t callbacks, void *user)
wickr_transport_data_flow wickr_transport_ctx_get_data_flow_mode(const wickr_transport_ctx_t *ctx)
wickr_buffer_t * wickr_transport_ctx_process_tx_buffer(wickr_transport_ctx_t *ctx, const wickr_buffer_t *buffer)
wickr_transport_state_change_func on_state
Definition: transport_ctx.h:101
Transport context to manage the state machine of a point to point connection using fundamentals of th...
void wickr_transport_ctx_set_user_ctx(wickr_transport_ctx_t *ctx, void *user)
wickr_buffer_t * wickr_transport_ctx_process_rx_buffer(wickr_transport_ctx_t *ctx, const wickr_buffer_t *buffer)
void wickr_transport_ctx_start(wickr_transport_ctx_t *ctx)
Represents a root -> node relationship as well as it's signature status.
Definition: identity.h:110
Interface to a set of cryptographic operations used throughout the library. Currently the default imp...
Definition: crypto_engine.h:53
const wickr_transport_callbacks_t * wickr_transport_ctx_get_callbacks(const wickr_transport_ctx_t *ctx)
const wickr_buffer_t * wickr_transport_ctx_get_rxstream_user_data(const wickr_transport_ctx_t *ctx)
wickr_transport_tx_func tx
Definition: transport_ctx.h:99
callbacks to notify the user of events within the transport
Definition: transport_ctx.h:98
const wickr_node_t * wickr_transport_ctx_get_local_node_ptr(const wickr_transport_ctx_t *ctx)
bool wickr_transport_ctx_force_tx_key_evo(wickr_transport_ctx_t *ctx)
wickr_transport_validate_identity_func on_identity_verify
Definition: transport_ctx.h:102