freebsd-skq/lib/libsecureboot
sjg 7993a62d04 veloader use vectx API for kernel and modules
The vectx API, computes the hash for verifying a file as it is read.
This avoids the overhead of reading files twice - once to verify, then
again to load.

For doing an install via loader, avoiding the need to rewind
large files is critical.

This API is only used for modules, kernel and mdimage as these are the
biggest files read by the loader.
The reduction in boot time depends on how expensive the I/O is
on any given platform.  On a fast VM we see 6% improvement.

For install via loader the first file to be verified is likely to be the
kernel, so some of the prep work (finding manifest etc) done by
verify_file() needs to be factored so it can be reused for
vectx_open().

For missing or unrecognized fingerprint entries, we fail
in vectx_open() unless verifying is disabled.

Otherwise fingerprint check happens in vectx_close() and
since this API is only used for files which must be verified
(VE_MUST) we panic if we get an incorrect hash.

Reviewed by:	imp,tsoome
MFC after:	1 week
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org//D23827
2020-03-08 17:42:42 +00:00
..
efi Extend libsecureboot(old libve) to obtain trusted certificates from UEFI and implement revocation 2019-03-06 06:39:42 +00:00
h veloader use vectx API for kernel and modules 2020-03-08 17:42:42 +00:00
openpgp libsecureboot: avoid recusion in ve_trust_init 2019-07-11 22:06:59 +00:00
tests veloader use vectx API for kernel and modules 2020-03-08 17:42:42 +00:00
brf.c
libsecureboot-priv.h libsecureboot: allow OpenPGP support to be dormant 2019-06-26 23:33:32 +00:00
local.trust.mk libsecureboot: allow OpenPGP support to be dormant 2019-06-26 23:33:32 +00:00
Makefile
Makefile.depend Update Makefile.depend files 2019-12-11 17:37:53 +00:00
Makefile.depend.amd64 Update Makefile.depend files 2019-12-11 17:37:53 +00:00
Makefile.depend.host
Makefile.inc libsecureboot: make it easier to customize trust anchors 2019-05-09 22:25:12 +00:00
Makefile.libsa.inc Create kernel module to parse Veriexec manifest based on envs 2019-04-03 03:57:37 +00:00
pass_manifest.c Create kernel module to parse Veriexec manifest based on envs 2019-04-03 03:57:37 +00:00
readfile.c libsecureboot: allow OpenPGP support to be dormant 2019-06-26 23:33:32 +00:00
README.rst
vectx.c veloader use vectx API for kernel and modules 2020-03-08 17:42:42 +00:00
veopen.c Allow no_hash to appear in manifest. 2019-04-23 20:25:25 +00:00
vepcr.c libsecureboot: allow control of when pseudo pcr is updated 2019-05-19 20:28:49 +00:00
verify_file.c veloader use vectx API for kernel and modules 2020-03-08 17:42:42 +00:00
vesigned.c
veta.c
vets.c Avoid unused vars when VE_ECDSA_HASH_AGAIN undefined 2019-12-20 21:56:28 +00:00

libsecureboot
*************

This library depends one way or another on verifying digital signatures.
To do that, the necessary trust anchors need to be available.

The simplest (and most attractive for an embedded system) is to
capture them in this library.

The makefile ``local.trust.mk`` is responsible for doing that.
The file provided is just an example and depends on the environment
here at Juniper.

Within Juniper we use signing servers, which apart from signing things
provide access to the necessary trust anchors.
That signing server is freely available - see
http://www.crufty.net/sjg/docs/signing-server.htm

X.509 certificates chains offer a lot of flexibility over time and are
a great solution for an embedded vendor like Juniper or even
FreeBSD.org, but are probably overkill for personal or small site use.

Setting up a CA for this is rather involved so I'll just provide a
link below to suitable tutorial below.

Using OpenPGP is much simpler.


OpenPGP
========

This is very simple to setup and use.

An RSA key pair can be generated with::

	GNUPGHOME=$PWD/.gnupg gpg --openpgp \
	--quick-generate-key --batch --passphrase '' "keyname" RSA

The use of ``GNUPGHOME=$PWD/.gnupg`` just avoids messing with personal
keyrings.
We can list the resulting key::

	GNUPGHOME=$PWD/.gnupg gpg --openpgp --list-keys

	gpg: WARNING: unsafe permissions on homedir
	'/h/sjg/openpgp/.gnupg'
	gpg: Warning: using insecure memory!
	/h/sjg/openpgp/.gnupg/pubring.kbx
	---------------------------------
	pub   rsa2048 2018-03-26 [SC] [expires: 2020-03-25]
	      AB39B111E40DD019E0E7C171ACA72B4719FD2523
	      uid           [ultimate] OpenPGPtest

The ``keyID`` we want later will be the last 8 octets
(``ACA72B4719FD2523``)
This is what we will use for looking up the key.

We can then export the private and public keys::

	GNUPGHOME=$PWD/.gnupg gpg --openpgp \
	--export --armor > ACA72B4719FD2523.pub.asc
	GNUPGHOME=$PWD/.gnupg gpg --openpgp \
	--export-secret-keys --armor > ACA72B4719FD2523.sec.asc

The public key ``ACA72B4719FD2523.pub.asc`` is what we want to
embed in this library.
If you look at the ``ta_asc.h`` target in ``openpgp/Makefile.inc``
we want the trust anchor in a file named ``t*.asc``
eg. ``ta_openpgp.asc``.

The ``ta_asc.h`` target will capture all such ``t*.asc`` into that
header.

Signatures
----------

We expect ascii armored (``.asc``) detached signatures.
Eg. signature for ``manifest`` would be in ``manifest.asc``

We only support version 4 signatures using RSA (the default for ``gpg``).


OpenSSL
========

The basic idea here is to setup a private CA.

There are lots of good tutorials on available on this topic;
just google *setup openssl ca*.
A good example is https://jamielinux.com/docs/openssl-certificate-authority/

All we need for this library is a copy of the PEM encoded root CA
certificate (trust anchor).  This is expected to be in a file named
``t*.pem`` eg. ``ta_rsa.pem``.

The ``ta.h`` target in ``Makefile.inc`` will combine all such
``t*.pem`` files into that header.

Signatures
----------

For Junos we currently use EC DSA signatures with file extension
``.esig`` so the signature for ``manifest`` would be ``manifest.esig``

This was the first signature method we used with the remote signing
servers and it ends up being a signature of a hash.
Ie. client sends a hash which during signing gets hashed again.
So for Junos we define VE_ECDSA_HASH_AGAIN which causes ``verify_ec``
to hash again.

Otherwise our EC DSA and RSA signatures are the default used by
OpenSSL - an original design goal was that a customer could verify our
signatures using nothing but an ``openssl`` binary.


Self tests
==========

If you want the ``loader`` to perform self-test of a given signature
verification method on startup (a must for FIPS 140-2 certification)
you need to provide a suitable file signed by each supported trust
anchor.

These should be stored in files with names that start with ``v`` and
have the same extension as the corresponding trust anchor.
Eg. for ``ta_openpgp.asc`` we use ``vc_openpgp.asc``
and for ``ta_rsa.pem`` we use ``vc_rsa.pem``.

Note for the X.509 case we simply extract the 2nd last certificate
from the relevant chain - which is sure to be a valid certificate
signed by the corresponding trust anchor.

--------------------
$FreeBSD$