Hi everyone,
I’m trying to establish a secure connection between an AWS MQTT endpoint and a ESP32 device, but the handshake fails.
A two way handshake is performed, with a CA bundle (for Trust Chain). Server hello gets done but the handshake fails in either client state 7 or 8, when the client presents its certificate.
We are using an ECC 384 key for the client and an ECC 521 key for the server. We haven’t had issues using RSA keys.
Other MQTT clients (with other TLS libraries) don’t have problems with ECC using the same certificates.
This is the log from the device (client):
I (40608) mbedtls: ssl_tls.c:8021 => handshake
I (40609) mbedtls: ssl_cli.c:3405 client state: 0
I (40609) mbedtls: ssl_tls.c:2751 => flush output
I (40614) mbedtls: ssl_tls.c:2763 <= flush output
I (40619) mbedtls: ssl_cli.c:3405 client state: 1
I (40625) mbedtls: ssl_tls.c:2751 => flush output
I (40630) mbedtls: ssl_tls.c:2763 <= flush output
I (40636) mbedtls: ssl_cli.c:774 => write client hello
D (40642) mbedtls: ssl_cli.c:812 client hello, max version: [3:3]
D (40648) mbedtls: ssl_cli.c:703 client hello, current time: 35
D (40655) mbedtls: ssl_cli.c:821 dumping 'client hello, random bytes' (32 bytes)
D (40662) mbedtls: ssl_cli.c:821 0000: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (40671) mbedtls: ssl_cli.c:821 0010: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (40681) mbedtls: ssl_cli.c:874 client hello, session id len.: 0
D (40687) mbedtls: ssl_cli.c:875 dumping 'client hello, session id' (0 bytes)
D (40695) mbedtls: ssl_cli.c:922 client hello, add ciphersuite: c02c
D (40701) mbedtls: ssl_cli.c:922 client hello, add ciphersuite: c030
.......
D (40996) mbedtls: ssl_cli.c:922 client hello, add ciphersuite: c004
D (41003) mbedtls: ssl_cli.c:922 client hello, add ciphersuite: c0a0
D (41009) mbedtls: ssl_cli.c:934 client hello, got 48 ciphersuites (excluding SCSVs)
D (41017) mbedtls: ssl_cli.c:943 adding EMPTY_RENEGOTIATION_INFO_SCSV
D (41024) mbedtls: ssl_cli.c:992 client hello, compress len.: 1
D (41030) mbedtls: ssl_cli.c:994 client hello, compress alg.: 0
D (41036) mbedtls: ssl_cli.c:69 client hello, adding server name extension: xxx.xxxx.xxx
D (41045) mbedtls: ssl_cli.c:186 client hello, adding signature_algorithms extension
D (41053) mbedtls: ssl_cli.c:271 client hello, adding supported_elliptic_curves extension
D (41061) mbedtls: ssl_cli.c:336 client hello, adding supported_point_formats extension
D (41069) mbedtls: ssl_cli.c:518 client hello, adding encrypt_then_mac extension
D (41077) mbedtls: ssl_cli.c:552 client hello, adding extended_master_secret extension
D (41085) mbedtls: ssl_cli.c:585 client hello, adding session ticket extension
D (41092) mbedtls: ssl_cli.c:1071 client hello, total extension length: 95
I (41099) mbedtls: ssl_tls.c:3180 => write handshake message
I (41108) mbedtls: ssl_tls.c:3337 => write record
D (41111) mbedtls: ssl_tls.c:3417 output record: msgtype = 22, version = [3:1], msglen = 238
I (41284) mbedtls: ssl_tls.c:2751 => flush output
I (41290) mbedtls: ssl_tls.c:2770 message length: 243, out_left: 243
I (41299) mbedtls: ssl_tls.c:2775 ssl->f_send() returned 243 (-0xffffff0d)
I (41305) mbedtls: ssl_tls.c:2803 <= flush output
I (41310) mbedtls: ssl_tls.c:3470 <= write record
I (41316) mbedtls: ssl_tls.c:3314 <= write handshake message
I (41322) mbedtls: ssl_cli.c:1106 <= write client hello
I (41328) mbedtls: ssl_cli.c:3405 client state: 2
I (41334) mbedtls: ssl_tls.c:2751 => flush output
I (41339) mbedtls: ssl_tls.c:2763 <= flush output
I (41345) mbedtls: ssl_cli.c:1499 => parse server hello
I (41351) mbedtls: ssl_tls.c:4305 => read record
I (41356) mbedtls: ssl_tls.c:2532 => fetch input
I (41362) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (43700) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (43701) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (43704) mbedtls: ssl_tls.c:2738 <= fetch input
D (43725) mbedtls: ssl_tls.c:4050 input record: msgtype = 22, version = [3:3], msglen = 87
I (43734) mbedtls: ssl_tls.c:2532 => fetch input
I (43739) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 92
I (43746) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 92
I (43752) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 87 (-0xffffffa9)
I (43760) mbedtls: ssl_tls.c:2738 <= fetch input
D (43832) mbedtls: ssl_tls.c:3620 handshake message: msglen = 87, type = 2, hslen = 87
I (43842) mbedtls: ssl_tls.c:4379 <= read record
D (43846) mbedtls: ssl_cli.c:1579 dumping 'server hello, version' (2 bytes)
D (43853) mbedtls: ssl_cli.c:1579 0000: 03 03 ..
D (43861) mbedtls: ssl_cli.c:1604 server hello, current time: 1571763635
D (43868) mbedtls: ssl_cli.c:1610 dumping 'server hello, random bytes' (32 bytes)
D (43876) mbedtls: ssl_cli.c:1610 0000: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (43886) mbedtls: ssl_cli.c:1610 0010: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (43895) mbedtls: ssl_cli.c:1690 server hello, session id len.: 32
D (43902) mbedtls: ssl_cli.c:1691 dumping 'server hello, session id' (32 bytes)
D (43909) mbedtls: ssl_cli.c:1691 0000: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (43919) mbedtls: ssl_cli.c:1691 0010: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (43929) mbedtls: ssl_cli.c:1729 no session has been resumed
D (43935) mbedtls: ssl_cli.c:1731 server hello, chosen ciphersuite: c02c
D (43942) mbedtls: ssl_cli.c:1732 server hello, compress alg.: 0
D (43948) mbedtls: ssl_cli.c:1764 server hello, chosen ciphersuite: TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384
I (43958) mbedtls: ssl_cli.c:1781 server hello, total extension length: 11
D (43966) mbedtls: ssl_cli.c:1880 found supported_point_formats extension
V (43973) mbedtls: ssl_cli.c:1292 point format selected: 0
D (43978) mbedtls: ssl_cli.c:1801 found renegotiation extension
I (43984) mbedtls: ssl_cli.c:1970 <= parse server hello
I (43991) mbedtls: ssl_cli.c:3405 client state: 3
I (43996) mbedtls: ssl_tls.c:2751 => flush output
I (44002) mbedtls: ssl_tls.c:2763 <= flush output
I (44007) mbedtls: ssl_tls.c:5440 => parse certificate
I (44013) mbedtls: ssl_tls.c:4305 => read record
I (44018) mbedtls: ssl_tls.c:2532 => fetch input
I (44024) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (44030) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (44036) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (44044) mbedtls: ssl_tls.c:2738 <= fetch input
D (44066) mbedtls: ssl_tls.c:4050 input record: msgtype = 22, version = [3:3], msglen = 3054
I (44074) mbedtls: ssl_tls.c:2532 => fetch input
I (44080) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 3059
I (44087) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 3059
I (44093) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 1323 (-0xfffffad5)
I (44811) mbedtls: ssl_tls.c:2717 in_left: 1328, nb_want: 3059
I (44812) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 1420 (-0xfffffa74)
I (46611) mbedtls: ssl_tls.c:2717 in_left: 2748, nb_want: 3059
I (46612) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 311 (-0xfffffec9)
I (46616) mbedtls: ssl_tls.c:2738 <= fetch input
D (48516) mbedtls: ssl_tls.c:3620 handshake message: msglen = 3054, type = 11, hslen = 3054
I (48527) mbedtls: ssl_tls.c:4379 <= read record
D (48534) mbedtls: ssl_tls.c:5650 peer certificate #1:
D (48536) mbedtls: ssl_tls.c:5650 cert. version : 3
D (48540) mbedtls: ssl_tls.c:5650 serial number : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48551) mbedtls: ssl_tls.c:5650 issuer name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48568) mbedtls: ssl_tls.c:5650 subject name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48584) mbedtls: ssl_tls.c:5650 issued on : XXXX-XX-XX XX:XX:XX
D (48591) mbedtls: ssl_tls.c:5650 expires on : XXXX-XX-XX XX:XX:XX
D (48598) mbedtls: ssl_tls.c:5650 signed using : ECDSA with SHA256
D (48604) mbedtls: ssl_tls.c:5650 EC key size : 521 bits
D (48610) mbedtls: ssl_tls.c:5650 subject alt name : 1.tcp.ngrok.io
D (48617) mbedtls: ssl_tls.c:5650 key usage : Digital Signature, Key Encipherment, Key Agreement
D (48627) mbedtls: ssl_tls.c:5650 ext key usage : TLS Web Server Authentication
D (48635) mbedtls: ssl_tls.c:5650 value of 'crt->eckey.Q(X)' (520 bits) is:
D (48642) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48650) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48657) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48665) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48673) mbedtls: ssl_tls.c:5650 XX
D (48677) mbedtls: ssl_tls.c:5650 value of 'crt->eckey.Q(Y)' (521 bits) is:
D (48684) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48692) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48699) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48707) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48715) mbedtls: ssl_tls.c:5650 XX XX
D (48719) mbedtls: ssl_tls.c:5650 peer certificate #2:
D (48725) mbedtls: ssl_tls.c:5650 cert. version : 3
D (48730) mbedtls: ssl_tls.c:5650 serial number : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48740) mbedtls: ssl_tls.c:5650 issuer name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48756) mbedtls: ssl_tls.c:5650 subject name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48774) mbedtls: ssl_tls.c:5650 issued on : XXXX-XX-XX XX:XX:XX
D (48781) mbedtls: ssl_tls.c:5650 expires on : XXXX-XX-XX XX:XX:XX
D (48788) mbedtls: ssl_tls.c:5650 signed using : ECDSA with SHA256
D (48795) mbedtls: ssl_tls.c:5650 EC key size : 521 bits
D (48801) mbedtls: ssl_tls.c:5650 basic constraints : CA=true, max_pathlen=1
D (48808) mbedtls: ssl_tls.c:5650 subject alt name :
D (48813) mbedtls: ssl_tls.c:5650 key usage : Key Cert Sign, CRL Sign
D (48821) mbedtls: ssl_tls.c:5650 value of 'crt->eckey.Q(X)' (520 bits) is:
D (48828) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48836) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48843) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48851) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48859) mbedtls: ssl_tls.c:5650 XX
D (48863) mbedtls: ssl_tls.c:5650 value of 'crt->eckey.Q(Y)' (519 bits) is:
D (48870) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48878) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48886) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48893) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (48901) mbedtls: ssl_tls.c:5650 XX
D (48905) mbedtls: ssl_tls.c:5650 peer certificate #3:
D (48911) mbedtls: ssl_tls.c:5650 cert. version : 3
D (48916) mbedtls: ssl_tls.c:5650 serial number : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48926) mbedtls: ssl_tls.c:5650 issuer name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48942) mbedtls: ssl_tls.c:5650 subject name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (48959) mbedtls: ssl_tls.c:5650 issued on : XXXX-XX-XX XX:XX:XX
D (48966) mbedtls: ssl_tls.c:5650 expires on : XXXX-XX-XX XX:XX:XX
D (48973) mbedtls: ssl_tls.c:5650 signed using : ECDSA with SHA256
D (48979) mbedtls: ssl_tls.c:5650 EC key size : 521 bits
D (48985) mbedtls: ssl_tls.c:5650 basic constraints : CA=true, max_pathlen=3
D (48993) mbedtls: ssl_tls.c:5650 subject alt name :
D (48998) mbedtls: ssl_tls.c:5650 key usage : Key Cert Sign, CRL Sign
D (49005) mbedtls: ssl_tls.c:5650 value of 'crt->eckey.Q(X)' (520 bits) is:
D (49013) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49020) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49028) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49036) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49044) mbedtls: ssl_tls.c:5650 XX
D (49048) mbedtls: ssl_tls.c:5650 value of 'crt->eckey.Q(Y)' (521 bits) is:
D (49055) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49062) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49070) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49078) mbedtls: ssl_tls.c:5650 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (49086) mbedtls: ssl_tls.c:5650 XX XX
D (50173) mbedtls: ssl_tls.c:5805 Certificate verification flags clear
I (50174) mbedtls: ssl_tls.c:5810 <= parse certificate
I (50175) mbedtls: ssl_cli.c:3405 client state: 4
I (50181) mbedtls: ssl_tls.c:2751 => flush output
I (50186) mbedtls: ssl_tls.c:2763 <= flush output
I (50192) mbedtls: ssl_cli.c:2317 => parse server key exchange
I (50198) mbedtls: ssl_tls.c:4305 => read record
I (50204) mbedtls: ssl_tls.c:2532 => fetch input
I (50209) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (50216) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (50222) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (50230) mbedtls: ssl_tls.c:2738 <= fetch input
D (50251) mbedtls: ssl_tls.c:4050 input record: msgtype = 22, version = [3:3], msglen = 283
I (50260) mbedtls: ssl_tls.c:2532 => fetch input
I (50265) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 288
I (50272) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 288
I (50278) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 283 (-0xfffffee5)
I (50286) mbedtls: ssl_tls.c:2738 <= fetch input
D (50476) mbedtls: ssl_tls.c:3620 handshake message: msglen = 283, type = 12, hslen = 283
I (50485) mbedtls: ssl_tls.c:4379 <= read record
D (50490) mbedtls: ssl_cli.c:2391 dumping 'server key exchange' (279 bytes)
D (50497) mbedtls: ssl_cli.c:2391 0000: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50507) mbedtls: ssl_cli.c:2391 0010: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50517) mbedtls: ssl_cli.c:2391 0020: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50527) mbedtls: ssl_cli.c:2391 0030: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50537) mbedtls: ssl_cli.c:2391 0040: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50546) mbedtls: ssl_cli.c:2391 0050: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50556) mbedtls: ssl_cli.c:2391 0060: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50566) mbedtls: ssl_cli.c:2391 0070: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50576) mbedtls: ssl_cli.c:2391 0080: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50586) mbedtls: ssl_cli.c:2391 0090: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50596) mbedtls: ssl_cli.c:2391 00a0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50605) mbedtls: ssl_cli.c:2391 00b0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50615) mbedtls: ssl_cli.c:2391 00c0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50625) mbedtls: ssl_cli.c:2391 00d0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50635) mbedtls: ssl_cli.c:2391 00e0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50645) mbedtls: ssl_cli.c:2391 00f0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50655) mbedtls: ssl_cli.c:2391 0100: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50664) mbedtls: ssl_cli.c:2391 0110: XX XX XX XX XX XX XX .......
I (50674) mbedtls: ssl_cli.c:2030 ECDH curve: secp521r1
D (50680) mbedtls: ssl_cli.c:2040 value of 'ECDH: Qp(X)' (521 bits) is:
D (50686) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50694) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50702) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50710) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50717) mbedtls: ssl_cli.c:2040 XX XX
D (50722) mbedtls: ssl_cli.c:2040 value of 'ECDH: Qp(Y)' (521 bits) is:
D (50728) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50736) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50744) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50752) mbedtls: ssl_cli.c:2040 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (50759) mbedtls: ssl_cli.c:2040 99 54
I (50764) mbedtls: ssl_cli.c:2259 Server used SignatureAlgorithm 3
I (50771) mbedtls: ssl_cli.c:2260 Server used HashAlgorithm 6
D (50777) mbedtls: ssl_cli.c:2546 dumping 'signature' (138 bytes)
D (50783) mbedtls: ssl_cli.c:2546 0000: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50793) mbedtls: ssl_cli.c:2546 0010: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50803) mbedtls: ssl_cli.c:2546 0020: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50813) mbedtls: ssl_cli.c:2546 0030: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50823) mbedtls: ssl_cli.c:2546 0040: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50833) mbedtls: ssl_cli.c:2546 0050: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50842) mbedtls: ssl_cli.c:2546 0060: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50852) mbedtls: ssl_cli.c:2546 0070: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50862) mbedtls: ssl_cli.c:2546 0080: XX XX XX XX XX XX XX XX XX XX ..........
D (50872) mbedtls: ssl_cli.c:2582 dumping 'parameters hash' (64 bytes)
D (50878) mbedtls: ssl_cli.c:2582 0000: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50888) mbedtls: ssl_cli.c:2582 0010: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50898) mbedtls: ssl_cli.c:2582 0020: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
D (50908) mbedtls: ssl_cli.c:2582 0030: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ................
I (52011) mbedtls: ssl_cli.c:2617 <= parse server key exchange
I (52012) mbedtls: ssl_cli.c:3405 client state: 5
I (52013) mbedtls: ssl_tls.c:2751 => flush output
I (52018) mbedtls: ssl_tls.c:2763 <= flush output
I (52024) mbedtls: ssl_cli.c:2650 => parse certificate request
I (52030) mbedtls: ssl_tls.c:4305 => read record
I (52036) mbedtls: ssl_tls.c:2532 => fetch input
I (52041) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (52048) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (52053) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (52062) mbedtls: ssl_tls.c:2738 <= fetch input
D (52083) mbedtls: ssl_tls.c:4050 input record: msgtype = 22, version = [3:3], msglen = 983
I (52092) mbedtls: ssl_tls.c:2532 => fetch input
I (52097) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 988
I (52104) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 988
I (52110) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 983 (-0xfffffc29)
I (52118) mbedtls: ssl_tls.c:2738 <= fetch input
D (52741) mbedtls: ssl_tls.c:3620 handshake message: msglen = 983, type = 13, hslen = 983
I (52750) mbedtls: ssl_tls.c:4379 <= read record
D (52754) mbedtls: ssl_cli.c:2677 got a certificate request
D (52760) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 6,3
D (52767) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 6,1
D (52774) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 5,3
D (52781) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 5,1
D (52788) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 4,3
D (52795) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 4,1
D (52803) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 3,3
D (52810) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 3,1
D (52817) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 2,3
D (52824) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 2,1
D (52831) mbedtls: ssl_cli.c:2777 Supported Signature Algorithm found: 2,2
I (52838) mbedtls: ssl_cli.c:2799 <= parse certificate request
I (52845) mbedtls: ssl_cli.c:3405 client state: 6
I (52850) mbedtls: ssl_tls.c:2751 => flush output
I (52856) mbedtls: ssl_tls.c:2763 <= flush output
I (52861) mbedtls: ssl_cli.c:2809 => parse server hello done
I (52868) mbedtls: ssl_tls.c:4305 => read record
I (52873) mbedtls: ssl_tls.c:2532 => fetch input
I (52878) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (52885) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (52891) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (52899) mbedtls: ssl_tls.c:2738 <= fetch input
D (52920) mbedtls: ssl_tls.c:4050 input record: msgtype = 22, version = [3:3], msglen = 4
I (52929) mbedtls: ssl_tls.c:2532 => fetch input
I (52934) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 9
I (52941) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 9
I (52946) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 4 (-0xfffffffc)
I (52955) mbedtls: ssl_tls.c:2738 <= fetch input
D (52977) mbedtls: ssl_tls.c:3620 handshake message: msglen = 4, type = 14, hslen = 4
I (52985) mbedtls: ssl_tls.c:4379 <= read record
I (52990) mbedtls: ssl_cli.c:2839 <= parse server hello done
I (52997) mbedtls: ssl_cli.c:3405 client state: 7
I (53002) mbedtls: ssl_tls.c:2751 => flush output
I (53008) mbedtls: ssl_tls.c:2763 <= flush output
I (53013) mbedtls: ssl_tls.c:5323 => write certificate
D (53019) mbedtls: ssl_tls.c:5375 own certificate #1:
D (53026) mbedtls: ssl_tls.c:5375 cert. version : 3
D (53030) mbedtls: ssl_tls.c:5375 serial number : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (53041) mbedtls: ssl_tls.c:5375 issuer name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (53058) mbedtls: ssl_tls.c:5375 subject name : C=XX, ST=XXXXXXXX, L=XXXXXX, postalCode=XXXXX, O=XXXXX, OU=XX + OU=XXXXXXX + OU=XXXXXXXXX, CN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
D (53075) mbedtls: ssl_tls.c:5375 issued on : XXXX-XX-XX XX:XX:XX
D (53082) mbedtls: ssl_tls.c:5375 expires on : XXXX-XX-XX XX:XX:XX
D (53089) mbedtls: ssl_tls.c:5375 signed using : ECDSA with SHA256
D (53096) mbedtls: ssl_tls.c:5375 EC key size : 384 bits
D (53102) mbedtls: ssl_tls.c:5375 subject alt name :
D (53107) mbedtls: ssl_tls.c:5375 key usage : Digital Signature, Key Encipherment, Key Agreement
D (53117) mbedtls: ssl_tls.c:5375 ext key usage : TLS Web Client Authentication
D (53125) mbedtls: ssl_tls.c:5375 value of 'crt->eckey.Q(X)' (384 bits) is:
D (53132) mbedtls: ssl_tls.c:5375 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (53140) mbedtls: ssl_tls.c:5375 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (53148) mbedtls: ssl_tls.c:5375 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (53155) mbedtls: ssl_tls.c:5375 value of 'crt->eckey.Q(Y)' (380 bits) is:
D (53163) mbedtls: ssl_tls.c:5375 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (53170) mbedtls: ssl_tls.c:5375 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (53178) mbedtls: ssl_tls.c:5375 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
I (53186) mbedtls: ssl_tls.c:3180 => write handshake message
I (53193) mbedtls: ssl_tls.c:3337 => write record
D (53198) mbedtls: ssl_tls.c:3417 output record: msgtype = 22, version = [3:3], msglen = 1065
I (53873) mbedtls: ssl_tls.c:2751 => flush output
I (53879) mbedtls: ssl_tls.c:2770 message length: 1070, out_left: 1070
I (53908) mbedtls: ssl_tls.c:2775 ssl->f_send() returned 1070 (-0xfffffbd2)
I (53909) mbedtls: ssl_tls.c:2803 <= flush output
I (53911) mbedtls: ssl_tls.c:3470 <= write record
I (53916) mbedtls: ssl_tls.c:3314 <= write handshake message
I (53923) mbedtls: ssl_tls.c:5427 <= write certificate
I (53929) mbedtls: ssl_cli.c:3405 client state: 8
I (53934) mbedtls: ssl_tls.c:2751 => flush output
I (53940) mbedtls: ssl_tls.c:2763 <= flush output
I (53945) mbedtls: ssl_cli.c:2851 => write client key exchange
D (54474) mbedtls: ssl_cli.c:2916 value of 'ECDH: Q(X)' (521 bits) is:
D (54475) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54478) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54486) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54494) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54501) mbedtls: ssl_cli.c:2916 XX XX
D (54506) mbedtls: ssl_cli.c:2916 value of 'ECDH: Q(Y)' (521 bits) is:
D (54512) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54520) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54528) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54536) mbedtls: ssl_cli.c:2916 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (54543) mbedtls: ssl_cli.c:2916 XX XX
D (55067) mbedtls: ssl_cli.c:2928 value of 'ECDH: z' (521 bits) is:
D (55068) mbedtls: ssl_cli.c:2928 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (55071) mbedtls: ssl_cli.c:2928 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (55079) mbedtls: ssl_cli.c:2928 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (55086) mbedtls: ssl_cli.c:2928 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
D (55094) mbedtls: ssl_cli.c:2928 XX XX
I (55098) mbedtls: ssl_tls.c:3180 => write handshake message
I (55105) mbedtls: ssl_tls.c:3337 => write record
D (55110) mbedtls: ssl_tls.c:3417 output record: msgtype = 22, version = [3:3], msglen = 138
I (55215) mbedtls: ssl_tls.c:2751 => flush output
I (55221) mbedtls: ssl_tls.c:2770 message length: 143, out_left: 143
I (55229) mbedtls: ssl_tls.c:2775 ssl->f_send() returned -80 (-0x0050)
W (55235) mbedtls: ssl_tls.c:3466 mbedtls_ssl_flush_output() returned -80 (-0x0050)
W (55244) mbedtls: ssl_tls.c:3309 ssl_write_record() returned -80 (-0x0050)
W (55251) mbedtls: ssl_cli.c:3089 mbedtls_ssl_write_handshake_msg() returned -80 (-0x0050)
I (55261) mbedtls: ssl_tls.c:8031 <= handshake
E (55266) esp-tls: mbedtls_ssl_handshake returned -0x50
E (55282) esp-tls: Failed to open new connection
E (55283) TRANS_SSL: Failed to open a new connection
E (55283) MQTT_CLIENT: Error transport connect
E (55288) mqtt_event_handler: Disconnected
Then we have the log from the server:
Acceptable client certificate CA names
C = XX, ST = XXXXXXXX, L = XXXXXX, postalCode = XXXXX, O = XXXXXXXXXXXXX, OU = XX + OU = XXXXXXX + OU = XXXXXXXXX, CN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
C = XX, ST = XXXXXXXX, L = XXXXXX, postalCode = XXXXX, O = XXXXXXXXXXXXX, OU = XX, OU = XXXXXXX, OU = XXXXXXXXX, CN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
C = XX, ST = XXXXXXXX, L = XXXXXX, postalCode = XXXXX, O = XXXXXXXXXXXXX, OU = XX + OU = XXXXXXX + OU = XXXXXXXXX, CN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
C = XX, ST = XXXXXXXX, L = XXXXXX, postalCode = XXXXX, O = XXXXXXXXXXXXX, OU = XX + OU = XXXXXXX + OU = XXXXXXXXX, CN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
C = XX, ST = XXXXXXXX, L = XXXXXX, postalCode = XXXXX, O = XXXXXXXXXXXXX, OU = XX + OU = XXXXXXX + OU = XXXXXXXXX, CN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Client Certificate Types: ECDSA sign, RSA sign, DSA sign
Requested Signature Algorithms: ECDSA+SHA512:RSA+SHA512:ECDSA+SHA384:RSA+SHA384:ECDSA+SHA256:RSA+SHA256:ECDSA+SHA224:RSA+SHA224:ECDSA+SHA1:RSA+SHA1:DSA+SHA1
Shared Requested Signature Algorithms: ECDSA+SHA512:RSA+SHA512:ECDSA+SHA384:RSA+SHA384:ECDSA+SHA256:RSA+SHA256:ECDSA+SHA224:RSA+SHA224:ECDSA+SHA1:RSA+SHA1:DSA+SHA1
Peer signing digest: SHA256
Peer signature type: ECDSA
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 4342 bytes and written 431 bytes
Verification error: self signed certificate in certificate chain
---
New, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384
Server public key is 521 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-ECDSA-AES256-GCM-SHA384
Session-ID: A76D351566E53FBB8545ACDADBD1EDB6086DBF8D8D49BB272CEF0D701143FD78
Session-ID-ctx:
Master-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1571786143
Timeout : 7200 (sec)
Verify return code: 19 (self signed certificate in certificate chain)
Extended master secret: no
---
I have tried to update the mbedTLS version, but it doesn’t seems to fix anything. I’m still trying some theories.
The mbedTLS branch I was working on is: mbedtls-2.13.1-idf (19eb57f7f7b2f4312d497ddbcb5f104fc6877c70)
Any idea on how to solve this issue?
Thank you all!