Revision of custom extension code.
[openssl.git] / ssl / ssl_lib.c
index 047f69aeed8a403df235be656e37f9863e491484..98f4018014df4414403fddc5891a0c8d683865a4 100644 (file)
@@ -1457,11 +1457,12 @@ char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
                (len < 2))
                return(NULL);
 
+       p=buf;
+       sk=s->session->ciphers;
+
        if (sk_SSL_CIPHER_num(sk) == 0)
                return NULL;
 
-       p=buf;
-       sk=s->session->ciphers;
        for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
                {
                int n;
@@ -1750,7 +1751,7 @@ void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned
        }
 # endif
 
-int SSL_CTX_set_custom_cli_ext(SSL_CTX *ctx, unsigned short ext_type,
+static int cert_set_custom_cli_ext(CERT *cert, unsigned short ext_type,
                               custom_cli_ext_first_cb_fn fn1, 
                               custom_cli_ext_second_cb_fn fn2, void* arg)
        {
@@ -1758,19 +1759,19 @@ int SSL_CTX_set_custom_cli_ext(SSL_CTX *ctx, unsigned short ext_type,
        custom_cli_ext_record* record;
 
        /* Check for duplicates */
-       for (i=0; i < ctx->custom_cli_ext_records_count; i++)
-               if (ext_type == ctx->custom_cli_ext_records[i].ext_type)
+       for (i=0; i < cert->custom_cli_ext_records_count; i++)
+               if (ext_type == cert->custom_cli_ext_records[i].ext_type)
                        return 0;
 
-       ctx->custom_cli_ext_records = OPENSSL_realloc(ctx->custom_cli_ext_records,
-                                                     (ctx->custom_cli_ext_records_count + 1) * 
+       cert->custom_cli_ext_records = OPENSSL_realloc(cert->custom_cli_ext_records,
+                                                     (cert->custom_cli_ext_records_count + 1) * 
                                                      sizeof(custom_cli_ext_record));
-       if (!ctx->custom_cli_ext_records) {
-               ctx->custom_cli_ext_records_count = 0;
+       if (!cert->custom_cli_ext_records) {
+               cert->custom_cli_ext_records_count = 0;
                return 0;
        }
-       ctx->custom_cli_ext_records_count++;
-       record = &ctx->custom_cli_ext_records[ctx->custom_cli_ext_records_count - 1];
+       cert->custom_cli_ext_records_count++;
+       record = &cert->custom_cli_ext_records[cert->custom_cli_ext_records_count - 1];
        record->ext_type = ext_type;
        record->fn1 = fn1;
        record->fn2 = fn2;
@@ -1778,7 +1779,7 @@ int SSL_CTX_set_custom_cli_ext(SSL_CTX *ctx, unsigned short ext_type,
        return 1;
        }
 
-int SSL_CTX_set_custom_srv_ext(SSL_CTX *ctx, unsigned short ext_type,
+static int cert_set_custom_srv_ext(CERT *cert, unsigned short ext_type,
                               custom_srv_ext_first_cb_fn fn1, 
                               custom_srv_ext_second_cb_fn fn2, void* arg)
        {
@@ -1786,25 +1787,39 @@ int SSL_CTX_set_custom_srv_ext(SSL_CTX *ctx, unsigned short ext_type,
        custom_srv_ext_record* record;
 
        /* Check for duplicates */      
-       for (i=0; i < ctx->custom_srv_ext_records_count; i++)
-               if (ext_type == ctx->custom_srv_ext_records[i].ext_type)
+       for (i=0; i < cert->custom_srv_ext_records_count; i++)
+               if (ext_type == cert->custom_srv_ext_records[i].ext_type)
                        return 0;
 
-       ctx->custom_srv_ext_records = OPENSSL_realloc(ctx->custom_srv_ext_records,
-                                                     (ctx->custom_srv_ext_records_count + 1) * 
+       cert->custom_srv_ext_records = OPENSSL_realloc(cert->custom_srv_ext_records,
+                                                     (cert->custom_srv_ext_records_count + 1) * 
                                                      sizeof(custom_srv_ext_record));
-       if (!ctx->custom_srv_ext_records) {
-               ctx->custom_srv_ext_records_count = 0;
+       if (!cert->custom_srv_ext_records) {
+               cert->custom_srv_ext_records_count = 0;
                return 0;
        }
-       ctx->custom_srv_ext_records_count++;
-       record = &ctx->custom_srv_ext_records[ctx->custom_srv_ext_records_count - 1];
+       cert->custom_srv_ext_records_count++;
+       record = &cert->custom_srv_ext_records[cert->custom_srv_ext_records_count - 1];
        record->ext_type = ext_type;
        record->fn1 = fn1;
        record->fn2 = fn2;
        record->arg = arg;
        return 1;
        }
+int SSL_CTX_set_custom_cli_ext(SSL_CTX *ctx, unsigned short ext_type,
+                              custom_cli_ext_first_cb_fn fn1, 
+                              custom_cli_ext_second_cb_fn fn2, void *arg)
+       {
+       return cert_set_custom_cli_ext(ctx->cert, ext_type, fn1, fn2,arg);
+       }
+
+int SSL_CTX_set_custom_srv_ext(SSL_CTX *ctx, unsigned short ext_type,
+                              custom_srv_ext_first_cb_fn fn1, 
+                              custom_srv_ext_second_cb_fn fn2, void *arg)
+       {
+       return cert_set_custom_srv_ext(ctx->cert, ext_type, fn1, fn2,arg);
+       }
 
 /* SSL_CTX_set_alpn_protos sets the ALPN protocol list on |ctx| to |protos|.
  * |protos| must be in wire-format (i.e. a series of non-empty, 8-bit
@@ -1878,65 +1893,6 @@ void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
                *len = ssl->s3->alpn_selected_len;
        }
 
-int SSL_CTX_set_cli_supp_data(SSL_CTX *ctx,
-                             unsigned short supp_data_type,
-                             cli_supp_data_first_cb_fn fn1,
-                             cli_supp_data_second_cb_fn fn2, void* arg)
-       {
-       size_t i;
-       cli_supp_data_record* record;
-
-       /* Check for duplicates */
-       for (i=0; i < ctx->cli_supp_data_records_count; i++)
-               if (supp_data_type == ctx->cli_supp_data_records[i].supp_data_type)
-                       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));
-       if (!ctx->cli_supp_data_records)
-               {
-               ctx->cli_supp_data_records_count = 0;
-               return 0;
-               }
-       ctx->cli_supp_data_records_count++;
-       record = &ctx->cli_supp_data_records[ctx->cli_supp_data_records_count - 1];
-       record->supp_data_type = supp_data_type;
-       record->fn1 = fn1;
-       record->fn2 = fn2;
-       record->arg = arg;
-       return 1;
-       }
-
-int SSL_CTX_set_srv_supp_data(SSL_CTX *ctx,
-                             unsigned short supp_data_type,
-                             srv_supp_data_first_cb_fn fn1,
-                             srv_supp_data_second_cb_fn fn2, void* arg)
-       {
-       size_t i;
-       srv_supp_data_record* record;
-
-       /* Check for duplicates */
-       for (i=0; i < ctx->srv_supp_data_records_count; i++)
-               if (supp_data_type == ctx->srv_supp_data_records[i].supp_data_type)
-                       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));
-       if (!ctx->srv_supp_data_records)
-               {
-               ctx->srv_supp_data_records_count = 0;
-               return 0;
-               }
-       ctx->srv_supp_data_records_count++;
-       record = &ctx->srv_supp_data_records[ctx->srv_supp_data_records_count - 1];
-       record->supp_data_type = supp_data_type;
-       record->fn1 = fn1;
-       record->fn2 = fn2;
-       record->arg = arg;
-
-       return 1;
-       }
-
 #endif /* !OPENSSL_NO_TLSEXT */
 
 int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
@@ -2136,14 +2092,6 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
 #ifndef OPENSSL_NO_SRP
        SSL_CTX_SRP_CTX_init(ret);
 #endif
-       ret->custom_cli_ext_records = NULL;
-       ret->custom_cli_ext_records_count = 0;
-       ret->custom_srv_ext_records = NULL;
-       ret->custom_srv_ext_records_count = 0;
-       ret->cli_supp_data_records = NULL;
-       ret->cli_supp_data_records_count = 0;
-       ret->srv_supp_data_records = NULL;
-       ret->srv_supp_data_records_count = 0;
 #ifndef OPENSSL_NO_BUF_FREELISTS
        ret->freelist_max_len = SSL_MAX_BUF_FREELIST_LEN_DEFAULT;
        ret->rbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST));
@@ -2282,12 +2230,6 @@ void SSL_CTX_free(SSL_CTX *a)
 #ifndef OPENSSL_NO_SRP
        SSL_CTX_SRP_CTX_free(a);
 #endif
-#ifndef OPENSSL_NO_TLSEXT
-       OPENSSL_free(a->custom_cli_ext_records);
-       OPENSSL_free(a->custom_srv_ext_records);
-       OPENSSL_free(a->cli_supp_data_records);
-       OPENSSL_free(a->srv_supp_data_records);
-#endif
 #ifndef OPENSSL_NO_ENGINE
        if (a->client_cert_engine)
                ENGINE_finish(a->client_cert_engine);