Class AbstractTlsServer
- java.lang.Object
-
- org.bouncycastle.tls.AbstractTlsPeer
-
- org.bouncycastle.tls.AbstractTlsServer
-
- Direct Known Subclasses:
DefaultTlsServer,PSKTlsServer,SRPTlsServer
public abstract class AbstractTlsServer extends AbstractTlsPeer implements TlsServer
Base class for a TLS server.
-
-
Field Summary
Fields Modifier and Type Field Description protected CertificateStatusRequestcertificateStatusRequestprotected int[]cipherSuitesprotected java.util.HashtableclientExtensionsprotected java.util.VectorclientProtocolNamesprotected booleanclientSentECPointFormatsprotected TlsServerContextcontextprotected booleanencryptThenMACOfferedprotected shortmaxFragmentLengthOfferedprotected int[]offeredCipherSuitesprotected ProtocolVersion[]protocolVersionsprotected intselectedCipherSuiteprotected ProtocolNameselectedProtocolNameprotected java.util.HashtableserverExtensionsprotected java.util.VectorstatusRequestV2protected booleantruncatedHMacOfferedprotected java.util.VectortrustedCAKeys
-
Constructor Summary
Constructors Constructor Description AbstractTlsServer(TlsCrypto crypto)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected booleanallowCertificateStatus()Whether to echo a client's "status_request" extension (RFC 6066 sec. 8) in the extended server hello, so that a stapled OCSP response can be sent.protected booleanallowEncryptThenMAC()protected booleanallowMultiCertStatus()Whether to echo a client's "status_request_v2" extension (RFC 6961 sec. 2.2) in the extended server hello.protected booleanallowTruncatedHMac()protected booleanallowTrustedCAIndication()protected java.util.HashtablecheckServerExtensions()Deprecated.Use 'serverExtensions' directly, it is now never nullprotected short[]getAllowedClientCertificateTypes()CertificateRequestgetCertificateRequest()CertificateStatusgetCertificateStatus()This method will be called (only) ifSecurityParameters.getStatusRequestVersion()is non-zero, meaning the client asked for a stapled response and the server undertook to answer: up to (D)TLS 1.2, that it echoed an extension of type "status_request" (RFC 6066 sec. 8.int[]getCipherSuites()protected java.lang.StringgetDetailMessageNoCipherSuite()TlsDHConfiggetDHConfig()TlsECConfiggetECDHConfig()TlsPSKExternalgetExternalPSK(java.util.Vector identities)WARNING: EXPERIMENTAL FEATURE, UNSTABLE API Return theexternal PSKto select from the ClientHello.protected intgetMaximumDefaultCurveBits()protected intgetMaximumDefaultFiniteFieldBits()protected intgetMaximumNegotiableCurveBits()protected intgetMaximumNegotiableFiniteFieldBits()protected byte[]getNewConnectionID()RFC 9146 DTLS connection ID.byte[]getNewSessionID()NewSessionTicketgetNewSessionTicket()RFC 5077 3.3.protected java.util.VectorgetProtocolNames()ProtocolVersion[]getProtocolVersions()TlsPSKIdentityManagergetPSKIdentityManager()intgetSelectedCipherSuite()java.util.HashtablegetServerExtensions()voidgetServerExtensionsForConnection(java.util.Hashtable serverExtensions)java.util.VectorgetServerSupplementalData()ProtocolVersiongetServerVersion()TlsSessiongetSessionToResume(byte[] sessionID)Return the specified session, if available.TlsSRPLoginParametersgetSRPLoginParameters()int[]getSupportedGroups()voidinit(TlsServerContext context)protected booleanisSelectableCipherSuite(int cipherSuite, int availCurveBits, int availFiniteFieldBits, java.util.Vector sigAlgs)voidnotifyClientCertificate(Certificate clientCertificate)Called by the protocol handler to report the client certificate, only ifTlsServer.getCertificateRequest()returned non-null.voidnotifyClientVersion(ProtocolVersion clientVersion)voidnotifyFallback(boolean isFallback)voidnotifyHandshakeBeginning()Notifies the peer that a new handshake is about to begin.voidnotifyOfferedCipherSuites(int[] offeredCipherSuites)voidnotifySession(TlsSession session)protected booleanpreferLocalCipherSuites()protected booleanpreferLocalClientCertificateTypes()booleanpreferLocalSupportedGroups()voidprocessClientExtensions(java.util.Hashtable clientExtensions)voidprocessClientSupplementalData(java.util.Vector clientSupplementalData)protected booleanselectCipherSuite(int cipherSuite)protected intselectDH(int minimumFiniteFieldBits)protected intselectDHDefault(int minimumFiniteFieldBits)protected intselectECDH(int minimumCurveBits)protected intselectECDHDefault(int minimumCurveBits)protected ProtocolNameselectProtocolName()protected ProtocolNameselectProtocolName(java.util.Vector clientProtocolNames, java.util.Vector serverProtocolNames)protected booleanshouldSelectProtocolNameEarly()-
Methods inherited from class org.bouncycastle.tls.AbstractTlsPeer
allowLegacyResumption, cancel, getCrypto, getHandshakeResendTimeMillis, getHandshakeTimeoutMillis, getHeartbeat, getHeartbeatPolicy, getKeyExchangeFactory, getMaxCertificateChainLength, getMaxHandshakeMessageSize, getPskKeyExchangeModes, getRenegotiationPolicy, getSupportedCipherSuites, getSupportedVersions, notifyAlertRaised, notifyAlertReceived, notifyCloseHandle, notifyConnectionClosed, notifyHandshakeComplete, notifySecureRenegotiation, requiresCloseNotify, requiresExtendedMasterSecret, shouldCheckSigAlgOfPeerCerts, shouldUseExtendedMasterSecret, shouldUseExtendedPadding, shouldUseGMTUnixTime
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bouncycastle.tls.TlsPeer
allowLegacyResumption, cancel, getCrypto, getHandshakeResendTimeMillis, getHandshakeTimeoutMillis, getHeartbeat, getHeartbeatPolicy, getKeyExchangeFactory, getMaxCertificateChainLength, getMaxHandshakeMessageSize, getPskKeyExchangeModes, getRenegotiationPolicy, notifyAlertRaised, notifyAlertReceived, notifyCloseHandle, notifyConnectionClosed, notifyHandshakeComplete, notifySecureRenegotiation, requiresCloseNotify, requiresExtendedMasterSecret, shouldCheckSigAlgOfPeerCerts, shouldUseExtendedMasterSecret, shouldUseExtendedPadding, shouldUseGMTUnixTime
-
Methods inherited from interface org.bouncycastle.tls.TlsServer
getCredentials
-
-
-
-
Field Detail
-
context
protected TlsServerContext context
-
protocolVersions
protected ProtocolVersion[] protocolVersions
-
cipherSuites
protected int[] cipherSuites
-
offeredCipherSuites
protected int[] offeredCipherSuites
-
clientExtensions
protected java.util.Hashtable clientExtensions
-
encryptThenMACOffered
protected boolean encryptThenMACOffered
-
maxFragmentLengthOffered
protected short maxFragmentLengthOffered
-
truncatedHMacOffered
protected boolean truncatedHMacOffered
-
clientSentECPointFormats
protected boolean clientSentECPointFormats
-
certificateStatusRequest
protected CertificateStatusRequest certificateStatusRequest
-
statusRequestV2
protected java.util.Vector statusRequestV2
-
trustedCAKeys
protected java.util.Vector trustedCAKeys
-
selectedCipherSuite
protected int selectedCipherSuite
-
clientProtocolNames
protected java.util.Vector clientProtocolNames
-
selectedProtocolName
protected ProtocolName selectedProtocolName
-
serverExtensions
protected final java.util.Hashtable serverExtensions
-
-
Constructor Detail
-
AbstractTlsServer
public AbstractTlsServer(TlsCrypto crypto)
-
-
Method Detail
-
allowCertificateStatus
protected boolean allowCertificateStatus()
Whether to echo a client's "status_request" extension (RFC 6066 sec. 8) in the extended server hello, so that a stapled OCSP response can be sent. Echoing it makesgetCertificateStatus()be called withSecurityParameters.getStatusRequestVersion()of 1; it does not oblige the server to actually supply a response.This governs (D)TLS 1.2 and earlier, where the echo is what announces the "certificate_status" message. TLS 1.3 has no echo to send - the response rides in a per-
CertificateEntryextension - so theregetCertificateStatus()is called whenever the client offered "status_request", whatever this returns, and returning null from it is how a TLS 1.3 server declines to staple.- Returns:
- true (the default) to echo "status_request" when the client offered it.
-
allowEncryptThenMAC
protected boolean allowEncryptThenMAC()
-
allowMultiCertStatus
protected boolean allowMultiCertStatus()
Whether to echo a client's "status_request_v2" extension (RFC 6961 sec. 2.2) in the extended server hello. When the client offered both, echoing this one takes precedence over "status_request", andgetCertificateStatus()is then called withSecurityParameters.getStatusRequestVersion()of 2 – so a server overriding this must be prepared to return aCertificateStatusType.ocsp_multistatus.- Returns:
- false (the default) to leave "status_request_v2" unanswered.
-
allowTruncatedHMac
protected boolean allowTruncatedHMac()
-
allowTrustedCAIndication
protected boolean allowTrustedCAIndication()
-
checkServerExtensions
@Deprecated protected java.util.Hashtable checkServerExtensions()
Deprecated.Use 'serverExtensions' directly, it is now never null
-
getDetailMessageNoCipherSuite
protected java.lang.String getDetailMessageNoCipherSuite()
-
getMaximumDefaultCurveBits
protected int getMaximumDefaultCurveBits()
-
getMaximumDefaultFiniteFieldBits
protected int getMaximumDefaultFiniteFieldBits()
-
getMaximumNegotiableCurveBits
protected int getMaximumNegotiableCurveBits()
-
getMaximumNegotiableFiniteFieldBits
protected int getMaximumNegotiableFiniteFieldBits()
-
getProtocolNames
protected java.util.Vector getProtocolNames()
-
isSelectableCipherSuite
protected boolean isSelectableCipherSuite(int cipherSuite, int availCurveBits, int availFiniteFieldBits, java.util.Vector sigAlgs)
-
preferLocalCipherSuites
protected boolean preferLocalCipherSuites()
-
preferLocalSupportedGroups
public boolean preferLocalSupportedGroups()
- Specified by:
preferLocalSupportedGroupsin interfaceTlsServer
-
selectCipherSuite
protected boolean selectCipherSuite(int cipherSuite) throws java.io.IOException- Throws:
java.io.IOException
-
selectDH
protected int selectDH(int minimumFiniteFieldBits)
-
selectDHDefault
protected int selectDHDefault(int minimumFiniteFieldBits)
-
selectECDH
protected int selectECDH(int minimumCurveBits)
-
selectECDHDefault
protected int selectECDHDefault(int minimumCurveBits)
-
selectProtocolName
protected ProtocolName selectProtocolName() throws java.io.IOException
- Throws:
java.io.IOException
-
selectProtocolName
protected ProtocolName selectProtocolName(java.util.Vector clientProtocolNames, java.util.Vector serverProtocolNames)
-
shouldSelectProtocolNameEarly
protected boolean shouldSelectProtocolNameEarly()
-
preferLocalClientCertificateTypes
protected boolean preferLocalClientCertificateTypes()
-
getAllowedClientCertificateTypes
protected short[] getAllowedClientCertificateTypes()
-
getNewConnectionID
protected byte[] getNewConnectionID()
RFC 9146 DTLS connection ID. This method will be called if a connection_id extension was sent by the client. If the return value is non-null, the server will send this connection ID to the client to use in future packets. As future communication doesn't include the connection IDs length, this should either be fixed-length or include the connection ID's length. (see explanation in RFC 9146 4. "cid:")- Returns:
- The connection ID to use.
-
init
public void init(TlsServerContext context)
-
getProtocolVersions
public ProtocolVersion[] getProtocolVersions()
- Specified by:
getProtocolVersionsin interfaceTlsPeer
-
getCipherSuites
public int[] getCipherSuites()
- Specified by:
getCipherSuitesin interfaceTlsPeer
-
notifyHandshakeBeginning
public void notifyHandshakeBeginning() throws java.io.IOExceptionDescription copied from interface:TlsPeerNotifies the peer that a new handshake is about to begin.- Specified by:
notifyHandshakeBeginningin interfaceTlsPeer- Overrides:
notifyHandshakeBeginningin classAbstractTlsPeer- Throws:
java.io.IOException
-
getSessionToResume
public TlsSession getSessionToResume(byte[] sessionID)
Description copied from interface:TlsServerReturn the specified session, if available. Note that the peer's certificate chain for the session (if any) may need to be periodically revalidated.- Specified by:
getSessionToResumein interfaceTlsServer- Parameters:
sessionID- the ID of the session to resume.- Returns:
- A
TlsSessionwith the specified session ID, or null. - See Also:
SessionParameters.getPeerCertificate()
-
getNewSessionID
public byte[] getNewSessionID()
- Specified by:
getNewSessionIDin interfaceTlsServer
-
getExternalPSK
public TlsPSKExternal getExternalPSK(java.util.Vector identities) throws java.io.IOException
Description copied from interface:TlsServerWARNING: EXPERIMENTAL FEATURE, UNSTABLE API Return theexternal PSKto select from the ClientHello. Note that this will only be called when TLS 1.3 or higher is amongst the offered protocol versions, and one or more PSKs are actually offered.- Specified by:
getExternalPSKin interfaceTlsServer- Parameters:
identities- aVectorofPskIdentityinstances.- Returns:
- the
TlsPSKExternalcorresponding to the selected identity, or null to not select any. - Throws:
java.io.IOException- if the handshake should be aborted. An implementation may throw aTlsFatalAlertto control the alert sent to the peer - e.g.AlertDescription.unknown_psk_identitywhen none of the offered identities is recognised, orAlertDescription.decrypt_errorwhen an identity is recognised but is invalid or expired (see RFC 8446 6.2). Returning null instead leaves PSK unselected without aborting.
-
notifySession
public void notifySession(TlsSession session)
- Specified by:
notifySessionin interfaceTlsServer
-
notifyClientVersion
public void notifyClientVersion(ProtocolVersion clientVersion) throws java.io.IOException
- Specified by:
notifyClientVersionin interfaceTlsServer- Throws:
java.io.IOException
-
notifyFallback
public void notifyFallback(boolean isFallback) throws java.io.IOException- Specified by:
notifyFallbackin interfaceTlsServer- Throws:
java.io.IOException
-
notifyOfferedCipherSuites
public void notifyOfferedCipherSuites(int[] offeredCipherSuites) throws java.io.IOException- Specified by:
notifyOfferedCipherSuitesin interfaceTlsServer- Throws:
java.io.IOException
-
processClientExtensions
public void processClientExtensions(java.util.Hashtable clientExtensions) throws java.io.IOException- Specified by:
processClientExtensionsin interfaceTlsServer- Throws:
java.io.IOException
-
getServerVersion
public ProtocolVersion getServerVersion() throws java.io.IOException
- Specified by:
getServerVersionin interfaceTlsServer- Throws:
java.io.IOException
-
getSupportedGroups
public int[] getSupportedGroups() throws java.io.IOException- Specified by:
getSupportedGroupsin interfaceTlsServer- Throws:
java.io.IOException
-
getSelectedCipherSuite
public int getSelectedCipherSuite() throws java.io.IOException- Specified by:
getSelectedCipherSuitein interfaceTlsServer- Throws:
java.io.IOException
-
getServerExtensions
public java.util.Hashtable getServerExtensions() throws java.io.IOException- Specified by:
getServerExtensionsin interfaceTlsServer- Throws:
java.io.IOException
-
getServerExtensionsForConnection
public void getServerExtensionsForConnection(java.util.Hashtable serverExtensions) throws java.io.IOException- Specified by:
getServerExtensionsForConnectionin interfaceTlsServer- Throws:
java.io.IOException
-
getServerSupplementalData
public java.util.Vector getServerSupplementalData() throws java.io.IOException- Specified by:
getServerSupplementalDatain interfaceTlsServer- Throws:
java.io.IOException
-
getCertificateStatus
public CertificateStatus getCertificateStatus() throws java.io.IOException
Description copied from interface:TlsServerThis method will be called (only) ifSecurityParameters.getStatusRequestVersion()is non-zero, meaning the client asked for a stapled response and the server undertook to answer: up to (D)TLS 1.2, that it echoed an extension of type "status_request" (RFC 6066 sec. 8. Certificate Status Request) or "status_request_v2" (RFC 6961 sec. 2.2. Multiple Certificate Status Request Record) with empty "extension_data" in the extended server hello; in TLS 1.3, simply that the client offered "status_request".The status request version says which of the two shapes the client will accept; returning the other one is a fatal alert at the client:
- 1 – "status_request". Return a
CertificateStatusType.ocspstatus carrying a single response, for the end-entity certificate. - 2 – "status_request_v2" was echoed. Return a
CertificateStatusType.ocsp_multistatus carrying one entry per certificate in the chain that was sent, in the same order, with a null entry wherever no response is available.
allowCertificateStatus()(defaults to true) andallowMultiCertStatus()(defaults to false).How the returned status reaches the client depends on the negotiated version. Up to (D)TLS 1.2 it is sent as a handshake message of type "certificate_status", for the whole chain at once. In TLS 1.3 there is no such message: the response travels in a "status_request" extension of the
CertificateEntrycontaining the certificate it answers for (RFC 8446 sec. 4.4.2.1), and the protocol distributes what this callback returns across those entries - anCertificateStatusType.ocspstatus answering for the end-entity certificate, anCertificateStatusType.ocsp_multistatus answering positionally, entryiof its list for certificateiof the chain. So a TLS 1.3 server with a response for more than the end-entity certificate returns the ocsp_multi shape even though the status request version is 1. An entry the server has itself given a "status_request" extension - by attaching it to theCertificateits credentials supply, which was previously the only way to staple in TLS 1.3 - is left as it stands.OCSPStaplingServerExamplein the misc module is a worked example.- Specified by:
getCertificateStatusin interfaceTlsServer- Returns:
- A
CertificateStatusto be sent to the client (or null for none). - Throws:
java.io.IOException
- 1 – "status_request". Return a
-
getCertificateRequest
public CertificateRequest getCertificateRequest() throws java.io.IOException
- Specified by:
getCertificateRequestin interfaceTlsServer- Throws:
java.io.IOException
-
getPSKIdentityManager
public TlsPSKIdentityManager getPSKIdentityManager() throws java.io.IOException
- Specified by:
getPSKIdentityManagerin interfaceTlsServer- Throws:
java.io.IOException
-
getSRPLoginParameters
public TlsSRPLoginParameters getSRPLoginParameters() throws java.io.IOException
- Specified by:
getSRPLoginParametersin interfaceTlsServer- Throws:
java.io.IOException
-
getDHConfig
public TlsDHConfig getDHConfig() throws java.io.IOException
- Specified by:
getDHConfigin interfaceTlsServer- Throws:
java.io.IOException
-
getECDHConfig
public TlsECConfig getECDHConfig() throws java.io.IOException
- Specified by:
getECDHConfigin interfaceTlsServer- Throws:
java.io.IOException
-
processClientSupplementalData
public void processClientSupplementalData(java.util.Vector clientSupplementalData) throws java.io.IOException- Specified by:
processClientSupplementalDatain interfaceTlsServer- Throws:
java.io.IOException
-
notifyClientCertificate
public void notifyClientCertificate(Certificate clientCertificate) throws java.io.IOException
Description copied from interface:TlsServerCalled by the protocol handler to report the client certificate, only ifTlsServer.getCertificateRequest()returned non-null. Note: this method is responsible for certificate verification and validation.- Specified by:
notifyClientCertificatein interfaceTlsServer- Parameters:
clientCertificate- the effective client certificate (may be an empty chain).- Throws:
java.io.IOException
-
getNewSessionTicket
public NewSessionTicket getNewSessionTicket() throws java.io.IOException
Description copied from interface:TlsServerRFC 5077 3.3. NewSessionTicket Handshake Message.This method will be called (only) if a NewSessionTicket extension was sent by the server. See RFC 5077 4. Recommended Ticket Construction for recommended format and protection.
- Specified by:
getNewSessionTicketin interfaceTlsServer- Returns:
- The ticket.
- Throws:
java.io.IOException
-
-