Skip to content

Commit

Permalink
Merge pull request #23 from Keyfactor/main
Browse files Browse the repository at this point in the history
Pull 2.0.1
  • Loading branch information
leefine02 authored Jan 19, 2024
2 parents 460ae06 + d7f866d commit b367ed6
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 221 deletions.
55 changes: 16 additions & 39 deletions .github/workflows/keyfactor-starter-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
name: Starter Workflow
on: [workflow_dispatch, push, pull_request]
name: Keyfactor Bootstrap Workflow

jobs:
call-create-github-release-workflow:
uses: Keyfactor/actions/.github/workflows/github-release.yml@main

get-manifest-properties:
runs-on: windows-latest
outputs:
update_catalog: ${{ steps.read-json.outputs.prop }}
steps:
- uses: actions/checkout@v3
- name: Read json
id: read-json
shell: pwsh
run: |
$json = Get-Content integration-manifest.json | ConvertFrom-Json
echo "::set-output name=prop::$(echo $json.update_catalog)"
call-dotnet-build-and-release-workflow:
needs: [call-create-github-release-workflow]
uses: Keyfactor/actions/.github/workflows/dotnet-build-and-release.yml@main
with:
release_version: ${{ needs.call-create-github-release-workflow.outputs.release_version }}
release_url: ${{ needs.call-create-github-release-workflow.outputs.release_url }}
release_dir: CitrixAdcOrchestratorJobExtension/bin/Release/netcoreapp3.1 # output directory to upload as a release, relative to checkout workspace
secrets:
token: ${{ secrets.PRIVATE_PACKAGE_ACCESS }}
on:
workflow_dispatch:
pull_request:
types: [opened, closed, synchronize, edited, reopened]
push:
create:
branches:
- 'release-*.*'

call-generate-readme-workflow:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: Keyfactor/actions/.github/workflows/generate-readme.yml@main
jobs:
call-starter-workflow:
uses: keyfactor/actions/.github/workflows/starter.yml@v2
secrets:
token: ${{ secrets.APPROVE_README_PUSH }}

call-update-catalog-workflow:
needs: get-manifest-properties
if: needs.get-manifest-properties.outputs.update_catalog == 'True' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
uses: Keyfactor/actions/.github/workflows/update-catalog.yml@main
secrets:
token: ${{ secrets.SDK_SYNC_PAT }}
token: ${{ secrets.V2BUILDTOKEN}}
APPROVE_README_PUSH: ${{ secrets.APPROVE_README_PUSH}}
gpg_key: ${{ secrets.KF_GPG_PRIVATE_KEY }}
gpg_pass: ${{ secrets.KF_GPG_PASSPHRASE }}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.0.1
* Fixed Issue with Inventory when VServer Cannot be retreived by Citrix API

2.0.0
* Added AutoSave Configuration (default set to false)
* Added PAM Support
Expand Down
18 changes: 13 additions & 5 deletions CitrixAdcOrchestratorJobExtension/CitrixAdcStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,13 @@ public X509Certificate2 GetX509Certificate(string fileLocation, out bool hasKey)
return null;
}

//Ignore Directories
if (f.filemode != null && f.filemode[0].ToUpper() == "DIRECTORY")
{
hasKey = false;
return null;
}

// Determine if it's a cert
X509Certificate2 x = null;
try
Expand Down Expand Up @@ -718,7 +725,8 @@ public X509Certificate2 GetX509Certificate(string fileLocation, out bool hasKey)
// check .key file
try
{
var keyFile = GetSystemFile(fileLocation + ".key");
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileLocation);
var keyFile = GetSystemFile(fileNameWithoutExtension + ".key");
keyString = Encoding.UTF8.GetString(Convert.FromBase64String(keyFile.filecontent));
}
catch (Exception e)
Expand Down Expand Up @@ -770,7 +778,7 @@ private systemfile GetSystemFile(string fileName)

//option.set_args($"filelocation:{urlPath},filename:{fileName}");
option.filelocation = StorePath;
var f = new systemfile {filelocation = StorePath, filename = fileName};
var f = new systemfile { filelocation = StorePath, filename = fileName };
var result = systemfile.get(_nss, f);
Logger.LogDebug("Exiting GetSystemFile(string fileName)");
return result;
Expand Down Expand Up @@ -843,10 +851,10 @@ private bool EvaluatePrivateKey(X509Certificate2 cert, string keyString)
if (string.IsNullOrEmpty(keyString)) return false;
try
{
var keypair = (AsymmetricCipherKeyPair) new PemReader(new StringReader(keyString)).ReadObject();
var privateKey = (RsaPrivateCrtKeyParameters) keypair.Private;
var keypair = (AsymmetricCipherKeyPair)new PemReader(new StringReader(keyString)).ReadObject();
var privateKey = (RsaPrivateCrtKeyParameters)keypair.Private;

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

return privateKey.Modulus.Equals(publicKey.Modulus) &&
Expand Down
36 changes: 22 additions & 14 deletions CitrixAdcOrchestratorJobExtension/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitIn


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

_logger.LogDebug("Logging into Citrix...");
store.Login();
Expand All @@ -76,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 @@ -109,7 +109,7 @@ private JobResult ProcessJob(CitrixAdcStore store, InventoryJobConfiguration job

processedAliases.Add(s);

Dictionary<string,object> parameters = new Dictionary<string, object>();
Dictionary<string, object> parameters = new Dictionary<string, object>();

var containsKeyWithPath = keyPairMap.ContainsKey(store.StorePath + "/" + s);
var containsKey = keyPairMap.ContainsKey(s);
Expand All @@ -126,17 +126,25 @@ private JobResult ProcessJob(CitrixAdcStore store, InventoryJobConfiguration job
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);
string bindingsCsv = string.Empty;
foreach (string server in virtualServerName.Split(','))
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)
{
var bindings = store.GetBindingByVServer(server);
var first = bindings.FirstOrDefault(b => b.certkeyname == keyPairName);
if (first != null) bindingsCsv += first.snicert + ",";
_logger.LogError($"Error handling SNI or VServerBindings {LogHandler.FlattenException(e)}");
}
parameters.Add("sniCert", bindingsCsv.TrimEnd(','));

}
}

Expand Down Expand Up @@ -198,4 +206,4 @@ private JobResult ProcessJob(CitrixAdcStore store, InventoryJobConfiguration job
}
}
}
}
}
Loading

0 comments on commit b367ed6

Please sign in to comment.