X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=ssl%2Fssl_cert.c;h=0153b18f46e92ad11ec79abfd2bc6a0215fbdc0e;hb=fe6ef2472db933f01b59cad82aa925736935984b;hp=05a444745059980ec67abe3c33ecd7aa3fefdfbc;hpb=df6da24bda457b724ba3e894e6c329a9b93d536f;p=openssl.git diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index 05a4447450..0153b18f46 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -192,6 +192,7 @@ CERT *ssl_cert_dup(CERT *cert) return (NULL); } + ret->references = 1; ret->key = &ret->pkeys[cert->key - cert->pkeys]; #ifndef OPENSSL_NO_RSA @@ -230,18 +231,6 @@ CERT *ssl_cert_dup(CERT *cert) ret->dh_tmp_auto = cert->dh_tmp_auto; #endif -#ifndef OPENSSL_NO_EC - if (cert->ecdh_tmp) { - ret->ecdh_tmp = EC_KEY_dup(cert->ecdh_tmp); - if (ret->ecdh_tmp == NULL) { - SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_EC_LIB); - goto err; - } - } - ret->ecdh_tmp_cb = cert->ecdh_tmp_cb; - ret->ecdh_tmp_auto = cert->ecdh_tmp_auto; -#endif - for (i = 0; i < SSL_PKEY_NUM; i++) { CERT_PKEY *cpk = cert->pkeys + i; CERT_PKEY *rpk = ret->pkeys + i; @@ -278,11 +267,10 @@ CERT *ssl_cert_dup(CERT *cert) } } - ret->references = 1; /* Configured sigalgs copied across */ if (cert->conf_sigalgs) { ret->conf_sigalgs = OPENSSL_malloc(cert->conf_sigalgslen); - if (!ret->conf_sigalgs) + if (ret->conf_sigalgs == NULL) goto err; memcpy(ret->conf_sigalgs, cert->conf_sigalgs, cert->conf_sigalgslen); ret->conf_sigalgslen = cert->conf_sigalgslen; @@ -291,7 +279,7 @@ CERT *ssl_cert_dup(CERT *cert) if (cert->client_sigalgs) { ret->client_sigalgs = OPENSSL_malloc(cert->client_sigalgslen); - if (!ret->client_sigalgs) + if (ret->client_sigalgs == NULL) goto err; memcpy(ret->client_sigalgs, cert->client_sigalgs, cert->client_sigalgslen); @@ -303,7 +291,7 @@ CERT *ssl_cert_dup(CERT *cert) /* Copy any custom client certificate types */ if (cert->ctypes) { ret->ctypes = OPENSSL_malloc(cert->ctype_num); - if (!ret->ctypes) + if (ret->ctypes == NULL) goto err; memcpy(ret->ctypes, cert->ctypes, cert->ctype_num); ret->ctype_num = cert->ctype_num; @@ -333,13 +321,13 @@ CERT *ssl_cert_dup(CERT *cert) goto err; if (!custom_exts_copy(&ret->srv_ext, &cert->srv_ext)) goto err; - +#ifndef OPENSSL_NO_PSK if (cert->psk_identity_hint) { ret->psk_identity_hint = BUF_strdup(cert->psk_identity_hint); if (ret->psk_identity_hint == NULL) goto err; } - +#endif return (ret); err: @@ -395,9 +383,6 @@ void ssl_cert_free(CERT *c) #ifndef OPENSSL_NO_DH DH_free(c->dh_tmp); #endif -#ifndef OPENSSL_NO_EC - EC_KEY_free(c->ecdh_tmp); -#endif ssl_cert_clear_certs(c); OPENSSL_free(c->conf_sigalgs); @@ -625,7 +610,7 @@ STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx) STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s) { - if (s->type == SSL_ST_CONNECT) { /* we are in the client */ + if (!s->server) { /* we are in the client */ if (((s->version >> 8) == SSL3_VERSION_MAJOR) && (s->s3 != NULL)) return (s->s3->tmp.ca_names); else @@ -672,7 +657,6 @@ static int xname_cmp(const X509_NAME *const *a, const X509_NAME *const *b) return (X509_NAME_cmp(*a, *b)); } -#ifndef OPENSSL_NO_STDIO /** * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed; * it doesn't really have anything to do with clients (except that a common use @@ -690,7 +674,7 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) sk = sk_X509_NAME_new(xname_cmp); - in = BIO_new(BIO_s_file_internal()); + in = BIO_new(BIO_s_file()); if ((sk == NULL) || (in == NULL)) { SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE, ERR_R_MALLOC_FAILURE); @@ -736,7 +720,6 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) ERR_clear_error(); return (ret); } -#endif /** * Add a file of certs to a stack. @@ -758,7 +741,7 @@ int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_cmp); - in = BIO_new(BIO_s_file_internal()); + in = BIO_new(BIO_s_file()); if (in == NULL) { SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK, @@ -916,6 +899,12 @@ int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l) SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB); return (0); } + /* + * It is valid for the chain not to be complete (because normally we + * don't include the root cert in the chain). Therefore we deliberately + * ignore the error return from this call. We're not actually verifying + * the cert - we're just building as much of the chain as we can + */ X509_verify_cert(&xs_ctx); /* Don't leave errors in the queue */ ERR_clear_error(); @@ -970,7 +959,7 @@ int ssl_build_cert_chain(SSL *s, SSL_CTX *ctx, int flags) /* Rearranging and check the chain: add everything to a store */ if (flags & SSL_BUILD_CHAIN_FLAG_CHECK) { chain_store = X509_STORE_new(); - if (!chain_store) + if (chain_store == NULL) goto err; for (i = 0; i < sk_X509_num(cpk->chain); i++) { x = sk_X509_value(cpk->chain, i);