Closed spuder closed 4 weeks ago
This appears to not be a problem when using the beta channel.
for reference, here is esphome config to talk to a Bambu Labs 3d printer which uses leaf certificates that omit hostname
mqtt:
broker: ${bambu_ip}
port: 8883
username: bblp
password: $bambu_access_code
client_id: ${name}
discover_ip: false
discovery: false
discovery_retain: false
discovery_prefix:
use_abbreviations: false
topic_prefix:
log_topic:
birth_message:
topic: # Dont post update to MQTT
payload: # Dont post update to MQTT
will_message:
topic: # Dont post update to MQTT
payload: # Dont post update to MQTT
# keepalive: 15s
# idf_send_async: true
skip_cert_cn_check: true
certificate_authority: |
-----BEGIN CERTIFICATE-----
MIIDZTCCAk2gAwIBAgIUV1FckwXElyek1onFnQ9kL7Bk4N8wDQYJKoZIhvcNAQEL
BQAwQjELMAkGA1UEBhMCQ04xIjAgBgNVBAoMGUJCTCBUZWNobm9sb2dpZXMgQ28u
LCBMdGQxDzANBgNVBAMMBkJCTCBDQTAeFw0yMjA0MDQwMzQyMTFaFw0zMjA0MDEw
MzQyMTFaMEIxCzAJBgNVBAYTAkNOMSIwIAYDVQQKDBlCQkwgVGVjaG5vbG9naWVz
IENvLiwgTHRkMQ8wDQYDVQQDDAZCQkwgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQDL3pnDdxGOk5Z6vugiT4dpM0ju+3Xatxz09UY7mbj4tkIdby4H
oeEdiYSZjc5LJngJuCHwtEbBJt1BriRdSVrF6M9D2UaBDyamEo0dxwSaVxZiDVWC
eeCPdELpFZdEhSNTaT4O7zgvcnFsfHMa/0vMAkvE7i0qp3mjEzYLfz60axcDoJLk
p7n6xKXI+cJbA4IlToFjpSldPmC+ynOo7YAOsXt7AYKY6Glz0BwUVzSJxU+/+VFy
/QrmYGNwlrQtdREHeRi0SNK32x1+bOndfJP0sojuIrDjKsdCLye5CSZIvqnbowwW
1jRwZgTBR29Zp2nzCoxJYcU9TSQp/4KZuWNVAgMBAAGjUzBRMB0GA1UdDgQWBBSP
NEJo3GdOj8QinsV8SeWr3US+HjAfBgNVHSMEGDAWgBSPNEJo3GdOj8QinsV8SeWr
3US+HjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQABlBIT5ZeG
fgcK1LOh1CN9sTzxMCLbtTPFF1NGGA13mApu6j1h5YELbSKcUqfXzMnVeAb06Htu
3CoCoe+wj7LONTFO++vBm2/if6Jt/DUw1CAEcNyqeh6ES0NX8LJRVSe0qdTxPJuA
BdOoo96iX89rRPoxeed1cpq5hZwbeka3+CJGV76itWp35Up5rmmUqrlyQOr/Wax6
itosIzG0MfhgUzU51A2P/hSnD3NDMXv+wUY/AvqgIL7u7fbDKnku1GzEKIkfH8hm
Rs6d8SCU89xyrwzQ0PR853irHas3WrHVqab3P+qNwR0YirL0Qk7Xt/q3O1griNg2
Blbjg3obpHo9
-----END CERTIFICATE-----
# clean_session: true
The problem
esphome is unable to connect to MQTT servers that have self signed (leaf/end entity) certs that include only a portion of the distinguished name (as is common on BambuLabs 3d printers).
The certs can be viewed with openssl
✅ Connection successful
❌ Connection fails
If you have a BambuLabs printer, you can also reproduce yourself by connecting to port 8883 of your printer. Observe that the leaf certificate provides only CN for the distinguished name
Which version of ESPHome has the issue?
2024.9.2
What type of installation are you using?
Docker
Which version of Home Assistant has the issue?
NA
What platform are you using?
ESP32-IDF
Board
wemos d1 mini S2
Component causing the issue
mqtt
Example YAML snippet
esphome config
```yaml esp32: board: lolin_s2_mini variant: esp32s2 framework: type: esp-idf mqtt: broker: 192.168.81.145 # IP address of workstation where docker is running port: 9993 client_id: ${name} username: bblp password: 12345678 log_topic: discover_ip: false discovery: false discovery_retain: false discovery_prefix: use_abbreviations: false topic_prefix: testtopic/1234 birth_message: topic: # Dont post update to MQTT payload: # Dont post update to MQTT will_message: topic: # Dont post update to MQTT payload: # Dont post update to MQTT skip_cert_cn_check: true certificate_authority: | -----BEGIN CERTIFICATE----- MIIDGTCCAgGgAwIBAgIBATANBgkqhkiG9w0BAQsFADBCMQswCQYDVQQG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jLApoz2XYg6kZbI4Ja+KnNu0AlYjhwKZrs3XszwCnkrj+zVxog Af1z4aUP7/PC -----END CERTIFICATE----- ```I've created a docker compose that can reproduce this problem. The docker container includes 3 mqtt servers running on localhost with various certs. The mqtt broker listening on port 8883 works correctly, however the mqtt broker listening on port 9993 reproduces the error.
Steps to reproduce
0x8004
Expected outcome
esp32 should be able to connect to servers regardless of what the distinguised name is
Actual outcome
esp32 is unable to connect to mqtt broker and produces the following logs
Logs
``` [13:39:21][V][esp-idf:000][mqtt_task]: E (2980149) esp-tls: [sock=57] delayed connect error: Connection reset by peer [13:39:21] [13:39:21][V][esp-idf:000][mqtt_task]: E (2980151) esp-tls: Failed to open new connection [13:39:21] [13:39:21][V][esp-idf:000][mqtt_task]: E (2980154) TRANSPORT_BASE: Failed to open a new connection [13:39:21] [13:39:21][V][esp-idf:000][mqtt_task]: E (2980156) MQTT_CLIENT: Error transport connect [13:39:21] [13:39:21][V][mqtt.idf:121]: Event dispatched from event loop event_id=0 [13:39:21][E][mqtt.idf:162]: MQTT_EVENT_ERROR [13:39:21][E][mqtt.idf:164]: Last error code reported from esp-tls: 0x8004 [13:39:21][E][mqtt.idf:165]: Last tls stack error number: 0x0 [13:39:21][E][mqtt.idf:167]: Last captured errno : 104 (Connection reset by peer) [13:39:21][V][mqtt.idf:121]: Event dispatched from event loop event_id=2 [13:39:21][V][mqtt.idf:133]: MQTT_EVENT_DISCONNECTED [13:39:21][W][mqtt:333]: MQTT Disconnected: TCP disconnected. [13:39:21][I][mqtt:244]: Connecting to MQTT... ```Anything in the logs that might be useful for us?
The actual commands used to generate the SSL certs are located in
certs/generate_certs.sh
of the sample git repo.Ignore the fact that one was created using a CSR and the other was created by signing the leaf cert directly. The key line is the following
-subj "/C=US/ST=State/L=City/O=Example/CN=example.com"
vs-subj "/CN=testprinter1"
Valid Cert
Rejected Cert
Additional information
The esphome mqtt documentation states:
Theory 1
common_name
https://github.com/espressif/esp-mqtt/blob/master/include/mqtt_client.h#L267-L271Theory 2