Handle DTLS edge-cases

This commit is contained in:
Marvin W 2021-04-12 18:05:08 +02:00
parent fe160d94ba
commit d19a01d5f2
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
3 changed files with 21 additions and 4 deletions

View file

@ -153,7 +153,13 @@ public class Handler {
DateTime current_time = new DateTime.now_utc(); DateTime current_time = new DateTime.now_utc();
if (maximum_time.compare(current_time) < 0) { if (maximum_time.compare(current_time) < 0) {
warning("DTLS handshake timeouted"); warning("DTLS handshake timeouted");
return ErrorCode.APPLICATION_ERROR_MIN + 1; err = ErrorCode.APPLICATION_ERROR_MIN + 1;
break;
}
if (stop) {
debug("DTLS handshake stopped");
err = ErrorCode.APPLICATION_ERROR_MIN + 2;
break;
} }
} while (err < 0 && !((ErrorCode)err).is_fatal()); } while (err < 0 && !((ErrorCode)err).is_fatal());
Idle.add(setup_dtls_connection.callback); Idle.add(setup_dtls_connection.callback);
@ -167,11 +173,17 @@ public class Handler {
running = false; running = false;
bool restart = restart; bool restart = restart;
buffer_mutex.unlock(); buffer_mutex.unlock();
if (restart) return yield setup_dtls_connection(); if (restart) {
debug("Restarting DTLS handshake");
return yield setup_dtls_connection();
}
return null; return null;
} }
buffer_mutex.unlock(); buffer_mutex.unlock();
throw_if_error(err); if (err != ErrorCode.SUCCESS) {
warning("DTLS handshake failed: %s", ((ErrorCode)err).to_string());
return null;
}
uint8[] km = new uint8[150]; uint8[] km = new uint8[150];
Datum? client_key, client_salt, server_key, server_salt; Datum? client_key, client_salt, server_key, server_salt;
@ -199,6 +211,7 @@ public class Handler {
self.buffer_cond.wait(self.buffer_mutex); self.buffer_cond.wait(self.buffer_mutex);
if (self.stop) { if (self.stop) {
self.buffer_mutex.unlock(); self.buffer_mutex.unlock();
debug("DTLS handshake pull_function stopped");
return -1; return -1;
} }
} }
@ -222,6 +235,7 @@ public class Handler {
self.buffer_cond.wait_until(self.buffer_mutex, end_time); self.buffer_cond.wait_until(self.buffer_mutex, end_time);
if (self.stop) { if (self.stop) {
self.buffer_mutex.unlock(); self.buffer_mutex.unlock();
debug("DTLS handshake pull_timeout_function stopped");
return -1; return -1;
} }

View file

@ -156,6 +156,9 @@ public class Dino.Plugins.Ice.TransportParameters : JingleIceUdp.IceUdpTransport
if (peer_setup == "passive") { if (peer_setup == "passive") {
dtls_srtp_handler.mode = DtlsSrtp.Mode.CLIENT; dtls_srtp_handler.mode = DtlsSrtp.Mode.CLIENT;
dtls_srtp_handler.stop_dtls_connection(); dtls_srtp_handler.stop_dtls_connection();
dtls_srtp_handler.setup_dtls_connection.begin((_, res) => {
this.content.encryption = dtls_srtp_handler.setup_dtls_connection.end(res) ?? this.content.encryption;
});
} }
} else { } else {
dtls_srtp_handler = null; dtls_srtp_handler = null;

View file

@ -98,7 +98,7 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
StanzaNode? fingerprint_node = node.get_subnode("fingerprint", DTLS_NS_URI); StanzaNode? fingerprint_node = node.get_subnode("fingerprint", DTLS_NS_URI);
if (fingerprint_node != null) { if (fingerprint_node != null) {
peer_fingerprint = fingerprint_to_bytes(fingerprint_node.get_deep_string_content()); peer_fingerprint = fingerprint_to_bytes(fingerprint_node.get_string_content());
peer_fp_algo = fingerprint_node.get_attribute("hash"); peer_fp_algo = fingerprint_node.get_attribute("hash");
peer_setup = fingerprint_node.get_attribute("setup"); peer_setup = fingerprint_node.get_attribute("setup");
} }