Skip to content

Commit

Permalink
Merge pull request dotnet#388 from dotnet/custom-cn
Browse files Browse the repository at this point in the history
Enable common name to be specified
  • Loading branch information
clairernovotny authored Jun 18, 2021
2 parents a8933a0 + 903fce3 commit cb51efa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/SignService/Controllers/KeyVaultController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task<IActionResult> CreateCertificate(CreateCertificateRequestModel
{
try
{
var csr = await keyVaultAdminService.CreateCsrAsync(model.VaultName, model.CertificateName, model.CertificateName);
var csr = await keyVaultAdminService.CreateCsrAsync(model.VaultName, model.CertificateId, model.CommonName);

return RedirectToAction(nameof(Details), new { id = model.VaultName });
}
Expand Down
10 changes: 8 additions & 2 deletions src/SignService/Models/CreateCertificateRequestModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;

using Microsoft.AspNetCore.Mvc;

namespace SignService.Models
{
public class CreateCertificateRequestModel
{
[HiddenInput]
public string VaultName { get; set; }
public string CertificateName { get; set; }

[DisplayName("Certificate Id in the Key Vault")]
public string CertificateId { get; set; }

public string CommonName { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/SignService/Services/KeyVaultAdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IKeyVaultAdminService
Task<DeleteCertificateOperation> CancelCsrAsync(string vaultName, string certificateName);
Task<KeyVaultCertificateWithPolicy> MergeCertificate(string vaultName, string certificateName, byte[] certData);
Task<CertificateOperation> GetCertificateOperation(Uri vaultUrl, string certificateName);
Task<CertificateOperation> CreateCsrAsync(string vaultName, string certificateName, string displayName);
Task<CertificateOperation> CreateCsrAsync(string vaultName, string certificateName, string commonName);
}

public class KeyVaultAdminService : IKeyVaultAdminService
Expand Down Expand Up @@ -300,9 +300,9 @@ public async Task<CertificateOperation> GetCertificateOperation(Uri vaultUrl, st
}
}

public async Task<CertificateOperation> CreateCsrAsync(string vaultName, string certificateName, string displayName)
public async Task<CertificateOperation> CreateCsrAsync(string vaultName, string certificateName, string commonName)
{
var policy = new CertificatePolicy("Unknown", $"CN={displayName}")
var policy = new CertificatePolicy("Unknown", $"CN={commonName}")
{
KeyType = CertificateKeyType.RsaHsm,
KeySize = 4096
Expand Down
11 changes: 8 additions & 3 deletions src/SignService/Views/KeyVault/CreateCertificate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
<form asp-action="CreateCertificate" asp-antiforgery="true">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="CertificateName" class="control-label"></label>
<input asp-for="CertificateName" class="form-control" />
<span asp-validation-for="CertificateName" class="text-danger"></span>
<label asp-for="CertificateId" class="control-label"></label>
<input asp-for="CertificateId" class="form-control" />
<span asp-validation-for="CertificateId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CommonName" class="control-label"></label>
<input asp-for="CommonName" class="form-control" />
<span asp-validation-for="CommonName" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
Expand Down

0 comments on commit cb51efa

Please sign in to comment.