-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Client-side TLS 1.3 support on OSX #117428
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
Merged
Merged
Changes from all commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
c062e18
Native Interop Layer
liveans ecba3f7
Native Layer Compilation fix for Mono + NativeAOT + templates
liveans bf130f3
First shape of new native + interop
liveans 0dcc599
Newlines at the end of files
liveans 44b3597
Default constructor ownsHandle to true
liveans 3cbcea7
Delete couple of unsafe keyword in Interop
liveans 3defe85
Update src/native/libs/System.Net.Security.Native.Apple/pal_networkfr…
liveans 57a7069
Merge branch 'main' into network_framework_integration_native_interop
liveans c1a2b6b
Fix PlatformManifestFileEntry
liveans 0977679
Review feedback
liveans fe343b0
Apply suggestions from code review
liveans 0fff060
Update src/libraries/Common/src/Interop/OSX/Interop.Network.Tls.cs
liveans 3441093
Review feedbacks
liveans 3e547c5
Merge branch 'main' into network_framework_integration_native_interop
liveans 25b8950
Further review feedback
liveans 91238c5
Add new library name to nativeaot build target file
liveans a250b67
Merge branch 'main' into network_framework_integration_native_interop
liveans beb5f93
Merge System.Net.Security.Native.Apple with System.Security.Cryptogra…
rzikm 0ab06b2
fixup! Merge System.Net.Security.Native.Apple with System.Security.Cr…
rzikm 39bef6d
Shared OSStatus
rzikm 8267454
Correctly release some handles
rzikm 4bf6eb9
Remove printf
rzikm f771ea9
Add comments
rzikm 6ab3942
Fix build
rzikm b05467e
Copy of initial changes
rzikm 9aa167a
Fix build
rzikm da8d285
WIP
rzikm e7fa071
WIP
rzikm d018034
more WIP
rzikm 4767c77
Minimal example is working
rzikm e629414
Fix concurrent read/write calls
rzikm becc664
ALPN fix
rzikm f4d4bc8
Certificate validation
rzikm b967fc9
Report remote alerts
rzikm 0f71d07
CipherSuitesPolicy support
rzikm 0718512
Fix IDNA
rzikm 0df2d19
Zero-bytes read support
rzikm 10f812a
fixup! ALPN fix
rzikm a77d7d2
Attach correct cancellation token to exceptions
rzikm 6ca7130
Fix framer lifetime
rzikm 0bc4003
fixup! CipherSuitesPolicy support
rzikm c26d47e
Cleanup some unwanted changes
rzikm 1bd7626
Some more cleanup
rzikm 1434381
Fix ALPN reading
rzikm dfd1753
ClientCertificates + CertificateContext + CertSelectionDelegate imple…
liveans bbe2e5d
Correctly pass remote certificate + acceptableIssuers to selection ca…
liveans aba17db
Disable Ciphersuite tests for NW
liveans 5c45a15
Fix formatting
liveans f6babf0
Fix some test scenarios
liveans cdf141c
Delete unused ResettableTaskSource
liveans e61e02a
Fix build
liveans fe3170b
Unify certificate validation code
rzikm 216b3a6
TARGET_OSX to TARGET_APPLE
rzikm 2ec8e98
Small changes
rzikm f6a17b0
Fix build of other platforms
rzikm 02d76f5
Disable known edge-case for now
liveans df9c144
Some test fixes
rzikm fbc3fb2
Disable EventSource order test for NW
liveans 2b1dbb3
Add TCS for completion on transportStream Write and propagate exceptions
liveans cf412ce
Propagate exception for handshake + write tcs from transport read task
liveans b2e7dc7
Missing write part of propagation exception for transport read task
liveans 16b48e1
App read optimization
rzikm 4212aff
fixup! App read optimization
rzikm 6c47976
Fix hanging pending read after read cancellation
rzikm ad232e8
Unify local cert selection
rzikm 9dff34a
Improve thisHandle lifetime management
rzikm 3488df4
Introduce specific exception for NetworkFramework + properly propagat…
liveans e444f02
Refactor NetworkFramework error handling to use enum for error domains
liveans a4a4c69
Refactor error extraction in NetworkFramework to return CFStringRef f…
liveans a824578
Enhance cancellation support in SafeDeleteNwContext by throwing on ca…
liveans f4edc9b
Typo fix
liveans 5a95f10
Switch to Network.framework tests on CI
liveans 0b92607
Fix memory leaks, introduce CancellationAction for ResettableValueTas…
liveans e062869
Reverting back running nw tests on ci, as some apis requires at least…
liveans 92d8770
A bit cleanup
liveans a15e0d9
Use more appropriate names in nw shim functions
rzikm 3a78fbe
Centralized gchandle management in native code
rzikm 03ce32f
Fix correct cancellation token when throwing
rzikm 53281db
Fix hang, remove try-catches in completion callbacks
rzikm b15b220
Revert unwanted changes
rzikm a292e7a
Fix comment
rzikm 39582fc
Logging improvements
rzikm 0d02b54
Merge remote-tracking branch 'upstream/main' into osx-tls13
rzikm a6ff82f
Apply suggestion from @liveans
rzikm 8102719
Update src/libraries/System.Net.Security/src/System/Net/Security/Pal.…
rzikm a6c124d
Code review feecback
rzikm 83bcaf1
Remove duplicate void* state argument in native functions
rzikm ba6e3fb
Update src/native/libs/System.Security.Cryptography.Native.Apple/pal_…
rzikm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/libraries/Common/src/Interop/OSX/Interop.NetworkFramework.Tls.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Buffers; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Net; | ||
| using System.Net.Security; | ||
| using System.Runtime.InteropServices; | ||
| using System.Security.Authentication; | ||
| using Microsoft.Win32.SafeHandles; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| // TLS 1.3 specific Network Framework implementation for macOS | ||
| internal static partial class NetworkFramework | ||
| { | ||
| internal static partial class Tls | ||
| { | ||
| // Initialize internal shim for NetworkFramework integration | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_Init")] | ||
| [return: MarshalAs(UnmanagedType.I4)] | ||
| internal static unsafe partial bool Init( | ||
| delegate* unmanaged<IntPtr, StatusUpdates, IntPtr, IntPtr, NetworkFrameworkError*, void> statusCallback, | ||
| delegate* unmanaged<IntPtr, byte*, ulong, void> writeCallback, | ||
| delegate* unmanaged<IntPtr, IntPtr, IntPtr> challengeCallback); | ||
|
|
||
| // Create a new connection context | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_NwConnectionCreate", StringMarshalling = StringMarshalling.Utf8)] | ||
| internal static unsafe partial SafeNwHandle NwConnectionCreate([MarshalAs(UnmanagedType.I4)] bool isServer, IntPtr context, string targetName, byte* alpnBuffer, int alpnLength, SslProtocols minTlsProtocol, SslProtocols maxTlsProtocol, uint* cipherSuites, int cipherSuitesLength); | ||
|
|
||
| // Start the TLS handshake, notifications are received via the status callback (potentially from a different thread). | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_NwConnectionStart")] | ||
| internal static partial int NwConnectionStart(SafeNwHandle connection, IntPtr context); | ||
|
|
||
| // takes encrypted input from underlying stream and feed it to the connection. | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_NwFramerDeliverInput")] | ||
| internal static unsafe partial int NwFramerDeliverInput(SafeNwHandle framer, IntPtr context, byte* buffer, int bufferLength, delegate* unmanaged<IntPtr, NetworkFrameworkError*, void> completionCallback); | ||
|
|
||
| // sends plaintext data to the connection. | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_NwConnectionSend")] | ||
| internal static unsafe partial void NwConnectionSend(SafeNwHandle connection, IntPtr context, void* buffer, int bufferLength, delegate* unmanaged<IntPtr, NetworkFrameworkError*, void> completionCallback); | ||
|
|
||
| // read plaintext data from the connection. | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_NwConnectionReceive")] | ||
| internal static unsafe partial void NwConnectionReceive(SafeNwHandle connection, IntPtr context, int length, delegate* unmanaged<IntPtr, NetworkFrameworkError*, byte*, int, void> readCompletionCallback); | ||
|
|
||
| // starts connection cleanup | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_NwConnectionCancel")] | ||
| internal static partial void NwConnectionCancel(SafeNwHandle connection); | ||
|
|
||
| // gets TLS connection information | ||
| [LibraryImport(Interop.Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_GetConnectionInfo")] | ||
| internal static unsafe partial int GetConnectionInfo(SafeNwHandle connection, IntPtr context, out SslProtocols pProtocol, out TlsCipherSuite pCipherSuiteOut, byte* negotiatedAlpn, ref int negotiatedAlpnLength); | ||
| } | ||
|
|
||
| // Status enumeration for Network Framework TLS operations | ||
| internal enum StatusUpdates | ||
| { | ||
| UnknownError = 0, | ||
| FramerStart = 1, | ||
| HandshakeFinished = 3, | ||
| ConnectionFailed = 4, | ||
| ConnectionCancelled = 103, | ||
| CertificateAvailable = 104, | ||
| DebugLog = 200, | ||
| } | ||
| } | ||
|
|
||
| // Safe handle classes for Network Framework TLS resources | ||
| internal sealed class SafeNwHandle : SafeHandleZeroOrMinusOneIsInvalid | ||
| { | ||
| public SafeNwHandle() : base(ownsHandle: true) { } | ||
|
|
||
| public SafeNwHandle(IntPtr handle, bool ownsHandle) : base(ownsHandle) | ||
| { | ||
| SetHandle(handle); | ||
| } | ||
|
|
||
| protected override bool ReleaseHandle() | ||
| { | ||
| NetworkFramework.Release(handle); | ||
| SetHandle(IntPtr.Zero); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
85 changes: 85 additions & 0 deletions
85
src/libraries/Common/src/Interop/OSX/Interop.NetworkFramework.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using Microsoft.Win32.SafeHandles; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class NetworkFramework | ||
| { | ||
| // Network Framework reference counting functions | ||
| [LibraryImport(Libraries.NetworkFramework, EntryPoint = "nw_retain")] | ||
| internal static partial IntPtr Retain(IntPtr obj); | ||
|
|
||
| [LibraryImport(Libraries.NetworkFramework, EntryPoint = "nw_release")] | ||
| internal static partial void Release(IntPtr obj); | ||
|
|
||
| // Network Framework error domains | ||
| internal enum NetworkFrameworkErrorDomain | ||
| { | ||
| Invalid = 0, | ||
| POSIX = 1, | ||
| DNS = 2, | ||
| TLS = 3 | ||
| } | ||
|
|
||
| internal enum NWErrorDomainPOSIX | ||
| { | ||
| OperationCanceled = 89, // ECANCELED | ||
| } | ||
|
|
||
| internal sealed class NetworkFrameworkException : Exception | ||
| { | ||
| public int ErrorCode { get; } | ||
| public NetworkFrameworkErrorDomain ErrorDomain { get; } | ||
|
|
||
| internal NetworkFrameworkException() | ||
| { | ||
| } | ||
|
|
||
| internal NetworkFrameworkException(int errorCode, NetworkFrameworkErrorDomain errorDomain, string? message) | ||
| : base(message ?? $"Network Framework error {errorCode} in domain {errorDomain}") | ||
| { | ||
| HResult = errorCode; | ||
| ErrorCode = errorCode; | ||
| ErrorDomain = errorDomain; | ||
| } | ||
|
|
||
| internal NetworkFrameworkException(int errorCode, NetworkFrameworkErrorDomain errorDomain, string? message, Exception innerException) | ||
| : base(message ?? $"Network Framework error {errorCode} in domain {errorDomain}", innerException) | ||
| { | ||
| HResult = errorCode; | ||
| ErrorCode = errorCode; | ||
| ErrorDomain = errorDomain; | ||
| } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return $"{base.ToString()}, ErrorCode: {ErrorCode}, ErrorDomain: {ErrorDomain}"; | ||
| } | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct NetworkFrameworkError | ||
| { | ||
| public int ErrorCode; | ||
| public int ErrorDomain; | ||
| public IntPtr ErrorMessage; // C string of NULL | ||
| } | ||
|
|
||
| internal static Exception CreateExceptionForNetworkFrameworkError(in NetworkFrameworkError error) | ||
| { | ||
| string? message = null; | ||
| NetworkFrameworkErrorDomain domain = (NetworkFrameworkErrorDomain)error.ErrorDomain; | ||
|
|
||
| if (error.ErrorMessage != IntPtr.Zero) | ||
| { | ||
| message = Marshal.PtrToStringUTF8(error.ErrorMessage); | ||
| } | ||
|
|
||
| return new NetworkFrameworkException(error.ErrorCode, domain, message); | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...ries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.OSStatus.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class AppleCrypto | ||
| { | ||
| internal static class OSStatus | ||
| { | ||
| public const int NoErr = 0; | ||
| public const int ReadErr = -19; | ||
| public const int WritErr = -20; | ||
| public const int EOFErr = -39; | ||
| public const int SecUserCanceled = -128; | ||
| public const int ErrSSLWouldBlock = -9803; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.