aboutsummaryrefslogtreecommitdiff
path: root/keyfile.sh
blob: c9dd31f714d629f0a1e2153215424c387e070e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash

set -euo pipefail

KEYFILE="$HOME/.local/share/keepass/trezor.key"

mkdir -m 0700 -p "$(dirname "$KEYFILE")"

# We use the SLIP-0016 master key as the key file for our KeePass database,
# with a more appropriate key.
# <https://github.com/satoshilabs/slips/blob/master/slip-0016.md>

ADDRESS=m/10016h/0
KEY='Unlock vault.kdbx?'
VALUE='2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee'

"${TREZORCTL:-trezorctl}" encrypt-keyvalue --address "$ADDRESS" --prompt always "$KEY" "$VALUE" \
	| xxd -r -p > "$KEYFILE"

# Restrict permissions on the file. We also set the `nodump` flag which some
# software will respect and omit from backups (notably, `tarsnap` which I use).
chmod 0400 "$KEYFILE"
if command -v chattr &>/dev/null; then
	chattr +d "$KEYFILE"
fi
if command -v chflags &>/dev/null; then
	chflags nodump "$KEYFILE"
fi