From: Kurt Roeckx Date: Sun, 7 Feb 2016 19:56:40 +0000 (+0100) Subject: Make function to convert version to string X-Git-Tag: OpenSSL_1_1_0-pre4~122 X-Git-Url: https://git.openssl.org/?a=commitdiff_plain;h=7d65007238e86e59fcf31d23fcefa01e3b30cc37;p=openssl.git Make function to convert version to string Reviewed-by: Viktor Dukhovni MR: #1595 --- diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 94d0a220e5..0571150e60 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -3060,26 +3060,31 @@ SSL_METHOD *ssl_bad_method(int ver) return (NULL); } -const char *SSL_get_version(const SSL *s) -{ - if (s->version == TLS1_2_VERSION) - return ("TLSv1.2"); - else if (s->version == TLS1_1_VERSION) - return ("TLSv1.1"); - else if (s->version == TLS1_VERSION) - return ("TLSv1"); - else if (s->version == SSL3_VERSION) - return ("SSLv3"); - else if (s->version == DTLS1_BAD_VER) - return ("DTLSv0.9"); - else if (s->version == DTLS1_VERSION) - return ("DTLSv1"); - else if (s->version == DTLS1_2_VERSION) - return ("DTLSv1.2"); +const char *version_to_string(int version) +{ + if (version == TLS1_2_VERSION) + return "TLSv1.2"; + else if (version == TLS1_1_VERSION) + return "TLSv1.1"; + else if (version == TLS1_VERSION) + return "TLSv1.0"; + else if (version == SSL3_VERSION) + return "SSLv3"; + else if (version == DTLS1_BAD_VER) + return "DTLSv0.9"; + else if (version == DTLS1_VERSION) + return "DTLSv1"; + else if (version == DTLS1_2_VERSION) + return "DTLSv1.2"; else return ("unknown"); } +const char *SSL_get_version(const SSL *s) +{ + return version_to_string(s->version); +} + SSL *SSL_dup(SSL *s) { STACK_OF(X509_NAME) *sk; diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index 7e8f6a5850..7f85b95d0c 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -1871,6 +1871,8 @@ struct openssl_ssl_test_functions { # endif }; +const char *version_to_string(int version); + # ifndef OPENSSL_UNIT_TEST void ssl_clear_cipher_ctx(SSL *s); diff --git a/ssl/ssl_txt.c b/ssl/ssl_txt.c index bdd802f600..5bc5a72887 100644 --- a/ssl/ssl_txt.c +++ b/ssl/ssl_txt.c @@ -111,22 +111,7 @@ int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) goto err; if (BIO_puts(bp, "SSL-Session:\n") <= 0) goto err; - if (x->ssl_version == SSL3_VERSION) - s = "SSLv3"; - else if (x->ssl_version == TLS1_2_VERSION) - s = "TLSv1.2"; - else if (x->ssl_version == TLS1_1_VERSION) - s = "TLSv1.1"; - else if (x->ssl_version == TLS1_VERSION) - s = "TLSv1"; - else if (x->ssl_version == DTLS1_VERSION) - s = "DTLSv1"; - else if (x->ssl_version == DTLS1_2_VERSION) - s = "DTLSv1.2"; - else if (x->ssl_version == DTLS1_BAD_VER) - s = "DTLSv1-bad"; - else - s = "unknown"; + s = version_to_string(x->ssl_version); if (BIO_printf(bp, " Protocol : %s\n", s) <= 0) goto err;