Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Page:  1  2  next
Avatar
bauerj #1
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
Subject: Question on Getting Started
Hello!

I'm trying out this library, but I have been struggling with trying to start a connection.

I have an eval license and managed to get your demo Android client up and running. It can make connections successfully with some public xmpp servers that I have been using.

I am trying to replicate what your client and tutorial posted online, but I keep getting an exception thrown when I try to open a connection.

---> (Inner Exception #0) System.IO.IOException: Authentication failed because the remote party has closed the transport stream.

Here is what I have:

  1. using System;
  2. using Synergy;
  3. using Synergy.iOS;
  4. using Matrix.Xmpp;
  5. using static Synergy.MatrixDependencyService;
  6. using Matrix.Xmpp.Client;
  7. using Matrix.License;
  8.  
  9. [assembly: Xamarin.Forms.Dependency (typeof (MatrixImplementation))]
  10. namespace Synergy.iOS
  11. {
  12.     public class MatrixImplementation : IMatrixDependencyService
  13.     {
  14.         void XmppClient_OnLogin(object sender, Matrix.EventArgs e)
  15.         {
  16.             Console.WriteLine("Login");
  17.         }
  18.  
  19.         void XmppClient_OnError(object sender, Matrix.ExceptionEventArgs e)
  20.         {
  21.             Console.WriteLine(e.Exception);
  22.         }
  23.  
  24.         public MatrixImplementation() { }
  25.  
  26.         public XmppClient xmppClient = new XmppClient();
  27.  
  28.         string lic = @"I Have a license here";
  29.  
  30.         void IMatrixDependencyService.Connect()
  31.         {
  32.             xmppClient.OnError += XmppClient_OnError;
  33.             xmppClient.OnLogin += XmppClient_OnLogin;
  34.  
  35.             try
  36.             {
  37.                 Matrix.License.LicenseManager.SetLicense(lic);
  38.  
  39.                 xmppClient.Username = "myusername";
  40.                 xmppClient.XmppDomain = "randomDomain.com"  ;
  41.                                 xmppClient.Password = "password";
  42.  
  43.                                 xmppClient.Status = "Hello World";
  44.                                 xmppClient.Show = Matrix.Xmpp.Show.Chat;
  45.  
  46.                 xmppClient.Open();
  47.  
  48.             }
  49.             catch (Exception err)
  50.             {
  51.                 Console.WriteLine(err.Message);
  52.             }
  53.         }
  54.  
  55.         void IMatrixDependencyService.Disconnect()
  56.         {
  57.             xmppClient.Close();
  58.         }
  59.     }
  60. }

Thank you ahead of time, I appreciate any assistance that you can give me. Let me know if you need any additional information.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Can you post your XML logs?
Can this be a TLS exception?
Are you using valid SSL certs on the server?

Alex
Avatar
bauerj #3
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
Sure, here are my logs:

  1. SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="007jabber.com" version="1.0" >
  2. SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="007jabber.com" version="1.0" >
  3. SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="007jabber.com" version="1.0" >
  4. SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="007jabber.com" version="1.0" >
  5. SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="007jabber.com" version="1.0" >
  6. RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="9972759243997872873" from="007jabber.com" version="1.0" xml:lang="en" >
  7. RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="9972759243997872873" from="007jabber.com" version="1.0" xml:lang="en" >
  8. RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="9972759243997872873" from="007jabber.com" version="1.0" xml:lang="en" >
  9. RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="9972759243997872873" from="007jabber.com" version="1.0" xml:lang="en" >
  10. RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="9972759243997872873" from="007jabber.com" version="1.0" xml:lang="en" >
  11. RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  12.  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="xCtUmQGWLCugQrH87qawGGXe5gM=" />
  13.  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  14.     <required />
  15.  </starttls>
  16. </stream:features>
  17. RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  18.  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="xCtUmQGWLCugQrH87qawGGXe5gM=" />
  19.  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  20.     <required />
  21.  </starttls>
  22. </stream:features>
  23. RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  24.  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="xCtUmQGWLCugQrH87qawGGXe5gM=" />
  25.  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  26.     <required />
  27.  </starttls>
  28. </stream:features>
  29. RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  30.  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="xCtUmQGWLCugQrH87qawGGXe5gM=" />
  31.  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  32.     <required />
  33.  </starttls>
  34. </stream:features>
  35. RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  36.  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="xCtUmQGWLCugQrH87qawGGXe5gM=" />
  37.  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  38.     <required />
  39.  </starttls>
  40. </stream:features>
  41. SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  42. SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  43. SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  44. SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  45. SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  46. RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  47. RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  48. RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  49. RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  50. RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  51. SEND: </stream:stream>
  52. SEND: </stream:stream>
  53. SEND: </stream:stream>
  54. SEND: </stream:stream>
  55. SEND: </stream:stream>

I'm not sure how to answer the other two questions. I know that the server I am using (007jabber.com) can handle a connection that requires TLS encryption. I am not sure if the server is using valid SSL certs.
This post was edited on 2018-07-10, 18:12 by Alex.
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
every package is 4 times in your logs. Is this an issue with your logging code, or are you connecting 4 times for some reason?

When I validate this server on xmpp.net I get warnings which could explain the authentication exception which seems to come from the Mono TLS stack.

See:
https://xmpp.net/result.p…?domain=007jabber.com&type=…
This post was edited on 2018-07-10, 18:34 by Alex.
Avatar
Alex #5
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Also, have you tried to subscribe to the certificate callbacks as described here in the docs?
https://www.ag-software.net/matrix-xmpp-sdk/matrix-develop…
Avatar
bauerj #6
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
I have not. I'll try that out. Thank you!
Avatar
bauerj #7
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
I am still getting the same error. I cannot seem to get the Validate Certificate event listener to trip. I have a few breakpoints to try and figure out what it going on. The OnTls event trips, so I know that it is trying to establish this connection. But, it skips over the OnValidateCertifictae listener and throws an error.

I also am trying a different server that has a better certificate score: https://xmpp.net/result.php?id=505565

Am I validating the certificate incorrectly?

  1. using System;
  2. using Synergy;
  3. using Synergy.iOS;
  4. using Matrix.Xmpp;
  5. using static Synergy.MatrixDependencyService;
  6. using Matrix.Xmpp.Client;
  7. using Matrix.License;
  8. using System.IO;
  9.  
  10. [assembly: Xamarin.Forms.Dependency (typeof (MatrixImplementation))]
  11. namespace Synergy.iOS
  12. {
  13.     public class MatrixImplementation : IMatrixDependencyService
  14.     {
  15.  
  16.         // Listeners for debugging
  17.         void XmppClient_OnTls(object sender, Matrix.EventArgs e)
  18.         {
  19.             Console.WriteLine("OnTls");
  20.         }
  21.  
  22.  
  23.         void XmppClient_OnLogin(object sender, Matrix.EventArgs e)
  24.         {
  25.             Console.WriteLine("Junk");  
  26.         }
  27.  
  28.  
  29.         void XmppClient_OnValidateCertificate(object sender, Matrix.CertificateEventArgs e)
  30.         {
  31.             e.AcceptCertificate = true;
  32.         }
  33.  
  34.  
  35.         void XmppClient_OnError(object sender, Matrix.ExceptionEventArgs e)
  36.         {
  37.             Console.WriteLine(e.Exception);
  38.         }
  39.  
  40.         // XML Logging
  41.         void XmppClient_OnSendXml(object sender, Matrix.TextEventArgs e)
  42.         {
  43.             AddDebug("SEND: " + e.Text);
  44.         }
  45.  
  46.         void XmppClient_OnReceiveXml(object sender, Matrix.TextEventArgs e)
  47.         {
  48.             AddDebug("RECV: " + e.Text);
  49.         }
  50.  
  51.         // Helper function for writing logs to a file
  52.         void AddDebug(string debug)
  53.         {
  54.             if (!File.Exists(path)){
  55.                 File.Create(path);
  56.                 TextWriter textWriter = new StreamWriter(path);
  57.                 textWriter.WriteLine(debug);
  58.                 textWriter.Close();
  59.             } else if (File.Exists(path)){
  60.                 using (var textWriter = new StreamWriter(path, true))
  61.                 {
  62.                     textWriter.WriteLine(debug);
  63.                 }
  64.             }
  65.         }
  66.  
  67.         public MatrixImplementation() { }
  68.  
  69.         public XmppClient xmppClient = new XmppClient();
  70.         public string debugText;
  71.         public string path = "/Users/numberthree/xamarinWebchat/logs.txt";
  72.  
  73.         string lic = @"My Lic is here";
  74.  
  75.  
  76.         void IMatrixDependencyService.Connect()
  77.         {
  78.             xmppClient.OnError += XmppClient_OnError;
  79.             xmppClient.OnReceiveXml += XmppClient_OnReceiveXml;
  80.             xmppClient.OnSendXml += XmppClient_OnSendXml;
  81.             xmppClient.OnValidateCertificate += XmppClient_OnValidateCertificate;
  82.             xmppClient.OnLogin += XmppClient_OnLogin;
  83.             xmppClient.OnTls += XmppClient_OnTls;
  84.  
  85.             try
  86.             {
  87.  
  88.                 Matrix.License.LicenseManager.SetLicense(lic);
  89.  
  90.                 xmppClient.Username = "myusernameishere";
  91.                 xmppClient.XmppDomain = "creep.im";
  92.                                 xmppClient.Password = "mypasswordishere";
  93.  
  94.                 xmppClient.Open();
  95.  
  96.             }
  97.             catch (Exception err)
  98.             {
  99.                 Console.WriteLine(err.Message);
  100.             }
  101.         }
  102.  
  103.         void IMatrixDependencyService.Disconnect()
  104.         {
  105.             xmppClient.Close();
  106.         }
  107.     }
  108. }

Here are my logs again:

  1. SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="creep.im" version="1.0" >
  2. RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="17835848626759151617" version="1.0" xml:lang="en" from="creep.im" xmlns="jabber:client" >
  3. RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  4.  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
  5.     <required />
  6.  </starttls>
  7.  </stream:features>
  8. SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  9. RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />

Thank again for your speedy responses. I really appreciate it.
This post was edited on 2018-07-13, 10:48 by Alex.
Avatar
Alex #8
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You have not mentioned yet which platform and Matrix packages you are using exactly.
Are you on Xamarin? Or Unity with Mono?
On Xamarin iOS you can also switch the underlying SSL/TLS stack between managed and native. Have you tried this?

See also:
https://forum.ag-software.net/thread/1873-Xamarin-iOS-disc…

Alex
Avatar
bauerj #9
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
Sorry! That's probably pretty important to mention. I'm using it on Xamarin. I'll try switching the SSL/TLS stack.
Avatar
bauerj #10
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
I wasn't aware that you guys had separate libraries for Xamarin either. I'll try these also and see what happens.
Avatar
bauerj #11
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
Also, I have done some digging, and I do not think that the option to choose which TLS stack exists anymore for iOS projects.

https://docs.microsoft.com/en-us/xamarin/cross-p…?tabs=m…
Avatar
Alex #12
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Yes, looks like managed TLS is gone in latest iOS builds.
Can you attach your test project code and exact Xamarin versions?
Will try to debug when I have some spare time.

Alex
Avatar
bauerj #13
Member since Jul 2018 · 9 posts
Group memberships: Members
Show profile · Link to this post
I put my project up on a public repo, thought it would be easier than attaching a bunch of files and forgetting some.

https://gitlab.com/bauerj/xmppXamarin

I believe it is Xamarin.Forms 3.1.0.
Avatar
Alex #14
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Traveling right now and have only a windows machine. Will try to reproduce with your code when I am back to the office end of next week.

Alex
This post was edited on 2018-07-16, 10:09 by Alex.
Avatar
Alex #15
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

sorry for the delay. I was able to debug your code on a Mac now.
The issue seems to be that you do not enable latest TLS versions 1.1 and 1.2.

an you please add the following to your code when you setup the XmppClient?

  1. using System.Security.Authentication;
  2.  
  3. xmppClient.TlsProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;

On MatriX for Xamarin Android by default only Tls 1.0 is enabled, because older versions did not support latest Tls protocols.
It is in our backlog to change the defaults with the next update, because ols Tls versions are getting disabled by most services now.

Please let me know if this change works for you.

Best,
Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next