Skip to content

Commit a49aa77

Browse files
author
Elena Fiocca
committed
Updated all filepaths to work cross-platform; Removed references to Axis.Trust; Updated HTTP client to use PAM credentials; Removed redundant qualifiers
1 parent e663e59 commit a49aa77

8 files changed

Lines changed: 44 additions & 34 deletions

File tree

AxisIPCamera/AxisIPCamera.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
<None Update="Files\GetMQTTBinding.json">
4444
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4545
</None>
46-
47-
<None Update="Files\Axis.Trust">
48-
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
49-
</None>
5046
</ItemGroup>
5147

5248
</Project>

AxisIPCamera/Client/AxisHttpClient.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public AxisHttpClient(JobConfiguration config, CertificateStore store, IPAMSecre
9797
string username = PAMUtilities.ResolvePAMField(resolver, Logger, "API Username", config.ServerUsername);
9898
string password = PAMUtilities.ResolvePAMField(resolver, Logger, "API Password", config.ServerPassword);
9999

100-
options.Authenticator = new HttpBasicAuthenticator(config.ServerUsername, config.ServerPassword);
100+
options.Authenticator = new HttpBasicAuthenticator(username, password);
101101

102102
// Add SSL validation
103103
Logger.LogTrace("Validating connection to the device...");
@@ -575,8 +575,8 @@ public void SetCertUsageBinding(string alias, Constants.CertificateUsage certUsa
575575
case Constants.CertificateUsage.Https:
576576
{
577577
Logger.LogTrace(
578-
$"Reading XML request body template from {assemblyPath}\\{Constants.SetHttpsTemplate}");
579-
var xmlTemplate = File.ReadAllText($"{assemblyPath}\\{Constants.SetHttpsTemplate}");
578+
$"Reading XML request body template from {Path.Combine(assemblyPath, Constants.SetHttpsTemplate)}");
579+
var xmlTemplate = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.SetHttpsTemplate)}");
580580
body = xmlTemplate.Replace("{ALIAS}", alias);
581581

582582
httpResponse = ExecuteHttp(Constants.SoapApiEntryPoint, Method.Post, Constants.ApiType.Soap,
@@ -587,8 +587,8 @@ public void SetCertUsageBinding(string alias, Constants.CertificateUsage certUsa
587587
case Constants.CertificateUsage.IEEE:
588588
{
589589
Logger.LogTrace(
590-
$"Reading XML request body template from {assemblyPath}\\{Constants.SetIEEETemplate}");
591-
var xmlTemplate = File.ReadAllText($"{assemblyPath}\\{Constants.SetIEEETemplate}");
590+
$"Reading XML request body template from {Path.Combine(assemblyPath, Constants.SetIEEETemplate)}");
591+
var xmlTemplate = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.SetIEEETemplate)}");
592592
body = xmlTemplate.Replace("{ALIAS}", alias);
593593

594594
httpResponse = ExecuteHttp(Constants.SoapApiEntryPoint, Method.Post, Constants.ApiType.Soap,
@@ -600,8 +600,8 @@ public void SetCertUsageBinding(string alias, Constants.CertificateUsage certUsa
600600
{
601601
// Get the config info that is required for the request body used to set the binding
602602
Logger.LogTrace(
603-
"Retrieve required MQTT configuration data required for the JSON request body to set the binding");
604-
var clientStatusBody = File.ReadAllText($"{assemblyPath}\\{Constants.GetMQTTTemplate}");
603+
$"Retrieve required MQTT configuration data required for the JSON request body to set the binding --- GET request body from {Path.Combine(assemblyPath, Constants.GetMQTTTemplate)}");
604+
var clientStatusBody = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.GetMQTTTemplate)}");
605605
var clientStatusResponse = ExecuteHttp(Constants.CgiApiEntryPoint, Method.Post,
606606
Constants.ApiType.Cgi,
607607
clientStatusBody);
@@ -656,7 +656,9 @@ public void SetCertUsageBinding(string alias, Constants.CertificateUsage certUsa
656656
throw new Exception($"Unable to parse JSON response: {ex2.Message}");
657657
}
658658

659-
var jsonTemplate = File.ReadAllText($"{assemblyPath}\\{Constants.SetMQTTTemplate}");
659+
Logger.LogTrace(
660+
$"Reading JSON request body template from {Path.Combine(assemblyPath, Constants.SetMQTTTemplate)}");
661+
var jsonTemplate = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.SetMQTTTemplate)}");
660662
Logger.LogDebug("Client Status Return Values - ");
661663
Logger.LogDebug("API Version: " + clientStatusData.ApiVersion);
662664
Logger.LogDebug("Host: " + clientStatusData.Data.Config.Server.Host);
@@ -786,24 +788,24 @@ public string GetCertUsageBinding(Constants.CertificateUsage certUsage)
786788
{
787789
case Constants.CertificateUsage.Https:
788790
{
789-
Logger.LogTrace($"Reading XML request body template from {assemblyPath}\\{Constants.GetHttpsTemplate}");
790-
body = File.ReadAllText($"{assemblyPath}\\{Constants.GetHttpsTemplate}");
791+
Logger.LogTrace($"Reading XML request body template from {Path.Combine(assemblyPath, Constants.GetHttpsTemplate)}");
792+
body = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.GetHttpsTemplate)}");
791793
httpResponse = ExecuteHttp(Constants.SoapApiEntryPoint, Method.Post, Constants.ApiType.Soap,body);
792794

793795
break;
794796
}
795797
case Constants.CertificateUsage.IEEE:
796798
{
797-
Logger.LogTrace($"Reading XML request body template from {assemblyPath}\\{Constants.GetIEEETemplate}");
798-
body = File.ReadAllText($"{assemblyPath}\\{Constants.GetIEEETemplate}");
799+
Logger.LogTrace($"Reading XML request body template from {Path.Combine(assemblyPath, Constants.GetIEEETemplate)}");
800+
body = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.GetIEEETemplate)}");
799801
httpResponse = ExecuteHttp(Constants.SoapApiEntryPoint, Method.Post, Constants.ApiType.Soap,body);
800802

801803
break;
802804
}
803805
case Constants.CertificateUsage.MQTT:
804806
{
805-
Logger.LogTrace($"Reading JSON request body template from {assemblyPath}\\{Constants.GetMQTTTemplate}");
806-
body = File.ReadAllText($"{assemblyPath}\\{Constants.GetMQTTTemplate}");
807+
Logger.LogTrace($"Reading JSON request body template from {Path.Combine(assemblyPath, Constants.GetMQTTTemplate)}");
808+
body = File.ReadAllText($"{Path.Combine(assemblyPath, Constants.GetMQTTTemplate)}");
807809
httpResponse = ExecuteHttp(Constants.CgiApiEntryPoint, Method.Post, Constants.ApiType.Cgi,body);
808810

809811
break;

AxisIPCamera/Helpers/DeviceCertValidator.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Linq;
1313
using System.Net.Http;
1414
using System.Net.Security;
15+
using System.Reflection;
1516
using System.Security.Cryptography.X509Certificates;
1617
using Microsoft.Extensions.Logging;
1718

@@ -59,8 +60,13 @@ public static class DeviceCertValidator
5960
logger.LogTrace($"Performing Cert Validator Check #1: Verify the TLS cert chain against custom chain of AXIS PKI certs...");
6061

6162
// Load custom trusted certs
62-
string trustedRootCertPath = "C:\\Program Files\\Keyfactor\\Keyfactor Orchestrator\\extensions\\AxisIPCamera\\Files\\Axis.Root";
63-
string trustedIntCertPath = "C:\\Program Files\\Keyfactor\\Keyfactor Orchestrator\\extensions\\AxisIPCamera\\Files\\Axis.Intermediate";
63+
string basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
64+
logger.LogTrace($"Base PATH for custom trusted certs: {basePath}");
65+
66+
string trustedRootCertPath = Path.Combine(basePath, "Files", "Axis.Root");
67+
string trustedIntCertPath = Path.Combine(basePath, "Files", "Axis.Intermediate");
68+
logger.LogTrace($"Combined PATH for custom trusted Root certs: {trustedRootCertPath}");
69+
logger.LogTrace($"Combined PATH for custom trusted Intermediate certs: {trustedIntCertPath}");
6470

6571
X509CertificateParser parser = new X509CertificateParser();
6672
var customChain = new List<X509Certificate> { };
@@ -207,6 +213,9 @@ public static class DeviceCertValidator
207213
private static bool VerifyAkiSkiChain(List<X509Certificate> customChain, ILogger logger)
208214
{
209215
logger.MethodEntry();
216+
217+
logger.LogTrace("Custom chain being validated includes: (1) Leaf cert from TLS session, (2) n-Intermediate certs from custom trust, &" +
218+
"n-Root certs from custom trust");
210219

211220
for (int i = 0; i < customChain.Count - 1; i++)
212221
{

AxisIPCamera/Inventory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
179179
{
180180
// ** NOTE: If the cause of the submitInventory.Invoke exception is a communication issue between the Orchestrator server and the Command server, the job status returned here
181181
// may not be reflected in Keyfactor Command.
182-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId,
182+
return new JobResult() { Result = OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId,
183183
FailureMessage = $"Inventory Job Failed During Inventory Item Submission: {e2.Message} - Refer to logs for more detailed information." };
184184
}
185185
}

AxisIPCamera/Management.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,17 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
197197
}
198198
default:
199199
//Invalid OperationType. Return error. Should never happen though
200-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = $"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}: Unsupported operation: {config.OperationType.ToString()}" };
200+
return new JobResult() { Result = OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = $"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}: Unsupported operation: {config.OperationType.ToString()}" };
201201
}
202202
}
203203
catch (Exception ex)
204204
{
205205
//Status: 2=Success, 3=Warning, 4=Error
206-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = $"Management Job Failed During '{config.OperationType.ToString()}' Operation: {ex.Message} - Refer to logs for more detailed information." };
206+
return new JobResult() { Result = OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = $"Management Job Failed During '{config.OperationType.ToString()}' Operation: {ex.Message} - Refer to logs for more detailed information." };
207207
}
208208

209209
//Status: 2=Success, 3=Warning, 4=Error
210-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Success, JobHistoryId = config.JobHistoryId };
210+
return new JobResult() { Result = OrchestratorJobStatusJobResult.Success, JobHistoryId = config.JobHistoryId };
211211
}
212212

213213
/// <summary>

AxisIPCamera/Model/Constants.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public static class Constants
3838

3939
// Below are the relative file paths to the SOAP and CGI API request body templates
4040
// ** NOTE: The 'Files' directory should be located in the same directory as the AxisIPCamera.dll
41-
public static string GetHttpsTemplate = $"Files\\GetHttpsBinding.xml";
42-
public static string GetIEEETemplate = $"Files\\GetIEEEBinding.xml";
43-
public static string GetMQTTTemplate = $"Files\\GetMQTTBinding.json";
44-
public static string SetHttpsTemplate = $"Files\\SetHttpsBinding.xml";
45-
public static string SetIEEETemplate = $"Files\\SetIEEEBinding.xml";
46-
public static string SetMQTTTemplate = $"Files\\SetMQTTBinding.json";
41+
public static readonly string GetHttpsTemplate = $"{Path.Combine("Files","GetHttpsBinding.xml")}";
42+
public static readonly string GetIEEETemplate = $"{Path.Combine("Files","GetIEEEBinding.xml")}";
43+
public static readonly string GetMQTTTemplate = $"{Path.Combine("Files","GetMQTTBinding.json")}";
44+
public static readonly string SetHttpsTemplate = $"{Path.Combine("Files", "SetHttpsBinding.xml")}";
45+
public static readonly string SetIEEETemplate = $"{Path.Combine("Files", "SetIEEEBinding.xml")}";
46+
public static readonly string SetMQTTTemplate = $"{Path.Combine("Files", "SetMQTTBinding.json")}";
4747

4848
public enum CertificateUsage
4949
{

AxisIPCamera/Reenrollment.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Keyfactor.Logging;
1616
using Keyfactor.Extensions.Orchestrator.AxisIPCamera.Client;
1717
using Keyfactor.Extensions.Orchestrator.AxisIPCamera.Model;
18+
using Keyfactor.Orchestrators.Common.Enums;
1819
using Keyfactor.Orchestrators.Extensions;
1920
using Keyfactor.Orchestrators.Extensions.Interfaces;
2021

@@ -173,12 +174,12 @@ public JobResult ProcessJob(ReenrollmentJobConfiguration config, SubmitReenrollm
173174
catch (Exception ex)
174175
{
175176
//Status: 2=Success, 3=Warning, 4=Error
176-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId,
177+
return new JobResult() { Result = OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId,
177178
FailureMessage = $"Reenrollment Job Failed: {ex.Message} - Refer to logs for more detailed information." };
178179
}
179180

180181
//Status: 2=Success, 3=Warning, 4=Error
181-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Success, JobHistoryId = config.JobHistoryId };
182+
return new JobResult() { Result = OrchestratorJobStatusJobResult.Success, JobHistoryId = config.JobHistoryId };
182183
}
183184
}
184185
}

docsource/content.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ To trust the device ID certificate, you must create a custom trust and add the r
4444

4545
### Steps to Create the Custom Trust:
4646

47-
1. Once the DLLs from GitHub are installed, create two (2) files in `..\[AXIS IP Camera orchestrator extension folder name]\Files` folder with the below names:
48-
* **Axis.Trust**
47+
1. Once the DLLs from GitHub are installed, create two (2) files in the sub-directory called "Files" with the below names (*Note: The "Files" folder should already exist):
48+
* **Axis.Root**
4949
* **Axis.Intermediate**
5050

51+
* **Default Path on Windows** - `C:\Program Files\Keyfactor\Keyfactor Orchestrator\extensions\[Axis IP Camera orchestrator extension folder]\Files`
52+
* **Default Path on Linux** - `/opt/keyfactor/orchestrator/extensions/[Axis IP Camera orchestrator extension folder]/Files`
5153
2. Copy and paste the PEM contents of the AXIS PKI root for the device ID cert configured for the HTTP server into the **Axis.Root** file
5254
3. Copy and paste the PEM contents of the AXIS PKI intermediate for the device ID configured for the HTTP server into the **Axis.Intermediate** file
5355

0 commit comments

Comments
 (0)