aboutsummaryrefslogtreecommitdiff
path: root/cmd/anubis/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/anubis/main.go')
-rw-r--r--cmd/anubis/main.go28
1 files changed, 6 insertions, 22 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go
index 3982e37..8c0327b 100644
--- a/cmd/anubis/main.go
+++ b/cmd/anubis/main.go
@@ -266,13 +266,10 @@ func metricsServer(ctx context.Context, done func()) {
}
}
-func sha256sum(text string) (string, error) {
+func sha256sum(text string) string {
hash := sha256.New()
- _, err := hash.Write([]byte(text))
- if err != nil {
- return "", err
- }
- return hex.EncodeToString(hash.Sum(nil)), nil
+ hash.Write([]byte(text))
+ return hex.EncodeToString(hash.Sum(nil))
}
func (s *Server) challengeFor(r *http.Request, difficulty int) string {
@@ -287,8 +284,7 @@ func (s *Server) challengeFor(r *http.Request, difficulty int) string {
fp,
difficulty,
)
- result, _ := sha256sum(data)
- return result
+ return sha256sum(data)
}
func New(target, policyFname string) (*Server, error) {
@@ -522,13 +518,7 @@ func (s *Server) maybeReverseProxy(w http.ResponseWriter, r *http.Request) {
}
calcString := fmt.Sprintf("%s%d", challenge, nonce)
- calculated, err := sha256sum(calcString)
- if err != nil {
- lg.Error("failed to calculate sha256sum", "path", r.URL.Path, "err", err)
- clearCookie(w)
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
+ calculated := sha256sum(calcString)
if subtle.ConstantTimeCompare([]byte(claims["response"].(string)), []byte(calculated)) != 1 {
lg.Debug("invalid response", "path", r.URL.Path)
@@ -635,13 +625,7 @@ func (s *Server) passChallenge(w http.ResponseWriter, r *http.Request) {
}
calcString := fmt.Sprintf("%s%d", challenge, nonce)
- calculated, err := sha256sum(calcString)
- if err != nil {
- clearCookie(w)
- lg.Debug("can't parse shasum", "err", err)
- templ.Handler(base("Oh noes!", errorPage("failed to calculate sha256sum")), templ.WithStatus(http.StatusInternalServerError)).ServeHTTP(w, r)
- return
- }
+ calculated := sha256sum(calcString)
if subtle.ConstantTimeCompare([]byte(response), []byte(calculated)) != 1 {
clearCookie(w)