-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI command for generating a certificate for webhook signatures (#…
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...RecordSystem/src/TeachingRecordSystem.Cli/Commands.GenerateWebhookSignatureCertificate.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,29 @@ | ||
using System.Security.Cryptography; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace TeachingRecordSystem.Cli; | ||
|
||
public static partial class Commands | ||
{ | ||
public static Command CreateGenerateWebhookSignatureCertificateCommand(IConfiguration configuration) | ||
{ | ||
var command = new Command( | ||
"generate-webhook-signature-certificate", | ||
$"Generates a new self-signed certificate and outputs its private key and certificate to key.pem and certificate.pem, respectively."); | ||
|
||
command.SetHandler( | ||
() => | ||
{ | ||
var key = ECDsa.Create(ECCurve.NamedCurves.nistP384); | ||
var certRequest = new CertificateRequest("CN=Teaching Record System", key, HashAlgorithmName.SHA384); | ||
var cert = certRequest.CreateSelfSigned(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(1)); | ||
var certPem = cert.ExportCertificatePem(); | ||
var keyPem = key.ExportECPrivateKeyPem(); | ||
|
||
File.WriteAllText("key.pem", keyPem); | ||
File.WriteAllText("certificate.pem", certPem); | ||
}); | ||
|
||
return command; | ||
} | ||
} |
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