This is needed due to the duplicated iommu stuff to help with the merge and to prevent future issues.
Showing the changes to scripts (2 of 285 files). Show all
Unified · Split
| @@ -17,13 +17,9 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <stdint.h> |
| 18 | 18 | #include <stdbool.h> |
| 19 | 19 | #include <string.h> |
| 20 | −#include <getopt.h> | |
| 21 | 20 | #include <err.h> |
| 22 | −#include <arpa/inet.h> | |
| 23 | 21 | #include <openssl/bio.h> |
| 24 | −#include <openssl/evp.h> | |
| 25 | 22 | #include <openssl/pem.h> |
| 26 | −#include <openssl/pkcs7.h> | |
| 27 | 23 | #include <openssl/err.h> |
| 28 | 24 | #include <openssl/engine.h> |
| 29 | 25 | |
| @@ -20,13 +20,34 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <getopt.h> |
| 21 | 21 | #include <err.h> |
| 22 | 22 | #include <arpa/inet.h> |
| 23 | +#include <openssl/opensslv.h> | |
| 23 | 24 | #include <openssl/bio.h> |
| 24 | 25 | #include <openssl/evp.h> |
| 25 | 26 | #include <openssl/pem.h> |
| 26 | −#include <openssl/cms.h> | |
| 27 | 27 | #include <openssl/err.h> |
| 28 | 28 | #include <openssl/engine.h> |
| 29 | 29 | |
| 30 | +/* | |
| 31 | + * Use CMS if we have openssl-1.0.0 or newer available - otherwise we have to | |
| 32 | + * assume that it's not available and its header file is missing and that we | |
| 33 | + * should use PKCS#7 instead. Switching to the older PKCS#7 format restricts | |
| 34 | + * the options we have on specifying the X.509 certificate we want. | |
| 35 | + * | |
| 36 | + * Further, older versions of OpenSSL don't support manually adding signers to | |
| 37 | + * the PKCS#7 message so have to accept that we get a certificate included in | |
| 38 | + * the signature message. Nor do such older versions of OpenSSL support | |
| 39 | + * signing with anything other than SHA1 - so we're stuck with that if such is | |
| 40 | + * the case. | |
| 41 | + */ | |
| 42 | +#if OPENSSL_VERSION_NUMBER < 0x10000000L | |
| 43 | +#define USE_PKCS7 | |
| 44 | +#endif | |
| 45 | +#ifndef USE_PKCS7 | |
| 46 | +#include <openssl/cms.h> | |
| 47 | +#else | |
| 48 | +#include <openssl/pkcs7.h> | |
| 49 | +#endif | |
| 50 | + | |
| 30 | 51 | struct module_signature { |
| 31 | 52 | uint8_t algo; /* Public-key crypto algorithm [0] */ |
| 32 | 53 | uint8_t hash; /* Digest algorithm [0] */ |
| @@ -110,30 +131,42 @@ int main(int argc, char **argv) · 77 unmodified lines | ||
| 110 | 131 | struct module_signature sig_info = { .id_type = PKEY_ID_PKCS7 }; |
| 111 | 132 | char *hash_algo = NULL; |
| 112 | 133 | char *private_key_name, *x509_name, *module_name, *dest_name; |
| 113 | − bool save_cms = false, replace_orig; | |
| 134 | + bool save_sig = false, replace_orig; | |
| 114 | 135 | bool sign_only = false; |
| 115 | 136 | unsigned char buf[4096]; |
| 116 | − unsigned long module_size, cms_size; | |
| 117 | − unsigned int use_keyid = 0, use_signed_attrs = CMS_NOATTR; | |
| 137 | + unsigned long module_size, sig_size; | |
| 138 | + unsigned int use_signed_attrs; | |
| 118 | 139 | const EVP_MD *digest_algo; |
| 119 | 140 | EVP_PKEY *private_key; |
| 141 | +#ifndef USE_PKCS7 | |
| 120 | 142 | CMS_ContentInfo *cms; |
| 143 | + unsigned int use_keyid = 0; | |
| 144 | +#else | |
| 145 | + PKCS7 *pkcs7; | |
| 146 | +#endif | |
| 121 | 147 | X509 *x509; |
| 122 | 148 | BIO *b, *bd = NULL, *bm; |
| 123 | 149 | int opt, n; |
| 124 | − | |
| 125 | 150 | OpenSSL_add_all_algorithms(); |
| 126 | 151 | ERR_load_crypto_strings(); |
| 127 | 152 | ERR_clear_error(); |
| 128 | 153 | |
| 129 | 154 | key_pass = getenv("KBUILD_SIGN_PIN"); |
| 130 | 155 | |
| 156 | +#ifndef USE_PKCS7 | |
| 157 | + use_signed_attrs = CMS_NOATTR; | |
| 158 | +#else | |
| 159 | + use_signed_attrs = PKCS7_NOATTR; | |
| 160 | +#endif | |
| 161 | + | |
| 131 | 162 | do { |
| 132 | 163 | opt = getopt(argc, argv, "dpk"); |
| 133 | 164 | switch (opt) { |
| 134 | − case 'p': save_cms = true; break; | |
| 135 | − case 'd': sign_only = true; save_cms = true; break; | |
| 165 | + case 'p': save_sig = true; break; | |
| 166 | + case 'd': sign_only = true; save_sig = true; break; | |
| 167 | +#ifndef USE_PKCS7 | |
| 136 | 168 | case 'k': use_keyid = CMS_USE_KEYID; break; |
| 169 | +#endif | |
| 137 | 170 | case -1: break; |
| 138 | 171 | default: format(); |
| 139 | 172 | } |
| @@ -157,6 +190,14 @@ int main(int argc, char **argv) · 17 unmodified lines | ||
| 157 | 190 | replace_orig = true; |
| 158 | 191 | } |
| 159 | 192 | |
| 193 | +#ifdef USE_PKCS7 | |
| 194 | + if (strcmp(hash_algo, "sha1") != 0) { | |
| 195 | + fprintf(stderr, "sign-file: %s only supports SHA1 signing\n", | |
| 196 | + OPENSSL_VERSION_TEXT); | |
| 197 | + exit(3); | |
| 198 | + } | |
| 199 | +#endif | |
| 200 | + | |
| 160 | 201 | /* Read the private key and the X.509 cert the PKCS#7 message |
| 161 | 202 | * will point to. |
| 162 | 203 | */ |
| @@ -213,7 +254,8 @@ int main(int argc, char **argv) · 50 unmodified lines | ||
| 213 | 254 | bm = BIO_new_file(module_name, "rb"); |
| 214 | 255 | ERR(!bm, "%s", module_name); |
| 215 | 256 | |
| 216 | − /* Load the CMS message from the digest buffer. */ | |
| 257 | +#ifndef USE_PKCS7 | |
| 258 | + /* Load the signature message from the digest buffer. */ | |
| 217 | 259 | cms = CMS_sign(NULL, NULL, NULL, NULL, |
| 218 | 260 | CMS_NOCERTS | CMS_PARTIAL | CMS_BINARY | CMS_DETACHED | CMS_STREAM); |
| 219 | 261 | ERR(!cms, "CMS_sign"); |
| @@ -221,17 +263,31 @@ int main(int argc, char **argv) · 1 unmodified line | ||
| 221 | 263 | ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo, |
| 222 | 264 | CMS_NOCERTS | CMS_BINARY | CMS_NOSMIMECAP | |
| 223 | 265 | use_keyid | use_signed_attrs), |
| 224 | − "CMS_sign_add_signer"); | |
| 266 | + "CMS_add1_signer"); | |
| 225 | 267 | ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) < 0, |
| 226 | 268 | "CMS_final"); |
| 227 | 269 | |
| 228 | − if (save_cms) { | |
| 229 | − char *cms_name; | |
| 270 | +#else | |
| 271 | + pkcs7 = PKCS7_sign(x509, private_key, NULL, bm, | |
| 272 | + PKCS7_NOCERTS | PKCS7_BINARY | | |
| 273 | + PKCS7_DETACHED | use_signed_attrs); | |
| 274 | + ERR(!pkcs7, "PKCS7_sign"); | |
| 275 | +#endif | |
| 230 | 276 | |
| 231 | − ERR(asprintf(&cms_name, "%s.p7s", module_name) < 0, "asprintf"); | |
| 232 | − b = BIO_new_file(cms_name, "wb"); | |
| 233 | − ERR(!b, "%s", cms_name); | |
| 234 | − ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) < 0, "%s", cms_name); | |
| 277 | + if (save_sig) { | |
| 278 | + char *sig_file_name; | |
| 279 | + | |
| 280 | + ERR(asprintf(&sig_file_name, "%s.p7s", module_name) < 0, | |
| 281 | + "asprintf"); | |
| 282 | + b = BIO_new_file(sig_file_name, "wb"); | |
| 283 | + ERR(!b, "%s", sig_file_name); | |
| 284 | +#ifndef USE_PKCS7 | |
| 285 | + ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) < 0, | |
| 286 | + "%s", sig_file_name); | |
| 287 | +#else | |
| 288 | + ERR(i2d_PKCS7_bio(b, pkcs7) < 0, | |
| 289 | + "%s", sig_file_name); | |
| 290 | +#endif | |
| 235 | 291 | BIO_free(b); |
| 236 | 292 | } |
| 237 | 293 | |
| @@ -247,9 +303,13 @@ int main(int argc, char **argv) · 9 unmodified lines | ||
| 247 | 303 | ERR(n < 0, "%s", module_name); |
| 248 | 304 | module_size = BIO_number_written(bd); |
| 249 | 305 | |
| 306 | +#ifndef USE_PKCS7 | |
| 250 | 307 | ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) < 0, "%s", dest_name); |
| 251 | − cms_size = BIO_number_written(bd) - module_size; | |
| 252 | − sig_info.sig_len = htonl(cms_size); | |
| 308 | +#else | |
| 309 | + ERR(i2d_PKCS7_bio(bd, pkcs7) < 0, "%s", dest_name); | |
| 310 | +#endif | |
| 311 | + sig_size = BIO_number_written(bd) - module_size; | |
| 312 | + sig_info.sig_len = htonl(sig_size); | |
| 253 | 313 | ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name); |
| 254 | 314 | ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name); |
| 255 | 315 | |