@Carmeloning证书验证失败可能由于多种原因而发生。例如,您尚未设置正确的受信任根证书。证书验证失败时返回
错误-0x2700 MBEDTLS_ERR_X509_CERT_VERIFY_FAILED并返回。
您还应该检查验证标志。
I used the server to give me the root certificate in the browser test and the server handshake is able to pass,But when i use the Mbed. IT is faild and it return like this:
Starting mbed-os-example-tls/tls-client
Using Mbed OS 5.9.7
[EasyConnect] IPv4 mode
[EasyConnect] Using WiFi (ESP8266)
[EasyConnect] Connecting to WiFi GE
[EasyConnect] Connected to Network successfully
[EasyConnect] MAC address 84:0d:8e:97:40:ca
[EasyConnect] IP address 192.168.1.15
Successfully connected to 39.108.211.173 at port 443
Starting the TLS handshake...
ssl_tls.c:6717: |2| => handshake
ssl_cli.c:3386: |2| client state: 0
ssl_tls.c:2471: |2| => flush output
ssl_tls.c:2483: |2| <= flush output
ssl_cli.c:3386: |2| client state: 1
ssl_tls.c:2471: |2| => flush output
ssl_tls.c:2483: |2| <= flush output
ssl_cli.c:770: |2| => write client hello
ssl_tls.c:2764: |2| => write record
ssl_tls.c:2471: |2| => flush output
ssl_tls.c:2489: |2| message length: 189, out_left: 189
ssl_tls.c:2496: |2| ssl->f_send() returned 189 (-0xffffff43)
ssl_tls.c:2523: |2| <= flush output
ssl_tls.c:2922: |2| <= write record
ssl_cli.c:1085: |2| <= write client hello
ssl_cli.c:3386: |2| client state: 2
ssl_tls.c:2471: |2| => flush output
ssl_tls.c:2483: |2| <= flush output
ssl_cli.c:1478: |2| => parse server hello
ssl_tls.c:3809: |2| => read record
ssl_tls.c:2252: |2| => fetch input
ssl_tls.c:2412: |2| in_left: 0, nb_want: 5
ssl_tls.c:2436: |2| in_left: 0, nb_want: 5
ssl_tls.c:2438: |2| ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
ssl_tls.c:2458: |2| <= fetch input
ssl_tls.c:2252: |2| => fetch input
ssl_tls.c:2412: |2| in_left: 5, nb_want: 66
ssl_tls.c:2436: |2| in_left: 5, nb_want: 66
ssl_tls.c:2438: |2| ssl->f_recv(_timeout)() returned 61 (-0xffffffc3)
ssl_tls.c:2458: |2| <= fetch input
ssl_tls.c:3846: |2| <= read record
ssl_cli.c:1760: |2| server hello, total extension length: 17
ssl_cli.c:1949: |2| <= parse server hello
ssl_cli.c:3386: |2| client state: 3
ssl_tls.c:2471: |2| => flush output
ssl_tls.c:2483: |2| <= flush output
ssl_tls.c:4376: |2| => parse certificate
ssl_tls.c:3809: |2| => read record
ssl_tls.c:2252: |2| => fetch input
ssl_tls.c:2412: |2| in_left: 0, nb_want: 5
ssl_tls.c:2436: |2| in_left: 0, nb_want: 5
ssl_tls.c:2438: |2| ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
ssl_tls.c:2458: |2| <= fetch input
ssl_tls.c:2252: |2| => fetch input
ssl_tls.c:2412: |2| in_left: 5, nb_want: 877
ssl_tls.c:2436: |2| in_left: 5, nb_want: 877
ssl_tls.c:2438: |2| ssl->f_recv(_timeout)() returned 872 (-0xfffffc98)
ssl_tls.c:2458: |2| <= fetch input
ssl_tls.c:3846: |2| <= read record
Verifying certificate at depth 0:
cert. version : 1
serial number : 8D:9E:62:C5:CC:7A:BA:B6
issuer name : C=CN, ST=myprovince, L=mycity, O=myorganization, OU=mygroup, CN=myCA
subject name : C=CN, ST=myprovince, L=mycity, O=myorganization, OU=mygroup, CN=myServer
issued on : 2019-01-14 02:25:20
expires on : 2020-01-14 02:25:20
signed using : RSA with SHA1
RSA key size : 2048 bits
ssl_tls.c:4643: |1| x509_verify_cert() returned -9984 (-0x2700)
ssl_tls.c:4180: |2| => send alert message
ssl_tls.c:2764: |2| => write record
ssl_tls.c:2471: |2| => flush output
ssl_tls.c:2489: |2| message length: 7, out_left: 7
ssl_tls.c:2496: |2| ssl->f_send() returned 7 (-0xfffffff9)
ssl_tls.c:2523: |2| <= flush output
ssl_tls.c:2922: |2| <= write record
ssl_tls.c:4193: |2| <= send alert message
ssl_tls.c:4740: |2| <= parse certificate
ssl_tls.c:6727: |2| <= handshake
mbedtls_ssl_handshake() returned -0x2700
FAIL
ssl_tls.c:7495: |2| => free
ssl_tls.c:7560: |2| <= free