Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity 2017.2.0b8 + .NET 4.6 + Firebase Scripting Runtime Websocket errors

Discussion in 'Experimental Scripting Previews' started by ItsLeeOwen, Jun 11, 2017.

  1. ItsLeeOwen

    ItsLeeOwen

    Joined:
    Jun 3, 2017
    Posts:
    11
    I'm looking forward to the .NET Scripting Runtime upgrade, and am seeing Websocket TLS errors coming from the Firebase C# Plugin. I'm not sure if this is ultimately a fix that will need to go into the firebase C# api, or unity.


    [Error] WebSocket: ws_0 - IOException during handshake
    System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0x3
    at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult asyncResult) [0x00040] in <59bcb3a41e31492f91d9513566444e88>:0
    at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (System.IAsyncResult ar, System.Boolean ignoreEmpty) [0x00000] in <59bcb3a41e31492f91d9513566444e88>:0
    at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (System.IAsyncResult result) [0x00071] in <59bcb3a41e31492f91d9513566444e88>:0
    --- End of inner exception stack trace ---
    at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (System.IAsyncResult result) [0x0003b] in <59bcb3a41e31492f91d9513566444e88>:0
    at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult asyncResult) [0x0000c] in <59bcb3a41e31492f91d9513566444e88>:0
    --- End of inner exception stack trace ---
    at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult asyncResult) [0x00057] in <59bcb3a41e31492f91d9513566444e88>:0
    at Mono.Net.Security.Private.LegacySslStream.EndAuthenticateAsClient (System.IAsyncResult asyncResult) [0x00011] in <f044fe2c9e7e4b8e91984b41f0cf0b04>:0
    at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x0000e] in <f044fe2c9e7e4b8e91984b41f0cf0b04>:0
    at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsClient (System.String targetHost) [0x00007] in <f044fe2c9e7e4b8e91984b41f0cf0b04>:0
    at Mono.Net.Security.Private.MonoSslStreamImpl.AuthenticateAsClient (System.String targetHost) [0x00006] in <f044fe2c9e7e4b8e91984b41f0cf0b04>:0
    at System.Net.Security.SslStream.AuthenticateAsClient (System.String targetHost) [0x00006] in <f044fe2c9e7e4b8e91984b41f0cf0b04>:0
    at Firebase.Database.Internal.TubeSock.WebSocket.RunReader () [0x000bf] in <cf10b78eead54f39b6cbec497dcd100b>:0
    UnityEngine.Debug:LogError(Object)
    Firebase.FirebaseHandler:LogMessage(LogLevel, String)
    Firebase.Unity.UnityLoggingService:LogMessage(LogLevel, String)
    Firebase.Database.Internal.Logging.DefaultLogger:Error(String, String)
    Firebase.Database.Internal.Logging.DefaultLogger:OnLogMessage(Level, String, String, Int64)
    Firebase.Database.Internal.Logging.LogWrapper:Error(String, Exception)
    Firebase.Database.Internal.TubeSock.WebSocket:LogError(String, Exception)
    Firebase.Database.Internal.TubeSock.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can you submit a bug report with this project? This certificate errors are notorious finicky, so I would like to be able to investigate it here.
     
  3. ItsLeeOwen

    ItsLeeOwen

    Joined:
    Jun 3, 2017
    Posts:
    11
    @JoshPeterson I submitted a report to Unity + Firebase. The Firebase team says they are unable to reproduce, I'm not 100% sure the support staff are familiar with the steps involved to run Unity with the newer runtime so I made a screen-recording of the issue & git repo.

    https://github.com/ItsLeeOwen/Unity2017-Firebase
     
    Qbit86 likes this.
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks, I saw the bug report come in today, so we will investigate it.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks! We will continue to investigate on our side as well. If you hear from them that it is corrected, please reply via the bug report so that we will be aware. Thanks!
     
  6. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    This error comes from not web-socket client library. The mono implementations for a lot of these things do not implement the TLS handshake correctly.... and are buggy in general. There are a few solutions for this problem. If you search Xamarin bugzilla you will see a few people crying over this bug (including myself).

    1. Change the websocket transport. All of them suck.
    2. Disable SSL / TLS
    3. Rewrite mono to correctly support SSL.
    4. Use a native websocket and use a bridge to bring it into unity.
    The last step completely side steps mono, and thus works the best. I would contact firebase and have them fix the issue.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    While we don't have a good solution for TLS with Mono at the moment, it is an active area of development. So longer-term, I would expect better support for this kind of thing in future Unity releases.
     
  8. ItsLeeOwen

    ItsLeeOwen

    Joined:
    Jun 3, 2017
    Posts:
    11
    With Unity 2017.2.0b8 + .NET4.6 + Firebase Unity SDK 4.0.3 ( https://firebase.google.com/support/release-notes/unity ) there is some improvement, the Websocker error is not thrown, and instead a workaround log is output to the console.

    But FirebaseDatabase doesn't seem to return either an err or result following the Firebase example code ( https://firebase.google.com/docs/database/unity/retrieve-data#read_data_once ).

    Using workaround for .NET 4.6 certificate bug.
    UnityEngine.Debug:Log(Object)
    Firebase.FirebaseHandler:LogMessage(LogLevel, String)
    Firebase.Unity.UnityLoggingService:LogMessage(LogLevel, String)
    Firebase.Unity.InstallRootCerts:.ctor()
    Firebase.Unity.InstallRootCerts:.cctor()
    Firebase.Unity.UnityPlatformServices:Install(GameObject)
    Firebase.FirebaseHandler:<Create>m__0()
    Firebase.FirebaseApp:TranslateDllNotFoundException(Action)
    Firebase.FirebaseHandler:Create()
    Firebase.FirebaseApp:get_DefaultInstance()
     
  9. ItsLeeOwen

    ItsLeeOwen

    Joined:
    Jun 3, 2017
    Posts:
    11
  10. ItsLeeOwen

    ItsLeeOwen

    Joined:
    Jun 3, 2017
    Posts:
    11
  11. bcjordan

    bcjordan

    Joined:
    Sep 23, 2013
    Posts:
    34
    Is this specific to iOS / Android? Or is there support for standalone (Windows / OS X) now?
     
  12. pesahov

    pesahov

    Joined:
    May 24, 2017
    Posts:
    12
    I have the same error for iOS build on 2017.1.2p2 .NET 4.6 but don't have it with Unity Cloud

    Code (CSharp):
    1. TlsException: Invalid certificate received from server. Error code: 0x3
    2. Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult asyncResult) (at <59bcb3a41e31492f91d9513566444e88>:0)
    3. Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (System.IAsyncResult ar, System.Boolean ignoreEmpty) (at <59bcb3a41e31492f91d9513566444e88>:0)
    4. Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (System.IAsyncResult result) (at <59bcb3a41e31492f91d9513566444e88>:0)
    5. Rethrow as IOException: The authentication or decryption has failed.
    6. Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (System.IAsyncResult result) (at <59bcb3a41e31492f91d9513566444e88>:0)
    7. Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult asyncResult) (at <59bcb3a41e31492f91d9513566444e88>:0)
    8. Rethrow as IOException: The authentication or decryption has failed.
    9. Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult asyncResult) (at <59bcb3a41e31492f91d9513566444e88>:0)
    10. Mono.Net.Security.Private.LegacySslStream.EndAuthenticateAsClient (System.IAsyncResult asyncResult) (at <f044fe2c9e7e4b8e91984b41f0cf0b04>:0)
    11. Mono.Net.Security.Private.LegacySslStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) (at <f044fe2c9e7e4b8e91984b41f0cf0b04>:0)
    12. Mono.Net.Security.MonoTlsStream.CreateStream (System.Byte[] buffer) (at <f044fe2c9e7e4b8e91984b41f0cf0b04>:0)
    13. Rethrow as WebException: Error: TrustFailure (The authentication or decryption has failed.)
    14. System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) (at <f044fe2c9e7e4b8e91984b41f0cf0b04>:0)
    15. System.Net.HttpWebRequest.GetResponse () (at <f044fe2c9e7e4b8e91984b41f0cf0b04>:0)
    16. UnityEditor.iOS.PostProcessiPhonePlayer.GetUsymUploadAuthToken (UnityEditor.iOS.PostProcessiPhonePlayer+BuildSettings bs) (at /Users/builduser/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:2568)
    17. UnityEditor.HostView:OnGUI()
    18.  
     
  13. tomerpeledNG

    tomerpeledNG

    Joined:
    Jul 14, 2017
    Posts:
    81
    Same issue, anyone solved it?

    Unity 2017.1.1f1 + Latest Fabric
     
    Last edited: Dec 5, 2017
  14. pesahov

    pesahov

    Joined:
    May 24, 2017
    Posts:
    12
    I have the same issue for Android with Unity 2017.2.0 and 3.0
    The solution for me was in logging out from Unity account and checking "Work offline". After this, my build was successful locally. On Unity Cloud I don't have this issue
     
    Shawn_Flanagan and drmgeorge like this.
  15. xortrox

    xortrox

    Joined:
    Feb 13, 2011
    Posts:
    22
  16. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
    This particular issue should be fixed in 2018.1 betas. It's unclear if this will be fixed in 2017.x series.

    New TLS support infrastructure is planned for all of Unity including the .NET/Mono APIs for 2018.2.
     
  17. xortrox

    xortrox

    Joined:
    Feb 13, 2011
    Posts:
    22
    Awesome!
     
  18. xortrox

    xortrox

    Joined:
    Feb 13, 2011
    Posts:
    22
    Wait did you mean the firebase problem or the one I linked to specifically? If you meant my problem would you point me in the right direction for which beta version? Latest beta seems to not solve it.
     
  19. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    63
  20. MrMichal

    MrMichal

    Joined:
    May 13, 2017
    Posts:
    2
    Still an issue in Unity 2018.2.4f1
     
    vovo801 likes this.
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I thought that all of the issues in this thread were corrected. Can you submit a new bug report?
     
  22. MrMichal

    MrMichal

    Joined:
    May 13, 2017
    Posts:
    2
    The problem was present only on physical device. I fixed that by re-importing all sdk, force resolving dependencies, rebuilding the project, changing scripting run-time version to .NET 3.5, and API compatibility level to .NET 2.0. If I will experience the issue again I will submit bug report.
     
  23. z-guohui-qian

    z-guohui-qian

    Joined:
    Oct 5, 2017
    Posts:
    3
    This problem goes on,
    I am using Unity2018.2.6 + Firebase 5.2 in Mac
    The procedure to reduce this is the same as ItsLeeOwen reported in Jun 13, 2017.
     
  24. z-guohui-qian

    z-guohui-qian

    Joined:
    Oct 5, 2017
    Posts:
    3
    I found the problem, it is the firewall.
    I changed the network to a private one instead of the one for company.
    Then it worked.
     
  25. lloydv

    lloydv

    Joined:
    Sep 15, 2015
    Posts:
    55
    I was getting a similar error that led me here, so I'll leave my solution in case anyone else runs into the same issue

    Error message

    [Error] WebSocket: ws_0 - IOException during handshake
    System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: Error while sending TLS Alert (Fatal:InternalError): System.IO.IOException: The authentication or decryption has failed. ---> System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'System.Net.Sockets.NetworkStream'.
    at System.Net.Sockets.NetworkStream.BeginRead (...


    Solution (required two changes)
    1. Generate and setup a p12 file for firebase from google cloud services, as stated in the docs.
    2.
    FirebaseDatabase.GetInstance
    must be called AFTER logging in via
    FirebaseAuth
    , the

    CheckAndFixDependenciesAsync().ContinueWith
    callback is not good enough.