-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows CNG virtualization-based security (#102495)
* Windows CNG virtualization-based security * Add missing change in Microsoft.Bcl.Cryptography.Tests
- Loading branch information
Showing
27 changed files
with
255 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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 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
75 changes: 75 additions & 0 deletions
75
src/libraries/Common/tests/System/Security/Cryptography/CngKeyWrapper.cs
This file contains 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,75 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using Xunit; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Security.Cryptography; | ||
|
||
namespace Test.Cryptography | ||
{ | ||
internal sealed class CngKeyWrapper : IDisposable | ||
{ | ||
private CngKeyWrapper( | ||
CngAlgorithm algorithm, | ||
CngKeyCreationParameters cngCreationParameters, | ||
string? keySuffix = null, | ||
[CallerMemberName] string? testName = null) | ||
{ | ||
Key = CngKey.Create(algorithm, $"{testName}{algorithm.Algorithm}{keySuffix}", cngCreationParameters); | ||
} | ||
|
||
public static CngKeyWrapper CreateMicrosoftPlatformCryptoProvider( | ||
CngAlgorithm algorithm, | ||
string? keySuffix = null, | ||
[CallerMemberName] string? testName = null, | ||
CngKeyCreationOptions creationOption = CngKeyCreationOptions.None, | ||
params CngProperty[] additionalParameters) | ||
{ | ||
const string MicrosoftPlatformCryptoProvider = "Microsoft Platform Crypto Provider"; | ||
|
||
#if NETFRAMEWORK | ||
CngProvider cngProvider = new(MicrosoftPlatformCryptoProvider); | ||
#else | ||
Assert.Equal(MicrosoftPlatformCryptoProvider, CngProvider.MicrosoftPlatformCryptoProvider.Provider); | ||
CngProvider cngProvider = CngProvider.MicrosoftPlatformCryptoProvider; | ||
#endif | ||
CngKeyCreationParameters cngCreationParameters = new() | ||
{ | ||
Provider = cngProvider, | ||
KeyCreationOptions = creationOption | CngKeyCreationOptions.OverwriteExistingKey, | ||
}; | ||
|
||
foreach (CngProperty parameter in additionalParameters) | ||
{ | ||
cngCreationParameters.Parameters.Add(parameter); | ||
} | ||
|
||
return new CngKeyWrapper(algorithm, cngCreationParameters, keySuffix, testName); | ||
} | ||
|
||
public static CngKeyWrapper CreateMicrosoftSoftwareKeyStorageProvider( | ||
CngAlgorithm algorithm, | ||
CngKeyCreationOptions creationOption, | ||
string? keySuffix = null, | ||
[CallerMemberName] string? testName = null) | ||
{ | ||
CngKeyCreationParameters cngCreationParameters = new() | ||
{ | ||
Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider, | ||
KeyCreationOptions = creationOption | CngKeyCreationOptions.OverwriteExistingKey, | ||
}; | ||
|
||
return new CngKeyWrapper(algorithm, cngCreationParameters, keySuffix, testName); | ||
} | ||
|
||
public CngKey Key { get; } | ||
|
||
public void Dispose() | ||
{ | ||
Key.Delete(); | ||
} | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
src/libraries/Common/tests/System/Security/Cryptography/CngPlatformProviderKey.cs
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.