Coverage Report

Created: 2025-03-18 06:55

/src/gnutls/lib/dtls.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2009-2012 Free Software Foundation, Inc.
3
 *
4
 * Author: Jonathan Bastien-Filiatrault
5
 *
6
 * This file is part of GNUTLS.
7
 *
8
 * The GNUTLS library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public License
10
 * as published by the Free Software Foundation; either version 2.1 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
20
 *
21
 */
22
23
#ifndef GNUTLS_LIB_DTLS_H
24
#define GNUTLS_LIB_DTLS_H
25
26
#include "config.h"
27
#include "gnutls_int.h"
28
#include "buffers.h"
29
#include "mbuffers.h"
30
#include "constate.h"
31
32
int _dtls_transmit(gnutls_session_t session);
33
int _dtls_record_check(struct record_parameters_st *rp, uint64_t seq_num);
34
void _dtls_reset_hsk_state(gnutls_session_t session);
35
void _dtls_reset_window(struct record_parameters_st *rp);
36
37
0
#define MAX_DTLS_TIMEOUT 60000
38
39
#define RETURN_DTLS_EAGAIN_OR_TIMEOUT(session, r)                            \
40
0
  {                                                                    \
41
0
    struct timespec _now;                                        \
42
0
    unsigned int _diff;                                          \
43
0
    gnutls_gettime(&_now);                                       \
44
0
                                                                             \
45
0
    _diff = timespec_sub_ms(                                     \
46
0
      &_now, &session->internals.handshake_start_time);    \
47
0
    if (_diff > session->internals.handshake_timeout_ms) {       \
48
0
      _gnutls_dtls_log("Session timeout: %u ms\n", _diff); \
49
0
      return gnutls_assert_val(GNUTLS_E_TIMEDOUT);         \
50
0
    } else {                                                     \
51
0
      int _rr;                                             \
52
0
      if (r != GNUTLS_E_INTERRUPTED)                       \
53
0
        _rr = GNUTLS_E_AGAIN;                        \
54
0
      else                                                 \
55
0
        _rr = r;                                     \
56
0
      if (!(session->internals.flags & GNUTLS_NONBLOCK))   \
57
0
        millisleep(50);                              \
58
0
      return gnutls_assert_val(_rr);                       \
59
0
    }                                                            \
60
0
  }
61
62
int _dtls_wait_and_retransmit(gnutls_session_t session);
63
64
/* returns true or false depending on whether we need to
65
 * handle asynchronously handshake data.
66
 */
67
inline static int _dtls_is_async(gnutls_session_t session)
68
0
{
69
0
  if ((session->security_parameters.entity == GNUTLS_SERVER &&
70
0
       !session->internals.resumed) ||
71
0
      (session->security_parameters.entity == GNUTLS_CLIENT &&
72
0
       session->internals.resumed))
73
0
    return 1;
74
0
  else
75
0
    return 0;
76
0
}
Unexecuted instantiation: record.c:_dtls_is_async
Unexecuted instantiation: handshake-tls13.c:_dtls_is_async
Unexecuted instantiation: buffers.c:_dtls_is_async
Unexecuted instantiation: handshake.c:_dtls_is_async
Unexecuted instantiation: constate.c:_dtls_is_async
Unexecuted instantiation: state.c:_dtls_is_async
Unexecuted instantiation: dtls.c:_dtls_is_async
Unexecuted instantiation: system_override.c:_dtls_is_async
Unexecuted instantiation: dtls-sw.c:_dtls_is_async
Unexecuted instantiation: post_handshake.c:_dtls_is_async
Unexecuted instantiation: heartbeat.c:_dtls_is_async
Unexecuted instantiation: session_ticket.c:_dtls_is_async
77
78
inline static void _dtls_async_timer_init(gnutls_session_t session)
79
0
{
80
0
  if (_dtls_is_async(session)) {
81
0
    _gnutls_dtls_log(
82
0
      "DTLS[%p]: Initializing timer for handshake state.\n",
83
0
      session);
84
0
    session->internals.dtls.async_term =
85
0
      gnutls_time(0) + MAX_DTLS_TIMEOUT / 1000;
86
0
  } else {
87
0
    _dtls_reset_hsk_state(session);
88
0
    _gnutls_handshake_io_buffer_clear(session);
89
0
    _gnutls_epoch_gc(session);
90
0
    session->internals.dtls.async_term = 0;
91
0
  }
92
0
}
Unexecuted instantiation: record.c:_dtls_async_timer_init
Unexecuted instantiation: handshake-tls13.c:_dtls_async_timer_init
Unexecuted instantiation: buffers.c:_dtls_async_timer_init
Unexecuted instantiation: handshake.c:_dtls_async_timer_init
Unexecuted instantiation: constate.c:_dtls_async_timer_init
Unexecuted instantiation: state.c:_dtls_async_timer_init
Unexecuted instantiation: dtls.c:_dtls_async_timer_init
Unexecuted instantiation: system_override.c:_dtls_async_timer_init
Unexecuted instantiation: dtls-sw.c:_dtls_async_timer_init
Unexecuted instantiation: post_handshake.c:_dtls_async_timer_init
Unexecuted instantiation: heartbeat.c:_dtls_async_timer_init
Unexecuted instantiation: session_ticket.c:_dtls_async_timer_init
93
94
void _dtls_async_timer_delete(gnutls_session_t session);
95
96
/* Checks whether it is time to terminate the timer
97
 */
98
inline static void _dtls_async_timer_check(gnutls_session_t session)
99
0
{
100
0
  if (!IS_DTLS(session))
101
0
    return;
102
103
0
  if (session->internals.dtls.async_term != 0) {
104
0
    time_t _now = time(0);
105
106
    /* check if we need to expire the queued handshake data */
107
0
    if (_now > session->internals.dtls.async_term) {
108
0
      _dtls_async_timer_delete(session);
109
0
    }
110
0
  }
111
0
}
Unexecuted instantiation: record.c:_dtls_async_timer_check
Unexecuted instantiation: handshake-tls13.c:_dtls_async_timer_check
Unexecuted instantiation: buffers.c:_dtls_async_timer_check
Unexecuted instantiation: handshake.c:_dtls_async_timer_check
Unexecuted instantiation: constate.c:_dtls_async_timer_check
Unexecuted instantiation: state.c:_dtls_async_timer_check
Unexecuted instantiation: dtls.c:_dtls_async_timer_check
Unexecuted instantiation: system_override.c:_dtls_async_timer_check
Unexecuted instantiation: dtls-sw.c:_dtls_async_timer_check
Unexecuted instantiation: post_handshake.c:_dtls_async_timer_check
Unexecuted instantiation: heartbeat.c:_dtls_async_timer_check
Unexecuted instantiation: session_ticket.c:_dtls_async_timer_check
112
113
unsigned _gnutls_record_overhead(const version_entry_st *ver,
114
         const cipher_entry_st *cipher,
115
         const mac_entry_st *mac, unsigned max);
116
117
/* Returns non-zero if the async timer is active */
118
inline static int _dtls_async_timer_active(gnutls_session_t session)
119
0
{
120
0
  if (!IS_DTLS(session))
121
0
    return 0;
122
123
0
  return session->internals.dtls.async_term;
124
0
}
Unexecuted instantiation: record.c:_dtls_async_timer_active
Unexecuted instantiation: handshake-tls13.c:_dtls_async_timer_active
Unexecuted instantiation: buffers.c:_dtls_async_timer_active
Unexecuted instantiation: handshake.c:_dtls_async_timer_active
Unexecuted instantiation: constate.c:_dtls_async_timer_active
Unexecuted instantiation: state.c:_dtls_async_timer_active
Unexecuted instantiation: dtls.c:_dtls_async_timer_active
Unexecuted instantiation: system_override.c:_dtls_async_timer_active
Unexecuted instantiation: dtls-sw.c:_dtls_async_timer_active
Unexecuted instantiation: post_handshake.c:_dtls_async_timer_active
Unexecuted instantiation: heartbeat.c:_dtls_async_timer_active
Unexecuted instantiation: session_ticket.c:_dtls_async_timer_active
125
126
/* This function is to be called from record layer once
127
 * a handshake replay is detected. It will make sure
128
 * it transmits only once per few seconds. Otherwise
129
 * it is the same as _dtls_transmit().
130
 */
131
inline static int _dtls_retransmit(gnutls_session_t session)
132
0
{
133
0
  return _dtls_transmit(session);
134
0
}
Unexecuted instantiation: record.c:_dtls_retransmit
Unexecuted instantiation: handshake-tls13.c:_dtls_retransmit
Unexecuted instantiation: buffers.c:_dtls_retransmit
Unexecuted instantiation: handshake.c:_dtls_retransmit
Unexecuted instantiation: constate.c:_dtls_retransmit
Unexecuted instantiation: state.c:_dtls_retransmit
Unexecuted instantiation: dtls.c:_dtls_retransmit
Unexecuted instantiation: system_override.c:_dtls_retransmit
Unexecuted instantiation: dtls-sw.c:_dtls_retransmit
Unexecuted instantiation: post_handshake.c:_dtls_retransmit
Unexecuted instantiation: heartbeat.c:_dtls_retransmit
Unexecuted instantiation: session_ticket.c:_dtls_retransmit
135
136
#endif /* GNUTLS_LIB_DTLS_H */