MT#55283 retain TLS ID for answer role change

DTLS connections created during an offer are passive by default. If the
answer requires a role change to active, don't reset the TLS ID, as we
have no way to communicate this change until a re-invite, which would
then lead to an unexpected reset of the connection.

Related: #2156

Change-Id: I49dcd93d63840a223c41a59c74e2f270d0a08f62
(cherry picked from commit 001d8fe4c6)
(cherry picked from commit c4e515f221)
mr26.1.1
Richard Fuchs 4 weeks ago
parent 6e904009b3
commit 26e8e3112b

@ -688,6 +688,34 @@ static long dtls_bio_callback_wrap(BIO *bio, int oper, const char *argp, int arg
}
#endif
// leaves TLS ID intact
static void dtls_connection_reset(struct dtls_connection *c) {
if (c->ssl_ctx || c->ssl)
ilogs(crypto, LOG_DEBUG, "Resetting DTLS connection context");
if (c->ssl_ctx)
SSL_CTX_free(c->ssl_ctx);
if (c->ssl)
SSL_free(c->ssl);
if (!c->init) {
if (c->r_bio)
BIO_free(c->r_bio);
if (c->w_bio)
BIO_free(c->w_bio);
}
obj_release(c->sfd);
c->ssl_ctx = NULL;
c->ssl = NULL;
c->r_bio = NULL;
c->w_bio = NULL;
c->ps = NULL;
ZERO(c->fsin);
c->init = c->active = c->connected = 0;
}
int dtls_connection_init(struct dtls_connection *d, struct packet_stream *ps, int active,
struct dtls_cert *cert)
{
@ -701,7 +729,7 @@ int dtls_connection_init(struct dtls_connection *d, struct packet_stream *ps, in
if (d->init) {
if ((d->active && active) || (!d->active && !active))
goto done;
dtls_connection_cleanup(d);
dtls_connection_reset(d);
}
d->ps = ps;
@ -781,7 +809,8 @@ int dtls_connection_init(struct dtls_connection *d, struct packet_stream *ps, in
d->active = active ? 1 : 0;
random_string(d->tls_id, sizeof(d->tls_id));
while (memcmp(d->tls_id, (unsigned char [sizeof(d->tls_id)]) {0}, sizeof(d->tls_id)) == 0)
random_string(d->tls_id, sizeof(d->tls_id));
done:
return 0;
@ -1007,22 +1036,11 @@ void dtls_shutdown(struct packet_stream *ps) {
ilogs(crypto, LOG_DEBUG, "Reuse SRTP crypto key");
}
void dtls_connection_cleanup(struct dtls_connection *c) {
if (c->ssl_ctx || c->ssl)
ilogs(crypto, LOG_DEBUG, "Resetting DTLS connection context");
if (c->ssl_ctx)
SSL_CTX_free(c->ssl_ctx);
if (c->ssl)
SSL_free(c->ssl);
if (!c->init) {
if (c->r_bio)
BIO_free(c->r_bio);
if (c->w_bio)
BIO_free(c->w_bio);
}
obj_release(c->sfd);
ZERO(*c);
// full reset including TLS ID
void dtls_connection_cleanup(struct dtls_connection *c) {
dtls_connection_reset(c);
ZERO(c->tls_id);
}

Loading…
Cancel
Save