Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: use monotonic timer for monitoring DTLS peer inactivity #450

Merged
merged 2 commits into from
May 25, 2023

Conversation

Danielius1922
Copy link
Member

No description provided.

@ocf-conformance-test-tool
Copy link

🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed.


ℹ️ To verify your latest change (45e83b9), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

@Danielius1922 Danielius1922 changed the base branch from master to adam/feature/434-fix-time-adjustment May 16, 2023 15:16
@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch 5 times, most recently from 4577be9 to 2d295c6 Compare May 18, 2023 09:27
Base automatically changed from adam/feature/434-fix-time-adjustment to master May 18, 2023 09:44
@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch 22 times, most recently from 4f90c22 to 029bd1d Compare May 23, 2023 13:51
@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch 4 times, most recently from 900f6a5 to 651a5f2 Compare May 23, 2023 17:11
@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label May 23, 2023
@Danielius1922 Danielius1922 marked this pull request as ready for review May 24, 2023 05:43
@Danielius1922 Danielius1922 requested a review from jkralik May 24, 2023 05:43
@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch from 651a5f2 to c8006b3 Compare May 24, 2023 08:42
@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label May 24, 2023
@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch from c8006b3 to 9c9a386 Compare May 24, 2023 10:39
api/oc_endpoint.c Outdated Show resolved Hide resolved
Comment on lines +573 to 574
if ((peer->endpoint.flags & TCP) == 0) {
mbedtls_ssl_close_notify(&peer->ssl_ctx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this code it seems to be more general - not only for DTLS (udp tls), but also for TLS (TCP) connection

Comment on lines 2026 to +2029
mbedtls_ssl_set_timer_cb(&peer->ssl_ctx, &peer->timer, ssl_set_timer,
ssl_get_timer);
oc_ri_add_timed_event_callback_seconds(
peer, oc_tls_inactive, (oc_clock_time_t)OC_DTLS_INACTIVITY_TIMEOUT);
oc_ri_add_timed_event_callback_ticks(peer, oc_dtls_inactive,
DTLS_INACTIVITY_TIMEOUT_TICKS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now I see the limitation to DTLS

Comment on lines 2026 to +2029
mbedtls_ssl_set_timer_cb(&peer->ssl_ctx, &peer->timer, ssl_set_timer,
ssl_get_timer);
oc_ri_add_timed_event_callback_seconds(
peer, oc_tls_inactive, (oc_clock_time_t)OC_DTLS_INACTIVITY_TIMEOUT);
oc_ri_add_timed_event_callback_ticks(peer, oc_dtls_inactive,
DTLS_INACTIVITY_TIMEOUT_TICKS);
Copy link
Member

@jkralik jkralik May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this timer could be used to close also TCP-TLS connection when we implement the closing idle sessions for TCP
not in this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm checking the header for mbedtls_ssl_set_timer_cb and it should work for TLS as well. It is mandatory for DTLS, but not for TLS so that's probably the reason why it is like this.

@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch 3 times, most recently from c701254 to 565abe0 Compare May 24, 2023 17:53
The previous implementation of monitoring DTLS peers' activity relied
on the absolute system time to track the last activity timestamp.
However, this approach had the unintended consequence of being
affected by changes in the system time. For instance, modifying
the system time by an interval equivalent to the DTLS inactivity
timeout would trigger a false inactivity timeout and result in
the closure of the DTLS session.

To address this issue, the monitoring mechanism has been updated
to utilize a monotonic timer. This timer is independent of
system time changes and provides a more accurate measure of
the duration of inactivity. By using a monotonic timer, the DTLS
session will only be closed if no activity occurs within the
specified timeout period, regardless of any changes in
the system time.

This refactor improves the reliability and accuracy of DTLS peer
monitoring, ensuring that the DTLS sessions are closed based on
actual inactivity rather than being influenced by system time
adjustments.
@Danielius1922 Danielius1922 force-pushed the adam/feature/434-fix-time-adjustment-tls-peer branch from 565abe0 to 469ea8f Compare May 24, 2023 18:24
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 1 Security Hotspot
Code Smell A 1 Code Smell

76.8% 76.8% Coverage
1.0% 1.0% Duplication

@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label May 24, 2023
@jkralik jkralik added OCF Conformance Testing OCF Conformance Testing required and removed OCF Conformance Testing OCF Conformance Testing required labels May 25, 2023
@Danielius1922 Danielius1922 merged commit 051b52c into master May 25, 2023
@Danielius1922 Danielius1922 deleted the adam/feature/434-fix-time-adjustment-tls-peer branch May 25, 2023 10:48
@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
OCF Conformance Testing OCF Conformance Testing required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants