Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private keys in smart-card storage #5

Open
gdamjan opened this issue Dec 19, 2017 · 9 comments
Open

Private keys in smart-card storage #5

gdamjan opened this issue Dec 19, 2017 · 9 comments
Milestone

Comments

@gdamjan
Copy link
Owner

gdamjan commented Dec 19, 2017

Investigate the possibility of storing the private keys in a smart-card. sbsign doesn't support that for now.

Do we need all of the private keys in a smart-card or the PK.key is enough?

@gdamjan gdamjan added this to the v3.0 milestone Dec 19, 2017
@KenMacD
Copy link

KenMacD commented Dec 22, 2017

Personally I'd be most interested in storing the db.cert alone in a smart-card (yubikey). The others I can keep offline, but the db key will be needed every time I upgrade, so is at the highest risk of being stolen.

I plan to try it in slot 9c on my Yubikey, and then maybe use pesign to sign the .efi.

I suppose the other keys could go in the other slots, or separate smart-cards.

@gdamjan
Copy link
Owner Author

gdamjan commented Dec 23, 2017

you are correct regarding db.key

about pesign, when I tried it, it wouldn't sign properly, I might revisit it.

@xdev-x
Copy link

xdev-x commented Aug 23, 2019

I'm very interested by this. @KenMacD , did your plan was a success ?

@KenMacD
Copy link

KenMacD commented Aug 24, 2019

@davidelbaze I didn't end up trying it after @gdamjan said it didn't work for him. If you get it working thought please let me know.

@gdamjan
Copy link
Owner Author

gdamjan commented Aug 26, 2019

I have version 0.9.2-1 of sbsigntools (on Arch), and sbsign has a --engine option now:

       --engine <eng>
              use the specified engine to load the key

so I guess now it should support having the key in a smart-card (like) device such as a yubikey.

seems that yubico have information how to setup openssl (and other openssl based apps) to use an engine:
https://developers.yubico.com/PIV/Guides/Certificate_authority.html

someone should test this.

@xdev-x
Copy link

xdev-x commented Aug 26, 2019 via email

@osresearch
Copy link

This worked for me with a yubikey:

sbsign \
  --engine pkcs11 \
  --key 'pkcs11:manufacturer=piv_II;id=%02' \
  --cert cert.pem  \
  --output bzImage.signed.efi \
  bzImage

However, the PIN has to be input twice (once to "login" to the card and once to unlock the signing key) and there appears to be a bug in sbsign related to freeing the engine too early:

diff --git a/src/fileio.c b/src/fileio.c
index 032eb1e..1588057 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -90,7 +90,7 @@ EVP_PKEY *fileio_read_engine_key(const char *engine, const char *filename)
 	}
 
 	pkey = ENGINE_load_private_key(e, filename, ui, NULL);
-	ENGINE_finish(e);
+	//ENGINE_finish(e);
 
  out_free:
 	ENGINE_free(e);

@gdamjan
Copy link
Owner Author

gdamjan commented Feb 5, 2020

great input @osresearch

what does exactly 'pkcs11:manufacturer=piv_II;id=%02' mean?

@osresearch
Copy link

It is a "PKCS#11 URI format defined in RFC7512", according to the error messages if it is not specified correctly. searching for that turned up OpenSC/libp11#104 (comment) and I remembered reading somewhere that key slot 0x9c was 0x02 according to other tools, so I tried some different things until it worked...

The full workflow for creating the key in slot 9c ("9c is for Digital Signature (PIN always checked)" according to yubico-piv-tool) and the final cert.crt x509 DER file is suitable for enrolling in the UEFI PK/KEK/DB:

yubico-piv-tool -s 9c -a generate -o pubkey.pem # will take a while and overwrite any existing private keys
yubico-piv-tool -s 9c -a verify-pin -a selfsign-certificate -S '/CN=test/OU=test/O=example.com/' -i pubkey.pem -o cert.pem
yubico-piv-tool -s 9c -a import-certificate -i cert.pem
openssl x509 -outform der -in cert.pem -out cert.crt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants