aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@suse.com>2015-07-20 16:16:27 -0400
committerDavid Howells <dhowells@redhat.com>2015-08-07 11:26:13 -0400
commit23dfbbabbb3a62104b040b422121c84800312ad0 (patch)
tree12439e74a90588034ce8a0eab7f12a05f51c2a38 /scripts
parent3f1e1bea34740069f70c6bc92d0f712345d5c28e (diff)
sign-file: Add option to only create signature file
Make the -d option (which currently isn't actually wired to anything) write out the PKCS#7 message as per the -p option and then exit without either modifying the source or writing out a compound file of the source, signature and metadata. This will be useful when firmware signature support is added upstream as firmware will be left intact, and we'll only require the signature file. The descriptor is implicit by file extension and the file's own size. Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com> Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/sign-file.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/scripts/sign-file.c b/scripts/sign-file.c
index 5b8a6dda3235..39aaabe89388 100755
--- a/scripts/sign-file.c
+++ b/scripts/sign-file.c
@@ -86,13 +86,14 @@ int main(int argc, char **argv)
86 char *hash_algo = NULL; 86 char *hash_algo = NULL;
87 char *private_key_name, *x509_name, *module_name, *dest_name; 87 char *private_key_name, *x509_name, *module_name, *dest_name;
88 bool save_pkcs7 = false, replace_orig; 88 bool save_pkcs7 = false, replace_orig;
89 bool sign_only = false;
89 unsigned char buf[4096]; 90 unsigned char buf[4096];
90 unsigned long module_size, pkcs7_size; 91 unsigned long module_size, pkcs7_size;
91 const EVP_MD *digest_algo; 92 const EVP_MD *digest_algo;
92 EVP_PKEY *private_key; 93 EVP_PKEY *private_key;
93 PKCS7 *pkcs7; 94 PKCS7 *pkcs7;
94 X509 *x509; 95 X509 *x509;
95 BIO *b, *bd, *bm; 96 BIO *b, *bd = NULL, *bm;
96 int opt, n; 97 int opt, n;
97 98
98 ERR_load_crypto_strings(); 99 ERR_load_crypto_strings();
@@ -102,6 +103,7 @@ int main(int argc, char **argv)
102 opt = getopt(argc, argv, "dp"); 103 opt = getopt(argc, argv, "dp");
103 switch (opt) { 104 switch (opt) {
104 case 'p': save_pkcs7 = true; break; 105 case 'p': save_pkcs7 = true; break;
106 case 'd': sign_only = true; save_pkcs7 = true; break;
105 case -1: break; 107 case -1: break;
106 default: format(); 108 default: format();
107 } 109 }
@@ -148,8 +150,10 @@ int main(int argc, char **argv)
148 /* Open the destination file now so that we can shovel the module data 150 /* Open the destination file now so that we can shovel the module data
149 * across as we read it. 151 * across as we read it.
150 */ 152 */
151 bd = BIO_new_file(dest_name, "wb"); 153 if (!sign_only) {
152 ERR(!bd, "%s", dest_name); 154 bd = BIO_new_file(dest_name, "wb");
155 ERR(!bd, "%s", dest_name);
156 }
153 157
154 /* Digest the module data. */ 158 /* Digest the module data. */
155 OpenSSL_add_all_digests(); 159 OpenSSL_add_all_digests();
@@ -180,6 +184,9 @@ int main(int argc, char **argv)
180 BIO_free(b); 184 BIO_free(b);
181 } 185 }
182 186
187 if (sign_only)
188 return 0;
189
183 /* Append the marker and the PKCS#7 message to the destination file */ 190 /* Append the marker and the PKCS#7 message to the destination file */
184 ERR(BIO_reset(bm) < 0, "%s", module_name); 191 ERR(BIO_reset(bm) < 0, "%s", module_name);
185 while ((n = BIO_read(bm, buf, sizeof(buf))), 192 while ((n = BIO_read(bm, buf, sizeof(buf))),