Skip to content

Commit

Permalink
ab#52646
Browse files Browse the repository at this point in the history
  • Loading branch information
leefine02 authored and leefine02 committed Jun 3, 2024
1 parent 72e67c3 commit 37e0c9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
2 changes: 1 addition & 1 deletion F5WafOrchestrator/CA/Management.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
break;
case CertStoreOperationType.Remove:
_logger.LogDebug($"BEGIN Delete Operation for {config.CertificateStoreDetails.StorePath} on {config.CertificateStoreDetails.ClientMachine}.");
F5Client.RemoveCaCertificate(config.CertificateStoreDetails.StorePath, config.JobCertificate.Alias);
F5Client.RemoveCaOrTlsCertificate(config.CertificateStoreDetails.StorePath, config.JobCertificate.Alias, false);
_logger.LogDebug($"END Delete Operation for {config.CertificateStoreDetails.StorePath} on {config.CertificateStoreDetails.ClientMachine}.");
break;
default:
Expand Down
39 changes: 7 additions & 32 deletions F5WafOrchestrator/F5WafClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,42 +502,13 @@ public CaPostRoot FormatCaCertificateRequest(ManagementJobCertificate mgmtJobCer
return reqBody;
}

public void RemoveTlsCertificate(string f5Namespace, string certName)
public void RemoveCaOrTlsCertificate(string f5Namespace, string certName, bool isTLSCertificate)
{
_logger.MethodEntry(LogLevel.Debug);

var response = F5Client.DeleteAsync($"/api/config/namespaces/{f5Namespace}/certificates/{certName}");
response.Wait();
var stringResponse = response.Result.Content.ReadAsStringAsync();
stringResponse.Wait();

//parse status code for error handling
string statusCode = string.Empty;
string[] respMessage = response.Result.ToString().Split(',');
for (int i = 0; i < respMessage.Length; i++)
{
if (respMessage[i].Contains("StatusCode:"))
{
statusCode = respMessage[i].Trim().Substring("StatsCode: ".Length).Trim();
break;
}
}

if (statusCode != "200")
{
var errorMessage = response.Result.Content.ReadAsStringAsync();
errorMessage.Wait();
throw new F5WAFException(errorMessage.ToString());
}

_logger.MethodExit(LogLevel.Debug);
}

public void RemoveCaCertificate(string f5Namespace, string certName)
{
_logger.MethodEntry(LogLevel.Debug);
string certType = isTLSCertificate ? "certificates" : "trusted_ca_lists";

var response = F5Client.DeleteAsync($"/api/config/namespaces/{f5Namespace}/trusted_ca_lists/{certName}");
var response = F5Client.DeleteAsync($"/api/config/namespaces/{f5Namespace}/{certType}/{certName}");
response.Wait();
var stringResponse = response.Result.Content.ReadAsStringAsync();
stringResponse.Wait();
Expand Down Expand Up @@ -776,6 +747,8 @@ public bool JobCertIsAttachedToHttpLoadBalancer(string f5Namespace, string jobCe

private string SubmitGetRequest(string endpoint)
{
_logger.MethodEntry(LogLevel.Debug);

var response = F5Client.GetAsync(endpoint).Result;
var result = response.Content.ReadAsStringAsync().Result;

Expand All @@ -790,6 +763,8 @@ private string SubmitGetRequest(string endpoint)
throw new F5WAFException(errorMessage);
}

_logger.MethodExit(LogLevel.Debug);

return result;
}

Expand Down
2 changes: 1 addition & 1 deletion F5WafOrchestrator/TLS/Management.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void PerformTlsCertRemove(ManagementJobConfiguration config)
"The job cert is bound to an http load balancer. Must unbind before performing management job.");
}

F5Client.RemoveTlsCertificate(config.CertificateStoreDetails.StorePath, config.JobCertificate.Alias);
F5Client.RemoveCaOrTlsCertificate(config.CertificateStoreDetails.StorePath, config.JobCertificate.Alias, true);

_logger.MethodExit(LogLevel.Debug);
}
Expand Down

0 comments on commit 37e0c9d

Please sign in to comment.