Skip to content

Commit

Permalink
balena-unique-key: avoid all digits short UUIDs
Browse files Browse the repository at this point in the history
All digit short UUIDs are not resolved and instead treated as IP
addresses. Iterate the UUID generation to avoid them starting with 7
digits.

Change-type: patch
Signed-off-by: Alex Gonzalez <[email protected]>
  • Loading branch information
alexgg committed Jan 29, 2024
1 parent 10c68e5 commit 2027d99
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ if ! key=$("${CAT}" "${CONFIG_PATH}" | jq -r ".$key_name //empty"); then
fi

if [ -z "$key" ]; then
key=$(openssl rand -hex 16)
cnt=100
while echo "$key" | grep -q -E '^[0-9]{7}'; do
key=$(openssl rand -hex 16)
cnt=$((cnt -1))
if [ ! $cnt ]; then
echo "[ERROR] balena-unique-key : Failed to generate the random key."
exit 1
fi
done
echo "[INFO] balena-unique-key: $key_name missing from config file. Generating..."
if ! key=$(openssl rand -hex 16); then
echo "[ERROR] balena-unique-key : Failed to generate the random key."
exit 1
fi
"${CAT}" "$CONFIG_PATH" | jq ".$key_name=\"$key\"" | "${WR}" "$CONFIG_PATH"
else
echo "[INFO] balena-unique-key : Device already has $key_name assigned."
Expand Down

0 comments on commit 2027d99

Please sign in to comment.