Cosmetic improvements

This commit is contained in:
Taras Kushnir
2025-09-03 15:42:39 +03:00
parent 668c9b0f86
commit 6c887eac45
3 changed files with 49 additions and 6 deletions
+6
View File
@@ -3,3 +3,9 @@ Usage:
```bash
curl -s -H "Origin: portal.privatecaptcha.com" https://api.privatecaptcha.com/puzzle?sitekey=abcdef | go run cmd/puzzledbg/main.go
```
For stub puzzle:
```bash
curl -s https://api.privatecaptcha.com/puzzle?sitekey=aaaaaaaabbbbccccddddeeeeeeeeeeee | go run cmd/puzzledbg/main.go -solve
```
+42 -6
View File
@@ -3,15 +3,26 @@ package main
import (
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"io"
"os"
"strings"
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/common"
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/puzzle"
"github.com/jackc/pgx/v5/pgtype"
)
var (
solveFlag = flag.Bool("solve", false, "Solve puzzle instead of printing")
)
func main() {
flag.Parse()
common.SetupTraceLogs()
data, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading stdin: %v\n", err)
@@ -33,11 +44,36 @@ func main() {
os.Exit(3)
}
out, err := json.MarshalIndent(p, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "Error marshalling puzzle: %v\n", err)
os.Exit(4)
}
if *solveFlag {
solver := &puzzle.ComputeSolver{}
solutions, err := solver.Solve(p)
if err != nil {
fmt.Fprintf(os.Stderr, "Error solving puzzle: %v\n", err)
os.Exit(5)
}
fmt.Print(string(out))
fmt.Printf("%s.%s", solutions.String(), responseStr)
} else {
m := make(map[string]interface{})
propertyID := p.PropertyID()
var propertyUUID pgtype.UUID
propertyUUID.Valid = true
copy(propertyUUID.Bytes[:], propertyID[:])
m["PuzzleID"] = p.PuzzleID()
m["PropertyID"] = propertyUUID.String()
m["Difficulty"] = p.Difficulty()
m["SolutionsCount"] = p.SolutionsCount()
m["Expiration"] = p.Expiration()
m["IsStub"] = p.IsStub()
m["IsZero"] = p.IsZero()
out, err := json.MarshalIndent(m, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "Error marshalling puzzle: %v\n", err)
os.Exit(4)
}
fmt.Print(string(out))
}
}
+1
View File
@@ -320,6 +320,7 @@ func (s *Server) pcVerifyHandler(w http.ResponseWriter, r *http.Request) {
payload, err := s.Verifier.ParseSolutionPayload(ctx, data)
if err != nil {
slog.Log(ctx, common.LevelTrace, "Failed to parse solution payload", common.ErrAttr(err))
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}