Package ghidra.net
Class PKIUtils
java.lang.Object
ghidra.net.PKIUtils
PKIUtils provides supporting utilities for creating and accessing X509 certificate
keystore files.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final String[]static final FileNameExtensionFilterstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final KeyStore.PrivateKeyEntrycreateKeyEntry(String alias, String dn, int durationDays, KeyStore.PrivateKeyEntry caEntry, File keyFile, String keystoreType, Collection<String> subjectAlternativeNames, char[] protectedPassphrase) Generate a newX509Certificatewith RSAKeyPairand create/update aKeyStoreoptionally backed by a keyFile.static final KeyStorecreateKeyStore(String alias, String dn, int durationDays, KeyStore.PrivateKeyEntry caEntry, File keyFile, String keystoreType, Collection<String> subjectAlternativeNames, char[] protectedPassphrase) Generate a newX509Certificatewith RSAKeyPairand create/update aKeyStoreoptionally backed by a keyFile.static StringdetectKeyStoreType(String keystorePath) Attempt to detect PKI KeyStore type ("JKS" or "PKCS12") for the specified file.static voidexportX509Certificates(Certificate[] certificates, File outFile) Export X.509 certificates to the specified outFile.static KeyStoregetKeyStoreInstance(String keystorePath, char[] password) Attempt to load a client/server keystore in a PKCS12 form (*.p12, *.pks, *.pfx) or Java JKS (*.jks) form.static X509TrustManagergetTrustManager(File caCertsFile) Establish X509TrustManager for the specified CA certificate storage.static KeyStoreloadCertificateStore(String certsPath) Load the all certificates from the specified certificate store in a standard X.509 form (e.g., concatenation of Base64 encoded certificates: *.pem, *.crt, *.cer, *.der) or Java JKS (*.jks) form.static voidlogCerts(X509Certificate[] x509Certs) Log all X509 certificates contained within array
-
Field Details
-
RSA_TYPE
- See Also:
-
BEGIN_CERT
- See Also:
-
END_CERT
- See Also:
-
PKCS_FILE_EXTENSIONS
-
PKCS_FILENAME_FILTER
-
-
Constructor Details
-
PKIUtils
public PKIUtils()
-
-
Method Details
-
getTrustManager
public static X509TrustManager getTrustManager(File caCertsFile) throws CancelledException, GeneralSecurityException, IOException Establish X509TrustManager for the specified CA certificate storage.- Parameters:
caCertsFile- CA certificates storage file- Returns:
- X509TrustManager
- Throws:
CancelledException- if password entry was cancelledGeneralSecurityException- if error occured during truststore initializationIOException- if file read error occurs
-
exportX509Certificates
public static void exportX509Certificates(Certificate[] certificates, File outFile) throws IOException, CertificateEncodingException Export X.509 certificates to the specified outFile.- Parameters:
certificates- certificates to be storedoutFile- output file- Throws:
IOException- if error occurs writing to outFileCertificateEncodingException- if error occurs while encoding certificate data
-
createKeyStore
public static final KeyStore createKeyStore(String alias, String dn, int durationDays, KeyStore.PrivateKeyEntry caEntry, File keyFile, String keystoreType, Collection<String> subjectAlternativeNames, char[] protectedPassphrase) throws KeyStoreException Generate a newX509Certificatewith RSAKeyPairand create/update aKeyStoreoptionally backed by a keyFile.- Parameters:
alias- entry alias with keystoredn- distinguished name (e.g., "CN=Ghidra Test, O=Ghidra, OU=Test, C=US" )durationDays- number of days which generated certificate should remain validcaEntry- optional CA private key entry. If null, a self-signed CA certificate will be generated.keyFile- optional file to load/store resultingKeyStore(may be null)keystoreType- support keystore type (e.g., "JKS", "PKCS12")subjectAlternativeNames- an optional list of subject alternative names to be included in certificate (may be null)protectedPassphrase- key and keystore protection password- Returns:
- keystore containing newly generated certification with key pair
- Throws:
KeyStoreException- if error occurs while updating keystore
-
createKeyEntry
public static final KeyStore.PrivateKeyEntry createKeyEntry(String alias, String dn, int durationDays, KeyStore.PrivateKeyEntry caEntry, File keyFile, String keystoreType, Collection<String> subjectAlternativeNames, char[] protectedPassphrase) throws KeyStoreException Generate a newX509Certificatewith RSAKeyPairand create/update aKeyStoreoptionally backed by a keyFile.- Parameters:
alias- entry alias with keystoredn- distinguished name (e.g., "CN=Ghidra Test, O=Ghidra, OU=Test, C=US" )durationDays- number of days which generated certificate should remain validcaEntry- optional CA private key entry. If null, a self-signed CA certificate will be generated.keyFile- optional file to load/store resultingKeyStore(may be null)keystoreType- support keystore type (e.g., "JKS", "PKCS12")subjectAlternativeNames- an optional list of subject alternative names to be included in certificate (may be null)protectedPassphrase- key and keystore protection password- Returns:
- newly generated keystore entry with key pair
- Throws:
KeyStoreException- if error occurs while updating keystore
-
loadCertificateStore
public static KeyStore loadCertificateStore(String certsPath) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException Load the all certificates from the specified certificate store in a standard X.509 form (e.g., concatenation of Base64 encoded certificates: *.pem, *.crt, *.cer, *.der) or Java JKS (*.jks) form.- Parameters:
certsPath- certificate(s) storage file path- Returns:
- KeyStore containing certificates
- Throws:
IOException- if failure occurred reading and processing keystore file.NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be foundCertificateException- if any of the certificates in the keystore could not be loadedKeyStoreException- if a general error occurred opening/processing keystore
-
getKeyStoreInstance
public static KeyStore getKeyStoreInstance(String keystorePath, char[] password) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException Attempt to load a client/server keystore in a PKCS12 form (*.p12, *.pks, *.pfx) or Java JKS (*.jks) form.- Parameters:
keystorePath- JKS or PKCS12 keystore file pathpassword- keystore password- Returns:
- keystore instance
- Throws:
IOException- if failure occurred reading and processing keystore file or if the given password was incorrect. If the error is due to a wrong password, thecauseof theIOExceptionshould be anUnrecoverableKeyExceptionNoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be foundCertificateException- if any of the certificates in the keystore could not be loadedKeyStoreException- if a general error occurred opening/processing keystore
-
detectKeyStoreType
Attempt to detect PKI KeyStore type ("JKS" or "PKCS12") for the specified file.- Parameters:
keystorePath- key store file path- Returns:
- "JKS", "PKCS12" or null
- Throws:
IOException- if file read error occurs
-
logCerts
Log all X509 certificates contained within array- Parameters:
x509Certs- array of certificates
-