diff options
| author | markus <> | 2002-09-05 12:51:50 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-05 12:51:50 +0000 |
| commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
| tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libssl/ssl_lib.c | |
| parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
| download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip | |
import openssl-0.9.7-beta1
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libssl/ssl_lib.c | 1484 |
1 files changed, 1027 insertions, 457 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index f562ec6b14..df307a80c5 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | /* ssl/ssl_lib.c */ | 1 | /*! \file ssl/ssl_lib.c |
| 2 | * \brief Version independent SSL functions. | ||
| 3 | */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 4 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 5 | * All rights reserved. |
| 4 | * | 6 | * |
| @@ -55,52 +57,126 @@ | |||
| 55 | * copied and put under another distribution licence | 57 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] | 58 | * [including the GNU Public Licence.] |
| 57 | */ | 59 | */ |
| 60 | /* ==================================================================== | ||
| 61 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 62 | * | ||
| 63 | * Redistribution and use in source and binary forms, with or without | ||
| 64 | * modification, are permitted provided that the following conditions | ||
| 65 | * are met: | ||
| 66 | * | ||
| 67 | * 1. Redistributions of source code must retain the above copyright | ||
| 68 | * notice, this list of conditions and the following disclaimer. | ||
| 69 | * | ||
| 70 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 71 | * notice, this list of conditions and the following disclaimer in | ||
| 72 | * the documentation and/or other materials provided with the | ||
| 73 | * distribution. | ||
| 74 | * | ||
| 75 | * 3. All advertising materials mentioning features or use of this | ||
| 76 | * software must display the following acknowledgment: | ||
| 77 | * "This product includes software developed by the OpenSSL Project | ||
| 78 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 79 | * | ||
| 80 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 81 | * endorse or promote products derived from this software without | ||
| 82 | * prior written permission. For written permission, please contact | ||
| 83 | * openssl-core@openssl.org. | ||
| 84 | * | ||
| 85 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 86 | * nor may "OpenSSL" appear in their names without prior written | ||
| 87 | * permission of the OpenSSL Project. | ||
| 88 | * | ||
| 89 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 90 | * acknowledgment: | ||
| 91 | * "This product includes software developed by the OpenSSL Project | ||
| 92 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 93 | * | ||
| 94 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 95 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 96 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 97 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 98 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 99 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 100 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 101 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 102 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 103 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 104 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 105 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 106 | * ==================================================================== | ||
| 107 | * | ||
| 108 | * This product includes cryptographic software written by Eric Young | ||
| 109 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 110 | * Hudson (tjh@cryptsoft.com). | ||
| 111 | * | ||
| 112 | */ | ||
| 58 | 113 | ||
| 114 | |||
| 115 | #ifdef REF_CHECK | ||
| 116 | # include <assert.h> | ||
| 117 | #endif | ||
| 59 | #include <stdio.h> | 118 | #include <stdio.h> |
| 60 | #include "objects.h" | 119 | #include <openssl/objects.h> |
| 61 | #include "lhash.h" | 120 | #include <openssl/lhash.h> |
| 121 | #include <openssl/x509v3.h> | ||
| 62 | #include "ssl_locl.h" | 122 | #include "ssl_locl.h" |
| 123 | #include "kssl_lcl.h" | ||
| 63 | 124 | ||
| 64 | char *SSL_version_str="SSLeay 0.9.0b 29-Jun-1998"; | 125 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; |
| 65 | |||
| 66 | static STACK *ssl_meth=NULL; | ||
| 67 | static STACK *ssl_ctx_meth=NULL; | ||
| 68 | static int ssl_meth_num=0; | ||
| 69 | static int ssl_ctx_meth_num=0; | ||
| 70 | 126 | ||
| 71 | SSL3_ENC_METHOD ssl3_undef_enc_method={ | 127 | OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={ |
| 72 | ssl_undefined_function, | 128 | /* evil casts, but these functions are only called if there's a library bug */ |
| 73 | ssl_undefined_function, | 129 | (int (*)(SSL *,int))ssl_undefined_function, |
| 74 | ssl_undefined_function, | 130 | (int (*)(SSL *, unsigned char *, int))ssl_undefined_function, |
| 75 | ssl_undefined_function, | ||
| 76 | ssl_undefined_function, | ||
| 77 | ssl_undefined_function, | 131 | ssl_undefined_function, |
| 132 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, | ||
| 133 | (int (*)(SSL*, int))ssl_undefined_function, | ||
| 134 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function | ||
| 78 | }; | 135 | }; |
| 79 | 136 | ||
| 80 | void SSL_clear(s) | 137 | int SSL_clear(SSL *s) |
| 81 | SSL *s; | ||
| 82 | { | 138 | { |
| 83 | int state; | ||
| 84 | 139 | ||
| 85 | if (s->method == NULL) return; | 140 | if (s->method == NULL) |
| 141 | { | ||
| 142 | SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED); | ||
| 143 | return(0); | ||
| 144 | } | ||
| 145 | |||
| 146 | if (ssl_clear_bad_session(s)) | ||
| 147 | { | ||
| 148 | SSL_SESSION_free(s->session); | ||
| 149 | s->session=NULL; | ||
| 150 | } | ||
| 86 | 151 | ||
| 87 | s->error=0; | 152 | s->error=0; |
| 88 | s->hit=0; | 153 | s->hit=0; |
| 154 | s->shutdown=0; | ||
| 89 | 155 | ||
| 156 | #if 0 /* Disabled since version 1.10 of this file (early return not | ||
| 157 | * needed because SSL_clear is not called when doing renegotiation) */ | ||
| 90 | /* This is set if we are doing dynamic renegotiation so keep | 158 | /* This is set if we are doing dynamic renegotiation so keep |
| 91 | * the old cipher. It is sort of a SSL_clear_lite :-) */ | 159 | * the old cipher. It is sort of a SSL_clear_lite :-) */ |
| 92 | if (s->new_session) return; | 160 | if (s->new_session) return(1); |
| 161 | #else | ||
| 162 | if (s->new_session) | ||
| 163 | { | ||
| 164 | SSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR); | ||
| 165 | return 0; | ||
| 166 | } | ||
| 167 | #endif | ||
| 93 | 168 | ||
| 94 | state=s->state; /* Keep to check if we throw away the session-id */ | ||
| 95 | s->type=0; | 169 | s->type=0; |
| 96 | 170 | ||
| 171 | s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT); | ||
| 172 | |||
| 97 | s->version=s->method->version; | 173 | s->version=s->method->version; |
| 174 | s->client_version=s->version; | ||
| 98 | s->rwstate=SSL_NOTHING; | 175 | s->rwstate=SSL_NOTHING; |
| 99 | s->state=SSL_ST_BEFORE; | ||
| 100 | s->rstate=SSL_ST_READ_HEADER; | 176 | s->rstate=SSL_ST_READ_HEADER; |
| 101 | s->read_ahead=s->ctx->default_read_ahead; | 177 | #if 0 |
| 102 | 178 | s->read_ahead=s->ctx->read_ahead; | |
| 103 | /* s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); */ | 179 | #endif |
| 104 | 180 | ||
| 105 | if (s->init_buf != NULL) | 181 | if (s->init_buf != NULL) |
| 106 | { | 182 | { |
| @@ -110,30 +186,34 @@ SSL *s; | |||
| 110 | 186 | ||
| 111 | ssl_clear_cipher_ctx(s); | 187 | ssl_clear_cipher_ctx(s); |
| 112 | 188 | ||
| 113 | if (ssl_clear_bad_session(s)) | ||
| 114 | { | ||
| 115 | SSL_SESSION_free(s->session); | ||
| 116 | s->session=NULL; | ||
| 117 | } | ||
| 118 | |||
| 119 | s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
| 120 | s->first_packet=0; | 189 | s->first_packet=0; |
| 121 | 190 | ||
| 122 | s->method->ssl_clear(s); | 191 | #if 1 |
| 192 | /* Check to see if we were changed into a different method, if | ||
| 193 | * so, revert back if we are not doing session-id reuse. */ | ||
| 194 | if (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method)) | ||
| 195 | { | ||
| 196 | s->method->ssl_free(s); | ||
| 197 | s->method=s->ctx->method; | ||
| 198 | if (!s->method->ssl_new(s)) | ||
| 199 | return(0); | ||
| 200 | } | ||
| 201 | else | ||
| 202 | #endif | ||
| 203 | s->method->ssl_clear(s); | ||
| 204 | return(1); | ||
| 123 | } | 205 | } |
| 124 | 206 | ||
| 125 | /* Used to change an SSL_CTXs default SSL method type */ | 207 | /** Used to change an SSL_CTXs default SSL method type */ |
| 126 | int SSL_CTX_set_ssl_version(ctx,meth) | 208 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth) |
| 127 | SSL_CTX *ctx; | ||
| 128 | SSL_METHOD *meth; | ||
| 129 | { | 209 | { |
| 130 | STACK *sk; | 210 | STACK_OF(SSL_CIPHER) *sk; |
| 131 | 211 | ||
| 132 | ctx->method=meth; | 212 | ctx->method=meth; |
| 133 | 213 | ||
| 134 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), | 214 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), |
| 135 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); | 215 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); |
| 136 | if ((sk == NULL) || (sk_num(sk) <= 0)) | 216 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) |
| 137 | { | 217 | { |
| 138 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | 218 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); |
| 139 | return(0); | 219 | return(0); |
| @@ -141,8 +221,7 @@ SSL_METHOD *meth; | |||
| 141 | return(1); | 221 | return(1); |
| 142 | } | 222 | } |
| 143 | 223 | ||
| 144 | SSL *SSL_new(ctx) | 224 | SSL *SSL_new(SSL_CTX *ctx) |
| 145 | SSL_CTX *ctx; | ||
| 146 | { | 225 | { |
| 147 | SSL *s; | 226 | SSL *s; |
| 148 | 227 | ||
| @@ -157,20 +236,50 @@ SSL_CTX *ctx; | |||
| 157 | return(NULL); | 236 | return(NULL); |
| 158 | } | 237 | } |
| 159 | 238 | ||
| 160 | s=(SSL *)Malloc(sizeof(SSL)); | 239 | s=(SSL *)OPENSSL_malloc(sizeof(SSL)); |
| 161 | if (s == NULL) goto err; | 240 | if (s == NULL) goto err; |
| 162 | memset(s,0,sizeof(SSL)); | 241 | memset(s,0,sizeof(SSL)); |
| 163 | 242 | ||
| 164 | if (ctx->default_cert != NULL) | 243 | #ifndef OPENSSL_NO_KRB5 |
| 165 | { | 244 | s->kssl_ctx = kssl_ctx_new(); |
| 166 | CRYPTO_add(&ctx->default_cert->references,1, | 245 | #endif /* OPENSSL_NO_KRB5 */ |
| 167 | CRYPTO_LOCK_SSL_CERT); | 246 | |
| 168 | s->cert=ctx->default_cert; | 247 | s->options=ctx->options; |
| 248 | s->mode=ctx->mode; | ||
| 249 | s->max_cert_list=ctx->max_cert_list; | ||
| 250 | |||
| 251 | if (ctx->cert != NULL) | ||
| 252 | { | ||
| 253 | /* Earlier library versions used to copy the pointer to | ||
| 254 | * the CERT, not its contents; only when setting new | ||
| 255 | * parameters for the per-SSL copy, ssl_cert_new would be | ||
| 256 | * called (and the direct reference to the per-SSL_CTX | ||
| 257 | * settings would be lost, but those still were indirectly | ||
| 258 | * accessed for various purposes, and for that reason they | ||
| 259 | * used to be known as s->ctx->default_cert). | ||
| 260 | * Now we don't look at the SSL_CTX's CERT after having | ||
| 261 | * duplicated it once. */ | ||
| 262 | |||
| 263 | s->cert = ssl_cert_dup(ctx->cert); | ||
| 264 | if (s->cert == NULL) | ||
| 265 | goto err; | ||
| 169 | } | 266 | } |
| 170 | else | 267 | else |
| 171 | s->cert=NULL; | 268 | s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */ |
| 172 | s->verify_mode=ctx->default_verify_mode; | 269 | |
| 270 | s->read_ahead=ctx->read_ahead; | ||
| 271 | s->msg_callback=ctx->msg_callback; | ||
| 272 | s->msg_callback_arg=ctx->msg_callback_arg; | ||
| 273 | s->verify_mode=ctx->verify_mode; | ||
| 274 | s->verify_depth=ctx->verify_depth; | ||
| 275 | s->sid_ctx_length=ctx->sid_ctx_length; | ||
| 276 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); | ||
| 173 | s->verify_callback=ctx->default_verify_callback; | 277 | s->verify_callback=ctx->default_verify_callback; |
| 278 | s->generate_session_id=ctx->generate_session_id; | ||
| 279 | s->purpose = ctx->purpose; | ||
| 280 | s->trust = ctx->trust; | ||
| 281 | s->quiet_shutdown=ctx->quiet_shutdown; | ||
| 282 | |||
| 174 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | 283 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); |
| 175 | s->ctx=ctx; | 284 | s->ctx=ctx; |
| 176 | 285 | ||
| @@ -179,30 +288,130 @@ SSL_CTX *ctx; | |||
| 179 | s->method=ctx->method; | 288 | s->method=ctx->method; |
| 180 | 289 | ||
| 181 | if (!s->method->ssl_new(s)) | 290 | if (!s->method->ssl_new(s)) |
| 182 | { | ||
| 183 | SSL_CTX_free(ctx); | ||
| 184 | Free(s); | ||
| 185 | goto err; | 291 | goto err; |
| 186 | } | ||
| 187 | 292 | ||
| 188 | s->quiet_shutdown=ctx->quiet_shutdown; | ||
| 189 | s->references=1; | 293 | s->references=1; |
| 190 | s->options=ctx->options; | 294 | s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1; |
| 295 | |||
| 191 | SSL_clear(s); | 296 | SSL_clear(s); |
| 192 | 297 | ||
| 193 | CRYPTO_new_ex_data(ssl_meth,(char *)s,&s->ex_data); | 298 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); |
| 194 | 299 | ||
| 195 | return(s); | 300 | return(s); |
| 196 | err: | 301 | err: |
| 302 | if (s != NULL) | ||
| 303 | { | ||
| 304 | if (s->cert != NULL) | ||
| 305 | ssl_cert_free(s->cert); | ||
| 306 | if (s->ctx != NULL) | ||
| 307 | SSL_CTX_free(s->ctx); /* decrement reference count */ | ||
| 308 | OPENSSL_free(s); | ||
| 309 | } | ||
| 197 | SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE); | 310 | SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE); |
| 198 | return(NULL); | 311 | return(NULL); |
| 199 | } | 312 | } |
| 200 | 313 | ||
| 201 | void SSL_free(s) | 314 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, |
| 202 | SSL *s; | 315 | unsigned int sid_ctx_len) |
| 316 | { | ||
| 317 | if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) | ||
| 318 | { | ||
| 319 | SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | ||
| 320 | return 0; | ||
| 321 | } | ||
| 322 | ctx->sid_ctx_length=sid_ctx_len; | ||
| 323 | memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len); | ||
| 324 | |||
| 325 | return 1; | ||
| 326 | } | ||
| 327 | |||
| 328 | int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx, | ||
| 329 | unsigned int sid_ctx_len) | ||
| 330 | { | ||
| 331 | if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) | ||
| 332 | { | ||
| 333 | SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | ||
| 334 | return 0; | ||
| 335 | } | ||
| 336 | ssl->sid_ctx_length=sid_ctx_len; | ||
| 337 | memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len); | ||
| 338 | |||
| 339 | return 1; | ||
| 340 | } | ||
| 341 | |||
| 342 | int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb) | ||
| 343 | { | ||
| 344 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 345 | ctx->generate_session_id = cb; | ||
| 346 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 347 | return 1; | ||
| 348 | } | ||
| 349 | |||
| 350 | int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb) | ||
| 351 | { | ||
| 352 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
| 353 | ssl->generate_session_id = cb; | ||
| 354 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
| 355 | return 1; | ||
| 356 | } | ||
| 357 | |||
| 358 | int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | ||
| 359 | unsigned int id_len) | ||
| 360 | { | ||
| 361 | /* A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how | ||
| 362 | * we can "construct" a session to give us the desired check - ie. to | ||
| 363 | * find if there's a session in the hash table that would conflict with | ||
| 364 | * any new session built out of this id/id_len and the ssl_version in | ||
| 365 | * use by this SSL. */ | ||
| 366 | SSL_SESSION r, *p; | ||
| 367 | r.ssl_version = ssl->version; | ||
| 368 | r.session_id_length = id_len; | ||
| 369 | memcpy(r.session_id, id, id_len); | ||
| 370 | /* NB: SSLv2 always uses a fixed 16-byte session ID, so even if a | ||
| 371 | * callback is calling us to check the uniqueness of a shorter ID, it | ||
| 372 | * must be compared as a padded-out ID because that is what it will be | ||
| 373 | * converted to when the callback has finished choosing it. */ | ||
| 374 | if((r.ssl_version == SSL2_VERSION) && | ||
| 375 | (id_len < SSL2_SSL_SESSION_ID_LENGTH)) | ||
| 376 | { | ||
| 377 | memset(r.session_id + id_len, 0, | ||
| 378 | SSL2_SSL_SESSION_ID_LENGTH - id_len); | ||
| 379 | r.session_id_length = SSL2_SSL_SESSION_ID_LENGTH; | ||
| 380 | } | ||
| 381 | |||
| 382 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 383 | p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r); | ||
| 384 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 385 | return (p != NULL); | ||
| 386 | } | ||
| 387 | |||
| 388 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose) | ||
| 389 | { | ||
| 390 | return X509_PURPOSE_set(&s->purpose, purpose); | ||
| 391 | } | ||
| 392 | |||
| 393 | int SSL_set_purpose(SSL *s, int purpose) | ||
| 394 | { | ||
| 395 | return X509_PURPOSE_set(&s->purpose, purpose); | ||
| 396 | } | ||
| 397 | |||
| 398 | int SSL_CTX_set_trust(SSL_CTX *s, int trust) | ||
| 399 | { | ||
| 400 | return X509_TRUST_set(&s->trust, trust); | ||
| 401 | } | ||
| 402 | |||
| 403 | int SSL_set_trust(SSL *s, int trust) | ||
| 404 | { | ||
| 405 | return X509_TRUST_set(&s->trust, trust); | ||
| 406 | } | ||
| 407 | |||
| 408 | void SSL_free(SSL *s) | ||
| 203 | { | 409 | { |
| 204 | int i; | 410 | int i; |
| 205 | 411 | ||
| 412 | if(s == NULL) | ||
| 413 | return; | ||
| 414 | |||
| 206 | i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL); | 415 | i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL); |
| 207 | #ifdef REF_PRINT | 416 | #ifdef REF_PRINT |
| 208 | REF_PRINT("SSL",s); | 417 | REF_PRINT("SSL",s); |
| @@ -216,7 +425,7 @@ SSL *s; | |||
| 216 | } | 425 | } |
| 217 | #endif | 426 | #endif |
| 218 | 427 | ||
| 219 | CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data); | 428 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); |
| 220 | 429 | ||
| 221 | if (s->bbio != NULL) | 430 | if (s->bbio != NULL) |
| 222 | { | 431 | { |
| @@ -236,8 +445,8 @@ SSL *s; | |||
| 236 | if (s->init_buf != NULL) BUF_MEM_free(s->init_buf); | 445 | if (s->init_buf != NULL) BUF_MEM_free(s->init_buf); |
| 237 | 446 | ||
| 238 | /* add extra stuff */ | 447 | /* add extra stuff */ |
| 239 | if (s->cipher_list != NULL) sk_free(s->cipher_list); | 448 | if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list); |
| 240 | if (s->cipher_list_by_id != NULL) sk_free(s->cipher_list_by_id); | 449 | if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id); |
| 241 | 450 | ||
| 242 | /* Make the next call work :-) */ | 451 | /* Make the next call work :-) */ |
| 243 | if (s->session != NULL) | 452 | if (s->session != NULL) |
| @@ -254,17 +463,14 @@ SSL *s; | |||
| 254 | if (s->ctx) SSL_CTX_free(s->ctx); | 463 | if (s->ctx) SSL_CTX_free(s->ctx); |
| 255 | 464 | ||
| 256 | if (s->client_CA != NULL) | 465 | if (s->client_CA != NULL) |
| 257 | sk_pop_free(s->client_CA,X509_NAME_free); | 466 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); |
| 258 | 467 | ||
| 259 | if (s->method != NULL) s->method->ssl_free(s); | 468 | if (s->method != NULL) s->method->ssl_free(s); |
| 260 | 469 | ||
| 261 | Free((char *)s); | 470 | OPENSSL_free(s); |
| 262 | } | 471 | } |
| 263 | 472 | ||
| 264 | void SSL_set_bio(s, rbio,wbio) | 473 | void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio) |
| 265 | SSL *s; | ||
| 266 | BIO *rbio; | ||
| 267 | BIO *wbio; | ||
| 268 | { | 474 | { |
| 269 | /* If the output buffering BIO is still in place, remove it | 475 | /* If the output buffering BIO is still in place, remove it |
| 270 | */ | 476 | */ |
| @@ -284,16 +490,18 @@ BIO *wbio; | |||
| 284 | s->wbio=wbio; | 490 | s->wbio=wbio; |
| 285 | } | 491 | } |
| 286 | 492 | ||
| 287 | BIO *SSL_get_rbio(s) | 493 | BIO *SSL_get_rbio(SSL *s) |
| 288 | SSL *s; | ||
| 289 | { return(s->rbio); } | 494 | { return(s->rbio); } |
| 290 | 495 | ||
| 291 | BIO *SSL_get_wbio(s) | 496 | BIO *SSL_get_wbio(SSL *s) |
| 292 | SSL *s; | ||
| 293 | { return(s->wbio); } | 497 | { return(s->wbio); } |
| 294 | 498 | ||
| 295 | int SSL_get_fd(s) | 499 | int SSL_get_fd(SSL *s) |
| 296 | SSL *s; | 500 | { |
| 501 | return(SSL_get_rfd(s)); | ||
| 502 | } | ||
| 503 | |||
| 504 | int SSL_get_rfd(SSL *s) | ||
| 297 | { | 505 | { |
| 298 | int ret= -1; | 506 | int ret= -1; |
| 299 | BIO *b,*r; | 507 | BIO *b,*r; |
| @@ -305,10 +513,20 @@ SSL *s; | |||
| 305 | return(ret); | 513 | return(ret); |
| 306 | } | 514 | } |
| 307 | 515 | ||
| 308 | #ifndef NO_SOCK | 516 | int SSL_get_wfd(SSL *s) |
| 309 | int SSL_set_fd(s, fd) | 517 | { |
| 310 | SSL *s; | 518 | int ret= -1; |
| 311 | int fd; | 519 | BIO *b,*r; |
| 520 | |||
| 521 | b=SSL_get_wbio(s); | ||
| 522 | r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR); | ||
| 523 | if (r != NULL) | ||
| 524 | BIO_get_fd(r,&ret); | ||
| 525 | return(ret); | ||
| 526 | } | ||
| 527 | |||
| 528 | #ifndef OPENSSL_NO_SOCK | ||
| 529 | int SSL_set_fd(SSL *s,int fd) | ||
| 312 | { | 530 | { |
| 313 | int ret=0; | 531 | int ret=0; |
| 314 | BIO *bio=NULL; | 532 | BIO *bio=NULL; |
| @@ -327,9 +545,7 @@ err: | |||
| 327 | return(ret); | 545 | return(ret); |
| 328 | } | 546 | } |
| 329 | 547 | ||
| 330 | int SSL_set_wfd(s, fd) | 548 | int SSL_set_wfd(SSL *s,int fd) |
| 331 | SSL *s; | ||
| 332 | int fd; | ||
| 333 | { | 549 | { |
| 334 | int ret=0; | 550 | int ret=0; |
| 335 | BIO *bio=NULL; | 551 | BIO *bio=NULL; |
| @@ -351,9 +567,7 @@ err: | |||
| 351 | return(ret); | 567 | return(ret); |
| 352 | } | 568 | } |
| 353 | 569 | ||
| 354 | int SSL_set_rfd(s, fd) | 570 | int SSL_set_rfd(SSL *s,int fd) |
| 355 | SSL *s; | ||
| 356 | int fd; | ||
| 357 | { | 571 | { |
| 358 | int ret=0; | 572 | int ret=0; |
| 359 | BIO *bio=NULL; | 573 | BIO *bio=NULL; |
| @@ -379,61 +593,104 @@ err: | |||
| 379 | } | 593 | } |
| 380 | #endif | 594 | #endif |
| 381 | 595 | ||
| 382 | int SSL_get_verify_mode(s) | 596 | |
| 383 | SSL *s; | 597 | /* return length of latest Finished message we sent, copy to 'buf' */ |
| 598 | size_t SSL_get_finished(SSL *s, void *buf, size_t count) | ||
| 599 | { | ||
| 600 | size_t ret = 0; | ||
| 601 | |||
| 602 | if (s->s3 != NULL) | ||
| 603 | { | ||
| 604 | ret = s->s3->tmp.finish_md_len; | ||
| 605 | if (count > ret) | ||
| 606 | count = ret; | ||
| 607 | memcpy(buf, s->s3->tmp.finish_md, count); | ||
| 608 | } | ||
| 609 | return ret; | ||
| 610 | } | ||
| 611 | |||
| 612 | /* return length of latest Finished message we expected, copy to 'buf' */ | ||
| 613 | size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count) | ||
| 614 | { | ||
| 615 | size_t ret = 0; | ||
| 616 | |||
| 617 | if (s->s3 != NULL) | ||
| 618 | { | ||
| 619 | ret = s->s3->tmp.peer_finish_md_len; | ||
| 620 | if (count > ret) | ||
| 621 | count = ret; | ||
| 622 | memcpy(buf, s->s3->tmp.peer_finish_md, count); | ||
| 623 | } | ||
| 624 | return ret; | ||
| 625 | } | ||
| 626 | |||
| 627 | |||
| 628 | int SSL_get_verify_mode(SSL *s) | ||
| 384 | { | 629 | { |
| 385 | return(s->verify_mode); | 630 | return(s->verify_mode); |
| 386 | } | 631 | } |
| 387 | 632 | ||
| 388 | int (*SSL_get_verify_callback(s))() | 633 | int SSL_get_verify_depth(SSL *s) |
| 389 | SSL *s; | 634 | { |
| 635 | return(s->verify_depth); | ||
| 636 | } | ||
| 637 | |||
| 638 | int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *) | ||
| 390 | { | 639 | { |
| 391 | return(s->verify_callback); | 640 | return(s->verify_callback); |
| 392 | } | 641 | } |
| 393 | 642 | ||
| 394 | int SSL_CTX_get_verify_mode(ctx) | 643 | int SSL_CTX_get_verify_mode(SSL_CTX *ctx) |
| 395 | SSL_CTX *ctx; | ||
| 396 | { | 644 | { |
| 397 | return(ctx->default_verify_mode); | 645 | return(ctx->verify_mode); |
| 398 | } | 646 | } |
| 399 | 647 | ||
| 400 | int (*SSL_CTX_get_verify_callback(ctx))() | 648 | int SSL_CTX_get_verify_depth(SSL_CTX *ctx) |
| 401 | SSL_CTX *ctx; | 649 | { |
| 650 | return(ctx->verify_depth); | ||
| 651 | } | ||
| 652 | |||
| 653 | int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *) | ||
| 402 | { | 654 | { |
| 403 | return(ctx->default_verify_callback); | 655 | return(ctx->default_verify_callback); |
| 404 | } | 656 | } |
| 405 | 657 | ||
| 406 | void SSL_set_verify(s, mode, callback) | 658 | void SSL_set_verify(SSL *s,int mode, |
| 407 | SSL *s; | 659 | int (*callback)(int ok,X509_STORE_CTX *ctx)) |
| 408 | int mode; | ||
| 409 | int (*callback)(); | ||
| 410 | { | 660 | { |
| 411 | s->verify_mode=mode; | 661 | s->verify_mode=mode; |
| 412 | if (callback != NULL) | 662 | if (callback != NULL) |
| 413 | s->verify_callback=callback; | 663 | s->verify_callback=callback; |
| 414 | } | 664 | } |
| 415 | 665 | ||
| 416 | void SSL_set_read_ahead(s, yes) | 666 | void SSL_set_verify_depth(SSL *s,int depth) |
| 417 | SSL *s; | 667 | { |
| 418 | int yes; | 668 | s->verify_depth=depth; |
| 669 | } | ||
| 670 | |||
| 671 | void SSL_set_read_ahead(SSL *s,int yes) | ||
| 419 | { | 672 | { |
| 420 | s->read_ahead=yes; | 673 | s->read_ahead=yes; |
| 421 | } | 674 | } |
| 422 | 675 | ||
| 423 | int SSL_get_read_ahead(s) | 676 | int SSL_get_read_ahead(SSL *s) |
| 424 | SSL *s; | ||
| 425 | { | 677 | { |
| 426 | return(s->read_ahead); | 678 | return(s->read_ahead); |
| 427 | } | 679 | } |
| 428 | 680 | ||
| 429 | int SSL_pending(s) | 681 | int SSL_pending(SSL *s) |
| 430 | SSL *s; | ||
| 431 | { | 682 | { |
| 683 | /* SSL_pending cannot work properly if read-ahead is enabled | ||
| 684 | * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)), | ||
| 685 | * and it is impossible to fix since SSL_pending cannot report | ||
| 686 | * errors that may be observed while scanning the new data. | ||
| 687 | * (Note that SSL_pending() is often used as a boolean value, | ||
| 688 | * so we'd better not return -1.) | ||
| 689 | */ | ||
| 432 | return(s->method->ssl_pending(s)); | 690 | return(s->method->ssl_pending(s)); |
| 433 | } | 691 | } |
| 434 | 692 | ||
| 435 | X509 *SSL_get_peer_certificate(s) | 693 | X509 *SSL_get_peer_certificate(SSL *s) |
| 436 | SSL *s; | ||
| 437 | { | 694 | { |
| 438 | X509 *r; | 695 | X509 *r; |
| 439 | 696 | ||
| @@ -449,23 +706,24 @@ SSL *s; | |||
| 449 | return(r); | 706 | return(r); |
| 450 | } | 707 | } |
| 451 | 708 | ||
| 452 | STACK *SSL_get_peer_cert_chain(s) | 709 | STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s) |
| 453 | SSL *s; | ||
| 454 | { | 710 | { |
| 455 | STACK *r; | 711 | STACK_OF(X509) *r; |
| 456 | 712 | ||
| 457 | if ((s == NULL) || (s->session == NULL) || (s->session->cert == NULL)) | 713 | if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL)) |
| 458 | r=NULL; | 714 | r=NULL; |
| 459 | else | 715 | else |
| 460 | r=s->session->cert->cert_chain; | 716 | r=s->session->sess_cert->cert_chain; |
| 461 | 717 | ||
| 718 | /* If we are a client, cert_chain includes the peer's own | ||
| 719 | * certificate; if we are a server, it does not. */ | ||
| 720 | |||
| 462 | return(r); | 721 | return(r); |
| 463 | } | 722 | } |
| 464 | 723 | ||
| 465 | /* Now in theory, since the calling process own 't' it should be safe to | 724 | /* Now in theory, since the calling process own 't' it should be safe to |
| 466 | * modify. We need to be able to read f without being hassled */ | 725 | * modify. We need to be able to read f without being hassled */ |
| 467 | void SSL_copy_session_id(t,f) | 726 | void SSL_copy_session_id(SSL *t,SSL *f) |
| 468 | SSL *t,*f; | ||
| 469 | { | 727 | { |
| 470 | CERT *tmp; | 728 | CERT *tmp; |
| 471 | 729 | ||
| @@ -490,30 +748,29 @@ SSL *t,*f; | |||
| 490 | else | 748 | else |
| 491 | t->cert=NULL; | 749 | t->cert=NULL; |
| 492 | if (tmp != NULL) ssl_cert_free(tmp); | 750 | if (tmp != NULL) ssl_cert_free(tmp); |
| 751 | SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length); | ||
| 493 | } | 752 | } |
| 494 | 753 | ||
| 495 | /* Fix this so it checks all the valid key/cert options */ | 754 | /* Fix this so it checks all the valid key/cert options */ |
| 496 | int SSL_CTX_check_private_key(ctx) | 755 | int SSL_CTX_check_private_key(SSL_CTX *ctx) |
| 497 | SSL_CTX *ctx; | ||
| 498 | { | 756 | { |
| 499 | if ( (ctx == NULL) || | 757 | if ( (ctx == NULL) || |
| 500 | (ctx->default_cert == NULL) || | 758 | (ctx->cert == NULL) || |
| 501 | (ctx->default_cert->key->x509 == NULL)) | 759 | (ctx->cert->key->x509 == NULL)) |
| 502 | { | 760 | { |
| 503 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | 761 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); |
| 504 | return(0); | 762 | return(0); |
| 505 | } | 763 | } |
| 506 | if (ctx->default_cert->key->privatekey == NULL) | 764 | if (ctx->cert->key->privatekey == NULL) |
| 507 | { | 765 | { |
| 508 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | 766 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); |
| 509 | return(0); | 767 | return(0); |
| 510 | } | 768 | } |
| 511 | return(X509_check_private_key(ctx->default_cert->key->x509, ctx->default_cert->key->privatekey)); | 769 | return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey)); |
| 512 | } | 770 | } |
| 513 | 771 | ||
| 514 | /* Fix this function so that it takes an optional type parameter */ | 772 | /* Fix this function so that it takes an optional type parameter */ |
| 515 | int SSL_check_private_key(ssl) | 773 | int SSL_check_private_key(SSL *ssl) |
| 516 | SSL *ssl; | ||
| 517 | { | 774 | { |
| 518 | if (ssl == NULL) | 775 | if (ssl == NULL) |
| 519 | { | 776 | { |
| @@ -521,7 +778,10 @@ SSL *ssl; | |||
| 521 | return(0); | 778 | return(0); |
| 522 | } | 779 | } |
| 523 | if (ssl->cert == NULL) | 780 | if (ssl->cert == NULL) |
| 524 | return(SSL_CTX_check_private_key(ssl->ctx)); | 781 | { |
| 782 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
| 783 | return 0; | ||
| 784 | } | ||
| 525 | if (ssl->cert->key->x509 == NULL) | 785 | if (ssl->cert->key->x509 == NULL) |
| 526 | { | 786 | { |
| 527 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | 787 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); |
| @@ -536,29 +796,37 @@ SSL *ssl; | |||
| 536 | ssl->cert->key->privatekey)); | 796 | ssl->cert->key->privatekey)); |
| 537 | } | 797 | } |
| 538 | 798 | ||
| 539 | int SSL_accept(s) | 799 | int SSL_accept(SSL *s) |
| 540 | SSL *s; | ||
| 541 | { | 800 | { |
| 801 | if (s->handshake_func == 0) | ||
| 802 | /* Not properly initialized yet */ | ||
| 803 | SSL_set_accept_state(s); | ||
| 804 | |||
| 542 | return(s->method->ssl_accept(s)); | 805 | return(s->method->ssl_accept(s)); |
| 543 | } | 806 | } |
| 544 | 807 | ||
| 545 | int SSL_connect(s) | 808 | int SSL_connect(SSL *s) |
| 546 | SSL *s; | ||
| 547 | { | 809 | { |
| 810 | if (s->handshake_func == 0) | ||
| 811 | /* Not properly initialized yet */ | ||
| 812 | SSL_set_connect_state(s); | ||
| 813 | |||
| 548 | return(s->method->ssl_connect(s)); | 814 | return(s->method->ssl_connect(s)); |
| 549 | } | 815 | } |
| 550 | 816 | ||
| 551 | long SSL_get_default_timeout(s) | 817 | long SSL_get_default_timeout(SSL *s) |
| 552 | SSL *s; | ||
| 553 | { | 818 | { |
| 554 | return(s->method->get_timeout()); | 819 | return(s->method->get_timeout()); |
| 555 | } | 820 | } |
| 556 | 821 | ||
| 557 | int SSL_read(s,buf,num) | 822 | int SSL_read(SSL *s,void *buf,int num) |
| 558 | SSL *s; | ||
| 559 | char *buf; | ||
| 560 | int num; | ||
| 561 | { | 823 | { |
| 824 | if (s->handshake_func == 0) | ||
| 825 | { | ||
| 826 | SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED); | ||
| 827 | return -1; | ||
| 828 | } | ||
| 829 | |||
| 562 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | 830 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) |
| 563 | { | 831 | { |
| 564 | s->rwstate=SSL_NOTHING; | 832 | s->rwstate=SSL_NOTHING; |
| @@ -567,11 +835,14 @@ int num; | |||
| 567 | return(s->method->ssl_read(s,buf,num)); | 835 | return(s->method->ssl_read(s,buf,num)); |
| 568 | } | 836 | } |
| 569 | 837 | ||
| 570 | int SSL_peek(s,buf,num) | 838 | int SSL_peek(SSL *s,void *buf,int num) |
| 571 | SSL *s; | ||
| 572 | char *buf; | ||
| 573 | int num; | ||
| 574 | { | 839 | { |
| 840 | if (s->handshake_func == 0) | ||
| 841 | { | ||
| 842 | SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED); | ||
| 843 | return -1; | ||
| 844 | } | ||
| 845 | |||
| 575 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | 846 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) |
| 576 | { | 847 | { |
| 577 | return(0); | 848 | return(0); |
| @@ -579,11 +850,14 @@ int num; | |||
| 579 | return(s->method->ssl_peek(s,buf,num)); | 850 | return(s->method->ssl_peek(s,buf,num)); |
| 580 | } | 851 | } |
| 581 | 852 | ||
| 582 | int SSL_write(s,buf,num) | 853 | int SSL_write(SSL *s,const void *buf,int num) |
| 583 | SSL *s; | ||
| 584 | char *buf; | ||
| 585 | int num; | ||
| 586 | { | 854 | { |
| 855 | if (s->handshake_func == 0) | ||
| 856 | { | ||
| 857 | SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED); | ||
| 858 | return -1; | ||
| 859 | } | ||
| 860 | |||
| 587 | if (s->shutdown & SSL_SENT_SHUTDOWN) | 861 | if (s->shutdown & SSL_SENT_SHUTDOWN) |
| 588 | { | 862 | { |
| 589 | s->rwstate=SSL_NOTHING; | 863 | s->rwstate=SSL_NOTHING; |
| @@ -593,42 +867,176 @@ int num; | |||
| 593 | return(s->method->ssl_write(s,buf,num)); | 867 | return(s->method->ssl_write(s,buf,num)); |
| 594 | } | 868 | } |
| 595 | 869 | ||
| 596 | int SSL_shutdown(s) | 870 | int SSL_shutdown(SSL *s) |
| 597 | SSL *s; | ||
| 598 | { | 871 | { |
| 872 | /* Note that this function behaves differently from what one might | ||
| 873 | * expect. Return values are 0 for no success (yet), | ||
| 874 | * 1 for success; but calling it once is usually not enough, | ||
| 875 | * even if blocking I/O is used (see ssl3_shutdown). | ||
| 876 | */ | ||
| 877 | |||
| 878 | if (s->handshake_func == 0) | ||
| 879 | { | ||
| 880 | SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED); | ||
| 881 | return -1; | ||
| 882 | } | ||
| 883 | |||
| 599 | if ((s != NULL) && !SSL_in_init(s)) | 884 | if ((s != NULL) && !SSL_in_init(s)) |
| 600 | return(s->method->ssl_shutdown(s)); | 885 | return(s->method->ssl_shutdown(s)); |
| 601 | else | 886 | else |
| 602 | return(1); | 887 | return(1); |
| 603 | } | 888 | } |
| 604 | 889 | ||
| 605 | int SSL_renegotiate(s) | 890 | int SSL_renegotiate(SSL *s) |
| 606 | SSL *s; | ||
| 607 | { | 891 | { |
| 608 | s->new_session=1; | 892 | if (s->new_session == 0) |
| 893 | { | ||
| 894 | s->new_session=1; | ||
| 895 | } | ||
| 609 | return(s->method->ssl_renegotiate(s)); | 896 | return(s->method->ssl_renegotiate(s)); |
| 610 | } | 897 | } |
| 611 | 898 | ||
| 612 | long SSL_ctrl(s,cmd,larg,parg) | 899 | int SSL_renegotiate_pending(SSL *s) |
| 613 | SSL *s; | 900 | { |
| 614 | int cmd; | 901 | /* becomes true when negotiation is requested; |
| 615 | long larg; | 902 | * false again once a handshake has finished */ |
| 616 | char *parg; | 903 | return (s->new_session != 0); |
| 904 | } | ||
| 905 | |||
| 906 | long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | ||
| 617 | { | 907 | { |
| 618 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | 908 | long l; |
| 909 | |||
| 910 | switch (cmd) | ||
| 911 | { | ||
| 912 | case SSL_CTRL_GET_READ_AHEAD: | ||
| 913 | return(s->read_ahead); | ||
| 914 | case SSL_CTRL_SET_READ_AHEAD: | ||
| 915 | l=s->read_ahead; | ||
| 916 | s->read_ahead=larg; | ||
| 917 | return(l); | ||
| 918 | |||
| 919 | case SSL_CTRL_SET_MSG_CALLBACK_ARG: | ||
| 920 | s->msg_callback_arg = parg; | ||
| 921 | return 1; | ||
| 922 | |||
| 923 | case SSL_CTRL_OPTIONS: | ||
| 924 | return(s->options|=larg); | ||
| 925 | case SSL_CTRL_MODE: | ||
| 926 | return(s->mode|=larg); | ||
| 927 | case SSL_CTRL_GET_MAX_CERT_LIST: | ||
| 928 | return(s->max_cert_list); | ||
| 929 | case SSL_CTRL_SET_MAX_CERT_LIST: | ||
| 930 | l=s->max_cert_list; | ||
| 931 | s->max_cert_list=larg; | ||
| 932 | return(l); | ||
| 933 | default: | ||
| 934 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | ||
| 935 | } | ||
| 936 | } | ||
| 937 | |||
| 938 | long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)()) | ||
| 939 | { | ||
| 940 | switch(cmd) | ||
| 941 | { | ||
| 942 | case SSL_CTRL_SET_MSG_CALLBACK: | ||
| 943 | s->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp); | ||
| 944 | return 1; | ||
| 945 | |||
| 946 | default: | ||
| 947 | return(s->method->ssl_callback_ctrl(s,cmd,fp)); | ||
| 948 | } | ||
| 619 | } | 949 | } |
| 620 | 950 | ||
| 621 | long SSL_CTX_ctrl(ctx,cmd,larg,parg) | 951 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx) |
| 622 | SSL_CTX *ctx; | ||
| 623 | int cmd; | ||
| 624 | long larg; | ||
| 625 | char *parg; | ||
| 626 | { | 952 | { |
| 627 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | 953 | return ctx->sessions; |
| 628 | } | 954 | } |
| 629 | 955 | ||
| 630 | int ssl_cipher_id_cmp(a,b) | 956 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) |
| 631 | SSL_CIPHER *a,*b; | 957 | { |
| 958 | long l; | ||
| 959 | |||
| 960 | switch (cmd) | ||
| 961 | { | ||
| 962 | case SSL_CTRL_GET_READ_AHEAD: | ||
| 963 | return(ctx->read_ahead); | ||
| 964 | case SSL_CTRL_SET_READ_AHEAD: | ||
| 965 | l=ctx->read_ahead; | ||
| 966 | ctx->read_ahead=larg; | ||
| 967 | return(l); | ||
| 968 | |||
| 969 | case SSL_CTRL_SET_MSG_CALLBACK_ARG: | ||
| 970 | ctx->msg_callback_arg = parg; | ||
| 971 | return 1; | ||
| 972 | |||
| 973 | case SSL_CTRL_GET_MAX_CERT_LIST: | ||
| 974 | return(ctx->max_cert_list); | ||
| 975 | case SSL_CTRL_SET_MAX_CERT_LIST: | ||
| 976 | l=ctx->max_cert_list; | ||
| 977 | ctx->max_cert_list=larg; | ||
| 978 | return(l); | ||
| 979 | |||
| 980 | case SSL_CTRL_SET_SESS_CACHE_SIZE: | ||
| 981 | l=ctx->session_cache_size; | ||
| 982 | ctx->session_cache_size=larg; | ||
| 983 | return(l); | ||
| 984 | case SSL_CTRL_GET_SESS_CACHE_SIZE: | ||
| 985 | return(ctx->session_cache_size); | ||
| 986 | case SSL_CTRL_SET_SESS_CACHE_MODE: | ||
| 987 | l=ctx->session_cache_mode; | ||
| 988 | ctx->session_cache_mode=larg; | ||
| 989 | return(l); | ||
| 990 | case SSL_CTRL_GET_SESS_CACHE_MODE: | ||
| 991 | return(ctx->session_cache_mode); | ||
| 992 | |||
| 993 | case SSL_CTRL_SESS_NUMBER: | ||
| 994 | return(ctx->sessions->num_items); | ||
| 995 | case SSL_CTRL_SESS_CONNECT: | ||
| 996 | return(ctx->stats.sess_connect); | ||
| 997 | case SSL_CTRL_SESS_CONNECT_GOOD: | ||
| 998 | return(ctx->stats.sess_connect_good); | ||
| 999 | case SSL_CTRL_SESS_CONNECT_RENEGOTIATE: | ||
| 1000 | return(ctx->stats.sess_connect_renegotiate); | ||
| 1001 | case SSL_CTRL_SESS_ACCEPT: | ||
| 1002 | return(ctx->stats.sess_accept); | ||
| 1003 | case SSL_CTRL_SESS_ACCEPT_GOOD: | ||
| 1004 | return(ctx->stats.sess_accept_good); | ||
| 1005 | case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE: | ||
| 1006 | return(ctx->stats.sess_accept_renegotiate); | ||
| 1007 | case SSL_CTRL_SESS_HIT: | ||
| 1008 | return(ctx->stats.sess_hit); | ||
| 1009 | case SSL_CTRL_SESS_CB_HIT: | ||
| 1010 | return(ctx->stats.sess_cb_hit); | ||
| 1011 | case SSL_CTRL_SESS_MISSES: | ||
| 1012 | return(ctx->stats.sess_miss); | ||
| 1013 | case SSL_CTRL_SESS_TIMEOUTS: | ||
| 1014 | return(ctx->stats.sess_timeout); | ||
| 1015 | case SSL_CTRL_SESS_CACHE_FULL: | ||
| 1016 | return(ctx->stats.sess_cache_full); | ||
| 1017 | case SSL_CTRL_OPTIONS: | ||
| 1018 | return(ctx->options|=larg); | ||
| 1019 | case SSL_CTRL_MODE: | ||
| 1020 | return(ctx->mode|=larg); | ||
| 1021 | default: | ||
| 1022 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | ||
| 1023 | } | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | ||
| 1027 | { | ||
| 1028 | switch(cmd) | ||
| 1029 | { | ||
| 1030 | case SSL_CTRL_SET_MSG_CALLBACK: | ||
| 1031 | ctx->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp); | ||
| 1032 | return 1; | ||
| 1033 | |||
| 1034 | default: | ||
| 1035 | return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp)); | ||
| 1036 | } | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b) | ||
| 632 | { | 1040 | { |
| 633 | long l; | 1041 | long l; |
| 634 | 1042 | ||
| @@ -639,8 +1047,8 @@ SSL_CIPHER *a,*b; | |||
| 639 | return((l > 0)?1:-1); | 1047 | return((l > 0)?1:-1); |
| 640 | } | 1048 | } |
| 641 | 1049 | ||
| 642 | int ssl_cipher_ptr_id_cmp(ap,bp) | 1050 | int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, |
| 643 | SSL_CIPHER **ap,**bp; | 1051 | const SSL_CIPHER * const *bp) |
| 644 | { | 1052 | { |
| 645 | long l; | 1053 | long l; |
| 646 | 1054 | ||
| @@ -651,10 +1059,9 @@ SSL_CIPHER **ap,**bp; | |||
| 651 | return((l > 0)?1:-1); | 1059 | return((l > 0)?1:-1); |
| 652 | } | 1060 | } |
| 653 | 1061 | ||
| 654 | /* return a STACK of the ciphers available for the SSL and in order of | 1062 | /** return a STACK of the ciphers available for the SSL and in order of |
| 655 | * preference */ | 1063 | * preference */ |
| 656 | STACK *SSL_get_ciphers(s) | 1064 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s) |
| 657 | SSL *s; | ||
| 658 | { | 1065 | { |
| 659 | if ((s != NULL) && (s->cipher_list != NULL)) | 1066 | if ((s != NULL) && (s->cipher_list != NULL)) |
| 660 | { | 1067 | { |
| @@ -668,10 +1075,9 @@ SSL *s; | |||
| 668 | return(NULL); | 1075 | return(NULL); |
| 669 | } | 1076 | } |
| 670 | 1077 | ||
| 671 | /* return a STACK of the ciphers available for the SSL and in order of | 1078 | /** return a STACK of the ciphers available for the SSL and in order of |
| 672 | * algorithm id */ | 1079 | * algorithm id */ |
| 673 | STACK *ssl_get_ciphers_by_id(s) | 1080 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) |
| 674 | SSL *s; | ||
| 675 | { | 1081 | { |
| 676 | if ((s != NULL) && (s->cipher_list_by_id != NULL)) | 1082 | if ((s != NULL) && (s->cipher_list_by_id != NULL)) |
| 677 | { | 1083 | { |
| @@ -685,29 +1091,25 @@ SSL *s; | |||
| 685 | return(NULL); | 1091 | return(NULL); |
| 686 | } | 1092 | } |
| 687 | 1093 | ||
| 688 | /* The old interface to get the same thing as SSL_get_ciphers() */ | 1094 | /** The old interface to get the same thing as SSL_get_ciphers() */ |
| 689 | char *SSL_get_cipher_list(s,n) | 1095 | const char *SSL_get_cipher_list(SSL *s,int n) |
| 690 | SSL *s; | ||
| 691 | int n; | ||
| 692 | { | 1096 | { |
| 693 | SSL_CIPHER *c; | 1097 | SSL_CIPHER *c; |
| 694 | STACK *sk; | 1098 | STACK_OF(SSL_CIPHER) *sk; |
| 695 | 1099 | ||
| 696 | if (s == NULL) return(NULL); | 1100 | if (s == NULL) return(NULL); |
| 697 | sk=SSL_get_ciphers(s); | 1101 | sk=SSL_get_ciphers(s); |
| 698 | if ((sk == NULL) || (sk_num(sk) <= n)) | 1102 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n)) |
| 699 | return(NULL); | 1103 | return(NULL); |
| 700 | c=(SSL_CIPHER *)sk_value(sk,n); | 1104 | c=sk_SSL_CIPHER_value(sk,n); |
| 701 | if (c == NULL) return(NULL); | 1105 | if (c == NULL) return(NULL); |
| 702 | return(c->name); | 1106 | return(c->name); |
| 703 | } | 1107 | } |
| 704 | 1108 | ||
| 705 | /* specify the ciphers to be used by defaut by the SSL_CTX */ | 1109 | /** specify the ciphers to be used by default by the SSL_CTX */ |
| 706 | int SSL_CTX_set_cipher_list(ctx,str) | 1110 | int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) |
| 707 | SSL_CTX *ctx; | ||
| 708 | char *str; | ||
| 709 | { | 1111 | { |
| 710 | STACK *sk; | 1112 | STACK_OF(SSL_CIPHER) *sk; |
| 711 | 1113 | ||
| 712 | sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list, | 1114 | sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list, |
| 713 | &ctx->cipher_list_by_id,str); | 1115 | &ctx->cipher_list_by_id,str); |
| @@ -715,12 +1117,10 @@ char *str; | |||
| 715 | return((sk == NULL)?0:1); | 1117 | return((sk == NULL)?0:1); |
| 716 | } | 1118 | } |
| 717 | 1119 | ||
| 718 | /* specify the ciphers to be used by the SSL */ | 1120 | /** specify the ciphers to be used by the SSL */ |
| 719 | int SSL_set_cipher_list(s, str) | 1121 | int SSL_set_cipher_list(SSL *s,const char *str) |
| 720 | SSL *s; | ||
| 721 | char *str; | ||
| 722 | { | 1122 | { |
| 723 | STACK *sk; | 1123 | STACK_OF(SSL_CIPHER) *sk; |
| 724 | 1124 | ||
| 725 | sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list, | 1125 | sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list, |
| 726 | &s->cipher_list_by_id,str); | 1126 | &s->cipher_list_by_id,str); |
| @@ -729,13 +1129,11 @@ char *str; | |||
| 729 | } | 1129 | } |
| 730 | 1130 | ||
| 731 | /* works well for SSLv2, not so good for SSLv3 */ | 1131 | /* works well for SSLv2, not so good for SSLv3 */ |
| 732 | char *SSL_get_shared_ciphers(s,buf,len) | 1132 | char *SSL_get_shared_ciphers(SSL *s,char *buf,int len) |
| 733 | SSL *s; | ||
| 734 | char *buf; | ||
| 735 | int len; | ||
| 736 | { | 1133 | { |
| 737 | char *p,*cp; | 1134 | char *p; |
| 738 | STACK *sk; | 1135 | const char *cp; |
| 1136 | STACK_OF(SSL_CIPHER) *sk; | ||
| 739 | SSL_CIPHER *c; | 1137 | SSL_CIPHER *c; |
| 740 | int i; | 1138 | int i; |
| 741 | 1139 | ||
| @@ -745,11 +1143,11 @@ int len; | |||
| 745 | 1143 | ||
| 746 | p=buf; | 1144 | p=buf; |
| 747 | sk=s->session->ciphers; | 1145 | sk=s->session->ciphers; |
| 748 | for (i=0; i<sk_num(sk); i++) | 1146 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) |
| 749 | { | 1147 | { |
| 750 | /* Decrement for either the ':' or a '\0' */ | 1148 | /* Decrement for either the ':' or a '\0' */ |
| 751 | len--; | 1149 | len--; |
| 752 | c=(SSL_CIPHER *)sk_value(sk,i); | 1150 | c=sk_SSL_CIPHER_value(sk,i); |
| 753 | for (cp=c->name; *cp; ) | 1151 | for (cp=c->name; *cp; ) |
| 754 | { | 1152 | { |
| 755 | if (len-- == 0) | 1153 | if (len-- == 0) |
| @@ -766,35 +1164,36 @@ int len; | |||
| 766 | return(buf); | 1164 | return(buf); |
| 767 | } | 1165 | } |
| 768 | 1166 | ||
| 769 | int ssl_cipher_list_to_bytes(s,sk,p) | 1167 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p) |
| 770 | SSL *s; | ||
| 771 | STACK *sk; | ||
| 772 | unsigned char *p; | ||
| 773 | { | 1168 | { |
| 774 | int i,j=0; | 1169 | int i,j=0; |
| 775 | SSL_CIPHER *c; | 1170 | SSL_CIPHER *c; |
| 776 | unsigned char *q; | 1171 | unsigned char *q; |
| 1172 | #ifndef OPENSSL_NO_KRB5 | ||
| 1173 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); | ||
| 1174 | #endif /* OPENSSL_NO_KRB5 */ | ||
| 777 | 1175 | ||
| 778 | if (sk == NULL) return(0); | 1176 | if (sk == NULL) return(0); |
| 779 | q=p; | 1177 | q=p; |
| 780 | 1178 | ||
| 781 | for (i=0; i<sk_num(sk); i++) | 1179 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) |
| 782 | { | 1180 | { |
| 783 | c=(SSL_CIPHER *)sk_value(sk,i); | 1181 | c=sk_SSL_CIPHER_value(sk,i); |
| 1182 | #ifndef OPENSSL_NO_KRB5 | ||
| 1183 | if ((c->algorithms & SSL_KRB5) && nokrb5) | ||
| 1184 | continue; | ||
| 1185 | #endif /* OPENSSL_NO_KRB5 */ | ||
| 784 | j=ssl_put_cipher_by_char(s,c,p); | 1186 | j=ssl_put_cipher_by_char(s,c,p); |
| 785 | p+=j; | 1187 | p+=j; |
| 786 | } | 1188 | } |
| 787 | return(p-q); | 1189 | return(p-q); |
| 788 | } | 1190 | } |
| 789 | 1191 | ||
| 790 | STACK *ssl_bytes_to_cipher_list(s,p,num,skp) | 1192 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, |
| 791 | SSL *s; | 1193 | STACK_OF(SSL_CIPHER) **skp) |
| 792 | unsigned char *p; | ||
| 793 | int num; | ||
| 794 | STACK **skp; | ||
| 795 | { | 1194 | { |
| 796 | SSL_CIPHER *c; | 1195 | SSL_CIPHER *c; |
| 797 | STACK *sk; | 1196 | STACK_OF(SSL_CIPHER) *sk; |
| 798 | int i,n; | 1197 | int i,n; |
| 799 | 1198 | ||
| 800 | n=ssl_put_cipher_by_char(s,NULL,NULL); | 1199 | n=ssl_put_cipher_by_char(s,NULL,NULL); |
| @@ -804,11 +1203,11 @@ STACK **skp; | |||
| 804 | return(NULL); | 1203 | return(NULL); |
| 805 | } | 1204 | } |
| 806 | if ((skp == NULL) || (*skp == NULL)) | 1205 | if ((skp == NULL) || (*skp == NULL)) |
| 807 | sk=sk_new(NULL); /* change perhaps later */ | 1206 | sk=sk_SSL_CIPHER_new_null(); /* change perhaps later */ |
| 808 | else | 1207 | else |
| 809 | { | 1208 | { |
| 810 | sk= *skp; | 1209 | sk= *skp; |
| 811 | sk_zero(sk); | 1210 | sk_SSL_CIPHER_zero(sk); |
| 812 | } | 1211 | } |
| 813 | 1212 | ||
| 814 | for (i=0; i<num; i+=n) | 1213 | for (i=0; i<num; i+=n) |
| @@ -817,7 +1216,7 @@ STACK **skp; | |||
| 817 | p+=n; | 1216 | p+=n; |
| 818 | if (c != NULL) | 1217 | if (c != NULL) |
| 819 | { | 1218 | { |
| 820 | if (!sk_push(sk,(char *)c)) | 1219 | if (!sk_SSL_CIPHER_push(sk,c)) |
| 821 | { | 1220 | { |
| 822 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | 1221 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE); |
| 823 | goto err; | 1222 | goto err; |
| @@ -830,23 +1229,28 @@ STACK **skp; | |||
| 830 | return(sk); | 1229 | return(sk); |
| 831 | err: | 1230 | err: |
| 832 | if ((skp == NULL) || (*skp == NULL)) | 1231 | if ((skp == NULL) || (*skp == NULL)) |
| 833 | sk_free(sk); | 1232 | sk_SSL_CIPHER_free(sk); |
| 834 | return(NULL); | 1233 | return(NULL); |
| 835 | } | 1234 | } |
| 836 | 1235 | ||
| 837 | unsigned long SSL_SESSION_hash(a) | 1236 | unsigned long SSL_SESSION_hash(SSL_SESSION *a) |
| 838 | SSL_SESSION *a; | ||
| 839 | { | 1237 | { |
| 840 | unsigned long l; | 1238 | unsigned long l; |
| 841 | 1239 | ||
| 842 | l= (a->session_id[0] )|(a->session_id[1]<< 8L)| | 1240 | l=(unsigned long) |
| 843 | (a->session_id[2]<<16L)|(a->session_id[3]<<24L); | 1241 | ((unsigned int) a->session_id[0] )| |
| 1242 | ((unsigned int) a->session_id[1]<< 8L)| | ||
| 1243 | ((unsigned long)a->session_id[2]<<16L)| | ||
| 1244 | ((unsigned long)a->session_id[3]<<24L); | ||
| 844 | return(l); | 1245 | return(l); |
| 845 | } | 1246 | } |
| 846 | 1247 | ||
| 847 | int SSL_SESSION_cmp(a, b) | 1248 | /* NB: If this function (or indeed the hash function which uses a sort of |
| 848 | SSL_SESSION *a; | 1249 | * coarser function than this one) is changed, ensure |
| 849 | SSL_SESSION *b; | 1250 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being |
| 1251 | * able to construct an SSL_SESSION that will collide with any existing session | ||
| 1252 | * with a matching session ID. */ | ||
| 1253 | int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b) | ||
| 850 | { | 1254 | { |
| 851 | if (a->ssl_version != b->ssl_version) | 1255 | if (a->ssl_version != b->ssl_version) |
| 852 | return(1); | 1256 | return(1); |
| @@ -855,17 +1259,29 @@ SSL_SESSION *b; | |||
| 855 | return(memcmp(a->session_id,b->session_id,a->session_id_length)); | 1259 | return(memcmp(a->session_id,b->session_id,a->session_id_length)); |
| 856 | } | 1260 | } |
| 857 | 1261 | ||
| 858 | SSL_CTX *SSL_CTX_new(meth) | 1262 | /* These wrapper functions should remain rather than redeclaring |
| 859 | SSL_METHOD *meth; | 1263 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each |
| 1264 | * variable. The reason is that the functions aren't static, they're exposed via | ||
| 1265 | * ssl.h. */ | ||
| 1266 | static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *) | ||
| 1267 | static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *) | ||
| 1268 | |||
| 1269 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | ||
| 860 | { | 1270 | { |
| 861 | SSL_CTX *ret; | 1271 | SSL_CTX *ret=NULL; |
| 862 | 1272 | ||
| 863 | if (meth == NULL) | 1273 | if (meth == NULL) |
| 864 | { | 1274 | { |
| 865 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | 1275 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); |
| 866 | return(NULL); | 1276 | return(NULL); |
| 867 | } | 1277 | } |
| 868 | ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX)); | 1278 | |
| 1279 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | ||
| 1280 | { | ||
| 1281 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | ||
| 1282 | goto err; | ||
| 1283 | } | ||
| 1284 | ret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX)); | ||
| 869 | if (ret == NULL) | 1285 | if (ret == NULL) |
| 870 | goto err; | 1286 | goto err; |
| 871 | 1287 | ||
| @@ -882,21 +1298,12 @@ SSL_METHOD *meth; | |||
| 882 | /* We take the system default */ | 1298 | /* We take the system default */ |
| 883 | ret->session_timeout=meth->get_timeout(); | 1299 | ret->session_timeout=meth->get_timeout(); |
| 884 | 1300 | ||
| 885 | ret->new_session_cb=NULL; | 1301 | ret->new_session_cb=0; |
| 886 | ret->remove_session_cb=NULL; | 1302 | ret->remove_session_cb=0; |
| 887 | ret->get_session_cb=NULL; | 1303 | ret->get_session_cb=0; |
| 888 | 1304 | ret->generate_session_id=0; | |
| 889 | ret->sess_connect=0; | 1305 | |
| 890 | ret->sess_connect_good=0; | 1306 | memset((char *)&ret->stats,0,sizeof(ret->stats)); |
| 891 | ret->sess_accept=0; | ||
| 892 | ret->sess_accept_renegotiate=0; | ||
| 893 | ret->sess_connect_renegotiate=0; | ||
| 894 | ret->sess_accept_good=0; | ||
| 895 | ret->sess_miss=0; | ||
| 896 | ret->sess_timeout=0; | ||
| 897 | ret->sess_cache_full=0; | ||
| 898 | ret->sess_hit=0; | ||
| 899 | ret->sess_cb_hit=0; | ||
| 900 | 1307 | ||
| 901 | ret->references=1; | 1308 | ret->references=1; |
| 902 | ret->quiet_shutdown=0; | 1309 | ret->quiet_shutdown=0; |
| @@ -909,19 +1316,26 @@ SSL_METHOD *meth; | |||
| 909 | 1316 | ||
| 910 | ret->info_callback=NULL; | 1317 | ret->info_callback=NULL; |
| 911 | 1318 | ||
| 912 | ret->app_verify_callback=NULL; | 1319 | ret->app_verify_callback=0; |
| 913 | ret->app_verify_arg=NULL; | 1320 | ret->app_verify_arg=NULL; |
| 914 | 1321 | ||
| 915 | ret->default_read_ahead=0; | 1322 | ret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT; |
| 916 | ret->default_verify_mode=SSL_VERIFY_NONE; | 1323 | ret->read_ahead=0; |
| 1324 | ret->msg_callback=0; | ||
| 1325 | ret->msg_callback_arg=NULL; | ||
| 1326 | ret->verify_mode=SSL_VERIFY_NONE; | ||
| 1327 | ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */ | ||
| 1328 | ret->sid_ctx_length=0; | ||
| 917 | ret->default_verify_callback=NULL; | 1329 | ret->default_verify_callback=NULL; |
| 918 | if ((ret->default_cert=ssl_cert_new()) == NULL) | 1330 | if ((ret->cert=ssl_cert_new()) == NULL) |
| 919 | goto err; | 1331 | goto err; |
| 920 | 1332 | ||
| 921 | ret->default_passwd_callback=NULL; | 1333 | ret->default_passwd_callback=0; |
| 922 | ret->client_cert_cb=NULL; | 1334 | ret->default_passwd_callback_userdata=NULL; |
| 1335 | ret->client_cert_cb=0; | ||
| 923 | 1336 | ||
| 924 | ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp); | 1337 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), |
| 1338 | LHASH_COMP_FN(SSL_SESSION_cmp)); | ||
| 925 | if (ret->sessions == NULL) goto err; | 1339 | if (ret->sessions == NULL) goto err; |
| 926 | ret->cert_store=X509_STORE_new(); | 1340 | ret->cert_store=X509_STORE_new(); |
| 927 | if (ret->cert_store == NULL) goto err; | 1341 | if (ret->cert_store == NULL) goto err; |
| @@ -929,7 +1343,8 @@ SSL_METHOD *meth; | |||
| 929 | ssl_create_cipher_list(ret->method, | 1343 | ssl_create_cipher_list(ret->method, |
| 930 | &ret->cipher_list,&ret->cipher_list_by_id, | 1344 | &ret->cipher_list,&ret->cipher_list_by_id, |
| 931 | SSL_DEFAULT_CIPHER_LIST); | 1345 | SSL_DEFAULT_CIPHER_LIST); |
| 932 | if ((ret->cipher_list == NULL) || (sk_num(ret->cipher_list) <= 0)) | 1346 | if (ret->cipher_list == NULL |
| 1347 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) | ||
| 933 | { | 1348 | { |
| 934 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS); | 1349 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS); |
| 935 | goto err2; | 1350 | goto err2; |
| @@ -951,10 +1366,13 @@ SSL_METHOD *meth; | |||
| 951 | goto err2; | 1366 | goto err2; |
| 952 | } | 1367 | } |
| 953 | 1368 | ||
| 954 | if ((ret->client_CA=sk_new_null()) == NULL) | 1369 | if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL) |
| 955 | goto err; | 1370 | goto err; |
| 956 | 1371 | ||
| 957 | CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data); | 1372 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data); |
| 1373 | |||
| 1374 | ret->extra_certs=NULL; | ||
| 1375 | ret->comp_methods=SSL_COMP_get_compression_methods(); | ||
| 958 | 1376 | ||
| 959 | return(ret); | 1377 | return(ret); |
| 960 | err: | 1378 | err: |
| @@ -964,8 +1382,12 @@ err2: | |||
| 964 | return(NULL); | 1382 | return(NULL); |
| 965 | } | 1383 | } |
| 966 | 1384 | ||
| 967 | void SSL_CTX_free(a) | 1385 | #if 0 |
| 968 | SSL_CTX *a; | 1386 | static void SSL_COMP_free(SSL_COMP *comp) |
| 1387 | { OPENSSL_free(comp); } | ||
| 1388 | #endif | ||
| 1389 | |||
| 1390 | void SSL_CTX_free(SSL_CTX *a) | ||
| 969 | { | 1391 | { |
| 970 | int i; | 1392 | int i; |
| 971 | 1393 | ||
| @@ -983,7 +1405,7 @@ SSL_CTX *a; | |||
| 983 | abort(); /* ok */ | 1405 | abort(); /* ok */ |
| 984 | } | 1406 | } |
| 985 | #endif | 1407 | #endif |
| 986 | CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data); | 1408 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); |
| 987 | 1409 | ||
| 988 | if (a->sessions != NULL) | 1410 | if (a->sessions != NULL) |
| 989 | { | 1411 | { |
| @@ -993,96 +1415,105 @@ SSL_CTX *a; | |||
| 993 | if (a->cert_store != NULL) | 1415 | if (a->cert_store != NULL) |
| 994 | X509_STORE_free(a->cert_store); | 1416 | X509_STORE_free(a->cert_store); |
| 995 | if (a->cipher_list != NULL) | 1417 | if (a->cipher_list != NULL) |
| 996 | sk_free(a->cipher_list); | 1418 | sk_SSL_CIPHER_free(a->cipher_list); |
| 997 | if (a->cipher_list_by_id != NULL) | 1419 | if (a->cipher_list_by_id != NULL) |
| 998 | sk_free(a->cipher_list_by_id); | 1420 | sk_SSL_CIPHER_free(a->cipher_list_by_id); |
| 999 | if (a->default_cert != NULL) | 1421 | if (a->cert != NULL) |
| 1000 | ssl_cert_free(a->default_cert); | 1422 | ssl_cert_free(a->cert); |
| 1001 | if (a->client_CA != NULL) | 1423 | if (a->client_CA != NULL) |
| 1002 | sk_pop_free(a->client_CA,X509_NAME_free); | 1424 | sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free); |
| 1003 | Free((char *)a); | 1425 | if (a->extra_certs != NULL) |
| 1426 | sk_X509_pop_free(a->extra_certs,X509_free); | ||
| 1427 | #if 0 /* This should never be done, since it removes a global database */ | ||
| 1428 | if (a->comp_methods != NULL) | ||
| 1429 | sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free); | ||
| 1430 | #else | ||
| 1431 | a->comp_methods = NULL; | ||
| 1432 | #endif | ||
| 1433 | OPENSSL_free(a); | ||
| 1004 | } | 1434 | } |
| 1005 | 1435 | ||
| 1006 | void SSL_CTX_set_default_passwd_cb(ctx,cb) | 1436 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) |
| 1007 | SSL_CTX *ctx; | ||
| 1008 | int (*cb)(); | ||
| 1009 | { | 1437 | { |
| 1010 | ctx->default_passwd_callback=cb; | 1438 | ctx->default_passwd_callback=cb; |
| 1011 | } | 1439 | } |
| 1012 | 1440 | ||
| 1013 | void SSL_CTX_set_cert_verify_cb(ctx,cb,arg) | 1441 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u) |
| 1014 | SSL_CTX *ctx; | 1442 | { |
| 1015 | int (*cb)(); | 1443 | ctx->default_passwd_callback_userdata=u; |
| 1016 | char *arg; | 1444 | } |
| 1445 | |||
| 1446 | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg) | ||
| 1017 | { | 1447 | { |
| 1018 | ctx->app_verify_callback=cb; | 1448 | ctx->app_verify_callback=cb; |
| 1019 | ctx->app_verify_arg=arg; | 1449 | ctx->app_verify_arg=arg; |
| 1020 | } | 1450 | } |
| 1021 | 1451 | ||
| 1022 | void SSL_CTX_set_verify(ctx,mode,cb) | 1452 | void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *)) |
| 1023 | SSL_CTX *ctx; | ||
| 1024 | int mode; | ||
| 1025 | int (*cb)(); | ||
| 1026 | { | 1453 | { |
| 1027 | ctx->default_verify_mode=mode; | 1454 | ctx->verify_mode=mode; |
| 1028 | ctx->default_verify_callback=cb; | 1455 | ctx->default_verify_callback=cb; |
| 1029 | /* This needs cleaning up EAY EAY EAY */ | ||
| 1030 | X509_STORE_set_verify_cb_func(ctx->cert_store,cb); | ||
| 1031 | } | 1456 | } |
| 1032 | 1457 | ||
| 1033 | void ssl_set_cert_masks(c) | 1458 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) |
| 1034 | CERT *c; | 1459 | { |
| 1460 | ctx->verify_depth=depth; | ||
| 1461 | } | ||
| 1462 | |||
| 1463 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | ||
| 1035 | { | 1464 | { |
| 1036 | CERT_PKEY *cpk; | 1465 | CERT_PKEY *cpk; |
| 1037 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | 1466 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; |
| 1038 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | 1467 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; |
| 1039 | int rsa_tmp_export,dh_tmp_export; | 1468 | int rsa_tmp_export,dh_tmp_export,kl; |
| 1040 | unsigned long mask,emask; | 1469 | unsigned long mask,emask; |
| 1041 | 1470 | ||
| 1042 | if ((c == NULL) || (c->valid)) return; | 1471 | if (c == NULL) return; |
| 1043 | 1472 | ||
| 1044 | #ifndef NO_RSA | 1473 | kl=SSL_C_EXPORT_PKEYLENGTH(cipher); |
| 1045 | rsa_tmp=((c->rsa_tmp != NULL) || (c->rsa_tmp_cb != NULL))?1:0; | 1474 | |
| 1046 | rsa_tmp_export=((c->rsa_tmp_cb != NULL) || | 1475 | #ifndef OPENSSL_NO_RSA |
| 1047 | (rsa_tmp && (RSA_size(c->rsa_tmp)*8 <= 512)))?1:0; | 1476 | rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL); |
| 1477 | rsa_tmp_export=(c->rsa_tmp_cb != NULL || | ||
| 1478 | (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl)); | ||
| 1048 | #else | 1479 | #else |
| 1049 | rsa_tmp=rsa_tmp_export=0; | 1480 | rsa_tmp=rsa_tmp_export=0; |
| 1050 | #endif | 1481 | #endif |
| 1051 | #ifndef NO_DH | 1482 | #ifndef OPENSSL_NO_DH |
| 1052 | dh_tmp=((c->dh_tmp != NULL) || (c->dh_tmp_cb != NULL))?1:0; | 1483 | dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL); |
| 1053 | dh_tmp_export=((c->dh_tmp_cb != NULL) || | 1484 | dh_tmp_export=(c->dh_tmp_cb != NULL || |
| 1054 | (dh_tmp && (DH_size(c->dh_tmp)*8 <= 512)))?1:0; | 1485 | (dh_tmp && DH_size(c->dh_tmp)*8 <= kl)); |
| 1055 | #else | 1486 | #else |
| 1056 | dh_tmp=dh_tmp_export=0; | 1487 | dh_tmp=dh_tmp_export=0; |
| 1057 | #endif | 1488 | #endif |
| 1058 | 1489 | ||
| 1059 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); | 1490 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); |
| 1060 | rsa_enc= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | 1491 | rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1061 | rsa_enc_export=(rsa_enc && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0; | 1492 | rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
| 1062 | cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]); | 1493 | cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]); |
| 1063 | rsa_sign=((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | 1494 | rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1064 | cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]); | 1495 | cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]); |
| 1065 | dsa_sign=((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | 1496 | dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1066 | cpk= &(c->pkeys[SSL_PKEY_DH_RSA]); | 1497 | cpk= &(c->pkeys[SSL_PKEY_DH_RSA]); |
| 1067 | dh_rsa= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | 1498 | dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1068 | dh_rsa_export=(dh_rsa && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0; | 1499 | dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
| 1069 | cpk= &(c->pkeys[SSL_PKEY_DH_DSA]); | 1500 | cpk= &(c->pkeys[SSL_PKEY_DH_DSA]); |
| 1070 | /* FIX THIS EAY EAY EAY */ | 1501 | /* FIX THIS EAY EAY EAY */ |
| 1071 | dh_dsa= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | 1502 | dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1072 | dh_dsa_export=(dh_dsa && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0; | 1503 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
| 1073 | 1504 | ||
| 1074 | mask=0; | 1505 | mask=0; |
| 1075 | emask=0; | 1506 | emask=0; |
| 1076 | 1507 | ||
| 1077 | #ifdef CIPHER_DEBUG | 1508 | #ifdef CIPHER_DEBUG |
| 1078 | printf("rt=%d dht=%d re=%d rs=%d ds=%d dhr=%d dhd=%d\n", | 1509 | printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", |
| 1079 | rsa_tmp,dh_tmp, | 1510 | rsa_tmp,rsa_tmp_export,dh_tmp, |
| 1080 | rsa_enc,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | 1511 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); |
| 1081 | #endif | 1512 | #endif |
| 1082 | 1513 | ||
| 1083 | if (rsa_enc || (rsa_tmp && rsa_sign)) | 1514 | if (rsa_enc || (rsa_tmp && rsa_sign)) |
| 1084 | mask|=SSL_kRSA; | 1515 | mask|=SSL_kRSA; |
| 1085 | if (rsa_enc_export || (rsa_tmp_export && rsa_sign)) | 1516 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) |
| 1086 | emask|=SSL_kRSA; | 1517 | emask|=SSL_kRSA; |
| 1087 | 1518 | ||
| 1088 | #if 0 | 1519 | #if 0 |
| @@ -1119,9 +1550,12 @@ CERT *c; | |||
| 1119 | emask|=SSL_aDSS; | 1550 | emask|=SSL_aDSS; |
| 1120 | } | 1551 | } |
| 1121 | 1552 | ||
| 1122 | #ifdef SSL_ALLOW_ADH | ||
| 1123 | mask|=SSL_aNULL; | 1553 | mask|=SSL_aNULL; |
| 1124 | emask|=SSL_aNULL; | 1554 | emask|=SSL_aNULL; |
| 1555 | |||
| 1556 | #ifndef OPENSSL_NO_KRB5 | ||
| 1557 | mask|=SSL_kKRB5|SSL_aKRB5; | ||
| 1558 | emask|=SSL_kKRB5|SSL_aKRB5; | ||
| 1125 | #endif | 1559 | #endif |
| 1126 | 1560 | ||
| 1127 | c->mask=mask; | 1561 | c->mask=mask; |
| @@ -1130,18 +1564,17 @@ CERT *c; | |||
| 1130 | } | 1564 | } |
| 1131 | 1565 | ||
| 1132 | /* THIS NEEDS CLEANING UP */ | 1566 | /* THIS NEEDS CLEANING UP */ |
| 1133 | X509 *ssl_get_server_send_cert(s) | 1567 | X509 *ssl_get_server_send_cert(SSL *s) |
| 1134 | SSL *s; | ||
| 1135 | { | 1568 | { |
| 1136 | unsigned long alg,mask,kalg; | 1569 | unsigned long alg,mask,kalg; |
| 1137 | CERT *c; | 1570 | CERT *c; |
| 1138 | int i,export; | 1571 | int i,is_export; |
| 1139 | 1572 | ||
| 1140 | c=s->cert; | 1573 | c=s->cert; |
| 1141 | ssl_set_cert_masks(c); | 1574 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); |
| 1142 | alg=s->s3->tmp.new_cipher->algorithms; | 1575 | alg=s->s3->tmp.new_cipher->algorithms; |
| 1143 | export=(alg & SSL_EXPORT)?1:0; | 1576 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); |
| 1144 | mask=(export)?c->export_mask:c->mask; | 1577 | mask=is_export?c->export_mask:c->mask; |
| 1145 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | 1578 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); |
| 1146 | 1579 | ||
| 1147 | if (kalg & SSL_kDHr) | 1580 | if (kalg & SSL_kDHr) |
| @@ -1157,18 +1590,21 @@ SSL *s; | |||
| 1157 | else | 1590 | else |
| 1158 | i=SSL_PKEY_RSA_ENC; | 1591 | i=SSL_PKEY_RSA_ENC; |
| 1159 | } | 1592 | } |
| 1593 | else if (kalg & SSL_aKRB5) | ||
| 1594 | { | ||
| 1595 | /* VRS something else here? */ | ||
| 1596 | return(NULL); | ||
| 1597 | } | ||
| 1160 | else /* if (kalg & SSL_aNULL) */ | 1598 | else /* if (kalg & SSL_aNULL) */ |
| 1161 | { | 1599 | { |
| 1162 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR); | 1600 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); |
| 1163 | return(NULL); | 1601 | return(NULL); |
| 1164 | } | 1602 | } |
| 1165 | if (c->pkeys[i].x509 == NULL) return(NULL); | 1603 | if (c->pkeys[i].x509 == NULL) return(NULL); |
| 1166 | return(c->pkeys[i].x509); | 1604 | return(c->pkeys[i].x509); |
| 1167 | } | 1605 | } |
| 1168 | 1606 | ||
| 1169 | EVP_PKEY *ssl_get_sign_pkey(s,cipher) | 1607 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) |
| 1170 | SSL *s; | ||
| 1171 | SSL_CIPHER *cipher; | ||
| 1172 | { | 1608 | { |
| 1173 | unsigned long alg; | 1609 | unsigned long alg; |
| 1174 | CERT *c; | 1610 | CERT *c; |
| @@ -1190,14 +1626,12 @@ SSL_CIPHER *cipher; | |||
| 1190 | } | 1626 | } |
| 1191 | else /* if (alg & SSL_aNULL) */ | 1627 | else /* if (alg & SSL_aNULL) */ |
| 1192 | { | 1628 | { |
| 1193 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR); | 1629 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); |
| 1194 | return(NULL); | 1630 | return(NULL); |
| 1195 | } | 1631 | } |
| 1196 | } | 1632 | } |
| 1197 | 1633 | ||
| 1198 | void ssl_update_cache(s,mode) | 1634 | void ssl_update_cache(SSL *s,int mode) |
| 1199 | SSL *s; | ||
| 1200 | int mode; | ||
| 1201 | { | 1635 | { |
| 1202 | int i; | 1636 | int i; |
| 1203 | 1637 | ||
| @@ -1205,9 +1639,10 @@ int mode; | |||
| 1205 | * and it would be rather hard to do anyway :-) */ | 1639 | * and it would be rather hard to do anyway :-) */ |
| 1206 | if (s->session->session_id_length == 0) return; | 1640 | if (s->session->session_id_length == 0) return; |
| 1207 | 1641 | ||
| 1208 | if ((s->ctx->session_cache_mode & mode) | 1642 | i=s->ctx->session_cache_mode; |
| 1209 | && (!s->hit) | 1643 | if ((i & mode) && (!s->hit) |
| 1210 | && SSL_CTX_add_session(s->ctx,s->session) | 1644 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP) |
| 1645 | || SSL_CTX_add_session(s->ctx,s->session)) | ||
| 1211 | && (s->ctx->new_session_cb != NULL)) | 1646 | && (s->ctx->new_session_cb != NULL)) |
| 1212 | { | 1647 | { |
| 1213 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | 1648 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); |
| @@ -1216,28 +1651,24 @@ int mode; | |||
| 1216 | } | 1651 | } |
| 1217 | 1652 | ||
| 1218 | /* auto flush every 255 connections */ | 1653 | /* auto flush every 255 connections */ |
| 1219 | i=s->ctx->session_cache_mode; | ||
| 1220 | if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) && | 1654 | if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) && |
| 1221 | ((i & mode) == mode)) | 1655 | ((i & mode) == mode)) |
| 1222 | { | 1656 | { |
| 1223 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | 1657 | if ( (((mode & SSL_SESS_CACHE_CLIENT) |
| 1224 | ?s->ctx->sess_connect_good | 1658 | ?s->ctx->stats.sess_connect_good |
| 1225 | :s->ctx->sess_accept_good) & 0xff) == 0xff) | 1659 | :s->ctx->stats.sess_accept_good) & 0xff) == 0xff) |
| 1226 | { | 1660 | { |
| 1227 | SSL_CTX_flush_sessions(s->ctx,time(NULL)); | 1661 | SSL_CTX_flush_sessions(s->ctx,time(NULL)); |
| 1228 | } | 1662 | } |
| 1229 | } | 1663 | } |
| 1230 | } | 1664 | } |
| 1231 | 1665 | ||
| 1232 | SSL_METHOD *SSL_get_ssl_method(s) | 1666 | SSL_METHOD *SSL_get_ssl_method(SSL *s) |
| 1233 | SSL *s; | ||
| 1234 | { | 1667 | { |
| 1235 | return(s->method); | 1668 | return(s->method); |
| 1236 | } | 1669 | } |
| 1237 | 1670 | ||
| 1238 | int SSL_set_ssl_method(s,meth) | 1671 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth) |
| 1239 | SSL *s; | ||
| 1240 | SSL_METHOD *meth; | ||
| 1241 | { | 1672 | { |
| 1242 | int conn= -1; | 1673 | int conn= -1; |
| 1243 | int ret=1; | 1674 | int ret=1; |
| @@ -1264,17 +1695,23 @@ SSL_METHOD *meth; | |||
| 1264 | return(ret); | 1695 | return(ret); |
| 1265 | } | 1696 | } |
| 1266 | 1697 | ||
| 1267 | int SSL_get_error(s,i) | 1698 | int SSL_get_error(SSL *s,int i) |
| 1268 | SSL *s; | ||
| 1269 | int i; | ||
| 1270 | { | 1699 | { |
| 1271 | int reason; | 1700 | int reason; |
| 1701 | unsigned long l; | ||
| 1272 | BIO *bio; | 1702 | BIO *bio; |
| 1273 | 1703 | ||
| 1274 | if (i > 0) return(SSL_ERROR_NONE); | 1704 | if (i > 0) return(SSL_ERROR_NONE); |
| 1275 | 1705 | ||
| 1276 | if (ERR_peek_error() != 0) | 1706 | /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake |
| 1277 | return(SSL_ERROR_SSL); | 1707 | * etc, where we do encode the error */ |
| 1708 | if ((l=ERR_peek_error()) != 0) | ||
| 1709 | { | ||
| 1710 | if (ERR_GET_LIB(l) == ERR_LIB_SYS) | ||
| 1711 | return(SSL_ERROR_SYSCALL); | ||
| 1712 | else | ||
| 1713 | return(SSL_ERROR_SSL); | ||
| 1714 | } | ||
| 1278 | 1715 | ||
| 1279 | if ((i < 0) && SSL_want_read(s)) | 1716 | if ((i < 0) && SSL_want_read(s)) |
| 1280 | { | 1717 | { |
| @@ -1282,12 +1719,23 @@ int i; | |||
| 1282 | if (BIO_should_read(bio)) | 1719 | if (BIO_should_read(bio)) |
| 1283 | return(SSL_ERROR_WANT_READ); | 1720 | return(SSL_ERROR_WANT_READ); |
| 1284 | else if (BIO_should_write(bio)) | 1721 | else if (BIO_should_write(bio)) |
| 1722 | /* This one doesn't make too much sense ... We never try | ||
| 1723 | * to write to the rbio, and an application program where | ||
| 1724 | * rbio and wbio are separate couldn't even know what it | ||
| 1725 | * should wait for. | ||
| 1726 | * However if we ever set s->rwstate incorrectly | ||
| 1727 | * (so that we have SSL_want_read(s) instead of | ||
| 1728 | * SSL_want_write(s)) and rbio and wbio *are* the same, | ||
| 1729 | * this test works around that bug; so it might be safer | ||
| 1730 | * to keep it. */ | ||
| 1285 | return(SSL_ERROR_WANT_WRITE); | 1731 | return(SSL_ERROR_WANT_WRITE); |
| 1286 | else if (BIO_should_io_special(bio)) | 1732 | else if (BIO_should_io_special(bio)) |
| 1287 | { | 1733 | { |
| 1288 | reason=BIO_get_retry_reason(bio); | 1734 | reason=BIO_get_retry_reason(bio); |
| 1289 | if (reason == BIO_RR_CONNECT) | 1735 | if (reason == BIO_RR_CONNECT) |
| 1290 | return(SSL_ERROR_WANT_CONNECT); | 1736 | return(SSL_ERROR_WANT_CONNECT); |
| 1737 | else if (reason == BIO_RR_ACCEPT) | ||
| 1738 | return(SSL_ERROR_WANT_ACCEPT); | ||
| 1291 | else | 1739 | else |
| 1292 | return(SSL_ERROR_SYSCALL); /* unknown */ | 1740 | return(SSL_ERROR_SYSCALL); /* unknown */ |
| 1293 | } | 1741 | } |
| @@ -1299,12 +1747,15 @@ int i; | |||
| 1299 | if (BIO_should_write(bio)) | 1747 | if (BIO_should_write(bio)) |
| 1300 | return(SSL_ERROR_WANT_WRITE); | 1748 | return(SSL_ERROR_WANT_WRITE); |
| 1301 | else if (BIO_should_read(bio)) | 1749 | else if (BIO_should_read(bio)) |
| 1750 | /* See above (SSL_want_read(s) with BIO_should_write(bio)) */ | ||
| 1302 | return(SSL_ERROR_WANT_READ); | 1751 | return(SSL_ERROR_WANT_READ); |
| 1303 | else if (BIO_should_io_special(bio)) | 1752 | else if (BIO_should_io_special(bio)) |
| 1304 | { | 1753 | { |
| 1305 | reason=BIO_get_retry_reason(bio); | 1754 | reason=BIO_get_retry_reason(bio); |
| 1306 | if (reason == BIO_RR_CONNECT) | 1755 | if (reason == BIO_RR_CONNECT) |
| 1307 | return(SSL_ERROR_WANT_CONNECT); | 1756 | return(SSL_ERROR_WANT_CONNECT); |
| 1757 | else if (reason == BIO_RR_ACCEPT) | ||
| 1758 | return(SSL_ERROR_WANT_ACCEPT); | ||
| 1308 | else | 1759 | else |
| 1309 | return(SSL_ERROR_SYSCALL); | 1760 | return(SSL_ERROR_SYSCALL); |
| 1310 | } | 1761 | } |
| @@ -1331,8 +1782,7 @@ int i; | |||
| 1331 | return(SSL_ERROR_SYSCALL); | 1782 | return(SSL_ERROR_SYSCALL); |
| 1332 | } | 1783 | } |
| 1333 | 1784 | ||
| 1334 | int SSL_do_handshake(s) | 1785 | int SSL_do_handshake(SSL *s) |
| 1335 | SSL *s; | ||
| 1336 | { | 1786 | { |
| 1337 | int ret=1; | 1787 | int ret=1; |
| 1338 | 1788 | ||
| @@ -1341,7 +1791,9 @@ SSL *s; | |||
| 1341 | SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET); | 1791 | SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET); |
| 1342 | return(-1); | 1792 | return(-1); |
| 1343 | } | 1793 | } |
| 1344 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | 1794 | |
| 1795 | s->method->ssl_renegotiate_check(s); | ||
| 1796 | |||
| 1345 | if (SSL_in_init(s) || SSL_in_before(s)) | 1797 | if (SSL_in_init(s) || SSL_in_before(s)) |
| 1346 | { | 1798 | { |
| 1347 | ret=s->handshake_func(s); | 1799 | ret=s->handshake_func(s); |
| @@ -1351,9 +1803,9 @@ SSL *s; | |||
| 1351 | 1803 | ||
| 1352 | /* For the next 2 functions, SSL_clear() sets shutdown and so | 1804 | /* For the next 2 functions, SSL_clear() sets shutdown and so |
| 1353 | * one of these calls will reset it */ | 1805 | * one of these calls will reset it */ |
| 1354 | void SSL_set_accept_state(s) | 1806 | void SSL_set_accept_state(SSL *s) |
| 1355 | SSL *s; | ||
| 1356 | { | 1807 | { |
| 1808 | s->server=1; | ||
| 1357 | s->shutdown=0; | 1809 | s->shutdown=0; |
| 1358 | s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE; | 1810 | s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE; |
| 1359 | s->handshake_func=s->method->ssl_accept; | 1811 | s->handshake_func=s->method->ssl_accept; |
| @@ -1361,9 +1813,9 @@ SSL *s; | |||
| 1361 | ssl_clear_cipher_ctx(s); | 1813 | ssl_clear_cipher_ctx(s); |
| 1362 | } | 1814 | } |
| 1363 | 1815 | ||
| 1364 | void SSL_set_connect_state(s) | 1816 | void SSL_set_connect_state(SSL *s) |
| 1365 | SSL *s; | ||
| 1366 | { | 1817 | { |
| 1818 | s->server=0; | ||
| 1367 | s->shutdown=0; | 1819 | s->shutdown=0; |
| 1368 | s->state=SSL_ST_CONNECT|SSL_ST_BEFORE; | 1820 | s->state=SSL_ST_CONNECT|SSL_ST_BEFORE; |
| 1369 | s->handshake_func=s->method->ssl_connect; | 1821 | s->handshake_func=s->method->ssl_connect; |
| @@ -1371,22 +1823,19 @@ SSL *s; | |||
| 1371 | ssl_clear_cipher_ctx(s); | 1823 | ssl_clear_cipher_ctx(s); |
| 1372 | } | 1824 | } |
| 1373 | 1825 | ||
| 1374 | int ssl_undefined_function(s) | 1826 | int ssl_undefined_function(SSL *s) |
| 1375 | SSL *s; | ||
| 1376 | { | 1827 | { |
| 1377 | SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 1828 | SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 1378 | return(0); | 1829 | return(0); |
| 1379 | } | 1830 | } |
| 1380 | 1831 | ||
| 1381 | SSL_METHOD *ssl_bad_method(ver) | 1832 | SSL_METHOD *ssl_bad_method(int ver) |
| 1382 | int ver; | ||
| 1383 | { | 1833 | { |
| 1384 | SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 1834 | SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 1385 | return(NULL); | 1835 | return(NULL); |
| 1386 | } | 1836 | } |
| 1387 | 1837 | ||
| 1388 | char *SSL_get_version(s) | 1838 | const char *SSL_get_version(SSL *s) |
| 1389 | SSL *s; | ||
| 1390 | { | 1839 | { |
| 1391 | if (s->version == TLS1_VERSION) | 1840 | if (s->version == TLS1_VERSION) |
| 1392 | return("TLSv1"); | 1841 | return("TLSv1"); |
| @@ -1398,30 +1847,67 @@ SSL *s; | |||
| 1398 | return("unknown"); | 1847 | return("unknown"); |
| 1399 | } | 1848 | } |
| 1400 | 1849 | ||
| 1401 | SSL *SSL_dup(s) | 1850 | SSL *SSL_dup(SSL *s) |
| 1402 | SSL *s; | 1851 | { |
| 1403 | { | 1852 | STACK_OF(X509_NAME) *sk; |
| 1404 | STACK *sk; | ||
| 1405 | X509_NAME *xn; | 1853 | X509_NAME *xn; |
| 1406 | SSL *ret; | 1854 | SSL *ret; |
| 1407 | int i; | 1855 | int i; |
| 1408 | 1856 | ||
| 1409 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) return(NULL); | 1857 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) |
| 1410 | 1858 | return(NULL); | |
| 1411 | /* This copies version, session-id, SSL_METHOD and 'cert' */ | 1859 | |
| 1412 | SSL_copy_session_id(ret,s); | 1860 | ret->version = s->version; |
| 1861 | ret->type = s->type; | ||
| 1862 | ret->method = s->method; | ||
| 1863 | |||
| 1864 | if (s->session != NULL) | ||
| 1865 | { | ||
| 1866 | /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */ | ||
| 1867 | SSL_copy_session_id(ret,s); | ||
| 1868 | } | ||
| 1869 | else | ||
| 1870 | { | ||
| 1871 | /* No session has been established yet, so we have to expect | ||
| 1872 | * that s->cert or ret->cert will be changed later -- | ||
| 1873 | * they should not both point to the same object, | ||
| 1874 | * and thus we can't use SSL_copy_session_id. */ | ||
| 1413 | 1875 | ||
| 1876 | ret->method = s->method; | ||
| 1877 | ret->method->ssl_new(ret); | ||
| 1878 | |||
| 1879 | if (s->cert != NULL) | ||
| 1880 | { | ||
| 1881 | if (ret->cert != NULL) | ||
| 1882 | { | ||
| 1883 | ssl_cert_free(ret->cert); | ||
| 1884 | } | ||
| 1885 | ret->cert = ssl_cert_dup(s->cert); | ||
| 1886 | if (ret->cert == NULL) | ||
| 1887 | goto err; | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | SSL_set_session_id_context(ret, | ||
| 1891 | s->sid_ctx, s->sid_ctx_length); | ||
| 1892 | } | ||
| 1893 | |||
| 1894 | ret->options=s->options; | ||
| 1895 | ret->mode=s->mode; | ||
| 1896 | SSL_set_max_cert_list(ret,SSL_get_max_cert_list(s)); | ||
| 1414 | SSL_set_read_ahead(ret,SSL_get_read_ahead(s)); | 1897 | SSL_set_read_ahead(ret,SSL_get_read_ahead(s)); |
| 1898 | ret->msg_callback = s->msg_callback; | ||
| 1899 | ret->msg_callback_arg = s->msg_callback_arg; | ||
| 1415 | SSL_set_verify(ret,SSL_get_verify_mode(s), | 1900 | SSL_set_verify(ret,SSL_get_verify_mode(s), |
| 1416 | SSL_get_verify_callback(s)); | 1901 | SSL_get_verify_callback(s)); |
| 1902 | SSL_set_verify_depth(ret,SSL_get_verify_depth(s)); | ||
| 1903 | ret->generate_session_id = s->generate_session_id; | ||
| 1417 | 1904 | ||
| 1418 | SSL_set_info_callback(ret,SSL_get_info_callback(s)); | 1905 | SSL_set_info_callback(ret,SSL_get_info_callback(s)); |
| 1419 | 1906 | ||
| 1420 | ret->debug=s->debug; | 1907 | ret->debug=s->debug; |
| 1421 | ret->options=s->options; | ||
| 1422 | 1908 | ||
| 1423 | /* copy app data, a little dangerous perhaps */ | 1909 | /* copy app data, a little dangerous perhaps */ |
| 1424 | if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data)) | 1910 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL, &ret->ex_data, &s->ex_data)) |
| 1425 | goto err; | 1911 | goto err; |
| 1426 | 1912 | ||
| 1427 | /* setup rbio, and wbio */ | 1913 | /* setup rbio, and wbio */ |
| @@ -1440,27 +1926,40 @@ SSL *s; | |||
| 1440 | else | 1926 | else |
| 1441 | ret->wbio=ret->rbio; | 1927 | ret->wbio=ret->rbio; |
| 1442 | } | 1928 | } |
| 1929 | ret->rwstate = s->rwstate; | ||
| 1930 | ret->in_handshake = s->in_handshake; | ||
| 1931 | ret->handshake_func = s->handshake_func; | ||
| 1932 | ret->server = s->server; | ||
| 1933 | ret->new_session = s->new_session; | ||
| 1934 | ret->quiet_shutdown = s->quiet_shutdown; | ||
| 1935 | ret->shutdown=s->shutdown; | ||
| 1936 | ret->state=s->state; /* SSL_dup does not really work at any state, though */ | ||
| 1937 | ret->rstate=s->rstate; | ||
| 1938 | ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */ | ||
| 1939 | ret->hit=s->hit; | ||
| 1940 | ret->purpose=s->purpose; | ||
| 1941 | ret->trust=s->trust; | ||
| 1443 | 1942 | ||
| 1444 | /* dup the cipher_list and cipher_list_by_id stacks */ | 1943 | /* dup the cipher_list and cipher_list_by_id stacks */ |
| 1445 | if (s->cipher_list != NULL) | 1944 | if (s->cipher_list != NULL) |
| 1446 | { | 1945 | { |
| 1447 | if ((ret->cipher_list=sk_dup(s->cipher_list)) == NULL) | 1946 | if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL) |
| 1448 | goto err; | 1947 | goto err; |
| 1449 | } | 1948 | } |
| 1450 | if (s->cipher_list_by_id != NULL) | 1949 | if (s->cipher_list_by_id != NULL) |
| 1451 | if ((ret->cipher_list_by_id=sk_dup(s->cipher_list_by_id)) | 1950 | if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id)) |
| 1452 | == NULL) | 1951 | == NULL) |
| 1453 | goto err; | 1952 | goto err; |
| 1454 | 1953 | ||
| 1455 | /* Dup the client_CA list */ | 1954 | /* Dup the client_CA list */ |
| 1456 | if (s->client_CA != NULL) | 1955 | if (s->client_CA != NULL) |
| 1457 | { | 1956 | { |
| 1458 | if ((sk=sk_dup(s->client_CA)) == NULL) goto err; | 1957 | if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err; |
| 1459 | ret->client_CA=sk; | 1958 | ret->client_CA=sk; |
| 1460 | for (i=0; i<sk_num(sk); i++) | 1959 | for (i=0; i<sk_X509_NAME_num(sk); i++) |
| 1461 | { | 1960 | { |
| 1462 | xn=(X509_NAME *)sk_value(sk,i); | 1961 | xn=sk_X509_NAME_value(sk,i); |
| 1463 | if ((sk_value(sk,i)=(char *)X509_NAME_dup(xn)) == NULL) | 1962 | if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL) |
| 1464 | { | 1963 | { |
| 1465 | X509_NAME_free(xn); | 1964 | X509_NAME_free(xn); |
| 1466 | goto err; | 1965 | goto err; |
| @@ -1468,10 +1967,6 @@ SSL *s; | |||
| 1468 | } | 1967 | } |
| 1469 | } | 1968 | } |
| 1470 | 1969 | ||
| 1471 | ret->shutdown=s->shutdown; | ||
| 1472 | ret->state=s->state; | ||
| 1473 | ret->handshake_func=s->handshake_func; | ||
| 1474 | |||
| 1475 | if (0) | 1970 | if (0) |
| 1476 | { | 1971 | { |
| 1477 | err: | 1972 | err: |
| @@ -1481,26 +1976,34 @@ err: | |||
| 1481 | return(ret); | 1976 | return(ret); |
| 1482 | } | 1977 | } |
| 1483 | 1978 | ||
| 1484 | void ssl_clear_cipher_ctx(s) | 1979 | void ssl_clear_cipher_ctx(SSL *s) |
| 1485 | SSL *s; | ||
| 1486 | { | 1980 | { |
| 1487 | if (s->enc_read_ctx != NULL) | 1981 | if (s->enc_read_ctx != NULL) |
| 1488 | { | 1982 | { |
| 1489 | EVP_CIPHER_CTX_cleanup(s->enc_read_ctx); | 1983 | EVP_CIPHER_CTX_cleanup(s->enc_read_ctx); |
| 1490 | Free(s->enc_read_ctx); | 1984 | OPENSSL_free(s->enc_read_ctx); |
| 1491 | s->enc_read_ctx=NULL; | 1985 | s->enc_read_ctx=NULL; |
| 1492 | } | 1986 | } |
| 1493 | if (s->enc_write_ctx != NULL) | 1987 | if (s->enc_write_ctx != NULL) |
| 1494 | { | 1988 | { |
| 1495 | EVP_CIPHER_CTX_cleanup(s->enc_write_ctx); | 1989 | EVP_CIPHER_CTX_cleanup(s->enc_write_ctx); |
| 1496 | Free(s->enc_write_ctx); | 1990 | OPENSSL_free(s->enc_write_ctx); |
| 1497 | s->enc_write_ctx=NULL; | 1991 | s->enc_write_ctx=NULL; |
| 1498 | } | 1992 | } |
| 1993 | if (s->expand != NULL) | ||
| 1994 | { | ||
| 1995 | COMP_CTX_free(s->expand); | ||
| 1996 | s->expand=NULL; | ||
| 1997 | } | ||
| 1998 | if (s->compress != NULL) | ||
| 1999 | { | ||
| 2000 | COMP_CTX_free(s->compress); | ||
| 2001 | s->compress=NULL; | ||
| 2002 | } | ||
| 1499 | } | 2003 | } |
| 1500 | 2004 | ||
| 1501 | /* Fix this function so that it takes an optional type parameter */ | 2005 | /* Fix this function so that it takes an optional type parameter */ |
| 1502 | X509 *SSL_get_certificate(s) | 2006 | X509 *SSL_get_certificate(SSL *s) |
| 1503 | SSL *s; | ||
| 1504 | { | 2007 | { |
| 1505 | if (s->cert != NULL) | 2008 | if (s->cert != NULL) |
| 1506 | return(s->cert->key->x509); | 2009 | return(s->cert->key->x509); |
| @@ -1509,8 +2012,7 @@ SSL *s; | |||
| 1509 | } | 2012 | } |
| 1510 | 2013 | ||
| 1511 | /* Fix this function so that it takes an optional type parameter */ | 2014 | /* Fix this function so that it takes an optional type parameter */ |
| 1512 | EVP_PKEY *SSL_get_privatekey(s) | 2015 | EVP_PKEY *SSL_get_privatekey(SSL *s) |
| 1513 | SSL *s; | ||
| 1514 | { | 2016 | { |
| 1515 | if (s->cert != NULL) | 2017 | if (s->cert != NULL) |
| 1516 | return(s->cert->key->privatekey); | 2018 | return(s->cert->key->privatekey); |
| @@ -1518,17 +2020,14 @@ SSL *s; | |||
| 1518 | return(NULL); | 2020 | return(NULL); |
| 1519 | } | 2021 | } |
| 1520 | 2022 | ||
| 1521 | SSL_CIPHER *SSL_get_current_cipher(s) | 2023 | SSL_CIPHER *SSL_get_current_cipher(SSL *s) |
| 1522 | SSL *s; | ||
| 1523 | { | 2024 | { |
| 1524 | if ((s->session != NULL) && (s->session->cipher != NULL)) | 2025 | if ((s->session != NULL) && (s->session->cipher != NULL)) |
| 1525 | return(s->session->cipher); | 2026 | return(s->session->cipher); |
| 1526 | return(NULL); | 2027 | return(NULL); |
| 1527 | } | 2028 | } |
| 1528 | 2029 | ||
| 1529 | int ssl_init_wbio_buffer(s,push) | 2030 | int ssl_init_wbio_buffer(SSL *s,int push) |
| 1530 | SSL *s; | ||
| 1531 | int push; | ||
| 1532 | { | 2031 | { |
| 1533 | BIO *bbio; | 2032 | BIO *bbio; |
| 1534 | 2033 | ||
| @@ -1544,7 +2043,7 @@ int push; | |||
| 1544 | if (s->bbio == s->wbio) | 2043 | if (s->bbio == s->wbio) |
| 1545 | s->wbio=BIO_pop(s->wbio); | 2044 | s->wbio=BIO_pop(s->wbio); |
| 1546 | } | 2045 | } |
| 1547 | BIO_reset(bbio); | 2046 | (void)BIO_reset(bbio); |
| 1548 | /* if (!BIO_set_write_buffer_size(bbio,16*1024)) */ | 2047 | /* if (!BIO_set_write_buffer_size(bbio,16*1024)) */ |
| 1549 | if (!BIO_set_read_buffer_size(bbio,1)) | 2048 | if (!BIO_set_read_buffer_size(bbio,1)) |
| 1550 | { | 2049 | { |
| @@ -1563,159 +2062,230 @@ int push; | |||
| 1563 | } | 2062 | } |
| 1564 | return(1); | 2063 | return(1); |
| 1565 | } | 2064 | } |
| 2065 | |||
| 2066 | void ssl_free_wbio_buffer(SSL *s) | ||
| 2067 | { | ||
| 2068 | if (s->bbio == NULL) return; | ||
| 2069 | |||
| 2070 | if (s->bbio == s->wbio) | ||
| 2071 | { | ||
| 2072 | /* remove buffering */ | ||
| 2073 | s->wbio=BIO_pop(s->wbio); | ||
| 2074 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ | ||
| 2075 | assert(s->wbio != NULL); | ||
| 2076 | #endif | ||
| 2077 | } | ||
| 2078 | BIO_free(s->bbio); | ||
| 2079 | s->bbio=NULL; | ||
| 2080 | } | ||
| 1566 | 2081 | ||
| 1567 | void SSL_CTX_set_quiet_shutdown(ctx,mode) | 2082 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode) |
| 1568 | SSL_CTX *ctx; | ||
| 1569 | int mode; | ||
| 1570 | { | 2083 | { |
| 1571 | ctx->quiet_shutdown=mode; | 2084 | ctx->quiet_shutdown=mode; |
| 1572 | } | 2085 | } |
| 1573 | 2086 | ||
| 1574 | int SSL_CTX_get_quiet_shutdown(ctx) | 2087 | int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx) |
| 1575 | SSL_CTX *ctx; | ||
| 1576 | { | 2088 | { |
| 1577 | return(ctx->quiet_shutdown); | 2089 | return(ctx->quiet_shutdown); |
| 1578 | } | 2090 | } |
| 1579 | 2091 | ||
| 1580 | void SSL_set_quiet_shutdown(s,mode) | 2092 | void SSL_set_quiet_shutdown(SSL *s,int mode) |
| 1581 | SSL *s; | ||
| 1582 | int mode; | ||
| 1583 | { | 2093 | { |
| 1584 | s->quiet_shutdown=mode; | 2094 | s->quiet_shutdown=mode; |
| 1585 | } | 2095 | } |
| 1586 | 2096 | ||
| 1587 | int SSL_get_quiet_shutdown(s) | 2097 | int SSL_get_quiet_shutdown(SSL *s) |
| 1588 | SSL *s; | ||
| 1589 | { | 2098 | { |
| 1590 | return(s->quiet_shutdown); | 2099 | return(s->quiet_shutdown); |
| 1591 | } | 2100 | } |
| 1592 | 2101 | ||
| 1593 | void SSL_set_shutdown(s,mode) | 2102 | void SSL_set_shutdown(SSL *s,int mode) |
| 1594 | SSL *s; | ||
| 1595 | int mode; | ||
| 1596 | { | 2103 | { |
| 1597 | s->shutdown=mode; | 2104 | s->shutdown=mode; |
| 1598 | } | 2105 | } |
| 1599 | 2106 | ||
| 1600 | int SSL_get_shutdown(s) | 2107 | int SSL_get_shutdown(SSL *s) |
| 1601 | SSL *s; | ||
| 1602 | { | 2108 | { |
| 1603 | return(s->shutdown); | 2109 | return(s->shutdown); |
| 1604 | } | 2110 | } |
| 1605 | 2111 | ||
| 1606 | int SSL_version(s) | 2112 | int SSL_version(SSL *s) |
| 1607 | SSL *s; | ||
| 1608 | { | 2113 | { |
| 1609 | return(s->version); | 2114 | return(s->version); |
| 1610 | } | 2115 | } |
| 1611 | 2116 | ||
| 1612 | SSL_CTX *SSL_get_SSL_CTX(ssl) | 2117 | SSL_CTX *SSL_get_SSL_CTX(SSL *ssl) |
| 1613 | SSL *ssl; | ||
| 1614 | { | 2118 | { |
| 1615 | return(ssl->ctx); | 2119 | return(ssl->ctx); |
| 1616 | } | 2120 | } |
| 1617 | 2121 | ||
| 1618 | int SSL_CTX_set_default_verify_paths(ctx) | 2122 | #ifndef OPENSSL_NO_STDIO |
| 1619 | SSL_CTX *ctx; | 2123 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) |
| 1620 | { | 2124 | { |
| 1621 | return(X509_STORE_set_default_paths(ctx->cert_store)); | 2125 | return(X509_STORE_set_default_paths(ctx->cert_store)); |
| 1622 | } | 2126 | } |
| 1623 | 2127 | ||
| 1624 | int SSL_CTX_load_verify_locations(ctx,CAfile,CApath) | 2128 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, |
| 1625 | SSL_CTX *ctx; | 2129 | const char *CApath) |
| 1626 | char *CAfile; | ||
| 1627 | char *CApath; | ||
| 1628 | { | 2130 | { |
| 1629 | return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); | 2131 | return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); |
| 1630 | } | 2132 | } |
| 2133 | #endif | ||
| 1631 | 2134 | ||
| 1632 | void SSL_set_info_callback(ssl,cb) | 2135 | void SSL_set_info_callback(SSL *ssl, |
| 1633 | SSL *ssl; | 2136 | void (*cb)(const SSL *ssl,int type,int val)) |
| 1634 | void (*cb)(); | ||
| 1635 | { | 2137 | { |
| 1636 | ssl->info_callback=cb; | 2138 | ssl->info_callback=cb; |
| 1637 | } | 2139 | } |
| 1638 | 2140 | ||
| 1639 | void (*SSL_get_info_callback(ssl))() | 2141 | void (*SSL_get_info_callback(SSL *ssl))(const SSL *ssl,int type,int val) |
| 1640 | SSL *ssl; | ||
| 1641 | { | 2142 | { |
| 1642 | return(ssl->info_callback); | 2143 | return ssl->info_callback; |
| 1643 | } | 2144 | } |
| 1644 | 2145 | ||
| 1645 | int SSL_state(ssl) | 2146 | int SSL_state(SSL *ssl) |
| 1646 | SSL *ssl; | ||
| 1647 | { | 2147 | { |
| 1648 | return(ssl->state); | 2148 | return(ssl->state); |
| 1649 | } | 2149 | } |
| 1650 | 2150 | ||
| 1651 | void SSL_set_verify_result(ssl,arg) | 2151 | void SSL_set_verify_result(SSL *ssl,long arg) |
| 1652 | SSL *ssl; | ||
| 1653 | long arg; | ||
| 1654 | { | 2152 | { |
| 1655 | ssl->verify_result=arg; | 2153 | ssl->verify_result=arg; |
| 1656 | } | 2154 | } |
| 1657 | 2155 | ||
| 1658 | long SSL_get_verify_result(ssl) | 2156 | long SSL_get_verify_result(SSL *ssl) |
| 1659 | SSL *ssl; | ||
| 1660 | { | 2157 | { |
| 1661 | return(ssl->verify_result); | 2158 | return(ssl->verify_result); |
| 1662 | } | 2159 | } |
| 1663 | 2160 | ||
| 1664 | int SSL_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | 2161 | int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, |
| 1665 | long argl; | 2162 | CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) |
| 1666 | char *argp; | 2163 | { |
| 1667 | int (*new_func)(); | 2164 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp, |
| 1668 | int (*dup_func)(); | 2165 | new_func, dup_func, free_func); |
| 1669 | void (*free_func)(); | 2166 | } |
| 1670 | { | ||
| 1671 | ssl_meth_num++; | ||
| 1672 | return(CRYPTO_get_ex_new_index(ssl_meth_num-1, | ||
| 1673 | &ssl_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 1674 | } | ||
| 1675 | 2167 | ||
| 1676 | int SSL_set_ex_data(s,idx,arg) | 2168 | int SSL_set_ex_data(SSL *s,int idx,void *arg) |
| 1677 | SSL *s; | ||
| 1678 | int idx; | ||
| 1679 | char *arg; | ||
| 1680 | { | 2169 | { |
| 1681 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | 2170 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); |
| 1682 | } | 2171 | } |
| 1683 | 2172 | ||
| 1684 | char *SSL_get_ex_data(s,idx) | 2173 | void *SSL_get_ex_data(SSL *s,int idx) |
| 1685 | SSL *s; | ||
| 1686 | int idx; | ||
| 1687 | { | 2174 | { |
| 1688 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | 2175 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); |
| 1689 | } | 2176 | } |
| 1690 | 2177 | ||
| 1691 | int SSL_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | 2178 | int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, |
| 1692 | long argl; | 2179 | CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) |
| 1693 | char *argp; | 2180 | { |
| 1694 | int (*new_func)(); | 2181 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp, |
| 1695 | int (*dup_func)(); | 2182 | new_func, dup_func, free_func); |
| 1696 | void (*free_func)(); | 2183 | } |
| 1697 | { | ||
| 1698 | ssl_ctx_meth_num++; | ||
| 1699 | return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1, | ||
| 1700 | &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 1701 | } | ||
| 1702 | 2184 | ||
| 1703 | int SSL_CTX_set_ex_data(s,idx,arg) | 2185 | int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg) |
| 1704 | SSL_CTX *s; | ||
| 1705 | int idx; | ||
| 1706 | char *arg; | ||
| 1707 | { | 2186 | { |
| 1708 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | 2187 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); |
| 1709 | } | 2188 | } |
| 1710 | 2189 | ||
| 1711 | char *SSL_CTX_get_ex_data(s,idx) | 2190 | void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx) |
| 1712 | SSL_CTX *s; | ||
| 1713 | int idx; | ||
| 1714 | { | 2191 | { |
| 1715 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | 2192 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); |
| 1716 | } | 2193 | } |
| 1717 | 2194 | ||
| 1718 | #if defined(_WINDLL) && defined(WIN16) | 2195 | int ssl_ok(SSL *s) |
| 2196 | { | ||
| 2197 | return(1); | ||
| 2198 | } | ||
| 2199 | |||
| 2200 | X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx) | ||
| 2201 | { | ||
| 2202 | return(ctx->cert_store); | ||
| 2203 | } | ||
| 2204 | |||
| 2205 | void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store) | ||
| 2206 | { | ||
| 2207 | if (ctx->cert_store != NULL) | ||
| 2208 | X509_STORE_free(ctx->cert_store); | ||
| 2209 | ctx->cert_store=store; | ||
| 2210 | } | ||
| 2211 | |||
| 2212 | int SSL_want(SSL *s) | ||
| 2213 | { | ||
| 2214 | return(s->rwstate); | ||
| 2215 | } | ||
| 2216 | |||
| 2217 | /*! | ||
| 2218 | * \brief Set the callback for generating temporary RSA keys. | ||
| 2219 | * \param ctx the SSL context. | ||
| 2220 | * \param cb the callback | ||
| 2221 | */ | ||
| 2222 | |||
| 2223 | #ifndef OPENSSL_NO_RSA | ||
| 2224 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl, | ||
| 2225 | int is_export, | ||
| 2226 | int keylength)) | ||
| 2227 | { | ||
| 2228 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | ||
| 2229 | } | ||
| 2230 | |||
| 2231 | void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl, | ||
| 2232 | int is_export, | ||
| 2233 | int keylength)) | ||
| 2234 | { | ||
| 2235 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | ||
| 2236 | } | ||
| 2237 | #endif | ||
| 2238 | |||
| 2239 | #ifdef DOXYGEN | ||
| 2240 | /*! | ||
| 2241 | * \brief The RSA temporary key callback function. | ||
| 2242 | * \param ssl the SSL session. | ||
| 2243 | * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite. | ||
| 2244 | * \param keylength if \c is_export is \c TRUE, then \c keylength is the size | ||
| 2245 | * of the required key in bits. | ||
| 2246 | * \return the temporary RSA key. | ||
| 2247 | * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback | ||
| 2248 | */ | ||
| 2249 | |||
| 2250 | RSA *cb(SSL *ssl,int is_export,int keylength) | ||
| 2251 | {} | ||
| 2252 | #endif | ||
| 2253 | |||
| 2254 | /*! | ||
| 2255 | * \brief Set the callback for generating temporary DH keys. | ||
| 2256 | * \param ctx the SSL context. | ||
| 2257 | * \param dh the callback | ||
| 2258 | */ | ||
| 2259 | |||
| 2260 | #ifndef OPENSSL_NO_DH | ||
| 2261 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | ||
| 2262 | int keylength)) | ||
| 2263 | { | ||
| 2264 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | ||
| 2265 | } | ||
| 2266 | |||
| 2267 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | ||
| 2268 | int keylength)) | ||
| 2269 | { | ||
| 2270 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | ||
| 2271 | } | ||
| 2272 | #endif | ||
| 2273 | |||
| 2274 | |||
| 2275 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | ||
| 2276 | { | ||
| 2277 | SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb); | ||
| 2278 | } | ||
| 2279 | void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | ||
| 2280 | { | ||
| 2281 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb); | ||
| 2282 | } | ||
| 2283 | |||
| 2284 | |||
| 2285 | |||
| 2286 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) | ||
| 1719 | #include "../crypto/bio/bss_file.c" | 2287 | #include "../crypto/bio/bss_file.c" |
| 1720 | #endif | 2288 | #endif |
| 1721 | 2289 | ||
| 2290 | IMPLEMENT_STACK_OF(SSL_CIPHER) | ||
| 2291 | IMPLEMENT_STACK_OF(SSL_COMP) | ||
