Make it possible to delete all certificates from an SSL structure.
[openssl.git] / ssl / ssl_lib.c
index 12a0448fe26c55920e4369619888748d9e6ba3a5..c291ee274cbaddb4ec4e8ebf6e2bcba906d9d1c3 100644 (file)
 #  include <assert.h>
 #endif
 #include <stdio.h>
-#include <openssl/crypto.h>
 #include "ssl_locl.h"
 #include "kssl_lcl.h"
 #include <openssl/objects.h>
@@ -528,8 +527,7 @@ int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm)
 
 void SSL_certs_clear(SSL *s)
        {
-       if (s->cert)
-               ssl_cert_clear_certs(s->cert);
+       ssl_cert_clear_certs(s->cert);
        }
 
 void SSL_free(SSL *s)
@@ -1656,7 +1654,6 @@ void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned
        ctx->next_proto_select_cb = cb;
        ctx->next_proto_select_cb_arg = arg;
        }
-
 # endif
 #endif
 
@@ -2043,16 +2040,6 @@ void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
        X509_VERIFY_PARAM_set_depth(ctx->param, depth);
        }
 
-void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb)(SSL *ssl, void *arg), void *arg)
-       {
-       ssl_cert_set_cert_cb(c->cert, cb, arg);
-       }
-
-void SSL_set_cert_cb(SSL *s, int (*cb)(SSL *ssl, void *arg), void *arg)
-       {
-       ssl_cert_set_cert_cb(s->cert, cb, arg);
-       }
-
 void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
        {
        CERT_PKEY *cpk;
@@ -2339,15 +2326,10 @@ int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s)
 #endif
 
 /* THIS NEEDS CLEANING UP */
-CERT_PKEY *ssl_get_server_send_pkey(SSL *s)
+static int ssl_get_server_cert_index(SSL *s)
        {
-       unsigned long alg_k,alg_a;
-       CERT *c;
-       int i;
+       unsigned long alg_k, alg_a;
 
-       c=s->cert;
-       ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
-       
        alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
        alg_a = s->s3->tmp.new_cipher->algorithm_auth;
 
@@ -2364,42 +2346,53 @@ CERT_PKEY *ssl_get_server_send_pkey(SSL *s)
                 * checks for SSL_kECDH before RSA
                 * checks ensures the correct cert is chosen.
                 */
-               i=SSL_PKEY_ECC;
+               return SSL_PKEY_ECC;
                }
        else if (alg_a & SSL_aECDSA)
-               {
-               i=SSL_PKEY_ECC;
-               }
+               return SSL_PKEY_ECC;
        else if (alg_k & SSL_kDHr)
-               i=SSL_PKEY_DH_RSA;
+               return SSL_PKEY_DH_RSA;
        else if (alg_k & SSL_kDHd)
-               i=SSL_PKEY_DH_DSA;
+               return SSL_PKEY_DH_DSA;
        else if (alg_a & SSL_aDSS)
-               i=SSL_PKEY_DSA_SIGN;
+               return SSL_PKEY_DSA_SIGN;
        else if (alg_a & SSL_aRSA)
                {
-               if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
-                       i=SSL_PKEY_RSA_SIGN;
+               if (s->cert->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
+                       return SSL_PKEY_RSA_SIGN;
                else
-                       i=SSL_PKEY_RSA_ENC;
+                       return SSL_PKEY_RSA_ENC;
                }
        else if (alg_a & SSL_aKRB5)
-               {
                /* VRS something else here? */
-               return(NULL);
-               }
+               return -1;
        else if (alg_a & SSL_aGOST94) 
-               i=SSL_PKEY_GOST94;
+               return SSL_PKEY_GOST94;
        else if (alg_a & SSL_aGOST01)
-               i=SSL_PKEY_GOST01;
+               return SSL_PKEY_GOST01;
        else /* if (alg_a & SSL_aNULL) */
                {
-               SSLerr(SSL_F_SSL_GET_SERVER_SEND_PKEY,ERR_R_INTERNAL_ERROR);
-               return(NULL);
+               SSLerr(SSL_F_SSL_GET_SERVER_CERT_INDEX,ERR_R_INTERNAL_ERROR);
+               return -1;
                }
-       if (c->pkeys[i].x509 == NULL) return(NULL);
+       }
+
+CERT_PKEY *ssl_get_server_send_pkey(SSL *s)
+       {
+       CERT *c;
+       int i;
+
+       c = s->cert;
+       ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
 
-       return(&c->pkeys[i]);
+       i = ssl_get_server_cert_index(s);
+
+       /* This may or may not be an error. */
+       if (i < 0)
+               return NULL;
+
+       /* May be NULL. */
+       return &c->pkeys[i];
        }
 
 EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher, const EVP_MD **pmd)
@@ -2434,6 +2427,27 @@ EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher, const EVP_MD **pmd)
        return c->pkeys[idx].privatekey;
        }
 
+#ifndef OPENSSL_NO_TLSEXT
+unsigned char *ssl_get_authz_data(SSL *s, size_t *authz_length)
+       {
+       CERT *c;
+       int i;
+
+       c = s->cert;
+       i = ssl_get_server_cert_index(s);
+
+       if (i == -1)
+               return NULL;
+
+       *authz_length = 0;
+       if (c->pkeys[i].authz == NULL)
+               return(NULL);
+       *authz_length = c->pkeys[i].authz_length;
+
+       return c->pkeys[i].authz;
+       }
+#endif
+
 void ssl_update_cache(SSL *s,int mode)
        {
        int i;