diff --git a/sources/identity/go.mod b/sources/identity/go.mod index bbbb7444..bdf758e0 100644 --- a/sources/identity/go.mod +++ b/sources/identity/go.mod @@ -32,7 +32,7 @@ require ( gopkg.in/go-jose/go-jose.v2 v2.6.3 ) -replace github.com/charmbracelet/charm => github.com/developing-today-forks/charm v0.12.7-0.20240312075138-411f9ff4f8ac +replace github.com/charmbracelet/charm => github.com/developing-today-forks/charm v0.12.7-0.20240312114852-48e1a5469398 require ( github.com/FZambia/eagle v0.1.0 // indirect diff --git a/sources/identity/go.sum b/sources/identity/go.sum index 99bb5d44..a15ab0ac 100644 --- a/sources/identity/go.sum +++ b/sources/identity/go.sum @@ -100,8 +100,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/developing-today-forks/charm v0.12.7-0.20240312075138-411f9ff4f8ac h1:tPq59hN7UOMb0D4LKjS2ZG+OYFUvzKf/A4pxCDarZYQ= -github.com/developing-today-forks/charm v0.12.7-0.20240312075138-411f9ff4f8ac/go.mod h1:6xzxrach+U21VLDQYKlWRMq+Basc95gD4AQ8v7LLEhE= +github.com/developing-today-forks/charm v0.12.7-0.20240312114852-48e1a5469398 h1:BEOlq80FE03qDV8V077hA18KIwnGPNZe7SGkq1xfwEE= +github.com/developing-today-forks/charm v0.12.7-0.20240312114852-48e1a5469398/go.mod h1:6xzxrach+U21VLDQYKlWRMq+Basc95gD4AQ8v7LLEhE= github.com/dgraph-io/badger/v3 v3.2103.5 h1:ylPa6qzbjYRQMU6jokoj4wzcaweHylt//CH0AKt0akg= github.com/dgraph-io/badger/v3 v3.2103.5/go.mod h1:4MPiseMeDQ3FNCYwRbbcBOGJLf5jsE0PPFzRiKjtcdw= github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= diff --git a/sources/identity/init.template.sh b/sources/identity/init.template.sh index e8b89291..a8fbd026 100644 --- a/sources/identity/init.template.sh +++ b/sources/identity/init.template.sh @@ -43,7 +43,7 @@ mkdir -p /etc/apt/keyrings curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_21.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list apt update -apt install -y curl nodejs npm ucspi-tcp unzip +apt install -y curl nodejs npm ucspi-tcp unzip xxd npm install -g npm@latest npm --version node --version @@ -55,16 +55,16 @@ else dpkg -i powershell_7.4.1-1.deb_amd64.deb apt install -f fi -cd ~$USER +cd ~ if [ ! -d "code" ]; then git clone https://github.com/developing-today/code else echo "code directory already exists" fi cd code/src/identity -chmod +x *.ps1 +chmod +x *.ps1 *.sh ./build-libsql.ps1 -"CHARM_LINK_URL=$CHARM_LINK_URL" ./provider.sh & +CHARM_LINK_URL="$CHARM_LINK_URL" ./provider.sh & get_http_status() { local url=$1 curl -o /dev/null -s -w "%{http_code}\n" "$url" @@ -85,7 +85,7 @@ while : ; do echo "Checking URL: $CHARM_LINK_URL - HTTP status: $http_status" if [ "$http_status" -eq 405 ]; then - echo "Received 405 code, exiting." + echo "Verified charm link url is working, breaking loop." break fi @@ -98,6 +98,13 @@ fi response=$(curl -sL "$CHARM_LINK_URL" --data-urlencode "keys=$(./identity charm keys --simple | tr '\n' ',' | sed 's/,$//')") if [ -n "$response" ]; then + extracted_value=$(echo "$response" | sed -n 's/.*HTTP\/1\.1 200 \(.*\)\r.*/\1/p') + + if [ -n "$extracted_value" ]; then + echo "Unexpected response: $extracted_value" + exit 1 + fi + CHARM_LINK=$response else echo "Failed to obtain charm link" diff --git a/sources/identity/provider/pages/link.sh b/sources/identity/provider/pages/link.sh index 74cb86fc..ac78faa9 100644 --- a/sources/identity/provider/pages/link.sh +++ b/sources/identity/provider/pages/link.sh @@ -2,7 +2,7 @@ if [[ "$REQUEST_METHOD" != "POST" ]]; then return $(status_code 405) fi random() { - echo $(dd if=/dev/urandom bs=1 count=64 2>/dev/null | xxd -p) + dd if=/dev/urandom bs=1 count="${1:-32}" 2>/dev/null | xxd -p | tr -d '[:space:]' } for key in "${!FORM_DATA[@]}"; do if [[ "$key" == "keys" ]]; then @@ -10,26 +10,28 @@ for key in "${!FORM_DATA[@]}"; do mkdir -p "$CHARM_DIR" LINK_CODE_PATH=$CHARM_DIR/.link rm -rf "$LINK_CODE_PATH" - ./identity charm link -d -o "$LINK_CODE_PATH" -keys "${FORM_DATA[$key]}" & - max_wait=60 # seconds - wait_interval=1 # seconds - elapsed_time=0 +mkdir -p "$(dirname "$LINK_CODE_PATH")" - while [[ ! -f "$LINK_CODE_PATH" && $elapsed_time -lt $max_wait ]]; do - sleep $wait_interval - ((elapsed_time+=wait_interval)) - done +~/code/src/identity/identity charm link -d -o "$LINK_CODE_PATH" -k "${FORM_DATA[$key]}" > /dev/null 2>&1 +max_wait=60 # seconds +wait_interval=1 # seconds +elapsed_time=0 - if [[ -f "$LINK_CODE_PATH" ]]; then - LINK_CODE=$(cat "$LINK_CODE_PATH") - if [[ -z "$LINK_CODE" ]]; then - respond 405 "Failure." - else - respond 200 "$LINK_CODE" - fi - else - respond 405 "Failure." - fi +while [[ ! -f "$LINK_CODE_PATH" && $elapsed_time -lt $max_wait ]]; do + sleep $wait_interval + ((elapsed_time+=wait_interval)) +done + +if [[ -f "$LINK_CODE_PATH" ]]; then + LINK_CODE=$(cat "$LINK_CODE_PATH") + if [[ -z "$LINK_CODE" ]]; then + respond 405 "Failure." + else + respond 200 "$LINK_CODE" + fi +else + respond 405 "Failure." +fi fi done