Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SslStream does not implement some connection-info properties (CipherStrength). #12552

Closed
Octoate opened this issue Jan 22, 2019 · 8 comments

Comments

@Octoate
Copy link

@Octoate Octoate commented Jan 22, 2019

Hi,
I am currently having problems to run a project under Linux. The project itself contains an ASP.NET Core webserver to provide a REST API, SSL usage is enabled. It works on my Windows machine without any problems, but on Linux it throws a System.NotImplementedException on any access. It seems that the Mono.Net.Security.SslStream.CipherStrength is not implemented by the current Mono version but used by Kestrel.

Steps to Reproduce

  1. Integrate an ASP.NET Core webserver into your .NET 4.7 project.
  2. Enable SSL certificate usage.
  3. Run the program with Mono
  4. Open a page of the webserver in the browser

Current Behavior

On any access to the webserver, you will get the following NotImplementedException:

fail: Microsoft.AspNetCore.Server.Kestrel[0] Uncaught exception from the OnConnectionAsync method of an IConnectionAdapter. System.NotImplementedException: The method or operation is not implemented. at Mono.Net.Security.MobileAuthenticatedStream.get_CipherStrength () [0x00000] in <707293861b9c49cf8f99c3b74fe2930c>:0 at System.Net.Security.SslStream.get_CipherStrength () [0x00006] in <707293861b9c49cf8f99c3b74fe2930c>:0 at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync (Microsoft.AspNetCore.Server. <708a61b06ae647a09457b7bb52b351ad>:0

Expected Behavior

The code should just work without throwing an exception.

On which platforms did you notice this

[ ] macOS
[X] Linux
[ ] Windows

Version Used:

Mono JIT compiler version 5.16.0 (makepkg/bb3ae37d71a Tue Dec 18 03:32:00 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        Interpreter:   yes
        LLVM:          supported, not enabled.
        GC:            sgen (concurrent by default)

Stacktrace

fail: Microsoft.AspNetCore.Server.Kestrel[0]
      Uncaught exception from the OnConnectionAsync method of an IConnectionAdapter.
System.NotImplementedException: The method or operation is not implemented.
  at Mono.Net.Security.MobileAuthenticatedStream.get_CipherStrength () [0x00000] in <707293861b9c49cf8f99c3b74fe2930c>:0
  at System.Net.Security.SslStream.get_CipherStrength () [0x00006] in <707293861b9c49cf8f99c3b74fe2930c>:0
  at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync (Microsoft.AspNetCore.Server. <708a61b06ae647a09457b7bb52b351ad>:0
@baulig

This comment has been minimized.

Copy link
Member

@baulig baulig commented Jan 24, 2019

We never implemented those properties.

@baulig baulig changed the title System.NotImplementedException when using ASP.NET Core and .NET Framework 4.7 SslStream does not implement some connection-info properties (CipherStrength). Jan 28, 2019
@baulig

This comment has been minimized.

Copy link
Member

@baulig baulig commented Jan 29, 2019

This is one of those issues where a decision regarding future work and us pulling more code from CoreFx is required - as this will greatly influence how this should be done.

Those strategic issues set aside, the situation here is at follows:

This CipherStrength property as well as a few others in SslStream can be loosely classified as "Connection Info" properties. Now, our native backends (and neither do CoreFx's) do not directly provide these information because they depend on the cipher algorithm that is being used. Or in other words, since the cipher algorithm controls the value of all those properties, the cipher algorithm is the only information that is required to deduct all the others.

From the native backend's point of view, the cipher algorithm is some binary number (as defined by the TLS spec). The C# / .NET frontend code also has some enums for this, but we need some kind of a mapping table.

Looking at some CoreFx code, SslStream.CipherStrength calls SslConnectionInfo.DataKeySize:

This calls GetSslConnectionInfo() - which calls the native CryptoNative_GetSslConnectionInfo().

I have also seen some mapping table from cipher algorithm to those properties in managed code somewhere, but can't seem to find it anymore.

@baulig baulig self-assigned this Jan 29, 2019
@baulig

This comment has been minimized.

Copy link
Member

@baulig baulig commented Jan 29, 2019

So, adding an API to retrieve the cipher algorithm from the native backend - that literally takes like half an hour.

The returned cipher algorithm uniquely and unambiguously defines the cipher strength as well as the other "Connection Info" properties. But a mapping table will be needed.

A design decision must be made as to where and how this mapping table should be implemented - should we try to reuse some of the relevant CoreFx code or duplicate it in Mono?

Since the algorithm id is defined by the TLS spec, the general logic of mapping algorithm id to "Connection Info" properties (which include cipher strength and others) is reusable across all implementations.

@migueldeicaza

This comment has been minimized.

Copy link
Member

@migueldeicaza migueldeicaza commented Jan 29, 2019

Can you link to the CoreFX code?

@baulig

This comment has been minimized.

Copy link
Member

@baulig baulig commented Jan 29, 2019

Trying to find it.

@baulig

This comment has been minimized.

Copy link
Member

@baulig baulig commented Jan 29, 2019

Okay, here it is: https://github.com/dotnet/corefx/blob/master/src/System.Net.Security/src/System/Net/Security/SslConnectionInfo.OSX.cs.

This won't work out-of-the-box, we'd have to replace their SafeSslHandle and Interop.AppleCrypto.SslGetProtocolVersion() / Interop.AppleCrypto.SslGetCipherSuite() with custom APIs. The remapping table at the end of that file looks reusable, though.

@baulig

This comment has been minimized.

Copy link
Member

@baulig baulig commented Jan 30, 2019

Working on it: #12687.

@Octoate

This comment has been minimized.

Copy link
Author

@Octoate Octoate commented Feb 5, 2019

Thanks a lot 👍!

akoeplinger added a commit that referenced this issue Feb 5, 2019
…12789)

Provide a Mono-specific version of CoreFx's `SslConnectionInfo` and use it to implement some "Connection Info" properties in `SslStream`: `CipherStrength`, `HashStrength` and `KeyExchangeStrength`.

Fixes #12552.

Backport of #12687.
@marek-safar marek-safar added this to the 2019-02 (6.0.xx) milestone Feb 18, 2019
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Apr 24, 2019
Bumps to mono/api-snapshot@ae01378
Bumps to mono/reference-assemblies@e5173a5
Bumps to mono/bockbuild@d30329d
Bumps to mono/boringssl@3d87996
Bumps to mono/corefx@72f7d76
Bumps to mono/corert@1b7d4a1
Bumps to mono/helix-binaries@7e893ea
Bumps to mono/illinker-test-assets@f21ff68
Bumps to mono/linker@13d864e
Bumps to mono/llvm@1aaaaa5 [mono]
Bumps to mono/llvm@2c2cffe [xamarin-android]
Bumps to mono/NUnitLite@0029561
Bumps to mono/roslyn-binaries@0bbc9b4
Bumps to mono/xunit-binaries@8f6e62e

	$ git diff --shortstat 886c4901..e66c7667      # mono
        3597 files changed, 350850 insertions(+), 91128 deletions(-)
	$ git diff --shortstat 349752c464c5fc93b32e7d45825f2890c85c8b7d..2c2cffedf01e0fe266b9aaad2c2563e05b750ff4
	 240 files changed, 18562 insertions(+), 6581 deletions(-)

Context: dotnet/coreclr#22046

Fixes: CVE 2018-8292 on macOS
Fixes: http://work.devdiv.io/737323
Fixes: dotnet/corefx#33965
Fixes: dotnet/standard#642
Fixes: mono/mono#6997
Fixes: mono/mono#7326
Fixes: mono/mono#7517
Fixes: mono/mono#7750
Fixes: mono/mono#7859
Fixes: mono/mono#8360
Fixes: mono/mono#8460
Fixes: mono/mono#8766
Fixes: mono/mono#8922
Fixes: mono/mono#9418
Fixes: mono/mono#9507
Fixes: mono/mono#9951
Fixes: mono/mono#10024
Fixes: mono/mono#10030
Fixes: mono/mono#10038
Fixes: mono/mono#10448
Fixes: mono/mono#10735
Fixes: mono/mono#10735
Fixes: mono/mono#10737
Fixes: mono/mono#10743
Fixes: mono/mono#10834
Fixes: mono/mono#10837
Fixes: mono/mono#10838
Fixes: mono/mono#10863
Fixes: mono/mono#10945
Fixes: mono/mono#11020
Fixes: mono/mono#11021
Fixes: mono/mono#11021
Fixes: mono/mono#11049
Fixes: mono/mono#11091
Fixes: mono/mono#11095
Fixes: mono/mono#11123
Fixes: mono/mono#11138
Fixes: mono/mono#11146
Fixes: mono/mono#11202
Fixes: mono/mono#11214
Fixes: mono/mono#11317
Fixes: mono/mono#11326
Fixes: mono/mono#11378
Fixes: mono/mono#11385
Fixes: mono/mono#11478
Fixes: mono/mono#11479
Fixes: mono/mono#11488
Fixes: mono/mono#11489
Fixes: mono/mono#11527
Fixes: mono/mono#11529
Fixes: mono/mono#11596
Fixes: mono/mono#11603
Fixes: mono/mono#11613
Fixes: mono/mono#11623
Fixes: mono/mono#11663
Fixes: mono/mono#11681
Fixes: mono/mono#11684
Fixes: mono/mono#11693
Fixes: mono/mono#11697
Fixes: mono/mono#11779
Fixes: mono/mono#11809
Fixes: mono/mono#11858
Fixes: mono/mono#11895
Fixes: mono/mono#11898
Fixes: mono/mono#11898
Fixes: mono/mono#11965
Fixes: mono/mono#12182
Fixes: mono/mono#12193
Fixes: mono/mono#12218
Fixes: mono/mono#12235
Fixes: mono/mono#12263
Fixes: mono/mono#12307
Fixes: mono/mono#12331
Fixes: mono/mono#12362
Fixes: mono/mono#12374
Fixes: mono/mono#12402
Fixes: mono/mono#12421
Fixes: mono/mono#12461
Fixes: mono/mono#12479
Fixes: mono/mono#12479
Fixes: mono/mono#12552
Fixes: mono/mono#12603
Fixes: mono/mono#12747
Fixes: mono/mono#12831
Fixes: mono/mono#12843
Fixes: mono/mono#12881
Fixes: mono/mono#13030
Fixes: mono/mono#13284
Fixes: mono/mono#13297
Fixes: mono/mono#13455
Fixes: mono/mono#13460
Fixes: mono/mono#13478
Fixes: mono/mono#13479
Fixes: mono/mono#13522
Fixes: mono/mono#13607
Fixes: mono/mono#13610
Fixes: mono/mono#13610
Fixes: mono/mono#13639
Fixes: mono/mono#13672
Fixes: mono/mono#13834
Fixes: mono/mono#13878
Fixes: mono/mono#6352
Fixes: mono/monodevelop#6898
Fixes: xamarin/maccore#1069
Fixes: xamarin/maccore#1407
Fixes: xamarin/maccore#604
Fixes: xamarin/xamarin-macios#4984
Fixes: xamarin/xamarin-macios#5289
Fixes: xamarin/xamarin-macios#5363
Fixes: xamarin/xamarin-macios#5381
Fixes: https://issuetracker.unity3d.com/issues/editor-crashes-with-g-logv-when-entering-play-mode-with-active-flowcanvas-script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.