2 * Copyright (c) 2018, Juniper Networks, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
29 * @file veta.c - add to trust anchors
34 #include "libsecureboot-priv.h"
39 #ifdef VE_OPENPGP_SUPPORT
40 #include "openpgp/packet.h"
44 * @brief add trust anchors from a file
46 * The file might contain X.509 certs
47 * or OpenPGP public key
50 trust_file_add(const char *trust)
52 br_x509_certificate *xcs;
55 xcs = read_certificates(trust, &num);
57 num = ve_trust_anchors_add(xcs, num);
59 #ifdef VE_OPENPGP_SUPPORT
60 else if (load_key_file(trust)) {
68 * @brief add trust anchors from a directory
70 * Pass each file in directory to trust_file_add
73 trust_dir_add(const char *trust)
75 char fbuf[MAXPATHLEN];
82 if (!(dh = opendir(trust)))
84 for (num = 0, de = readdir(dh); de; de = readdir(dh)) {
85 if (de->d_name[0] == '.')
87 sz = snprintf(fbuf, sizeof(fbuf), "%s/%s", trust, de->d_name);
88 if (sz >= (ssize_t)sizeof(fbuf))
90 if (stat(fbuf, &st) < 0 || S_ISDIR(st.st_mode))
92 num += trust_file_add(fbuf);
99 * @brief add trust anchors
102 ve_trust_add(const char *trust)
106 if (stat(trust, &st) < 0)
108 if (S_ISDIR(st.st_mode))
109 return (trust_dir_add(trust));
110 return (trust_file_add(trust));