Skip to content

Commit 0ebf371

Browse files
committed
Impl SSL_client_hello_get0_legacy_version
1 parent 78c2e58 commit 0ebf371

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/openssl/ssl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,15 @@ OPENSSL_EXPORT void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_
11721172
// SSL_client_hello_isv2 always returns zero as SSLv2 is not supported.
11731173
OPENSSL_EXPORT int SSL_client_hello_isv2(SSL *s);
11741174

1175+
1176+
// SSL_client_hello_get0_legacy_version provides the value of the
1177+
// "legacy_version" field in the client hello.
1178+
//
1179+
// This function can only be called from within a client hello callback (see
1180+
// |SSL_CTX_set_client_hello_cb|) or during server certificate selection (see
1181+
// |SSL_CTX_set_select_certificate_cb|).
1182+
OPENSSL_EXPORT unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
1183+
11751184
// SSL_client_hello_get0_ext searches the extensions in the ClientHello for an
11761185
// extension of the given type. If found, it sets |*out| to point to the
11771186
// extension contents (not including the type and length bytes) and |*outlen|

ssl/ssl_client_hello_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ int callback_SSL_client_hello_get1_extensions_present_impl(
369369
EXPECT_GT(extensions_len, 0u);
370370
EXPECT_NE(nullptr, extensions);
371371

372+
unsigned legacy_version = SSL_client_hello_get0_legacy_version(ssl);
373+
EXPECT_NE(legacy_version, 0u);
374+
372375
// Verify a few common extensions are present
373376
bool found_supported_groups = false;
374377
bool found_session_ticket = false;
@@ -482,6 +485,9 @@ TEST(SSLClientHelloTest, GetExtensionOrder) {
482485
return SSL_CLIENT_HELLO_ERROR;
483486
}
484487

488+
unsigned legacy_version = SSL_client_hello_get0_legacy_version(ssl);
489+
EXPECT_NE(legacy_version, 0u);
490+
485491
// Call with a buffer that is too small and confirm it fails.
486492
size_t too_small_num_extensions = num_extensions - 1;
487493
uint16_t* too_small_exts =

ssl/ssl_lib.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,6 +3167,20 @@ int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts, size_t *num_ext
31673167
return 1;
31683168
}
31693169

3170+
unsigned int SSL_client_hello_get0_legacy_version(SSL *s) {
3171+
GUARD_PTR(s);
3172+
GUARD_PTR(s->s3);
3173+
SSL_HANDSHAKE *hs = s->s3->hs.get();
3174+
GUARD_PTR(hs);
3175+
3176+
SSLMessage msg_unused;
3177+
SSL_CLIENT_HELLO client_hello;
3178+
if (!hs->GetClientHello(&msg_unused, &client_hello)) {
3179+
return 0;
3180+
}
3181+
return client_hello.version;
3182+
}
3183+
31703184
void SSL_CTX_set_keylog_callback(SSL_CTX *ctx,
31713185
void (*cb)(const SSL *ssl, const char *line)) {
31723186
ctx->keylog_callback = cb;

0 commit comments

Comments
 (0)