mirror of
https://github.com/m8tin/cis.git
synced 2026-11-02 14:17:24 +01:00
Improvments and renaming of aptUpdate
This commit is contained in:
2 files changed
+26
-22
No files matched your search
File renamed without changes.
+26
-22
@@ -1,5 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
AES_STORE_FILE=~/tpm/aes-key-safe
|
||||||
|
SECRETS_STORE_FILE=~/tpm/secrets
|
||||||
|
SECRETS_PLAIN_PATH=/run/user/$(id -u)/secrets/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function checkPreconditions() {
|
function checkPreconditions() {
|
||||||
@@ -18,8 +22,8 @@ function checkPreconditions() {
|
|||||||
|
|
||||||
function checkSafe() {
|
function checkSafe() {
|
||||||
printf -- "%s" 'Checking TPM derived safe ... ' >&2 \
|
printf -- "%s" 'Checking TPM derived safe ... ' >&2 \
|
||||||
&& [ -f /root/tpm/aes-key-safe.priv ] \
|
&& [ -f "${AES_STORE_FILE}" ] \
|
||||||
&& [ -f /root/tpm/aes-key-safe.pub ] \
|
&& [ -f "${AES_STORE_FILE}.pub" ] \
|
||||||
&& printf -- "%s\n" '(found)' >&2 \
|
&& printf -- "%s\n" '(found)' >&2 \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
@@ -53,22 +57,19 @@ function checkOrCreateSafe() {
|
|||||||
checkSafe \
|
checkSafe \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
[ -f /root/tpm/aes-key-safe.priv ] \
|
[ -f "${AES_STORE_FILE}" ] \
|
||||||
&& echo 'ABORT existing safe file found: "/root/tpm/aes-key-safe.priv"' >&2 \
|
&& echo 'ABORT existing safe file found: "${AES_STORE_FILE}"' >&2 \
|
||||||
&& return 1
|
&& return 1
|
||||||
|
|
||||||
[ -f /root/tpm/aes-key-safe.pub ] \
|
[ -f "${AES_STORE_FILE}.pub" ] \
|
||||||
&& echo 'ABORT existing safe file found: "/root/tpm/aes-key-safe.pub"' >&2 \
|
&& echo 'ABORT existing safe file found: "${AES_STORE_FILE}.pub"' >&2 \
|
||||||
&& return 1
|
&& return 1
|
||||||
|
|
||||||
printf -- "%s" 'Creating TPM derived safe ... ' >&2
|
printf -- "%s" 'Creating TPM derived safe ... ' >&2
|
||||||
umask 077
|
mkdir -p "$(dirname "${AES_STORE_FILE}")"
|
||||||
mkdir -p /root/tpm
|
|
||||||
[ -f /tmp/primary.ctx ] || tpm2_createprimary -C o -Q -c /tmp/primary.ctx
|
[ -f /tmp/primary.ctx ] || tpm2_createprimary -C o -Q -c /tmp/primary.ctx
|
||||||
openssl rand 32 | tpm2_create -C /tmp/primary.ctx -Q -i - -r /root/tpm/aes-key-safe.priv -u /root/tpm/aes-key-safe.pub \
|
openssl rand 32 | tpm2_create -C /tmp/primary.ctx -Q -i - -r "${AES_STORE_FILE}" -u "${AES_STORE_FILE}.pub" \
|
||||||
&& [ -f /root/tpm/aes-key-safe.priv ] \
|
&& checkSafe \
|
||||||
&& [ -f /root/tpm/aes-key-safe.pub ] \
|
|
||||||
&& printf -- "%s\n" '(done)' >&2 \
|
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
echo 'FAILURE: unable to provide a usable safe.' >&2
|
echo 'FAILURE: unable to provide a usable safe.' >&2
|
||||||
@@ -76,34 +77,37 @@ function checkOrCreateSafe() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function seal() {
|
function seal() {
|
||||||
! chmod -R go-rwx /dev/shm/host/secret/* \
|
# Ensure all secrets have restricte permissions before tar
|
||||||
|
! chmod -R go-rwx "${SECRETS_PLAIN_PATH}" \
|
||||||
&& return 1
|
&& return 1
|
||||||
|
|
||||||
[ -f /tmp/primary.ctx ] || tpm2_createprimary -C o -Q -c /tmp/primary.ctx
|
[ -f /tmp/primary.ctx ] || tpm2_createprimary -C o -Q -c /tmp/primary.ctx
|
||||||
[ -f /tmp/safe.ctx ] || tpm2_load \
|
[ -f /tmp/safe.ctx ] || tpm2_load \
|
||||||
-C /tmp/primary.ctx -Q \
|
-C /tmp/primary.ctx -Q \
|
||||||
-r /root/tpm/aes-key-safe.priv \
|
-r "${AES_STORE_FILE}" \
|
||||||
-u /root/tpm/aes-key-safe.pub \
|
-u "${AES_STORE_FILE}.pub" \
|
||||||
-c /tmp/safe.ctx
|
-c /tmp/safe.ctx
|
||||||
umask 077
|
|
||||||
openssl enc -aes-256-cbc -salt -pbkdf2 \
|
openssl enc -aes-256-cbc -salt -pbkdf2 \
|
||||||
-in <(tar -czvf - /dev/shm/host/secret/*) \
|
-in <(tar -czvf - "${SECRETS_PLAIN_PATH%/}/"*) \
|
||||||
-out /root/tpm/host_secrets.tar.gz.aes \
|
-out "${SECRETS_STORE_FILE}.tar.gz.aes" \
|
||||||
-pass file:<(tpm2_unseal -c /tmp/safe.ctx)
|
-pass file:<(tpm2_unseal -c /tmp/safe.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
function unseal() {
|
function unseal() {
|
||||||
! [ -f /root/tpm/host_secrets.tar.gz.aes ] \
|
! [ -f "${SECRETS_STORE_FILE}.tar.gz.aes" ] \
|
||||||
|
&& return 1
|
||||||
|
|
||||||
|
! mkdir -m 1700 -p "${SECRETS_PLAIN_PATH}" \
|
||||||
&& return 1
|
&& return 1
|
||||||
|
|
||||||
[ -f /tmp/primary.ctx ] || tpm2_createprimary -C o -Q -c /tmp/primary.ctx
|
[ -f /tmp/primary.ctx ] || tpm2_createprimary -C o -Q -c /tmp/primary.ctx
|
||||||
[ -f /tmp/safe.ctx ] || tpm2_load \
|
[ -f /tmp/safe.ctx ] || tpm2_load \
|
||||||
-C /tmp/primary.ctx -Q \
|
-C /tmp/primary.ctx -Q \
|
||||||
-r /root/tpm/aes-key-safe.priv \
|
-r "${AES_STORE_FILE}" \
|
||||||
-u /root/tpm/aes-key-safe.pub \
|
-u "${AES_STORE_FILE}.pub" \
|
||||||
-c /tmp/safe.ctx
|
-c /tmp/safe.ctx
|
||||||
openssl enc -d -aes-256-cbc -pbkdf2 \
|
openssl enc -d -aes-256-cbc -pbkdf2 \
|
||||||
-in /root/tpm/host_secrets.tar.gz.aes \
|
-in "${SECRETS_STORE_FILE}.tar.gz.aes" \
|
||||||
-out - \
|
-out - \
|
||||||
-pass file:<(tpm2_unseal -c /tmp/safe.ctx) | tar -xzvf - -C /
|
-pass file:<(tpm2_unseal -c /tmp/safe.ctx) | tar -xzvf - -C /
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user