yuezonghe | c78e2ef | 2025-02-13 17:57:46 -0800 | [diff] [blame^] | 1 |
|
| 2 | #ifndef MQTT_DTLS_H
|
| 3 | #define MQTT_DTLS_H
|
| 4 |
|
| 5 |
|
| 6 | #include "mbedtls/net.h"
|
| 7 | #include "mbedtls/ssl.h"
|
| 8 | #include "mbedtls/certs.h"
|
| 9 | #include "mbedtls/entropy.h"
|
| 10 | #include "mbedtls/ctr_drbg.h"
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 | #define MQTT_MAX_TIMEOUT (10 * 60) //10 min
|
| 16 |
|
| 17 |
|
| 18 | typedef struct mqttsClientSslTag
|
| 19 | {
|
| 20 | mbedtls_ssl_context sslContext;
|
| 21 | mbedtls_net_context netContext;
|
| 22 | mbedtls_ssl_config sslConfig;
|
| 23 | mbedtls_entropy_context entropyContext;
|
| 24 | mbedtls_ctr_drbg_context ctrDrbgContext;
|
| 25 | mbedtls_x509_crt_profile crtProfile;
|
| 26 | mbedtls_x509_crt caCert;
|
| 27 | mbedtls_x509_crt clientCert;
|
| 28 | mbedtls_pk_context pkContext;
|
| 29 | }mqttsClientSsl;
|
| 30 |
|
| 31 | typedef struct mqttsClientContextTag
|
| 32 | {
|
| 33 | int socket;
|
| 34 | int timeout_s;
|
| 35 | int timeout_r;
|
| 36 | int isMqtts;
|
| 37 | int method;
|
| 38 | uint16_t port;
|
| 39 | unsigned int keepAliveInterval;
|
| 40 | size_t sendBufSize;
|
| 41 | size_t readBufSize;
|
| 42 | unsigned char *sendBuf;
|
| 43 | unsigned char *readBuf;
|
| 44 |
|
| 45 | mqttsClientSsl * ssl;
|
| 46 | char *caCert;
|
| 47 | char *clientCert;
|
| 48 | char *clientPk;
|
| 49 | char *hostName;
|
| 50 | char *psk_key;
|
| 51 | char *psk_identity;
|
| 52 | int caCertLen;
|
| 53 | int clientCertLen;
|
| 54 | int clientPkLen;
|
| 55 | uint8_t seclevel;//0:no verify; 1:verify server; 2:both verify
|
| 56 | int32_t ciphersuite[2];//just like 0x0035 TLS_RSA_WITH_AES_256_CBC_SHA,ciphersuite[1] must NULL
|
| 57 | uint8_t pdpId;//pdp context id--cid--0 is default
|
| 58 |
|
| 59 | }mqttsClientContext;
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 | int mqttSslConn_old(mqttsClientContext* context, char* host);
|
| 64 | int mqttSslSend(mqttsClientContext* context, unsigned char* buf, int len);
|
| 65 | int mqttSslRecv(mqttsClientContext* context, unsigned char* buf, int minLen, int maxLen, int* pReadLen);
|
| 66 | int mqttSslRead(mqttsClientContext* context, unsigned char *buffer, int len, int timeout_ms);
|
| 67 | int mqttSslClose(mqttsClientContext* context);
|
| 68 | int mqttSslConn_new(mqttsClientContext* context, char* host);
|
| 69 |
|
| 70 | #endif
|
| 71 |
|