@@ -15,6 +15,8 @@ import (
15
15
"testing"
16
16
"time"
17
17
18
+ "github.com/ory/kratos/hash"
19
+
18
20
"golang.org/x/net/publicsuffix"
19
21
20
22
"github.com/duo-labs/webauthn/protocol"
@@ -172,19 +174,9 @@ const (
172
174
const DefaultSessionCookieName = "ory_kratos_session"
173
175
174
176
type (
175
- Argon2 struct {
176
- Memory bytesize.ByteSize `json:"memory"`
177
- Iterations uint32 `json:"iterations"`
178
- Parallelism uint8 `json:"parallelism"`
179
- SaltLength uint32 `json:"salt_length"`
180
- KeyLength uint32 `json:"key_length"`
181
- ExpectedDuration time.Duration `json:"expected_duration"`
182
- ExpectedDeviation time.Duration `json:"expected_deviation"`
183
- DedicatedMemory bytesize.ByteSize `json:"dedicated_memory"`
184
- }
185
- Bcrypt struct {
186
- Cost uint32 `json:"cost"`
187
- }
177
+ Argon2 hash.Argon2Config
178
+ Bcrypt hash.BcryptConfig
179
+
188
180
SelfServiceHook struct {
189
181
Name string `json:"hook"`
190
182
Config json.RawMessage `json:"config"`
@@ -215,6 +207,7 @@ type (
215
207
216
208
Provider interface {
217
209
Config (ctx context.Context ) * Config
210
+ hash.ConfigProvider
218
211
}
219
212
)
220
213
@@ -394,10 +387,10 @@ func (p *Config) SessionName() string {
394
387
return stringsx .Coalesce (p .p .String (ViperKeySessionName ), DefaultSessionCookieName )
395
388
}
396
389
397
- func (p * Config ) HasherArgon2 () * Argon2 {
390
+ func (p * Config ) HasherArgon2 () * hash. Argon2Config {
398
391
// warn about usage of default values and point to the docs
399
392
// warning will require https://github.com/ory/viper/issues/19
400
- return & Argon2 {
393
+ return & hash. Argon2Config {
401
394
Memory : p .p .ByteSizeF (ViperKeyHasherArgon2ConfigMemory , Argon2DefaultMemory ),
402
395
Iterations : uint32 (p .p .IntF (ViperKeyHasherArgon2ConfigIterations , int (Argon2DefaultIterations ))),
403
396
Parallelism : uint8 (p .p .IntF (ViperKeyHasherArgon2ConfigParallelism , int (Argon2DefaultParallelism ))),
@@ -409,15 +402,15 @@ func (p *Config) HasherArgon2() *Argon2 {
409
402
}
410
403
}
411
404
412
- func (p * Config ) HasherBcrypt () * Bcrypt {
405
+ func (p * Config ) HasherBcrypt () * hash. BcryptConfig {
413
406
// warn about usage of default values and point to the docs
414
407
// warning will require https://github.com/ory/viper/issues/19
415
408
cost := uint32 (p .p .IntF (ViperKeyHasherBcryptCost , int (BcryptDefaultCost )))
416
409
if ! p .IsInsecureDevMode () && cost < BcryptDefaultCost {
417
410
cost = BcryptDefaultCost
418
411
}
419
412
420
- return & Bcrypt {Cost : cost }
413
+ return & hash. BcryptConfig {Cost : cost }
421
414
}
422
415
423
416
func (p * Config ) listenOn (key string ) string {
@@ -1040,6 +1033,10 @@ func (p *Config) HasherPasswordHashingAlgorithm() string {
1040
1033
}
1041
1034
}
1042
1035
1036
+ func (p * Config ) Hasher (provider hash.ConfigProvider ) hash.Hasher {
1037
+ return hash .NewHasher (p .HasherPasswordHashingAlgorithm (), provider )
1038
+ }
1039
+
1043
1040
func (p * Config ) CipherAlgorithm () string {
1044
1041
configValue := p .p .StringF (ViperKeyCipherAlgorithm , DefaultCipherAlgorithm )
1045
1042
switch configValue {
0 commit comments