Skip to content

Commit

Permalink
hicli/verify: add support for passphrase in addition to recovery key
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Nov 15, 2024
1 parent e0612ac commit b585d72
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/hicli/json-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (h *HiClient) handleJSONCommand(ctx context.Context, req *JSONCommand) (any
})
case "verify":
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":
return unmarshalAndCall(req.Data, func(params *discoverHomeserverParams) (*mautrix.ClientWellKnown, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/hicli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h *HiClient) LoginAndVerify(ctx context.Context, homeserverURL, username,
if err != nil {
return err
}
err = h.VerifyWithRecoveryKey(ctx, recoveryKey)
err = h.Verify(ctx, recoveryKey)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/hicli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package hicli
import (
"context"
"encoding/base64"
"errors"
"fmt"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -125,13 +126,16 @@ func (h *HiClient) storeCrossSigningPrivateKeys(ctx context.Context) error {
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()
keyID, keyData, err := h.Crypto.SSSS.GetDefaultKeyData(ctx)
if err != nil {
return fmt.Errorf("failed to get default SSSS key data: %w", err)
}
key, err := keyData.VerifyRecoveryKey(keyID, code)
if errors.Is(err, ssss.ErrInvalidRecoveryKey) && keyData.Passphrase != nil {
key, err = keyData.VerifyPassphrase(keyID, code)
}
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/ui/login/VerificationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const VerificationScreen = ({ client, clientState }: LoginScreenProps) =>
type="text"
autoComplete="off"
id="mxlogin-recoverykey"
placeholder="Recovery key"
placeholder="Recovery key or passphrase"
value={recoveryKey}
onChange={evt => setRecoveryKey(evt.target.value)}
/>
Expand Down

0 comments on commit b585d72

Please sign in to comment.