mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33: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)
|
// verify (fetch)
|
||||||
key, err := getSSSS(mach, conf.MxPassword, conf.RecoveryPhrase)
|
key, err := getSSSS(mach, conf.RecoveryPhrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func initDirs() (string, string, string, string, error) {
|
||||||
return config, data, cache, download, nil
|
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()
|
_, keyData, err := mach.SSSS.GetDefaultKeyData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, mautrix.MNotFound) {
|
if errors.Is(err, mautrix.MNotFound) {
|
||||||
|
@ -147,19 +147,11 @@ func getSSSS(mach *crypto.OlmMachine, password, recoveryPhrase string) (*ssss.Ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var key *ssss.Key
|
key, err := keyData.VerifyRecoveryKey(recoveryPhrase)
|
||||||
if keyData.Passphrase != nil && keyData.Passphrase.Algorithm == ssss.PassphraseAlgorithmPBKDF2 {
|
if errors.Is(err, ssss.ErrInvalidRecoveryKey) {
|
||||||
key, err = keyData.VerifyPassphrase(password)
|
return nil, fmt.Errorf("Malformed recovery key")
|
||||||
if errors.Is(err, ssss.ErrIncorrectSSSSKey) {
|
} else if errors.Is(err, ssss.ErrIncorrectSSSSKey) {
|
||||||
return nil, fmt.Errorf("Incorrect passphrase")
|
return nil, fmt.Errorf("Incorrect recovery key")
|
||||||
}
|
|
||||||
} 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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// All the errors should already be handled above, this is just for backup
|
// All the errors should already be handled above, this is just for backup
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue