]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: crtlist_dup_ssl_conf() duplicates a ssl_bind_conf
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 10 Sep 2020 17:06:43 +0000 (19:06 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 16 Sep 2020 14:28:26 +0000 (16:28 +0200)
Implement the crtlist_dup_ssl_conf() which allocates and duplicates a
ssl_bind_conf structure.

src/ssl_crtlist.c

index 4639bd9d5c36ae29e1e1d5e9e4ff41ddb4a37f52..d70e2ab91d646e7ff72514c9fd4ad718e8e4a329 100644 (file)
@@ -61,6 +61,79 @@ void ssl_sock_free_ssl_conf(struct ssl_bind_conf *conf)
        }
 }
 
+/*
+ * Allocate and copy a ssl_bind_conf structure
+ */
+struct ssl_bind_conf *crtlist_dup_ssl_conf(struct ssl_bind_conf *src)
+{
+       struct ssl_bind_conf *dst;
+
+       if (!src)
+               return NULL;
+
+       dst = calloc(1, sizeof(*dst));
+       if (!dst)
+               return NULL;
+
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
+       if (src->npn_str) {
+               dst->npn_str = strdup(src->npn_str);
+               if (!dst->npn_str)
+                       goto error;
+       }
+#endif
+#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
+       if (src->alpn_str) {
+               dst->alpn_str = strdup(src->alpn_str);
+               if (!dst->alpn_str)
+                       goto error;
+       }
+#endif
+       if (src->ca_file) {
+               dst->ca_file = strdup(src->ca_file);
+               if (!dst->ca_file)
+                       goto error;
+       }
+       if (src->ca_verify_file) {
+               dst->ca_verify_file = strdup(src->ca_verify_file);
+               if (!dst->ca_verify_file)
+                       goto error;
+       }
+       if (src->crl_file) {
+               dst->crl_file = strdup(src->crl_file);
+               if (!dst->crl_file)
+                       goto error;
+       }
+       if (src->ciphers) {
+               dst->ciphers = strdup(src->ciphers);
+               if (!dst->ciphers)
+                       goto error;
+       }
+#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
+       if (src->ciphersuites) {
+               dst->ciphersuites = strdup(src->ciphersuites);
+               if (!dst->ciphersuites)
+                       goto error;
+       }
+#endif
+       if (src->curves) {
+               dst->curves = strdup(src->curves);
+               if (!dst->curves)
+                       goto error;
+       }
+       if (src->ecdhe) {
+               dst->ecdhe = strdup(src->ecdhe);
+               if (!dst->ecdhe)
+                       goto error;
+       }
+       return dst;
+
+error:
+       ssl_sock_free_ssl_conf(dst);
+       free(dst);
+
+       return NULL;
+}
 
 /* free sni filters */
 void crtlist_free_filters(char **args)