BoringSSL allows you to explicitly define the ordering of TLS extensions using the SSL_CTX_set_tls_extension_order function. This function is part of the BoringSSL API and lets you specify the desired order in which the TLS extensions should appear in the ClientHello message.
Here’s how you can define TLS extension ordering in BoringSSL:
Function to Set TLS Extension Order: SSL_CTX_set_tls_extension_order
ctx: A pointer to the SSL_CTX object associated with your SSL/TLS session.
ext_types: An array of uint16_t values specifying the desired order of TLS extensions. Each entry in this array corresponds to an extension type (e.g., TLSEXT_TYPE_signature_algorithms, TLSEXT_TYPE_supported_groups, etc.).
num_ext_types: The number of elements in the ext_types array.
Example Usage
Here's an example of how to define the order of TLS extensions:
c
#include <openssl/ssl.h>
void configure_tls_extension_order(SSL_CTX *ctx) {
// Define the desired order of TLS extensions by their type IDs.
// For example, 13 is the extension type for "signature_algorithms" and
// 10 is for "supported_groups". Adjust the array according to your needs.
uint16_t extension_order[] = {
TLSEXT_TYPE_signature_algorithms,
TLSEXT_TYPE_supported_groups,
TLSEXT_TYPE_key_share,
TLSEXT_TYPE_psk_key_exchange_modes
};
// Set the extension order on the SSL_CTX object.
SSL_CTX_set_tls_extension_order(ctx, extension_order,
sizeof(extension_order) / sizeof(extension_order[0]));
}
Notes:
Default Behavior: By default, BoringSSL will automatically choose the best ordering for the extensions to maximize interoperability and performance. You only need to set the order explicitly if you have specific reasons (e.g., compliance with a protocol spec or testing).
Custom Extensions: If you're using custom extensions, you can include their type IDs (as uint16_t) in the ext_types array to specify their placement relative to the standard ones.
Impact: This function only affects the order of extensions in the ClientHello message during the TLS handshake. It does not modify the extensions themselves or their behavior.
Compatibility: Ensure that the specified order is valid and compatible with the requirements of the server you're communicating with. Servers may expect certain extensions to appear in a specific order.
By using SSL_CTX_set_tls_extension_order, you can explicitly control the extension order to meet your application's requirements or to comply with specific testing scenarios.