Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

CipherSuitePolicy implementation#36775

Merged
krwq merged 30 commits intodotnet:masterfrom
krwq:ciphersuitespolicy
Apr 13, 2019
Merged

CipherSuitePolicy implementation#36775
krwq merged 30 commits intodotnet:masterfrom
krwq:ciphersuitespolicy

Conversation

@krwq
Copy link
Member

@krwq krwq commented Apr 10, 2019

Fixes: https://github.com/dotnet/corefx/issues/24588
Fixes: https://github.com/dotnet/corefx/issues/33809

Replacing: #36648 because CI doesn't work correctly with draft PRs

cc: @karelz @joshfree

@krwq krwq added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 10, 2019
@krwq krwq force-pushed the ciphersuitespolicy branch from 8370757 to 60e1235 Compare April 10, 2019 21:34
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s), but failed to run 1 pipeline(s).

@krwq
Copy link
Member Author

krwq commented Apr 10, 2019

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s), but failed to run 1 pipeline(s).

@krwq krwq removed the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 11, 2019
ret &= SSL_CTX_set_ciphersuites(ctx, cipherSuites);
}
#else
(void)cipherSuites;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ret &= (cipherSuites == NULL);? (aka fail if cipherSuites made it this far?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code was initially written with working on lower than 1.1.1 in mind (the only issue with that is we would have to have IANA -> OpenSSL string mapping somewhere since SSL_CIPHER_find is not available), assuming we got here and TLS 1.3 is not supported then setting 1.3 cipher suites will have no effect anyway since we already would have failed when setting < 1.3 cipher suites.

@krwq krwq merged commit 07f443b into dotnet:master Apr 13, 2019
Ssl.SslCtxSetQuietShutdown(innerContext);

if (!Ssl.SetEncryptionPolicy(innerContext, policy))
byte[] cipherList =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Debug.Assert that these are null terminated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already do the checks inside ShouldOptOutOfTls13 and ShouldOptOutOfLowerThanTls13 but can add another one

else
{
// iOS, tvOS, watchOS
SSLCipherSuite* cipherSuites16 = (SSLCipherSuite*)malloc(sizeof(SSLCipherSuite) * (size_t)numCipherSuites);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value of malloc should be checked against nullptr for OOM conditions. (And honestly it's best practice to use calloc instead of malloc.)

Copy link
Member Author

@krwq krwq Apr 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on OOM, for calloc comment: we fill it out anyway instruction later so not sure why use calloc - we will double initialize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a hot code path, so not concerned about double-initialization. In general the primary benefit of calloc is that you avoid possible integer overflow when computing the total required byte size. I can't imagine this particular call would overflow, but it's a good habit to get in to.

@davidfowl
Copy link
Member

Do we need to react to this change in Kestrel?

cc @shirhatti @blowdart @halter73 @Tratcher @anurse

@Tratcher
Copy link
Member

Tratcher commented Apr 13, 2019

Yes, exposing this API: https://github.com/dotnet/corefx/pull/36775/files#diff-bd768ea3857573965e853e2ce2563434R134

HTTP/2 is supposed to restrict ciphers. I'll file it. dotnet/aspnetcore#9349

@Tratcher
Copy link
Member

Was there any discussion for implementing a deny list as well? That's what HTTP/2 calls for.
https://tools.ietf.org/html/rfc7540#section-9.2.2
https://tools.ietf.org/html/rfc7540#appendix-A

@davidsh
Copy link
Contributor

davidsh commented Apr 13, 2019

Was there any discussion for implementing a deny list as well?

Tons of discussions with the Windows team. We spent a long time discussing this API and what is best for all the platforms (Windows, Linux, etc.). This API and PR is the result of that long effort.

Feel free to watch the API review on YouTube. :)

@davidfowl
Copy link
Member

@Tratcher it would be good if we could expose this entire type (if it makes sense) so we could avoid the property by property copy when new features are added.

@krwq
Copy link
Member Author

krwq commented Apr 13, 2019

@Tratcher for blocking "bad" cipher suites you can simply only allow TLS 1.3 which only allows 5 "safe" cipher suites or specify a list explicitly. Current implementation is ready for adding more advanced filtering in the future: https://github.com/dotnet/corefx/blob/master/src/System.Net.Security/src/System/Net/Security/TlsCipherSuiteData.Lookup.tt - technically it should be possible to expose this as an external tool which generates CipherSuitesPolicy.

@ViktorHofer
Copy link
Member

This broke the official build: https://dev.azure.com/dnceng/internal/_build/results?buildId=154142

/__w/1/s/src/Native/Unix/System.Security.Cryptography.Native/pal_ssl.c(374,14): error GAA0F1F0D: implicit declaration of function 'SSL_CIPHER_find' is invalid in C99 [-Werror,-Wimplicit-function-declaration] [/__w/1/s/src/Native/build-native.proj]
/__w/1/s/src/Native/Unix/System.Security.Cryptography.Native/pal_ssl.c(374,12): error GD47D7371: incompatible integer to pointer conversion assigning to 'const SSL_CIPHER *' (aka 'const struct ssl_cipher_st *') from 'int' [-Werror,-Wint-conversion] [/__w/1/s/src/Native/build-native.proj]
/__w/1/s/src/Native/build-native.proj(36,5): error MSB3073: The command ""/__w/1/s/src/Native/build-native.sh" x64 Release Linux outconfig netcoreapp-Linux-Release-x64 stripsymbols" exited with code 1.
    0 Warning(s)
    3 Error(s)

cc @safern

@karelz
Copy link
Member

karelz commented Apr 14, 2019

If we're blocking official builds, we should back out the change ASAP.

@krwq krwq mentioned this pull request Apr 14, 2019
@krwq
Copy link
Member Author

krwq commented Apr 14, 2019

@karelz I'll try to address this right now since we don't have good CI coverage for this case

@karelz karelz added this to the 3.0 milestone May 4, 2019
@Tratcher
Copy link
Member

Feel free to watch the API review on YouTube. :)

@karelz @davidsh Anybody have a link for that? Or at least a date? They're not well indexed or linked from any of the issues.

@karelz
Copy link
Member

karelz commented May 24, 2019

@Tratcher check out api-approved date: 4/2: https://github.com/dotnet/corefx/issues/33809#event-2247491106 ... that's the one you're looking for ;)

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* CipherSuitePolicy implementation (Linux)

* SSL_CIPHER_find

* do not call TLS1.3 APIs on platforms which don't support it

* Non-TLS1.3 specific tests are skipped when not enough cipher suites is enabled

* clean ups

* attempt to fix OSX

* another attempt to fix OSX

* missing define

* address some feedback, try to fix test failures

* portable build fix

* do not call old set ciphers API when only TLS 1.3 is requested

* apply feedback

* add OSX implementation

* fixes to OSX

* explicit convert

* use explicit SSLCipherSuite instead of uint16_t

* random change to trigger CI

* s/unsafe/fixed

* fixes

* random change to trigger CI

* client ordering does not have to win

* tests: AllowedCipherSuites, new CipherSuitesPolicy(null)

* run AllowedCipherSuites tests only when CSP is supported

* add summary on CipherSuitesPolicy

* address feedback

* move OS specific files to CipherSuitesPolicyPal

* FALLBACK->LIGHTUP and remove local_

* do not call 1.1.1 function on non-portable build when lower openssl version is installed

* get rid of warning that arg is unused

* make CipherSuitesPolicyPal public members internal


Commit migrated from dotnet/corefx@07f443b
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: SSLStream Allow Configuration of CipherSuites SSLStream Allow Configuration of CipherSuites

9 participants