summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r--src/lib/libssl/ssl_lib.c103
1 files changed, 60 insertions, 43 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index ee9a82d586..631229558f 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -121,6 +121,7 @@
121#include <openssl/objects.h> 121#include <openssl/objects.h>
122#include <openssl/lhash.h> 122#include <openssl/lhash.h>
123#include <openssl/x509v3.h> 123#include <openssl/x509v3.h>
124#include <openssl/fips.h>
124 125
125const char *SSL_version_str=OPENSSL_VERSION_TEXT; 126const char *SSL_version_str=OPENSSL_VERSION_TEXT;
126 127
@@ -500,18 +501,18 @@ void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
500 s->wbio=wbio; 501 s->wbio=wbio;
501 } 502 }
502 503
503BIO *SSL_get_rbio(SSL *s) 504BIO *SSL_get_rbio(const SSL *s)
504 { return(s->rbio); } 505 { return(s->rbio); }
505 506
506BIO *SSL_get_wbio(SSL *s) 507BIO *SSL_get_wbio(const SSL *s)
507 { return(s->wbio); } 508 { return(s->wbio); }
508 509
509int SSL_get_fd(SSL *s) 510int SSL_get_fd(const SSL *s)
510 { 511 {
511 return(SSL_get_rfd(s)); 512 return(SSL_get_rfd(s));
512 } 513 }
513 514
514int SSL_get_rfd(SSL *s) 515int SSL_get_rfd(const SSL *s)
515 { 516 {
516 int ret= -1; 517 int ret= -1;
517 BIO *b,*r; 518 BIO *b,*r;
@@ -523,7 +524,7 @@ int SSL_get_rfd(SSL *s)
523 return(ret); 524 return(ret);
524 } 525 }
525 526
526int SSL_get_wfd(SSL *s) 527int SSL_get_wfd(const SSL *s)
527 { 528 {
528 int ret= -1; 529 int ret= -1;
529 BIO *b,*r; 530 BIO *b,*r;
@@ -605,7 +606,7 @@ err:
605 606
606 607
607/* return length of latest Finished message we sent, copy to 'buf' */ 608/* return length of latest Finished message we sent, copy to 'buf' */
608size_t SSL_get_finished(SSL *s, void *buf, size_t count) 609size_t SSL_get_finished(const SSL *s, void *buf, size_t count)
609 { 610 {
610 size_t ret = 0; 611 size_t ret = 0;
611 612
@@ -620,7 +621,7 @@ size_t SSL_get_finished(SSL *s, void *buf, size_t count)
620 } 621 }
621 622
622/* return length of latest Finished message we expected, copy to 'buf' */ 623/* return length of latest Finished message we expected, copy to 'buf' */
623size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count) 624size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count)
624 { 625 {
625 size_t ret = 0; 626 size_t ret = 0;
626 627
@@ -635,32 +636,32 @@ size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count)
635 } 636 }
636 637
637 638
638int SSL_get_verify_mode(SSL *s) 639int SSL_get_verify_mode(const SSL *s)
639 { 640 {
640 return(s->verify_mode); 641 return(s->verify_mode);
641 } 642 }
642 643
643int SSL_get_verify_depth(SSL *s) 644int SSL_get_verify_depth(const SSL *s)
644 { 645 {
645 return(s->verify_depth); 646 return(s->verify_depth);
646 } 647 }
647 648
648int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *) 649int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *)
649 { 650 {
650 return(s->verify_callback); 651 return(s->verify_callback);
651 } 652 }
652 653
653int SSL_CTX_get_verify_mode(SSL_CTX *ctx) 654int SSL_CTX_get_verify_mode(const SSL_CTX *ctx)
654 { 655 {
655 return(ctx->verify_mode); 656 return(ctx->verify_mode);
656 } 657 }
657 658
658int SSL_CTX_get_verify_depth(SSL_CTX *ctx) 659int SSL_CTX_get_verify_depth(const SSL_CTX *ctx)
659 { 660 {
660 return(ctx->verify_depth); 661 return(ctx->verify_depth);
661 } 662 }
662 663
663int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *) 664int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *)
664 { 665 {
665 return(ctx->default_verify_callback); 666 return(ctx->default_verify_callback);
666 } 667 }
@@ -683,12 +684,12 @@ void SSL_set_read_ahead(SSL *s,int yes)
683 s->read_ahead=yes; 684 s->read_ahead=yes;
684 } 685 }
685 686
686int SSL_get_read_ahead(SSL *s) 687int SSL_get_read_ahead(const SSL *s)
687 { 688 {
688 return(s->read_ahead); 689 return(s->read_ahead);
689 } 690 }
690 691
691int SSL_pending(SSL *s) 692int SSL_pending(const SSL *s)
692 { 693 {
693 /* SSL_pending cannot work properly if read-ahead is enabled 694 /* SSL_pending cannot work properly if read-ahead is enabled
694 * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)), 695 * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)),
@@ -700,7 +701,7 @@ int SSL_pending(SSL *s)
700 return(s->method->ssl_pending(s)); 701 return(s->method->ssl_pending(s));
701 } 702 }
702 703
703X509 *SSL_get_peer_certificate(SSL *s) 704X509 *SSL_get_peer_certificate(const SSL *s)
704 { 705 {
705 X509 *r; 706 X509 *r;
706 707
@@ -716,7 +717,7 @@ X509 *SSL_get_peer_certificate(SSL *s)
716 return(r); 717 return(r);
717 } 718 }
718 719
719STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s) 720STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s)
720 { 721 {
721 STACK_OF(X509) *r; 722 STACK_OF(X509) *r;
722 723
@@ -733,7 +734,7 @@ STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s)
733 734
734/* Now in theory, since the calling process own 't' it should be safe to 735/* Now in theory, since the calling process own 't' it should be safe to
735 * modify. We need to be able to read f without being hassled */ 736 * modify. We need to be able to read f without being hassled */
736void SSL_copy_session_id(SSL *t,SSL *f) 737void SSL_copy_session_id(SSL *t,const SSL *f)
737 { 738 {
738 CERT *tmp; 739 CERT *tmp;
739 740
@@ -762,7 +763,7 @@ void SSL_copy_session_id(SSL *t,SSL *f)
762 } 763 }
763 764
764/* Fix this so it checks all the valid key/cert options */ 765/* Fix this so it checks all the valid key/cert options */
765int SSL_CTX_check_private_key(SSL_CTX *ctx) 766int SSL_CTX_check_private_key(const SSL_CTX *ctx)
766 { 767 {
767 if ( (ctx == NULL) || 768 if ( (ctx == NULL) ||
768 (ctx->cert == NULL) || 769 (ctx->cert == NULL) ||
@@ -780,7 +781,7 @@ int SSL_CTX_check_private_key(SSL_CTX *ctx)
780 } 781 }
781 782
782/* Fix this function so that it takes an optional type parameter */ 783/* Fix this function so that it takes an optional type parameter */
783int SSL_check_private_key(SSL *ssl) 784int SSL_check_private_key(const SSL *ssl)
784 { 785 {
785 if (ssl == NULL) 786 if (ssl == NULL)
786 { 787 {
@@ -824,7 +825,7 @@ int SSL_connect(SSL *s)
824 return(s->method->ssl_connect(s)); 825 return(s->method->ssl_connect(s));
825 } 826 }
826 827
827long SSL_get_default_timeout(SSL *s) 828long SSL_get_default_timeout(const SSL *s)
828 { 829 {
829 return(s->method->get_timeout()); 830 return(s->method->get_timeout());
830 } 831 }
@@ -1071,7 +1072,7 @@ int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1071 1072
1072/** return a STACK of the ciphers available for the SSL and in order of 1073/** return a STACK of the ciphers available for the SSL and in order of
1073 * preference */ 1074 * preference */
1074STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s) 1075STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s)
1075 { 1076 {
1076 if (s != NULL) 1077 if (s != NULL)
1077 { 1078 {
@@ -1108,7 +1109,7 @@ STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
1108 } 1109 }
1109 1110
1110/** The old interface to get the same thing as SSL_get_ciphers() */ 1111/** The old interface to get the same thing as SSL_get_ciphers() */
1111const char *SSL_get_cipher_list(SSL *s,int n) 1112const char *SSL_get_cipher_list(const SSL *s,int n)
1112 { 1113 {
1113 SSL_CIPHER *c; 1114 SSL_CIPHER *c;
1114 STACK_OF(SSL_CIPHER) *sk; 1115 STACK_OF(SSL_CIPHER) *sk;
@@ -1145,7 +1146,7 @@ int SSL_set_cipher_list(SSL *s,const char *str)
1145 } 1146 }
1146 1147
1147/* works well for SSLv2, not so good for SSLv3 */ 1148/* works well for SSLv2, not so good for SSLv3 */
1148char *SSL_get_shared_ciphers(SSL *s,char *buf,int len) 1149char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
1149 { 1150 {
1150 char *p; 1151 char *p;
1151 const char *cp; 1152 const char *cp;
@@ -1249,7 +1250,7 @@ err:
1249 return(NULL); 1250 return(NULL);
1250 } 1251 }
1251 1252
1252unsigned long SSL_SESSION_hash(SSL_SESSION *a) 1253unsigned long SSL_SESSION_hash(const SSL_SESSION *a)
1253 { 1254 {
1254 unsigned long l; 1255 unsigned long l;
1255 1256
@@ -1266,7 +1267,7 @@ unsigned long SSL_SESSION_hash(SSL_SESSION *a)
1266 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being 1267 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
1267 * able to construct an SSL_SESSION that will collide with any existing session 1268 * able to construct an SSL_SESSION that will collide with any existing session
1268 * with a matching session ID. */ 1269 * with a matching session ID. */
1269int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b) 1270int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
1270 { 1271 {
1271 if (a->ssl_version != b->ssl_version) 1272 if (a->ssl_version != b->ssl_version)
1272 return(1); 1273 return(1);
@@ -1292,6 +1293,14 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
1292 return(NULL); 1293 return(NULL);
1293 } 1294 }
1294 1295
1296#ifdef OPENSSL_FIPS
1297 if (FIPS_mode() && (meth->version < TLS1_VERSION))
1298 {
1299 SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
1300 return NULL;
1301 }
1302#endif
1303
1295 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) 1304 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1296 { 1305 {
1297 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); 1306 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
@@ -1722,7 +1731,7 @@ int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1722 return(ret); 1731 return(ret);
1723 } 1732 }
1724 1733
1725int SSL_get_error(SSL *s,int i) 1734int SSL_get_error(const SSL *s,int i)
1726 { 1735 {
1727 int reason; 1736 int reason;
1728 unsigned long l; 1737 unsigned long l;
@@ -1856,13 +1865,19 @@ int ssl_undefined_function(SSL *s)
1856 return(0); 1865 return(0);
1857 } 1866 }
1858 1867
1868int ssl_undefined_const_function(const SSL *s)
1869 {
1870 SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1871 return(0);
1872 }
1873
1859SSL_METHOD *ssl_bad_method(int ver) 1874SSL_METHOD *ssl_bad_method(int ver)
1860 { 1875 {
1861 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 1876 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1862 return(NULL); 1877 return(NULL);
1863 } 1878 }
1864 1879
1865const char *SSL_get_version(SSL *s) 1880const char *SSL_get_version(const SSL *s)
1866 { 1881 {
1867 if (s->version == TLS1_VERSION) 1882 if (s->version == TLS1_VERSION)
1868 return("TLSv1"); 1883 return("TLSv1");
@@ -2031,7 +2046,7 @@ void ssl_clear_cipher_ctx(SSL *s)
2031 } 2046 }
2032 2047
2033/* Fix this function so that it takes an optional type parameter */ 2048/* Fix this function so that it takes an optional type parameter */
2034X509 *SSL_get_certificate(SSL *s) 2049X509 *SSL_get_certificate(const SSL *s)
2035 { 2050 {
2036 if (s->cert != NULL) 2051 if (s->cert != NULL)
2037 return(s->cert->key->x509); 2052 return(s->cert->key->x509);
@@ -2048,7 +2063,7 @@ EVP_PKEY *SSL_get_privatekey(SSL *s)
2048 return(NULL); 2063 return(NULL);
2049 } 2064 }
2050 2065
2051SSL_CIPHER *SSL_get_current_cipher(SSL *s) 2066SSL_CIPHER *SSL_get_current_cipher(const SSL *s)
2052 { 2067 {
2053 if ((s->session != NULL) && (s->session->cipher != NULL)) 2068 if ((s->session != NULL) && (s->session->cipher != NULL))
2054 return(s->session->cipher); 2069 return(s->session->cipher);
@@ -2112,7 +2127,7 @@ void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
2112 ctx->quiet_shutdown=mode; 2127 ctx->quiet_shutdown=mode;
2113 } 2128 }
2114 2129
2115int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx) 2130int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx)
2116 { 2131 {
2117 return(ctx->quiet_shutdown); 2132 return(ctx->quiet_shutdown);
2118 } 2133 }
@@ -2122,7 +2137,7 @@ void SSL_set_quiet_shutdown(SSL *s,int mode)
2122 s->quiet_shutdown=mode; 2137 s->quiet_shutdown=mode;
2123 } 2138 }
2124 2139
2125int SSL_get_quiet_shutdown(SSL *s) 2140int SSL_get_quiet_shutdown(const SSL *s)
2126 { 2141 {
2127 return(s->quiet_shutdown); 2142 return(s->quiet_shutdown);
2128 } 2143 }
@@ -2132,17 +2147,17 @@ void SSL_set_shutdown(SSL *s,int mode)
2132 s->shutdown=mode; 2147 s->shutdown=mode;
2133 } 2148 }
2134 2149
2135int SSL_get_shutdown(SSL *s) 2150int SSL_get_shutdown(const SSL *s)
2136 { 2151 {
2137 return(s->shutdown); 2152 return(s->shutdown);
2138 } 2153 }
2139 2154
2140int SSL_version(SSL *s) 2155int SSL_version(const SSL *s)
2141 { 2156 {
2142 return(s->version); 2157 return(s->version);
2143 } 2158 }
2144 2159
2145SSL_CTX *SSL_get_SSL_CTX(SSL *ssl) 2160SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl)
2146 { 2161 {
2147 return(ssl->ctx); 2162 return(ssl->ctx);
2148 } 2163 }
@@ -2156,7 +2171,9 @@ int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
2156int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, 2171int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
2157 const char *CApath) 2172 const char *CApath)
2158 { 2173 {
2159 return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); 2174 int r;
2175 r=X509_STORE_load_locations(ctx->cert_store,CAfile,CApath);
2176 return r;
2160 } 2177 }
2161#endif 2178#endif
2162 2179
@@ -2166,12 +2183,12 @@ void SSL_set_info_callback(SSL *ssl,
2166 ssl->info_callback=cb; 2183 ssl->info_callback=cb;
2167 } 2184 }
2168 2185
2169void (*SSL_get_info_callback(SSL *ssl))(const SSL *ssl,int type,int val) 2186void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val)
2170 { 2187 {
2171 return ssl->info_callback; 2188 return ssl->info_callback;
2172 } 2189 }
2173 2190
2174int SSL_state(SSL *ssl) 2191int SSL_state(const SSL *ssl)
2175 { 2192 {
2176 return(ssl->state); 2193 return(ssl->state);
2177 } 2194 }
@@ -2181,7 +2198,7 @@ void SSL_set_verify_result(SSL *ssl,long arg)
2181 ssl->verify_result=arg; 2198 ssl->verify_result=arg;
2182 } 2199 }
2183 2200
2184long SSL_get_verify_result(SSL *ssl) 2201long SSL_get_verify_result(const SSL *ssl)
2185 { 2202 {
2186 return(ssl->verify_result); 2203 return(ssl->verify_result);
2187 } 2204 }
@@ -2198,7 +2215,7 @@ int SSL_set_ex_data(SSL *s,int idx,void *arg)
2198 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); 2215 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
2199 } 2216 }
2200 2217
2201void *SSL_get_ex_data(SSL *s,int idx) 2218void *SSL_get_ex_data(const SSL *s,int idx)
2202 { 2219 {
2203 return(CRYPTO_get_ex_data(&s->ex_data,idx)); 2220 return(CRYPTO_get_ex_data(&s->ex_data,idx));
2204 } 2221 }
@@ -2215,7 +2232,7 @@ int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg)
2215 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); 2232 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
2216 } 2233 }
2217 2234
2218void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx) 2235void *SSL_CTX_get_ex_data(const SSL_CTX *s,int idx)
2219 { 2236 {
2220 return(CRYPTO_get_ex_data(&s->ex_data,idx)); 2237 return(CRYPTO_get_ex_data(&s->ex_data,idx));
2221 } 2238 }
@@ -2225,7 +2242,7 @@ int ssl_ok(SSL *s)
2225 return(1); 2242 return(1);
2226 } 2243 }
2227 2244
2228X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx) 2245X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx)
2229 { 2246 {
2230 return(ctx->cert_store); 2247 return(ctx->cert_store);
2231 } 2248 }
@@ -2237,7 +2254,7 @@ void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store)
2237 ctx->cert_store=store; 2254 ctx->cert_store=store;
2238 } 2255 }
2239 2256
2240int SSL_want(SSL *s) 2257int SSL_want(const SSL *s)
2241 { 2258 {
2242 return(s->rwstate); 2259 return(s->rwstate);
2243 } 2260 }