aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/caddyauth
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2019-10-30 13:56:27 -0600
committerMatthew Holt <[email protected]>2019-10-30 13:56:27 -0600
commit76c22c7b388d659530a4f6d0ae9f242827f7ed82 (patch)
treea320d8878e97712fd23a952a3daa232f9d27100e /modules/caddyhttp/caddyauth
parentc7da6175bc654a37510541d6d55b7a0010cfd210 (diff)
downloadcaddy-76c22c7b388d659530a4f6d0ae9f242827f7ed82.tar.gz
caddy-76c22c7b388d659530a4f6d0ae9f242827f7ed82.zip
auth: Clean up basicauth
Diffstat (limited to 'modules/caddyhttp/caddyauth')
-rw-r--r--modules/caddyhttp/caddyauth/basicauth.go26
-rw-r--r--modules/caddyhttp/caddyauth/hashes.go6
2 files changed, 6 insertions, 26 deletions
diff --git a/modules/caddyhttp/caddyauth/basicauth.go b/modules/caddyhttp/caddyauth/basicauth.go
index b7c002be3..6412d36e5 100644
--- a/modules/caddyhttp/caddyauth/basicauth.go
+++ b/modules/caddyhttp/caddyauth/basicauth.go
@@ -15,8 +15,6 @@
package caddyauth
import (
- "crypto/sha256"
- "crypto/subtle"
"encoding/json"
"fmt"
"net/http"
@@ -126,30 +124,6 @@ type Comparer interface {
Compare(hashedPassword, plaintextPassword, salt []byte) (bool, error)
}
-type quickComparer struct{}
-
-func (quickComparer) Compare(theirHash, plaintext, _ []byte) (bool, error) {
- ourHash := quickHash(plaintext)
- return hashesMatch(ourHash, theirHash), nil
-}
-
-func hashesMatch(pwdHash1, pwdHash2 []byte) bool {
- return subtle.ConstantTimeCompare(pwdHash1, pwdHash2) == 1
-}
-
-// quickHash returns the SHA-256 of v. It
-// is not secure for password storage, but
-// it is useful for efficiently normalizing
-// the length of plaintext passwords for
-// constant-time comparisons.
-//
-// Errors are discarded.
-func quickHash(v []byte) []byte {
- h := sha256.New()
- h.Write([]byte(v))
- return h.Sum(nil)
-}
-
// Account contains a username, password, and salt (if applicable).
type Account struct {
Username string `json:"username"`
diff --git a/modules/caddyhttp/caddyauth/hashes.go b/modules/caddyhttp/caddyauth/hashes.go
index a515c0929..13010db7e 100644
--- a/modules/caddyhttp/caddyauth/hashes.go
+++ b/modules/caddyhttp/caddyauth/hashes.go
@@ -15,6 +15,8 @@
package caddyauth
import (
+ "crypto/subtle"
+
"github.com/caddyserver/caddy/v2"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/scrypt"
@@ -103,6 +105,10 @@ func (s ScryptHash) Compare(hashed, plaintext, salt []byte) (bool, error) {
return false, nil
}
+func hashesMatch(pwdHash1, pwdHash2 []byte) bool {
+ return subtle.ConstantTimeCompare(pwdHash1, pwdHash2) == 1
+}
+
// Interface guards
var (
_ Comparer = (*BcryptHash)(nil)