public static final class TLS13PostHandshakeConfig.TLS13KeyUpdateConfig extends TLS13PostHandshakeConfig implements java.lang.Cloneable
KEY_UPDATE
.
At any time after having sent its Finished message a TLS 1.3 client
or server may send a KeyUpdate
post handshake message
to notify the peer that it is updating its write keys (see RFC 8446):
enum { update_not_requested(0), update_requested(1), (255) } KeyUpdateRequest; struct { KeyUpdateRequest request_update; } KeyUpdate;The
KeyUpdate
message itself is encrypted with the old keys.
When receiving a KeyUpdate
message the local TLS application has
to update its read keys. When the request_update
field of the received KeyUpdate
message is set to update_requested
the local application shall also
update its write keys and send back a KeyUpdate
message with
the request_update
field set to update_not_requested
.
Doing so both sides of the connection have updated their whole keying
material.
Per default iSaSiLk does not request any key update but follows key update requests received from the peer. This class allows to configure the key update behavior by specifying the following parameters:
responseDataLimit
parameter
specifies the amount of data that may be read until the peer has to respond
to a KeyUpdate message with a KeyUpdate message notifying that it has updated its
write keys (default: -1; accept that the peer may not send a key update message).
ignorePeerKeyUpdateRequests
parameter specifies whether to ignore write key update requests from the peer
(do ensure to only update write keys by locally triggering a key update).
(default: false
; write key update requests from the peer are not ignored)
requestPeerWriteKeyUpdate
parameter
specifies whether to request a write key update from the peer when sending a KeyUpdate
message (default: true
).
readPeerResponseImmediately
parameter specifies whether to try to read the peer KeyUpdate post handshake message
immediately after having sent the post handshake KeyUpdate message (default:
false
; the peer KeyUpdate message is not read before the
next read()
call).
requesting
a write key update from the peer.
updateWriteKeysImmediately
parameter specifies whether to update the write keys immediately after having received
a KeyUpdate request from the peer. By default iSaSiLk does not update the write keys
immediately after having received a KeyUpdate request, rather it waits with the write
key update until the next regular (data) write operation
checkKeyUpdateMessagesBasedOnAvailibility
parameter specifies whether to call available()
on the underlying stream before
trying to read a further message after a KeyUpdate message has been received.
postHandshake
has to be called on the SSLSocket/SSLTransport in use. When
calling postHandshake
to explicitly trigger a KeyUpdate care has to be
taken that the regular handshake has been already finished (and some data has
been exchanged) and a protocol version >=1.3 has been negotiated, e.g.:
SSLSocket sslSocket = ...; ... sslSocket.startHandshake(); ... // do some data reading/writing ... boolean triggerKeyUpdate = true; TLS13KeyUpdateConfig keyUpdateConfig = new TLS13KeyUpdateConfig(triggerKeyUpdate); sslSocket.postHandshake(keyUpdateConfig);When triggering key updates special care has to be taken because of interoperability and performance issues. Key updates may not performed too frequently. When triggering a key update by explicitly calling method
postHandshake
on the SSLSocket/SSLTransport object in use, and knowing that the peer will
immediately send back its KeyUpdate message the TLS13KeyUpdateConfig may be
directed to immediately try to read the KeyUpdate response from the peer.
TLS13PostHandshakeConfig.TLS13KeyUpdateConfig, TLS13PostHandshakeConfig.TLS13NewSessionTicketConfig, TLS13PostHandshakeConfig.TLS13PostHandshakeAuthConfig
KEY_UPDATE, NEW_SESSION_TICKET, POST_HANDSHAKE_AUTH
Constructor and Description |
---|
TLS13KeyUpdateConfig()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a clone of this TLS13KeyUpdateConfig.
|
void |
setCheckKeyUpdateMessagesBasedOnAvailibility(boolean checkAvailable)
Sets whether to call
available() on the underlying stream before
trying to read a further message after a KeyUpdate message has been received. |
void |
setIgnorePeerKeyUpdateRequests(boolean ignore)
Sets whether to ignore write key update requests from the peer.
|
void |
setReadPeerResponseImmediately(boolean read)
Sets whether to try to read the peer KeyUpdate post handshake message
immediately after having sent the post handshake KeyUpdate message.
|
void |
setRequestPeerWriteKeyUpdate(boolean requestUpdate)
Sets whether to request a write key update from the peer when
sending a KeyUpdate message.
|
void |
setResponseDataLimit(long responseDataLimit)
Sets the amount of data that may be read until the peer has
to respond to a KeyUpdate message with a KeyUpdate
message notifying that it has updated its write keys.
|
void |
setUpdateWriteKeysImmediately(boolean update)
Sets whether to update the write keys immediately after having received
a KeyUpdate request from the peer.
|
java.lang.String |
toString()
Gets a string representation of this configuration.
|
setMaxNumberOfPostHandshakeMessages, setMaxNumberOfSubsequentPostHandshakeMessages
public void setResponseDataLimit(long responseDataLimit)
Note that a short responseDataLimt
value may cause to abort the
connection before all data has been transmitted/received.
responseDataLimit
- the amount of data that may be read until
the peer has to respond to a KeyUpdate message with a KeyUpdate
message notifying that it has updated its write keys.
(Default: -1; no key update message from the peer may be sent)java.lang.IllegalArgumentException
- of no dataLimit has been setpublic void setIgnorePeerKeyUpdateRequests(boolean ignore)
When having configured a key update interval it may be considerable to
ignore any write key update requests from the peer (to limit the number
of key updates) by setting ignorePeerKeyUpdateRequests
to true
. In this case, when receiving a KeyUpdate
post handshake request message from the peer, the read keys will
updated as required but the write keys will not be updated until
the local update interval has beem exhausted.
ignore
- whether to ignore write key update requests from the
peer (do ensure to only update write keys in the
locally configured intervals).
(Default: false
; write key update requests
from the peer are not ignored)public void setRequestPeerWriteKeyUpdate(boolean requestUpdate)
true
(default) not only the local write keys
will be updated but also the peer will be requested to update its
write keys (and thus doing a full read/write key update). When set to
false
only the local write keys will
be updated and the peer will not be requested to update its write keys
(and thus only updating its read keys).requestUpdate
- whether to also request a write key update from
the peer or only cause the peer to update its
read keyspublic void setReadPeerResponseImmediately(boolean read)
requesting
a write key update from the peer.
When set to true
iSaSiLk tries to read
the peer KeyUpdate message (if requesting
a peer write key update) immediately after having sent the KeyUpdate message. Any
application data that the client sends in front of the the client authentication
messages is internally buffered to be pushed back after the peer key update messages
has arrived. However, this may cause an exception if too much application
data is sent to can be internally buffered. For that reason you may call
setReadPeerResponseImmediately(true);
only if you are sure that
the peer will send the key update message immediately (or at least reasonable)
soon after having received the key update request. Alternatively you may make
some explicitly read() call -- or span up some listener thread -- after having
triggered the post handshake KeyUpdate request to explicitly handle any blocking
condition or receiving of application data before receiving the KeyUpdate messages.
read
- true
if trying to read the peer KeyUpdate response
(if requested
)
immediately after having sent the KeyUpdate request,
false
if not trying to read the response (default)public void setUpdateWriteKeysImmediately(boolean update)
By default iSaSiLk does not immediately update the write keys if having received a KeyUpdate request from the peer. Since a write key update is only required when actually writing some data iSaSiLk by default waits with the write key update until (application) data is actually written.
update
- whether to update the write keys immediately after
having received a KeyUpdate request from the peer, false
(default) if waiting with the write key update until the next regular
(data) write operationpublic void setCheckKeyUpdateMessagesBasedOnAvailibility(boolean checkAvailable)
available()
on the underlying stream before
trying to read a further message after a KeyUpdate message has been received.
available()
may only work properly if the
SSLInputInputStream.available
mode is set to "decrypted".
By default iSaSiLk decides whether trying to read further messages after
a KeyUpdate based on the number of pending KeyUpdate requests, except when
SSLInputInputStream.available
mode is set to "decrypted".
In this case available()
is called on the underlying stream
before trying to read a further message.
With this method you can configure iSaSiLk to call available()
in any (or no) case, respectively.checkAvailable
- true
to call ir.messageAvailable();
before
trying to read a further message, false
if deciding
whether to read a further message based on the number of pending
key update requestspublic java.lang.Object clone()
clone
in class TLS13PostHandshakeConfig
public java.lang.String toString()
toString
in class java.lang.Object