gnupg-root/README.md

250 lines
8.5 KiB
Markdown
Raw Permalink Normal View History

2020-09-10 16:02:20 +00:00
# GnuPG root
To get the hole gpg thing working, you should use a offline computer. This system needs to kept save and usually generates and/or store your master key. From this system you would also deliver those subkeys, which you can use on a daily base.
Most people do not have laying around a lot of hardware, which the would spend using for this. In general nobody uses a dedicated offline root CA, if I need to explain why privacy is important.
2022-12-31 08:06:45 +00:00
## Prerequisites
2020-09-10 16:02:20 +00:00
1. small embedded linux powered device
2. easily available and widely used platform
3. security orientated os
2022-03-27 18:18:18 +00:00
4. offline
2020-09-10 16:02:20 +00:00
5. RO system
6. persistance with overlay
7. possible file integrity checks
8. USB-A connector(s) for the GNUK token/SmartCard Reader
2022-12-31 08:06:45 +00:00
## terminal user interface
2020-09-10 16:02:20 +00:00
2022-12-31 08:06:45 +00:00
### main page - overview
2020-09-10 16:02:20 +00:00
1. Integrity OK/Fail
1. /root filesystem
2. user config
3. .gnupg path
2. rootCA/MasterKey SmartCard/GNUK available
3. user SmartCard/GNUK available
4. RNG status
5. RTC/Time/Date status
6. Key Expire failure/warning
7. Key length Failure/Warning (BSI recommendation)
8. revocation certificate available
## 00-preparation
1. format sd card with 3 partitions
1. MBR 'msdos'
2. 256MB FAT32 for /boot partition
3. 2GB ext4 for overlay
2022-12-28 20:11:15 +00:00
2. extract image: `tar -xzvf ~/Downloads/alpine-rpi-3.12.0-armhf.tar.gz -C /run/media/**** --no-same-owner `
2020-09-10 16:02:20 +00:00
3. edit cmdline.txt
4. create usercfg.txt
2022-01-07 18:22:39 +00:00
5. prepare /cache with useful apk (e2fsprogs, lsblk, vim, gnupg, gnupg-scdaemon, pinentry, ccid, opensc, pcsc-lite-libs, tmux, htop, exfat-utils, cryptsetup, mkinitfs, squashfs-tools, p7zip libusb, hwids-usb {pcsc-lite libudev-zero fsverity-utils} ) [70MB]
2021-01-13 10:28:08 +00:00
6. connect UART TX/RX/GND to pin 8/10/6 green/white/black
2020-09-10 16:02:20 +00:00
7. boot rpi
8. mount second partition to folder /media/mmcblk0p2
9. change /etc/lbu/lbu.conf
2022-03-27 18:18:18 +00:00
10. run setup-alpine ( rc- add wpa_supplicant boot [confirm])
11. fix chrony and rtc (rc- add hwclock boot, rc- del chronyd default rc- -u [confirm])
2020-09-10 16:02:20 +00:00
12. add community repo (ccid, opensc)
2022-03-27 18:18:18 +00:00
13. rc- del acpid default (arm only)
2021-01-13 10:28:08 +00:00
## persistent /usr
2022-12-28 20:11:15 +00:00
1. `dd if=/dev/zero of=/media/mmcblk0p2/persist.img bs=1024 count=0 seek=2097152`
2. `apk add e2fsprogs`
3. `mkfs.ext4 /media/mmcblk0p2/persist.img`
4. `echo "/media/mmcblk0p2/persist.img /media/persist ext4 rw,relatime,errors=remount-ro 0 0" >> /etc/fstab`
5. `mkdir /media/persist`
6. `mount -a`
7. `mkdir /media/persist/usr `
8. `mkdir /media/persist/.work `
9. `echo "overlay /usr overlay lowerdir=/usr,upperdir=/media/persist/usr,workdir=/media/persist/.work 0 0" >> /etc/fstab `
10. `mount -a`
11. `lbu commit`
2020-09-10 16:02:20 +00:00
## rng
2022-03-27 18:18:18 +00:00
- the kernel has hwrnd support (CONFIG_HW_RANDOM_BCM2835=y)
- haveged speeds up the random process to 40seconds
- rngd speeds up this to 52 seconds
- an added BT4.0 usb adapter speeds up this to 20seconds
- an added usb stick speeds up this to 5 seconds
- lbu include /var/lib/misc/random-seed [needs confirm]
2020-09-10 16:02:20 +00:00
## rtc
2022-03-27 18:18:18 +00:00
- a ds3231 is added to the i2c pins and works due the added 'dtoverlay=i2c-rtc,ds3231'
`[ 29.896261] rtc-ds1307 1-0068: registered as rtc0`
- glibc posix api change and leads to hwclock openRC bug https://github.com/OpenRC/openrc/issues/352
`CONFIG_RTC_HCTOSYS not set`
2020-09-10 16:02:20 +00:00
## encrypted container (encrypted storage)
2022-12-28 20:11:15 +00:00
```
2021-01-13 10:28:08 +00:00
apk add cryptsetup
fallocate -l 10MB PRIVATE [minimal 20MB]
cryptsetup -v luksFormat PRIVATE [takes some seconds]
2020-09-10 16:02:20 +00:00
--use secure passphrase
2022-01-07 18:22:39 +00:00
cryptsetup -v luksOpen /mnt/mmcblk0p2/PRIVATE private_file
2021-01-13 10:28:08 +00:00
mkfs -t ext4 /dev/mapper/private_file
2020-09-10 16:02:20 +00:00
mkdir /mnt/private_file
2022-01-07 18:22:39 +00:00
ln -s /mnt/private_file/user/.gnupg /home/user/.gnupg
ln -s /mnt/private_file/root/.gnupg /root/.gnupg
2020-09-10 16:02:20 +00:00
mount /dev/mapper/private_file /mnt/private_file
--Umount and close file
2022-01-07 18:22:39 +00:00
killall gpg-agent
2020-09-10 16:02:20 +00:00
umount /mnt/private_file
cryptsetup luksClose private_file
2022-12-28 20:11:15 +00:00
```
2020-09-10 16:02:20 +00:00
2022-12-28 20:11:15 +00:00
```
2022-01-07 18:22:39 +00:00
mkdir /mnt/private_file/user/.gnupg
chmod 750 /mnt/private_file/user
chown user:user /mnt/private_file/user/.gnupg
2022-12-28 20:11:15 +00:00
```
2022-01-07 18:22:39 +00:00
2021-01-13 10:28:08 +00:00
edit /etc/mdev.conf for usb tokens [ToDo]
killall gpg-agent
2022-01-07 18:22:39 +00:00
#mount encrypted container
2022-12-31 08:06:45 +00:00
```
2022-01-07 18:22:39 +00:00
cryptsetup -v luksOpen /media/mmcblk0p2/PRIVATE private_file
mount /dev/mapper/private_file /mnt/private_file
--Umount and close file
killall gpg-agent
umount /mnt/private_file
cryptsetup luksClose private_file
2022-12-31 08:06:45 +00:00
```
2022-01-07 18:22:39 +00:00
2021-01-13 10:28:08 +00:00
##kernel update [inProgress]
2022-06-05 09:49:31 +00:00
2022-03-27 18:18:18 +00:00
##kernel [inProgress]
2022-12-28 20:11:15 +00:00
related: [https://gitlab.alpinelinux.org/alpine/aports/-/issues/11980]
2021-01-13 10:28:08 +00:00
2022-12-28 20:11:15 +00:00
```
2021-01-13 10:28:08 +00:00
gnupg-root:/media/mmcblk0p2# mkdir modloopfs
gnupg-root:/media/mmcblk0p2# cd modloopfs/
gnupg-root:/media/mmcblk0p2/modloopfs# unsquashfs /media/mmcblk0p1/boot/modloop-
rpi
Parallel unsquashfs: Using 1 processor
1814 inodes (2087 blocks) to write
created 1814 files
created 359 directories
created 0 symlinks
created 0 devices
created 0 fifos
gnupg-root:/media/mmcblk0p2/modloopfs/squashfs-root# mount | grep modloop
/media/mmcblk0p1/boot/modloop-rpi on /.modloop type squashfs (ro,relatime)
gnupg-root:/media/mmcblk0p2/modloopfs/squashfs-root# ls -l /lib/modules
lrwxrwxrwx 1 root root 17 Jan 1 1970 /lib/modules -> /.modloop/modules
gnupg-root:/media/mmcblk0p2/modloopfs/squashfs-root# rm /lib/modules
gnupg-root:/media/mmcblk0p2/modloopfs/squashfs-root# ln -s /media/mmcblk0p2/modloopfs/squashfs-root/modules /lib/modules
gnupg-root:/media/mmcblk0p2/modloopfs/squashfs-root# ls -l /lib/modules
lrwxrwxrwx 1 root root 48 Sep 26 13:58 /lib/modules -> /media/mmcblk0p2/modloopfs/squashfs-root/modules
2022-12-28 20:11:15 +00:00
```
```
2021-01-13 10:28:08 +00:00
mksquashfs squashfs-root/ livefs.squashfs -noappend -always-use-fragments
apk add linux-rpi
2022-12-28 20:11:15 +00:00
```
2021-01-13 10:28:08 +00:00
## generic image upgrade
2022-06-05 09:49:31 +00:00
2022-01-07 18:22:39 +00:00
[offline]
2022-12-28 20:11:15 +00:00
1. extract original image to first partion
2. restore cmdline and usercfg.txt
2022-12-31 08:06:45 +00:00
- [root] delete from overlay partition the cache folder
2022-12-28 20:11:15 +00:00
1. in case of a folder (delete from overlay the /usr)
2. in case of an image
- `rm persist.img && dd if=/dev/zero of=persist.img bs=1024 count=0 seek=209715`
2022-12-31 08:06:45 +00:00
- `mkfs.ext4 persist.img`
2022-01-07 18:22:39 +00:00
[online]
2022-12-28 20:11:15 +00:00
1. recreate .work folder under /media/persist
2. recreate usr folder under /media/persist
2022-12-31 08:06:45 +00:00
3. `mkdir /mnt/private_file`
2022-12-28 20:11:15 +00:00
4. check mountpoint for /usr | mount /usr
5. fix the repository
6. fix the network interface
7. apk update
8. apk upgrade
9. 're-add' installed packages [e.g. 00-preparation]
2022-12-31 08:06:45 +00:00
10. remount /media/mmcblk0p1 rewritable
2022-12-28 20:11:15 +00:00
11. `mount -o rw,remount /media/mmcblk0p1/`
2022-12-31 08:06:45 +00:00
12. `cd /media/mmcblk0p2/cache && cp *.apk /media/mmcblk0p1/apks/armhf`
13. `lsblk`
14. `ln -s /media/mmcblk0p1/boot boot`
15. `mkinitfs`
16. reboot without lbu commit
2022-06-05 09:49:31 +00:00
## fast major release update
2022-03-27 18:18:18 +00:00
1. delete content of first partition
2. extract original image to first partion
3. restore cmdline and usercfg.txt
- `modules=loop,overlay,squashfs,sd-mod,usb-storage quiet dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200`
- usercfg.txt
2022-06-05 09:49:31 +00:00
4. delete from overlay the cache folder
5. boot RPI zero
2022-12-28 20:11:15 +00:00
6. change `/etc/apk/repositories`
2022-06-05 09:49:31 +00:00
7. lbu commit
2022-03-27 18:18:18 +00:00
8. reboot
9. apk update
10. apk upgrade
11. reboot
2022-12-31 08:06:45 +00:00
## generic minor (to install it into ram)
2022-03-27 18:18:18 +00:00
1. apk
2. apk upgrade
3. lbu commit
2021-01-13 10:28:08 +00:00
## 1.44" OLED and button
2022-12-31 08:06:45 +00:00
create a overlay for /usr otherwise space is missing
2021-01-13 10:28:08 +00:00
https://gist.github.com/sdalu/4fd108e0a96d6b41d52fde7542cc95ce [not working fbtft module mossing]
apk add python2 #obsolete
2022-01-07 18:22:39 +00:00
apk add build-base #binary is build for rpi3
2021-01-13 10:28:08 +00:00
// ToDo
sudo modprobe fbtft_device name=adafruit18_green gpios=reset:27,dc:25,cs:8,led:24 height=128 width=128 rotate=180 fps=30 bgr=1 speed=40000000 debug=$((1<<5))
vi /etc/modprobe.d/fbtft.conf
options fbtft_device name=fb_st7735r gpios=reset:27,dc:25,led:18 speed=16000000 bgr=1 custom=1 width=128 height=128
2022-01-07 18:22:39 +00:00
## python approach
pip install --user RPi.GPIO
pip install --user spidev
2022-12-31 08:06:45 +00:00
## modern kernel approach
2022-01-07 18:22:39 +00:00
wget https://github.com/juj/fbcp-ili9341/archive/refs/heads/master.zip
cmake -DWAVESHARE_ST7735S_HAT=ON -DSPI_BUS_CLOCK_DIVISOR=6
apk add raspberrypi-dev
2021-01-13 10:28:08 +00:00
## nitrokey
2022-12-31 08:06:45 +00:00
```
2022-01-07 18:22:39 +00:00
apk add py-pip build-base python3-dev py3-wheel [240Mb]
2021-01-13 10:28:08 +00:00
apk add libffi-dev [7Mb]
2022-01-07 18:22:39 +00:00
apk add openssl-dev rust cargo [337Mb]
#pip install --user setuptools_rust
apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo
apk add py3-pep517 py3-cryptography
//see https://cryptography.io/en/latest/installation/
2021-01-13 10:28:08 +00:00
reboot
lbu inc /home
lbu inc /root
2022-01-07 18:22:39 +00:00
pip3 install --user wheel
pip3 install --user pynitrokey [takes about 35min, can fail due missing space left on device, but cbor fails nevertheless]
2022-12-31 08:06:45 +00:00
```
2021-01-13 10:28:08 +00:00
#fix $PATH to /root/.local/bin in /etc/profile
#need mdev/udev rules to grant access for user
#libudev-zero is a replacement, which is needed for pcscd
2022-01-07 18:22:39 +00:00
2021-01-13 10:28:08 +00:00
## ToDo
#tmux
2022-01-07 18:22:39 +00:00
#camera to scan QR code
#predefine common action scheme
#general reconsideration of usefulness
2021-01-13 10:28:08 +00:00
2020-09-10 16:02:20 +00:00
### links
2022-12-31 08:06:45 +00:00
[https://github.com/hashbang/airgap]
[https://riseup.net/de/security/message-security/openpgp/gpg-best-practices]
[https://vincentserpoul.github.io/post/alpine-linux-rpi0/]