summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_lib.c
diff options
context:
space:
mode:
authorbeck <>2000-03-19 11:13:58 +0000
committerbeck <>2000-03-19 11:13:58 +0000
commit796d609550df3a33fc11468741c5d2f6d3df4c11 (patch)
tree6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libssl/ssl_lib.c
parent5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff)
downloadopenbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2 if you are using the ssl26 packages for ssh and other things to work you will need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r--src/lib/libssl/ssl_lib.c175
1 files changed, 143 insertions, 32 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index e192fc4cac..3109708480 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -61,22 +61,24 @@
61#include <stdio.h> 61#include <stdio.h>
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/lhash.h> 63#include <openssl/lhash.h>
64#include <openssl/x509v3.h>
64#include "ssl_locl.h" 65#include "ssl_locl.h"
65 66
66char *SSL_version_str=OPENSSL_VERSION_TEXT; 67const char *SSL_version_str=OPENSSL_VERSION_TEXT;
67 68
68static STACK *ssl_meth=NULL; 69static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_meth=NULL;
69static STACK *ssl_ctx_meth=NULL; 70static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_ctx_meth=NULL;
70static int ssl_meth_num=0; 71static int ssl_meth_num=0;
71static int ssl_ctx_meth_num=0; 72static int ssl_ctx_meth_num=0;
72 73
73OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={ 74OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={
75 /* evil casts, but these functions are only called if there's a library bug */
76 (int (*)(SSL *,int))ssl_undefined_function,
77 (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
74 ssl_undefined_function, 78 ssl_undefined_function,
75 ssl_undefined_function, 79 (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
76 ssl_undefined_function, 80 (int (*)(SSL*, int))ssl_undefined_function,
77 ssl_undefined_function, 81 (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function
78 ssl_undefined_function,
79 ssl_undefined_function,
80 }; 82 };
81 83
82int SSL_clear(SSL *s) 84int SSL_clear(SSL *s)
@@ -93,10 +95,17 @@ int SSL_clear(SSL *s)
93 s->hit=0; 95 s->hit=0;
94 s->shutdown=0; 96 s->shutdown=0;
95 97
96#if 0 98#if 0 /* Disabled since version 1.10 of this file (early return not
99 * needed because SSL_clear is not called when doing renegotiation) */
97 /* This is set if we are doing dynamic renegotiation so keep 100 /* This is set if we are doing dynamic renegotiation so keep
98 * the old cipher. It is sort of a SSL_clear_lite :-) */ 101 * the old cipher. It is sort of a SSL_clear_lite :-) */
99 if (s->new_session) return(1); 102 if (s->new_session) return(1);
103#else
104 if (s->new_session)
105 {
106 SSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR);
107 return 0;
108 }
100#endif 109#endif
101 110
102 state=s->state; /* Keep to check if we throw away the session-id */ 111 state=s->state; /* Keep to check if we throw away the session-id */
@@ -201,6 +210,8 @@ SSL *SSL_new(SSL_CTX *ctx)
201 s->verify_mode=ctx->verify_mode; 210 s->verify_mode=ctx->verify_mode;
202 s->verify_depth=ctx->verify_depth; 211 s->verify_depth=ctx->verify_depth;
203 s->verify_callback=ctx->default_verify_callback; 212 s->verify_callback=ctx->default_verify_callback;
213 s->purpose = ctx->purpose;
214 s->trust = ctx->trust;
204 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); 215 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
205 s->ctx=ctx; 216 s->ctx=ctx;
206 217
@@ -218,7 +229,7 @@ SSL *SSL_new(SSL_CTX *ctx)
218 s->mode=ctx->mode; 229 s->mode=ctx->mode;
219 SSL_clear(s); 230 SSL_clear(s);
220 231
221 CRYPTO_new_ex_data(ssl_meth,(char *)s,&s->ex_data); 232 CRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);
222 233
223 return(s); 234 return(s);
224err: 235err:
@@ -262,6 +273,46 @@ int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
262 return 1; 273 return 1;
263 } 274 }
264 275
276int SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
277{
278 if(X509_PURPOSE_get_by_id(purpose) == -1) {
279 SSLerr(SSL_F_SSL_CTX_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
280 return 0;
281 }
282 s->purpose = purpose;
283 return 1;
284}
285
286int SSL_set_purpose(SSL *s, int purpose)
287{
288 if(X509_PURPOSE_get_by_id(purpose) == -1) {
289 SSLerr(SSL_F_SSL_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
290 return 0;
291 }
292 s->purpose = purpose;
293 return 1;
294}
295
296int SSL_CTX_set_trust(SSL_CTX *s, int trust)
297{
298 if(X509_TRUST_get_by_id(trust) == -1) {
299 SSLerr(SSL_F_SSL_CTX_SET_TRUST, SSL_R_INVALID_TRUST);
300 return 0;
301 }
302 s->trust = trust;
303 return 1;
304}
305
306int SSL_set_trust(SSL *s, int trust)
307{
308 if(X509_TRUST_get_by_id(trust) == -1) {
309 SSLerr(SSL_F_SSL_SET_TRUST, SSL_R_INVALID_TRUST);
310 return 0;
311 }
312 s->trust = trust;
313 return 1;
314}
315
265void SSL_free(SSL *s) 316void SSL_free(SSL *s)
266 { 317 {
267 int i; 318 int i;
@@ -324,7 +375,7 @@ void SSL_free(SSL *s)
324 375
325 if (s->method != NULL) s->method->ssl_free(s); 376 if (s->method != NULL) s->method->ssl_free(s);
326 377
327 Free((char *)s); 378 Free(s);
328 } 379 }
329 380
330void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio) 381void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
@@ -433,6 +484,38 @@ err:
433 } 484 }
434#endif 485#endif
435 486
487
488/* return length of latest Finished message we sent, copy to 'buf' */
489size_t SSL_get_finished(SSL *s, void *buf, size_t count)
490 {
491 size_t ret = 0;
492
493 if (s->s3 != NULL)
494 {
495 ret = s->s3->tmp.finish_md_len;
496 if (count > ret)
497 count = ret;
498 memcpy(buf, s->s3->tmp.finish_md, count);
499 }
500 return ret;
501 }
502
503/* return length of latest Finished message we expected, copy to 'buf' */
504size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count)
505 {
506 size_t ret = 0;
507
508 if (s->s3 != NULL)
509 {
510 ret = s->s3->tmp.peer_finish_md_len;
511 if (count > ret)
512 count = ret;
513 memcpy(buf, s->s3->tmp.peer_finish_md, count);
514 }
515 return ret;
516 }
517
518
436int SSL_get_verify_mode(SSL *s) 519int SSL_get_verify_mode(SSL *s)
437 { 520 {
438 return(s->verify_mode); 521 return(s->verify_mode);
@@ -706,6 +789,20 @@ long SSL_ctrl(SSL *s,int cmd,long larg,char *parg)
706 } 789 }
707 } 790 }
708 791
792long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)())
793 {
794 switch(cmd)
795 {
796 default:
797 return(s->method->ssl_callback_ctrl(s,cmd,fp));
798 }
799 }
800
801struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
802 {
803 return ctx->sessions;
804 }
805
709long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg) 806long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg)
710 { 807 {
711 long l; 808 long l;
@@ -765,6 +862,15 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg)
765 } 862 }
766 } 863 }
767 864
865long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
866 {
867 switch(cmd)
868 {
869 default:
870 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
871 }
872 }
873
768int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b) 874int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b)
769 { 875 {
770 long l; 876 long l;
@@ -834,8 +940,8 @@ const char *SSL_get_cipher_list(SSL *s,int n)
834 return(c->name); 940 return(c->name);
835 } 941 }
836 942
837/** specify the ciphers to be used by defaut by the SSL_CTX */ 943/** specify the ciphers to be used by default by the SSL_CTX */
838int SSL_CTX_set_cipher_list(SSL_CTX *ctx,char *str) 944int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
839 { 945 {
840 STACK_OF(SSL_CIPHER) *sk; 946 STACK_OF(SSL_CIPHER) *sk;
841 947
@@ -846,7 +952,7 @@ int SSL_CTX_set_cipher_list(SSL_CTX *ctx,char *str)
846 } 952 }
847 953
848/** specify the ciphers to be used by the SSL */ 954/** specify the ciphers to be used by the SSL */
849int SSL_set_cipher_list(SSL *s,char *str) 955int SSL_set_cipher_list(SSL *s,const char *str)
850 { 956 {
851 STACK_OF(SSL_CIPHER) *sk; 957 STACK_OF(SSL_CIPHER) *sk;
852 958
@@ -1127,7 +1233,7 @@ void SSL_CTX_free(SSL_CTX *a)
1127 sk_X509_pop_free(a->extra_certs,X509_free); 1233 sk_X509_pop_free(a->extra_certs,X509_free);
1128 if (a->comp_methods != NULL) 1234 if (a->comp_methods != NULL)
1129 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free); 1235 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1130 Free((char *)a); 1236 Free(a);
1131 } 1237 }
1132 1238
1133void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) 1239void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
@@ -1254,10 +1360,8 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1254 emask|=SSL_aDSS; 1360 emask|=SSL_aDSS;
1255 } 1361 }
1256 1362
1257#ifdef SSL_ALLOW_ADH
1258 mask|=SSL_aNULL; 1363 mask|=SSL_aNULL;
1259 emask|=SSL_aNULL; 1364 emask|=SSL_aNULL;
1260#endif
1261 1365
1262 c->mask=mask; 1366 c->mask=mask;
1263 c->export_mask=emask; 1367 c->export_mask=emask;
@@ -1274,7 +1378,7 @@ X509 *ssl_get_server_send_cert(SSL *s)
1274 c=s->cert; 1378 c=s->cert;
1275 ssl_set_cert_masks(c, s->s3->tmp.new_cipher); 1379 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1276 alg=s->s3->tmp.new_cipher->algorithms; 1380 alg=s->s3->tmp.new_cipher->algorithms;
1277 is_export=SSL_IS_EXPORT(alg); 1381 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
1278 mask=is_export?c->export_mask:c->mask; 1382 mask=is_export?c->export_mask:c->mask;
1279 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); 1383 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1280 1384
@@ -1527,7 +1631,7 @@ SSL_METHOD *ssl_bad_method(int ver)
1527 return(NULL); 1631 return(NULL);
1528 } 1632 }
1529 1633
1530char *SSL_get_version(SSL *s) 1634const char *SSL_get_version(SSL *s)
1531 { 1635 {
1532 if (s->version == TLS1_VERSION) 1636 if (s->version == TLS1_VERSION)
1533 return("TLSv1"); 1637 return("TLSv1");
@@ -1831,8 +1935,8 @@ long SSL_get_verify_result(SSL *ssl)
1831 return(ssl->verify_result); 1935 return(ssl->verify_result);
1832 } 1936 }
1833 1937
1834int SSL_get_ex_new_index(long argl,char *argp,int (*new_func)(), 1938int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
1835 int (*dup_func)(),void (*free_func)()) 1939 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
1836 { 1940 {
1837 ssl_meth_num++; 1941 ssl_meth_num++;
1838 return(CRYPTO_get_ex_new_index(ssl_meth_num-1, 1942 return(CRYPTO_get_ex_new_index(ssl_meth_num-1,
@@ -1849,8 +1953,8 @@ void *SSL_get_ex_data(SSL *s,int idx)
1849 return(CRYPTO_get_ex_data(&s->ex_data,idx)); 1953 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1850 } 1954 }
1851 1955
1852int SSL_CTX_get_ex_new_index(long argl,char *argp,int (*new_func)(), 1956int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
1853 int (*dup_func)(),void (*free_func)()) 1957 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
1854 { 1958 {
1855 ssl_ctx_meth_num++; 1959 ssl_ctx_meth_num++;
1856 return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1, 1960 return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1,
@@ -1899,13 +2003,16 @@ int SSL_want(SSL *s)
1899void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl, 2003void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl,
1900 int is_export, 2004 int is_export,
1901 int keylength)) 2005 int keylength))
1902 { SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb); } 2006 {
1903#endif 2007 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2008 }
1904 2009
1905#ifndef NO_RSA 2010void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,
1906void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,int is_export, 2011 int is_export,
1907 int keylength)) 2012 int keylength))
1908 { SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb); } 2013 {
2014 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2015 }
1909#endif 2016#endif
1910 2017
1911#ifdef DOXYGEN 2018#ifdef DOXYGEN
@@ -1932,11 +2039,15 @@ RSA *cb(SSL *ssl,int is_export,int keylength)
1932#ifndef NO_DH 2039#ifndef NO_DH
1933void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, 2040void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
1934 int keylength)) 2041 int keylength))
1935 { SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh); } 2042 {
2043 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2044 }
1936 2045
1937void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, 2046void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
1938 int keylength)) 2047 int keylength))
1939 { SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh); } 2048 {
2049 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2050 }
1940#endif 2051#endif
1941 2052
1942#if defined(_WINDLL) && defined(WIN16) 2053#if defined(_WINDLL) && defined(WIN16)