-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Switch to dynamic cert gen for tests #39685
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
7 commits
Select commit
Hold shift + click to select a range
9d03931
Switch to dynamic cert gen for tests
HaoK ed3fc9c
Try making cert older for linux
HaoK b9a5e89
Enable ubuntu skip
HaoK 4a19702
Only skip on ubuntu
HaoK 4219244
Update CertificateTests.cs
HaoK cbabce3
Reskip failing tests
HaoK d4f81a8
Get rid of cer files, use new shared helper
HaoK 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Security.Cryptography; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
public static class Certificates | ||
{ | ||
private static string ServerEku = "1.3.6.1.5.5.7.3.1"; | ||
private static string ClientEku = "1.3.6.1.5.5.7.3.2"; | ||
|
||
static Certificates() | ||
{ | ||
DateTimeOffset now = DateTimeOffset.UtcNow; | ||
|
||
SelfSignedPrimaryRoot = MakeCert( | ||
"CN=Valid Self Signed Client EKU,OU=dev,DC=idunno-dev,DC=org", | ||
ClientEku, | ||
now); | ||
|
||
SignedSecondaryRoot = MakeCert( | ||
"CN=Valid Signed Secondary Root EKU,OU=dev,DC=idunno-dev,DC=org", | ||
ClientEku, | ||
now); | ||
|
||
SelfSignedValidWithServerEku = MakeCert( | ||
"CN=Valid Self Signed Server EKU,OU=dev,DC=idunno-dev,DC=org", | ||
ServerEku, | ||
now); | ||
|
||
SelfSignedValidWithClientEku = MakeCert( | ||
"CN=Valid Self Signed Server EKU,OU=dev,DC=idunno-dev,DC=org", | ||
ClientEku, | ||
now); | ||
|
||
SelfSignedValidWithNoEku = MakeCert( | ||
"CN=Valid Self Signed No EKU,OU=dev,DC=idunno-dev,DC=org", | ||
eku: null, | ||
now); | ||
|
||
SelfSignedExpired = MakeCert( | ||
"CN=Expired Self Signed,OU=dev,DC=idunno-dev,DC=org", | ||
eku: null, | ||
now.AddYears(-2), | ||
now.AddYears(-1)); | ||
|
||
SelfSignedNotYetValid = MakeCert( | ||
"CN=Not Valid Yet Self Signed,OU=dev,DC=idunno-dev,DC=org", | ||
eku: null, | ||
now.AddYears(2), | ||
now.AddYears(3)); | ||
|
||
SignedClient = MakeCert( | ||
"CN=Valid Signed Client,OU=dev,DC=idunno-dev,DC=org", | ||
ClientEku, | ||
now); | ||
|
||
} | ||
|
||
private static readonly X509KeyUsageExtension s_digitalSignatureOnlyUsage = | ||
new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, true); | ||
|
||
private static X509Certificate2 MakeCert( | ||
string subjectName, | ||
string eku, | ||
DateTimeOffset now) | ||
{ | ||
return MakeCert(subjectName, eku, now, now.AddYears(5)); | ||
} | ||
|
||
private static X509Certificate2 MakeCert( | ||
string subjectName, | ||
string eku, | ||
DateTimeOffset notBefore, | ||
DateTimeOffset notAfter) | ||
{ | ||
using (var key = RSA.Create(2048)) | ||
{ | ||
CertificateRequest request = new CertificateRequest( | ||
subjectName, | ||
key, | ||
HashAlgorithmName.SHA256, | ||
RSASignaturePadding.Pkcs1); | ||
|
||
request.CertificateExtensions.Add(s_digitalSignatureOnlyUsage); | ||
|
||
if (eku != null) | ||
{ | ||
request.CertificateExtensions.Add( | ||
new X509EnhancedKeyUsageExtension( | ||
new OidCollection { new Oid(eku, null) }, false)); | ||
} | ||
|
||
return request.CreateSelfSigned(notBefore, notAfter); | ||
} | ||
} | ||
|
||
public static X509Certificate2 SelfSignedPrimaryRoot { get; private set; } | ||
|
||
public static X509Certificate2 SignedSecondaryRoot { get; private set; } | ||
|
||
public static X509Certificate2 SignedClient { get; private set; } | ||
|
||
public static X509Certificate2 SelfSignedValidWithClientEku { get; private set; } | ||
|
||
public static X509Certificate2 SelfSignedValidWithNoEku { get; private set; } | ||
|
||
public static X509Certificate2 SelfSignedValidWithServerEku { get; private set; } | ||
|
||
public static X509Certificate2 SelfSignedNotYetValid { get; private set; } | ||
|
||
public static X509Certificate2 SelfSignedExpired { get; private set; } | ||
} |
Binary file removed
BIN
-920 Bytes
src/Shared/test/Certificates/selfSignedNoEkuCertificateExpired.cer
Binary file not shown.
Binary file removed
BIN
-932 Bytes
src/Shared/test/Certificates/selfSignedNoEkuCertificateNotValidYet.cer
Binary file not shown.
Binary file removed
BIN
-928 Bytes
src/Shared/test/Certificates/validSelfSignedClientEkuCertificate.cer
Binary file not shown.
Binary file not shown.
20 changes: 0 additions & 20 deletions
20
src/Shared/test/Certificates/validSelfSignedPrimaryRootCertificate.cer
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-928 Bytes
src/Shared/test/Certificates/validSelfSignedServerEkuCertificate.cer
Binary file not shown.
20 changes: 0 additions & 20 deletions
20
src/Shared/test/Certificates/validSignedClientCertificate.cer
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/Shared/test/Certificates/validSignedSecondaryRootCertificate.cer
This file was deleted.
Oops, something went wrong.
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
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.