- 学习路线
- RT-Thread 简介
- RT-Thread Nano
- RT-Thread Smart
- RT-Thread Studio
- 快速上手
- 内核
- Env 工具
- 设备和驱动
- 组件
- 软件包
- 物联网
- 工具
- MicroPython用户手册
- 应用开发
- RT-Thread 版本选择
- 开发环境搭建
- 固件尺寸优化
- 在RT-Thread潘多拉开发板上实现电源管理
- 网络协议栈驱动移植
- 在STM32F429上应用网络功能
- 在STM32F429上应用文件系统
- 在潘多拉上使用 SFUD 操作 Flash
- FreeModbus 应用笔记
- 应用AT组件连接ESP8266模块
- 多线程非阻塞网络编程
- 使用QEMU运行动态模块组件
- CmBacktrace应用
- 在 STM32L4 上应用 littlefs 文件系统
- STM32通用Bootloader
- wireshark抓取tls数据包
- 在 STM32 上应用 C++
- STM32 上使用 PWM
- STM32 上使用 USB Host 读写 U 盘
- QEMU 网络视频教程
- Demo 示例
- 其他
- 传感器驱动开发指南
- 软件包开发
- 向RT-Thread贡献代码
- 内核视频教程
- Env 视频教程
- rw007 SPI WiFi 模块使用
- wireshark抓取tls数据包
- Keil MDK 安装
- Rtthread dir
- 支持的传感器列表
- 支持的 Touch 列表
- Builtin functions and exceptions
- Cmath
- Gc
- Math
- Sys
- Uarray
- Ubinascii
- Ucollections
- Uerrno
- Uhashlib
- Uheapq
- Uio
- Ujson
- Uos
- Ure
- Uselect
- Usocket
- ussl – SSL/TLS 模块
- Ustruct
- Utime
- Uzlib
- thread
- micropython – 内部功能访问与控制模块
- Rtthread
- Machine
- Pin
- I2C
- SPI
- UART
- LCD
- RTC
- PWM
- ADC
- WDT
- Timer
- Network
- Wlan
- 传感器驱动框架介绍
- Preparations
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
示例说明
该示例程序提供了一个简单的 TLS client,与测试网站建立 TLS 连接并获取加密数据。
示例文件
示例程序路径 | 说明 |
---|---|
samples/tls_app_test.c | TLS 测试例程 |
例程工作流程
本例程使用了 RT-Thread 官方 TLS 测试网站 www.rt-thread.org
,使用 mbedtls_client_write
函数发送 HTTP 测试请求,成功后,该网站会返回文本数据,测试例程将解析后的数据输出到控制台。
- 例程使用的 HTTP 请求数据如下所示
"GET /download/rt-thread.txt HTTP/1.0\r\n"
"Host: www.rt-thread.org\r\n"
"User-Agent: rtthread/3.1 rtt\r\n"
"\r\n";
mbedTLS 测试例程的基本工作流程如下所示
- client连接测试网站
www.rt-thread.org
- client 和 server 握手成功
- client 发送请求
- server 回应请求
- TLS 测试成功/失败
- client连接测试网站
准备工作
获取软件包
menuconfig 配置软件包
打开 RT-Thread 提供的 ENV 工具,使用 menuconfig 配置软件包。
启用 mbedtls 软件包,并配置使能测试例程(Enable a mbedtls client example),如下所示:
RT-Thread online packages --->
security packages --->
Select Root Certificate ---> # 选择证书文件
[*] mbedtls: An portable and flexible SSL/TLS library # 打开 mbedtls 软件包
[*] Store the AES tables in ROM # 将 AES 表存储在 ROM 中
(2) Maximum window size used # 用于点乘的最大“窗口”大小(2-7)
(3584) Maxium fragment length in bytes # 配置数据帧大小
[*] Enable a mbedtls client example # 开启 mbedtls 测试例程
[ ] Enable Debug log output # 开启调试 log 输出
version (latest) ---> # 选择软件包版本,默认为最新版本
- 使用
pkgs --update
命令下载软件包 - 编译下载
同步设备时间
SSL/TLS 服务器进行证书校验的过程中,会对当前发起校验请求的时间进行认证,如果时间不满足服务器的要求,就会校验证书失败。因此,我们需要为设备同步本地时间。
方式一: 使用
date
命令未同步过时间的设备输入
date
命令后如下所示:
msh />date
Thu Jan 1 00:00:06 1970
使用 date
设置当前时间,如下所示:
msh />date 2018 08 02 12 23 00
msh />date
Thu Aug 2 12:23:01 2018
msh />
方式二: 使用 NTP 同步网络时间
该方式需要依赖 NTP 工具包,使用
menuconfig
配置获取,如下所示:
RT-Thread online packages --->
IoT - internet of things --->
-*- netutils: Networking utilities for RT-Thread --->
-*- Enable NTP(Network Time Protocol) client
(8) Timezone for calculate local time
(cn.ntp.org.cn) NTP server name
使用命令 ntp_sync
同步网络时间
msh />ntp_sync
Get local time from NTP server: Thu Aug 2 14:31:30 2018
The system time is updated. Timezone is 8.
msh />date
Thu Aug 2 14:31:34 2018
启动例程
在 MSH 中使用命令 tls_test
执行示例程序,成功建立 TLS 连接后,设备会从服务器拿到一组密码套件,设备 log 如下所示:
msh />tls_test
MbedTLS test sample!
Memory usage before the handshake connection is established:
total memory: 33554408
used memory : 20968
maximum allocated memory: 20968
Start handshake tick:3313
[tls]mbedtls client struct init success...
[tls]Loading the CA root certificate success...
[tls]mbedtls client context init success...
msh />[tls]Connected www.rt-thread.org:443 success...
[tls]Certificate verified success...
Finish handshake tick:6592
MbedTLS connect success...
Memory usage after the handshake connection is established:
total memory: 33554408
used memory : 45480
maximum allocated memory: 50808
Writing HTTP request success...
Getting HTTP response...
HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Fri, 31 Aug 2018 08:29:24 GMT
Content-Type: text/plain
Content-Length: 267
Last-Modified: Sat, 04 Aug 2018 02:14:51 GMT
Connection: keep-alive
ETag: "5b650c1b-10b"
Strict-Transport-Security: max-age=1800; includeSubdomains; preload
Accept-Ranges: bytes
RT-Thread is an open source IoT operating system from China, which has strong scalability: from a tiny kernel running on a tiny core, for example ARM Cortex-M0, or Cortex-M3/4/7, to a rich feature system running on MIPS32, ARM Cortex-A8, ARM Cortex-A9 DualCore etc.
MbedTLS connection close success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论