diff options
author | Matt Caswell <matt@openssl.org> | 2017-05-04 11:28:08 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2017-05-04 16:02:08 +0100 |
commit | 16afd71c1dbafad398fc0c40e90b06acccca29de (patch) | |
tree | adf10be24de76aca35bbe40cda15c5f5f6a41e12 /test | |
parent | bade29da33155afc87ed5806c996efea7684666c (diff) |
Add a test for loading serverinfo data from memory
The previous commit fixed a bug which occurs when serverinfo is loaded
from memory (not from a file). This adds a test for loading serverinfo
from memory.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3382)
Diffstat (limited to 'test')
-rw-r--r-- | test/sslapitest.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/sslapitest.c b/test/sslapitest.c index c43adba159..bfa3a308c7 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -53,6 +53,21 @@ struct sslapitest_log_counts { unsigned int server_application_secret_count; }; + +static unsigned char serverinfov1[] = { + 0xff, 0xff, /* Dummy extension type */ + 0x00, 0x01, /* Extension length is 1 byte */ + 0xff /* Dummy extension data */ +}; + +static unsigned char serverinfov2[] = { + 0x00, 0x00, 0x00, + (unsigned char)(SSL_EXT_CLIENT_HELLO & 0xff), /* Dummy context - 4 bytes */ + 0xff, 0xff, /* Dummy extension type */ + 0x00, 0x01, /* Extension length is 1 byte */ + 0xff /* Dummy extension data */ +}; + static void client_keylog_callback(const SSL *ssl, const char *line) { int line_length = strlen(line); @@ -2043,6 +2058,63 @@ end: return testresult; } +/* + * Test loading of serverinfo data in various formats. test_sslmessages actually + * tests to make sure the extensions appear in the handshake + */ +static int test_serverinfo(int tst) +{ + unsigned int version; + unsigned char *sibuf; + size_t sibuflen; + int ret, expected, testresult = 0; + SSL_CTX *ctx; + + ctx = SSL_CTX_new(TLS_method()); + if (!TEST_ptr(ctx)) + goto end; + + if ((tst & 0x01) == 0x01) + version = SSL_SERVERINFOV2; + else + version = SSL_SERVERINFOV1; + + if ((tst & 0x02) == 0x02) { + sibuf = serverinfov2; + sibuflen = sizeof(serverinfov2); + expected = (version == SSL_SERVERINFOV2); + } else { + sibuf = serverinfov1; + sibuflen = sizeof(serverinfov1); + expected = (version == SSL_SERVERINFOV1); + } + + if ((tst & 0x04) == 0x04) { + ret = SSL_CTX_use_serverinfo_ex(ctx, version, sibuf, sibuflen); + } else { + ret = SSL_CTX_use_serverinfo(ctx, sibuf, sibuflen); + + /* + * The version variable is irrelevant in this case - it's what is in the + * buffer that matters + */ + if ((tst & 0x02) == 0x02) + expected = 0; + else + expected = 1; + } + + if (!TEST_true(ret == expected)) + goto end; + + testresult = 1; + + end: + SSL_CTX_free(ctx); + + return testresult; +} + int test_main(int argc, char *argv[]) { int testresult = 1; @@ -2093,6 +2165,7 @@ int test_main(int argc, char *argv[]) #else ADD_ALL_TESTS(test_custom_exts, 2); #endif + ADD_ALL_TESTS(test_serverinfo, 8); testresult = run_tests(argv[0]); |