Files
MTSC/MTSC.OAuth2.Tests/CertificateUtilities.cs
amacocian 0fe9f9957c Setup OAuth2 support (#20)
* Setup OAuth2 support

* Setup tests project

* Setup OAuth2 unit tests in CI pipeline

* Setup authorizeattribute tests

* Test

* Setup tests for AuthorizeAttribute

* Setup OAuth2 support
Unit Tests coverage

* Add OAuth2 project to release
2022-09-02 16:13:08 +02:00

30 lines
927 B
C#

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace MTSC.OAuth2.Tests;
public static class CertificateUtilities
{
public static X509Certificate2 CreateNewSelfSignedCertificate()
{
using var parent = RSA.Create(4096);
using var rsa = RSA.Create(2048);
var parentReq = new CertificateRequest(
"CN=Experimental Issuing Authority",
parent,
HashAlgorithmName.SHA256,
RSASignaturePadding.Pkcs1);
parentReq.CertificateExtensions.Add(
new X509BasicConstraintsExtension(true, false, 0, true));
parentReq.CertificateExtensions.Add(
new X509SubjectKeyIdentifierExtension(parentReq.PublicKey, false));
return parentReq.CreateSelfSigned(
DateTimeOffset.UtcNow.AddDays(-45),
DateTimeOffset.UtcNow.AddDays(365));
}
}