iPXE
rootcert.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <stdlib.h>
28#include <ipxe/crypto.h>
29#include <ipxe/sha256.h>
30#include <ipxe/x509.h>
31#include <ipxe/settings.h>
32#include <ipxe/dhcp.h>
33#include <ipxe/init.h>
34#include <ipxe/rootcert.h>
35
36/** @file
37 *
38 * Root certificate store
39 *
40 */
41
42/** Length of a root certificate fingerprint */
43#define FINGERPRINT_LEN SHA256_DIGEST_SIZE
44
45/* Allow trusted certificates to be overridden if not explicitly specified */
46#ifndef ALLOW_TRUST_OVERRIDE
47 #ifdef TRUSTED
48 #define ALLOW_TRUST_OVERRIDE 0
49 #else
50 #define ALLOW_TRUST_OVERRIDE 1
51 #endif
52#endif
53
54/* Use iPXE root CA if no trusted certificates are explicitly specified */
55#ifndef TRUSTED
56#define TRUSTED \
57 /* iPXE root CA */ \
58 0x9f, 0xaf, 0x71, 0x7b, 0x7f, 0x8c, 0xa2, 0xf9, 0x3c, 0x25, \
59 0x6c, 0x79, 0xf8, 0xac, 0x55, 0x91, 0x89, 0x5d, 0x66, 0xd1, \
60 0xff, 0x3b, 0xee, 0x63, 0x97, 0xa7, 0x0d, 0x29, 0xc6, 0x5e, \
61 0xed, 0x1a,
62#endif
63
64/** Flag indicating if root of trust may be overridden at runtime */
66
67/** Root certificate fingerprints */
68static const uint8_t fingerprints[] = { TRUSTED };
69
70/** Root certificate fingerprint setting */
71static struct setting trust_setting __setting ( SETTING_CRYPTO, trust ) = {
72 .name = "trust",
73 .description = "Trusted root certificate fingerprints",
74 .tag = DHCP_EB_TRUST,
75 .type = &setting_type_hex,
76};
77
78/** Root certificates */
80 .refcnt = REF_INIT ( ref_no_free ),
81 .digest = &sha256_algorithm,
82 .count = ( sizeof ( fingerprints ) / FINGERPRINT_LEN ),
84};
85
86/**
87 * Initialise root certificate
88 *
89 * The list of trusted root certificates can be specified at build
90 * time using the TRUST= build parameter. If no certificates are
91 * specified, then the default iPXE root CA certificate is trusted.
92 *
93 * If no certificates were explicitly specified, then we allow the
94 * list of trusted root certificate fingerprints to be overridden
95 * using the "trust" setting, but only at the point of iPXE
96 * initialisation. This prevents untrusted sources of settings
97 * (e.g. DHCP) from subverting the chain of trust, while allowing
98 * trustworthy sources (e.g. VMware GuestInfo or non-volatile stored
99 * options) to specify the trusted root certificate without requiring
100 * a rebuild.
101 */
102static void rootcert_init ( void ) {
103 static int initialised;
104 void *external = NULL;
105 int len;
106
107 /* Allow trusted root certificates to be overridden only if
108 * not explicitly specified at build time.
109 */
110 if ( ALLOW_TRUST_OVERRIDE && ( ! initialised ) ) {
111
112 /* Fetch copy of "trust" setting, if it exists. This
113 * memory will never be freed.
114 */
115 if ( ( len = fetch_raw_setting_copy ( NULL, &trust_setting,
116 &external ) ) >= 0 ) {
117 root_certificates.fingerprints = external;
119 }
120
121 /* Prevent subsequent modifications */
122 initialised = 1;
123 }
124
125 DBGC ( &root_certificates, "ROOTCERT using %d %s certificate(s):\n",
126 root_certificates.count, ( external ? "external" : "built-in" ));
127 DBGC_HDA ( &root_certificates, 0, root_certificates.fingerprints,
129}
130
131/** Root certificate initialiser */
132struct startup_fn rootcert_startup_fn __startup_fn ( STARTUP_LATE ) = {
133 .name = "rootcert",
134 .startup = rootcert_init,
135};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
unsigned char uint8_t
Definition stdint.h:10
ring len
Length.
Definition dwmac.h:226
#define DBGC(...)
Definition compiler.h:505
#define DBGC_HDA(...)
Definition compiler.h:506
#define DHCP_EB_TRUST
Trusted root certficate fingerprints.
Definition dhcp.h:417
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define SETTING_CRYPTO
Cryptography settings.
Definition settings.h:80
#define STARTUP_LATE
Late startup.
Definition init.h:66
Cryptographic API.
Dynamic Host Configuration Protocol.
Configuration settings.
#define __setting(setting_order, name)
Declare a configuration setting.
Definition settings.h:57
#define __startup_fn(startup_order)
Declare a startup/shutdown function.
Definition init.h:53
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition refcnt.c:102
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition refcnt.h:78
static const uint8_t fingerprints[]
Root certificate fingerprints.
Definition rootcert.c:68
#define TRUSTED
Definition rootcert.c:56
const int allow_trust_override
Flag indicating if root of trust may be overridden at runtime.
Definition rootcert.c:65
#define ALLOW_TRUST_OVERRIDE
Definition rootcert.c:50
#define FINGERPRINT_LEN
Length of a root certificate fingerprint.
Definition rootcert.c:43
struct x509_root root_certificates
Root certificates.
Definition rootcert.c:79
static void rootcert_init(void)
Initialise root certificate.
Definition rootcert.c:102
Root certificate store.
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition settings.c:822
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
Definition sha256.c:265
SHA-256 algorithm.
A setting.
Definition settings.h:24
A startup/shutdown function.
Definition init.h:43
An X.509 root certificate list.
Definition x509.h:375
X.509 certificates.