mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
Use recovery phrase to verify in headless client
This commit is contained in:
parent
c628bfb97c
commit
b8a41425bd
1 changed files with 7 additions and 15 deletions
|
@ -62,7 +62,7 @@ func HeadlessInit(conf HeadlessConfig) error {
|
|||
}
|
||||
|
||||
// verify (fetch)
|
||||
key, err := getSSSS(mach, conf.MxPassword, conf.RecoveryPhrase)
|
||||
key, err := getSSSS(mach, conf.RecoveryPhrase)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ func initDirs() (string, string, string, string, error) {
|
|||
return config, data, cache, download, nil
|
||||
}
|
||||
|
||||
func getSSSS(mach *crypto.OlmMachine, password, recoveryPhrase string) (*ssss.Key, error) {
|
||||
func getSSSS(mach *crypto.OlmMachine, recoveryPhrase string) (*ssss.Key, error) {
|
||||
_, keyData, err := mach.SSSS.GetDefaultKeyData()
|
||||
if err != nil {
|
||||
if errors.Is(err, mautrix.MNotFound) {
|
||||
|
@ -147,19 +147,11 @@ func getSSSS(mach *crypto.OlmMachine, password, recoveryPhrase string) (*ssss.Ke
|
|||
}
|
||||
}
|
||||
|
||||
var key *ssss.Key
|
||||
if keyData.Passphrase != nil && keyData.Passphrase.Algorithm == ssss.PassphraseAlgorithmPBKDF2 {
|
||||
key, err = keyData.VerifyPassphrase(password)
|
||||
if errors.Is(err, ssss.ErrIncorrectSSSSKey) {
|
||||
return nil, fmt.Errorf("Incorrect passphrase")
|
||||
}
|
||||
} else {
|
||||
key, err = keyData.VerifyRecoveryKey(recoveryPhrase)
|
||||
if errors.Is(err, ssss.ErrInvalidRecoveryKey) {
|
||||
return nil, fmt.Errorf("Malformed recovery key")
|
||||
} else if errors.Is(err, ssss.ErrIncorrectSSSSKey) {
|
||||
return nil, fmt.Errorf("Incorrect recovery key")
|
||||
}
|
||||
key, err := keyData.VerifyRecoveryKey(recoveryPhrase)
|
||||
if errors.Is(err, ssss.ErrInvalidRecoveryKey) {
|
||||
return nil, fmt.Errorf("Malformed recovery key")
|
||||
} else if errors.Is(err, ssss.ErrIncorrectSSSSKey) {
|
||||
return nil, fmt.Errorf("Incorrect recovery key")
|
||||
}
|
||||
// All the errors should already be handled above, this is just for backup
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue