Certificate Creation for SSH Connections Using SIA
Environment
Secure Infrastructure Access (formerly DPA) DPA for SSH
Procedure
Create a certificate
First we create the certificate. On your Mac or Linux container run the following:
openssl genrsa -out rootCA.key 4096openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt -subj "/C=US/ST=MA/L=Boston/O=Cyberark/OU=aus/CN=<DOMAIN NAME>"openssl genrsa -out dpa.key -des3 2048openssl req -new -key dpa.key -out dpa.csr -subj "/C=US/ST=MA/L=Boston/O=Cyberark/OU=DPA/CN=<DOMAIN/TARGET NAME>"openssl x509 -req -days 365 -in dpa.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out dpa.pemopenssl pkcs12 -export -out dpa.pfx -inkey dpa.key -in dpa.pem |
For <DOMAIN NAME> a valid domain is the FQDN (ex. ad.my-domain.com.)
For <DOMAIN/TARGET NAME> you can either use a wildcard (e.g. *.ad.my-domain.com) for domain wide certificate, or specify a target (e.g. win-target-0.ad.my-domain.com) for a specific target certificate.
Note: Some commands will require you to type a password, it is best to keep the password handy as it will be used in the next step.
Several files will now be generated.
The rootCA.crt file should be added to the TLS Certificates of the tenant.
The dpa.pfx should be copied to the target machine.
Install the certificate on the target machine
On the target machine, open the management console by typing 'mmc' in the run command prompt.
- In the MMC window, go to File > Add/Remove Snap-in...
- In the "Add or Remove Snap-ins" window, select "Certificates" and click the "Add >" button.
- Choose "Computer account" and click "Next."
- Select "Local computer" and click "Finish."
- Click "OK" to close the "Add or Remove Snap-ins" window.
In the MMC, expand "Certificates" on the left-hand side to reveal the certificate stores.
To import the Certificate perform the following:
- Right-click on "Personal" and choose All Tasks > Import....
- The Certificate Import Wizard will open. Click "Next."
- Browse to the location of the PFX file and select it. Click "Next." (this is the dpa.pfx file we created in the previous step)
- Enter the password for the PFX file, if it's password-protected. Click "Next."
- Choose "Place all certificates in the following store" and click "Browse..."
- Select "Personal" and click "OK."
- Click "Next" and then "Finish" to complete the import.
Open an administrator level PowerShell
Type the following command:
Get-ChildItem "Cert:\LocalMachine\My"
A list of certificates thumbprints will be shown, copy the thumbprint of your certificate.
Then run the following commands:
$PATH = (Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices)Set-WmiInstance -Path $PATH -argument @{SSLCertificateSHA1Hash="<my certificate thumbprint>"} |
Note: the thumbprint should be enclosed with quotes - e.g. @{SSLCertificateSHA1Hash="abcdef123456789"}
If certificate validation is enabled it will try to match the certificates added via the TLS Certificates page with the certificates installed on the target machine.
Create a certificate chain (RootCA → IntermediateCA → End entity)
On your machine, create a dedicated directory for the certificates' creation.
Populate the directory with the following:
mkdir -p myCA/rootCA/{certs,crl,newcerts,private,csr} && mkdir -p myCA/intermediateCA/{certs,crl,newcerts,private,csr}echo 1000 > myCA/rootCA/serial && echo 1000 > myCA/intermediateCA/serialecho 0100 > myCA/rootCA/crlnumber && echo 0100 > myCA/intermediateCA/crlnumbertouch myCA/rootCA/index.txt && touch myCA/intermediateCA/index.txttouch openssl_root.cnf && touch openssl_intermediate.cnf
The initial structure should be:
Set the content of openssl_root.cnf:
Set the content of openssl_intermediate.cnf
Once everything is configured, run the following commands to create the certificates:
# Generate an RSA key pair for the root CA
openssl genrsa -out myCA/rootCA/private/ca.key.pem 4096
openssl rsa -noout -text -in myCA/rootCA/private/ca.key.pem
# Replace the content of -subj flag
openssl req -config openssl_root.cnf -key myCA/rootCA/private/ca.key.pem -new -x509 -days 7300 -sha256 -extensions v3_ca -out myCA/rootCA/certs/ca.cert.pem -subj "/C=US/ST=California/L=San Francisco/O=Example Corp/OU=IT Department/CN=ad.test-cert.com"
# verify the root CA certificate
openssl x509 -noout -text -in myCA/rootCA/certs/ca.cert.pem
# Generate the intermediate CA certificate
openssl genrsa -out myCA/intermediateCA/private/intermediate.key.pem 4096
# Create the intermediate CA CSR
# Replace the content of -subj flag
openssl req -config openssl_intermediate.cnf -key myCA/intermediateCA/private/intermediate.key.pem -new -sha256 -out myCA/intermediateCA/certs/intermediate.csr.pem -subj "/C=US/ST=California/L=San Francisco/O=Example Corp/OU=IT Department/CN=ad.test-cert.com"
# Sign the intermediate CSR with root CA key
openssl ca -config openssl_root.cnf -extensions v3_intermediate_ca -days 3650 -notext -md sha256 -in myCA/intermediateCA/certs/intermediate.csr.pem -out myCA/intermediateCA/certs/intermediate.cert.pem
# Verify the intermediate CA certificate
openssl x509 -noout -text -in myCA/intermediateCA/certs/intermediate.cert.pem
openssl verify -CAfile myCA/rootCA/certs/ca.cert.pem myCA/intermediateCA/certs/intermediate.cert.pem
# Generate certificate chain (certificate bundle)
# Concatenate the intermediate and root certicates into a single file
cat myCA/intermediateCA/certs/intermediate.cert.pem myCA/rootCA/certs/ca.cert.pem > myCA/intermediateCA/certs/ca-chain.cert.pem
# Verify the chain
openssl verify -CAfile myCA/intermediateCA/certs/ca-chain.cert.pem myCA/intermediateCA/certs/intermediate.cert.pem
# Generate the sign server certificate with the intermediate CA
openssl genpkey -algorithm RSA -out myCA/intermediateCA/private/win-target-0.key.pem
# Create the server CA CSR
# Replace the content of -subj flag
openssl req -config openssl_intermediate.cnf -key myCA/intermediateCA/private/win-target-0.key.pem -new -sha256 -out myCA/intermediateCA/csr/win-target-0.csr.pem -subj "/C=US/ST=California/L=San Francisco/O=Example Corp/OU=IT Department/CN=win-target-0.ad.test-cert.com"
# Sign the server CSR with the intermediate CA
openssl ca -config openssl_intermediate.cnf -extensions server_cert -days 375 -notext -md sha256 -in myCA/intermediateCA/csr/win-target-0.csr.pem -out myCA/intermediateCA/certs/win-target-0.cert.pem
# Verify the server certificate
openssl x509 -noout -text -in myCA/intermediateCA/certs/win-target-0.cert.pem
# Create PKCS#12 (PFX) file for the server Certificate
openssl pkcs12 -export -out win-target-0.pfx -inkey myCA/intermediateCA/private/win-target-0.key.pem -in myCA/intermediateCA/certs/win-target-0.cert.pem
Install the certificates chain on the target machine
On the target machine, type 'mmc' in the run command prompt to launch the management console
In the MMC, expand "Certificates" on the left-hand side to reveal the certificate stores.
To import the Intermediate Certificate do:
Copy the file .../myCA/intermediateCA/certs/intermediate.cert.pem to the target machine.
- Right-click on "Intermediate Certification Authorities" and choose All Tasks > Import....
- The Certificate Import Wizard will open. Click "Next."
- Browse to the location of the certificate file and select it. Click "Next." (this is the intermediate.cert.pem file we created in the previous step)
- Choose "Place all certificates in the following store" and click "Browse..."
- Select "Intermediate Certification Authorities" and click "OK."
- Click "Next" and then "Finish" to complete the import.
To import the Root Certificate do:
Copy the file .../myCA/rootCA/certs/ca.cert.pem to the target machine.
- Right-click on "Trusted Root Certification Authorities" and choose All Tasks > Import....
- The Certificate Import Wizard will open. Click "Next."
- Browse to the location of the certificate file and select it. Click "Next." (this is the ca.cert.pem file we created in the previous step)
- Choose "Place all certificates in the following store" and click "Browse..."
- Select "Intermediate Certification Authorities" and click "OK."
- Click "Next" and then "Finish" to complete the import.
To import the end entity Certificate do:
Copy the file .../win-target-0.pfx to the target machine.
- Right-click on "Personal" and choose All Tasks > Import....
- The Certificate Import Wizard will open. Click "Next."
- Browse to the location of the PFX file and select it. Click "Next." (this is the win-target-0.pfx file we created in the previous step)
- Enter the password for the PFX file, if it's password-protected. Click "Next."
- Choose "Place all certificates in the following store" and click "Browse..."
- Select "Personal" and click "OK."
- Click "Next" and then "Finish" to complete the import.
Perform the Powershell commands as detailed before for the pfx file.