Closer file structure to desired
This commit is contained in:
@@ -11,5 +11,5 @@ do_compress () {
|
|||||||
#find "$1" \( -type f -name "*.wasm" -o -name "*.css" -o -name "*.js" -o -name "*.mjs" \) -exec zstd -v -f -19 -o {}.zst {} \;
|
#find "$1" \( -type f -name "*.wasm" -o -name "*.css" -o -name "*.js" -o -name "*.mjs" \) -exec zstd -v -f -19 -o {}.zst {} \;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_compress challenge/
|
do_compress embed/challenge/
|
||||||
do_compress assets/
|
do_compress embed/assets/
|
@@ -6,4 +6,4 @@ set -o pipefail
|
|||||||
cd "$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
cd "$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
|
|
||||||
|
|
||||||
go run ./poison -path ./poison/
|
go run ./generate-poison -path ./poison/
|
Binary file not shown.
@@ -61,6 +61,8 @@ func main() {
|
|||||||
challengeTemplate := flag.String("challenge-template", "anubis", "name or path of the challenge template to use (anubis, forgejo)")
|
challengeTemplate := flag.String("challenge-template", "anubis", "name or path of the challenge template to use (anubis, forgejo)")
|
||||||
challengeTemplateTheme := flag.String("challenge-template-theme", "", "name of the challenge template theme to use (forgejo => [forgejo-dark, forgejo-light, gitea...])")
|
challengeTemplateTheme := flag.String("challenge-template-theme", "", "name of the challenge template theme to use (forgejo => [forgejo-dark, forgejo-light, gitea...])")
|
||||||
|
|
||||||
|
packageName := flag.String("package-path", "git.gammaspectra.live/git/go-away/cmd/go-away", "package name to expose in .well-known url path")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -93,7 +95,7 @@ func main() {
|
|||||||
|
|
||||||
state, err := lib.NewState(p, lib.StateSettings{
|
state, err := lib.NewState(p, lib.StateSettings{
|
||||||
Debug: *debug,
|
Debug: *debug,
|
||||||
PackagePath: "git.gammaspectra.live/git/go-away/cmd",
|
PackageName: *packageName,
|
||||||
ChallengeTemplate: *challengeTemplate,
|
ChallengeTemplate: *challengeTemplate,
|
||||||
ChallengeTemplateTheme: *challengeTemplateTheme,
|
ChallengeTemplateTheme: *challengeTemplateTheme,
|
||||||
})
|
})
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
@@ -4,8 +4,8 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"git.gammaspectra.live/git/go-away/challenge"
|
"git.gammaspectra.live/git/go-away/lib/challenge"
|
||||||
"git.gammaspectra.live/git/go-away/challenge/inline"
|
"git.gammaspectra.live/git/go-away/lib/challenge/inline"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
BIN
embed/challenge/js-pow-sha256/runtime/runtime.wasm
Normal file
BIN
embed/challenge/js-pow-sha256/runtime/runtime.wasm
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
package go_away
|
package embed
|
||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|
@@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
<link rel="stylesheet" href="{{ .Path }}/assets/static/anubis/style.css?cacheBust={{ .Random }}"/>
|
<link rel="stylesheet" href="{{ .Path }}/embed/assets/static/anubis/style.css?cacheBust={{ .Random }}"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
{{ range $key, $value := .Meta }}
|
{{ range $key, $value := .Meta }}
|
||||||
{{ if eq $key "refresh"}}
|
{{ if eq $key "refresh"}}
|
||||||
@@ -151,7 +151,7 @@
|
|||||||
<img
|
<img
|
||||||
id="image"
|
id="image"
|
||||||
style="width:100%;max-width:256px;"
|
style="width:100%;max-width:256px;"
|
||||||
src="{{ .Path }}/assets/static/logo.png?cacheBust={{ .Random }}"
|
src="{{ .Path }}/embed/assets/static/logo.png?cacheBust={{ .Random }}"
|
||||||
/>
|
/>
|
||||||
{{if .Challenge }}
|
{{if .Challenge }}
|
||||||
<p id="status">Loading challenge <em>{{ .Challenge }}</em>...</p>
|
<p id="status">Loading challenge <em>{{ .Challenge }}</em>...</p>
|
@@ -2,7 +2,7 @@ package challenge
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.gammaspectra.live/git/go-away/challenge/inline"
|
"git.gammaspectra.live/git/go-away/lib/challenge/inline"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MakeChallenge func(in Allocation) (out Allocation)
|
type MakeChallenge func(in Allocation) (out Allocation)
|
@@ -9,7 +9,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
go_away "git.gammaspectra.live/git/go-away"
|
"git.gammaspectra.live/git/go-away/embed"
|
||||||
"git.gammaspectra.live/git/go-away/lib/network"
|
"git.gammaspectra.live/git/go-away/lib/network"
|
||||||
"git.gammaspectra.live/git/go-away/lib/policy"
|
"git.gammaspectra.live/git/go-away/lib/policy"
|
||||||
"github.com/google/cel-go/common/types"
|
"github.com/google/cel-go/common/types"
|
||||||
@@ -43,7 +43,7 @@ func init() {
|
|||||||
|
|
||||||
templates = make(map[string]*template.Template)
|
templates = make(map[string]*template.Template)
|
||||||
|
|
||||||
dir, err := go_away.TemplatesFs.ReadDir("templates")
|
dir, err := embed.TemplatesFs.ReadDir("templates")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ func init() {
|
|||||||
if e.IsDir() {
|
if e.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data, err := go_away.TemplatesFs.ReadFile(filepath.Join("templates", e.Name()))
|
data, err := embed.TemplatesFs.ReadFile(filepath.Join("templates", e.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -373,7 +373,7 @@ func (state *State) setupRoutes() error {
|
|||||||
|
|
||||||
state.Mux.HandleFunc("/", state.handleRequest)
|
state.Mux.HandleFunc("/", state.handleRequest)
|
||||||
|
|
||||||
state.Mux.Handle("GET "+state.UrlPath+"/assets/", http.StripPrefix(state.UrlPath, gzipped.FileServer(gzipped.FS(go_away.AssetsFs))))
|
state.Mux.Handle("GET "+state.UrlPath+"/assets/", http.StripPrefix(state.UrlPath, gzipped.FileServer(gzipped.FS(embed.AssetsFs))))
|
||||||
|
|
||||||
for challengeName, c := range state.Challenges {
|
for challengeName, c := range state.Challenges {
|
||||||
if c.Static != nil {
|
if c.Static != nil {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
go_away "git.gammaspectra.live/git/go-away"
|
"git.gammaspectra.live/git/go-away/embed"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -17,7 +17,7 @@ func (state *State) getPoison(mime string, encodings []string) (r io.ReadCloser,
|
|||||||
}
|
}
|
||||||
|
|
||||||
p := path.Join("poison", strings.ReplaceAll(mime, "/", "_")+"."+encoding+".poison")
|
p := path.Join("poison", strings.ReplaceAll(mime, "/", "_")+"."+encoding+".poison")
|
||||||
f, err := go_away.PoisonFs.Open(p)
|
f, err := embed.PoisonFs.Open(p)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return f, encoding
|
return f, encoding
|
||||||
}
|
}
|
||||||
|
26
lib/state.go
26
lib/state.go
@@ -11,9 +11,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
go_away "git.gammaspectra.live/git/go-away"
|
"git.gammaspectra.live/git/go-away/embed"
|
||||||
"git.gammaspectra.live/git/go-away/challenge"
|
challenge2 "git.gammaspectra.live/git/go-away/lib/challenge"
|
||||||
"git.gammaspectra.live/git/go-away/challenge/inline"
|
"git.gammaspectra.live/git/go-away/lib/challenge/inline"
|
||||||
"git.gammaspectra.live/git/go-away/lib/condition"
|
"git.gammaspectra.live/git/go-away/lib/condition"
|
||||||
"git.gammaspectra.live/git/go-away/lib/policy"
|
"git.gammaspectra.live/git/go-away/lib/policy"
|
||||||
"github.com/google/cel-go/cel"
|
"github.com/google/cel-go/cel"
|
||||||
@@ -101,7 +101,7 @@ type ChallengeState struct {
|
|||||||
|
|
||||||
type StateSettings struct {
|
type StateSettings struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
PackagePath string
|
PackageName string
|
||||||
ChallengeTemplate string
|
ChallengeTemplate string
|
||||||
ChallengeTemplateTheme string
|
ChallengeTemplateTheme string
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func NewState(p policy.Policy, settings StateSettings) (state *State, err error)
|
|||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
state.UrlPath = "/.well-known/." + state.Settings.PackagePath
|
state.UrlPath = "/.well-known/." + state.Settings.PackageName
|
||||||
|
|
||||||
state.Backends = make(map[string]http.Handler)
|
state.Backends = make(map[string]http.Handler)
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ func NewState(p policy.Policy, settings StateSettings) (state *State, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
assetPath := c.Path + "/static/"
|
assetPath := c.Path + "/static/"
|
||||||
subFs, err := fs.Sub(go_away.ChallengeFs, fmt.Sprintf("challenge/%s/static", challengeName))
|
subFs, err := fs.Sub(embed.ChallengeFs, fmt.Sprintf("challenge/%s/static", challengeName))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Static = http.StripPrefix(
|
c.Static = http.StripPrefix(
|
||||||
assetPath,
|
assetPath,
|
||||||
@@ -458,7 +458,7 @@ func NewState(p policy.Policy, settings StateSettings) (state *State, err error)
|
|||||||
})
|
})
|
||||||
|
|
||||||
case "wasm":
|
case "wasm":
|
||||||
wasmData, err := go_away.ChallengeFs.ReadFile(fmt.Sprintf("challenge/%s/runtime/%s", challengeName, p.Runtime.Asset))
|
wasmData, err := embed.ChallengeFs.ReadFile(fmt.Sprintf("challenge/%s/runtime/%s", challengeName, p.Runtime.Asset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("c %s: could not load runtime: %w", challengeName, err)
|
return nil, fmt.Errorf("c %s: could not load runtime: %w", challengeName, err)
|
||||||
}
|
}
|
||||||
@@ -470,7 +470,7 @@ func NewState(p policy.Policy, settings StateSettings) (state *State, err error)
|
|||||||
c.MakeChallenge = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
c.MakeChallenge = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
err := state.ChallengeMod(challengeName, func(ctx context.Context, mod api.Module) (err error) {
|
err := state.ChallengeMod(challengeName, func(ctx context.Context, mod api.Module) (err error) {
|
||||||
|
|
||||||
in := challenge.MakeChallengeInput{
|
in := challenge2.MakeChallengeInput{
|
||||||
Key: state.GetChallengeKeyForRequest(challengeName, time.Now().UTC().Add(DefaultValidity).Round(DefaultValidity), r),
|
Key: state.GetChallengeKeyForRequest(challengeName, time.Now().UTC().Add(DefaultValidity).Round(DefaultValidity), r),
|
||||||
Parameters: p.Parameters,
|
Parameters: p.Parameters,
|
||||||
Headers: inline.MIMEHeader(r.Header),
|
Headers: inline.MIMEHeader(r.Header),
|
||||||
@@ -480,7 +480,7 @@ func NewState(p policy.Policy, settings StateSettings) (state *State, err error)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := challenge.MakeChallengeCall(state.WasmContext, mod, in)
|
out, err := challenge2.MakeChallengeCall(state.WasmContext, mod, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -502,21 +502,21 @@ func NewState(p policy.Policy, settings StateSettings) (state *State, err error)
|
|||||||
|
|
||||||
c.Verify = func(key []byte, result string) (ok bool, err error) {
|
c.Verify = func(key []byte, result string) (ok bool, err error) {
|
||||||
err = state.ChallengeMod(challengeName, func(ctx context.Context, mod api.Module) (err error) {
|
err = state.ChallengeMod(challengeName, func(ctx context.Context, mod api.Module) (err error) {
|
||||||
in := challenge.VerifyChallengeInput{
|
in := challenge2.VerifyChallengeInput{
|
||||||
Key: key,
|
Key: key,
|
||||||
Parameters: p.Parameters,
|
Parameters: p.Parameters,
|
||||||
Result: []byte(result),
|
Result: []byte(result),
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := challenge.VerifyChallengeCall(state.WasmContext, mod, in)
|
out, err := challenge2.VerifyChallengeCall(state.WasmContext, mod, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if out == challenge.VerifyChallengeOutputError {
|
if out == challenge2.VerifyChallengeOutputError {
|
||||||
return errors.New("error checking challenge")
|
return errors.New("error checking challenge")
|
||||||
}
|
}
|
||||||
ok = out == challenge.VerifyChallengeOutputOK
|
ok = out == challenge2.VerifyChallengeOutputOK
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user