Deleted Added
full compact
ssl_lib.c (59191) ssl_lib.c (68651)
1/*! \file ssl/ssl_lib.c
2 * \brief Version independent SSL functions.
3 */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).

--- 44 unchanged lines hidden (view full) ---

53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60
1/*! \file ssl/ssl_lib.c
2 * \brief Version independent SSL functions.
3 */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).

--- 44 unchanged lines hidden (view full) ---

53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60
61
62#include <assert.h>
61#include <stdio.h>
62#include <openssl/objects.h>
63#include <openssl/lhash.h>
64#include <openssl/x509v3.h>
65#include "ssl_locl.h"
66
67const char *SSL_version_str=OPENSSL_VERSION_TEXT;
68

--- 109 unchanged lines hidden (view full) ---

178 return(NULL);
179 }
180 if (ctx->method == NULL)
181 {
182 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
183 return(NULL);
184 }
185
63#include <stdio.h>
64#include <openssl/objects.h>
65#include <openssl/lhash.h>
66#include <openssl/x509v3.h>
67#include "ssl_locl.h"
68
69const char *SSL_version_str=OPENSSL_VERSION_TEXT;
70

--- 109 unchanged lines hidden (view full) ---

180 return(NULL);
181 }
182 if (ctx->method == NULL)
183 {
184 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
185 return(NULL);
186 }
187
186 s=(SSL *)Malloc(sizeof(SSL));
188 s=(SSL *)OPENSSL_malloc(sizeof(SSL));
187 if (s == NULL) goto err;
188 memset(s,0,sizeof(SSL));
189
190 if (ctx->cert != NULL)
191 {
192 /* Earlier library versions used to copy the pointer to
193 * the CERT, not its contents; only when setting new
194 * parameters for the per-SSL copy, ssl_cert_new would be

--- 39 unchanged lines hidden (view full) ---

234 return(s);
235err:
236 if (s != NULL)
237 {
238 if (s->cert != NULL)
239 ssl_cert_free(s->cert);
240 if (s->ctx != NULL)
241 SSL_CTX_free(s->ctx); /* decrement reference count */
189 if (s == NULL) goto err;
190 memset(s,0,sizeof(SSL));
191
192 if (ctx->cert != NULL)
193 {
194 /* Earlier library versions used to copy the pointer to
195 * the CERT, not its contents; only when setting new
196 * parameters for the per-SSL copy, ssl_cert_new would be

--- 39 unchanged lines hidden (view full) ---

236 return(s);
237err:
238 if (s != NULL)
239 {
240 if (s->cert != NULL)
241 ssl_cert_free(s->cert);
242 if (s->ctx != NULL)
243 SSL_CTX_free(s->ctx); /* decrement reference count */
242 Free(s);
244 OPENSSL_free(s);
243 }
244 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
245 return(NULL);
246 }
247
248int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
249 unsigned int sid_ctx_len)
250 {

--- 119 unchanged lines hidden (view full) ---

370
371 if (s->ctx) SSL_CTX_free(s->ctx);
372
373 if (s->client_CA != NULL)
374 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
375
376 if (s->method != NULL) s->method->ssl_free(s);
377
245 }
246 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
247 return(NULL);
248 }
249
250int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
251 unsigned int sid_ctx_len)
252 {

--- 119 unchanged lines hidden (view full) ---

372
373 if (s->ctx) SSL_CTX_free(s->ctx);
374
375 if (s->client_CA != NULL)
376 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
377
378 if (s->method != NULL) s->method->ssl_free(s);
379
378 Free(s);
380 OPENSSL_free(s);
379 }
380
381void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
382 {
383 /* If the output buffering BIO is still in place, remove it
384 */
385 if (s->bbio != NULL)
386 {

--- 482 unchanged lines hidden (view full) ---

869 {
870 switch(cmd)
871 {
872 default:
873 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
874 }
875 }
876
381 }
382
383void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
384 {
385 /* If the output buffering BIO is still in place, remove it
386 */
387 if (s->bbio != NULL)
388 {

--- 482 unchanged lines hidden (view full) ---

871 {
872 switch(cmd)
873 {
874 default:
875 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
876 }
877 }
878
877int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b)
879int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
878 {
879 long l;
880
881 l=a->id-b->id;
882 if (l == 0L)
883 return(0);
884 else
885 return((l > 0)?1:-1);
886 }
887
880 {
881 long l;
882
883 l=a->id-b->id;
884 if (l == 0L)
885 return(0);
886 else
887 return((l > 0)?1:-1);
888 }
889
888int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp)
890int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
891 const SSL_CIPHER * const *bp)
889 {
890 long l;
891
892 l=(*ap)->id-(*bp)->id;
893 if (l == 0L)
894 return(0);
895 else
896 return((l > 0)?1:-1);

--- 131 unchanged lines hidden (view full) ---

1028
1029 n=ssl_put_cipher_by_char(s,NULL,NULL);
1030 if ((num%n) != 0)
1031 {
1032 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1033 return(NULL);
1034 }
1035 if ((skp == NULL) || (*skp == NULL))
892 {
893 long l;
894
895 l=(*ap)->id-(*bp)->id;
896 if (l == 0L)
897 return(0);
898 else
899 return((l > 0)?1:-1);

--- 131 unchanged lines hidden (view full) ---

1031
1032 n=ssl_put_cipher_by_char(s,NULL,NULL);
1033 if ((num%n) != 0)
1034 {
1035 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1036 return(NULL);
1037 }
1038 if ((skp == NULL) || (*skp == NULL))
1036 sk=sk_SSL_CIPHER_new(NULL); /* change perhaps later */
1039 sk=sk_SSL_CIPHER_new_null(); /* change perhaps later */
1037 else
1038 {
1039 sk= *skp;
1040 sk_SSL_CIPHER_zero(sk);
1041 }
1042
1043 for (i=0; i<num; i+=n)
1044 {

--- 49 unchanged lines hidden (view full) ---

1094 return(NULL);
1095 }
1096
1097 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1098 {
1099 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1100 goto err;
1101 }
1040 else
1041 {
1042 sk= *skp;
1043 sk_SSL_CIPHER_zero(sk);
1044 }
1045
1046 for (i=0; i<num; i+=n)
1047 {

--- 49 unchanged lines hidden (view full) ---

1097 return(NULL);
1098 }
1099
1100 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1101 {
1102 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1103 goto err;
1104 }
1102 ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX));
1105 ret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
1103 if (ret == NULL)
1104 goto err;
1105
1106 memset(ret,0,sizeof(SSL_CTX));
1107
1108 ret->method=meth;
1109
1110 ret->cert_store=NULL;

--- 79 unchanged lines hidden (view full) ---

1190err:
1191 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1192err2:
1193 if (ret != NULL) SSL_CTX_free(ret);
1194 return(NULL);
1195 }
1196
1197static void SSL_COMP_free(SSL_COMP *comp)
1106 if (ret == NULL)
1107 goto err;
1108
1109 memset(ret,0,sizeof(SSL_CTX));
1110
1111 ret->method=meth;
1112
1113 ret->cert_store=NULL;

--- 79 unchanged lines hidden (view full) ---

1193err:
1194 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1195err2:
1196 if (ret != NULL) SSL_CTX_free(ret);
1197 return(NULL);
1198 }
1199
1200static void SSL_COMP_free(SSL_COMP *comp)
1198 { Free(comp); }
1201 { OPENSSL_free(comp); }
1199
1200void SSL_CTX_free(SSL_CTX *a)
1201 {
1202 int i;
1203
1204 if (a == NULL) return;
1205
1206 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);

--- 24 unchanged lines hidden (view full) ---

1231 if (a->cert != NULL)
1232 ssl_cert_free(a->cert);
1233 if (a->client_CA != NULL)
1234 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1235 if (a->extra_certs != NULL)
1236 sk_X509_pop_free(a->extra_certs,X509_free);
1237 if (a->comp_methods != NULL)
1238 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1202
1203void SSL_CTX_free(SSL_CTX *a)
1204 {
1205 int i;
1206
1207 if (a == NULL) return;
1208
1209 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);

--- 24 unchanged lines hidden (view full) ---

1234 if (a->cert != NULL)
1235 ssl_cert_free(a->cert);
1236 if (a->client_CA != NULL)
1237 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1238 if (a->extra_certs != NULL)
1239 sk_X509_pop_free(a->extra_certs,X509_free);
1240 if (a->comp_methods != NULL)
1241 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1239 Free(a);
1242 OPENSSL_free(a);
1240 }
1241
1242void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1243 {
1244 ctx->default_passwd_callback=cb;
1245 }
1246
1247void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)

--- 506 unchanged lines hidden (view full) ---

1754 return(ret);
1755 }
1756
1757void ssl_clear_cipher_ctx(SSL *s)
1758 {
1759 if (s->enc_read_ctx != NULL)
1760 {
1761 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1243 }
1244
1245void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1246 {
1247 ctx->default_passwd_callback=cb;
1248 }
1249
1250void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)

--- 506 unchanged lines hidden (view full) ---

1757 return(ret);
1758 }
1759
1760void ssl_clear_cipher_ctx(SSL *s)
1761 {
1762 if (s->enc_read_ctx != NULL)
1763 {
1764 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1762 Free(s->enc_read_ctx);
1765 OPENSSL_free(s->enc_read_ctx);
1763 s->enc_read_ctx=NULL;
1764 }
1765 if (s->enc_write_ctx != NULL)
1766 {
1767 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1766 s->enc_read_ctx=NULL;
1767 }
1768 if (s->enc_write_ctx != NULL)
1769 {
1770 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1768 Free(s->enc_write_ctx);
1771 OPENSSL_free(s->enc_write_ctx);
1769 s->enc_write_ctx=NULL;
1770 }
1771 if (s->expand != NULL)
1772 {
1773 COMP_CTX_free(s->expand);
1774 s->expand=NULL;
1775 }
1776 if (s->compress != NULL)

--- 61 unchanged lines hidden (view full) ---

1838 if (s->wbio == bbio)
1839 s->wbio=BIO_pop(bbio);
1840 }
1841 return(1);
1842 }
1843
1844void ssl_free_wbio_buffer(SSL *s)
1845 {
1772 s->enc_write_ctx=NULL;
1773 }
1774 if (s->expand != NULL)
1775 {
1776 COMP_CTX_free(s->expand);
1777 s->expand=NULL;
1778 }
1779 if (s->compress != NULL)

--- 61 unchanged lines hidden (view full) ---

1841 if (s->wbio == bbio)
1842 s->wbio=BIO_pop(bbio);
1843 }
1844 return(1);
1845 }
1846
1847void ssl_free_wbio_buffer(SSL *s)
1848 {
1846 BIO *under;
1847
1848 if (s->bbio == NULL) return;
1849
1850 if (s->bbio == s->wbio)
1851 {
1852 /* remove buffering */
1849 if (s->bbio == NULL) return;
1850
1851 if (s->bbio == s->wbio)
1852 {
1853 /* remove buffering */
1853 under=BIO_pop(s->wbio);
1854 if (under != NULL)
1855 s->wbio=under;
1856 else
1857 abort(); /* ok */
1858 }
1854 s->wbio=BIO_pop(s->wbio);
1855#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */
1856 assert(s->wbio != NULL);
1857#endif
1858 }
1859 BIO_free(s->bbio);
1860 s->bbio=NULL;
1861 }
1862
1863void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
1864 {
1865 ctx->quiet_shutdown=mode;
1866 }

--- 195 unchanged lines hidden ---
1859 BIO_free(s->bbio);
1860 s->bbio=NULL;
1861 }
1862
1863void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
1864 {
1865 ctx->quiet_shutdown=mode;
1866 }

--- 195 unchanged lines hidden ---