|
15 | 15 | #include <keys/asymmetric-type.h> |
16 | 16 | #include <keys/system_keyring.h> |
17 | 17 | #include <crypto/pkcs7.h> |
| 18 | +#include "common.h" |
18 | 19 |
|
19 | 20 | static struct key *builtin_trusted_keys; |
20 | 21 | #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
@@ -136,54 +137,10 @@ device_initcall(system_trusted_keyring_init); |
136 | 137 | */ |
137 | 138 | static __init int load_system_certificate_list(void) |
138 | 139 | { |
139 | | - key_ref_t key; |
140 | | - const u8 *p, *end; |
141 | | - size_t plen; |
142 | | - |
143 | 140 | pr_notice("Loading compiled-in X.509 certificates\n"); |
144 | 141 |
|
145 | | - p = system_certificate_list; |
146 | | - end = p + system_certificate_list_size; |
147 | | - while (p < end) { |
148 | | - /* Each cert begins with an ASN.1 SEQUENCE tag and must be more |
149 | | - * than 256 bytes in size. |
150 | | - */ |
151 | | - if (end - p < 4) |
152 | | - goto dodgy_cert; |
153 | | - if (p[0] != 0x30 && |
154 | | - p[1] != 0x82) |
155 | | - goto dodgy_cert; |
156 | | - plen = (p[2] << 8) | p[3]; |
157 | | - plen += 4; |
158 | | - if (plen > end - p) |
159 | | - goto dodgy_cert; |
160 | | - |
161 | | - key = key_create_or_update(make_key_ref(builtin_trusted_keys, 1), |
162 | | - "asymmetric", |
163 | | - NULL, |
164 | | - p, |
165 | | - plen, |
166 | | - ((KEY_POS_ALL & ~KEY_POS_SETATTR) | |
167 | | - KEY_USR_VIEW | KEY_USR_READ), |
168 | | - KEY_ALLOC_NOT_IN_QUOTA | |
169 | | - KEY_ALLOC_BUILT_IN | |
170 | | - KEY_ALLOC_BYPASS_RESTRICTION); |
171 | | - if (IS_ERR(key)) { |
172 | | - pr_err("Problem loading in-kernel X.509 certificate (%ld)\n", |
173 | | - PTR_ERR(key)); |
174 | | - } else { |
175 | | - pr_notice("Loaded X.509 cert '%s'\n", |
176 | | - key_ref_to_ptr(key)->description); |
177 | | - key_ref_put(key); |
178 | | - } |
179 | | - p += plen; |
180 | | - } |
181 | | - |
182 | | - return 0; |
183 | | - |
184 | | -dodgy_cert: |
185 | | - pr_err("Problem parsing in-kernel X.509 certificate list\n"); |
186 | | - return 0; |
| 142 | + return load_certificate_list(system_certificate_list, system_certificate_list_size, |
| 143 | + builtin_trusted_keys); |
187 | 144 | } |
188 | 145 | late_initcall(load_system_certificate_list); |
189 | 146 |
|
|
0 commit comments