From 9572e031f26e88840e6466f384f8efec2f3b0151 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 16 Jan 2024 20:41:06 +0100 Subject: [PATCH 1/6] Rename src/nuggits to nuggits.tsv --- build.sh | 2 +- lib.sh | 2 +- src/{nuggits => nuggits.tsv} | 0 test.sh | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/{nuggits => nuggits.tsv} (100%) diff --git a/build.sh b/build.sh index 2d9461d..51a0f30 100755 --- a/build.sh +++ b/build.sh @@ -60,7 +60,7 @@ ALMOST_CREDITS_HASH="$(git hash-object -w "$DOCDIR/almost_credits.txt")" FINAL_CREDITS_HASH="$(tr 'A-Za-z' 'N-ZA-Mn-za-m' < "$DOCDIR/credits.txt" | git hash-object -w --stdin)" CREDITS_TREE="$(printf "100644 blob %s almost\n100644 blob %s final\n" "$ALMOST_CREDITS_HASH" "$FINAL_CREDITS_HASH" | git mktree)" -NUMBER_OF_NUGGITS="$(wc -l <"$DOCDIR/nuggits")" +NUMBER_OF_NUGGITS="$(wc -l <"$DOCDIR/nuggits.tsv")" replace NUMBER_OF_NUGGITS CREDITS_TREE NUGGIT_DESCRIPTION_TREE "$DOCDIR/redeem-nuggit.sh" > ./.git/redeem.nuggit chmod a=rx ./.git/redeem.nuggit diff --git a/lib.sh b/lib.sh index 240ac37..c51ef20 100644 --- a/lib.sh +++ b/lib.sh @@ -122,7 +122,7 @@ store_nuggits() { fi # piped into mktree, this creates a sub-folder in general one with the name of the hashed nuggit to avoid easy discovery printf "40000 tree %s %s\n" "$description_tree_hash" "$nuggit_folder_name" - done < "$DOCDIR/nuggits"))" + done < "$DOCDIR/nuggits.tsv"))" LOCAL_CODE_EXECUTION_HASH="$(cat tmp)" rm tmp } diff --git a/src/nuggits b/src/nuggits.tsv similarity index 100% rename from src/nuggits rename to src/nuggits.tsv diff --git a/test.sh b/test.sh index 7b81cf7..ac1beff 100755 --- a/test.sh +++ b/test.sh @@ -24,7 +24,7 @@ check_redeem_without_local_code_execution() { [ "$nuggit" != LocalCodeExecution ] || continue [ "$nuggit" != WorkInProgress ] || continue # we want to do this after all the others, so we see that this is the first time that the "You almost got it" text is shown expect "git redeem-nuggit '$nuggit'" not to contain "You almost got it" - done < "$DOCDIR/nuggits" + done < "$DOCDIR/nuggits.tsv" # the second last nuggit should show the "Almost got it" text and resubmitting should show the same expect "git redeem-nuggit WorkInProgress" to contain "You almost got it! There is only a single nuggit left to redeem..." expect "git redeem-nuggit WorkInProgress" to contain "You almost got it! There is only a single nuggit left to redeem..." @@ -174,7 +174,7 @@ check_redeem() { expect "git redeem-nuggit '$nuggit'" to contain "already redeemed" expect "git redeem-nuggit '$nuggit'" not to contain Success expect "git log nuggits" to contain "$nuggit" - done < "$DOCDIR/nuggits" + done < "$DOCDIR/nuggits.tsv" } it 'All nuggits should be redeemed at the end of the test' check_redeem From 2e51170804f7bbecb21abda1061a3973e9378fa4 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 16 Jan 2024 21:34:59 +0100 Subject: [PATCH 2/6] redeem-nuggit: format maths consistantly --- build.sh | 2 +- src/redeem-nuggit.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 51a0f30..e96b552 100755 --- a/build.sh +++ b/build.sh @@ -60,7 +60,7 @@ ALMOST_CREDITS_HASH="$(git hash-object -w "$DOCDIR/almost_credits.txt")" FINAL_CREDITS_HASH="$(tr 'A-Za-z' 'N-ZA-Mn-za-m' < "$DOCDIR/credits.txt" | git hash-object -w --stdin)" CREDITS_TREE="$(printf "100644 blob %s almost\n100644 blob %s final\n" "$ALMOST_CREDITS_HASH" "$FINAL_CREDITS_HASH" | git mktree)" -NUMBER_OF_NUGGITS="$(wc -l <"$DOCDIR/nuggits.tsv")" +NUMBER_OF_NUGGITS="$(($(wc -l <"$DOCDIR/nuggits.tsv")))" replace NUMBER_OF_NUGGITS CREDITS_TREE NUGGIT_DESCRIPTION_TREE "$DOCDIR/redeem-nuggit.sh" > ./.git/redeem.nuggit chmod a=rx ./.git/redeem.nuggit diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index d21ae9f..c74f4ed 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -20,12 +20,12 @@ fi already_redeemed=0 git cat-file -e "$(already_redeemed "$nuggit" | git hash-object --stdin)" 2>/dev/null && already_redeemed=1 -redeemed_nuggits="$(git rev-list --count nuggits)" -redeemed_nuggits=$((redeemed_nuggits - already_redeemed)) +redeemed_nuggits="$(($(git rev-list --count nuggits) - already_redeemed))" -[ "$redeemed_nuggits" -ne $((NUMBER_OF_NUGGITS - 1 )) ] || git cat-file -p CREDITS_TREE:almost; +[ "$redeemed_nuggits" -ne $((NUMBER_OF_NUGGITS - 1)) ] || git cat-file -p CREDITS_TREE:almost; -[ "$redeemed_nuggits" -ne $(( NUMBER_OF_NUGGITS + 0 )) ] || { +# shellcheck disable=2170 +[ "$redeemed_nuggits" -ne NUMBER_OF_NUGGITS ] || { git cat-file -e "$(git hash-object --stdin <<< "$((NUMBER_OF_NUGGITS - 1))" | git hash-object --stdin)" 2>/dev/null || { echo Noughty boy!; exit 1; } git cat-file -p CREDITS_TREE:final | tr 'A-Za-z' 'N-ZA-Mn-za-m'; } @@ -53,6 +53,6 @@ $description" > .git/nuggits.bak } commit_nuggit "$nuggit" -echo "Number of redeemed nuggits: $redeemed_nuggits of $((NUMBER_OF_NUGGITS))" +echo "Number of redeemed nuggits: $redeemed_nuggits of NUMBER_OF_NUGGITS" already_redeemed "$nuggit" | git hash-object --stdin -w >/dev/null 2>&1 git hash-object --stdin <<< "$redeemed_nuggits"| git hash-object --stdin -w >/dev/null 2>&1 From 4f1ae53f545a2cbccdbda3f4303a164c4396ccb9 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 16 Jan 2024 21:43:07 +0100 Subject: [PATCH 3/6] redeem-nuggit: simplify already_redeemed & tried_before --- src/redeem-nuggit.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index c74f4ed..fd5dab0 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -3,10 +3,6 @@ nuggit="$1" -already_redeemed() { - echo "'$1' already redeemed" -} - if [ -z "$nuggit" ]; then echo "no nuggit passed in..." >&2 echo "Usage: \`$0 TestNuggit\`" >&2 @@ -18,9 +14,12 @@ if [ "$nuggit" = TestNuggit ]; then exit fi -already_redeemed=0 -git cat-file -e "$(already_redeemed "$nuggit" | git hash-object --stdin)" 2>/dev/null && already_redeemed=1 -redeemed_nuggits="$(($(git rev-list --count nuggits) - already_redeemed))" +already_redeemed="'$nuggit' already redeemed" +tried_before="You tried '$nuggit' before. It still isn't a valid answer... 🙄" + +redeemed=0 +git cat-file -e "$(echo "$already_redeemed" | git hash-object --stdin)" 2>/dev/null && redeemed=1 +redeemed_nuggits="$(($(git rev-list --count nuggits) - redeemed))" [ "$redeemed_nuggits" -ne $((NUMBER_OF_NUGGITS - 1)) ] || git cat-file -p CREDITS_TREE:almost; @@ -30,12 +29,12 @@ redeemed_nuggits="$(($(git rev-list --count nuggits) - already_redeemed))" git cat-file -p CREDITS_TREE:final | tr 'A-Za-z' 'N-ZA-Mn-za-m'; } -git cat-file -p "$(already_redeemed "$nuggit" | git hash-object --stdin)" 2>/dev/null && exit -git cat-file -p "$(echo "You tried '$nuggit' before. It still isn't a valid answer... 🙄" | git hash-object --stdin)" 2>/dev/null && exit 1 +git cat-file -p "$(echo "$already_redeemed" | git hash-object --stdin)" 2>/dev/null && exit +git cat-file -p "$(echo "$tried_before" | git hash-object --stdin)" 2>/dev/null && exit 1 git cat-file -p "NUGGIT_DESCRIPTION_TREE:$(echo "$nuggit" | git hash-object --stdin)/success" 2>/dev/null || { echo "Unfortunately that is not a valid nuggit :/ Try again!" >&2 - echo "You tried '$nuggit' before. It still isn't a valid answer... 🙄" | git hash-object --stdin -w >/dev/null 2>&1 + echo "$tried_before" | git hash-object --stdin -w >/dev/null 2>&1 exit 1 } @@ -54,5 +53,5 @@ $description" > .git/nuggits.bak commit_nuggit "$nuggit" echo "Number of redeemed nuggits: $redeemed_nuggits of NUMBER_OF_NUGGITS" -already_redeemed "$nuggit" | git hash-object --stdin -w >/dev/null 2>&1 +echo "$already_redeemed" | git hash-object --stdin -w >/dev/null 2>&1 git hash-object --stdin <<< "$redeemed_nuggits"| git hash-object --stdin -w >/dev/null 2>&1 From b6d8d7cf6a0b00cfe34fe7d638e3fa6859755a21 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 16 Jan 2024 22:01:45 +0100 Subject: [PATCH 4/6] redeem-nuggit: strip comments This is, so that we can document the code more without making it easier to reverse-engineer --- build.sh | 2 +- src/redeem-nuggit.sh | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index e96b552..abd9736 100755 --- a/build.sh +++ b/build.sh @@ -62,7 +62,7 @@ CREDITS_TREE="$(printf "100644 blob %s almost\n100644 blob %s final\n" "$ALMOST_ NUMBER_OF_NUGGITS="$(($(wc -l <"$DOCDIR/nuggits.tsv")))" -replace NUMBER_OF_NUGGITS CREDITS_TREE NUGGIT_DESCRIPTION_TREE "$DOCDIR/redeem-nuggit.sh" > ./.git/redeem.nuggit +replace NUMBER_OF_NUGGITS CREDITS_TREE NUGGIT_DESCRIPTION_TREE "$DOCDIR/redeem-nuggit.sh" | sed -e 's/\s*# .*$//' -e '/^[[:space:]]*$/d' > ./.git/redeem.nuggit chmod a=rx ./.git/redeem.nuggit # ------------------------------------------------------------------------------------------- # diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index fd5dab0..cdbc892 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash -# This file is not really intended for you to look into too much - but I like how curious you are, so here is a nuggit for you: CuriosityKilledTheCat +#This file is not really intended for you to look into too much - but I like +#how curious you are, so here is a nuggit for you: +#nuggit: CuriosityKilledTheCat +# +#Note for developers: comments starting with "#" and empty lines are +#stripped from the build version to make reverse engineering this just a tiny +#bit harder ;) nuggit="$1" From 3179d46b24fbdf9c90033cb9bb7d1eda94bb9004 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 16 Jan 2024 22:38:51 +0100 Subject: [PATCH 5/6] redeem-nuggit: add many comments on what we are doing This is now not a "threat for reverse-engineering" any more, since the comments are stripped when "building" --- src/redeem-nuggit.sh | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index cdbc892..bf0aedf 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -24,21 +24,40 @@ already_redeemed="'$nuggit' already redeemed" tried_before="You tried '$nuggit' before. It still isn't a valid answer... 🙄" redeemed=0 +# check if this nuggit was already_redeemed git cat-file -e "$(echo "$already_redeemed" | git hash-object --stdin)" 2>/dev/null && redeemed=1 +# The total number of nuggits is one bigger than the already committed ones +# because of the root commit, so we have to subtract 1 if this one was already +# redeemed redeemed_nuggits="$(($(git rev-list --count nuggits) - redeemed))" +# For the second last nuggit we want to show a hint that one is still missing +# to give a hint that LocalCodeExecution is self-deleting. +# CREDITS_TREE is a tree-object and CREDITS_TREE:almost means the blob with the +# name "almost" inside of it [ "$redeemed_nuggits" -ne $((NUMBER_OF_NUGGITS - 1)) ] || git cat-file -p CREDITS_TREE:almost; -# shellcheck disable=2170 +# shellcheck disable=2170 # NUMBER_OF_NUGGITS will be replaced by an integer, once we "build" it. [ "$redeemed_nuggits" -ne NUMBER_OF_NUGGITS ] || { - git cat-file -e "$(git hash-object --stdin <<< "$((NUMBER_OF_NUGGITS - 1))" | git hash-object --stdin)" 2>/dev/null || { echo Noughty boy!; exit 1; } + # check if the player did not just add a commit to our "nuggits" + # pseudobranch by looking up if we wrote the last number of redeemed + # nuggits to the objects. This is just a very basic "cheat-detection"... + git cat-file -e "$(git hash-object --stdin <<< "$((NUMBER_OF_NUGGITS - 1))" | git hash-object --stdin)" 2>/dev/null || { echo Naughty boy!; exit 1; } + # print the final credits. See "almost" above for syntax description + # Also do rot13 on the result in order to make it just a bit harder to just + # find the blob and read it git cat-file -p CREDITS_TREE:final | tr 'A-Za-z' 'N-ZA-Mn-za-m'; } +# if we already have redeemed this nuggit, print that it was already redeemed and exit git cat-file -p "$(echo "$already_redeemed" | git hash-object --stdin)" 2>/dev/null && exit +# if the user already tried to submit this wrong string, print the error and exit git cat-file -p "$(echo "$tried_before" | git hash-object --stdin)" 2>/dev/null && exit 1 +# Print the success message for this nuggit if it exists git cat-file -p "NUGGIT_DESCRIPTION_TREE:$(echo "$nuggit" | git hash-object --stdin)/success" 2>/dev/null || { + # if it does not exist, then this is not a valid nuggit (or it was + # LocalCodeExecution and that was deleted) echo "Unfortunately that is not a valid nuggit :/ Try again!" >&2 echo "$tried_before" | git hash-object --stdin -w >/dev/null 2>&1 exit 1 @@ -48,16 +67,20 @@ commit_nuggit() { # Manage our own little "branch" manually local tree # get the tree object from the last commit in nuggits tree="$(git rev-parse "nuggits^{tree}")" + # get the description from our "nuggit tree object" from the folder with + # the hash of the nuggit and inside of that the description file description="$(git cat-file -p "NUGGIT_DESCRIPTION_TREE:$(echo "$1" | git hash-object --stdin)/description")" # add an empty commit with the parent being nuggits and "reset nuggits to that new commit" - git commit-tree "$tree" -p "$(cat .git/nuggits)" -m "$1 - -$description" > .git/nuggits.bak + git commit-tree "$tree" -p "$(cat .git/nuggits)" -m "$(printf "%s\n\n" "$nuggit" "$description")" > .git/nuggits.bak # We can't directly pipe it into the file, because it will empty it before we read it... + # Therefore write it into a backup file and then replace it mv .git/nuggits.bak .git/nuggits } commit_nuggit "$nuggit" +# Print some stats for the player, so they know if they still need to look for other nuggits echo "Number of redeemed nuggits: $redeemed_nuggits of NUMBER_OF_NUGGITS" +# Write to our database, that this nuggit is now redeemed echo "$already_redeemed" | git hash-object --stdin -w >/dev/null 2>&1 +# Write as a "cheat-detection" for the final credits how many we have redeemed git hash-object --stdin <<< "$redeemed_nuggits"| git hash-object --stdin -w >/dev/null 2>&1 From e6405461122d9ab2454b8397d1a1076a4fcf9a6a Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 16 Jan 2024 22:45:22 +0100 Subject: [PATCH 6/6] redeem-nuggit: inline commit_nuggit function This is done to make reverse engineering a bit harder --- src/redeem-nuggit.sh | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index bf0aedf..ccc1727 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -63,20 +63,18 @@ git cat-file -p "NUGGIT_DESCRIPTION_TREE:$(echo "$nuggit" | git hash-object --st exit 1 } -commit_nuggit() { # Manage our own little "branch" manually - local tree - # get the tree object from the last commit in nuggits - tree="$(git rev-parse "nuggits^{tree}")" - # get the description from our "nuggit tree object" from the folder with - # the hash of the nuggit and inside of that the description file - description="$(git cat-file -p "NUGGIT_DESCRIPTION_TREE:$(echo "$1" | git hash-object --stdin)/description")" - # add an empty commit with the parent being nuggits and "reset nuggits to that new commit" - git commit-tree "$tree" -p "$(cat .git/nuggits)" -m "$(printf "%s\n\n" "$nuggit" "$description")" > .git/nuggits.bak - # We can't directly pipe it into the file, because it will empty it before we read it... - # Therefore write it into a backup file and then replace it - mv .git/nuggits.bak .git/nuggits -} -commit_nuggit "$nuggit" +# Manage our own little "branch" manually + +# get the tree object from the last commit in nuggits +tree="$(git rev-parse "nuggits^{tree}")" +# get the description from our "nuggit tree object" from the folder with +# the hash of the nuggit and inside of that the description file +description="$(git cat-file -p "NUGGIT_DESCRIPTION_TREE:$(echo "$nuggit" | git hash-object --stdin)/description")" +# add an empty commit with the parent being nuggits and "reset nuggits to that new commit" +git commit-tree "$tree" -p "$(cat .git/nuggits)" -m "$(printf "%s\n\n" "$nuggit" "$description")" > .git/nuggits.bak +# We can't directly pipe it into the file, because it will empty it before we read it... +# Therefore write it into a backup file and then replace it +mv .git/nuggits.bak .git/nuggits # update our "branch" # Print some stats for the player, so they know if they still need to look for other nuggits echo "Number of redeemed nuggits: $redeemed_nuggits of NUMBER_OF_NUGGITS"