Skip to content

Commit 8ca5f19

Browse files
efioccaspbsoluble
authored andcommitted
Add logic to log warning attempting to remove a non-Trust cert
1 parent c3f5360 commit 8ca5f19

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

AxisIPCamera/Client/AxisHttpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public void AddCACertificate(string alias, string pemCert)
543543
/// Removes a CA certificate from the device.
544544
/// </summary>
545545
/// <param name="alias">Unique identifier of the CA certificate to be removed</param>
546-
public void RemoveCertificate(string alias)
546+
public void RemoveCACertificate(string alias)
547547
{
548548
try
549549
{

AxisIPCamera/Management.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,34 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
158158
// Retrieve management config from Command
159159
_logger.LogDebug($"Management Config {JsonConvert.SerializeObject(config)}");
160160
_logger.LogDebug($"Client Machine: {config.CertificateStoreDetails.ClientMachine}");
161+
162+
// Get needed information from config
163+
string alias = config.JobCertificate.Alias;
164+
string certBase64Der = config.JobCertificate.Contents;
161165

166+
// Prevent removal of client certs; Client certs may be removed as part of a future update
167+
if (IsCACertificate(certBase64Der))
168+
{
169+
_logger.LogInformation("Certificate is a CA trust cert. Proceeding with Remove operation...");
170+
}
171+
else
172+
{
173+
_logger.LogWarning("Certificate is an end-entity cert. Unable to remove this certificate type from a device.");
174+
return new JobResult()
175+
{
176+
Result = OrchestratorJobStatusJobResult.Warning,
177+
JobHistoryId = config.JobHistoryId,
178+
FailureMessage = $"UNSUPPORTED OPERATION --- This certificate is an end-entity cert. Unable to remove end-entity certificates from a device."
179+
};
180+
}
181+
162182
// Create client to connect to device
163183
_logger.LogTrace("Creating Api Rest Client...");
164184
var client = new AxisHttpClient(config, config.CertificateStoreDetails);
165185
_logger.LogTrace("Api Rest Client Created...");
166186

167-
// Get needed information from config
168-
string alias = config.JobCertificate.Alias;
169-
170187
// Remove certificate with alias from the device
171-
client.RemoveCertificate(alias);
188+
client.RemoveCACertificate(alias);
172189

173190
break;
174191
}

0 commit comments

Comments
 (0)