Verified Owner
Top Fields Constructors Methods
org.jabref.logic.net.ssl

public Class TrustStoreManager

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.nio.file.Files, .Path, java.security.KeyManagementException, .KeyStore, .KeyStoreException, .NoSuchAlgorithmException, java.security.cert.CertificateException, .CertificateFactory, .X509Certificate, java.util.Collections, .List, .Optional, java.util.stream.Collectors, javax.net.ssl.HttpsURLConnection, .SSLContext, .TrustManager, .TrustManagerFactory, .X509TrustManager, org.jspecify.annotations.NonNull, org.slf4j.Logger, .LoggerFactory

Implementation Note

SSL certificates are installed at TrustStoreManager#configureTrustStore(Path)

Field Summary

Modifier and TypeField and Description
private static final Logger
private KeyStore
private static final String
private final Path

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public List<String>
public boolean
public int
public void
clearCustomCertificates()

Deletes all custom certificates, Custom certificates are certificates with alias that ends with [custom]

private static void
private static X509TrustManager
createMergedTrustManager(X509TrustManager jreTrustManager, X509TrustManager customTrustManager)

public static void
createTruststoreFileIfNotExist(Path
path of the truststore
storePath
)

This method checks to see if the truststore is present in storePath, and if it isn't, it copies the default JDK truststore to the specified location.

public void
private static X509TrustManager
public void
public X509Certificate
public List<SSLCertificate>
private static X509TrustManager
private static X509TrustManager
private Boolean
isCustomCertificate(String alias)

Custom certificates are certificates with alias that ends with [custom]

private static void
mergeMissingBundledCertificates(Path storePath)

Adds any certificate present in the bundled /ssl/truststore.jks resource but missing from the truststore at storePath (e.g. a root added in a newer JabRef release), so upgrading an existing installation still picks up new roots.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER
storeback to summary
private KeyStore store
STORE_PASSWORDback to summary
private static final String STORE_PASSWORD
storePathback to summary
private final Path storePath

Constructor Detail

TrustStoreManagerback to summary
public TrustStoreManager(Path storePath)

Method Detail

addCertificateback to summary
public void addCertificate(@NonNull String alias, @NonNull Path certPath)
aliasesback to summary
public List<String> aliases()
certificateExistsback to summary
public boolean certificateExists(@NonNull String alias)
certsCountback to summary
public int certsCount()
clearCustomCertificatesback to summary
public void clearCustomCertificates()

Deletes all custom certificates, Custom certificates are certificates with alias that ends with [custom]

configureTrustStoreback to summary
private static void configureTrustStore(Path myStorePath) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, CertificateException, IOException

Implementation Note

based on https://stackoverflow.com/a/62586564/3450689

createMergedTrustManagerback to summary
private static X509TrustManager createMergedTrustManager(X509TrustManager jreTrustManager, X509TrustManager customTrustManager)
createTruststoreFileIfNotExistback to summary
public static void createTruststoreFileIfNotExist(Path storePath)

This method checks to see if the truststore is present in storePath, and if it isn't, it copies the default JDK truststore to the specified location. If it already exists (e.g. carried over from a previous JabRef installation), any certificates newly bundled with this version but missing from the existing file are merged in, so upgrading users pick up new roots like HARICA TLS ECC Root CA 2021.

Parameters
storePath:Path

path of the truststore

deleteCertificateback to summary
public void deleteCertificate(@NonNull String alias)
findDefaultTrustManagerback to summary
private static X509TrustManager findDefaultTrustManager(KeyStore keyStore) throws NoSuchAlgorithmException, KeyStoreException
flushback to summary
public void flush()
getCertificateback to summary
public X509Certificate getCertificate(String alias)
getCustomCertificatesback to summary
public List<SSLCertificate> getCustomCertificates()
getJabRefTrustManagerback to summary
private static X509TrustManager getJabRefTrustManager(Path myStorePath) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException
getJreTrustManagerback to summary
private static X509TrustManager getJreTrustManager() throws NoSuchAlgorithmException, KeyStoreException
isCustomCertificateback to summary
private Boolean isCustomCertificate(String alias)

Custom certificates are certificates with alias that ends with [custom]

mergeMissingBundledCertificatesback to summary
private static void mergeMissingBundledCertificates(Path storePath)

Adds any certificate present in the bundled /ssl/truststore.jks resource but missing from the truststore at storePath (e.g. a root added in a newer JabRef release), so upgrading an existing installation still picks up new roots.

setSystemTrustManagerback to summary
private static void setSystemTrustManager(X509TrustManager mergedTrustManager) throws NoSuchAlgorithmException, KeyManagementException