Class SpkiPinningClientTlsStrategy
java.lang.Object
org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy
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 the
SubjectPublicKeyInfo (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.com matches
a.example.com but not a.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 ClassesModifier and TypeClassDescriptionstatic final classBuilder forSpkiPinningClientTlsStrategy.private static final classByte-array key with constant-time equality for use in sets/maps.private static final classMatch rule for a host or single-label wildcard. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final List<SpkiPinningClientTlsStrategy.Rule> private static final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSpkiPinningClientTlsStrategy(SSLContext sslContext, List<SpkiPinningClientTlsStrategy.Rule> rules) -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[][]chainSpkiSha256(SSLSession session) private static String(package private) voidenforcePins(String hostname, SSLSession sslSession) Enforce SPKI pins for the given hostname and session.private List<SpkiPinningClientTlsStrategy.Rule> matchedRules(String host) newBuilder(SSLContext sslContext) Create a new builder.private static StringpeerPinsForLog(byte[][] hashes) protected voidverifySession(String hostname, SSLSession sslSession) Invoked after the default trust and hostname checks.Methods inherited from class DefaultClientTlsStrategy
applyParameters, createDefault, createSystemDefault, createTlsDetails, getDefault, getSystemDefaultMethods inherited from class AbstractClientTlsStrategy
initializeEngine, initializeSocket, toEscapedString, upgrade, upgrade, upgrade, verifySession
-
Field Details
-
PIN_PREFIX
- See Also:
-
SHA256_LEN
private static final int SHA256_LEN- See Also:
-
rules
-
-
Constructor Details
-
SpkiPinningClientTlsStrategy
private SpkiPinningClientTlsStrategy(SSLContext sslContext, List<SpkiPinningClientTlsStrategy.Rule> rules)
-
-
Method Details
-
verifySession
Invoked 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.- Overrides:
verifySessionin classAbstractClientTlsStrategy- Throws:
SSLException
-
enforcePins
Enforce SPKI pins for the given hostname and session. Package-private for testing.- Throws:
SSLException
-
newBuilder
Create a new builder.- Parameters:
sslContext- SSL context used for handshakes (trust + keys).- Returns:
- builder
-
matchedRules
-
chainSpkiSha256
- Throws:
SSLException
-
configuredPinsFor
-
peerPinsForLog
-