1
+ #ifndef ESP_SSLCLIENT_CONST_H
2
+ #define ESP_SSLCLIENT_CONST_H
3
+
4
+ #pragma GCC diagnostic ignored "-Wunused-function"
5
+ #pragma GCC diagnostic ignored "-Wvla"
6
+
7
+ #include "ESP_SSLClient_FS.h"
8
+
9
+ #include <Arduino.h>
10
+ #include <Client.h>
11
+
12
+ #define ESP_SSLCLIENT_VALID_TIMESTAMP 1690979919
13
+
14
+ #ifndef SSLCLIENT_CONNECTION_UPGRADABLE
15
+ #define SSLCLIENT_CONNECTION_UPGRADABLE
16
+ #endif
17
+
18
+ #ifdef ESP_SSLCLIENT_ENABLE_DEBUG
19
+ #if !defined(ESP_SSLCLIENT_DEBUG_PORT )
20
+ #define ESP_SSLCLIENT_DEBUG_PORT Serial
21
+ #endif
22
+ #define ESP_SSLCLIENT_DEBUG_PRINT ESP_SSLCLIENT_DEBUG_PORT.print
23
+ #else
24
+ #define ESP_SSLCLIENT_DEBUG_PRINT (...)
25
+ #endif
26
+
27
+ enum esp_ssl_client_debug_level
28
+ {
29
+ esp_ssl_debug_none = 0 ,
30
+ esp_ssl_debug_error = 1 ,
31
+ esp_ssl_debug_warn = 2 ,
32
+ esp_ssl_debug_info = 3 ,
33
+ esp_ssl_debug_dump = 4
34
+ };
35
+
36
+ enum esp_ssl_client_error_types
37
+ {
38
+ esp_ssl_ok ,
39
+ esp_ssl_connection_fail ,
40
+ esp_ssl_write_error ,
41
+ esp_ssl_read_error ,
42
+ esp_ssl_out_of_memory ,
43
+ esp_ssl_internal_error
44
+ };
45
+
46
+ #if defined(ESP_SSLCLIENT_ENABLE_DEBUG )
47
+
48
+ static void esp_ssl_debug_print_prefix (const char * func_name , int level )
49
+ {
50
+ ESP_SSLCLIENT_DEBUG_PRINT (PSTR ("> " ));
51
+ // print the debug level
52
+ switch (level )
53
+ {
54
+ case esp_ssl_debug_info :
55
+ ESP_SSLCLIENT_DEBUG_PRINT (PSTR ("INFO." ));
56
+ break ;
57
+ case esp_ssl_debug_warn :
58
+ ESP_SSLCLIENT_DEBUG_PRINT (PSTR ("WARN." ));
59
+ break ;
60
+ case esp_ssl_debug_error :
61
+ ESP_SSLCLIENT_DEBUG_PRINT (PSTR ("ERROR." ));
62
+ break ;
63
+ default :
64
+ break ;
65
+ }
66
+
67
+ // print the function name
68
+ ESP_SSLCLIENT_DEBUG_PRINT (PSTR ("" ));
69
+ ESP_SSLCLIENT_DEBUG_PRINT (func_name );
70
+ ESP_SSLCLIENT_DEBUG_PRINT (PSTR (": " ));
71
+ }
72
+
73
+ static void esp_ssl_debug_print (PGM_P msg , int debug_level , int level , const char * func_name )
74
+ {
75
+ if (debug_level >= level )
76
+ {
77
+ esp_ssl_debug_print_prefix (func_name , level );
78
+ ESP_SSLCLIENT_DEBUG_PRINT (msg );
79
+ ESP_SSLCLIENT_DEBUG_PRINT ("\r\n" );
80
+ }
81
+ }
82
+
83
+ #endif
84
+
85
+ static uint8_t htoi (unsigned char c )
86
+ {
87
+ if (c >= '0' && c <= '9' )
88
+ return c - '0' ;
89
+ else if (c >= 'A' && c <= 'F' )
90
+ return 10 + c - 'A' ;
91
+ else if (c >= 'a' && c <= 'f' )
92
+ return 10 + c - 'a' ;
93
+ else
94
+ return 255 ;
95
+ }
96
+
97
+ // Helper function which aborts a TLS handshake by sending TLS
98
+ // ClientAbort and ClientClose messages.
99
+ static bool send_abort (Client * probe , bool supportsLen )
100
+ {
101
+ // If we're still connected, send the appropriate notice that
102
+ // we're aborting the handshake per RFCs.
103
+ static const uint8_t clientAbort_P [] PROGMEM = {
104
+ 0x15 /*alert*/ , 0x03 , 0x03 /*TLS 1.2*/ , 0x00 , 0x02 ,
105
+ 1 , 90 /* warning: user_cancelled */
106
+ };
107
+ static const uint8_t clientClose_P [] PROGMEM = {
108
+ 0x15 /*alert*/ , 0x03 , 0x03 /*TLS 1.2*/ , 0x00 , 0x02 ,
109
+ 1 , 0 /* warning: close_notify */
110
+ };
111
+ if (probe -> connected ())
112
+ {
113
+ uint8_t msg [sizeof (clientAbort_P )];
114
+ memcpy_P (msg , clientAbort_P , sizeof (clientAbort_P ));
115
+ probe -> write (msg , sizeof (clientAbort_P ));
116
+ memcpy_P (msg , clientClose_P , sizeof (clientClose_P ));
117
+ probe -> write (msg , sizeof (clientClose_P ));
118
+ }
119
+ return supportsLen ;
120
+ }
121
+
122
+ const uint16_t _secure_ports [26 ] = {443 /* HTTPS */ , 465 /* SMTP */ , 563 /* NNTP */ , 636 /* LDAPS */ , 695 /* IEEE-MMS-SSL */ , 832 /* NETCONF */ , 853 /* DNS */ , 989 /* FTPS */ , 990 /* FTPS */ , 992 /* Telnet */ , 993 /* IMAP */ , 995 /* POP3 */ , 4116 /* Smartcard */ , 4843 /* OPC */ , 5061 /* SIP */ , 5085 /* LLIP */ , 5349 /* NAT */ , 5671 /* AMQP */ , 5986 /* WinRM-HTTPS */ , 6513 /* NETCONF */ , 6514 /* Syslog */ , 6515 /* Elipse RPC */ , 6619 /* OFTP */ , 8243 /* Apache Synapse */ , 8403 /* GxFWD */ , 8883 /* MQTT */ };
123
+
124
+ #endif
0 commit comments