wickr-crypto-c
transport_ctx.h
1 /*
2  * Copyright © 2012-2020 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 #include "transport_error.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
50 struct wickr_transport_ctx;
52 
53 typedef enum {
54  TRANSPORT_STATUS_NONE, /* Transport has not been initialized */
55  TRANSPORT_STATUS_INITIAL_HANDSHAKE, /* Transport has generated and sent handshake packet */
56  TRANSPORT_STATUS_ACTIVE, /* Transport has both rx and tx streams initialized and is able to send encrypted packets */
57  TRANSPORT_STATUS_ERROR /* Transport has encountered an error, and communication is no longer possible */
58 } wickr_transport_status;
59 
60 /* Function callback to handle sending / receiving / errors via an actual transport, eg socket */
61 typedef void (*wickr_transport_tx_func)(const wickr_transport_ctx_t *ctx, wickr_buffer_t *data);
62 typedef void (*wickr_transport_rx_func)(const wickr_transport_ctx_t *ctx, wickr_buffer_t *data);
63 typedef void (*wickr_transport_state_change_func)(const wickr_transport_ctx_t *ctx, wickr_transport_status status);
64 typedef void (*wickr_transport_validate_identity_callback)(const wickr_transport_ctx_t *ctx, bool is_valid);
65 typedef void (*wickr_transport_validate_identity_func)(const wickr_transport_ctx_t *ctx, wickr_identity_chain_t *identity,
66  wickr_transport_validate_identity_callback on_complete);
67 
85  wickr_transport_tx_func tx;
86  wickr_transport_rx_func rx;
87  wickr_transport_state_change_func on_state;
88  wickr_transport_validate_identity_func on_identity_verify;
89 };
90 
92 
112  wickr_identity_chain_t *local_identity,
113  wickr_identity_chain_t *remote_identity,
114  uint32_t evo_count,
115  wickr_transport_callbacks_t callbacks,
116  void *user);
117 
127 
136 
153 
168 
179 
180 
181 /* GETTERS AND SETTERS */
182 
192 wickr_transport_status wickr_transport_ctx_get_status(const wickr_transport_ctx_t *ctx);
193 
203 
213 
223 
233 
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* transport_h */
wickr_identity_chain
Represents a root -> node relationship as well as it's signature status.
Definition: identity.h:116
wickr_transport_ctx_get_last_error
wickr_transport_error wickr_transport_ctx_get_last_error(const wickr_transport_ctx_t *ctx)
wickr_transport_ctx_process_tx_buffer
void wickr_transport_ctx_process_tx_buffer(wickr_transport_ctx_t *ctx, const wickr_buffer_t *buffer)
wickr_crypto_engine
Interface to a set of cryptographic operations used throughout the library. Currently the default imp...
Definition: crypto_engine.h:53
wickr_transport_callbacks::on_state
wickr_transport_state_change_func on_state
Definition: transport_ctx.h:87
wickr_transport_callbacks::rx
wickr_transport_rx_func rx
Definition: transport_ctx.h:86
wickr_transport_ctx_get_local_identity_ptr
const wickr_identity_chain_t * wickr_transport_ctx_get_local_identity_ptr(const wickr_transport_ctx_t *ctx)
wickr_transport_ctx_copy
wickr_transport_ctx_t * wickr_transport_ctx_copy(const wickr_transport_ctx_t *ctx)
wickr_transport_callbacks::tx
wickr_transport_tx_func tx
Definition: transport_ctx.h:85
wickr_transport_ctx_process_rx_buffer
void wickr_transport_ctx_process_rx_buffer(wickr_transport_ctx_t *ctx, const wickr_buffer_t *buffer)
wickr_transport_ctx_get_user_ctx
const void * wickr_transport_ctx_get_user_ctx(const wickr_transport_ctx_t *ctx)
wickr_transport_ctx_create
wickr_transport_ctx_t * wickr_transport_ctx_create(const wickr_crypto_engine_t engine, wickr_identity_chain_t *local_identity, wickr_identity_chain_t *remote_identity, uint32_t evo_count, wickr_transport_callbacks_t callbacks, void *user)
wickr_transport_error
wickr_transport_error
Definition: transport_error.h:59
wickr_transport_callbacks
callbacks to notify the user of events within the transport
Definition: transport_ctx.h:84
wickr_transport_callbacks::on_identity_verify
wickr_transport_validate_identity_func on_identity_verify
Definition: transport_ctx.h:88
wickr_transport_ctx_destroy
void wickr_transport_ctx_destroy(wickr_transport_ctx_t **ctx)
wickr_transport_ctx_get_status
wickr_transport_status wickr_transport_ctx_get_status(const wickr_transport_ctx_t *ctx)
wickr_buffer
Represents an array of bytes and the length of the allocation associated with those bytes.
Definition: buffer.h:51
wickr_transport_ctx_get_remote_identity_ptr
const wickr_identity_chain_t * wickr_transport_ctx_get_remote_identity_ptr(const wickr_transport_ctx_t *ctx)
wickr_transport_ctx_start
void wickr_transport_ctx_start(wickr_transport_ctx_t *ctx)
wickr_transport_ctx
Transport context to manage the state machine of a point to point connection using fundamentals of th...
wickr_transport_ctx_set_user_ctx
void wickr_transport_ctx_set_user_ctx(wickr_transport_ctx_t *ctx, void *user)