public class Record extends Object
The Datagram Transport Layer Security specification defines a set of data structures at the Record layer containing the data to be exchanged with peers.
This class is used to transform these data structures from their binary encoding as received from the network interface to their object representation and vice versa.
| Modifier and Type | Field and Description |
|---|---|
static int |
CID_LENGTH_BITS |
static int |
CONTENT_TYPE_BITS |
static int |
EPOCH_BITS |
static int |
LENGTH_BITS |
static int |
RECORD_HEADER_BITS |
static int |
RECORD_HEADER_BYTES
Bytes for dtls record header.
|
static int |
SEQUENCE_NUMBER_BITS |
static int |
VERSION_BITS |
| Constructor and Description |
|---|
Record(ContentType type,
int epoch,
long sequenceNumber,
DTLSMessage fragment,
DTLSSession session,
boolean cid,
int pad)
Creates an outbound record containing a
DTLSMessage as its
payload. |
Record(ContentType type,
ProtocolVersion version,
long sequenceNumber,
DTLSMessage fragment,
InetSocketAddress peerAddress)
Creates an outbound record representing a
DTLSMessage as its payload. |
| Modifier and Type | Method and Description |
|---|---|
void |
applySession(DTLSSession session)
Apply session for incoming records and decrypt fragment.
|
static List<Record> |
fromByteArray(byte[] byteArray,
InetSocketAddress peerAddress,
ConnectionIdGenerator cidGenerator,
long receiveNanos)
Deprecated.
|
static List<Record> |
fromReader(org.eclipse.californium.elements.util.DatagramReader reader,
InetSocketAddress peerAddress,
InetSocketAddress router,
ConnectionIdGenerator cidGenerator,
long receiveNanos)
Parses a sequence of DTLSCiphertext structures into
Record instances. |
protected byte[] |
generateAdditionalData(int length)
See RFC 5246:
|
protected byte[] |
generateExplicitNonce()
Generates the explicit part of the nonce to be used with the AEAD Cipher.
|
ConnectionId |
getConnectionId()
Get connection id.
|
int |
getEpoch() |
DTLSMessage |
getFragment()
Gets the object representation of this record's
DTLSPlaintext.fragment.
|
byte[] |
getFragmentBytes()
Get fragment payload as byte array.
|
int |
getFragmentLength()
Gets the length of the fragment contained in this record in bytes.
|
InetSocketAddress |
getPeerAddress()
Get peer address.
|
long |
getReceiveNanos()
Get uptime nanoseconds receiving this record.
|
InetSocketAddress |
getRouter()
Get router address.
|
long |
getSequenceNumber() |
ContentType |
getType() |
ProtocolVersion |
getVersion() |
boolean |
isDecoded()
Check, if record is decoded.
|
boolean |
isFollowUpRecord()
Get follow-up-record marker for received record.
|
boolean |
isNewClientHello()
Check, if record is CLIENT_HELLO of epoch 0.
|
static ConnectionId |
readConnectionIdFromReader(org.eclipse.californium.elements.util.DatagramReader reader,
ConnectionIdGenerator cidGenerator)
Read the connection id.
|
int |
size() |
byte[] |
toByteArray()
Encodes this record into its corresponding DTLSCiphertext structure.
|
String |
toString() |
public static final int CONTENT_TYPE_BITS
public static final int VERSION_BITS
public static final int EPOCH_BITS
public static final int SEQUENCE_NUMBER_BITS
public static final int LENGTH_BITS
public static final int CID_LENGTH_BITS
public static final int RECORD_HEADER_BITS
public static final int RECORD_HEADER_BYTES
public Record(ContentType type, int epoch, long sequenceNumber, DTLSMessage fragment, DTLSSession session, boolean cid, int pad) throws GeneralSecurityException
DTLSMessage as its
payload.
The given fragment is encoded into its binary representation and
encrypted according to the given session's current write state. In order
to create a Record containing an un-encrypted fragment, use
the Record(ContentType, ProtocolVersion, long, DTLSMessage, InetSocketAddress)
constructor.type - the type of the record's payload. The new record type
ContentType.TLS12_CID is not supported directly.
Provide the inner type and true for the parameter cidepoch - the epochsequenceNumber - the 48-bit sequence numberfragment - the payloadsession - the session to determine the current write state fromcid - if true use write connection id from provided session.
Otherwise use null as connection idpad - if cid is enabled, pad could be used to add that number of
zero-bytes as padding to the payload to obfuscate the payload
length.IllegalArgumentException - if the given sequence number is longer
than 48 bits or less than 0, the given epoch is less than 0,
the provided type is not supported or the fragment could not
be converted into bytes. Or the provided session doesn't have
a peer address.NullPointerException - if the given type, fragment or session is
null.GeneralSecurityException - if the message could not be encrypted,
e.g. because the JVM does not support the negotiated cipher
suite's cipher algorithmpublic Record(ContentType type, ProtocolVersion version, long sequenceNumber, DTLSMessage fragment, InetSocketAddress peerAddress)
DTLSMessage as its payload.
The payload will be sent un-encrypted using epoch 0.type - the type of the record's payload. The new record type
ContentType.TLS12_CID is not supported.version - the versionsequenceNumber - the 48-bit sequence numberfragment - the payload to sendpeerAddress - the IP address and port of the peer this record should
be sent toIllegalArgumentException - if the given sequence number is longer
than 48 bits or less than 0, the given epoch is less than
0, or the fragment could not be converted into bytes.NullPointerException - if the given type, fragment or peer address
is null.public byte[] toByteArray()
public int size()
@Deprecated public static List<Record> fromByteArray(byte[] byteArray, InetSocketAddress peerAddress, ConnectionIdGenerator cidGenerator, long receiveNanos)
fromReader(DatagramReader, InetSocketAddress, InetSocketAddress, ConnectionIdGenerator, long) instead.Record instances.
The binary representation is expected to comply with the DTLSCiphertext structure
defined in RFC6347, Section 4.3.1.byteArray - the raw binary representation containing one or more DTLSCiphertext structurespeerAddress - the IP address and port of the peer from which the bytes have been
receivedcidGenerator - the connection id generator. May be null.receiveNanos - uptime nanoseconds of receiving this recordRecord instancesNullPointerException - if either one of the byte array or peer address is nullpublic static List<Record> fromReader(org.eclipse.californium.elements.util.DatagramReader reader, InetSocketAddress peerAddress, InetSocketAddress router, ConnectionIdGenerator cidGenerator, long receiveNanos)
Record instances.
The binary representation is expected to comply with the DTLSCiphertext structure
defined in RFC6347, Section 4.3.1.reader - a reader with the raw binary representation containing one or more DTLSCiphertext structurespeerAddress - the IP address and port of the peer from which the bytes have been
receivedrouter - router address, null, if not used.cidGenerator - the connection id generator. May be null.receiveNanos - uptime nanoseconds of receiving this recordRecord instancesNullPointerException - if either one of the reader or peer address is nullpublic static ConnectionId readConnectionIdFromReader(org.eclipse.californium.elements.util.DatagramReader reader, ConnectionIdGenerator cidGenerator)
reader - reader with the raw received record.cidGenerator - cid generator.null, if not available.NullPointerException - if either reader or cid generator is
null.IllegalArgumentException - if the cid generator doesn't use cid or
the record is too short.protected byte[] generateExplicitNonce()
protected byte[] generateAdditionalData(int length)
additional_data = seq_num + TLSCompressed.type +
TLSCompressed.version + TLSCompressed.length;
where "+" denotes concatenation.
For the new tls_cid record, currently defined in
Draft dtls-connection-id
this is extended by the conneciton id:
additional_data = seq_num + TLSCompressed.type + TLSCompressed.version +
connection_id + connection_id_length + TLSCompressed.length;
with the connection_id_length encoded in one uint8 byte.length - length of the data to be authenticatedpublic boolean isFollowUpRecord()
true, if record follows up an other record in the same
datagram, false, otherwise.public boolean isNewClientHello()
true, if record contains CLIENT_HELLO of epoch 0,
false otherwise.public boolean isDecoded()
true, if records is decode, false, otherwise.public ContentType getType()
public ProtocolVersion getVersion()
public int getEpoch()
public long getSequenceNumber()
public int getFragmentLength()
The overall length of this record's DTLSCiphertext
representation is thus Record.length + 13 (DTLS record headers)
bytes.
public void applySession(DTLSSession session) throws GeneralSecurityException, HandshakeException
session - session to apply. If null is provided,
DTLSConnectionState.NULL is used for de-cryption.GeneralSecurityException - if de-cryption fails, e.g. because the
JVM does not support the negotiated cipher algorithm, or
decoding of the inner plain text of
ContentType.TLS12_CID fails.HandshakeException - if the TLSPlaintext.fragment could not be
parsed into a valid handshake messageIllegalArgumentException - if session was already applied.public InetSocketAddress getPeerAddress()
public InetSocketAddress getRouter()
null, if no router is used.public ConnectionId getConnectionId()
public long getReceiveNanos()
0, if records wasn't received.public byte[] getFragmentBytes()
public DTLSMessage getFragment()
applySession(DTLSSession).IllegalStateException - if plaint-text fragment is not availableCopyright © 2023 Eclipse Foundation. All rights reserved.