esp_local_ctrl: Add support for insecure HTTP server transport
This commit is contained in:
@@ -74,12 +74,14 @@ Select properties to set (0 to re-read, 'q' to quit) : q
|
||||
Quitting...
|
||||
```
|
||||
|
||||
The script also allows to connect over BLE, and provide a custom service name. To display the list of supported parameters, run:
|
||||
The script also allows to connect over plain HTTP or BLE, and provide a custom service name. To display the list of supported parameters, run:
|
||||
|
||||
```
|
||||
python scripts/esp_local_ctrl.py --help
|
||||
```
|
||||
|
||||
**Note:** To use plain HTTP transport, disable the config option `CONFIG_ESP_HTTPS_SERVER_ENABLE`.
|
||||
|
||||
## Certificates
|
||||
|
||||
You can generate a new server certificate using the OpenSSL command line tool.
|
||||
|
||||
@@ -20,8 +20,11 @@
|
||||
#include <esp_log.h>
|
||||
#include <esp_timer.h>
|
||||
#include <esp_local_ctrl.h>
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
#include <esp_https_server.h>
|
||||
|
||||
#else
|
||||
#include <esp_http_server.h>
|
||||
#endif
|
||||
static const char *TAG = "control";
|
||||
|
||||
#define SERVICE_NAME "my_esp_ctrl_device"
|
||||
@@ -225,6 +228,7 @@ static void free_str(void *arg)
|
||||
/* Function used by app_main to start the esp_local_ctrl service */
|
||||
void start_esp_local_ctrl_service(void)
|
||||
{
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
/* Set the configuration */
|
||||
httpd_ssl_config_t https_conf = HTTPD_SSL_CONFIG_DEFAULT();
|
||||
|
||||
@@ -239,7 +243,9 @@ void start_esp_local_ctrl_service(void)
|
||||
extern const unsigned char prvtkey_pem_end[] asm("_binary_prvtkey_pem_end");
|
||||
https_conf.prvtkey_pem = prvtkey_pem_start;
|
||||
https_conf.prvtkey_len = prvtkey_pem_end - prvtkey_pem_start;
|
||||
|
||||
#else
|
||||
httpd_config_t http_conf = HTTPD_DEFAULT_CONFIG();
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_PROTOCOMM_SECURITY_VERSION_1
|
||||
/* What is the security level that we want (0, 1, 2):
|
||||
* - PROTOCOMM_SECURITY_0 is simply plain text communication.
|
||||
@@ -284,7 +290,11 @@ void start_esp_local_ctrl_service(void)
|
||||
esp_local_ctrl_config_t config = {
|
||||
.transport = ESP_LOCAL_CTRL_TRANSPORT_HTTPD,
|
||||
.transport_config = {
|
||||
.httpd = &https_conf
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
.httpd = &https_conf,
|
||||
#else
|
||||
.httpd = &http_conf,
|
||||
#endif
|
||||
},
|
||||
.proto_sec = {
|
||||
.version = security,
|
||||
|
||||
@@ -42,7 +42,15 @@ class CustomProcess(object):
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.temp_skip_ci(targets=['esp32c6'], reason='c6 support TBD')
|
||||
@pytest.mark.wifi_router
|
||||
def test_examples_esp_local_ctrl(dut: Dut) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default',
|
||||
'http',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
def test_examples_esp_local_ctrl(config: str, dut: Dut) -> None:
|
||||
|
||||
rel_project_path = os.path.join('examples', 'protocols', 'esp_local_ctrl')
|
||||
idf_path = get_sdk_path()
|
||||
@@ -54,8 +62,9 @@ def test_examples_esp_local_ctrl(dut: Dut) -> None:
|
||||
ap_password = get_env_config_variable(env_name, 'ap_password')
|
||||
dut.write(f'{ap_ssid} {ap_password}')
|
||||
dut_ip = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]')[1].decode()
|
||||
dut.expect('esp_https_server: Starting server')
|
||||
dut.expect('esp_https_server: Server listening on port 443')
|
||||
if config == 'default':
|
||||
dut.expect('esp_https_server: Starting server')
|
||||
dut.expect('esp_https_server: Server listening on port 443')
|
||||
dut.expect('control: esp_local_ctrl service started with name : my_esp_ctrl_device')
|
||||
|
||||
def dut_expect_read() -> None:
|
||||
@@ -66,12 +75,21 @@ def test_examples_esp_local_ctrl(dut: Dut) -> None:
|
||||
|
||||
# Running mDNS services in docker is not a trivial task. Therefore, the script won't connect to the host name but
|
||||
# to IP address. However, the certificates were generated for the host name and will be rejected.
|
||||
cmd = ' '.join([sys.executable, os.path.join(idf_path, rel_project_path, 'scripts/esp_local_ctrl.py'),
|
||||
'--sec_ver 2',
|
||||
'--sec2_username wifiprov',
|
||||
'--sec2_pwd abcd1234',
|
||||
'--name', dut_ip,
|
||||
'--dont-check-hostname']) # don't reject the certificate because of the hostname
|
||||
if config == 'default':
|
||||
cmd = ' '.join([sys.executable, os.path.join(idf_path, rel_project_path, 'scripts/esp_local_ctrl.py'),
|
||||
'--sec_ver 2',
|
||||
'--sec2_username wifiprov',
|
||||
'--sec2_pwd abcd1234',
|
||||
'--name', dut_ip,
|
||||
'--dont-check-hostname']) # don't reject the certificate because of the hostname
|
||||
elif config == 'http':
|
||||
cmd = ' '.join([sys.executable, os.path.join(idf_path, rel_project_path, 'scripts/esp_local_ctrl.py'),
|
||||
'--sec_ver 2',
|
||||
'--transport http',
|
||||
'--sec2_username wifiprov',
|
||||
'--sec2_pwd abcd1234',
|
||||
'--name', dut_ip,
|
||||
'--dont-check-hostname'])
|
||||
esp_local_ctrl_log = os.path.join(idf_path, rel_project_path, 'esp_local_ctrl.log')
|
||||
with CustomProcess(cmd, esp_local_ctrl_log) as ctrl_py:
|
||||
|
||||
@@ -89,7 +107,8 @@ def test_examples_esp_local_ctrl(dut: Dut) -> None:
|
||||
property3 = ''
|
||||
|
||||
ctrl_py.pexpect_proc.expect_exact('Connecting to {}'.format(dut_ip))
|
||||
dut.expect('esp_https_server: performing session handshake', timeout=60)
|
||||
if config == 'default':
|
||||
dut.expect('esp_https_server: performing session handshake', timeout=60)
|
||||
expect_properties(property1, property3)
|
||||
|
||||
ctrl_py.pexpect_proc.sendline('1')
|
||||
|
||||
@@ -127,6 +127,8 @@ async def get_transport(sel_transport, service_name, check_hostname):
|
||||
try:
|
||||
tp = None
|
||||
if (sel_transport == 'http'):
|
||||
tp = esp_prov.transport.Transport_HTTP(service_name, None)
|
||||
elif (sel_transport == 'https'):
|
||||
example_path = os.environ['IDF_PATH'] + '/examples/protocols/esp_local_ctrl'
|
||||
cert_path = example_path + '/main/certs/rootCA.pem'
|
||||
ssl_ctx = ssl.create_default_context(cafile=cert_path)
|
||||
@@ -277,7 +279,7 @@ async def main():
|
||||
help='Protocol version', default='')
|
||||
|
||||
parser.add_argument('--transport', dest='transport', type=str,
|
||||
help='transport i.e http or ble', default='http')
|
||||
help='transport i.e http/https/ble', default='https')
|
||||
|
||||
parser.add_argument('--name', dest='service_name', type=str,
|
||||
help='BLE Device Name / HTTP Server hostname or IP', default='')
|
||||
@@ -332,7 +334,7 @@ async def main():
|
||||
|
||||
if args.service_name == '':
|
||||
args.service_name = 'my_esp_ctrl_device'
|
||||
if args.transport == 'http':
|
||||
if args.transport == 'http' or args.transport == 'https':
|
||||
args.service_name += '.local'
|
||||
|
||||
obj_transport = await get_transport(args.transport, args.service_name, not args.dont_check_hostname)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y
|
||||
CONFIG_ESP_HTTPS_SERVER_ENABLE=n
|
||||
Reference in New Issue
Block a user