Skip to content

Commit

Permalink
Common name is extracted from hosts and ip addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
nomailme committed Apr 7, 2021
1 parent eb92a91 commit 3b73b85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion source/TestAuthorityCore/Contracts/CertificateRequestModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Linq;

namespace TestAuthorityCore.Contracts
{
Expand All @@ -7,10 +8,27 @@ namespace TestAuthorityCore.Contracts
/// </summary>
public class CertificateRequestModel
{
private string commonName = string.Empty;
/// <summary>
/// Common Name
/// </summary>
public string CommonName { get; set; } = "Certificate";
public string CommonName
{
get
{
if (string.IsNullOrEmpty(commonName))
{
var allSanRecords = Hostname.ToList().Concat(IpAddress);
var firstRecord = allSanRecords.First();
return $"{firstRecord} certificate";
}
return commonName;
}
set
{
commonName = value;
}
}

/// <summary>
/// Password that will be used for PFX file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public byte[] GenerateCrl()
/// </summary>
/// <param name="request">Certificate Request.</param>
/// <returns>Certificate <seecref name="CertificateWithKey"/>.</returns>
public CertificateWithKey GenerateSslCertificate(PfxCertificateRequest request)
public CertificateWithKey GenerateSslCertificate(CertificateRequest request)
{
DateTimeOffset notBefore = DateTimeOffset.UtcNow.AddHours(-2);
DateTimeOffset notAfter = DateTimeOffset.UtcNow.AddDays(request.ValidtyInDays);
Expand Down
2 changes: 1 addition & 1 deletion source/TestAuthorityCore/X509/PfxCertificateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TestAuthorityCore.X509
/// <summary>
/// Request for certificate.
/// </summary>
public class PfxCertificateRequest
public class CertificateRequest
{
/// <summary>
/// Common name of the certificate.
Expand Down

0 comments on commit 3b73b85

Please sign in to comment.