Not logged in. · Lost password · Register
Forum: MatriX RSS
Page: previous  1  2 
Avatar
Alex #16
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post ID 10818
new need to write an implementation of ITlsHandlerProvider and set it in Matrix.
See here for the current default implementation:
https://github.com/matrix-xmpp/matrix-vnext/blob/master/sr…

Alex
Avatar
Brad #17
Member since Jun 2019 · 7 posts
Group memberships: Members
Show profile · Link to this post
Got it, thanks!
Avatar
Alex #18
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
And you need to add the code from the PR I linked directly to your code base. You should also adjust the class names or namespace to prevent conflicts
Avatar
Brad #19
Member since Jun 2019 · 7 posts
Group memberships: Members
Show profile · Link to this post
Sorry - one more issue. I had this working before with

  1. xmppClient.CertificateValidator = new AlwaysAcceptCertificateValidator();

but now it seems to not be working. I get the states 'Connected' > 'Securing' > 'Disconnected'.

I'm pretty sure it's in the
  1. this.sslStream.AuthenticateAsClientAsync
part of the custom TlsHandler so it's just not respecting the AlwaysAcceptCertificateValidator or I've got it in the wrong spot now.
This post was edited on 2019-12-22, 10:04 by Alex.
Avatar
Alex #20
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
in the DefaultTlsHandler we set the CertificateValidator from the XmppClient here:
https://github.com/matrix-xmpp/matrix-vnext/blob/7da775b17…

You don't have to use the one from the XmppClient, you can create one directly in your ITlsHandlerProvider implementation.
I kept it as it because I did not want to cause breaking API changes for now.

Alex
Avatar
Brad #21
Member since Jun 2019 · 7 posts
Group memberships: Members
Show profile · Link to this post
I'm trying with this syntax but I get the same results

  1.  var tlsSettings = await xmppClient.TlsSettingsProvider.ProvideAsync(xmppClient);
  2.  var alwaysAcceptCertificateValidator = new AlwaysAcceptCertificateValidator();
  3.  
  4.  return new CustomMonoTlsHandler.TlsHandler(
  5.     stream => new SslStream(
  6.       stream,
  7.       true,
  8.       alwaysAcceptCertificateValidator.RemoteCertificateValidationCallback
  9.     ),
  10.     tlsSettings);
Avatar
Alex #22
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
are you sure the problem is the CertificateValidator?
Have you tried to debug everything and step through?

Alex
Avatar
Brad #23
Member since Jun 2019 · 7 posts
Group memberships: Members
Show profile · Link to this post
I'm not sure it's the validator, but it does seem to be failing because of some kind of cert / auth issue. It's connecting, it just doesn't seem to make it all the way.

XMPP SEND:: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="im.contactatonce.com" version="1.0" >
XMPP RECV:: <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='3688202177' from='im.mydomain.com' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
[Mono] Loading reference 6 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/DotNetty.Handlers.dll asmctx DEFAULT, looking for DotNetty.Codecs, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref DotNetty.Handlers[0x7132cb6180] -> DotNetty.Codecs[0x7132d13f80]: 3
[Mono] Loading reference 5 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/LPA.Platforms.Connect.dll asmctx DEFAULT, looking for CustomMonoTlsHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref LPA.Platforms.Connect[0x712044ef80] -> CustomMonoTlsHandler[0x7120464080]: 2
[Mono] Loading reference 2 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/CustomMonoTlsHandler.dll asmctx DEFAULT, looking for DotNetty.Codecs, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref CustomMonoTlsHandler[0x7120464080] -> DotNetty.Codecs[0x7132d13f80]: 4
Loaded assembly: System.Security.Cryptography.X509Certificates.dll [External]
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/DotNetty.Codecs.dll asmctx DEFAULT, looking for DotNetty.Buffers, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref DotNetty.Codecs[0x7132d13f80] -> DotNetty.Buffers[0x7132d13e80]: 5
[Mono] Loading reference 1 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/CustomMonoTlsHandler.dll asmctx DEFAULT, looking for DotNetty.Handlers, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref CustomMonoTlsHandler[0x7120464080] -> DotNetty.Handlers[0x7132cb6180]: 4
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/CustomMonoTlsHandler.dll asmctx DEFAULT, looking for DotNetty.Common, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref CustomMonoTlsHandler[0x7120464080] -> DotNetty.Common[0x7132cb6080]: 6
[Mono] Loading reference 4 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/CustomMonoTlsHandler.dll asmctx DEFAULT, looking for DotNetty.Transport, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref CustomMonoTlsHandler[0x7120464080] -> DotNetty.Transport[0x7132cb6280]: 6
[Mono] Loading reference 5 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/CustomMonoTlsHandler.dll asmctx DEFAULT, looking for DotNetty.Buffers, Version=0.6.0.0, Culture=neutral, PublicKeyToken=bc13ca065fa06c29
[Mono] Assembly Ref addref CustomMonoTlsHandler[0x7120464080] -> DotNetty.Buffers[0x7132d13e80]: 6
[Mono] Loading reference 4 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/DotNetty.Handlers.dll asmctx DEFAULT, looking for System.Net.Primitives, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[Mono] Assembly Ref addref DotNetty.Handlers[0x7132cb6180] -> System.Net.Primitives[0x7119257280]: 4
[Mono] Loading reference 2 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/DotNetty.Handlers.dll asmctx DEFAULT, looking for System.Security.Cryptography.X509Certificates, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[Mono] Image addref System.Security.Cryptography.X509Certificates[0x71164fb000] (asmctx DEFAULT) -> System.Security.Cryptography.X509Certificates.dll[0x711d4f6800]: 2
[Mono] Prepared to set up assembly 'System.Security.Cryptography.X509Certificates' (System.Security.Cryptography.X509Certificates.dll)
[Mono] Assembly System.Security.Cryptography.X509Certificates[0x71164fb000] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Security.Cryptography.X509Certificates.dll.so' not found: dlopen failed: library "System.Security.Cryptography.X509Certificates.dll.so" not found
[Mono] AOT: image '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-arm64-v8a-release/lib/mono/aot-cache/arm64/System.Security.Cryptography.X509Certificates.dll.so' not found: (null)
[Mono] Config attempting to parse: 'System.Security.Cryptography.X509Certificates.dll.config'.
[Mono] Config attempting to parse: '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-arm64-v8a-release/etc/mono/assemblies/System.Security.Cryptography.X509Certificates/System.Security.Cryptography.X509Certificates.config'.
[Mono] Assembly Ref addref DotNetty.Handlers[0x7132cb6180] -> System.Security.Cryptography.X509Certificates[0x71164fb000]: 2
[Mono] Loading reference 1 of System.Security.Cryptography.X509Certificates.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref System.Security.Cryptography.X509Certificates[0x71164fb000] -> System[0x7120464480]: 20
[Mono] Loading reference 0 of System.Security.Cryptography.X509Certificates.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref System.Security.Cryptography.X509Certificates[0x71164fb000] -> mscorlib[0x7132c8fd80]: 132
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.cao.chat/files/.__override__/DotNetty.Handlers.dll asmctx DEFAULT, looking for System.Collections, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[Mono] Assembly Ref addref DotNetty.Handlers[0x7132cb6180] -> System.Collections[0x711ece3900]: 9
Resolved pending breakpoint at 'TlsHandler.cs:102,1' to void CustomMonoTlsHandler.TlsHandler.ExceptionCaught (DotNetty.Transport.Channels.IChannelHandlerContext context, System.Exception exception) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:119,1' to bool CustomMonoTlsHandler.TlsHandler.IgnoreException (System.Exception t) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:737,1' to void CustomMonoTlsHandler.TlsHandler.HandleFailure (System.Exception cause) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:765,1' to void CustomMonoTlsHandler.TlsHandler.NotifyHandshakeFailure (System.Exception cause) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:188,1' to void CustomMonoTlsHandler.TlsHandler.Decode (DotNetty.Transport.Channels.IChannelHandlerContext context, DotNetty.Buffers.IByteBuffer input, System.Collections.Generic.List<object> output) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:128,1' to void CustomMonoTlsHandler.TlsHandler.HandleHandshakeCompleted (System.Threading.Tasks.Task task, object state) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:582,1' to bool CustomMonoTlsHandler.TlsHandler.EnsureAuthenticated () [0x00072].
Resolved pending breakpoint at 'TlsHandler.cs:83,1' to void CustomMonoTlsHandler.TlsHandler.ChannelActive (DotNetty.Transport.Channels.IChannelHandlerContext context) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:319,1' to void CustomMonoTlsHandler.TlsHandler.Unwrap (DotNetty.Transport.Channels.IChannelHandlerContext ctx, DotNetty.Buffers.IByteBuffer packet, int offset, int length, System.Collections.Generic.List<int> packetLengths, System.Collections.Generic.List<object> output) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:471,1' to void CustomMonoTlsHandler.TlsHandler.UnwrapCompleted (System.Threading.Tasks.Task<int> task, object state) [0x00001].
Resolved pending breakpoint at 'TlsHandler.cs:586,1' to bool CustomMonoTlsHandler.TlsHandler.EnsureAuthenticated () [0x000b8].
Resolved pending breakpoint at 'TlsHandler.cs:589,1' to bool CustomMonoTlsHandler.TlsHandler.EnsureAuthenticated () [0x000bd].
[Mono] Loading reference 1 of Mono.Security.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[Mono] Unloading image System.dll [0x711ce3e000].
[Mono] Image addref System[0x71164fb300] (asmctx DEFAULT) -> System.dll[0x7120463800]: 5
[Mono] Config attempting to parse: 'System.dll.config'.
[Mono] Config attempting to parse: '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-arm64-v8a-release/etc/mono/assemblies/System/System.config'.
[Mono] Assembly Ref addref Mono.Security[0x7120464500] -> System[0x7120464480]: 21
XMPP SEND:: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
XMPP RECV:: <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
XMPP SEND:: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="im.mydomain.com" version="1.0" >
Avatar
Brad #24
Member since Jun 2019 · 7 posts
Group memberships: Members
Show profile · Link to this post
Nevermind, I'm an idiot. :) I think I've got it working now.
Avatar
Alex #25
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
great, let us know if your problems are solved.
And maybe how you solved them in case other readers here run into similar issues,

Alex
Avatar
Brad #26
Member since Jun 2019 · 7 posts
Group memberships: Members
Show profile · Link to this post
great, let us know if your problems are solved.

Yup, looks like it. I'm checking in my code now and sending it off for PR.

I had two issues.

One, if you take the code from the PR at the start of this thread you, of course, get all of the DotNetty files. I was able to get that down to half a dozen files, but it turns out that you don't even need that many. When Matrix was calling my custom handler it was getting exceptions trying to convert between my custom types and the DotNetty types. I believe you actually gave a warning about this exact scenario and to use a different namespace. I did use a different namespace but still wound up in the same trap by using the same class names. It wouldn't have been too bad but the exceptions were not throwing and were just being eaten by Xamarin. :(

Here is the PR as a GitHub Gist with only the four files you need to get this to work:

https://gist.github.com/TrueGeek/960641d12e42d477bf8f35e73…

Two - in line 583 of the TlsHandler above it wanted to use a 509 collection in the ClientTlsSettings. There isn't such a thing. So I just sent 'null' instead.

Thank you so much for your help with this Alex. You made a long work weekend a bit more bearable. Fröhliche Weihnachten
Avatar
Alex #27
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Brad,

thanks for posting your codes. This will help other developers as well.
In your case it would be easier to rename the class of TlsHandler to CustomMonoTlsHandler only and keep the namespaces.
Then you can rely on the default DotNetty classes and lower the amount of files you need to add. The other classes you added see to be all public and should not be required when you keep the original namespace and rename the TlsHandler.

Alex
Avatar
Alex #28
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I published a branch named xamarin-tls here which includes a TlsHandler for Mono/Xamarin:
https://github.com/matrix-xmpp/matrix-vnext/tree/xamarin-tls

in /src/Matrix.Tls.Mono there is a TlsHandler which includes the Mono fixed. I am travelling for a while and don't have a Mac with me. It would be great if someone who that the issues discussed in the thread could test this code.

If it works fine I can publish an official NuGet package for this Tls provider.

Alex
Avatar
Alex #29
Member since Feb 2003 · 4363 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
It looks like this issue was addressed now in Xamarin.
See:
https://github.com/mono/mono/issues/18865
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: previous  1  2 
Forum: MatriX RSS