TODO: not ported yet
- SSLLabs
- Convert Certs and Private Key to PEM format
- Find the Right Intermediate Chain Certificate
- Combine Certificates into Complete Chain of Trust
- Verify the Chain
- Check Base64 Encoding
- Correct Base64 Padding
- JKS - Java Key Store
- Troubleshooting
Detailed report on your website's SSL certificate:
https://www.ssllabs.com/ssltest/
Using OpenSSL...
Convert the public cert:
openssl x509 -in "$name.crt" -out "$name.pem" -outform PEMConvert the private key:
openssl rsa -in "$name-private.key" -out "$name-privatekey.pem" -outform PEMFor any intermediate chain certs:
openssl x509 -in chain.crt -out chain.pem -outform PEMopenssl x509 -in "$name-cert.pem" -noout -issuerOutput:
issuer= /C=US/O=DigiCert Inc/CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1
openssl x509 -in "$chain.pem" -noout -subjecteg.
openssl x509 -in "DigiCert Global G2 TLS RSA SHA256 2020 CA1.pem" -noout -subjectOutput:
subject= /C=US/O=DigiCert Inc/CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1
openssl x509 -in "DigiCert Global Root G2.pem" -noout -subjectOutput:
subject= /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root G2The right chain certificate is the one that matches the output from your domain cert, in this case:
DigiCert Global G2 TLS RSA SHA256 2020 CA1.pem
If the issuer and subject are the same for a chain certificate, it is the root certificate
This makes sense when you look at the file naming as the other certificate is the Root CA certificate, not an intermediate chain certificate.
Since each chain certificate may lead to a different root certificate, you can confirm the complete chain of trust.
openssl x509 -in "DigiCert Global G2 TLS RSA SHA256 2020 CA1.pem" -noout -issuer -subjectopenssl x509 -in "DigiCert Global Root G2.pem" -noout -issuer -subjectIf the chain cert issuer matches the root CA cert subject, then the chain of trust is complete.
Add the intermediate chain certificate for maximum client compatibility (had issues with this in public Ad Tech due to some clients not being able to resolve the intermediate chain certificate themselves).
cat "$name-cert.pem" "DigiCert Global G2 TLS RSA SHA256 2020 CA1.pem" > fullchain.pemOr including the root certificate - you'd think it'd not be needed as most browsers should already have the root CA cert in their list of trusted certs but see the next section verify the chain...
cat "$name-cert.pem" "DigiCert Global G2 TLS RSA SHA256 2020 CA1.pem" "DigiCert Global Root G2.pem" > fullchain-with-root.pemopenssl verify -CAfile fullchain.pem "$name-cert.pem"Output:
$name-cert.pem: C = US, O = DigiCert Inc, CN = DigiCert Global G2 TLS RSA SHA256 2020 CA1
error 2 at 1 depth lookup:unable to get issuer certificate
openssl verify -CAfile fullchain-with-root.pem "$name-cert.pem"Output:
$name-cert.pem: OK
openssl x509 -in "$name-cert.pem" -text -nooutOutput:
Certificate:
...
openssl rsa -in "$name-privatekey.pem" -checkOutput:
RSA key ok
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
...
openssl x509 -in "$chain.pem" -text -nooutOutput:
Certificate:
...
If you're getting errors like this:
Invalid base64: "-----BEGIN PRIVATE KEY-----
Re-pad the files:
grep -v -- "-----" "$name-cert.pem" | base64 --decode | base64 > "$name-cert-fixed.pem"grep -v -- "-----" "$name-privatekey.pem" | base64 --decode | base64 > "$name-privatekey-fixed.pem"grep -v -- "-----" "$chain.pem" | base64 --decode | base64 > "$chain-fixed.pem"List keystore entries:
keytool -list -keystore "$JKS_NAME".jks -storepass "$JKS_PASSWORD"List keystore entries with detailed info:
keytool -list -v -keystore "$JKS_NAME".jks -storepass "$JKS_PASSWORD"List a specific alias:
keytool -list -v -keystore "$JKS_NAME".jks -alias "$JKS_KEY_ALIAS" -storepass "$JKS_PASSWORD"Check the certificate chain in RFC (PEM) format:
keytool -list -rfc -keystore "$JKS_NAME".jks -storepass "$JKS_PASSWORD"Export the cert:
keytool -export -alias "$JKS_KEY_ALIAS" -keystore "$JKS_NAME".jks -storepass "$JKS_PASSWORD" -file "$JKS_NAME"_cert.cerView the extracted certificate:
openssl x509 -in "$JKS_NAME"_cert.cer -text -nooutkeytool -importkeystore -srckeystore "$JKS_NAME".jks -destkeystore "$JKS_NAME".p12 -deststoretype PKCS12 -srcstorrcalias "$JKS_KEY_ALIAS" -srckeypass "$JKS_KEY_PASSWORD"Different store and key passwords are not supported for p12 stores
so -destkeypass is not needed and would be ignored with this warning:
Warning: Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified -destkeypass value.
Inspect the p12:
openssl pkcs12 -info -in "$JKS_NAME".p12 -passin env:JKS_PASSWORD -passout env:JKS_PASSWORDError outputting keys and certificates
C01EECDE01000000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto/evp/evp_fetch.c:355:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
Add this switch to support legacy algorithms:
-legacy
eg.
openssl pkcs12 -in "$file.p12" -info -noout -password pass:"$CERTIFICATE_PASSWORD" -legacyMAC: sha1, Iteration 1
MAC length: 20, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
Certificate bag
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048