Skip to content

Commit

Permalink
TLS: Drop messages associated with a closed endpoint in the processes
Browse files Browse the repository at this point in the history
When a session has been closed, we also need to clean up the process
events associated with the endpoint.
  • Loading branch information
jkralik committed Sep 22, 2023
1 parent 35f679b commit d95e34b
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions security/oc_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,46 @@ process_drop_event_for_removed_endpoint(oc_process_event_t ev,
{
const oc_endpoint_t *endpoint = (const oc_endpoint_t *)user_data;
if (ev != oc_event_to_oc_process_event(RI_TO_TLS_EVENT) &&
ev != oc_event_to_oc_process_event(UDP_TO_TLS_EVENT)) {
ev != oc_event_to_oc_process_event(UDP_TO_TLS_EVENT) &&
#ifdef OC_OSCORE
ev != oc_event_to_oc_process_event(INBOUND_OSCORE_EVENT) &&
ev != oc_event_to_oc_process_event(OUTBOUND_OSCORE_EVENT) &&
#endif /* OC_OSCORE */
ev != oc_event_to_oc_process_event(INBOUND_RI_EVENT) &&
ev != oc_event_to_oc_process_event(OUTBOUND_NETWORK_EVENT) &&
ev != oc_event_to_oc_process_event(INBOUND_NETWORK_EVENT)) {
return false;
}
oc_message_t *message = (oc_message_t *)data;
if (oc_endpoint_compare(&message->endpoint, endpoint) == 0) {
#if OC_DBG_IS_ENABLED
oc_string64_t endpoint_str;
oc_endpoint_to_string64(&message->endpoint, &endpoint_str);
OC_DBG("oc_tls: dropping %s message for removed endpoint(%s)",
(ev == oc_event_to_oc_process_event(RI_TO_TLS_EVENT)) ? "sent"
: "received",
const char *msg = "";
if (ev == oc_event_to_oc_process_event(RI_TO_TLS_EVENT)) {
msg = "send-tls-message";
}
if (ev == oc_event_to_oc_process_event(UDP_TO_TLS_EVENT)) {
msg = "received-tls-message";
}
if (ev == oc_event_to_oc_process_event(OUTBOUND_NETWORK_EVENT)) {
msg = "send-message";
}
if (ev == oc_event_to_oc_process_event(INBOUND_NETWORK_EVENT)) {
msg = "received-message";
}
if (ev == oc_event_to_oc_process_event(INBOUND_RI_EVENT)) {
msg = "received-coap-message";
}
#ifdef OC_OSCORE
if (ev == oc_event_to_oc_process_event(INBOUND_OSCORE_EVENT)) {
msg = "received-oscore-message";
}
if (ev == oc_event_to_oc_process_event(OUTBOUND_OSCORE_EVENT)) {
msg = "send-oscore-message";
}
#endif /* OC_OSCORE */
OC_DBG("oc_tls: dropping %s for removed endpoint(%s)", msg,
oc_string(endpoint_str));
#endif /* OC_DBG_IS_ENABLED */
oc_message_unref(message);
Expand Down Expand Up @@ -464,6 +493,16 @@ oc_tls_free_peer(oc_tls_peer_t *peer, bool inactivity_cb, bool from_reset)
}
oc_process_drop(&oc_tls_handler, process_drop_event_for_removed_endpoint,
&peer->endpoint);
OC_PROCESS_NAME(oc_message_buffer_handler);
oc_process_drop(&oc_message_buffer_handler,
process_drop_event_for_removed_endpoint, &peer->endpoint);
OC_PROCESS_NAME(g_coap_engine);
oc_process_drop(&g_coap_engine, process_drop_event_for_removed_endpoint,
&peer->endpoint);
#ifdef OC_OSCORE
oc_process_drop(&oc_oscore_handler, process_drop_event_for_removed_endpoint,
&peer->endpoint);
#endif /* OC_OSCORE */
#ifdef OC_PKI
oc_free_string(&peer->public_key);
#endif /* OC_PKI */
Expand Down

0 comments on commit d95e34b

Please sign in to comment.