examples: Add esp-ssl example tests server/client

Closes IDF-1156
This commit is contained in:
suren.gabrielyan
2021-02-11 00:46:28 +04:00
committed by Suren Gabrielyan
parent 822cdd81ef
commit 823abfdfd5
24 changed files with 600 additions and 233 deletions
+59 -9
View File
@@ -1,17 +1,67 @@
# Openssl Example
# OpenSSL Client Example
The Example contains of OpenSSL client demo.
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Open the project configuration menu (`idf.py menuconfig`):
This example shows how to set up esp openssl client and communicate over ssl transport layer.
* Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../README.md) for more details.
## How to use example
### Python scripts
Script example_test.py could be used as a client part to the ESP-OPENSSL server demo,
```
python example_test.py
```
Note that this script is used in automated tests, as well, so the IDF test framework packages need to be imported;
please add `$IDF_PATH/tools/ci/python_packages` to `PYTHONPATH`.
### Hardware Required
This example can be executed on any ESP32 board, the only required interface is WiFi and connection to internet.
### Configure the project
* Open the project configuration menu (`idf.py menuconfig`)
* Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details.
* Configure the openssl client endpoint URI under "Example Configuration", if "OPENSSL_CLIENT_URI_FROM_STDIN" is selected then the example application will connect to the URI it reads from stdin (used for testing)
* When using Make build system, set `Default serial port` under `Serial flasher config`.
* Configure target domain and port number under "Example Configuration"
* When using OPENSSL_CLIENT_URI_FROM_STRING configure target domain and port number under "Example Configuration"
If you want to test the OpenSSL client demo:
1. compile the code and load the firmware
2. open the UART TTY, then you can see it print the context of target domain
* Please note that verification mode is VERIFY_PEER by default, that's why during connection to public host('www.baidu.com') it's needed to use
appropriate certificates('baidu_ca.crt'), or it is needed to change verify mode to VERIFY_NONE.
See the README.md file in the upper level 'examples' directory for more information about examples.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
```
I (2601) esp_netif_handlers: example_connect: sta ip: 192.168.1.191, mask: 255.255.255.0, gw: 192.168.1.1
I (2601) example_connect: Got IPv4 event: Interface "example_connect: sta" address: 192.168.1.191
I (3601) example_connect: Got IPv6 event: Interface "example_connect: sta" address: fe80:0000:0000:0000:260a:c4ff:fee7:a660, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (3601) example_connect: Connected to example_connect: sta
I (3611) example_connect: - IPv4 address: 192.168.1.191
I (3611) example_connect: - IPv6 address: fe80:0000:0000:0000:260a:c4ff:fee7:a660, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (3631) openssl_example: Test started
I (3631) openssl_example: Trying connect to www.baidu.com port 443 ...
I (3641) openssl_example: DNS lookup succeeded. IP=103.235.46.39
I (4101) openssl_example: OK
I (4101) openssl_example: Create SSL obj
I (4101) openssl_example: OK
I (4101) openssl_example: SSL verify mode = 0 connected to www.baidu.com port 443 ...
I (8091) openssl_example: OK
I (8091) openssl_example: SSL Connection Succeed
```