Skip to content

Prompt for TFA code in CLI on PSTATUS_TFA_REQUIRED. - #209

Open
julienisapunk wants to merge 3 commits into
pCloud:masterfrom
julienisapunk:tfa-prompt
Open

Prompt for TFA code in CLI on PSTATUS_TFA_REQUIRED.#209
julienisapunk wants to merge 3 commits into
pCloud:masterfrom
julienisapunk:tfa-prompt

Conversation

@julienisapunk

Copy link
Copy Markdown

The library already exposes psync_tfa_send_nofification / psync_tfa_send_sms / psync_tfa_set_code, but the console client never wired them up, so a login on a TFA-protected (or new-device-verified) account looped forever on LOGIN_REQUIRED. Handle PSTATUS_TFA_REQUIRED by triggering a code via notification (falling back to SMS), reading it from stdin, and submitting it with trust=1; re-prompt on PSTATUS_BAD_TFA_CODE. A 'r:' prefix routes to psync_tfa_set_code with is_recovery=1 for recovery codes.

lqwer and others added 3 commits May 14, 2026 07:56
The library already exposes psync_tfa_send_nofification / psync_tfa_send_sms /
psync_tfa_set_code, but the console client never wired them up, so a login on
a TFA-protected (or new-device-verified) account looped forever on
LOGIN_REQUIRED. Handle PSTATUS_TFA_REQUIRED by triggering a code via
notification (falling back to SMS), reading it from stdin, and submitting it
with trust=1; re-prompt on PSTATUS_BAD_TFA_CODE. A 'r:' prefix routes to
psync_tfa_set_code with is_recovery=1 for recovery codes.
get_connected_socket() only cleared a pending two factor code for results
2000/2012/2064/2074/2092. Anything else fell through to the bare
psync_milisleep(PSYNC_SLEEP_BEFORE_RECONNECT) with psync_my_2fa_code still
set, so the next iteration resent the same code. A malformed code gets 1022
"Please provide 'code'" rather than 2012, so entering one wedged the login
in a silent five second retry loop: status stayed CONNECTING, no
PSTATUS_AUTH_BADCODE was ever raised, the CLI never re-prompted, and
psync_fs_start() never ran -- leaving an empty mountpoint and nothing on
screen to explain why. Discard the code and raise PSTATUS_AUTH_BADCODE for
any unhandled result while one is pending, so the existing
PSTATUS_BAD_TFA_CODE handler asks again.

Also normalize what is typed at the prompt before it reaches the API, since
1022 is indistinguishable from a genuinely missing parameter: trim
whitespace, drop spaces and dashes inside the code, read 'r:' or 'recovery:'
(any case) as the recovery marker, reject a non-recovery code holding
non-digits or one longer than psync_my_2fa_code's 31 usable bytes, and
re-prompt locally instead of spending a round trip on input that cannot
work. Exit on stdin EOF instead of submitting an empty code.

The marker has to carry its colon. A bare leading 'r' is far more likely a
mistyped device code than a real recovery code, since codes sent to a device
are six digits while tfa_loginwithrecoverycode wants something longer, so
treating it as the marker would only trade a local rejection for a round
trip that comes back 2012. 'r341820' now fails the digits check and the user
is pointed at the prefix instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Building the vendored mbedtls the documented way ("cmake ." then "make" in
pCloudCC/lib/mbedtls) writes a Makefile into every configured subdirectory.
mbedtls' own .gitignore lists CMakeCache.txt, CMakeFiles and
cmake_install.cmake but not these, so they showed up as untracked and were
easy to stage by accident. Nothing named Makefile is tracked anywhere under
that tree -- only CMakeLists.txt files -- so one anchored pattern covers the
top level, library/, and anything configured later.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant