Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIT: provisioning fetching scripts use either tsh or ssh #286

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions scripts/fetch-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

set -o errexit # abort on nonzero exit status
set -o errtrace # pass ERR trap down to functions, substitutions, etc
set -o nounset # abort on unbound variable
set -o pipefail # don’t hide errors within pipes

# Function to display usage information
usage() {
echo "Usage: $0 [OPTIONS] <teleport-tunnel|ipv4> <destination-folder>

Arguments:
<teleport-tunnel|ipv4> Specify the teleport tunnel or IPv4 address
<destination-folder> Specify the destination folder for fetching

Options:
-s, --short Skip the attestation certificate
-p, --passphrase Expected to be used with IPv4 address

Description:
Copy the certificates from the device to the host machine.
Notes:
For development images, both the teleport tunnel and IPv4 address can be used.
For production images, the ssh client is disabled, only teleport can by used."
}

main() {
local arg
local remote
local short=false
local passphrase=""
local scp_prefix="tsh"
local positional_args=()
while [[ $# -gt 0 ]]; do
arg="${1}"; shift
case ${arg} in
-h | --help)
usage; exit 0 ;;
-s | --short)
short=true ;;
-p | --passphrase)
passphrase=${1}; shift ;;
-*)
echo "invalid argument: ${arg}"
usage; exit 1 ;;
*)
positional_args+=( "${arg}" ) ;;
esac
done
set -- "${positional_args[@]}"

if [[ "$#" -ne 2 ]]; then
echo "Error: Arguments are missing"
usage; exit 1
fi

remote="${1}"
if [[ "${remote}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ -z "${passphrase}" ]]; then
echo "Error: Passphrase is missing"
usage; exit 1
fi
scp_prefix="sshpass -p "${passphrase}""
fi

local destination_folder="${2}"
mkdir -p "${destination_folder}"

local -a certificates=(
"70000001.extra.raw"
"70000001.signature.raw"
"70000001.pubkey.raw"
"70000002.extra.raw"
"70000002.signature.raw"
"70000002.pubkey.raw"
"7fff0206.chip_id.raw"
"7fff0206.extra.raw"
"7fff0206.signature.raw"
"sss_70000001_0002_0040.bin"
"sss_70000002_0002_0040.bin"
"sss_F0000012_0002_0040.bin"
"sss_fat.bin"
)
local -r attestation_cert="f0000013.cert"
if [[ "${short}" == false ]]; then
certificates+=( "${attestation_cert}" )
fi

local file
for file in "${certificates[@]}"; do
if [[ "$short" == true && "$file" == "f0000013.cert" ]]; then
continue
fi
echo "Copying ${file} from ${remote}..."
if ! ${scp_prefix} scp "worldcoin@${remote}:/usr/persistent/se/keystore/${file}" "${destination_folder}/"; then
echo "Error: Failed to copy ${file}"
fi
done
}

# Ensure that main only runs when called as a script
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
60 changes: 0 additions & 60 deletions scripts/tsh-certs.sh

This file was deleted.

Loading