aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala
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
parent3454201e5a3da058ccbef0bbaf467599912a8c38 (diff)
downloaddino-8d1c6c29be7018c74ec3f8ea05f5849eac5b4069.tar.gz
dino-8d1c6c29be7018c74ec3f8ea05f5849eac5b4069.zip
Display+store call encryption info
Diffstat (limited to 'xmpp-vala')
-rw-r--r--xmpp-vala/src/module/xep/0166_jingle/content.vala9
-rw-r--r--xmpp-vala/src/module/xep/0167_jingle_rtp/content_parameters.vala3
-rw-r--r--xmpp-vala/src/module/xep/0167_jingle_rtp/stream.vala2
-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
5 files changed, 55 insertions, 10 deletions
diff --git a/xmpp-vala/src/module/xep/0166_jingle/content.vala b/xmpp-vala/src/module/xep/0166_jingle/content.vala
index 67c13dd8..bce03a7b 100644
--- a/xmpp-vala/src/module/xep/0166_jingle/content.vala
+++ b/xmpp-vala/src/module/xep/0166_jingle/content.vala
@@ -34,6 +34,8 @@ public class Xmpp.Xep.Jingle.Content : Object {
public weak Session session;
public Map<uint8, ComponentConnection> component_connections = new HashMap<uint8, ComponentConnection>(); // TODO private
+ public ContentEncryption? encryption { get; set; }
+
// INITIATE_SENT | INITIATE_RECEIVED | CONNECTING
public Set<string> tried_transport_methods = new HashSet<string>();
@@ -233,4 +235,11 @@ public class Xmpp.Xep.Jingle.Content : Object {
public void send_transport_info(StanzaNode transport) {
session.send_transport_info(this, transport);
}
+}
+
+public class Xmpp.Xep.Jingle.ContentEncryption : Object {
+ public string encryption_ns { get; set; }
+ public string encryption_name { get; set; }
+ public uint8[] our_key { get; set; }
+ public uint8[] peer_key { get; set; }
} \ No newline at end of file
diff --git a/xmpp-vala/src/module/xep/0167_jingle_rtp/content_parameters.vala b/xmpp-vala/src/module/xep/0167_jingle_rtp/content_parameters.vala
index ff3d31f4..ac65f88c 100644
--- a/xmpp-vala/src/module/xep/0167_jingle_rtp/content_parameters.vala
+++ b/xmpp-vala/src/module/xep/0167_jingle_rtp/content_parameters.vala
@@ -116,6 +116,9 @@ public class Xmpp.Xep.JingleRtp.Parameters : Jingle.ContentParameters, Object {
remote_crypto = null;
local_crypto = null;
}
+ if (remote_crypto != null && local_crypto != null) {
+ content.encryption = new Xmpp.Xep.Jingle.ContentEncryption() { encryption_ns = "", encryption_name = "SRTP", our_key=local_crypto.key, peer_key=remote_crypto.key };
+ }
this.stream = parent.create_stream(content);
rtp_datagram.datagram_received.connect(this.stream.on_recv_rtp_data);
diff --git a/xmpp-vala/src/module/xep/0167_jingle_rtp/stream.vala b/xmpp-vala/src/module/xep/0167_jingle_rtp/stream.vala
index 730ce9f8..adae11f5 100644
--- a/xmpp-vala/src/module/xep/0167_jingle_rtp/stream.vala
+++ b/xmpp-vala/src/module/xep/0167_jingle_rtp/stream.vala
@@ -1,5 +1,7 @@
public abstract class Xmpp.Xep.JingleRtp.Stream : Object {
+
public Jingle.Content content { get; protected set; }
+
public string name { get {
return content.content_name;
}}
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