a Raspberry Pi2 as an offline PKI
The PKI is implemented with openssl using the easy-rsa script from OpenVPN There are two environments:
- SHARED: It contain the keys and certificates for your clients and servers but not the CA key.
- PRIVATE: It contain the complete PKI with the CA root certificate and private key.
The usage is as follows: The SHARED environment can be accessed from other computers to fill request and retrieve signed certificates. It can also be used to update the configuration (ie add some specific client or server configuration file).
The PRIVATE environment is only accessed by RasPKI. This is your offline PKI.
There is a wrapper script called raspki
that invoke easyrsa in either the SHARED or PRIVATE environment.
either clone with --recursive
option
or use git submodule update --init
You can customize the configuration by populating the overlay/etc/easy-rsa
directory.
The content on this directory is copied to (or merged with) the SHARED and PRIVATE environment.
-
build toolchain:
make -f Makefile.toolchain
-
build raspki:
make
You need a 2GB minimum SDCard. The following instruction will ERASE all normal content present on your SDCard, make sure you are ready to dedicate it to this purpose. However if it contains a previous version of RasPKI your SHARED and PRIVATE environment will not be erased.
Also be ready to store is safe as it will contain your CA.
Identify your sdcard device (assuming sdb bellow)
sudo dd if=output/images/sdcard.img of=/dev/sdb bs=1M
You need a serial adapter connected to your Raspberry Pi2, the screen/keyboard might work but is really not tested (patch welcome). Unplug the network cable from your Raspberry Pi2, it won't work anyway
-
Open a the serial link, place the SDCard in the Raspberry Pi2 and power it up.
-
At boot it will ask for the date as the Raspberry Pi does not have an RTC and we obviously can't use NTP.
-
It will prompt you for a key to open the PRIVATE environment. (At first boot you will have to choose that key).
-
Then it will update the easy-rsa configurations and ask you whether you want to update or not each modified files. The update are done twice, first from the RasPKI distribution (in case you updated it) to the SHARED environment then from the SHARED to the PRIVATE environment.
-
-
Finally you will have to log in as root.
You can now use the raspki
command to work on your PKI.
-
At first use you should run
raspki init
to prepare the 2 environment and build your CA (you will have to chose a passphrase that will then be required for any CA operation). -
The
raspki
commands are:shared
execute easyrsa in SHARED environment, all remaining parameters are transmitted to easyrsa.private
execute easyrsa in PRIVATE environment, all remaining parameters are transmitted to easyrsa. Note: The publish feature is enabled by default to any signed certificate will be copied to the SHARED environmentpublish
update the PRIVATE environment index database, generate the CRL and copy the CA certificate, the CRL and the index database to the SHARED environment.auto
automatically process a certificate for a given type. (see raspki headers in x509-types config files bellow).list-types
list available types, with (auto) for those usable with theauto
command.status
display a summary of all certificates (and types). The columns are "t req key crt export ser st name":t
:t
=type exist,a
=exist with auto commandreq
: requestS
=in SHARED env -P
= in PRIVATE envkey
: keyS
=in SHARED env -P
= in PRIVATE envcrt
: certificateS
=in SHARED env -P
= in PRIVATE envexport
:p12
=pkcs12,p7b
=pkcs7ser
: serial numberst
: revocation statusname
: base file name
clean
remove all files associated with the given basename provided the certificate is revoked.
-
When you are done, don't forget to launch
raspki publish
to update your SHARED environment. Then typepowerdown
and wait for the Raspberry Pi activity LED to stop blinking before removing the SDCard.
- either use
easyrsa gen-req
on your server and import the request to the SHARED environment (in that case the key is on your server already and will not be copied) - or directly generate it on RasPKI with:
raspki shared gen-req your-server-common-name
- import the request in the PRIVATE environment with:
raspki private import-req your-server-common-name
- sign your request with:
raspki private sign server your-server-common-name
- generate a request in the PRIVATE environment with:
raspki private gen-req your-client-common-name
- sign your request with:
raspki private sign client your-client-common-name
- export your client certificate with it's key:
raspki private export-p12 your-client-common-name
Once installed your SD Card will have three partitions.
- The first one in FAT32 contains the Raspberry Pi2 bootloader, the kernel and the full system (as initrd).
- The second in the SHARED environment, it's and ext4 partition mounted as /mnt/shared.
- The third is the PRIVATE environment, it's an encrypted volume with an ext4 partition in it mounted as /mnt/private
Notes: Important: never mount the PRIVATE partition on any other computer, only on the Raspberry Pi2 running RasPKI with no network cable connected. It should probably not be on the same card and be backed up but it's still a lot better than having the CA on an online server...
The image only contains the partition tables and the first FAT32 partition so you can update your RasPKI configuration without destroying your SHARED and PRIVATE environments.
raspki comes with an auto
command, this command simply executes easy-rsa several time to generate, sign, export a given certificate according to the configuration.
This is done by parsing the headers to generate the parameters to the easyrsa command.
Using the headers the x509-types file is no longer generic as the client
and server
files provided by easy-rsa but are specific to a certificate.
The file should configure as much parameters as needed to automate the generation of the certificate.
- for a server certificate named
server-name
the header should be
##raspki shared --req-cn=your-server-common-name --batch gen-req server-name
##raspki private import-req server-name
##raspki private sign-req server-name server-name
You can add any needed easyrsa parameters to each line.
The rest of the file should be similar to the server
file provided by easyrsa. You can add extra openssl configuration.
- for a client certificate named
client-name
the header should be
##raspki private --req-cn=your-client-common-name --batch gen-req client-name
##raspki private sign-req client-name client-name
##raspki private export-p12 client-name
This is basically the Raspberry Pi2 defconfig with the network stack disabled and the driver for the ChaosKey enabled.
Generating cryptographic keys relies on good random number generators, so test yours !
dieharder -a -g 201 -f /dev/hwrng
This is VERY slow the Raspberry Pi2 rng has a low bandwidth. About 2.84e+04 rands/second as reported by dieharder mesured on a Raspberry Pi2 2.
dieharder -a -g 201 -f /dev/chaoskey0
The ChaosKey is a little faster 6.20e+04 rands/second when connected to a Raspberry Pi2.
To test /dev/random use:
dieharder -a -g 500