Skip to content

Commit

Permalink
Merge final changes from 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Henderson committed Jan 11, 2024
1 parent 9683808 commit 6558102
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
21 changes: 16 additions & 5 deletions CitrixAdcOrchestratorJobExtension/CitrixAdcStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,14 @@ public X509Certificate2 GetX509Certificate(string fileLocation, out bool hasKey)
}
catch
{
logger.LogError("Error Occurred in GetSystemFile(fileLocation)");
Logger.LogError("Error Occurred in GetSystemFile(fileLocation)");
hasKey = false;
return null;
}

//Ignore Directories
if (f.filemode != null && f.filemode[0].ToUpper() == "DIRECTORY")
{
hasKey = false;
return null;
}
Expand Down Expand Up @@ -746,8 +753,12 @@ private systemfile GetSystemFile(string fileName)
var option = new systemfile_args();
Logger.LogTrace($"urlPath: {StorePath} fileName:{fileName}");

logger.LogDebug($"filelocation:{urlPath},filename:{fileName} not found");
throw new Exception("file not found");
//option.set_args($"filelocation:{urlPath},filename:{fileName}");
option.filelocation = StorePath;
var f = new systemfile { filelocation = StorePath, filename = fileName };
var result = systemfile.get(_nss, f);
Logger.LogDebug("Exiting GetSystemFile(string fileName)");
return result;
}
catch (Exception e)
{
Expand Down Expand Up @@ -820,8 +831,8 @@ private bool EvaluatePrivateKey(X509Certificate2 cert, string keyString)
var keypair = (AsymmetricCipherKeyPair)new PemReader(new StringReader(keyString)).ReadObject();
var privateKey = (RsaPrivateCrtKeyParameters)keypair.Private;

var publicKey = (RsaKeyParameters) DotNetUtilities.FromX509Certificate(cert).GetPublicKey();
logger.LogDebug("Exiting EvaluatePrivateKey(X509Certificate2 cert, string keyString)");
var publicKey = (RsaKeyParameters)DotNetUtilities.FromX509Certificate(cert).GetPublicKey();
Logger.LogDebug("Exiting EvaluatePrivateKey(X509Certificate2 cert, string keyString)");

return privateKey.Modulus.Equals(publicKey.Modulus) &&
publicKey.Exponent.Equals(privateKey.PublicExponent);
Expand Down
50 changes: 33 additions & 17 deletions CitrixAdcOrchestratorJobExtension/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ public Inventory(IPAMSecretResolver resolver)

public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitInventoryUpdate submitInventoryUpdate)
{
logger.LogDebug($"Client Machine: {jobConfiguration.CertificateStoreDetails.ClientMachine}");
logger.LogDebug($"UseSSL: {jobConfiguration.UseSSL}");
logger.LogDebug($"StorePath: {jobConfiguration.CertificateStoreDetails.StorePath}");
_logger = LogHandler.GetClassLogger<Inventory>();
_logger.LogDebug($"Client Machine: {jobConfiguration.CertificateStoreDetails.ClientMachine}");
_logger.LogDebug($"UseSSL: {jobConfiguration.UseSSL}");
_logger.LogDebug($"StorePath: {jobConfiguration.CertificateStoreDetails.StorePath}");
ServerPassword = ResolvePamField("ServerPassword", jobConfiguration.ServerPassword);
ServerUserName = ResolvePamField("ServerUserName", jobConfiguration.ServerUsername);

logger.LogDebug("Entering ProcessJob");
CitrixAdcStore store = new CitrixAdcStore(jobConfiguration);

logger.LogDebug("Logging into Citrix...");
_logger.LogDebug("Entering ProcessJob");
CitrixAdcStore store = new CitrixAdcStore(jobConfiguration, ServerUserName, ServerPassword);

_logger.LogDebug("Logging into Citrix...");
store.Login();

JobResult result = ProcessJob(store, jobConfiguration, submitInventoryUpdate);
Expand All @@ -72,8 +76,8 @@ private string ResolvePamField(string name, string value)

private JobResult ProcessJob(CitrixAdcStore store, InventoryJobConfiguration jobConfiguration, SubmitInventoryUpdate submitInventoryUpdate)
{
logger.LogDebug("Begin Inventory...");
_logger.LogDebug("Begin New Bindings Fix Inventory...");

List<CurrentInventoryItem> inventory = new List<CurrentInventoryItem>();

try
Expand Down Expand Up @@ -120,18 +124,30 @@ private JobResult ProcessJob(CitrixAdcStore store, InventoryJobConfiguration job
var binding = store.GetBinding(keyPairName);

var vserverBindings = binding?.sslcertkey_sslvserver_binding;
if (vserverBindings != null) {
var virtualServerName = String.Join(",", vserverBindings.Select(p=>p.servername));
logger.LogDebug($"Found virtualServerName(s): {virtualServerName}");
parameters.Add("virtualServerName", virtualServerName);
if (vserverBindings != null)
{
try
{
var virtualServerName = String.Join(",", vserverBindings.Select(p => p.servername));
_logger.LogDebug($"Found virtualServerName(s): {virtualServerName}");
parameters.Add("virtualServerName", virtualServerName);
string bindingsCsv = string.Empty;
foreach (string server in virtualServerName.Split(','))
{
var bindings = store.GetBindingByVServer(server);
var first = bindings.FirstOrDefault(b => b.certkeyname == keyPairName);
if (first != null) bindingsCsv += first.snicert + ",";
}
parameters.Add("sniCert", bindingsCsv.TrimEnd(','));
}
catch (Exception e)
{
_logger.LogError($"Error handling SNI or VServerBindings {LogHandler.FlattenException(e)}");
}

}
//TODO: Other binding methods
//binding.sslcertkey_service_binding
//binding.sslcertkey_crldistribution_binding
//binding.sslcertkey_sslocspresponder_binding
}


inventory.Add(new CurrentInventoryItem()
{
Alias = s,
Expand Down

0 comments on commit 6558102

Please sign in to comment.