Package com.browserup.bup.mitm
Class TrustSource
- java.lang.Object
-
- com.browserup.bup.mitm.TrustSource
-
public class TrustSource extends java.lang.ObjectA source of trusted root certificate authorities. Provides static methods to obtain default trust sources:defaultTrustSource()- both the built-in and JVM-trusted CAsjavaTrustSource()- only default CAs trusted by the JVMbuiltinTrustSource()- only built-in trusted CAs (ultimately derived from Firefox's trust list)
empty(), then calling the various add() methods to add PEM-encoded files and Strings, KeyStores, and X509Certificates to the TrustSource. For example:TrustSource customTrustSource = TrustSource.empty() .add(myX509Certificate) .add(pemFileContainingMyCA) .add(javaKeyStore);Note: This class is immutable, so calls to add() will return a new instance, rather than modifying the existing instance.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTrustSource()Creates a TrustSource that contains no trusted certificates.protectedTrustSource(java.security.cert.X509Certificate... trustedCAs)Creates a TrustSource that considers only the specified certificates as "trusted".
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TrustSourceadd(TrustSource trustSource)Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus the trusted CAs in the specified TrustSource.TrustSourceadd(java.io.File trustedCAPemFile)Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more CAs contained in the PEM-encoded File.TrustSourceadd(java.lang.String trustedPemEncodedCAs)Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more CAs contained in the PEM-encoded String.TrustSourceadd(java.security.cert.X509Certificate... trustedCertificates)Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more additional trusted X509Certificates.TrustSourceadd(java.security.KeyStore trustStore)Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus all trusted certificate entries from the specified trustStore.static TrustSourcebuiltinTrustSource()Returns a TrustSource containing only the builtin trusted CAs and does not include the JVM's trusted CAs.static TrustSourcedefaultTrustSource()Returns a TrustSource containing the default trusted CAs.static TrustSourceempty()Returns a TrustSource that contains no trusted CAs.java.security.cert.X509Certificate[]getTrustedCAs()Returns the X509 certificates considered "trusted" by this TrustSource.static TrustSourcejavaTrustSource()Returns a TrustSource containing the default CAs trusted by this JVM.
-
-
-
Constructor Detail
-
TrustSource
protected TrustSource()
Creates a TrustSource that contains no trusted certificates. For public use, seeempty().
-
TrustSource
protected TrustSource(java.security.cert.X509Certificate... trustedCAs)
Creates a TrustSource that considers only the specified certificates as "trusted". For public use, useempty()followed byadd(X509Certificate...).- Parameters:
trustedCAs- root CAs to trust
-
-
Method Detail
-
getTrustedCAs
public java.security.cert.X509Certificate[] getTrustedCAs()
Returns the X509 certificates considered "trusted" by this TrustSource. This method will not return null, but may return an empty array.- Returns:
- X509Certificate[]
-
empty
public static TrustSource empty()
Returns a TrustSource that contains no trusted CAs. Can be used in conjunction with the add() methods to build a TrustSource containing custom CAs from a variety of sources (PEM files, KeyStores, etc.).- Returns:
- TrustSource
-
defaultTrustSource
public static TrustSource defaultTrustSource()
Returns a TrustSource containing the default trusted CAs. By default, contains both the JVM's trusted CAs and the built-in trusted CAs (Firefox's trusted CAs).- Returns:
- TrustSource
-
builtinTrustSource
public static TrustSource builtinTrustSource()
Returns a TrustSource containing only the builtin trusted CAs and does not include the JVM's trusted CAs. SeeTrustUtil.getBuiltinTrustedCAs().- Returns:
- TrustSource
-
javaTrustSource
public static TrustSource javaTrustSource()
Returns a TrustSource containing the default CAs trusted by this JVM. SeeTrustUtil.getJavaTrustedCAs().- Returns:
- TrustSource
-
add
public TrustSource add(java.lang.String trustedPemEncodedCAs)
Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more CAs contained in the PEM-encoded String. The String may contain multiple certificates and may contain comments or other non-PEM-encoded text, as long as the PEM-encoded certificates are delimited by appropriate BEGIN_CERTIFICATE and END_CERTIFICATE text blocks.- Parameters:
trustedPemEncodedCAs- String containing PEM-encoded certificates to trust- Returns:
- a new TrustSource containing this TrustSource's trusted CAs plus the CAs in the specified String
-
add
public TrustSource add(java.security.cert.X509Certificate... trustedCertificates)
Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more additional trusted X509Certificates. If trustedCertificates is null or empty, returns this same TrustSource.- Parameters:
trustedCertificates- X509Certificates of CAs to trust- Returns:
- a new TrustSource containing this TrustSource's trusted CAs plus the specified CAs
-
add
public TrustSource add(java.security.KeyStore trustStore)
Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus all trusted certificate entries from the specified trustStore. This method will only add trusted certificate entries from the specified KeyStore (i.e. entries of typeKeyStore.TrustedCertificateEntry; private keys will be ignored. The trustStore may be in JKS or PKCS12 format.- Parameters:
trustStore- keystore containing trusted certificate entries- Returns:
- a new TrustSource containing this TrustSource's trusted CAs plus trusted certificate entries from the keystore
-
add
public TrustSource add(java.io.File trustedCAPemFile)
Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more CAs contained in the PEM-encoded File. The File may contain multiple certificates and may contain comments or other non-PEM-encoded text, as long as the PEM-encoded certificates are delimited by appropriate BEGIN_CERTIFICATE and END_CERTIFICATE text blocks. The file may contain UTF-8 characters, but the PEM-encoded certificate data itself must be US-ASCII.- Parameters:
trustedCAPemFile- File containing PEM-encoded certificates- Returns:
- a new TrustSource containing this TrustSource's trusted CAs plus the CAs in the specified String
-
add
public TrustSource add(TrustSource trustSource)
Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus the trusted CAs in the specified TrustSource.- Parameters:
trustSource- TrustSource to combine with this TrustSource- Returns:
- a new TrustSource containing both TrustSources' trusted CAs
-
-