Skip to content

Commit

Permalink
added certificate validity
Browse files Browse the repository at this point in the history
  • Loading branch information
nomailme committed Apr 28, 2020
1 parent 8acd67f commit fea7697
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions source/TestAuthorityCore/Controllers/CertificateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public IActionResult GetRootCertificate()
{
byte[] result = rootCertificateService.GetRootCertificate().Certificate.RawData;
return File(result, MediaTypeNames.Application.Octet, "root.cer");
}
}

/// <summary>
/// Generate current Crl.
/// </summary>
Expand All @@ -48,7 +48,7 @@ public IActionResult GetCrl()
/// <param name="filename"></param>
/// <returns></returns>
[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())
{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions source/TestAuthorityCore/X509/PfxCertificateRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace TestAuthorityCore.X509
{
Expand All @@ -10,6 +9,9 @@ public class PfxCertificateRequest
public List<string> Hostnames { get; set; }

public List<string> IpAddresses { get; set; }

public string Password { get; set; }

public int ValidtyInDays { get; set; } = 364;
}
}

0 comments on commit fea7697

Please sign in to comment.