Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev release 2.1 #13

Closed
wants to merge 90 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
e355acb
Update generated README
Mar 17, 2023
b124d45
Panorama (#7)
fiddlermikey May 8, 2023
e1c60bc
Palo dev (#9)
bhillkeyfactor Sep 12, 2023
95e5f05
Merge branch 'main' into release-2.0
fiddlermikey Sep 12, 2023
0b3fccf
Update generated README
Sep 12, 2023
751a1d7
Update Entry.cs
fiddlermikey Sep 12, 2023
d5f971e
Update generated README
Feb 16, 2024
e1b44e9
Checkpoint
bhillkeyfactor Feb 22, 2024
9357f08
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Feb 22, 2024
55d529b
Path Changes
bhillkeyfactor Feb 22, 2024
75488ab
path changes
bhillkeyfactor Feb 22, 2024
2cdd99e
Checkpoint
bhillkeyfactor Feb 23, 2024
00be498
Binding Changes
bhillkeyfactor Feb 23, 2024
ea92ba4
Code Cleanup
bhillkeyfactor Feb 23, 2024
3d8ccb1
Fixed Error Handling
bhillkeyfactor Feb 26, 2024
418adf8
Fixed ErrorHandling
bhillkeyfactor Feb 27, 2024
d3c5a83
Private Key Fix
bhillkeyfactor Feb 27, 2024
ed53fb9
Path Validation
bhillkeyfactor Feb 27, 2024
5c401ed
Fixed path validation
bhillkeyfactor Feb 27, 2024
df407c7
fixed alias issue
bhillkeyfactor Feb 29, 2024
0b7e721
Test case fixes
bhillkeyfactor Feb 29, 2024
5f73e38
fixed test harness
bhillkeyfactor Feb 29, 2024
556b20f
Fixed inventory issue
bhillkeyfactor Mar 4, 2024
012b05b
Readme Updates
bhillkeyfactor Mar 5, 2024
340494c
Fixed Issues
bhillkeyfactor Mar 5, 2024
b53be1d
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
97c870d
Update generated README
Mar 5, 2024
0e125ac
readme updates
bhillkeyfactor Mar 5, 2024
ee32a1f
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
1a6cefd
Update generated README
Mar 5, 2024
cdccd4c
readme updates
bhillkeyfactor Mar 5, 2024
c7ff759
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
ee4e918
Update generated README
Mar 5, 2024
9271a0a
readme updates
bhillkeyfactor Mar 5, 2024
08d73c8
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
c63b354
Update generated README
Mar 5, 2024
d27c159
readme updates
bhillkeyfactor Mar 5, 2024
70efd68
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
cfc00bc
Update generated README
Mar 5, 2024
78e36ed
readme updates
bhillkeyfactor Mar 5, 2024
a8d95e8
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
3ea4673
Update generated README
Mar 5, 2024
04d7cef
readme updates
bhillkeyfactor Mar 5, 2024
a5bbdd9
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
138039c
Update generated README
Mar 5, 2024
6d55137
readme updates
bhillkeyfactor Mar 5, 2024
e84a68e
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
9a34e79
Update generated README
Mar 5, 2024
28c2f0b
readme updates
bhillkeyfactor Mar 5, 2024
313fc35
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
739c524
Update generated README
Mar 5, 2024
d4bd1f5
readme updates
bhillkeyfactor Mar 5, 2024
a7ec383
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
d2fd2e8
Update generated README
Mar 5, 2024
ab42efc
readme updates
bhillkeyfactor Mar 5, 2024
a0ebce2
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
21bdda4
Update generated README
Mar 5, 2024
5bc73c3
readme updates
bhillkeyfactor Mar 5, 2024
9e59ade
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
0b4d05a
Update generated README
Mar 5, 2024
b0fffbb
readme updates
bhillkeyfactor Mar 5, 2024
6363896
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
4c35ac1
Update generated README
Mar 5, 2024
5702fd0
readme updates
bhillkeyfactor Mar 5, 2024
e73ddfa
Update generated README
Mar 5, 2024
f214bcd
readme updates
bhillkeyfactor Mar 5, 2024
9b9093e
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
437d7c3
Update generated README
Mar 5, 2024
6e6bddf
readme updates
bhillkeyfactor Mar 5, 2024
908ea36
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
f53807b
Update generated README
Mar 5, 2024
b0c3f8e
readme updates
bhillkeyfactor Mar 5, 2024
4c3c5c9
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 5, 2024
1de9992
Update generated README
Mar 5, 2024
920e210
Update integration-manifest.json
bhillkeyfactor Mar 6, 2024
cbb048d
Update generated README
Mar 6, 2024
cab233a
Update integration-manifest.json
bhillkeyfactor Mar 6, 2024
6298ed6
Update integration-manifest.json
bhillkeyfactor Mar 6, 2024
9a98e83
readme updates
bhillkeyfactor Mar 6, 2024
aeaa67f
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 6, 2024
eb28d0f
Update generated README
Mar 6, 2024
8a9f7d7
readme updates
bhillkeyfactor Mar 6, 2024
5b7dfd7
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 6, 2024
10f0833
Update generated README
Mar 6, 2024
f69d985
readme updates
bhillkeyfactor Mar 6, 2024
87139b4
Merge branch 'dev_release_2.1' of https://github.com/Keyfactor/paloal…
bhillkeyfactor Mar 6, 2024
b75a221
Update generated README
Mar 6, 2024
881917b
Update CHANGELOG.md
bhillkeyfactor Mar 6, 2024
225c9af
Fixed Inventory Issue
bhillkeyfactor Mar 6, 2024
076f029
Merge branch 'main' into dev_release_2.1
bhillkeyfactor Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.1.0
* Support for Pan Level Certficates
* Support for Pushing Entire Certificate Chain to Panorama
* Auto Detection of Trusted Root Certificates
* Fix Inventory Check For Private Key from Dummy to Anything

2.0.1
* Fix Epoch Time in Model from int to long to prevent inventory errors

Expand Down
167 changes: 33 additions & 134 deletions PaloAlto/Client/PaloAltoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
Expand Down Expand Up @@ -136,26 +137,15 @@ public async Task<CommitResponse> GetCommitAllResponse(string deviceGroup)
}
}

public async Task<ErrorSuccessResponse> SubmitEditProfile(EditProfileRequest request, string templateName)
public async Task<ErrorSuccessResponse> SubmitEditProfile(EditProfileRequest request, string templateName, string storePath)
{
try
{
var editXml =
$"<entry name=\"{request.Name}\"><protocol-settings><min-version>{request.ProtocolSettings.MinVersion.Text}</min-version><max-version>{request.ProtocolSettings.MaxVersion.Text}</max-version></protocol-settings><certificate>{request.Certificate}</certificate></entry>";
string uri;

//if not Panorama use firewall path
if (templateName == "/")
{
templateName = "";
uri =
$@"/api/?type=config&action=edit&xpath=/config/shared/ssl-tls-service-profile/entry[@name='{request.Name}']&element={editXml}&key={ApiKey}&target-tpl={templateName}";
}
else
{
uri =
$@"/api/?type=config&action=edit&xpath=/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/ssl-tls-service-profile/entry&element={editXml}&key={ApiKey}&target-tpl={templateName}";
}
string uri=
$@"/api/?type=config&action=edit&xpath={storePath}/ssl-tls-service-profile/entry[@name='{request.Name}']&element={editXml}&key={ApiKey}&target-tpl={GetTemplateName(storePath)}";

var response = await GetXmlResponseAsync<ErrorSuccessResponse>(await HttpClient.GetAsync(uri));
return response;
Expand All @@ -165,17 +155,29 @@ public async Task<ErrorSuccessResponse> SubmitEditProfile(EditProfileRequest req
_logger.LogError($"Error Occured in PaloAltoClient.SubmitDeleteCertificate: {e.Message}");
throw;
}
}

public async Task<GetProfileByCertificateResponse> GetProfileByCertificate(string templateName,
string certificate)
}

private string GetTemplateName(string storePath)
{
string pattern = @"\/template\/entry\[@name='([^']+)'\]";
Regex regex = new Regex(pattern);
Match match = regex.Match(storePath);

string templateName = string.Empty;
if (match.Success)
{
templateName = match.Groups[1].Value;
}

return templateName;
}

public async Task<GetProfileByCertificateResponse> GetProfileByCertificate(string storePath, string certificate)
{
try
{
var xPath = templateName == "/"
? $"/config/shared/ssl-tls-service-profile/entry[@name='{certificate}']"
: $"/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/ssl-tls-service-profile/entry[./certificate='{certificate}']";
var uri = $"/api/?type=config&action=get&target-tpl={templateName}&xpath={xPath}&key={ApiKey}";
var xPath = $"{storePath}/ssl-tls-service-profile/entry[./certificate='{certificate}']";
var uri = $"/api/?type=config&action=get&target-tpl={GetTemplateName(storePath)}&xpath={xPath}&key={ApiKey}";
var response =
await GetXmlResponseAsync<GetProfileByCertificateResponse>(await HttpClient.GetAsync(uri));
return response;
Expand Down Expand Up @@ -231,23 +233,11 @@ public async Task<string> GetCertificateByName(string name)
}
}

public async Task<ErrorSuccessResponse> SubmitDeleteCertificate(string name, string templateName)
public async Task<ErrorSuccessResponse> SubmitDeleteCertificate(string name, string storePath)
{
try
{
string uri;
if (templateName == "/")
{
templateName = "";
uri =
$@"/api/?type=config&action=delete&xpath=/config/shared/certificate/entry[@name='{name}']&key={ApiKey}&target-tpl={templateName}";
}
else
{
uri =
$@"/api/?type=config&action=delete&xpath=/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/certificate/entry[@name='{name}']&key={ApiKey}&target-tpl={templateName}";
}

string uri =$@"/api/?type=config&action=delete&xpath={storePath}/certificate/entry[@name='{name}']&key={ApiKey}&target-tpl={GetTemplateName(storePath)}";
return await GetXmlResponseAsync<ErrorSuccessResponse>(await HttpClient.GetAsync(uri));
}
catch (Exception e)
Expand All @@ -257,23 +247,11 @@ public async Task<ErrorSuccessResponse> SubmitDeleteCertificate(string name, str
}
}

public async Task<ErrorSuccessResponse> SubmitDeleteTrustedRoot(string name, string templateName)
public async Task<ErrorSuccessResponse> SubmitDeleteTrustedRoot(string name, string storePath)
{
try
{
string uri;
if (templateName == "/")
{
templateName = "";
uri =
$@"/api/?type=config&action=delete&xpath=/config/shared/ssl-decrypt/trusted-root-CA/member[text()='{name}']&key={ApiKey}&target-tpl={templateName}";
}
else
{
uri =
$@"/api/?type=config&action=delete&xpath=/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/ssl-decrypt/trusted-root-CA/member[text()='{name}']&key={ApiKey}&target-tpl={templateName}";
}

string uri= $@"/api/?type=config&action=delete&xpath={storePath}/ssl-decrypt/trusted-root-CA/member[text()='{name}']&key={ApiKey}&target-tpl={GetTemplateName(storePath)}";
return await GetXmlResponseAsync<ErrorSuccessResponse>(await HttpClient.GetAsync(uri));
}
catch (Exception e)
Expand All @@ -283,23 +261,11 @@ public async Task<ErrorSuccessResponse> SubmitDeleteTrustedRoot(string name, str
}
}

public async Task<ErrorSuccessResponse> SubmitSetTrustedRoot(string name, string templateName)
public async Task<ErrorSuccessResponse> SubmitSetTrustedRoot(string name, string storePath)
{
try
{
string uri;
if (templateName == "/")
{
templateName = "";
uri =
$@"/api/?type=config&action=set&xpath=/config/shared/ssl-decrypt&element=<trusted-root-CA><member>{name}</member></trusted-root-CA>&key={ApiKey}&target-tpl={templateName}";
}
else
{
uri =
$@"/api/?type=config&action=set&xpath=/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/ssl-decrypt&element=<trusted-root-CA><member>{name}</member></trusted-root-CA>&key={ApiKey}&target-tpl={templateName}";
}

{
string uri = $@"/api/?type=config&action=set&xpath={storePath}/ssl-decrypt&element=<trusted-root-CA><member>{name}</member></trusted-root-CA>&key={ApiKey}&target-tpl={GetTemplateName(storePath)}";
return await GetXmlResponseAsync<ErrorSuccessResponse>(await HttpClient.GetAsync(uri));
}
catch (Exception e)
Expand All @@ -309,79 +275,12 @@ public async Task<ErrorSuccessResponse> SubmitSetTrustedRoot(string name, string
}
}

public async Task<GetProfileByCertificateResponse> GetBinding(JobEntryParams jobEntryParams, string templateName)
{
try
{
string uri;
if (templateName == "/")
{
templateName = "";
uri =
$@"/api/?type=config&action=get&xpath=/config/shared/ssl-tls-service-profile/entry[@name='{jobEntryParams.TlsProfileName}']&key={ApiKey}&target-tpl={templateName}";
}
else
{
uri =
$@"/api/?type=config&action=get&xpath=/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/ssl-tls-service-profile/entry[@name='{jobEntryParams.TlsProfileName}']&key={ApiKey}&target-tpl={templateName}";
}
return await GetXmlResponseAsync<GetProfileByCertificateResponse>(await HttpClient.GetAsync(uri));
}
catch (Exception e)
{
_logger.LogError($"Error Occured in PaloAltoClient.GetBinding: {e.Message}");
throw;
}
}

public async Task<ErrorSuccessResponse> SubmitDeleteBinding(JobEntryParams jobEntryParams, string templateName)
{
try
{
string uri;
if (templateName == "/")
{
templateName = "";
uri =
$@"/api/?type=config&action=delete&xpath=/config/shared/ssl-tls-service-profile/entry[@name='{jobEntryParams.TlsProfileName}']&key={ApiKey}&target-tpl={templateName}";
}
else
{
uri =
$@"/api/?type=config&action=delete&xpath=/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='{templateName}']/config/shared/ssl-tls-service-profile/entry[@name='{jobEntryParams.TlsProfileName}']&key={ApiKey}&target-tpl={templateName}";
}

return await GetXmlResponseAsync<ErrorSuccessResponse>(await HttpClient.GetAsync(uri));
}
catch (Exception e)
{
_logger.LogError($"Error Occured in PaloAltoClient.SubmitDeleteBinding: {e.Message}");
throw;
}
}

public async Task<ErrorSuccessResponse> SubmitSetForwardTrust(string name)
{
try
{
var uri =
$@"/api/?type=config&action=set&xpath=/config/shared/ssl-decrypt&element=<forward-trust-certificate><rsa>{name}</rsa></forward-trust-certificate>&key={ApiKey}";
return await GetXmlResponseAsync<ErrorSuccessResponse>(await HttpClient.GetAsync(uri));
}
catch (Exception e)
{
_logger.LogError($"Error Occured in PaloAltoClient.SubmitSetForwardTrust: {e.Message}");
throw;
}
}

public async Task<ErrorSuccessResponse> ImportCertificate(string name, string passPhrase, byte[] bytes,
string includeKey, string category, string templateName)
string includeKey, string category, string storePath)
{
try
{
if (templateName == "/")
templateName = "";
var templateName=GetTemplateName(storePath);
var uri =
$@"/api/?type=import&category={category}&certificate-name={name}&format=pem&include-key={includeKey}&passphrase={passPhrase}&target-tpl={templateName}&target-tpl-vsys=&vsys&key={ApiKey}";
var boundary = $"--------------------------{Guid.NewGuid():N}";
Expand Down
20 changes: 4 additions & 16 deletions PaloAlto/Jobs/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,7 @@ private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInven
_logger.LogTrace("Inventory Palo Alto Client Created");

//Change the path if you are pointed to a Panorama Device
CertificateListResponse rawCertificatesResult;
if (IsPanoramaDevice(config))
rawCertificatesResult =
client.GetCertificateList(
$"/config/devices/entry/template/entry[@name='{config.CertificateStoreDetails.StorePath}']//certificate/entry")
.Result;
else
rawCertificatesResult = client.GetCertificateList("/config/shared/certificate/entry").Result;
var rawCertificatesResult = client.GetCertificateList($"{config.CertificateStoreDetails.StorePath}/certificate/entry").Result;

var certificatesResult =
rawCertificatesResult.CertificateResult.Entry.FindAll(c => c.PublicKey != null);
Expand All @@ -118,10 +111,10 @@ private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInven
try
{
_logger.LogTrace(
$"Building Cert List Inventory Item Alias: {c.Name} Pem: {c.PublicKey} Private Key: dummy (from PA API)");
$"Building Cert List Inventory Item Alias: {c.Name} Pem: {c.PublicKey} Private Key: {c.PrivateKey?.Length > 0}");
var bindings =
client.GetProfileByCertificate(config.CertificateStoreDetails.StorePath, c.Name).Result;
return BuildInventoryItem(c.Name, c.PublicKey, c.PrivateKey == "dummy",bindings,false);
return BuildInventoryItem(c.Name, c.PublicKey, c.PrivateKey?.Length>0,bindings,false);
}
catch
{
Expand Down Expand Up @@ -193,11 +186,6 @@ private JobResult ReturnJobResult(InventoryJobConfiguration config, bool warning
};
}

private static bool IsPanoramaDevice(InventoryJobConfiguration config)
{
return config.CertificateStoreDetails.StorePath.Length > 1;
}

private void LogResponse<T>(T content)
{
var resWriter = new StringWriter();
Expand All @@ -215,7 +203,7 @@ protected virtual CurrentInventoryItem BuildInventoryItem(string alias, string c
//Add Entry Params so the show up in the UI Inventory Store Popup
var siteSettingsDict = new Dictionary<string, object>
{
{ "ProfileName", string.IsNullOrEmpty(bindings.Result?.Entry?.Name)?"":bindings.Result?.Entry?.Name},
{ "TlsProfileName", string.IsNullOrEmpty(bindings.Result?.Entry?.Name)?"":bindings.Result?.Entry?.Name},
{ "TlsMinVersion", string.IsNullOrEmpty(bindings.Result?.Entry?.ProtocolSettings?.MinVersion?.Text)?"":bindings.Result?.Entry?.ProtocolSettings?.MinVersion?.Text},
{ "TlsMaxVersion", string.IsNullOrEmpty(bindings.Result?.Entry?.ProtocolSettings?.MaxVersion?.Text)?"":bindings.Result?.Entry?.ProtocolSettings?.MaxVersion?.Text },
{ "Trusted Root", trustedRoot},
Expand Down
Loading
Loading