Package org.apache.hc.client5.http.ssl
Class SpkiPinningClientTlsStrategy
- java.lang.Object
-
- org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy
-
- org.apache.hc.client5.http.ssl.SpkiPinningClientTlsStrategy
-
- All Implemented Interfaces:
TlsSocketStrategy,org.apache.hc.core5.http.nio.ssl.TlsStrategy
@Contract(threading=IMMUTABLE) public final class SpkiPinningClientTlsStrategy extends DefaultClientTlsStrategy
SPKI pinning decorator for client-side TLS.
This strategy enforces one or more
sha256/<base64(SPKI)>pins for a given host or single-label wildcard (e.g.*.example.com) after the standard trust manager and hostname verification succeed. Pins are matched against theSubjectPublicKeyInfo(SPKI) of any certificate in the peer chain.Host matching is performed on the IDNA ASCII (Punycode) lowercase form. Wildcards are single-label only (e.g.
*.example.commatchesa.example.combut nota.b.example.com).Warning: Certificate pinning increases operational risk. Always ship at least two pins (active + backup) and keep normal PKI + hostname verification enabled.
Thread-safety: immutable and thread-safe.
- Since:
- 5.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpkiPinningClientTlsStrategy.BuilderBuilder forSpkiPinningClientTlsStrategy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidinitializeEngine(javax.net.ssl.SSLEngine sslEngine)protected voidinitializeSocket(javax.net.ssl.SSLSocket socket)static SpkiPinningClientTlsStrategy.BuildernewBuilder(javax.net.ssl.SSLContext sslContext)Create a new builder.javax.net.ssl.SSLSocketupgrade(java.net.Socket socket, java.lang.String target, int port, java.lang.Object attachment, org.apache.hc.core5.http.protocol.HttpContext context)Upgrades the given plain socket and executes the TLS handshake over it.booleanupgrade(org.apache.hc.core5.reactor.ssl.TransportSecurityLayer tlsSession, org.apache.hc.core5.http.HttpHost host, java.net.SocketAddress localAddress, java.net.SocketAddress remoteAddress, java.lang.Object attachment, org.apache.hc.core5.util.Timeout handshakeTimeout)Deprecated.useTlsStrategy.upgrade(TransportSecurityLayer, NamedEndpoint, Object, Timeout, FutureCallback)voidupgrade(org.apache.hc.core5.reactor.ssl.TransportSecurityLayer tlsSession, org.apache.hc.core5.net.NamedEndpoint endpoint, java.lang.Object attachment, org.apache.hc.core5.util.Timeout handshakeTimeout, org.apache.hc.core5.concurrent.FutureCallback<org.apache.hc.core5.reactor.ssl.TransportSecurityLayer> callback)protected voidverifySession(java.lang.String hostname, javax.net.ssl.SSLSession sslSession)Invoked after the default trust and hostname checks.-
Methods inherited from class org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy
createDefault, createSystemDefault, getDefault, getSystemDefault
-
-
-
-
Method Detail
-
verifySession
protected void verifySession(java.lang.String hostname, javax.net.ssl.SSLSession sslSession) throws javax.net.ssl.SSLExceptionInvoked after the default trust and hostname checks. If one or more rules match thehostname, at least one pin must match any SPKI in the peer chain.- Throws:
javax.net.ssl.SSLException
-
newBuilder
public static SpkiPinningClientTlsStrategy.Builder newBuilder(javax.net.ssl.SSLContext sslContext)
Create a new builder.- Parameters:
sslContext- SSL context used for handshakes (trust + keys).- Returns:
- builder
-
upgrade
@Deprecated public boolean upgrade(org.apache.hc.core5.reactor.ssl.TransportSecurityLayer tlsSession, org.apache.hc.core5.http.HttpHost host, java.net.SocketAddress localAddress, java.net.SocketAddress remoteAddress, java.lang.Object attachment, org.apache.hc.core5.util.Timeout handshakeTimeout)Deprecated.useTlsStrategy.upgrade(TransportSecurityLayer, NamedEndpoint, Object, Timeout, FutureCallback)- Specified by:
upgradein interfaceorg.apache.hc.core5.http.nio.ssl.TlsStrategy
-
upgrade
public void upgrade(org.apache.hc.core5.reactor.ssl.TransportSecurityLayer tlsSession, org.apache.hc.core5.net.NamedEndpoint endpoint, java.lang.Object attachment, org.apache.hc.core5.util.Timeout handshakeTimeout, org.apache.hc.core5.concurrent.FutureCallback<org.apache.hc.core5.reactor.ssl.TransportSecurityLayer> callback)- Specified by:
upgradein interfaceorg.apache.hc.core5.http.nio.ssl.TlsStrategy
-
initializeEngine
protected void initializeEngine(javax.net.ssl.SSLEngine sslEngine)
-
initializeSocket
protected void initializeSocket(javax.net.ssl.SSLSocket socket)
-
upgrade
public javax.net.ssl.SSLSocket upgrade(java.net.Socket socket, java.lang.String target, int port, java.lang.Object attachment, org.apache.hc.core5.http.protocol.HttpContext context) throws java.io.IOExceptionDescription copied from interface:TlsSocketStrategyUpgrades the given plain socket and executes the TLS handshake over it.- Specified by:
upgradein interfaceTlsSocketStrategy- Parameters:
socket- the existing plain sockettarget- the name of the target host.port- the port to connect to on the target host.attachment- connect request attachment.context- the actual HTTP context.- Returns:
- socket upgraded to TLS.
- Throws:
java.io.IOException
-
-