Skip to content

T-REPLACE-RX doesn't work as expected when escaping curly braces #11890

@maddes-b

Description

@maddes-b

Have you searched for an existing issue?

  • Yes, I tried searching and reviewed the pinned issues

Brief Summary

Update: Refined in this comment

When using T-REPLACE-RX for empty placeholders and/or in a nested way, then KeePassXC fails to process the functions.

Empty placeholder: {T-REPLACE-RX:/&digits={S:TimeOtp-Length}/&digits=\{S:TimeOtp-Length\}//}
Nested fucntion: {T-REPLACE-RX:#{T-REPLACE-RX:!{S:TimeOtp-Algorithm}!HMAC-!!}#SHA-#SHA#}

In my case I run into the pitfall of different OTP definitions between KeePassXC and KeePass2, due to switching to KeePassXC for private use, while having to use KeePass2 at work.
So I convert the TOTP settings when needed. I started on KeePass2 by converting the KP2 fields into an otpauth URI for KPXC - folllowing IETF draft [1].
Worked well in KP2 for the first batch I converted, but failed in KPXC when converting further for otpauth parameters that are build with T-REPLACE-RX.
This is either due to escaping the curly braces {} or due to having nested T-REPLACE-RX statements.

[1] https://datatracker.ietf.org/doc/draft-linuxgemini-otpauth-uri/

Steps to Reproduce

Create a test entry that has the fields for TOTP as stored by KeePass2:

  • field "TimeOtp-Algorithm", value "HMAC-SHA-256"
  • field "TimeOtp-Length", value "7"
  • field "TimeOtp-Period", value "15"
  • field "TimeOtp-Secret-Base32", value "AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPSAIJCEMSCKJRHFAUSUKZMFUXC6MBRGIZTINJWG44DSOR3HQ6T4PY"

Add additional field to convert KeePass2 TOTP fields into an otpauth string (IETF draft) for KeePassXC

  • field "kp2-otpauth", value "otpauth://totp/{T-CONV:/{USERNAME}/Uri/}?secret={S:TimeOtp-Secret-Base32}&issuer={T-CONV:/{TITLE}/Uri/}{T-REPLACE-RX:/&digits={S:TimeOtp-Length}/&digits={S:TimeOtp-Length}//}{T-REPLACE-RX:/&period={S:TimeOtp-Period}/&period={S:TimeOtp-Period}//}{T-REPLACE-RX:/&algorithm={T-REPLACE-RX:#{T-REPLACE-RX:!{S:TimeOtp-Algorithm}!HMAC-!!}#SHA-#SHA#}/&period={S:TimeOtp-Algorithm}//}"

Copy attribute "kp2-otpath" and check resulting value.

Expected Versus Actual Behavior

Expected result (as returned by KeePass 2.58 [2]):
otpauth://totp/std_usr?secret=AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPSAIJCEMSCKJRHFAUSUKZMFUXC6MBRGIZTINJWG44DSOR3HQ6T4PY&issuer=Test%20Convert%20KeePass%20to%20XC&digits=7&period=15&algorithm=SHA256

Actual result of KeePassXC:
otpauth://totp/std_usr?secret=AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPSAIJCEMSCKJRHFAUSUKZMFUXC6MBRGIZTINJWG44DSOR3HQ6T4PY&issuer=Test%20Convert%20KeePass%20to%20XC

[2] https://keepass.info/help/base/placeholders.html#texttrf

KeePassXC Debug Information

KeePassXC - Version 2.7.10
Revision: b342be4

Qt 5.15.11
Debugging mode is disabled.

Operating system: Windows 10 Version 2009
CPU architecture: x86_64
Kernel: winnt 10.0.19045

Enabled extensions:
- Auto-Type
- Browser Integration
- Passkeys
- SSH Agent
- KeeShare
- YubiKey
- Quick Unlock

Cryptographic libraries:
- Botan 3.1.1

Operating System

Windows

Linux Desktop Environment

None

Linux Windowing System

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions