2025-04-08 18:46:12 +08:00
..
2025-04-08 18:46:12 +08:00
2025-04-08 18:46:12 +08:00
2025-04-08 18:46:12 +08:00
2025-04-08 18:46:12 +08:00
2025-04-08 18:46:12 +08:00
2025-04-08 18:46:12 +08:00
2025-04-08 18:46:12 +08:00

mbedTLS

1、介绍

mbedTLS前称PolarSSL是一个ARM公司授权的开源的SSL库主要是用于嵌入式产品中的加密和SSL/TLS功能。
这个 mbedtls 库是RT-thread针对ARMmbed/mbedtls库的移植 有关mbedTLS的更多信息请参阅https://tls.mbed.org 。

2、获取方式

  •  Git方式获取 git clone https://github.com/RT-Thread-packages/mbedtls

  • env工具辅助下载   menuconfig package pathRT-Thread online packages/security/mbedtls

3、示例介绍

3.1 获取示例

menuconfig pathRT-Thread online packages/security/mbedtls/Enable a client example
配置获取示例选项,配置包版本选为最新版latest_version,示例代码位置examples/tls_app_test.c

3.2 运行示例

该示例为一个简单的TLS client与外网建立TLS连接并传输数据。
主要流程client连接外网TLS测试网站www.howsmyssl.com-->client和server握手成功-->client发送请求-->server回应请求-->TLS测试成功。
使用方式msh cmd tls_testfinsh cmd tls_test()

msh />tls_test   
mbedtls client struct init success...   
Loading the CA root certificate success...   
mbedtls client context init success...   
Connected www.howsmyssl.com:443 success...   
Certificate verified success...   
Writing HTTP request success...   
Getting HTTP response...   
get response data....   

4、常见问题

4.1 证书验证失败

[tls]verification info: ! The CRL is not correctly signed by the trusted CA

原因mbedtls包中支持多种主流CA机构根证书部分CA机构未支持
解决方法若测试其他TLS网站证书验证失败手动获取测试网站根证书Root Cerificate添加到mbedtls/tls_cerificate.c文件中

4.2 证书时间错误:

verification info: ! The certificate validity has expired
verification info: ! The certificate validity starts in the future

原因TLS握手是证书验证需要时间的验证本地时间获取有误导致
解决方式检查RTC设备是否支持检查RT_USING_RTC宏是否打开,校准设备时间

4.3 证书CN错误

verification info: ! The certificate Common Name (CN) does not match with the expected CN

原因测试其他TLS网站时若输入域名不符合证书的Common NameCN出现CN验证失败问题
解决方法检查输入域名和证书中CN是否匹配或输入IP地址

4.4 IAR编译错误

Fatal Error "MBEDTLS_CONFIG_FILE" expected a file name 

原因SConscript中预定义语法IAR编辑器不支持
解决方法:拷贝mbedtls-port/inc/tls_config.h内容到mbedtls/include/mbedtls/config.h

5、参考资料