Class ClientTrust
java.lang.Object
com.perforce.p4java.impl.mapbased.rpc.func.client.ClientTrust
Handle the client trust and fingerprint for Perforce SSL connections.
This also include methods to assist in validating a certificate path. We trust all certificates but save the certificates for later checking with methods in this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final char[]static final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringconvert2Hex(byte[] data) Convert a byte array to a hexadecimal stringbooleanfingerprintExists(String serverKey, String fingerprintUser) Check if the fingerprint exists for the specified server IP and portbooleanfingerprintMatches(String serverKey, String fingerprintUser, String fingerprint) Check if the fingerprint for the specified server IP and port matches the one in trust file.static StringgenerateFingerprint(X509Certificate certificate) Generate fingerprint from a certificate using MessageDigest.static StringgenerateFingerprint(PublicKey publicKey) Generate fingerprint from public key using MessageDigest.static X509TrustManagerGet the system default trust managerX509TrustManagerGets the messages.static Set<TrustAnchor>Gets the root CAs in the trust store, either the default truststore or as specified by javax.net.ssl.trustStore/javax.net.ssl.trustStorePassword.static Set<TrustAnchor>getTrustedCAs(boolean refreshCache) Gets the root CAs from the trust store, either the default truststore or as specified by javax.net.ssl.trustStore/javax.net.ssl.trustStorePassword.voidinstallFingerprint(String serverIpPort, String fingerprintUser, String fingerprint) Install the fingerprint for the specified server IP and portvoidremoveFingerprint(String serverIpPort, String fingerprintUser) Removes the fingerprint for the specified server IP and portstatic voidvalidateServerChain(X509Certificate[] certs, String refName) Check the certificate chain.static voidCheck the certificate Not Before and Not After datesstatic voidverifyCertificateSubject(X509Certificate cert, String hostName) Verify the request's hostname to that in the certificate.
-
Field Details
-
DIGEST_TYPE
- See Also:
-
HEX_CHARS
public static final char[] HEX_CHARS -
FINGERPRINT_USER_NAME
- See Also:
-
FINGERPRINT_REPLACEMENT_USER_NAME
- See Also:
-
CLIENT_TRUST_MESSAGES
- See Also:
-
CLIENT_TRUST_WARNING_NOT_ESTABLISHED
- See Also:
-
CLIENT_TRUST_WARNING_NEW_CONNECTION
- See Also:
-
CLIENT_TRUST_WARNING_NEW_KEY
- See Also:
-
CLIENT_TRUST_EXCEPTION_NEW_CONNECTION
- See Also:
-
CLIENT_TRUST_EXCEPTION_NEW_KEY
- See Also:
-
CLIENT_TRUST_ADD_EXCEPTION_NEW_CONNECTION
- See Also:
-
CLIENT_TRUST_ADD_EXCEPTION_NEW_KEY
- See Also:
-
CLIENT_TRUST_ADDED
- See Also:
-
CLIENT_TRUST_REMOVED
- See Also:
-
CLIENT_TRUST_ALREADY_ESTABLISHED
- See Also:
-
CLIENT_TRUST_INSTALL_EXCEPTION
- See Also:
-
CLIENT_TRUST_UNINSTALL_EXCEPTION
- See Also:
-
SSL_CLIENT_TRUST_BADDATE
- See Also:
-
SSL_CLIENT_TRUST_BADHOST
- See Also:
-
-
Constructor Details
-
ClientTrust
Instantiates a new client trust.- Parameters:
rpcServer- the rpc server
-
-
Method Details
-
installFingerprint
public void installFingerprint(String serverIpPort, String fingerprintUser, String fingerprint) throws TrustException Install the fingerprint for the specified server IP and port- Parameters:
serverIpPort- the serverIpPortfingerprintUser- the fingerprintUserfingerprint- the fingerprint- Throws:
TrustException- the trust exception
-
removeFingerprint
Removes the fingerprint for the specified server IP and port- Parameters:
serverIpPort- the serverIpPortfingerprintUser- the fingerprintUser- Throws:
TrustException- the trust exception
-
fingerprintExists
Check if the fingerprint exists for the specified server IP and port- Parameters:
serverKey- the serverIpPort or serverHostNamefingerprintUser- the fingerprintUser- Returns:
- true, if successful
-
fingerprintMatches
Check if the fingerprint for the specified server IP and port matches the one in trust file.- Parameters:
serverKey- the serverIpPort or serverHostNamefingerprintUser- the fingerprintUserfingerprint- the fingerprint- Returns:
- true, if successful
-
generateFingerprint
Generate fingerprint from public key using MessageDigest.- Parameters:
publicKey- the public key- Returns:
- the string
- Throws:
NoSuchAlgorithmException- the no such algorithm exception
-
generateFingerprint
public static String generateFingerprint(X509Certificate certificate) throws NoSuchAlgorithmException, CertificateEncodingException Generate fingerprint from a certificate using MessageDigest.- Parameters:
certificate- the certificate- Returns:
- the string
- Throws:
NoSuchAlgorithmException- the no such algorithm exceptionCertificateEncodingException- the certificate encoding exception
-
convert2Hex
Convert a byte array to a hexadecimal string- Parameters:
data- the data- Returns:
- the string
-
getMessages
Gets the messages.- Returns:
- the messages
-
getTrustedCAs
public static Set<TrustAnchor> getTrustedCAs() throws NoSuchAlgorithmException, KeyStoreException, InvalidAlgorithmParameterExceptionGets the root CAs in the trust store, either the default truststore or as specified by javax.net.ssl.trustStore/javax.net.ssl.trustStorePassword. root CAs are cached.- Returns:
- root CAs
- Throws:
NoSuchAlgorithmException- on errorKeyStoreException- on errorInvalidAlgorithmParameterException- on error
-
getTrustedCAs
public static Set<TrustAnchor> getTrustedCAs(boolean refreshCache) throws NoSuchAlgorithmException, KeyStoreException, InvalidAlgorithmParameterException Gets the root CAs from the trust store, either the default truststore or as specified by javax.net.ssl.trustStore/javax.net.ssl.trustStorePassword.- Parameters:
refreshCache- force retrieve from truststore- Returns:
- root CAs
- Throws:
NoSuchAlgorithmException- on errorKeyStoreException- on errorInvalidAlgorithmParameterException- on error
-
getDefaultX509TrustManager
public static X509TrustManager getDefaultX509TrustManager() throws NoSuchAlgorithmException, KeyStoreExceptionGet the system default trust managerX509TrustManager- Returns:
- trust manager
- Throws:
NoSuchAlgorithmException- on errrorKeyStoreException- on error
-
validateServerChain
public static void validateServerChain(X509Certificate[] certs, String refName) throws CertificateException Check the certificate chain.- Parameters:
certs- the certificates from p4d handshake.refName- refName- Throws:
CertificateException- if the validation fails
-
verifyCertificateDates
Check the certificate Not Before and Not After dates- Parameters:
cert- cert- Throws:
CertificateException- on error
-
verifyCertificateSubject
public static void verifyCertificateSubject(X509Certificate cert, String hostName) throws CertificateParsingException, CertificateException, UnknownHostException Verify the request's hostname to that in the certificate.- Parameters:
cert- certificatehostName- Host name- Throws:
CertificateParsingException- on errorCertificateException- on errorUnknownHostException- Could not find IP Address for Given Host name
-