WildernessLabs / Meadow_Issues

Public repo for bugs and issues with Meadow
15 stars 0 forks source link

TLS handshake fails with -9984 due to NTP not working over cellular network #714

Closed duduita closed 1 week ago

duduita commented 3 months ago

Describe the bug Since NTP events are not getting called when cellular network is selected, it's causing TLS handshake failures.

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> Mono.MbedTls.MbedTlsIOException: TLS handshake failed. Return code: -9984. Error: Certificate verification failed, e.g. CRL, CA or signature check failed.

When checking the device time we can see a clock desync, which may cause issues in TLS operations that need the right clock time.

05/24/2024 18:52:36 Sampling sensors...

To Reproduce Run a sample app that makes requests to https://home.thegreatco.com:7296/sensor over the cellular network.

Expected behavior The NtpUpdateEvent should be fired, as it happens on WiFi, for instance.

When booting Wi-Fi, we get the following:

Device is configured to use WiFi for the network interface
* * *
Sending command to connect
Sending ESP command. destination:1, function:2
ESP Ioctl returned success: CompletedOk
SendingCommand returned: CompletedOk
Wifi InvokeEvent NetworkConnectedEvent returned CompletedOk
Wifi InvokeEvent NtpUpdateEvent returned CompletedOk
Network time changed to 10/03/2023 15:15:05, IsTimeSet is True
Interface: wlan0: wlan0 Wireless80211 Up

However, when booting cellular, that event never fires:

Meadow StdOut: Device is configured to use Cell for the network interface
Meadow StdOut: Cell InvokeEvent NetworkConnectedEvent returned CompletedOk
Meadow StdOut: Cell connected event triggered!
Meadow StdInfo: Connection established successfully! IP address '10.47.0.243'.
Meadow StdOut: Cell network invoked with APN [envizor.vzwentp]
Meadow StdOut: Cellular network is up
Meadow StdOut: - Ip Address: 255.255.255.255
Meadow StdOut: - Subnet: 255.255.255.255
Meadow StdOut: - Gateway: 255.255.255.255
Meadow StdOut: - Signal: Good (17)

Additional context To get more context see this conversation on public slack.

duduita commented 3 months ago

While we are fixing it, as a workaround you can use:

await _device.PlatformOS.NtpClient.Synchronize("pool.ntp.org");

After cell establishes a connection, to resolve this issue.