Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
OpenSSL ENGINE support#88656
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
OpenSSL ENGINE support #88656
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8797103
OpenSSL ENGINE support
krwq 5b96938
Remove trailing spaces on README file
krwq a6d8a64
Address PR feedback
krwq 196f57b
Test for PNSE and run tests on all platforms supporting OSSL
krwq b1f2941
Update IsOpenSslSupported
krwq f3ba6ee
s/IsOpenSslSupported/OpenSslPresentOnSystem
krwq 511c666
Fix OpenSslNotPresentOnSystem on Windows
krwq 5463146
Add preventive OpenSslIsAvailable check for better error handling
krwq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46 src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.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
2 changes: 1 addition & 1 deletion
2 src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.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
1 change: 1 addition & 0 deletions
1 src/libraries/Common/tests/TestUtilities/System/PlatformDetection.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
12 changes: 12 additions & 0 deletions
12 src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.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
16 changes: 16 additions & 0 deletions
16 ...ies/System.Security.Cryptography/src/System/Security/Cryptography/OpenSsl.NotSupported.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
105 changes: 105 additions & 0 deletions
105 ...ystem.Security.Cryptography/src/System/Security/Cryptography/SafeEvpPKeyHandle.OpenSsl.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 |
|---|---|---|
| @@ -86,5 +86,110 @@ public SafeEvpPKeyHandle DuplicateHandle() | ||
| [UnsupportedOSPlatform("tvos")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public static long OpenSslVersion { get; } = Interop.OpenSsl.OpenSslVersionNumber(); | ||
| /// <summary> | ||
| /// Open a named private key using a named OpenSSL <code>ENGINE</code>. | ||
| /// </summary> | ||
| /// <param name="engineName"> | ||
| /// The name of the <code>ENGINE</code> to process the private key open request. | ||
| /// </param> | ||
| /// <param name="keyId"> | ||
| /// The name of the key to open. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The opened key. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="engineName"/> or <paramref name="keyId"/> is <see langword="null" />. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentException"> | ||
| /// <paramref name="engineName"/> or <paramref name="keyId"/> is the empty string. | ||
| /// </exception> | ||
| /// <exception cref="CryptographicException"> | ||
| /// the key could not be opened via the specified ENGINE. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// This operation will fail if OpenSSL cannot successfully load the named <code>ENGINE</code>, | ||
| /// or if the named <code>ENGINE</code> cannot load the named key. | ||
| /// </para> | ||
| /// <para> | ||
| /// Not all <code>ENGINE</code>s support loading private keys. | ||
| /// </para> | ||
| /// <para> | ||
| /// The syntax for <paramref name="keyId"/> is determined by each individual | ||
| /// <code>ENGINE</code>. | ||
| /// </para> | ||
| /// </remarks> | ||
| [UnsupportedOSPlatform("android")] | ||
| [UnsupportedOSPlatform("browser")] | ||
| [UnsupportedOSPlatform("ios")] | ||
| [UnsupportedOSPlatform("tvos")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public static SafeEvpPKeyHandle OpenPrivateKeyFromEngine(string engineName, string keyId) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(engineName); | ||
| ArgumentException.ThrowIfNullOrEmpty(keyId); | ||
| if (!Interop.OpenSslNoInit.OpenSslIsAvailable) | ||
| { | ||
| throw new PlatformNotSupportedException(SR.PlatformNotSupported_CryptographyOpenSSL); | ||
| } | ||
| return Interop.Crypto.LoadPrivateKeyFromEngine(engineName, keyId); | ||
vcsjones marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| /// <summary> | ||
| /// Open a named public key using a named OpenSSL <code>ENGINE</code>. | ||
| /// </summary> | ||
| /// <param name="engineName"> | ||
| /// The name of the <code>ENGINE</code> to process the public key open request. | ||
| /// </param> | ||
| /// <param name="keyId"> | ||
| /// The name of the key to open. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The opened key. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="engineName"/> or <paramref name="keyId"/> is <see langword="null" />. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentException"> | ||
| /// <paramref name="engineName"/> or <paramref name="keyId"/> is the empty string. | ||
| /// </exception> | ||
| /// <exception cref="CryptographicException"> | ||
| /// the key could not be opened via the specified ENGINE. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// This operation will fail if OpenSSL cannot successfully load the named <code>ENGINE</code>, | ||
| /// or if the named <code>ENGINE</code> cannot load the named key. | ||
| /// </para> | ||
| /// <para> | ||
| /// Not all <code>ENGINE</code>s support loading public keys, even ones that support | ||
| /// loading private keys. | ||
| /// </para> | ||
| /// <para> | ||
| /// The syntax for <paramref name="keyId"/> is determined by each individual | ||
| /// <code>ENGINE</code>. | ||
| /// </para> | ||
| /// </remarks> | ||
| [UnsupportedOSPlatform("android")] | ||
| [UnsupportedOSPlatform("browser")] | ||
| [UnsupportedOSPlatform("ios")] | ||
| [UnsupportedOSPlatform("tvos")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public static SafeEvpPKeyHandle OpenPublicKeyFromEngine(string engineName, string keyId) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(engineName); | ||
| ArgumentException.ThrowIfNullOrEmpty(keyId); | ||
| if (!Interop.OpenSslNoInit.OpenSslIsAvailable) | ||
| { | ||
| throw new PlatformNotSupportedException(SR.PlatformNotSupported_CryptographyOpenSSL); | ||
| } | ||
| return Interop.Crypto.LoadPublicKeyFromEngine(engineName, keyId); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I've never been able to store/load a public key in an engine before. Usually, with both TPM and PKCS#11 (via SoftHSM) the public keys were embedded in the X.509 certificate. That said, this could be allowed by some engines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point but as @bartonjs has already responded:#55356 (comment) "it's a low enough incremental cost that it doesn't hurt." which I fully agree