New functions to retrieve certificate from SSL_CTX
[openssl.git] / ssl / ssl_lib.c
index 0b2d5ffd95575e565b8df2a61ac560885d4112f3..1bedb54d47673e5284231e55563ea3fb4dedfcf7 100644 (file)
@@ -1596,7 +1596,6 @@ int SSL_get_servername_type(const SSL *s)
        return -1;
        }
 
-# ifndef OPENSSL_NO_NEXTPROTONEG
 /* SSL_select_next_proto implements the standard protocol selection. It is
  * expected that this function is called from the callback set by
  * SSL_CTX_set_next_proto_select_cb.
@@ -1663,6 +1662,7 @@ int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsi
        return status;
        }
 
+# ifndef OPENSSL_NO_NEXTPROTONEG
 /* SSL_get0_next_proto_negotiated sets *data and *len to point to the client's
  * requested protocol for this connection and returns 0. If the client didn't
  * request any protocol, then *data is set to NULL.
@@ -1855,7 +1855,7 @@ int SSL_CTX_set_cli_supp_data(SSL_CTX *ctx,
                        return 0;
 
        ctx->cli_supp_data_records = OPENSSL_realloc(ctx->cli_supp_data_records,
-       (ctx->cli_supp_data_records_count+1) * sizeof(cli_supp_data_record));
+         (ctx->cli_supp_data_records_count+1) * sizeof(cli_supp_data_record));
        if (!ctx->cli_supp_data_records)
                {
                ctx->cli_supp_data_records_count = 0;
@@ -1884,7 +1884,7 @@ int SSL_CTX_set_srv_supp_data(SSL_CTX *ctx,
                        return 0;
 
        ctx->srv_supp_data_records = OPENSSL_realloc(ctx->srv_supp_data_records,
-       (ctx->srv_supp_data_records_count+1) * sizeof(srv_supp_data_record));
+         (ctx->srv_supp_data_records_count+1) * sizeof(srv_supp_data_record));
        if (!ctx->srv_supp_data_records)
                {
                ctx->srv_supp_data_records_count = 0;
@@ -3103,7 +3103,6 @@ void ssl_clear_cipher_ctx(SSL *s)
 #endif
        }
 
-/* Fix this function so that it takes an optional type parameter */
 X509 *SSL_get_certificate(const SSL *s)
        {
        if (s->cert != NULL)
@@ -3112,8 +3111,7 @@ X509 *SSL_get_certificate(const SSL *s)
                return(NULL);
        }
 
-/* Fix this function so that it takes an optional type parameter */
-EVP_PKEY *SSL_get_privatekey(SSL *s)
+EVP_PKEY *SSL_get_privatekey(const SSL *s)
        {
        if (s->cert != NULL)
                return(s->cert->key->privatekey);
@@ -3121,6 +3119,22 @@ EVP_PKEY *SSL_get_privatekey(SSL *s)
                return(NULL);
        }
 
+X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx)
+       {
+       if (ctx->cert != NULL)
+               return ctx->cert->key->x509;
+       else
+               return NULL;
+       }
+
+EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx)
+       {
+       if (ctx->cert != NULL)
+               return ctx->cert->key->privatekey;
+       else
+               return NULL ;
+       }
+
 const SSL_CIPHER *SSL_get_current_cipher(const SSL *s)
        {
        if ((s->session != NULL) && (s->session->cipher != NULL))