History

Merge 4.3-rc4 into char-misc-next

This is needed due to the duplicated iommu stuff to help with the merge and to prevent future issues.

Greg Kroah-Hartman committed 11 years ago

Commit c39b7ee2 parents 1e1851f 049e6dd285 files · +2457 −1583Browse files

Showing the changes to scripts (2 of 285 files). Show all

Unified · Split

2 files
  1. scripts/extract-cert.c +0 −4
  2. scripts/sign-file.c +77 −17
scripts/extract-cert.c+0−4
@@ -17,13 +17,9 @@ · 16 unmodified lines
1717 #include <stdint.h>
1818 #include <stdbool.h>
1919 #include <string.h>
20−#include <getopt.h>
2120 #include <err.h>
22−#include <arpa/inet.h>
2321 #include <openssl/bio.h>
24−#include <openssl/evp.h>
2522 #include <openssl/pem.h>
26−#include <openssl/pkcs7.h>
2723 #include <openssl/err.h>
2824 #include <openssl/engine.h>
2925
scripts/sign-file.c+77−17
@@ -20,13 +20,34 @@ · 19 unmodified lines
2020 #include <getopt.h>
2121 #include <err.h>
2222 #include <arpa/inet.h>
23+#include <openssl/opensslv.h>
2324 #include <openssl/bio.h>
2425 #include <openssl/evp.h>
2526 #include <openssl/pem.h>
26−#include <openssl/cms.h>
2727 #include <openssl/err.h>
2828 #include <openssl/engine.h>
2929
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+
3051 struct module_signature {
3152 uint8_t algo; /* Public-key crypto algorithm [0] */
3253 uint8_t hash; /* Digest algorithm [0] */
@@ -110,30 +131,42 @@ int main(int argc, char **argv) · 77 unmodified lines
110131 struct module_signature sig_info = { .id_type = PKEY_ID_PKCS7 };
111132 char *hash_algo = NULL;
112133 char *private_key_name, *x509_name, *module_name, *dest_name;
113− bool save_cms = false, replace_orig;
134+ bool save_sig = false, replace_orig;
114135 bool sign_only = false;
115136 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;
118139 const EVP_MD *digest_algo;
119140 EVP_PKEY *private_key;
141+#ifndef USE_PKCS7
120142 CMS_ContentInfo *cms;
143+ unsigned int use_keyid = 0;
144+#else
145+ PKCS7 *pkcs7;
146+#endif
121147 X509 *x509;
122148 BIO *b, *bd = NULL, *bm;
123149 int opt, n;
124−
125150 OpenSSL_add_all_algorithms();
126151 ERR_load_crypto_strings();
127152 ERR_clear_error();
128153
129154 key_pass = getenv("KBUILD_SIGN_PIN");
130155
156+#ifndef USE_PKCS7
157+ use_signed_attrs = CMS_NOATTR;
158+#else
159+ use_signed_attrs = PKCS7_NOATTR;
160+#endif
161+
131162 do {
132163 opt = getopt(argc, argv, "dpk");
133164 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
136168 case 'k': use_keyid = CMS_USE_KEYID; break;
169+#endif
137170 case -1: break;
138171 default: format();
139172 }
@@ -157,6 +190,14 @@ int main(int argc, char **argv) · 17 unmodified lines
157190 replace_orig = true;
158191 }
159192
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+
160201 /* Read the private key and the X.509 cert the PKCS#7 message
161202 * will point to.
162203 */
@@ -213,7 +254,8 @@ int main(int argc, char **argv) · 50 unmodified lines
213254 bm = BIO_new_file(module_name, "rb");
214255 ERR(!bm, "%s", module_name);
215256
216− /* Load the CMS message from the digest buffer. */
257+#ifndef USE_PKCS7
258+ /* Load the signature message from the digest buffer. */
217259 cms = CMS_sign(NULL, NULL, NULL, NULL,
218260 CMS_NOCERTS | CMS_PARTIAL | CMS_BINARY | CMS_DETACHED | CMS_STREAM);
219261 ERR(!cms, "CMS_sign");
@@ -221,17 +263,31 @@ int main(int argc, char **argv) · 1 unmodified line
221263 ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo,
222264 CMS_NOCERTS | CMS_BINARY | CMS_NOSMIMECAP |
223265 use_keyid | use_signed_attrs),
224− "CMS_sign_add_signer");
266+ "CMS_add1_signer");
225267 ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) < 0,
226268 "CMS_final");
227269
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
230276
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
235291 BIO_free(b);
236292 }
237293
@@ -247,9 +303,13 @@ int main(int argc, char **argv) · 9 unmodified lines
247303 ERR(n < 0, "%s", module_name);
248304 module_size = BIO_number_written(bd);
249305
306+#ifndef USE_PKCS7
250307 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);
253313 ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name);
254314 ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
255315