Amazon Kinesis Webrtc C SDK
 
Loading...
Searching...
No Matches
Tls.h
Go to the documentation of this file.
1#ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_CRYPTO_TLS__
2#define __KINESIS_VIDEO_WEBRTC_CLIENT_CRYPTO_TLS__
3
4#pragma once
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef enum {
11 TLS_SESSION_STATE_NEW, /* Tls is just created, but the handshake process has not started */
12 TLS_SESSION_STATE_CONNECTING, /* TLS is in the process of negotiating a secure connection and verifying the remote fingerprint. */
13 TLS_SESSION_STATE_CONNECTED, /* TLS has completed negotiation of a secure connection and verified the remote fingerprint. */
14 TLS_SESSION_STATE_CLOSED, /* The transport has been closed intentionally as the result of receipt of a close_notify alert */
16
17/* Callback that is fired when Tls session wishes to send packet */
18typedef STATUS (*TlsSessionOutboundPacketFunc)(UINT64, PBYTE, UINT32);
19
20/* Callback that is fired when Tls state has changed */
22
23typedef struct {
25 // outBoundPacketFn is a required callback to tell TlsSession how to send outbound packets
27 // stateChangeFn is an optional callback to listen to TlsSession state changes
31
36
37#ifdef KVS_USE_OPENSSL
38 SSL_CTX* pSslCtx;
39 SSL* pSsl;
40#elif KVS_USE_MBEDTLS
41 IOBuffer* pReadBuffer;
42
43 mbedtls_ssl_context sslCtx;
44 mbedtls_ssl_config sslCtxConfig;
45#if MBEDTLS_VERSION_MAJOR < 4
46 mbedtls_entropy_context entropy;
47 mbedtls_ctr_drbg_context ctrDrbg;
48#endif
49 mbedtls_x509_crt cacert;
50#else
51#error "A Crypto implementation is required."
52#endif
53};
54
64
71
81STATUS tlsSessionStartWithHostname(PTlsSession, BOOL, PCHAR);
82
90STATUS tlsSessionStart(PTlsSession, BOOL);
91
101STATUS tlsSessionProcessPacket(PTlsSession, PBYTE, UINT32, PUINT32);
102
111STATUS tlsSessionPutApplicationData(PTlsSession, PBYTE, UINT32);
112
118
119/* internal functions */
121
122#ifdef KVS_USE_OPENSSL
123INT32 tlsSessionCertificateVerifyCallback(INT32, X509_STORE_CTX*);
124#elif KVS_USE_MBEDTLS
125/* mbedTLS 3.0 introduced <mbedtls/build_info.h>; 2.x ships only <mbedtls/version.h>.
126 * Nested guard: old preprocessors (GCC < 5) parse the whole #if line even when
127 * defined(__has_include) is false, so __has_include(...) must not appear on the
128 * same line as the defined() check. */
129#ifdef __has_include
130#if __has_include(<mbedtls/build_info.h>)
131#include <mbedtls/build_info.h>
132#else
133#include <mbedtls/version.h>
134#endif
135#else
136#include <mbedtls/version.h>
137#endif
138#if defined(MBEDTLS_VERSION_NUMBER)
139#define MBEDTLS_BEFORE_V3 (MBEDTLS_VERSION_NUMBER < 0x03000000)
140#define MBEDTLS_V4_OR_LATER (MBEDTLS_VERSION_MAJOR >= 4)
141#else
142#define MBEDTLS_BEFORE_V3 (1) /* default to before v3 */
143#define MBEDTLS_V4_OR_LATER (0)
144#endif
145// following are required callbacks for mbedtls
146// NOTE: const is not a pure C qualifier, they're here because there's no way to type cast
147// a callback signature.
148INT32 tlsSessionSendCallback(PVOID, const unsigned char*, ULONG);
149INT32 tlsSessionReceiveCallback(PVOID, unsigned char*, ULONG);
150
151#else
152#error "A Crypto implementation is required."
153#endif
154
155#ifdef __cplusplus
156}
157#endif
158#endif //__KINESIS_VIDEO_WEBRTC_CLIENT_CRYPTO_TLS__
struct __TlsSession * PTlsSession
Definition Tls.h:32
STATUS tlsSessionStart(PTlsSession, BOOL)
Definition Tls_mbedtls.c:196
struct TlsSessionCallbacks * PTlsSessionCallbacks
STATUS createTlsSession(PTlsSessionCallbacks, PTlsSession *)
Definition Tls_mbedtls.c:38
TLS_SESSION_STATE
Definition Tls.h:10
@ TLS_SESSION_STATE_CONNECTING
Definition Tls.h:12
@ TLS_SESSION_STATE_CLOSED
Definition Tls.h:14
@ TLS_SESSION_STATE_NEW
Definition Tls.h:11
@ TLS_SESSION_STATE_CONNECTED
Definition Tls.h:13
STATUS freeTlsSession(PTlsSession *)
Definition Tls_mbedtls.c:81
STATUS(* TlsSessionOutboundPacketFunc)(UINT64, PBYTE, UINT32)
Definition Tls.h:18
STATUS tlsSessionShutdown(PTlsSession)
Definition Tls_mbedtls.c:291
STATUS tlsSessionStartWithHostname(PTlsSession, BOOL, PCHAR)
Definition Tls_mbedtls.c:142
STATUS tlsSessionProcessPacket(PTlsSession, PBYTE, UINT32, PUINT32)
Definition Tls_mbedtls.c:201
VOID(* TlsSessionOnStateChange)(UINT64, TLS_SESSION_STATE)
Definition Tls.h:21
STATUS tlsSessionPutApplicationData(PTlsSession, PBYTE, UINT32)
Definition Tls_mbedtls.c:262
STATUS tlsSessionChangeState(PTlsSession, TLS_SESSION_STATE)
Definition Tls.c:4
INT32 tlsSessionSendCallback(PVOID customData, const unsigned char *buf, ULONG len)
Definition Tls_mbedtls.c:108
INT32 tlsSessionReceiveCallback(PVOID customData, unsigned char *buf, ULONG len)
Definition Tls_mbedtls.c:122
INT32 tlsSessionCertificateVerifyCallback(INT32 preverify_ok, X509_STORE_CTX *ctx)
Definition Tls_openssl.c:62
Definition Tls.h:23
UINT64 stateChangeFnCustomData
Definition Tls.h:28
UINT64 outBoundPacketFnCustomData
Definition Tls.h:24
TlsSessionOnStateChange stateChangeFn
Definition Tls.h:29
TlsSessionOutboundPacketFunc outboundPacketFn
Definition Tls.h:26
Definition IOBuffer.h:11
Definition Tls.h:33
TLS_SESSION_STATE state
Definition Tls.h:35
TlsSessionCallbacks callbacks
Definition Tls.h:34