30 lines
978 B
Bash
Executable File
30 lines
978 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
private_key="${MADD_PRIV_KEY:-"/etc/ssh/ssh_host_ed25519_key"}"
|
|
public_key="${MADD_PUB_KEY:-"$private_key.pub"}"
|
|
|
|
hostname="${MADD_HOSTNAME:-"$(hostname -s)"}"
|
|
requested_ip=$MADD_IP # TODO: Obtain IP automatically
|
|
|
|
endpoint=$MADD_ENDPOINT
|
|
|
|
echo "(MADD) Updating DNS..."
|
|
echo
|
|
echo " Endpoint: $endpoint"
|
|
echo "Priv. key: $private_key"
|
|
echo " Pub. key: $public_key"
|
|
echo " Hostname: $hostname"
|
|
echo " IP: $requested_ip"
|
|
echo
|
|
|
|
# Generate the request and receive the identifier to sign
|
|
identifier=$(curl "$endpoint/request/$hostname/$requested_ip" --fail-with-body --data-binary @$public_key 2>/dev/null)
|
|
|
|
# Sign the request using the SSH key
|
|
signed=$(echo -n "$identifier $hostname $requested_ip" | ssh-keygen -Y sign -f $private_key -n madd 2>/dev/null)
|
|
|
|
# Escape slashes in the identifier
|
|
identifier_escaped=$(sed "s|/|%2F|g" <<< "$identifier")
|
|
|
|
# Submit the signed request
|
|
curl "$endpoint/signed/$identifier_escaped" --fail-with-body --data "$signed" |