Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KV-HCVault-SavingIssues #13

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions hashicorp-vault-orchestrator/HcvKeyValueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -279,9 +274,15 @@ public async Task<IEnumerable<CurrentInventoryItem>> GetCertificates()

return certs;
}
private static Func<string, string> 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<string, string> Pemify = ss =>
ss.Length <= 64 ? ss : ss.Substring(0, 64) + "\n" + Pemify(ss.Substring(64));
return header + FormatBase64(base64Cert) + footer;
};
}
}