java.lang.Object
org.miaixz.bus.http.secure.CertificatePinner
Constrains which certificates are trusted. Certificate pinning increases security, but also limits your server team's
abilities to update their TLS certificates. Do not use certificate pinning without the blessing of your
server's TLS administrator!
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CertificatePinnerA default certificate pinner that trusts any certificate chain. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheck(String hostname, List<Certificate> peerCertificates) Confirms that at least one of the certificates pinned forhostnameis present inpeerCertificates.booleaninthashCode()static Stringpin(Certificate certificate) Returns the SHA-256 ofcertificate's public key.withCertificateChainCleaner(CertificateChainCleaner certificateChainCleaner) Returns a new certificate pinner that usescertificateChainCleaner.
-
Field Details
-
DEFAULT
A default certificate pinner that trusts any certificate chain.
-
-
Method Details
-
pin
Returns the SHA-256 ofcertificate's public key.- Parameters:
certificate- The certificate to hash.- Returns:
- A string in the format "sha256/<base64-hash>".
-
equals
-
hashCode
public int hashCode() -
check
public void check(String hostname, List<Certificate> peerCertificates) throws SSLPeerUnverifiedException Confirms that at least one of the certificates pinned forhostnameis present inpeerCertificates. This method is called after a successful TLS handshake, but before the connection is used.- Parameters:
hostname- The hostname of the peer.peerCertificates- The certificate chain presented by the peer.- Throws:
SSLPeerUnverifiedException- ifpeerCertificatesdoes not match the certificates pinned forhostname.
-
withCertificateChainCleaner
public CertificatePinner withCertificateChainCleaner(CertificateChainCleaner certificateChainCleaner) Returns a new certificate pinner that usescertificateChainCleaner.- Parameters:
certificateChainCleaner- The cleaner to use.- Returns:
- a new
CertificatePinnerinstance.
-