(Question) CCP with Client Cert Auth vis PoSh or Python

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(Question) CCP with Client Cert Auth vis PoSh or Python

L2 Linker

We have configured CCP client certificate auth and have the Windows browser and a MacOS browser pulling the credentials but are having trouble getting a PowerShell (Invoke-Rest-Method) or Python (Import Requests) script working. Does anyone have the syntax or a script that can pass either the cert or the thumbprint/SN via Python or Powershell? 

 

The curl command working looks like this:

 

-Convert the .pfx to .cer

openssl pkcs12 -in /path/to/CERT_export.pfx -out /path/to/CERT_export.cer -nodes

Enter Import Password:

MAC verified OK

 

-Call the CCP

curl --request GET --url 'https://cyberark.com/AIMWebService/api/Accounts?AppID=<APPID>&Safe=<SAFE>&Folder=Root&Object=<OBJECT-NAME>' --header 'Content-Type: application/json' --cert '/PATH/TO/CERT_export.cer'

1 accepted solution

Accepted Solutions

L2 Linker

The code snippet option is enabled now. That is great! Thanks.

 

Just to close the loop on this thread, I will include the sample scripts I pasted earlier that work for CCP with Client Cert Auth:

 

  • PowerShell: Assuming the certificate has been imported to your machines cert store, this script will authenticate to the CCP using the cert thumbprint.
# Declare Variables $BASEURL="____" $APPID="____" $SAFE="____" $FOLDER="____" $OBJECT="____" $THUMBPRINT="XXXXXXXXXXXXXXXXXXXXXXXXX"   # Call the CCP Invoke-RestMethod -Uri "$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $THUMBPRINT

 

  • PowerShell: This script will ingest the pfx cert at runtime, prompt the user for the cert file password, and input the Thumbprint into the REST call .
# Declare Variables $BASEURL="____" $APPID="____" $SAFE="____" $FOLDER="____" $OBJECT="____" $CERTPATH="____"   # Retrieve Certificate $CERT=Get-PfxCertificate -FilePath $CERTPATH   # Call the CCP Invoke-RestMethod -Uri "https://$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $CERT.ThumbPrint

 

 

View solution in original post

9 REPLIES 9

L2 Linker

I hope this is what you're looking for:

 

Invoke-RestMethod -Uri "https://cyberark.com/AIMWebservice/api/Accounts?AppID=<AppID>&Safe=<Safe>&object=<Object-Name>" -Method Get -CertificateThumbprint <Cert Thumbprint w/ no spaces>

L2 Linker

Thanks for the reply. There must've been an issue with how the cert was imported because that syntax wasn't working but I have two versions that work now.

 

  1. This will ingest the cert and ask for the pfx password at runtime.

 

# Declare Variables

$BASEURL="____"

$APPID="____"

$SAFE="____"

$FOLDER="____"

$OBJECT="____"

$CERTPATH="____"

 

# Retrieve Certificate

$CERT=Get-PfxCertificate -FilePath $CERTPATH

 

# Call the CCP

Invoke-RestMethod -Uri "https://$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $CERT.ThumbPrint

 

2. This assumes that the cert is imported in the local machine personal store.

 

# Declare Variables

$BASEURL="____"

$APPID="____"

$SAFE="____"

$FOLDER="____"

$OBJECT="____"

$THUMBPRINT="XXXXXXXXXXXXXXXXXXXXXXXXX"

 

# Call the CCP

Invoke-RestMethod -Uri "$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $THUMBPRINT

 

L3 Networker

Hi @James Stutes​  and @Peter Greenwood​  you can use now Code Snippet </> for getting better presentation of code:

# Declare Variables $BASEURL="____" $APPID="____" $SAFE="____" $FOLDER="____" $OBJECT="____" $THUMBPRINT="XXXXXXXXXXXXXXXXXXXXXXXXX"   # Call the CCP Invoke-RestMethod -Uri "$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $THUMBPRINT

 

L2 Linker

@Yaron Zorea​  How do you insert a code snippet? It doesn't look like I have that format option.

Field_Content_versions_oct20__06850000004OhJRAA0.png

L1 Bithead

Hi @Peter Greenwood​ I have a different user license and permissions. I have checked it now with a the same user type that you are using and this option is not available.

I will investigate it next week and will update.

Thanks,

Yaron

 

L0 Member

Field_Content_versions_oct20__06850000005Pgl9AAC.pngHi @Peter Greenwood​ ,

We have enabled code snippet for community users. Please let us know if it is working for you.

Yaron

L0 Member
--- Sample Code # Declare Variables $BASEURL="____" $APPID="____" $SAFE="____" $FOLDER="____" $OBJECT="____" $THUMBPRINT="XXXXXXXXXXXXXXXXXXXXXXXXX" # Call the CCP Invoke-RestMethod -Uri "$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $THUMBPRINT

 

L2 Linker

The code snippet option is enabled now. That is great! Thanks.

 

Just to close the loop on this thread, I will include the sample scripts I pasted earlier that work for CCP with Client Cert Auth:

 

  • PowerShell: Assuming the certificate has been imported to your machines cert store, this script will authenticate to the CCP using the cert thumbprint.
# Declare Variables $BASEURL="____" $APPID="____" $SAFE="____" $FOLDER="____" $OBJECT="____" $THUMBPRINT="XXXXXXXXXXXXXXXXXXXXXXXXX"   # Call the CCP Invoke-RestMethod -Uri "$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $THUMBPRINT

 

  • PowerShell: This script will ingest the pfx cert at runtime, prompt the user for the cert file password, and input the Thumbprint into the REST call .
# Declare Variables $BASEURL="____" $APPID="____" $SAFE="____" $FOLDER="____" $OBJECT="____" $CERTPATH="____"   # Retrieve Certificate $CERT=Get-PfxCertificate -FilePath $CERTPATH   # Call the CCP Invoke-RestMethod -Uri "https://$BASEURL/AIMWebService/api/Accounts?AppID=$APPID&Safe=$SAFE&Folder=$FOLDER&Object=$OBJECT" -Method Get -CertificateThumbprint $CERT.ThumbPrint

 

 

L4 Transporter

Hi all,

 

This is my first time dealing with CCP Cert Authentication. When you say "This is assuming that certificate has been imported to your machines cert store." Do you mean the machine from where the call is being made or the CCP server?

 

Thank you in advance,

Douglas Galan

  • 1 accepted solution
  • 1226 Views
  • 9 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!