Fix newline handling in JSON data for keyring#4
Conversation
|
I just realized that although this solution works, there is an important caveat to consider. The keyring is also accessible by other applications, which may suffer from the same issue, potentially making this fix ineffective. A more robust approach would be to Base64-encode the certificate values instead |
Update storage format to base64 encode JSON data for keyring.
|
The solution provided, although working, should be considered a temporary workaround. A better and more stable approach would be to Base64-encode only the certificate value, but that would need to be implemented elsewhere. |
Decode stored data from base64 before loading JSON.
|
hi @antoniogfs , why do you say the following?
I think storing all keyring entries encoded in base64 is more stable because it guarantees new lines will never end up in keyring entries, to avoid triggering the gnome-keyring bug. The main downside is that it makes debugging the keyring a bit more complicated but it's something we can deal with. However, many users will have entries in the keyring that were not encoded to base64 and this would break the keyring for those users. We can't introduce a breaking change. We could introduce a |
|
Hi @jllaneras, IMHO, this does not change much from a debugging perspective. The certificate is already in PEM format, so encoding it in Base64 does not really make it less readable. In any case, it still needs to be handled programmatically. Regarding the breaking change, I think you are partially right. However, I also believe the number of impacted users could be quite large. For example, users relying on other tools such as Chrome, which use the same keyring, may already be affected by this issue. Moreover, there may be possible workarounds that could preserve backward compatibility and support both cases. So, the question seems more about finding the right trade-off between:
Of course, you probably have much more context and information than I do, so I’ll leave the difficult decision to you. I just wanted to contribute to the discussion and hopefully help. |
This patch fixes a critical issue where the keyring parser fails to properly handle certificate data from ProtonVPN that contains newline characters. The fix escapes literal newlines in JSON-serialized data before storing it in the system keyring, ensuring the data can be reliably parsed back on retrieval.
What This Patch Solves
The Problem:
ProtonVPN certificates embedded in keyring data contain actual newline characters that break the keyring's ability to parse the stored JSON. When the system attempts to retrieve and deserialize this data, the JSON decoder fails because the literal newlines in the certificate strings corrupt the JSON structure, causing a
JSONDecodeErrorthat cascades into aKeyError.The Solution:
The patch modifies the
_set_item()method inproton/keyring_linux/core/keyring_linux.pyto escape all literal newline characters (\n) to their escaped string representation (\\n) before storing the JSON in the keyring. This ensures:_get_item(), the JSON decoder successfully deserializes it without errorsTechnical Details
proton/keyring_linux/core/keyring_linux.py_set_item()methodThe Code Change:
The fix intercepts the JSON string immediately after serialization and replaces all unescaped newlines with their escaped equivalents before passing the data to the keyring backend.
Why This Matters
Impact Scope: This bug affects any ProtonVPN credential or certificate data that contains multiline content (e.g., X.509 certificates commonly have newlines for readability). Without this fix:
With This Patch:
Risk Assessment
Risk Level: LOW
_get_item()) remains unchangedThis is a stable, focused bug fix with high confidence in its correctness.