Skip to content

Commit a32f865

Browse files
committed
New TLS implementation
Implement TLS to mqtt server thanks to WiFiClientSecure class
1 parent dc43fc3 commit a32f865

File tree

1 file changed

+56
-18
lines changed

1 file changed

+56
-18
lines changed

MyConfig.h

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,29 +1548,64 @@
15481548
//#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
15491549

15501550
/**
1551-
* @def MY_MQTT_CA_CERT
1552-
* @brief Set a specific CA certificate needed to validate MQTT server against. Use the certificate as a trust anchor, accepting remote certificates signed by it.
1551+
* @def MY_SSL_CERT_AUTHx
1552+
* @brief Up to three root Certificates Authorities could be defined to validate the mqtt server' certificate. The most secure.
1553+
*
1554+
* This define is mandatory when you need connect MQTT over SSL/TLS. Certificate Authorities.
1555+
* The best method to validate server certificates.
1556+
* Advised to retrieve root Certificate Authorities as they expire less often than server certificates.
1557+
* With let's encrypt you may need up to three Certificate Authorities
15531558
*
1554-
* This define is mandatory when you need connect MQTT over SSL/TLS.
15551559
* Example: @code
15561560
*
1557-
* const char mqtt_ca_cert[] PROGMEM = R"EOF(
1561+
* const char cert_isrgrootx1_Authority[] PROGMEM = R"EOF(
1562+
* ----- BEGIN THE CERTIFICATE -----
1563+
* XXX ... XXX
1564+
* ----- FINISH CERTIFICATE -----
1565+
* )EOF";
1566+
*
1567+
* const char cert_isrgrootx2_Authority[] PROGMEM = R"EOF(
15581568
* ----- BEGIN THE CERTIFICATE -----
15591569
* XXX ... XXX
15601570
* ----- FINISH CERTIFICATE -----
15611571
* )EOF";
15621572
*
1563-
* #define MY_MQTT_CA_CERT mqtt_ca_cert
1573+
* const char cert_letsEncryptR3_Authority[] PROGMEM = R"EOF(
1574+
* ----- BEGIN THE CERTIFICATE -----
1575+
* XXX ... XXX
1576+
* ----- FINISH CERTIFICATE -----
1577+
* )EOF";
15641578
*
1579+
* #define MY_SSL_CERT_AUTH1 cert_isrgrootx1_Authority
1580+
* #define MY_SSL_CERT_AUTH1 cert_isrgrootx2_Authority
1581+
* #define MY_SSL_CERT_AUTH1 cert_letsEncryptR3_Authority
1582+
*
1583+
* @endcode
1584+
*/
1585+
//#define MY_SSL_CERT_AUTH1
1586+
1587+
/**
1588+
* @def MY_SSL_FINGERPRINT
1589+
* @brief Server certificate validation with its fingerprint
1590+
*
1591+
* The finger print to validate the mqtt server certificate. This is less secure and less convenient
1592+
* than using certificate authorities.
1593+
* Command (3 lines...) to obtain the certificate finger print:
1594+
* $>openssl s_client -connect <hostname>:<host port> < /dev/null 2>/dev/null | \
1595+
* openssl x509 -fingerprint -noout -in /dev/stdin \
1596+
* awk -F= '{print $2}'
1597+
*
1598+
* Example: @code
1599+
* const char mqtt_fingerprint [] PROGMEM = "CA:CE:2B:ED:D3:32:A7:F1:8C:73:9E:9B:B7:D5:75:4A:10:61:E4:05";
15651600
* @endcode
15661601
*/
1567-
//#define MY_MQTT_CA_CERT
1602+
//#define MY_SSL_FINGERPRINT
15681603

15691604
/**
1570-
* @def MY_MQTT_CLIENT_CERT
1605+
* @def MY_SSL_CERT_CLIENT
15711606
* @brief Set a client certificate to send to a MQTT server that requests one over TLS connection.
15721607
*
1573-
* This define is mandatory when you need connect MQTT over SSL/TLS.
1608+
* This define is mandatory when you need connect MQTT over SSL/TLS and client certificate is requested.
15741609
* Example: @code
15751610
*
15761611
* const char mqtt_client_cert[] PROGMEM = R"EOF(
@@ -1579,17 +1614,17 @@
15791614
* ----- FINISH CERTIFICATE -----
15801615
* )EOF";
15811616
*
1582-
* #define MY_MQTT_CLIENT_CERT mqtt_client_cert
1617+
* #define MY_SSL_CERT_CLIENT mqtt_client_cert
15831618
*
15841619
* @endcode
15851620
*/
1586-
//#define MY_MQTT_CLIENT_CERT
1621+
//#define MY_SSL_CERT_CLIENT
15871622

15881623
/**
1589-
* @def MY_MQTT_CLIENT_KEY
1590-
* @brief Set a client private key to send to a MQTT server that requests one over TLS connection.
1624+
* @def MY_SSL_KEY_CLIENT
1625+
* @brief Set the client private key generated with the MY_SSL_CERT_CLIENT.
15911626
*
1592-
* This define is mandatory when you need connect MQTT over SSL/TLS.
1627+
* This define is mandatory when you need connect MQTT over SSL/TLS and client certificate is requested.
15931628
* Example: @code
15941629
*
15951630
* const char mqtt_client_key[] PROGMEM = R"EOF(
@@ -1598,11 +1633,11 @@
15981633
* ----- FINISH THE RSA PRIVATE KEY -----
15991634
* )EOF";
16001635
*
1601-
* #define MY_MQTT_CLIENT_KEY mqtt_client_key
1636+
* #define MY_SSL_KEY_CLIENT mqtt_client_key
16021637
*
16031638
* @endcode
16041639
*/
1605-
//#define MY_MQTT_CLIENT_KEY
1640+
//#define MY_SSL_KEY_CLIENT
16061641

16071642
/**
16081643
* @def MY_IP_ADDRESS
@@ -2373,9 +2408,12 @@
23732408
#define MY_MQTT_CLIENT_ID
23742409
#define MY_MQTT_PUBLISH_TOPIC_PREFIX
23752410
#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX
2376-
#define MY_MQTT_CA_CERT
2377-
#define MY_MQTT_CLIENT_CERT
2378-
#define MY_MQTT_CLIENT_KEY
2411+
#define MY_SSL_CERT_AUTH1
2412+
#define MY_SSL_CERT_AUTH2
2413+
#define MY_SSL_CERT_AUTH3
2414+
#define MY_SSL_FINGERPRINT
2415+
#define MY_SSL_CERT_CLIENT
2416+
#define MY_SSL_KEY_CLIENT
23792417
#define MY_SIGNAL_REPORT_ENABLED
23802418
// general
23812419
#define MY_WITH_LEDS_BLINKING_INVERSE

0 commit comments

Comments
 (0)