diff --git a/source/TestAuthorityCore/Controllers/CertificateController.cs b/source/TestAuthorityCore/Controllers/CertificateController.cs index fe517c6..ab6e018 100644 --- a/source/TestAuthorityCore/Controllers/CertificateController.cs +++ b/source/TestAuthorityCore/Controllers/CertificateController.cs @@ -25,8 +25,8 @@ public IActionResult GetRootCertificate() { byte[] result = rootCertificateService.GetRootCertificate().Certificate.RawData; return File(result, MediaTypeNames.Application.Octet, "root.cer"); - } - + } + /// /// Generate current Crl. /// @@ -48,7 +48,7 @@ public IActionResult GetCrl() /// /// [HttpGet] - public IActionResult IssueCertificate([FromQuery] string commonName, [FromQuery] string password, [FromQuery] string[] hostname, [FromQuery] string[] ipAddress, [FromQuery] string filename = "certificate.pfx") + public IActionResult IssueCertificate([FromQuery] string commonName, [FromQuery] string password, [FromQuery] string[] hostname, [FromQuery] string[] ipAddress, [FromQuery] string filename = "certificate.pfx", [FromQuery] int validityInDays = 364) { if (hostname.IsNullOrEmpty()) { @@ -75,7 +75,8 @@ public IActionResult IssueCertificate([FromQuery] string commonName, [FromQuery] CommonName = commonName, Hostnames = hostname.ToList(), IpAddresses = ipAddress.ToList(), - Password = password + Password = password, + ValidtyInDays = validityInDays }; byte[] certificate = service.GenerateSslCertificate(request); diff --git a/source/TestAuthorityCore/Service/CertificateAuthorityService.cs b/source/TestAuthorityCore/Service/CertificateAuthorityService.cs index 44fd852..9bfc7ea 100644 --- a/source/TestAuthorityCore/Service/CertificateAuthorityService.cs +++ b/source/TestAuthorityCore/Service/CertificateAuthorityService.cs @@ -39,7 +39,7 @@ public byte[] GenerateCrl() public byte[] GenerateSslCertificate(PfxCertificateRequest request) { DateTimeOffset notBefore = DateTimeOffset.UtcNow.AddHours(-2); - DateTimeOffset notAfter = DateTimeOffset.UtcNow.AddYears(3); + DateTimeOffset notAfter = DateTimeOffset.UtcNow.AddDays(request.ValidtyInDays); SecureRandom random = randomService.GenerateRandom(); CertificateBuilder2 builder = builderFactory(random, SignerCertificate); diff --git a/source/TestAuthorityCore/X509/PfxCertificateRequest.cs b/source/TestAuthorityCore/X509/PfxCertificateRequest.cs index 3ca9c3b..1e365b6 100644 --- a/source/TestAuthorityCore/X509/PfxCertificateRequest.cs +++ b/source/TestAuthorityCore/X509/PfxCertificateRequest.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace TestAuthorityCore.X509 { @@ -10,6 +9,9 @@ public class PfxCertificateRequest public List Hostnames { get; set; } public List IpAddresses { get; set; } + public string Password { get; set; } + + public int ValidtyInDays { get; set; } = 364; } }