X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=ssl%2Fssl_lib.c;h=c7d178da893a9c7909929be5baea071c3a6a9b11;hb=f3f1cf8444f439c0be9de04bf3821a20d00fd956;hp=d29da6dfbfef7c04352bbc0c6fdd00529f0995d3;hpb=a18a31e49d266b687f425c3c434a5aef1f719e38;p=openssl.git diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index d29da6dfbf..c7d178da89 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -142,7 +142,7 @@ * OTHERWISE. */ -#ifdef REF_CHECK +#ifdef REF_DEBUG # include #endif #include @@ -190,10 +190,11 @@ struct ssl_async_args { SSL *s; void *buf; int num; - int type; + enum { READFUNC, WRITEFUNC, OTHERFUNC} type; union { - int (*func1)(SSL *, void *, int); - int (*func2)(SSL *, const void *, int); + int (*func_read)(SSL *, void *, int); + int (*func_write)(SSL *, const void *, int); + int (*func_other)(SSL *); } f; }; @@ -714,6 +715,7 @@ SSL *SSL_new(SSL_CTX *ctx) s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len; } + s->verified_chain = NULL; s->verify_result = X509_V_OK; s->default_passwd_callback = ctx->default_passwd_callback; @@ -911,7 +913,7 @@ int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki) { struct dane_st *dane = &s->dane; - if (!DANETLS_ENABLED(dane)) + if (!DANETLS_ENABLED(dane) || s->verify_result != X509_V_OK) return -1; if (dane->mtlsa) { if (mcert) @@ -927,7 +929,7 @@ int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector, { struct dane_st *dane = &s->dane; - if (!DANETLS_ENABLED(dane)) + if (!DANETLS_ENABLED(dane) || s->verify_result != X509_V_OK) return -1; if (dane->mtlsa) { if (usage) @@ -993,17 +995,10 @@ void SSL_free(SSL *s) return; i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL); -#ifdef REF_PRINT - REF_PRINT("SSL", s); -#endif + REF_PRINT_COUNT("SSL", s); if (i > 0) return; -#ifdef REF_CHECK - if (i < 0) { - fprintf(stderr, "SSL_free, bad reference count\n"); - abort(); /* ok */ - } -#endif + REF_ASSERT_ISNT(i < 0); X509_VERIFY_PARAM_free(s->param); dane_final(&s->dane); @@ -1051,6 +1046,8 @@ void SSL_free(SSL *s) sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free); + sk_X509_pop_free(s->verified_chain, X509_free); + if (s->method != NULL) s->method->ssl_free(s); @@ -1469,10 +1466,15 @@ static int ssl_io_intern(void *vargs) s = args->s; buf = args->buf; num = args->num; - if (args->type == 1) - return args->f.func1(s, buf, num); - else - return args->f.func2(s, buf, num); + switch (args->type) { + case READFUNC: + return args->f.func_read(s, buf, num); + case WRITEFUNC: + return args->f.func_write(s, buf, num); + case OTHERFUNC: + return args->f.func_other(s); + } + return -1; } int SSL_read(SSL *s, void *buf, int num) @@ -1493,8 +1495,8 @@ int SSL_read(SSL *s, void *buf, int num) args.s = s; args.buf = buf; args.num = num; - args.type = 1; - args.f.func1 = s->method->ssl_read; + args.type = READFUNC; + args.f.func_read = s->method->ssl_read; return ssl_start_async_job(s, &args, ssl_io_intern); } else { @@ -1518,8 +1520,8 @@ int SSL_peek(SSL *s, void *buf, int num) args.s = s; args.buf = buf; args.num = num; - args.type = 1; - args.f.func1 = s->method->ssl_peek; + args.type = READFUNC; + args.f.func_read = s->method->ssl_peek; return ssl_start_async_job(s, &args, ssl_io_intern); } else { @@ -1546,8 +1548,8 @@ int SSL_write(SSL *s, const void *buf, int num) args.s = s; args.buf = (void *)buf; args.num = num; - args.type = 2; - args.f.func2 = s->method->ssl_write; + args.type = WRITEFUNC; + args.f.func_write = s->method->ssl_write; return ssl_start_async_job(s, &args, ssl_io_intern); } else { @@ -1569,7 +1571,22 @@ int SSL_shutdown(SSL *s) return -1; } - return s->method->ssl_shutdown(s); + if (!SSL_in_init(s)) { + if((s->mode & SSL_MODE_ASYNC) && ASYNC_get_current_job() == NULL) { + struct ssl_async_args args; + + args.s = s; + args.type = OTHERFUNC; + args.f.func_other = s->method->ssl_shutdown; + + return ssl_start_async_job(s, &args, ssl_io_intern); + } else { + return s->method->ssl_shutdown(s); + } + } else { + SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_SHUTDOWN_WHILE_IN_INIT); + return -1; + } } int SSL_renegotiate(SSL *s) @@ -1964,7 +1981,7 @@ char *SSL_get_shared_ciphers(const SSL *s, char *buf, int len) *p = '\0'; return buf; } - strcpy(p, c->name); + memcpy(p, c->name, n + 1); p += n; *(p++) = ':'; len -= n + 1; @@ -2246,6 +2263,9 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) return (NULL); } + if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL)) + return NULL; + if (FIPS_mode() && (meth->version < TLS1_VERSION)) { SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_AT_LEAST_TLS_1_0_NEEDED_IN_FIPS_MODE); return NULL; @@ -2344,6 +2364,13 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) * deployed might change this. */ ret->options |= SSL_OP_LEGACY_SERVER_CONNECT; + /* + * Disable compression by default to prevent CRIME. Applications can + * re-enable compression by configuring + * SSL_CTX_clear_options(ctx, SSL_OP_NO_COMPRESSION); + * or by using the SSL_CONF library. + */ + ret->options |= SSL_OP_NO_COMPRESSION; return (ret); err: @@ -2366,17 +2393,10 @@ void SSL_CTX_free(SSL_CTX *a) return; i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_SSL_CTX); -#ifdef REF_PRINT - REF_PRINT("SSL_CTX", a); -#endif + REF_PRINT_COUNT("SSL_CTX", a); if (i > 0) return; -#ifdef REF_CHECK - if (i < 0) { - fprintf(stderr, "SSL_CTX_free, bad reference count\n"); - abort(); /* ok */ - } -#endif + REF_ASSERT_ISNT(i < 0); X509_VERIFY_PARAM_free(a->param); dane_ctx_final(&a->dane); @@ -3240,8 +3260,11 @@ void ssl_free_wbio_buffer(SSL *s) if (s->bbio == s->wbio) { /* remove buffering */ s->wbio = BIO_pop(s->wbio); -#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids - * adding one more preprocessor symbol */ +#ifdef REF_DEBUG + /* + * not the usual REF_DEBUG, but this avoids + * adding one more preprocessor symbol + */ assert(s->wbio != NULL); #endif } @@ -3675,7 +3698,7 @@ int ssl_handshake_hash(SSL *s, unsigned char *out, int outlen) return ret; } -int SSL_cache_hit(SSL *s) +int SSL_session_reused(SSL *s) { return s->hit; } @@ -3797,4 +3820,9 @@ unsigned long SSL_clear_options(SSL *s, unsigned long op) return s->options &= ~op; } +STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s) +{ + return s->verified_chain; +} + IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);