aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/sign-file.c
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2015-07-20 16:16:29 -0400
committerDavid Howells <dhowells@redhat.com>2015-08-07 11:26:14 -0400
commit6e3e281f39af78bd680b82d9762bf6c4f8f3f5f4 (patch)
tree612d8e13158ff6fe8a988154e1883ae7bed9a17d /scripts/sign-file.c
parentaf1eb2913275c3ab1598b0c24c893499092df08a (diff)
modsign: Allow signing key to be PKCS#11
This is only the key; the corresponding *cert* still needs to be in $(topdir)/signing_key.x509. And there's no way to actually use this from the build system yet. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'scripts/sign-file.c')
-rwxr-xr-xscripts/sign-file.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/scripts/sign-file.c b/scripts/sign-file.c
index 720b9bc933ae..ad0aa21bd3ac 100755
--- a/scripts/sign-file.c
+++ b/scripts/sign-file.c
@@ -22,6 +22,7 @@
22#include <openssl/pem.h> 22#include <openssl/pem.h>
23#include <openssl/pkcs7.h> 23#include <openssl/pkcs7.h>
24#include <openssl/err.h> 24#include <openssl/err.h>
25#include <openssl/engine.h>
25 26
26struct module_signature { 27struct module_signature {
27 uint8_t algo; /* Public-key crypto algorithm [0] */ 28 uint8_t algo; /* Public-key crypto algorithm [0] */
@@ -154,11 +155,29 @@ int main(int argc, char **argv)
154 /* Read the private key and the X.509 cert the PKCS#7 message 155 /* Read the private key and the X.509 cert the PKCS#7 message
155 * will point to. 156 * will point to.
156 */ 157 */
157 b = BIO_new_file(private_key_name, "rb"); 158 if (!strncmp(private_key_name, "pkcs11:", 7)) {
158 ERR(!b, "%s", private_key_name); 159 ENGINE *e;
159 private_key = PEM_read_bio_PrivateKey(b, NULL, pem_pw_cb, NULL); 160
160 ERR(!private_key, "%s", private_key_name); 161 ENGINE_load_builtin_engines();
161 BIO_free(b); 162 drain_openssl_errors();
163 e = ENGINE_by_id("pkcs11");
164 ERR(!e, "Load PKCS#11 ENGINE");
165 if (ENGINE_init(e))
166 drain_openssl_errors();
167 else
168 ERR(1, "ENGINE_init");
169 if (key_pass)
170 ERR(!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0), "Set PKCS#11 PIN");
171 private_key = ENGINE_load_private_key(e, private_key_name, NULL,
172 NULL);
173 ERR(!private_key, "%s", private_key_name);
174 } else {
175 b = BIO_new_file(private_key_name, "rb");
176 ERR(!b, "%s", private_key_name);
177 private_key = PEM_read_bio_PrivateKey(b, NULL, pem_pw_cb, NULL);
178 ERR(!private_key, "%s", private_key_name);
179 BIO_free(b);
180 }
162 181
163 b = BIO_new_file(x509_name, "rb"); 182 b = BIO_new_file(x509_name, "rb");
164 ERR(!b, "%s", x509_name); 183 ERR(!b, "%s", x509_name);