diff options
author | 2015-02-07 04:20:23 +0000 | |
---|---|---|
committer | 2015-02-07 04:20:23 +0000 | |
commit | 8a66d6443ab6acac16716cb353ab2ce2943396a1 (patch) | |
tree | 1bca3ac03907af1dcd717b323b997e62a2bb80ab | |
parent | Provide a SSL_CIPHER_get_by_value() function that allows a cipher to be (diff) | |
download | wireguard-openbsd-8a66d6443ab6acac16716cb353ab2ce2943396a1.tar.xz wireguard-openbsd-8a66d6443ab6acac16716cb353ab2ce2943396a1.zip |
Add regress tests for SSL_CIPHER_get_by_value() and SSL_CIPHER_get_by_id().
-rw-r--r-- | regress/lib/libssl/ciphers/cipherstest.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/regress/lib/libssl/ciphers/cipherstest.c b/regress/lib/libssl/ciphers/cipherstest.c index f9c4cdc7c11..b20ec8bd528 100644 --- a/regress/lib/libssl/ciphers/cipherstest.c +++ b/regress/lib/libssl/ciphers/cipherstest.c @@ -110,10 +110,70 @@ cipher_get_put_tests(void) return failed; } +static int +cipher_get_by_value_tests(void) +{ + STACK_OF(SSL_CIPHER) *ciphers; + const SSL_CIPHER *cipher; + SSL_CTX *ssl_ctx = NULL; + SSL *ssl = NULL; + unsigned long id; + uint16_t value; + int ret = 1; + int i; + + if ((ssl_ctx = SSL_CTX_new(SSLv23_method())) == NULL) { + fprintf(stderr, "SSL_CTX_new() returned NULL\n"); + goto failure; + } + if ((ssl = SSL_new(ssl_ctx)) == NULL) { + fprintf(stderr, "SSL_new() returned NULL\n"); + goto failure; + } + + if ((ciphers = SSL_get_ciphers(ssl)) == NULL) { + fprintf(stderr, "no ciphers\n"); + goto failure; + } + + for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { + cipher = sk_SSL_CIPHER_value(ciphers, i); + + id = SSL_CIPHER_get_id(cipher); + if (SSL_CIPHER_get_by_id(id) == NULL) { + fprintf(stderr, "SSL_CIPHER_get_by_id() failed " + "for %s (0x%lx)\n", SSL_CIPHER_get_name(cipher), + id); + goto failure; + } + + value = SSL_CIPHER_get_value(cipher); + if (SSL_CIPHER_get_by_value(value) == NULL) { + fprintf(stderr, "SSL_CIPHER_get_by_value() failed " + "for %s (0x%04hx)\n", SSL_CIPHER_get_name(cipher), + value); + goto failure; + } + } + + ret = 0; + +failure: + SSL_CTX_free(ssl_ctx); + SSL_free(ssl); + + return (ret); +} + int main(int argc, char **argv) { + int failed = 0; + SSL_library_init(); - return cipher_get_put_tests(); + failed |= cipher_get_put_tests(); + failed |= cipher_get_by_value_tests(); + + return (failed); } |