Package org.bouncycastle.tls
Class AbstractTlsPeer
java.lang.Object
org.bouncycastle.tls.AbstractTlsPeer
- All Implemented Interfaces:
TlsPeer
- Direct Known Subclasses:
AbstractTlsClient,AbstractTlsServer
Base class for a TLS client or server.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidcancel()intNOTE: Currently only respected by DTLS protocols.intNOTE: Currently only respected by DTLS protocols.Return aTlsHeartbeatinstance that will control the generation of heartbeats locally (if permitted by the remote peer), or null to not generate heartbeats.shortReturn the heartbeat mode applicable to the remote peer.intintshort[]intWARNING: EXPERIMENTAL FEATURE Return this peer's policy on renegotiation requests from the remote peer.protected abstract int[]protected ProtocolVersion[]Get theProtocolVersionvalues that are supported by this peer.voidnotifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) This method will be called when an alert is raised by the protocol.voidnotifyAlertReceived(short alertLevel, short alertDescription) This method will be called when an alert is received from the remote peer.voidnotifyCloseHandle(TlsCloseable closeHandle) voidNotifies the peer that the connection has been closed.voidNotifies the peer that a new handshake is about to begin.voidNotifies the peer that the handshake has been successfully completed.voidnotifySecureRenegotiation(boolean secureRenegotiation) RFC 5746 3.4/3.6.booleanThis option is provided as a last resort for interoperability with TLS peers that fail to correctly send a close_notify alert at end of stream.booleanThis implementation supports RFC 7627 and will always negotiate the extended_master_secret extension where possible.booleanControls whether the protocol will check the 'signatureAlgorithm' of received certificates as specified in RFC 5246 7.4.2, 7.4.4, 7.4.6 and similar rules for earlier TLS versions.booleanbooleanSee RFC 5246 6.2.3.2.booleandraft-mathewson-no-gmtunixtime-00 2.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bouncycastle.tls.TlsPeer
getCipherSuites, getProtocolVersions
-
Constructor Details
-
AbstractTlsPeer
-
-
Method Details
-
getSupportedVersions
Get theProtocolVersionvalues that are supported by this peer. WARNING: Mixing DTLS and TLS versions in the returned array is currently NOT supported. Use a separate (sub-)class for each case.- Returns:
- an array of supported
ProtocolVersionvalues.
-
getSupportedCipherSuites
protected abstract int[] getSupportedCipherSuites() -
cancel
- Specified by:
cancelin interfaceTlsPeer- Throws:
IOException
-
getCrypto
-
notifyCloseHandle
- Specified by:
notifyCloseHandlein interfaceTlsPeer
-
notifyHandshakeBeginning
Description copied from interface:TlsPeerNotifies the peer that a new handshake is about to begin.- Specified by:
notifyHandshakeBeginningin interfaceTlsPeer- Throws:
IOException
-
getHandshakeTimeoutMillis
public int getHandshakeTimeoutMillis()Description copied from interface:TlsPeerNOTE: Currently only respected by DTLS protocols.
Specify the timeout, in milliseconds, to use for the complete handshake process. Negative values are not allowed. A timeout of zero means an infinite timeout (i.e. the handshake will never time out).
- Specified by:
getHandshakeTimeoutMillisin interfaceTlsPeer- Returns:
- the handshake timeout, in milliseconds.
-
getHandshakeResendTimeMillis
public int getHandshakeResendTimeMillis()Description copied from interface:TlsPeerNOTE: Currently only respected by DTLS protocols.
Specify the time, in milliseconds, after which a handshake packet is resent.
- Specified by:
getHandshakeResendTimeMillisin interfaceTlsPeer- Returns:
- the handshake resend time, in milliseconds.
-
allowLegacyResumption
public boolean allowLegacyResumption()- Specified by:
allowLegacyResumptionin interfaceTlsPeer
-
getMaxCertificateChainLength
public int getMaxCertificateChainLength()- Specified by:
getMaxCertificateChainLengthin interfaceTlsPeer
-
getMaxHandshakeMessageSize
public int getMaxHandshakeMessageSize()- Specified by:
getMaxHandshakeMessageSizein interfaceTlsPeer
-
getPskKeyExchangeModes
public short[] getPskKeyExchangeModes()- Specified by:
getPskKeyExchangeModesin interfaceTlsPeer
-
requiresCloseNotify
public boolean requiresCloseNotify()Description copied from interface:TlsPeerThis option is provided as a last resort for interoperability with TLS peers that fail to correctly send a close_notify alert at end of stream. Implementations SHOULD return true; caution is advised if returning false without a full understanding of the implications.- Specified by:
requiresCloseNotifyin interfaceTlsPeer
-
requiresExtendedMasterSecret
public boolean requiresExtendedMasterSecret()Description copied from interface:TlsPeerThis implementation supports RFC 7627 and will always negotiate the extended_master_secret extension where possible. When connecting to a peer that does not offer/accept this extension, it is recommended to abort the handshake. This option is provided for interoperability with legacy peers, although some TLS features will be disabled in that case (see RFC 7627 5.4).- Specified by:
requiresExtendedMasterSecretin interfaceTlsPeer- Returns:
trueif the handshake should be aborted when the peer does not negotiate the extended_master_secret extension, orfalseto support legacy interoperability.
-
shouldCheckSigAlgOfPeerCerts
public boolean shouldCheckSigAlgOfPeerCerts()Description copied from interface:TlsPeerControls whether the protocol will check the 'signatureAlgorithm' of received certificates as specified in RFC 5246 7.4.2, 7.4.4, 7.4.6 and similar rules for earlier TLS versions. We recommend to enable these checks, but this option is provided for cases where the default checks are for some reason too strict.- Specified by:
shouldCheckSigAlgOfPeerCertsin interfaceTlsPeer- Returns:
trueif the 'signatureAlgorithm' of received certificates should be checked, orfalseto skip those checks.
-
shouldUseExtendedMasterSecret
public boolean shouldUseExtendedMasterSecret()- Specified by:
shouldUseExtendedMasterSecretin interfaceTlsPeer
-
shouldUseExtendedPadding
public boolean shouldUseExtendedPadding()Description copied from interface:TlsPeerSee RFC 5246 6.2.3.2. Controls whether block cipher encryption may randomly add extra padding beyond the minimum. Note that in configurations where this is known to be potential security risk this setting will be ignored (and extended padding disabled). Extra padding is always supported when decrypting received records.- Specified by:
shouldUseExtendedPaddingin interfaceTlsPeer- Returns:
trueif random extra padding should be added during block cipher encryption, orfalseto always use the minimum amount of required padding.
-
shouldUseGMTUnixTime
public boolean shouldUseGMTUnixTime()Description copied from interface:TlsPeerdraft-mathewson-no-gmtunixtime-00 2. "If existing users of a TLS implementation may rely on gmt_unix_time containing the current time, we recommend that implementors MAY provide the ability to set gmt_unix_time as an option only, off by default." NOTE: For a server that has negotiated TLS 1.3 (or later), or a client that has offered TLS 1.3 (or later), this is not called and gmt_unix_time is not used.- Specified by:
shouldUseGMTUnixTimein interfaceTlsPeer- Returns:
trueif the current time should be used in the gmt_unix_time field of Random, orfalseif gmt_unix_time should contain a cryptographically random value.
-
notifySecureRenegotiation
Description copied from interface:TlsPeerRFC 5746 3.4/3.6. In case this is false, peers may want to terminate the handshake instead of continuing; see Section 4.1/4.3 for discussion. NOTE: TLS 1.3 forbids renegotiation, so this is never called when TLS 1.3 (or later) was negotiated.- Specified by:
notifySecureRenegotiationin interfaceTlsPeer- Throws:
IOException
-
getKeyExchangeFactory
- Specified by:
getKeyExchangeFactoryin interfaceTlsPeer- Throws:
IOException
-
notifyAlertRaised
public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) Description copied from interface:TlsPeerThis method will be called when an alert is raised by the protocol.- Specified by:
notifyAlertRaisedin interfaceTlsPeer- Parameters:
alertLevel-AlertLevelalertDescription-AlertDescriptionmessage- A human-readable message explaining what caused this alert. May be null.cause- TheThrowablethat caused this alert to be raised. May be null.
-
notifyAlertReceived
public void notifyAlertReceived(short alertLevel, short alertDescription) Description copied from interface:TlsPeerThis method will be called when an alert is received from the remote peer.- Specified by:
notifyAlertReceivedin interfaceTlsPeer- Parameters:
alertLevel-AlertLevelalertDescription-AlertDescription
-
notifyConnectionClosed
public void notifyConnectionClosed()Description copied from interface:TlsPeerNotifies the peer that the connection has been closed.- Specified by:
notifyConnectionClosedin interfaceTlsPeer
-
notifyHandshakeComplete
Description copied from interface:TlsPeerNotifies the peer that the handshake has been successfully completed.- Specified by:
notifyHandshakeCompletein interfaceTlsPeer- Throws:
IOException
-
getHeartbeat
Description copied from interface:TlsPeerReturn aTlsHeartbeatinstance that will control the generation of heartbeats locally (if permitted by the remote peer), or null to not generate heartbeats. Heartbeats are described in RFC 6520.- Specified by:
getHeartbeatin interfaceTlsPeer- Returns:
- an instance of
TlsHeartbeat. - See Also:
-
getHeartbeatPolicy
public short getHeartbeatPolicy()Description copied from interface:TlsPeerReturn the heartbeat mode applicable to the remote peer. Heartbeats are described in RFC 6520.
See enumeration class
HeartbeatModefor appropriate return values.- Specified by:
getHeartbeatPolicyin interfaceTlsPeer- Returns:
- the
HeartbeatModevalue.
-
getRenegotiationPolicy
public int getRenegotiationPolicy()Description copied from interface:TlsPeerWARNING: EXPERIMENTAL FEATURE Return this peer's policy on renegotiation requests from the remote peer. This will be called only outside of ongoing handshakes, either when a remote server has sent a hello_request, or a remote client has sent a new ClientHello, and only when the requirements for secure renegotiation (including those of RFC 5746) have been met.- Specified by:
getRenegotiationPolicyin interfaceTlsPeer- Returns:
- The
RenegotiationPolicyconstant corresponding to the desired policy. - See Also:
-