Skip to content

Commit 01a3f15

Browse files
committed
feat: add support for sha256 and sha512 htpasswd formats
Fixes issue #3495 We currently support only bcrypt htpasswd hashes, however bcrypt is not FIPS-140 approved since it uses Blowfish. This PR adds support for sha256 and sha512 formats and enforces that bcrypt be disabled when fips140 mode is enabled. Signed-off-by: Ramkumar Chinchani <[email protected]>
1 parent 33c466e commit 01a3f15

25 files changed

+466
-132
lines changed

examples/config-minimal.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
},
66
"http": {
77
"address": "127.0.0.1",
8-
"port": "8080"
8+
"port": "8080",
9+
"auth": {
10+
"htpasswd": {
11+
"path": "test/data/htpasswd"
12+
}
13+
}
914
},
1015
"log": {
1116
"level": "debug"

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.24.4
44

55
require (
66
github.com/99designs/gqlgen v0.17.81
7+
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5
78
github.com/Masterminds/semver v1.5.0
89
github.com/alicebob/miniredis/v2 v2.35.0
910
github.com/aquasecurity/trivy v0.65.0
@@ -43,6 +44,7 @@ require (
4344
github.com/json-iterator/go v1.1.12
4445
github.com/migueleliasweb/go-github-mock v1.4.0
4546
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c
47+
github.com/nathanaelle/password v1.0.0
4648
github.com/nats-io/nats-server/v2 v2.12.1
4749
github.com/nats-io/nats.go v1.47.0
4850
github.com/nmcclain/ldap v0.0.0-20210720162743-7f8d1e44eeba

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl
689689
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
690690
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
691691
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
692+
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5 h1:IEjq88XO4PuBDcvmjQJcQGg+w+UaafSy8G5Kcb5tBhI=
693+
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5/go.mod h1:exZ0C/1emQJAw5tHOaUDyY1ycttqBAPcxuzf7QbY6ec=
692694
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible h1:juIaKLLVhqzP55d8x4cSVgwyQv76Z55/fRv/UBr2KkQ=
693695
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible/go.mod h1:BB1eHdMLYEFuFdBlRMb0N7YGVdM5s6Pt0njxgvfbGGs=
694696
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 h1:ErKg/3iS1AKcTkf3yixlZ54f9U1rljCkQyEXWUnIUxc=
@@ -1731,6 +1733,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
17311733
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
17321734
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
17331735
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
1736+
github.com/nathanaelle/password v1.0.0 h1:1Etka3uuBvATlCb72f7P5vsgedus+C91Fgff1oMloq0=
1737+
github.com/nathanaelle/password v1.0.0/go.mod h1:wt9xV3xwQmc3Qi0ofowmzR7N+kF1L4cguCuWjAfdj1Q=
17341738
github.com/nats-io/jwt/v2 v2.8.0 h1:K7uzyz50+yGZDO5o772eRE7atlcSEENpL7P+b74JV1g=
17351739
github.com/nats-io/jwt/v2 v2.8.0/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA=
17361740
github.com/nats-io/nats-server/v2 v2.12.1 h1:0tRrc9bzyXEdBLcHr2XEjDzVpUxWx64aZBm7Rl1QDrA=

pkg/api/authn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestAPIKeys(t *testing.T) {
9999

100100
username, seedUser := test.GenerateRandomString()
101101
password, seedPass := test.GenerateRandomString()
102-
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
102+
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetBcryptCredString(username, password))
103103

104104
defer os.Remove(htpasswdPath)
105105

@@ -871,7 +871,7 @@ func TestAPIKeysOpenDBError(t *testing.T) {
871871
conf := config.New()
872872
username, seedUser := test.GenerateRandomString()
873873
password, seedPass := test.GenerateRandomString()
874-
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
874+
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetBcryptCredString(username, password))
875875

876876
defer os.Remove(htpasswdPath)
877877

@@ -1154,7 +1154,7 @@ func TestCookieSecureFlag(t *testing.T) {
11541154

11551155
username, _ := test.GenerateRandomString()
11561156
password, _ := test.GenerateRandomString()
1157-
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
1157+
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetBcryptCredString(username, password))
11581158

11591159
defer os.Remove(htpasswdPath)
11601160

0 commit comments

Comments
 (0)