Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
nir #1
Member since Aug 2021 · 11 posts
Group memberships: Members
Show profile · Link to this post
Subject: Matrix vNext Console Client Error
I'm running the Console Client of Matrix vNext Net5 Branch and I get the following:
At the call of await xmppClient.ConnectAsync();
System.IO.IOException: 'Cannot determine the frame size or a corrupted frame was received.'
This exception was originally thrown at this call stack:
    [External Code]
    Matrix.Transport.Socket.SocketTransport.InitTls(string) in SocketTransport.cs
    [External Code]
    Matrix.Transport.Socket.SocketTransport.ConnectAsync(string) in SocketTransport.cs
    [External Code]
    Matrix.XmppClient.ConnectAsync(System.Threading.CancellationToken) in XmppClient.cs
    [External Code]
    Matrix.XmppClient.ConnectAsync() in XmppClient.cs
    [External Code]
    ConsoleClient.Program.Main(string[]) in Program.cs

Thanks,
Nicholas
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
InitTls is the top of your stacktrace. I assume something is going wrong at TLS init with your server.

Alex
Avatar
Alex #3
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I was able to reproduce this error in an Android project. During SSL handshake it raises the following exception:

Ssl error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER

This seems to be an issue in Xamarin to me. I have not found a solution yet for this.

Alex
nir #4
Member since Aug 2021 · 11 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the update.
Is there any other way today, to run matrix vNext on Xamarin Forms Android with the current Nugget packages?
Avatar
Alex #5
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Have you tried this branch with the fixed/patched Mono Tls code?
https://github.com/matrix-xmpp/matrix-vnext/tree/xamarin-tls

There are also threads about this here in the forum.

I think I will file an issue in Microsofts GitHub with the net5 TLS issue if I cannot find a solution to it with some Google research.

I guess the best is probably to wait until Microsoft merged Mono finally with netcore. Because there are always problems where MONO behaves different that .NET. And for MatriX vNext we are not going to make hacks again for specific .NET platforms. Or use compiler conditions to create different binaries for different platforms.

Best,
Alex
nir #6
Member since Aug 2021 · 11 posts
Group memberships: Members
Show profile · Link to this post
I am trying with the Mono Tls code.

  1. xmppClient = new XmppClient()
  2.             {
  3.                 Username = "entersoft",
  4.                 Password = "testtest",
  5.                 XmppDomain = "xmpp.jp",
  6.                 HostnameResolver = new StaticNameResolver(IPAddress.Parse("133.125.37.233")),
  7.                 TlsHandlerProvider = new MonoTlsHandlerProvider()
  8.             };

[0:] State changed: Connected
Loaded assembly: /data/data/com.companyname.appclient/files/.__override__/System.Runtime.CompilerServices.Unsafe.dll [External]
?[40m?[32minfo?[39m?[22m?[49m: AppClient.App[0]
      SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="xmpp.jp" version="1.0" >
?[40m?[32minfo?[39m?[22m?[49m: AppClient.App[0]
      RECV: <?xml version='1.0'?><stream:stream id='14668281379043316013' version='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' from='xmpp.jp' xmlns='jabber:client'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls></stream:features>
[0:] State changed: Securing
Loaded assembly: /data/data/com.companyname.appclient/files/.__override__/System.Security.Cryptography.X509Certificates.dll [External]
?[40m?[32minfo?[39m?[22m?[49m: AppClient.App[0]
      SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
?[40m?[32minfo?[39m?[22m?[49m: AppClient.App[0]
      RECV: <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
?[40m?[32minfo?[39m?[22m?[49m: AppClient.App[0]
      SEND: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="xmpp.jp" version="1.0" >
[0:] State changed: Disconnected
This post was edited on 2021-09-07, 14:39 by Alex.
Avatar
Alex #7
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Do you see why it disconnects?
Do you see any exceptions?

Alex
nir #8
Member since Aug 2021 · 11 posts
Group memberships: Members
Show profile · Link to this post
No exceptions on Android. On uwp its working fine.
I added a Xamarin Forms (Xamarin 5) project inside the solution of the Matrix-vNext xamarin-tls branch.
Here is my code:
  1. using System;
  2. using Xamarin.Forms;
  3. using System.Reactive.Linq;
  4. using Matrix;
  5. using Matrix.Extensions.Client.Roster;
  6. using Matrix.Extensions.Client.Presence;
  7. using Matrix.Xmpp;
  8. using Matrix.Xmpp.Base;
  9. using System.Diagnostics;
  10. using Matrix.Network.Resolver;
  11. using System.Net;
  12. using Matrix.Tls.Mono;
  13. using System.Threading.Tasks;
  14.  
  15. namespace AppClient
  16. {
  17.     public partial class App : Application
  18.     {
  19.         private XmppClient xmppClient;
  20.  
  21.         public App()
  22.         {
  23.             InitializeComponent();
  24.  
  25.             MainPage = new MainPage();
  26.         }
  27.  
  28.         protected override void OnStart()
  29.         {
  30.             Task.Run(async () => {
  31.                 xmppClient = new XmppClient()
  32.                 {
  33.                     Username = "entersoft",
  34.                     Password = "testtest",
  35.                     XmppDomain = "xmpp.jp",
  36.                     HostnameResolver = new StaticNameResolver(IPAddress.Parse("133.125.37.233")),
  37.                 };
  38.  
  39.                 if (Device.RuntimePlatform != Device.UWP)
  40.                 {
  41.                     xmppClient.TlsHandlerProvider = new MonoTlsHandlerProvider();
  42.                 }
  43.  
  44.                 xmppClient.XmppSessionStateObserver.Subscribe(v => {
  45.                     Debug.WriteLine($"State changed: {v}");
  46.                 });
  47.  
  48.                 xmppClient
  49.                     .XmppXElementStreamObserver
  50.                     .Where(el => el is Presence)
  51.                     .Subscribe(el =>
  52.                     {
  53.                         Debug.WriteLine(el.ToString());
  54.                     });
  55.  
  56.                 xmppClient
  57.                     .XmppXElementStreamObserver
  58.                     .Where(el => el is Message)
  59.                     .Subscribe(el =>
  60.                     {
  61.                         Debug.WriteLine(el.ToString());
  62.                     });
  63.  
  64.                 xmppClient
  65.                     .XmppXElementStreamObserver
  66.                     .Where(el => el is Iq)
  67.                     .Subscribe(el =>
  68.                     {
  69.                         Debug.WriteLine(el.ToString());
  70.                     });
  71.  
  72.                 // Connect the XMPP connection
  73.                 await xmppClient.ConnectAsync();
  74.  
  75.                 // request the roster (aka contact list)
  76.                 var roster = await xmppClient.RequestRosterAsync();
  77.                 Debug.WriteLine(roster.ToString());
  78.  
  79.                 // Send our presence to the server
  80.                 xmppClient.SendPresenceAsync(Show.Chat, "free for chat").GetAwaiter().GetResult();
  81.             });
  82.            
  83.         }
  84.  
  85.         protected override async void OnSleep()
  86.         {
  87.             await xmppClient.DisconnectAsync();
  88.         }
  89.  
  90.         protected override void OnResume()
  91.         {
  92.         }
  93.     }
  94. }

BTW thanks for all your support,
Nicholas
This post was edited on 2021-09-07, 14:54 by Alex.
Avatar
Alex #9
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
It should not disconnect without a reason.
Can you add timestamps to your log messages? Is there a delay between TLS negotiation and disconnect?

It may be the same problem now ad on the net5 branch.
And as you can see the code works fine on other platforms and only fails on Xamarin because of some issues in Mono. I still think we should contact Microsoft and the Xamarin team to see why TLS in failing in Xamarin on Android.

Have you tried on iOS BTW?

Alex
nir #10
Member since Aug 2021 · 11 posts
Group memberships: Members
Show profile · Link to this post
I will try on iOS next week and I will update you.

DotNetty logging:
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] RECEIVED_COMPLETE
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] READ
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] RECEIVED_COMPLETE
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] EXCEPTION: DotNetty.Transport.Channels.ChannelPipelineException: TlsHandler.HandlerAdded() has thrown an exception; removed. ---> System.InvalidCastException: Specified cast is not valid.
        at Matrix.Tls.Mono.TlsHandler.EnsureAuthenticated () [0x00072] in C:\Users
ir\Source\Repos\matrix\src\Matrix.Tls.Mono\TlsHandler.cs:502
        at Matrix.Tls.Mono.TlsHandler.HandlerAdded (DotNetty.Transport.Channels.IChannelHandlerContext context) [0x00041] in C:\Users
ir\Source\Repos\matrix\src\Matrix.Tls.Mono\TlsHandler.cs:167
        at DotNetty.Transport.Channels.DefaultChannelPipeline.CallHandlerAdded0 (DotNetty.Transport.Channels.AbstractChannelHandlerContext ctx) [0x00006] in <0b1e95c3117b403b95bd433d56cb87f1>:0
         --- End of inner exception stack trace ---
DotNetty.Transport.Channels.ChannelPipelineException: TlsHandler.HandlerAdded() has thrown an exception; removed. ---> System.InvalidCastException: Specified cast is not valid.
  at Matrix.Tls.Mono.TlsHandler.EnsureAuthenticated () [0x00072] in C:\Users
ir\Source\Repos\matrix\src\Matrix.Tls.Mono\TlsHandler.cs:502
  at Matrix.Tls.Mono.TlsHandler.HandlerAdded (DotNetty.Transport.Channels.IChannelHandlerContext context) [0x00041] in C:\Users
ir\Source\Repos\matrix\src\Matrix.Tls.Mono\TlsHandler.cs:167
  at DotNetty.Transport.Channels.DefaultChannelPipeline.CallHandlerAdded0 (DotNetty.Transport.Channels.AbstractChannelHandlerContext ctx) [0x00006] in <0b1e95c3117b403b95bd433d56cb87f1>:0
   --- End of inner exception stack trace ---
�[40m�[1m�[33mwarn�[39m�[22m�[49m: DotNetty.Transport.Channels.DefaultChannelPipeline[0]
      An ExceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
DotNetty.Transport.Channels.ChannelPipelineException: TlsHandler.HandlerAdded() has thrown an exception; removed. ---> System.InvalidCastException: Specified cast is not valid.
  at Matrix.Tls.Mono.TlsHandler.EnsureAuthenticated () [0x00072] in C:\Users
ir\Source\Repos\matrix\src\Matrix.Tls.Mono\TlsHandler.cs:502
  at Matrix.Tls.Mono.TlsHandler.HandlerAdded (DotNetty.Transport.Channels.IChannelHandlerContext context) [0x00041] in C:\Users
ir\Source\Repos\matrix\src\Matrix.Tls.Mono\TlsHandler.cs:167
  at DotNetty.Transport.Channels.DefaultChannelPipeline.CallHandlerAdded0 (DotNetty.Transport.Channels.AbstractChannelHandlerContext ctx) [0x00006] in <0b1e95c3117b403b95bd433d56cb87f1>:0
   --- End of inner exception stack trace ---
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] WRITE: 113B
               +-------------------------------------------------+
               |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
      +--------+-------------------------------------------------+----------------+
      |100000000| 3C 73 74 72 65 61 6D 3A 73 74 72 65 61 6D 20 78 |<stream:stream x|
      |100000010| 6D 6C 6E 73 3A 73 74 72 65 61 6D 3D 22 68 74 74 |mlns:stream="htt|
      |100000020| 70 3A 2F 2F 65 74 68 65 72 78 2E 6A 61 62 62 65 |p://etherx.jabbe|
      |100000030| 72 2E 6F 72 67 2F 73 74 72 65 61 6D 73 22 20 78 |r.org/streams" x|
      |100000040| 6D 6C 6E 73 3D 22 6A 61 62 62 65 72 3A 63 6C 69 |mlns="jabber:cli|
      |100000050| 65 6E 74 22 20 74 6F 3D 22 78 6D 70 70 2E 6A 70 |ent" to="xmpp.jp|
      |100000060| 22 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 20 |" version="1.0" |
      |100000070| 3E                                              |>               |
      +--------+-------------------------------------------------+----------------+
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] FLUSH
Thread started: <Thread Pool> #24
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] RECEIVED_COMPLETE
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 => [::ffff:133.125.37.233]:5222] READ
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 :> [::ffff:133.125.37.233]:5222] INACTIVE
[0:] State changed: Disconnected
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 :> [::ffff:133.125.37.233]:5222] UNREGISTERED
�[40m�[37mdbug�[39m�[22m�[49m: DotNetty.Handlers.Logging.LoggingHandler[0]
      [id: 0x31f1233c, [::ffff:192.168.5.36]:42630 :> [::ffff:133.125.37.233]:5222] HANDLER_REMOVED
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: