aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0176_jingle_ice_udp
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-04-08 12:07:04 +0200
committerfiaxh <git@lightrise.org>2021-04-09 22:23:13 +0200
commit8d1c6c29be7018c74ec3f8ea05f5849eac5b4069 (patch)
treedde27c13cd0ae8af31b9194b3450c58d4fe9cf02 /xmpp-vala/src/module/xep/0176_jingle_ice_udp
parent3454201e5a3da058ccbef0bbaf467599912a8c38 (diff)
downloaddino-8d1c6c29be7018c74ec3f8ea05f5849eac5b4069.tar.gz
dino-8d1c6c29be7018c74ec3f8ea05f5849eac5b4069.zip
Display+store call encryption info
Diffstat (limited to 'xmpp-vala/src/module/xep/0176_jingle_ice_udp')
-rw-r--r--xmpp-vala/src/module/xep/0176_jingle_ice_udp/jingle_ice_udp_module.vala4
-rw-r--r--xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala47
2 files changed, 41 insertions, 10 deletions
diff --git a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/jingle_ice_udp_module.vala b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/jingle_ice_udp_module.vala
index 4b7c7a36..5211e3a9 100644
--- a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/jingle_ice_udp_module.vala
+++ b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/jingle_ice_udp_module.vala
@@ -5,6 +5,7 @@ using Xmpp;
namespace Xmpp.Xep.JingleIceUdp {
private const string NS_URI = "urn:xmpp:jingle:transports:ice-udp:1";
+public const string DTLS_NS_URI = "urn:xmpp:jingle:apps:dtls:0";
public abstract class Module : XmppStreamModule, Jingle.Transport {
public static Xmpp.ModuleIdentity<Module> IDENTITY = new Xmpp.ModuleIdentity<Module>(NS_URI, "0176_jingle_ice_udp");
@@ -12,10 +13,11 @@ public abstract class Module : XmppStreamModule, Jingle.Transport {
public override void attach(XmppStream stream) {
stream.get_module(Jingle.Module.IDENTITY).register_transport(this);
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
- stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, "urn:xmpp:jingle:apps:dtls:0");
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, DTLS_NS_URI);
}
public override void detach(XmppStream stream) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).remove_feature(stream, NS_URI);
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).remove_feature(stream, DTLS_NS_URI);
}
public override string get_ns() { return NS_URI; }
diff --git a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala
index 3c69d0af..f194f06d 100644
--- a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala
+++ b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala
@@ -13,8 +13,9 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
public ConcurrentList<Candidate> unsent_local_candidates = new ConcurrentList<Candidate>(Candidate.equals_func);
public Gee.List<Candidate> remote_candidates = new ArrayList<Candidate>(Candidate.equals_func);
- public string? own_fingerprint = null;
- public string? peer_fingerprint = null;
+ public uint8[]? own_fingerprint = null;
+ public uint8[]? peer_fingerprint = null;
+ public string? peer_fp_algo = null;
public Jid local_full_jid { get; private set; }
public Jid peer_full_jid { get; private set; }
@@ -24,7 +25,7 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
public bool incoming { get; private set; default = false; }
private bool connection_created = false;
- private weak Jingle.Content? content = null;
+ protected weak Jingle.Content? content = null;
protected IceUdpTransportParameters(uint8 components, Jid local_full_jid, Jid peer_full_jid, StanzaNode? node = null) {
this.components_ = components;
@@ -38,9 +39,10 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
remote_candidates.add(Candidate.parse(candidateNode));
}
- StanzaNode? fingerprint_node = node.get_subnode("fingerprint", "urn:xmpp:jingle:apps:dtls:0");
+ StanzaNode? fingerprint_node = node.get_subnode("fingerprint", DTLS_NS_URI);
if (fingerprint_node != null) {
- peer_fingerprint = fingerprint_node.get_deep_string_content();
+ peer_fingerprint = fingerprint_to_bytes(fingerprint_node.get_deep_string_content());
+ peer_fp_algo = fingerprint_node.get_attribute("hash");
}
}
}
@@ -67,10 +69,10 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
.put_attribute("pwd", local_pwd);
if (own_fingerprint != null) {
- var fingerprint_node = new StanzaNode.build("fingerprint", "urn:xmpp:jingle:apps:dtls:0")
+ var fingerprint_node = new StanzaNode.build("fingerprint", DTLS_NS_URI)
.add_self_xmlns()
.put_attribute("hash", "sha-256")
- .put_node(new StanzaNode.text(own_fingerprint));
+ .put_node(new StanzaNode.text(format_fingerprint(own_fingerprint)));
if (incoming) {
fingerprint_node.put_attribute("setup", "active");
} else {
@@ -95,9 +97,10 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
remote_candidates.add(Candidate.parse(candidateNode));
}
- StanzaNode? fingerprint_node = node.get_subnode("fingerprint", "urn:xmpp:jingle:apps:dtls:0");
+ StanzaNode? fingerprint_node = node.get_subnode("fingerprint", DTLS_NS_URI);
if (fingerprint_node != null) {
- peer_fingerprint = fingerprint_node.get_deep_string_content();
+ peer_fingerprint = fingerprint_to_bytes(fingerprint_node.get_deep_string_content());
+ peer_fp_algo = fingerprint_node.get_attribute("hash");
}
}
@@ -138,4 +141,30 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
content.send_transport_info(to_transport_stanza_node());
}
}
+
+
+
+ private string format_fingerprint(uint8[] fingerprint) {
+ var sb = new StringBuilder();
+ for (int i = 0; i < fingerprint.length; i++) {
+ sb.append("%02x".printf(fingerprint[i]));
+ if (i < fingerprint.length - 1) {
+ sb.append(":");
+ }
+ }
+ return sb.str;
+ }
+
+ private uint8[] fingerprint_to_bytes(string? fingerprint_) {
+ if (fingerprint_ == null) return null;
+
+ string fingerprint = fingerprint_.replace(":", "").up();
+
+ uint8[] bin = new uint8[fingerprint.length / 2];
+ const string HEX = "0123456789ABCDEF";
+ for (int i = 0; i < fingerprint.length / 2; i++) {
+ bin[i] = (uint8) (HEX.index_of_char(fingerprint[i*2]) << 4) | HEX.index_of_char(fingerprint[i*2+1]);
+ }
+ return bin;
+ }
} \ No newline at end of file