Hello!
I need to use download_client to get files from an HTTPS server. I'm stuck in the implementation process - I'm lost when it comes to TLS etc. I tried to extract some precious details from the example in samples/net/sockets/http_client. MBEDTLS etc are enabled in Kconfig.
The following steps were taken:
1. generated a CA certificate:
openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 365000 -key ca-key.pem -out ca-cert.pem
2. generated the .DER file:
openssl base64 -d -in ca-cert.pem -out ca-cert.der
3. with my tool (which is quite similar to file2hex.py
) it was converted to a C array (static const uint8_t ca_cert[] = {...}
);
4. included in my source (#include "ca_cert.h"
);
5. initiated the download:
int cfg_sec_tag_list[] = {1};
struct download_client_cfg cfg = {
.sec_tag_list = cfg_sec_tag_list,
.sec_tag_count = ARRAY_SIZE(cfg_sec_tag_list),
.pdn_id = 0,
.frag_size_override = 0,
.set_tls_hostname = 0,
};
...
...
tls_credential_add(cfg_sec_tag_list[0],
TLS_CREDENTIAL_CA_CERTIFICATE,
ca_cert,
sizeof(ca_cert));
download_client_init(&dlc, c_cb);
download_client_get(&dlc, "">https://my.url/file", &cfg, NULL, 0);
6. got these results:
[00:00:28.969,543] <dbg> download_client: set_state: state = 1
[00:00:28.969,573] <inf> download_client: Downloading: https://my.url/file [0]
[00:00:29.183,044] <dbg> download_client: client_connect: Port not specified, using default: 443
[00:00:29.183,074] <dbg> download_client: client_connect: family: 1, type: 1, proto: 258
[00:00:29.183,715] <inf> download_client: Setting up TLS credentials, sec tag count 1
[00:00:29.183,746] <inf> download_client: Connecting to https://my.url/file
[00:00:29.183,776] <dbg> download_client: client_connect: fd 5, addrlen 8, fam IPv4, port 443
[00:00:29.412,231] <err> download_client: Unable to connect, errno 22
[00:00:29.412,658] <dbg> download_client: set_state: state = 0
--------------------------------------------------------------------
I believe this must be something TLS-related, but I'm very rookie in this field.
Please give me a guide how to setup download_client to be able to get files via HTTPS on the simplest way.