Skip to content

Instantly share code, notes, and snippets.

@XavierChanth
Last active November 27, 2024 15:42
Show Gist options
  • Save XavierChanth/24f9ad95b73d1b53a8e7879b65cf6594 to your computer and use it in GitHub Desktop.
Save XavierChanth/24f9ad95b73d1b53a8e7879b65cf6594 to your computer and use it in GitHub Desktop.
atserver quick authentication script
#!/usr/bin/env bash
if ! command -v openssl >/dev/null 2>&1; then
echo "openssl is required for atsign commands"
return
fi
head -n 1 < <(openssl s_client -connect root.atsign.org:64 -quiet -verify_quiet < <(
echo "$1"
sleep 1
echo "@exit"
) 2>/dev/null)
#!/usr/bin/env bash
script_dir="$(dirname -- "$(readlink -f -- "$0")")"
if ! command -v openssl >/dev/null 2>&1; then
echo "openssl is required for atsign commands"
return
fi
atsign="$1"
if [[ ${atsign:0:1} != "@" ]]; then
atsign="@$atsign"
fi
fqdn=$($script_dir/atdirectory "${atsign:1}" | tr -d '\r\n\t ')
atkeys="$HOME/.atsign/keys/${atsign}_key.atKeys"
coproc { openssl s_client -brief -connect "${fqdn:1}"; }
echo "from:$atsign" >&${COPROC[1]}
echo "from:$atsign"
read -r line <&${COPROC[0]}
echo $line
challenge=$line
pkamres="pkam:$(at_pkam -p $atkeys -r ${challenge:6})"
echo $pkamres >&${COPROC[1]}
echo "@$pkamres"
# Connect stdout/stdin to terminal foreground
exec {OUT}<&${COPROC[0]}-
exec {IN}>&${COPROC[1]}-
cat <&0 >&${IN} &
cat <&${OUT} >&1 &
wait $COPROC_PID

AtServer quick authentication scripts

Requirements:

Scripts

atdirectory

Takes an atSign and returns the fqdn/port of that atSign

atserver

Takes an atSign, performs pkam authentication, then releases stdin/stdout to the foreground.

Notes:

  • You will get warnings about cat when exiting the script, this is fine, don't worry.
  • Bash needs support for bash coproc (bash version 4)
  • at_pkam is expected to be on the path by default
  • atdirectory is expected to be in the same directory as atserver
  • atkeys for the atSign are expected to be located at ~/.atsign/keys/<atSign>_key.atKeys
  • You can modify the script if you don't want to change the paths for any of the above
    • Each item only appears once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment