From 939284194d163015a799cb952c04c14e204bf85c Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 23 Mar 2025 18:19:58 +0800 Subject: Rename token -> identifier --- main.go | 18 +++++++++--------- tmpl.go | 18 +++++++++--------- token.go | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 06feec7..3a69564 100644 --- a/main.go +++ b/main.go @@ -14,9 +14,9 @@ import ( ) type tparams struct { - UnsignedTokenBase64 string - Message string - Global any + Identifier string + Message string + Global any } func main() { @@ -31,7 +31,7 @@ func main() { } } - identifier, expectedMAC := makeSignedToken(request) + identifier, expectedMAC := makeIdentifierMAC(request) if validateCookie(cookie, expectedMAC) { proxyRequest(writer, request) @@ -40,9 +40,9 @@ func main() { authPage := func(message string) { _ = tmpl.Execute(writer, tparams{ - UnsignedTokenBase64: base64.StdEncoding.EncodeToString(identifier), - Message: message, - Global: global, + Identifier: base64.StdEncoding.EncodeToString(identifier), + Message: message, + Global: global, }) } @@ -94,12 +94,12 @@ func validateCookie(cookie *http.Cookie, expectedMAC []byte) bool { return false } - gotToken, err := base64.StdEncoding.DecodeString(cookie.Value) + gotMAC, err := base64.StdEncoding.DecodeString(cookie.Value) if err != nil { return false } - return subtle.ConstantTimeCompare(gotToken, expectedMAC) == 1 + return subtle.ConstantTimeCompare(gotMAC, expectedMAC) == 1 } func getRemoteIP(request *http.Request) (remoteIP string) { diff --git a/tmpl.go b/tmpl.go index 3c297ec..de77674 100644 --- a/tmpl.go +++ b/tmpl.go @@ -192,16 +192,16 @@ func init() { {{- end }}
-

Select a nonce no longer than 32 bytes, such that when it is appended to the decoded form of the challenge token, and the entire result is hashed with SHA-256, the first {{ .Global.NeedBits }} bits of the SHA-256 hash are all zeros. Within one octet, higher bits are considered to come before lower bits.

- - +

Select a nonce no longer than 32 bytes, such that when it is appended to the decoded form of the challenge identifier, and the entire result is hashed with SHA-256, the first {{ .Global.NeedBits }} bits of the SHA-256 hash are all zeros. Within one octet, higher bits are considered to come before lower bits.

+ +

Encode your selected nonce in base64 and submit it below.

Please note that if your submission is successful, you will be given a cookie that will allow you to access this site for a period of time without having to complete the challenge again. By pressing the submit button, you agree to be given cookies for this purpose.

- +
@@ -219,7 +219,7 @@ func init() {