forked from Mirrors/gomuks
hicli/verify: add support for passphrase in addition to recovery key
This commit is contained in:
parent
e0612ac0fb
commit
b585d72069
4 changed files with 8 additions and 4 deletions
|
@ -129,7 +129,7 @@ func (h *HiClient) handleJSONCommand(ctx context.Context, req *JSONCommand) (any
|
||||||
})
|
})
|
||||||
case "verify":
|
case "verify":
|
||||||
return unmarshalAndCall(req.Data, func(params *verifyParams) (bool, error) {
|
return unmarshalAndCall(req.Data, func(params *verifyParams) (bool, error) {
|
||||||
return true, h.VerifyWithRecoveryKey(ctx, params.RecoveryKey)
|
return true, h.Verify(ctx, params.RecoveryKey)
|
||||||
})
|
})
|
||||||
case "discover_homeserver":
|
case "discover_homeserver":
|
||||||
return unmarshalAndCall(req.Data, func(params *discoverHomeserverParams) (*mautrix.ClientWellKnown, error) {
|
return unmarshalAndCall(req.Data, func(params *discoverHomeserverParams) (*mautrix.ClientWellKnown, error) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (h *HiClient) LoginAndVerify(ctx context.Context, homeserverURL, username,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = h.VerifyWithRecoveryKey(ctx, recoveryKey)
|
err = h.Verify(ctx, recoveryKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ package hicli
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
@ -125,13 +126,16 @@ func (h *HiClient) storeCrossSigningPrivateKeys(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HiClient) VerifyWithRecoveryKey(ctx context.Context, code string) error {
|
func (h *HiClient) Verify(ctx context.Context, code string) error {
|
||||||
defer h.dispatchCurrentState()
|
defer h.dispatchCurrentState()
|
||||||
keyID, keyData, err := h.Crypto.SSSS.GetDefaultKeyData(ctx)
|
keyID, keyData, err := h.Crypto.SSSS.GetDefaultKeyData(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get default SSSS key data: %w", err)
|
return fmt.Errorf("failed to get default SSSS key data: %w", err)
|
||||||
}
|
}
|
||||||
key, err := keyData.VerifyRecoveryKey(keyID, code)
|
key, err := keyData.VerifyRecoveryKey(keyID, code)
|
||||||
|
if errors.Is(err, ssss.ErrInvalidRecoveryKey) && keyData.Passphrase != nil {
|
||||||
|
key, err = keyData.VerifyPassphrase(keyID, code)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ export const VerificationScreen = ({ client, clientState }: LoginScreenProps) =>
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
id="mxlogin-recoverykey"
|
id="mxlogin-recoverykey"
|
||||||
placeholder="Recovery key"
|
placeholder="Recovery key or passphrase"
|
||||||
value={recoveryKey}
|
value={recoveryKey}
|
||||||
onChange={evt => setRecoveryKey(evt.target.value)}
|
onChange={evt => setRecoveryKey(evt.target.value)}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Reference in a new issue