Skip to content

Commit

Permalink
Merge pull request #3 from redpwn/go1.17
Browse files Browse the repository at this point in the history
chore: upgrade to go1.17
  • Loading branch information
ginkoid authored Aug 29, 2021
2 parents bf2007f + 9dec43b commit 7a27171
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
38 changes: 18 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16.5
- run: |
go-version: 1.17.0
- uses: actions/checkout@v2
- name: go build
run: |
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf
sudo dpkg --add-architecture arm64
sudo dpkg --add-architecture armhf
Expand All @@ -21,9 +23,6 @@ jobs:
' | sudo tee /etc/apt/sources.list.d/arm.list
sudo apt-get update || true
sudo apt-get install libgmp-dev:arm64 libgmp-dev:armhf
- uses: actions/checkout@v2
- name: go build
run: |
go build -v -ldflags '-w -s -extldflags -static' -o redpwnpow-linux-amd64 ./cmd/redpwnpow
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOARCH=arm64 go build -v -ldflags '-w -s -extldflags -static' -o redpwnpow-linux-arm64 ./cmd/redpwnpow
CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOARCH=arm go build -v -ldflags '-w -s -extldflags -static' -o redpwnpow-linux-armv6l ./cmd/redpwnpow
Expand All @@ -32,11 +31,11 @@ jobs:
name: linux
path: redpwnpow-linux-*
darwin:
runs-on: macos-10.15
runs-on: macos-11
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16.5
go-version: 1.17.0
- uses: actions/checkout@v2
- name: go build
run: |
Expand All @@ -45,28 +44,29 @@ jobs:
go build -v -ldflags "-w -s -extldflags -L$lib_tmp" -o redpwnpow-darwin-amd64 ./cmd/redpwnpow
oci_tmp=$(mktemp -d)
ghcr_token=$(curl -f 'https://ghcr.io/token?scope=repository:homebrew/core/gmp:pull' | jq -r .token)
curl -fLH "authorization: Bearer $ghcr_token" https://ghcr.io/v2/homebrew/core/gmp/blobs/sha256:ff4ad8d068ba4c14d146abb454991b6c4f246796ec2538593dc5f04ca7593eec | tar xzC "$oci_tmp" --strip-components=2
curl -fLH "authorization: Bearer $ghcr_token" https://ghcr.io/v2/homebrew/core/gmp/blobs/sha256:ff4ad8d068ba4c14d146abb454991b6c4f246796ec2538593dc5f04ca7593eec | tar xzC "$oci_tmp" --strip-components 2
lib_tmp=$(mktemp -d)
cp "$oci_tmp/lib/libgmp.a" "$lib_tmp"
export SDK_NAME=macosx
export SDK_PATH=$(xcrun --show-sdk-path --sdk $SDK_NAME)
export CC="$(xcrun -sdk $SDK_PATH --find clang) -arch arm64 -isysroot $SDK_PATH"
export CFLAGS="-isysroot $SDK_PATH -arch arm64 -I$SDK_PATH/usr/include"
export LD_LIBRARY_PATH="$SDK_PATH/usr/lib"
export CGO_LDFLAGS="-isysroot $SDK_PATH -arch arm64 -L$lib_tmp"
export CGO_CFLAGS="-isysroot $SDK_PATH -arch arm64 -I/usr/local/include"
CGO_ENABLED=1 GOARCH=arm64 go build -v -ldflags '-w -s' -o redpwnpow-darwin-arm64 ./cmd/redpwnpow
sdk_path="$(xcrun --show-sdk-path --sdk macosx)"
CGO_ENABLED=1 GOARCH=arm64 CC="$(xcrun -sdk $sdk_path --find clang) -arch arm64 -isysroot $sdk_path" \
CFLAGS="-isysroot $sdk_path -arch arm64 -I$sdk_path/usr/include" LD_LIBRARY_PATH="$sdk_path/usr/lib" \
CGO_LDFLAGS="-isysroot $sdk_path -arch arm64 -L$lib_tmp" CGO_CFLAGS="-isysroot $sdk_path -arch arm64 -I/usr/local/include" \
go build -v -ldflags '-w -s' -o redpwnpow-darwin-arm64 ./cmd/redpwnpow
lipo -create -output redpwnpow-darwin redpwnpow-darwin-amd64 redpwnpow-darwin-arm64
- uses: actions/upload-artifact@v2
with:
name: darwin
path: redpwnpow-darwin
windows:
runs-on: windows-2019
runs-on: windows-2022
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17.0
- uses: msys2/setup-msys2@v2
with:
install: mingw-w64-x86_64-go mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp
path-type: inherit
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp
- uses: actions/checkout@v2
- name: go build
shell: msys2 {0}
Expand All @@ -90,8 +90,6 @@ jobs:
- uses: softprops/action-gh-release@v1
with:
files: build/*/redpwnpow-*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: cloudflare
run: >
curl -sSXPUT https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT }}/workers/scripts/pow
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ redpwnpow challenge
## kCTF

redpwnpow can be used as a drop-in replacement for [kCTF](https://google.github.io/kctf/)'s proof of work solver.
redpwnpow is approximately **10x faster** than kCTF's [Python solver](https://github.com/google/kctf/blob/v1.0/docker-images/challenge/pow.py).

## Go module

Expand All @@ -43,10 +42,10 @@ func main() {
c := pow.GenerateChallenge(5000)
fmt.Printf("proof of work: curl -sSfL https://pwn.red/pow | sh -s %s\nsolution: ", c)
s, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if correct, err := c.Check(s); err == nil && correct {
fmt.Println("correct")
if good, err := c.Check(s); err == nil && good {
fmt.Println("good")
} else {
fmt.Println("incorrect")
fmt.Println("bad")
}
}
```
2 changes: 1 addition & 1 deletion cmd/redpwnpow/redpwnpow.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func run() error {

func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
11 changes: 7 additions & 4 deletions cmd/redpwnpow/run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
# redpwnpow proof of work runner
# https://github.com/redpwn/pow/blob/master/cmd/redpwnpow/run.sh
# https://github.com/redpwn/pow

set -e
set -eu
version=VERSION
run() {
case $(uname | tr '[:upper:]' '[:lower:]') in
Expand All @@ -17,10 +17,13 @@ run() {
msys*|mingw*|cygwin*) release=windows-amd64.exe;;
*) echo unknown operating system >&2; exit 1
esac
cache_root=$HOME/.cache/redpwnpow
cache_root=${XDG_CACHE_HOME:-$HOME/.cache}/redpwnpow
mkdir -p "$cache_root"
cache_path=$cache_root/redpwnpow-$version-$release
[ -e "$cache_path" ] || curl -sSfLo "$cache_path" "https://github.com/redpwn/pow/releases/download/$version/redpwnpow-$release" && chmod u+x "$cache_path"
if [ ! -e "$cache_path" ]; then
curl -sSfLo "$cache_path" "https://github.com/redpwn/pow/releases/download/$version/redpwnpow-$release"
chmod u+x "$cache_path"
fi
"$cache_path" "$@"
}
run "$@"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/redpwn/pow

go 1.16
go 1.17

require github.com/ncw/gmp v1.0.4

0 comments on commit 7a27171

Please sign in to comment.