diff --git a/hashicorp-vault-orchestrator/HcvKeyValueClient.cs b/hashicorp-vault-orchestrator/HcvKeyValueClient.cs index 78438dd..3fb1dbf 100644 --- a/hashicorp-vault-orchestrator/HcvKeyValueClient.cs +++ b/hashicorp-vault-orchestrator/HcvKeyValueClient.cs @@ -38,9 +38,6 @@ public class HcvKeyValueClient : IHashiClient //private VaultClientSettings clientSettings { get; set; } - private static readonly string privKeyStart = "-----BEGIN RSA PRIVATE KEY-----\n"; - private static readonly string privKeyEnd = "\n-----END RSA PRIVATE KEY-----"; - public HcvKeyValueClient(string vaultToken, string serverUrl, string mountPoint, string storePath) { // Initialize one of the several auth methods. @@ -193,10 +190,8 @@ public async Task PutCertificate(string certName, string contents, string pfxPas try { - privateKeyString = privateKeyString.Replace(privKeyStart, "").Replace(privKeyEnd, ""); certDict.Add("PRIVATE_KEY", privateKeyString); certDict.Add("PUBLIC_KEY", pubCertPem); - certDict.Add("KEY_SECRET", pfxPassword); } catch (Exception ex) { @@ -279,9 +274,15 @@ public async Task> GetCertificates() return certs; } + private static Func Pemify = base64Cert => + { + string FormatBase64(string ss) => + ss.Length <= 64 ? ss : ss.Substring(0, 64) + "\n" + FormatBase64(ss.Substring(64)); + string header = "-----BEGIN CERTIFICATE-----\n"; + string footer = "\n-----END CERTIFICATE-----"; - private static Func Pemify = ss => - ss.Length <= 64 ? ss : ss.Substring(0, 64) + "\n" + Pemify(ss.Substring(64)); + return header + FormatBase64(base64Cert) + footer; + }; } }