aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core/starttls_xmpp_stream.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-11-16 15:55:33 +0100
committerfiaxh <git@lightrise.org>2020-11-20 15:21:18 +0100
commit07917f1d841f449157aa3aaa2507b0547dd274e7 (patch)
tree315ef3bc243491565d3d5097968dca38d67a7eab /xmpp-vala/src/core/starttls_xmpp_stream.vala
parent881b9eec9dcd8fd8c81b0b9d7bfd2ae714d7722e (diff)
downloaddino-07917f1d841f449157aa3aaa2507b0547dd274e7.tar.gz
dino-07917f1d841f449157aa3aaa2507b0547dd274e7.zip
Refactor XmppStream, TLS and connection method logic
fixes #534
Diffstat (limited to 'xmpp-vala/src/core/starttls_xmpp_stream.vala')
-rw-r--r--xmpp-vala/src/core/starttls_xmpp_stream.vala54
1 files changed, 54 insertions, 0 deletions
diff --git a/xmpp-vala/src/core/starttls_xmpp_stream.vala b/xmpp-vala/src/core/starttls_xmpp_stream.vala
new file mode 100644
index 00000000..3df0dffb
--- /dev/null
+++ b/xmpp-vala/src/core/starttls_xmpp_stream.vala
@@ -0,0 +1,54 @@
+public class Xmpp.StartTlsXmppStream : TlsXmppStream {
+
+ private const string TLS_NS_URI = "urn:ietf:params:xml:ns:xmpp-tls";
+
+ string host;
+ uint16 port;
+
+ public StartTlsXmppStream(Jid remote, string host, uint16 port) {
+ this.remote_name = remote;
+ this.host = host;
+ this.port = port;
+ }
+
+ public override async void connect() throws IOStreamError {
+ try {
+ SocketClient client = new SocketClient();
+ debug("Connecting to %s %i (starttls)", host, port);
+ IOStream stream = yield client.connect_to_host_async(host, port);
+ reset_stream(stream);
+
+ yield setup();
+
+ StanzaNode node = yield read();
+ var starttls_node = node.get_subnode("starttls", TLS_NS_URI);
+ if (starttls_node == null) {
+ warning("%s does not offer starttls", remote_name.to_string());
+ }
+
+ write(new StanzaNode.build("starttls", TLS_NS_URI).add_self_xmlns());
+
+ node = yield read();
+
+ if (node.ns_uri != TLS_NS_URI || node.name != "proceed") {
+ warning("Server did not 'proceed' starttls request");
+ }
+
+ try {
+ var identity = new NetworkService("xmpp-client", "tcp", remote_name.to_string());
+ var conn = TlsClientConnection.new(get_stream(), identity);
+ reset_stream(conn);
+
+ conn.accept_certificate.connect(on_invalid_certificate);
+ } catch (Error e) {
+ stderr.printf("Failed to start TLS: %s\n", e.message);
+ }
+
+ yield setup();
+
+ attach_negotation_modules();
+ } catch (Error e) {
+ throw new IOStreamError.CONNECT("Failed connecting to %s:%i (starttls): %s", host, port, e.message);
+ }
+ }
+} \ No newline at end of file