|
iPXE
|
TLS data formats. More...
#include <string.h>#include <errno.h>#include <byteswap.h>#include <ipxe/tls.h>#include <ipxe/tlsfmt.h>Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| static const char * | tls_map_name (const uint8_t *map) |
| Get data structure descriptor mapping name (for debugging). | |
| static int | tls_parse_extensions (const uint8_t *map, unsigned int index, struct tls_cursor *fields, unsigned int count) |
| Parse TLS extensions within a data structure. | |
| int | tls_parse_map (const uint8_t *map, unsigned int version, const struct tls_cursor *cursor, union tls_ptr_len *desc) |
| Parse TLS data structure. | |
| int | tls_parse_opt_map (const uint8_t *map, unsigned int version, const struct tls_cursor *cursor, union tls_ptr_len *desc) |
| Parse optional TLS data structure. | |
| static int | tls_build_extensions (const uint8_t *map, unsigned int index, struct tls_cursor *fields, unsigned int count) |
| Build TLS extensions within a data structure. | |
| int | tls_build_map (const uint8_t *map, unsigned int version, union tls_ptr_len *desc, struct tls_cursor *cursor) |
| Build TLS data structure. | |
| int | tls_size_map (const uint8_t *map, unsigned int version, union tls_ptr_len *desc, struct tls_cursor *cursor) |
| Calculate length of TLS data structure. | |
| TLS_DESCR_MAPPING (tls_certificate) | |
| Certificate descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_certificate_entry) | |
| CertificateEntry descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_client_hello) | |
| ClientHello descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_client_key_exchange_dhe) | |
| ClientKeyExchange descriptor mapping (for DHE). | |
| TLS_DESCR_MAPPING (tls_client_key_exchange_ecdhe) | |
| ClientKeyExchange descriptor mapping (for ECDHE). | |
| TLS_DESCR_MAPPING (tls_client_key_exchange_pubkey) | |
| ClientKeyExchange descriptor mapping (for key transport). | |
| TLS_DESCR_MAPPING (tls_digitally_signed) | |
| DigitallySigned descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_extension) | |
| Extension descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_hello_request) | |
| HelloRequest descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_key_share_client_hello) | |
| KeyShareClientHello descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_key_share_entry) | |
| KeyShareEntry descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_key_share_hello_retry_request) | |
| KeyShareHelloRetryRequest descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_key_share_server_hello) | |
| KeyShareServerHello descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_max_fragment_length) | |
| MaxFragmentLength descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_named_group_list) | |
| NamedGroupList descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_new_session_ticket) | |
| NewSessionTicket descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_psk_key_exchange_modes) | |
| PskKeyExchangeModes descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_renegotiation_info) | |
| RenegotiationInfo descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_server_hello) | |
| ServerHello descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_server_hello_done) | |
| ServerHello descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_server_key_exchange_dhe) | |
| ServerKeyExchange descriptor mapping (for DHE). | |
| TLS_DESCR_MAPPING (tls_server_key_exchange_ecdhe) | |
| ServerKeyExchange descriptor mapping (for ECDHE). | |
| TLS_DESCR_MAPPING (tls_server_name) | |
| ServerName descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_server_name_list) | |
| ServerNameList descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_signature_scheme_list) | |
| SignatureSchemeList descriptor mapping. | |
| TLS_DESCR_MAPPING (tls_supported_version) | |
| SupportedVersions descriptor mapping (in ServerHello). | |
| TLS_DESCR_MAPPING (tls_supported_versions) | |
| SupportedVersions descriptor mapping (in ClientHello). | |
TLS data formats.
Definition in file tlsfmt.c.
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
static |
Get data structure descriptor mapping name (for debugging).
| map | Data structure descriptor mapping |
| name | Data structure name |
Definition at line 45 of file tlsfmt.c.
References map.
Referenced by tls_build_extensions(), tls_build_map(), tls_parse_extensions(), tls_parse_map(), and tls_parse_opt_map().
|
static |
Parse TLS extensions within a data structure.
| map | Data structure descriptor mapping |
| index | Current index within mapping |
| fields | Extensions data fields |
| count | Number of extensions |
| rc | Return status code |
Definition at line 111 of file tlsfmt.c.
References __attribute__, count, data, tls_cursor::data, tls_extension::data, DBGC, DBGC2, DBGC2_HDA, EINVAL, EPROTO, index, len, tls_cursor::len, map, tls_extension::next, ntohs, rc, tls_map_name(), tls_parse, TLS_VERSION_BASE, tls_extension::type, and type.
Referenced by tls_parse_map().
| int tls_parse_map | ( | const uint8_t * | map, |
| unsigned int | version, | ||
| const struct tls_cursor * | cursor, | ||
| union tls_ptr_len * | desc ) |
Parse TLS data structure.
| map | Data structure descriptor mapping |
| version | Protocol version |
| cursor | Cursor containing TLS data structure |
| desc | Data structure descriptor to fill in |
| rc | Return status code |
Definition at line 172 of file tlsfmt.c.
References assert, container_of, count, data, tls_cursor::data, DBGC, DBGC2, DBGC2_HDA, DBGC_HDA, desc, EINVAL, EPROTO, fixed, index, len, tls_cursor::len, map, memset(), next, rc, TLS_MAP_EXTENSIONS, TLS_MAP_FIXED, TLS_MAP_LEN_LEN, TLS_MAP_MIN, tls_map_name(), tls_parse_extensions(), TLS_VERSION_TLS_1_3, and version.
Referenced by tls_parse_opt_map().
| int tls_parse_opt_map | ( | const uint8_t * | map, |
| unsigned int | version, | ||
| const struct tls_cursor * | cursor, | ||
| union tls_ptr_len * | desc ) |
Parse optional TLS data structure.
| map | Data structure descriptor mapping |
| version | Protocol version |
| cursor | Cursor containing TLS data structure |
| desc | Data structure descriptor to fill in |
| rc | Return status code |
Definition at line 343 of file tlsfmt.c.
References count, tls_cursor::data, DBGC, desc, EINVAL, map, memset(), rc, tls_map_name(), tls_parse_map(), and version.
Referenced by tls_new_server_hello().
|
static |
Build TLS extensions within a data structure.
| map | Data structure descriptor mapping |
| index | Current index within mapping |
| fields | Extensions data fields |
| count | Number of extensions |
| rc | Return status code |
Definition at line 380 of file tlsfmt.c.
References __attribute__, count, data, tls_cursor::data, tls_extension::data, DBGC, DBGC2, DBGC2_HDA, EINVAL, index, len, tls_cursor::len, map, tls_extension::next, ntohs, rc, tls_build, tls_map_name(), TLS_VERSION_BASE, tls_extension::type, and type.
Referenced by tls_build_map().
| int tls_build_map | ( | const uint8_t * | map, |
| unsigned int | version, | ||
| union tls_ptr_len * | desc, | ||
| struct tls_cursor * | cursor ) |
Build TLS data structure.
| map | Data structure descriptor mapping |
| version | Protocol version |
| desc | Data structure descriptor |
| cursor | Cursor to contain TLS data structure |
| rc | Return status code |
Build a TLS data structure at the cursor. The cursor's original length will be ignored and will be set to the overall length of the built data structure. The caller must ensure that sufficient space already exists (e.g. by calling tls_size() first to determine the required length).
The overall length will be calculated based on the variable lengths within the descriptor. The output content will be be copied from any non-NULL pointers within the descriptor (with any missing content initialised to zero).
Pointers within the descriptor will be updated to point to the appropriate location within the built data structure.
The caller must therefore fill in any variable lengths within the descriptor beforehand, but may freely choose to either fill in pointers within the descriptor beforehand or to write through the updated pointers afterwards.
A cursor with a NULL data pointer may be used to calculate the required length without copying in any data or updating any pointers within the descriptor.
Definition at line 468 of file tlsfmt.c.
References assert, container_of, count, data, tls_cursor::data, DBGC, DBGC2, DBGC2_HDA, desc, EINVAL, ERANGE, fixed, index, len, tls_cursor::len, map, max, memcpy(), memset(), next, NULL, rc, tls_build_extensions(), TLS_MAP_EXTENSIONS, TLS_MAP_FIXED, TLS_MAP_LEN_LEN, TLS_MAP_LEN_LEN_MAX, TLS_MAP_MIN, tls_map_name(), TLS_VERSION_TLS_1_3, and version.
Referenced by tls_send_client_key_exchange(), and tls_size_map().
| int tls_size_map | ( | const uint8_t * | map, |
| unsigned int | version, | ||
| union tls_ptr_len * | desc, | ||
| struct tls_cursor * | cursor ) |
Calculate length of TLS data structure.
| type | Descriptor structure name |
| version | Protocol version |
| desc | Data structure descriptor to fill in |
| cursor | Cursor to contain TLS data structure |
| rc | Return status code |
The cursor size will be set to the overall length required to contain the TLS data structure, and the cursor data pointer will be set to NULL.
If this function returns successfully, then a subsequent call to tls_build() with the exact same inputs is guaranteed to succeed and need not be checked for an error return status. The data structure descriptor must not be modified in any way that would affect its length before calling tls_build(): the easiest way to ensure this is to not modify the data structure descriptor at all.
If this function fails, then the cursor length will be set to a value that is too large to be represented by a 24-bit length field. If the cursor itself lies within a containing data structure descriptor (e.g. if tls_size() is being used to calculate the size of an extension within a ClientHello descriptor), then this guarantees that a subsequent call to tls_size() on the containing descriptor will also fail. The caller therefore need only check the return status code from the call to tls_size() for the outermost descriptor.
Note that this optimisation applies only when the result cursor lies within a containing data structure descriptor and so is guaranteed to be consumed by a subsequent call to calculate the length of that containing TLS data structure. If a caller is using the result from tls_size() in any other way (e.g. to add up the lengths of a sequence of CertificateEntry structures), then the caller must check the return status code in the normal way.
Definition at line 658 of file tlsfmt.c.
References tls_cursor::data, desc, tls_cursor::len, map, NULL, rc, tls_build_map(), and version.
Referenced by tls_send_client_key_exchange().
| TLS_DESCR_MAPPING | ( | tls_certificate | ) |
Certificate descriptor mapping.
References TLS_MAPSZ, TLS_VAR08, TLS_VAR24, TLS_VERSION_BASE, and TLS_VERSION_TLS_1_3.
| TLS_DESCR_MAPPING | ( | tls_certificate_entry | ) |
CertificateEntry descriptor mapping.
References ext, next, TLS_EXT16, TLS_EXTRA, TLS_MAPSZ, TLS_VAR24, TLS_VERSION_BASE, and TLS_VERSION_TLS_1_3.
| TLS_DESCR_MAPPING | ( | tls_client_hello | ) |
ClientHello descriptor mapping.
References ext, TLS_COOKIE, TLS_EXT16, TLS_EXTENDED_MASTER_SECRET, TLS_EXTND, TLS_FIXED, TLS_KEY_SHARE, TLS_MAPSZ, TLS_MAX_FRAGMENT_LENGTH, TLS_NAMED_GROUP, TLS_PSK_MODES, TLS_RECORD_SIZE_LIMIT, TLS_RENEGOTIATION_INFO, TLS_SERVER_NAME, TLS_SESSION_TICKET, TLS_SIGNATURE_ALGORITHMS, TLS_SUPPORTED_VERSIONS, TLS_VAR08, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_client_key_exchange_dhe | ) |
ClientKeyExchange descriptor mapping (for DHE).
References TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_client_key_exchange_ecdhe | ) |
ClientKeyExchange descriptor mapping (for ECDHE).
References TLS_MAPSZ, TLS_VAR08, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_client_key_exchange_pubkey | ) |
ClientKeyExchange descriptor mapping (for key transport).
References TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_digitally_signed | ) |
DigitallySigned descriptor mapping.
References sig, TLS_FIXED, TLS_MAPSZ, TLS_VAR16, TLS_VERSION_BASE, and TLS_VERSION_TLS_1_2.
| TLS_DESCR_MAPPING | ( | tls_extension | ) |
| TLS_DESCR_MAPPING | ( | tls_hello_request | ) |
HelloRequest descriptor mapping.
References TLS_MAPSZ.
| TLS_DESCR_MAPPING | ( | tls_key_share_client_hello | ) |
KeyShareClientHello descriptor mapping.
References TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_key_share_entry | ) |
| TLS_DESCR_MAPPING | ( | tls_key_share_hello_retry_request | ) |
KeyShareHelloRetryRequest descriptor mapping.
References group, TLS_FIXED, TLS_MAPSZ, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_key_share_server_hello | ) |
KeyShareServerHello descriptor mapping.
References group, TLS_FIXED, TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_max_fragment_length | ) |
MaxFragmentLength descriptor mapping.
References max, TLS_FIXED, TLS_MAPSZ, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_named_group_list | ) |
NamedGroupList descriptor mapping.
References TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_new_session_ticket | ) |
| TLS_DESCR_MAPPING | ( | tls_psk_key_exchange_modes | ) |
PskKeyExchangeModes descriptor mapping.
References TLS_MAPSZ, TLS_VAR08, and TLS_VERSION_TLS_1_3.
| TLS_DESCR_MAPPING | ( | tls_renegotiation_info | ) |
RenegotiationInfo descriptor mapping.
References TLS_MAPSZ, TLS_VAR08, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_server_hello | ) |
ServerHello descriptor mapping.
References ext, TLS_COOKIE, TLS_EXT16, TLS_EXTENDED_MASTER_SECRET, TLS_EXTND, TLS_FIXED, TLS_KEY_SHARE, TLS_MAPSZ, TLS_RENEGOTIATION_INFO, TLS_SUPPORTED_VERSIONS, TLS_VAR08, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_server_hello_done | ) |
ServerHello descriptor mapping.
References TLS_MAPSZ.
| TLS_DESCR_MAPPING | ( | tls_server_key_exchange_dhe | ) |
ServerKeyExchange descriptor mapping (for DHE).
References TLS_EXTRA, TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_server_key_exchange_ecdhe | ) |
ServerKeyExchange descriptor mapping (for ECDHE).
References TLS_EXTRA, TLS_FIXED, TLS_MAPSZ, TLS_VAR08, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_server_name | ) |
| TLS_DESCR_MAPPING | ( | tls_server_name_list | ) |
ServerNameList descriptor mapping.
References TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_signature_scheme_list | ) |
SignatureSchemeList descriptor mapping.
References TLS_MAPSZ, TLS_VAR16, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_supported_version | ) |
SupportedVersions descriptor mapping (in ServerHello).
References TLS_FIXED, TLS_MAPSZ, and TLS_VERSION_BASE.
| TLS_DESCR_MAPPING | ( | tls_supported_versions | ) |
SupportedVersions descriptor mapping (in ClientHello).
References TLS_MAPSZ, TLS_VAR08, and TLS_VERSION_BASE.