Merge remote-tracking branch 'origin/development' into development-restricted
* origin/development: (51 commits) Fix possibly-lossy conversion warning from MSVC Reintroduce length 0 check for records Don't use memcpy() for 2-byte copy operation Remove integer parsing macro Fix alignment in record header parsing routine Don't disallow 'record from another epoch' log msg in proxy ref test Make sure 'record from another epoch' is displayed for next epoch Implement record checking API Mark ssl_parse_record_header() as `const` in SSL context Make mbedtls_ssl_in_hdr_len() CID-unaware Remove duplicate setting of ssl->in_msgtype and ssl->in_msglen Move update of in_xxx fields in ssl_get_next_record() Move update of in_xxx fields outside of ssl_prepare_record_content() Reduce dependency of ssl_prepare_record_content() on in_xxx fields Move ssl_update_in_pointers() to after record hdr parsing Mark DTLS replay check as `const` on the SSL context Move updating the internal rec ptrs to outside of rec hdr parsing Mark ssl_decrypt_buf() as `const in the input SSL context Adapt ssl_prepare_record_content() to use SSL record structure Use record length from record structure when fetching content in TLS ...
This commit is contained in:
commit
833899ee37
9 changed files with 791 additions and 258 deletions
|
@ -1350,6 +1350,20 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_RECORD_CHECKING
|
||||
*
|
||||
* Enable the function mbedtls_ssl_check_record() which can be used to check
|
||||
* the validity and authenticity of an incoming record, to verify that it has
|
||||
* not been seen before. These checks are performed without modifying the
|
||||
* externally visible state of the SSL context.
|
||||
*
|
||||
* See mbedtls_ssl_check_record() for more information.
|
||||
*
|
||||
* Uncomment to enable support for record checking.
|
||||
*/
|
||||
#define MBEDTLS_SSL_RECORD_CHECKING
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_DTLS_CONNECTION_ID
|
||||
*
|
||||
|
|
|
@ -1756,6 +1756,56 @@ void mbedtls_ssl_set_verify( mbedtls_ssl_context *ssl,
|
|||
*/
|
||||
void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
|
||||
|
||||
#if defined(MBEDTLS_SSL_RECORD_CHECKING)
|
||||
/**
|
||||
* \brief Check whether a buffer contains a valid and authentic record
|
||||
* that has not been seen before. (DTLS only).
|
||||
*
|
||||
* This function does not change the user-visible state
|
||||
* of the SSL context. Its sole purpose is to provide
|
||||
* an indication of the legitimacy of an incoming record.
|
||||
*
|
||||
* This can be useful e.g. in distributed server environments
|
||||
* using the DTLS Connection ID feature, in which connections
|
||||
* might need to be passed between service instances on a change
|
||||
* of peer address, but where such disruptive operations should
|
||||
* only happen after the validity of incoming records has been
|
||||
* confirmed.
|
||||
*
|
||||
* \param ssl The SSL context to use.
|
||||
* \param buf The address of the buffer holding the record to be checked.
|
||||
* This must be a read/write buffer of length \p buflen Bytes.
|
||||
* \param buflen The length of \p buf in Bytes.
|
||||
*
|
||||
* \note This routine only checks whether the provided buffer begins
|
||||
* with a valid and authentic record that has not been seen
|
||||
* before, but does not check potential data following the
|
||||
* initial record. In particular, it is possible to pass DTLS
|
||||
* datagrams containing multiple records, in which case only
|
||||
* the first record is checked.
|
||||
*
|
||||
* \note This function modifies the input buffer \p buf. If you need
|
||||
* to preserve the original record, you have to maintain a copy.
|
||||
*
|
||||
* \return \c 0 if the record is valid and authentic and has not been
|
||||
* seen before.
|
||||
* \return MBEDTLS_ERR_SSL_INVALID_MAC if the check completed
|
||||
* successfully but the record was found to be not authentic.
|
||||
* \return MBEDTLS_ERR_SSL_INVALID_RECORD if the check completed
|
||||
* successfully but the record was found to be invalid for
|
||||
* a reason different from authenticity checking.
|
||||
* \return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD if the check completed
|
||||
* successfully but the record was found to be unexpected
|
||||
* in the state of the SSL context, including replayed records.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
* In this case, the SSL context becomes unusable and needs
|
||||
* to be freed or reset before reuse.
|
||||
*/
|
||||
int mbedtls_ssl_check_record( mbedtls_ssl_context const *ssl,
|
||||
unsigned char *buf,
|
||||
size_t buflen );
|
||||
#endif /* MBEDTLS_SSL_RECORD_CHECKING */
|
||||
|
||||
/**
|
||||
* \brief Set the timer callbacks (Mandatory for DTLS.)
|
||||
*
|
||||
|
|
|
@ -672,18 +672,29 @@ struct mbedtls_ssl_transform
|
|||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t ctr[8]; /* Record sequence number */
|
||||
uint8_t type; /* Record type */
|
||||
uint8_t ver[2]; /* SSL/TLS version */
|
||||
uint8_t ctr[8]; /* In TLS: The implicit record sequence number.
|
||||
* In DTLS: The 2-byte epoch followed by
|
||||
* the 6-byte sequence number.
|
||||
* This is stored as a raw big endian byte array
|
||||
* as opposed to a uint64_t because we rarely
|
||||
* need to perform arithmetic on this, but do
|
||||
* need it as a Byte array for the purpose of
|
||||
* MAC computations. */
|
||||
uint8_t type; /* The record content type. */
|
||||
uint8_t ver[2]; /* SSL/TLS version as present on the wire.
|
||||
* Convert to internal presentation of versions
|
||||
* using mbedtls_ssl_read_version() and
|
||||
* mbedtls_ssl_write_version().
|
||||
* Keep wire-format for MAC computations. */
|
||||
|
||||
unsigned char *buf; /* Memory buffer enclosing the record content */
|
||||
size_t buf_len; /* Buffer length */
|
||||
size_t data_offset; /* Offset of record content */
|
||||
size_t data_len; /* Length of record content */
|
||||
unsigned char *buf; /* Memory buffer enclosing the record content */
|
||||
size_t buf_len; /* Buffer length */
|
||||
size_t data_offset; /* Offset of record content */
|
||||
size_t data_len; /* Length of record content */
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
uint8_t cid_len; /* Length of the CID (0 if not present) */
|
||||
unsigned char cid[ MBEDTLS_SSL_CID_LEN_MAX ]; /* The CID */
|
||||
uint8_t cid_len; /* Length of the CID (0 if not present) */
|
||||
unsigned char cid[ MBEDTLS_SSL_CID_LEN_MAX ]; /* The CID */
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
} mbedtls_record;
|
||||
|
||||
|
@ -930,7 +941,20 @@ void mbedtls_ssl_read_version( int *major, int *minor, int transport,
|
|||
|
||||
static inline size_t mbedtls_ssl_in_hdr_len( const mbedtls_ssl_context *ssl )
|
||||
{
|
||||
return( (size_t) ( ssl->in_iv - ssl->in_hdr ) );
|
||||
#if !defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
((void) ssl);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
return( 13 );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
{
|
||||
return( 5 );
|
||||
}
|
||||
}
|
||||
|
||||
static inline size_t mbedtls_ssl_out_hdr_len( const mbedtls_ssl_context *ssl )
|
||||
|
@ -958,7 +982,7 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl );
|
|||
|
||||
/* Visible for testing purposes only */
|
||||
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
|
||||
int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl );
|
||||
int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context const *ssl );
|
||||
void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
|
||||
#endif
|
||||
|
||||
|
@ -1013,7 +1037,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
|||
mbedtls_record *rec,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context *ssl,
|
||||
int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||
mbedtls_ssl_transform *transform,
|
||||
mbedtls_record *rec );
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue