Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Use auth key derivation from API response #32

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
const (
totpTimeStep = 10
totpDigits = 7
kdfRounds = 1e3
kdfKeyLen = 256
)

Expand Down Expand Up @@ -86,7 +85,7 @@ func generateTOTP(secret []byte, t time.Time, digits int, timeStep int64) (strin
return fmt.Sprintf(f, mod), nil
}

func decryptToken(encryptedSeedB64, salt, passphrase string) (string, error) {
func decryptToken(kdfRounds int, encryptedSeedB64, salt, passphrase string) (string, error) {
encryptedSeed, err := base64.StdEncoding.DecodeString(encryptedSeedB64)
if err != nil {
return "", fmt.Errorf("Error decoding encrypted seed: %v", err)
Expand Down
5 changes: 4 additions & 1 deletion objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ type AuthenticatorToken struct {
// The encrypted TOTP seed
EncryptedSeed string `json:"encrypted_seed"`

// The number of rounds for password-based key derivation
KDFRounds int `json:"key_derivation_iterations"`

// User-nominated name for the token
Name string `json:"name"`

Expand All @@ -173,7 +176,7 @@ type AuthenticatorToken struct {
// Decrypt returns the base32-encoded seed for this TOTP token, decrypted
// by passphrase.
func (t AuthenticatorToken) Decrypt(passphrase string) (string, error) {
secret, err := decryptToken(t.EncryptedSeed, t.Salt, passphrase)
secret, err := decryptToken(t.KDFRounds, t.EncryptedSeed, t.Salt, passphrase)
if err != nil {
return "", err
}
Expand Down