]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Put curl cert attributes into TLS-Cert TLVs
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 21 Jun 2021 21:10:05 +0000 (16:10 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 21 Jun 2021 21:10:15 +0000 (16:10 -0500)
src/lib/curl/attrs.h [new file with mode: 0644]
src/lib/curl/base.c

diff --git a/src/lib/curl/attrs.h b/src/lib/curl/attrs.h
new file mode 100644 (file)
index 0000000..1675c06
--- /dev/null
@@ -0,0 +1,24 @@
+#pragma once
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Attribute definitions for lib curl
+ *
+ * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ */
+RCSIDH(attrs_h, "$Id$")
+
+extern fr_dict_attr_t const *attr_tls_cert;
index f869f8b282d2e73efa59996d56435ca44ed18ff6..d98ab3b4ab466139bf87c85f19fac7ff409426d4 100644 (file)
 
 #include <freeradius-devel/util/talloc.h>
 
+#include "attrs.h"
+
 static uint32_t instance_count = 0;
+
+fr_dict_attr_t const *attr_tls_cert;
 static fr_dict_t const *dict_freeradius; /*internal dictionary for server*/
 
+extern fr_dict_attr_autoload_t curl_attr[];
+fr_dict_attr_autoload_t curl_attr[] = {
+       { .out = &attr_tls_cert, .name = "TLS-Cert", .type = FR_TYPE_TLV, .dict = &dict_freeradius },
+       { NULL }
+};
+
 static fr_dict_autoload_t curl_dict[] = {
        { .out = &dict_freeradius, .proto = "freeradius" },
        { NULL }
@@ -93,6 +103,11 @@ int fr_curl_init(void)
                return -1;
        }
 
+       if (fr_dict_attr_autoload(curl_attr) < 0) {
+               PERROR("Failed loading dictionaries for curl");
+               return -1;
+       }
+
        ret = curl_global_init(CURL_GLOBAL_ALL);
        if (ret != CURLE_OK) {
                ERROR("CURL init returned error: %i - %s", ret, curl_easy_strerror(ret));
@@ -153,7 +168,7 @@ int fr_curl_response_certinfo(request_t *request, fr_curl_io_request_t *randle)
        CURLcode                ret;
        int                     i;
        char                    buffer[265];
-       char                    *p , *q, *attr = buffer;
+       char                    *p , *q;
        fr_pair_list_t          cert_vps;
        /*
         *      Examples and documentation show cert_info being
@@ -177,11 +192,13 @@ int fr_curl_response_certinfo(request_t *request, fr_curl_io_request_t *randle)
                return -1;
        }
 
-       attr += strlcpy(attr, "TLS-Cert-", sizeof(buffer));
-
        RDEBUG2("Chain has %i certificate(s)", ptr.to_certinfo->num_of_certs);
        for (i = 0; i < ptr.to_certinfo->num_of_certs; i++) {
                struct curl_slist *cert_attrs;
+               fr_pair_t *container;
+
+               MEM(container = fr_pair_afrom_da(request->request_ctx, attr_tls_cert));
+               fr_pair_append(&cert_vps, container);
 
                RDEBUG2("Processing certificate %i",i);
 
@@ -197,19 +214,19 @@ int fr_curl_response_certinfo(request_t *request, fr_curl_io_request_t *randle)
                                continue;
                        }
 
-                       strlcpy(attr, cert_attrs->data, (q - cert_attrs->data) + 1);
-                       for (p = attr; *p != '\0'; p++) if (*p == ' ') *p = '-';
+                       strlcpy(buffer, cert_attrs->data, (q - cert_attrs->data) + 1);
+                       for (p = buffer; *p != '\0'; p++) if (*p == ' ') *p = '-';
 
-                       da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), buffer);
+                       da = fr_dict_attr_by_name(NULL, attr_tls_cert, buffer);
                        if (!da) {
                                RDEBUG3("Skipping %s += '%s'", buffer, q + 1);
                                RDEBUG3("If this value is required, define attribute \"%s\"", buffer);
                                continue;
                        }
-                       MEM(vp = fr_pair_afrom_da(request->request_ctx, da));
+                       MEM(vp = fr_pair_afrom_da(container, da));
                        fr_pair_value_from_str(vp, q + 1, -1, '\0', true);
 
-                       fr_pair_append(&cert_vps, vp);
+                       fr_pair_append(&container->vp_group, vp);
                }
                /*
                 *      Add a copy of the cert_vps to the request list.