public abstract class Handshaker extends Object implements Destroyable
| Modifier and Type | Field and Description |
|---|---|
protected AdvancedPskStore |
advancedPskStore
Used to retrieve identity/pre-shared-key for a given destination
|
protected List<X509Certificate> |
certificateChain
The chain of certificates asserting this handshaker's identity
|
protected boolean |
certificateVerfied
Indicates, that the certificate or public key verification has finished.
|
protected NewAdvancedCertificateVerifier |
certificateVerifier
The logic in charge of verifying the chain of certificates asserting this
handshaker's identity
|
protected Random |
clientRandom |
protected ConnectionIdGenerator |
connectionIdGenerator
The configured connection id length.
|
protected int |
flightNumber
The current flight number.
|
protected List<HandshakeMessage> |
handshakeMessages
List of handshake messages
|
protected boolean |
isClient
Indicates whether this handshaker performs the client or server part of
the protocol.
|
protected org.slf4j.Logger |
LOGGER |
protected SecretKey |
masterSecret
The master secret for this handshake.
|
protected CertPath |
peerCertPath
The certificate path of the other peer
|
protected PrivateKey |
privateKey
The handshaker's private key.
|
protected PublicKey |
publicKey
The handshaker's public key.
|
protected ReassemblingHandshakeMessage |
reassembledMessage
Current partial reassembled handshake message.
|
protected Integer |
recordSizeLimit
Record size limit.
|
protected Random |
serverRandom |
protected DTLSSession |
session |
protected boolean |
sniEnabled
Support Server Name Indication TLS extension.
|
protected HandshakeState[] |
states |
protected int |
statesIndex |
protected ProtocolVersion |
usedProtocol |
protected boolean |
useKeyUsageVerification
Use key usage verification for x509.
|
protected boolean |
useStateValidation
Use handshake state machine validation.
|
protected boolean |
useTruncatedCertificatePathForVerification
Truncate certificate path for validation.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Handshaker(boolean isClient,
int initialMessageSeq,
DTLSSession session,
RecordLayer recordLayer,
ScheduledExecutorService timer,
Connection connection,
DtlsConnectorConfig config)
Creates a new handshaker for negotiating a DTLS session with a given
peer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addApplicationDataForDeferredProcessing(org.eclipse.californium.elements.RawData outgoingMessage)
Add outgoing application data for deferred processing.
|
void |
addRecordsForDeferredProcessing(Record incomingMessage)
Add incoming records for deferred processing.
|
void |
addSessionListener(SessionListener listener)
Adds a listener to the list of listeners to be notified
about session life cycle events.
|
protected void |
applyMasterSecret(SecretKey masterSecret)
Applying the key expansion on the master secret generates a large key
block to generate the encryption, MAC and IV keys.
|
protected void |
calculateKeys(SecretKey masterSecret)
Calculates the encryption key, MAC key and IV from a given master secret.
|
void |
completePendingFlight()
Registers an outbound flight that has not been acknowledged by the peer
yet in order to be able to cancel its re-transmission later once it has
been acknowledged.
|
DTLSFlight |
createFlight()
Create new flight with the current
getSession() and the current
flightNumber. |
void |
destroy() |
protected abstract void |
doProcessMessage(HandshakeMessage message)
Does the specific processing of a message received from a peer in
the course of an ongoing handshake.
|
protected void |
ensureUndestroyed()
Check, if this handshaker has been destroyed.
|
protected void |
expectChangeCipherSpecMessage()
Marks this handshaker to expect the peer's CHANGE_CIPHER_SPEC message next.
|
protected void |
expectMessage(DTLSMessage message)
Check, if message is expected.
|
protected byte[] |
generateRandomSeed()
Generate random seed for master secret.
|
Random |
getClientRandom()
Get client random.
|
Connection |
getConnection()
Gets related connection.
|
Throwable |
getFailureCause()
Get cause of failure.
|
protected MessageDigest |
getHandshakeMessageDigest()
Get message digest for FINISH message.
|
InetSocketAddress |
getPeerAddress()
Gets the IP address and port of the peer this handshaker is used to
negotiate a session with.
|
ConnectionId |
getReadConnectionId()
Get read connection ID for inbound records
|
Random |
getServerRandom()
Get server random.
|
DTLSSession |
getSession()
Gets the session this handshaker is used to establish.
|
void |
handshakeAborted(Throwable cause)
Abort handshake.
|
void |
handshakeCompleted()
Forward handshake completed to registered listeners.
|
void |
handshakeFailed(Throwable cause)
Notifies all registered session listeners about a handshake failure.
|
void |
handshakeFlightRetransmitted(int flight)
Notifies all registered session listeners about a handshake
retransmit of a flight.
|
protected void |
handshakeStarted()
Forward handshake start to registered listeners.
|
boolean |
hasSessionEstablished()
Checks, if the session is established.
|
boolean |
isChangeCipherSpecMessageExpected()
Checks whether the peer's CHANGE_CIPHER_SPEC message is the next message
expected in the ongoing handshake.
|
boolean |
isDestroyed() |
boolean |
isExpired()
Test, if handshake is expired according nano realtime.
|
boolean |
isInboundMessageProcessed()
Check, if inbound messages are all processed.
|
boolean |
isProbing()
Test, if handshake was started in probing mode.
|
boolean |
isPskRequestPending()
Check, if psk request is pending.
|
boolean |
isRemovingConnection()
Check, if the connection must be removed.
|
void |
processAsyncHandshakeResult(HandshakeResult handshakeResult)
Process asynchronous handshake result.
|
void |
processAsyncPskSecretResult(PskSecretResult pskSecretResult)
Deprecated.
use
processAsyncHandshakeResult(HandshakeResult) instead. |
protected void |
processCertificateVerificationResult(CertificateVerificationResult certificateVerificationResult)
Process certificate verification result.
|
protected abstract void |
processCertificateVerified()
Do the handshaker specific processing of successful verified certificates
|
protected abstract void |
processMasterSecret(SecretKey masterSecret)
Do the handshaker specific master secret processing
|
void |
processMessage(Record record)
Processes a handshake record received from a peer based on the
handshake's current state.
|
protected void |
processPskSecretResult(PskSecretResult pskSecretResult)
Process PSK secret result.
|
protected GenericHandshakeMessage |
reassembleFragment(FragmentedHandshakeMessage fragment)
Process a received fragmented handshake message.
|
void |
removeSessionListener(SessionListener listener)
Removes a listener from the list of listeners to be notified
about session life cycle events.
|
protected PskSecretResult |
requestPskSecretResult(PskPublicInformation pskIdentity,
SecretKey otherSecret)
Request psk secret result for PSK cipher suites.
|
void |
resetProbing()
Reset probing mode, when data is received during.
|
void |
sendFlight(DTLSFlight flight)
Send flight.
|
void |
sendLastFlight(DTLSFlight flight)
Send last flight.
|
protected void |
sessionEstablished()
Forward session established to registered listeners.
|
protected void |
setCurrentReadState() |
protected void |
setCurrentWriteState() |
void |
setFailureCause(Throwable cause)
Set the failure cause.
|
void |
setGenerateClusterMacKeys(boolean enable)
Enable to generate keys for cluster MAC.
|
abstract void |
startHandshake()
Starts the handshake by sending the first flight to the peer.
|
List<org.eclipse.californium.elements.RawData> |
takeDeferredApplicationData()
Take deferred outgoing application data.
|
void |
takeDeferredApplicationData(Handshaker replacedHandshaker)
Take deferred outgoing application data from provided handshaker.
|
List<Record> |
takeDeferredRecords()
Take deferred incoming records.
|
void |
verifyCertificate(CertificateMessage message)
Start validating the X.509 certificate chain provided by the the peer as
part of this message, or the raw public key of the message.
|
protected void |
wrapMessage(DTLSFlight flight,
DTLSMessage fragment)
Wraps a DTLS message fragment into (potentially multiple) DTLS records
and add them to the flight.
|
protected final org.slf4j.Logger LOGGER
protected final boolean isClient
protected ProtocolVersion usedProtocol
protected Random clientRandom
protected Random serverRandom
protected SecretKey masterSecret
protected final DTLSSession session
protected final NewAdvancedCertificateVerifier certificateVerifier
protected final AdvancedPskStore advancedPskStore
protected final ConnectionIdGenerator connectionIdGenerator
null, not supported,
0 supported but not used.protected int flightNumber
protected Integer recordSizeLimit
null, if not used.protected final List<HandshakeMessage> handshakeMessages
protected ReassemblingHandshakeMessage reassembledMessage
protected final PrivateKey privateKey
protected final PublicKey publicKey
protected final List<X509Certificate> certificateChain
protected CertPath peerCertPath
protected boolean certificateVerfied
protected boolean sniEnabled
protected boolean useStateValidation
protected final boolean useKeyUsageVerification
protected final boolean useTruncatedCertificatePathForVerification
protected int statesIndex
protected HandshakeState[] states
protected Handshaker(boolean isClient,
int initialMessageSeq,
DTLSSession session,
RecordLayer recordLayer,
ScheduledExecutorService timer,
Connection connection,
DtlsConnectorConfig config)
isClient - indicates whether this handshaker plays the client or
server role.initialMessageSeq - the initial message sequence number to use and
expect in the exchange of handshake messages with the peer.
This parameter can be used to initialize the
message_seq and receive_next_seq counters to
a value larger than 0, e.g. if one or more cookie exchange
round-trips have been performed with the peer before the
handshake starts.session - the session this handshaker is negotiating.recordLayer - the object to use for sending flights to the peer.timer - scheduled executor for flight retransmission (since 2.4).connection - the connection related to this handshaker.config - the dtls configurationNullPointerException - if session, recordLayer, or config is
null.IllegalArgumentException - if the initial message sequence number
is negativepublic boolean isInboundMessageProcessed()
true, all inbound messages are processed, false,
some inbound messages are pending.public final void processMessage(Record record) throws HandshakeException
inboundMessageBuffer and
delegates processing of the ordered messages to the
doProcessMessage(HandshakeMessage) method. If
ChangeCipherSpecMessage is processed, the
deferredRecords are passed again to the RecordLayer to
get decrypted and processed.record - the handshake recordHandshakeException - if the record's plaintext fragment cannot be
parsed into a handshake message or cannot be processed
properlyIllegalArgumentException - if the record's epoch differs from the
session's read epochprotected void expectMessage(DTLSMessage message) throws HandshakeException
message - mesage to checkHandshakeException - if the message is not expecteduseStateValidation,
DtlsConnectorConfig.useHandshakeStateValidation()protected abstract void doProcessMessage(HandshakeMessage message) throws HandshakeException, GeneralSecurityException
message - the message received from the peerHandshakeException - if the record's plaintext fragment cannot be parsed into
a handshake message or cannot be processed properlyGeneralSecurityException - if the record's ciphertext fragment cannot be decryptedpublic abstract void startHandshake()
throws HandshakeException
The particular message to be sent depends on this peer's role in the handshake, i.e. if this end represents the client or server.
HandshakeException - if the message to start the handshake cannot be
created and sent using the session's current security parameters.public void processAsyncHandshakeResult(HandshakeResult handshakeResult) throws HandshakeException
doProcessMessage(HandshakeMessage)
implementations! If handshake expects the cipher change message, then
process the messages from the inbound buffer.handshakeResult - asynchronous handshake resultHandshakeException - if an error occursIllegalStateException - if pskRequestPending or
certificateVerificationPending is not pending, or
the handshaker isDestroyed().@Deprecated public void processAsyncPskSecretResult(PskSecretResult pskSecretResult) throws HandshakeException
processAsyncHandshakeResult(HandshakeResult) instead.doProcessMessage(HandshakeMessage)
implementations! If handshake expects the cipher change message, then
process the messages from the inbound buffer.pskSecretResult - PSK secret result.HandshakeException - if an error occursIllegalStateException - if pskRequestPending is not
pending, or the handshaker isDestroyed().protected void processPskSecretResult(PskSecretResult pskSecretResult) throws HandshakeException
pskSecretResult - PSK secret result.HandshakeException - if an error occursIllegalStateException - if pskRequestPending is not
pending, or the handshaker isDestroyed().protected abstract void processMasterSecret(SecretKey masterSecret) throws HandshakeException
masterSecret - master secretHandshakeException - if an error occursprotected void processCertificateVerificationResult(CertificateVerificationResult certificateVerificationResult) throws HandshakeException
certificateVerificationResult - certificate verification resultHandshakeException - if an error occurred during processingIllegalStateException - if certificateVerificationPending
is not pending, or the handshaker isDestroyed().protected abstract void processCertificateVerified()
throws HandshakeException
HandshakeException - if an error occursprotected final MessageDigest getHandshakeMessageDigest()
handshakeMessagesprotected void applyMasterSecret(SecretKey masterSecret)
masterSecret - the master secret.masterSecretprotected void calculateKeys(SecretKey masterSecret)
masterSecret - the master secret.protected byte[] generateRandomSeed()
protected PskSecretResult requestPskSecretResult(PskPublicInformation pskIdentity, SecretKey otherSecret)
pskRequestPending.pskIdentity - PSK identityotherSecret - others secret for ECHDE support. Maybe null.null, if result is returned
asynchronous.protected final void setCurrentReadState()
protected final void setCurrentWriteState()
protected final void wrapMessage(DTLSFlight flight, DTLSMessage fragment) throws HandshakeException
flight - the flight to add the wrapped messagesfragment - the message fragmentHandshakeException - if the message could not be encrypted using
the session's current security parametersprotected GenericHandshakeMessage reassembleFragment(FragmentedHandshakeMessage fragment) throws HandshakeException
fragment - the fragmented handshake message.null, otherwise.HandshakeException - if the reassembling failspublic final DTLSSession getSession()
public final InetSocketAddress getPeerAddress()
public final Connection getConnection()
public DTLSFlight createFlight()
getSession() and the current
flightNumber.public ConnectionId getReadConnectionId()
null, if connection ID
is not supported, a empty connection ID, if connection ID is
supported but not used for inbound records.public Random getClientRandom()
null, if not available.public Random getServerRandom()
null, if not available.public void addApplicationDataForDeferredProcessing(org.eclipse.californium.elements.RawData outgoingMessage)
outgoingMessage - outgoing application datapublic void addRecordsForDeferredProcessing(Record incomingMessage)
incomingMessage - incoming record.public List<org.eclipse.californium.elements.RawData> takeDeferredApplicationData()
public List<Record> takeDeferredRecords()
public void takeDeferredApplicationData(Handshaker replacedHandshaker)
replacedHandshaker - replaced handshaker to take deferred outgoing
application datapublic void completePendingFlight()
public void sendLastFlight(DTLSFlight flight)
flight - last flight to sendsendFlight(DTLSFlight)public void sendFlight(DTLSFlight flight)
flight - flight to sendsendFlight(DTLSFlight)public final void addSessionListener(SessionListener listener)
listener - The listener to add.public final void removeSessionListener(SessionListener listener)
listener - The listener to remove.protected final void handshakeStarted()
throws HandshakeException
HandshakeException - if thrown by listenerprotected final void sessionEstablished()
throws HandshakeException
amendPeerPrincipal().HandshakeException - if thrown by listenerpublic final void handshakeCompleted()
public final void handshakeFailed(Throwable cause)
setFailureCause(Throwable) was called before, only calls with
the same cause will notify the listeners. If
setFailureCause(Throwable) wasn't called before, sets the
cause property to the given cause.cause - The reason for the failure.isRemovingConnection(),
handshakeAborted(Throwable)public final void handshakeAborted(Throwable cause)
setFailureCause(Throwable) was called before, only calls with
the same cause will notify the listeners. If
setFailureCause(Throwable) wasn't called before, sets the
cause property to the given cause.cause - The reason for the abort.handshakeFailed(Throwable),
isRemovingConnection()public boolean hasSessionEstablished()
true, if the session is established, false,
otherwise.public boolean isProbing()
true, if handshake is in probing mode, false,
otherwise.ResumingClientHandshakerpublic void resetProbing()
ResumingClientHandshakerpublic boolean isExpired()
true, if handshake is expired, mainly during deep sleep,
false, if the handshake is still in time.public boolean isPskRequestPending()
true, if psk request is pending, false,
otherwise.public boolean isRemovingConnection()
handshakeFailed(Throwable)
was called, and the connection has no established session.true, remove the connection, false, keep it.public Throwable getFailureCause()
null, if the cause is unknown and not set beforesetFailureCause(Throwable),
handshakeFailed(Throwable)public void setFailureCause(Throwable cause)
handshakeFailed(Throwable) to
notify listener in that case.cause - failure causehandshakeFailed(Throwable),
getFailureCause()public void setGenerateClusterMacKeys(boolean enable)
enable - true, generate keys for cluster MAC, false,
otherwise.public final void handshakeFlightRetransmitted(int flight)
flight - number of retransmitted flight.public final boolean isChangeCipherSpecMessageExpected()
true if the message is expected next.protected final void expectChangeCipherSpecMessage()
public void verifyCertificate(CertificateMessage message) throws HandshakeException
NewAdvancedCertificateVerifier. If a asynchronous implementation
of NewAdvancedCertificateVerifier is used, the result will be not
available after this call, but will be available after the callback of the
asynchronous implementation.message - the certificate messageHandshakeException - if any of the checks failspublic void destroy()
throws DestroyFailedException
destroy in interface DestroyableDestroyFailedExceptionpublic boolean isDestroyed()
isDestroyed in interface Destroyableprotected void ensureUndestroyed()
IllegalStateException - if the handshake has been destroyed.Copyright © 2023 Eclipse Foundation. All rights reserved.