esp-open-rtos/examples/aws_iot/ssl_connection.h
rongsaws 7041c014bb Added a MQTT pub/sub example of using AWS IoT (#173)
* Added a MQTT pub/sub example of using AWS IoT (via ECC based TLS1.2 connection).

* Fixed a buffer overflow issue when receiving large MQTT packet.

* Reset TLS connection on read/write errors.
2016-08-29 19:55:32 +02:00

40 lines
1.1 KiB
C

#ifndef _SSL_CONNECTION_H_
#define _SSL_CONNECTION_H_
// this must be ahead of any mbedtls header files so the local mbedtls/config.h can be properly referenced
#include "mbedtls/config.h"
#include "mbedtls/net.h"
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/certs.h"
typedef struct SSLConnection {
mbedtls_net_context net_ctx;
mbedtls_ssl_context ssl_ctx;
mbedtls_ssl_config ssl_conf;
mbedtls_ctr_drbg_context drbg_ctx;
mbedtls_entropy_context entropy_ctx;
mbedtls_x509_crt ca_cert;
mbedtls_x509_crt client_cert;
mbedtls_pk_context client_key;
char *ca_cert_str;
char *client_cert_str;
char *client_key_str;
} SSLConnection;
extern void ssl_init(SSLConnection* n);
extern int ssl_connect(SSLConnection* n, const char* host, int port);
extern int ssl_destroy(SSLConnection* n);
extern int ssl_read(SSLConnection* n, unsigned char* buffer, int len,
int timeout_ms);
extern int ssl_write(SSLConnection* n, unsigned char* buffer, int len,
int timeout_ms);
#endif /* _SSL_CONNECTION_H_ */