Skip to content

Fix a couple of problems with crypto utilities - #18897

Merged
gtritchie merged 3 commits into
mainfrom
bugfix-crypto-warning
Sep 24, 2026
Merged

gtritchie merged 3 commits into
mainfrom
bugfix-crypto-warning

Conversation

@jeffvroom

Copy link
Copy Markdown
Contributor

Intent

Fixes #18896

Approach

Turn warning into debug - fixed unsigned problem.

@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 19:59 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 19:59 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:01 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:01 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:04 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:04 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:11 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:11 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:11 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:11 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:11 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 22, 2026 20:11 — with GitHub Actions Active
@gtritchie gtritchie added this to the 2026.10 (Blue Mistflower) milestone Sep 22, 2026

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues. 1 follow-up, 1 nit

🔴 must be resolved before merge. 🟠 is real but not merge-blocking — either address it here or open an issue to do so later. 🟡 is optional.

  • 🟠 src/cpp/shared_core/system/encryption/EncryptionVersion.cpp:418 — v2 ciphertext of an empty plaintext no longer decrypts
  • 🟡 src/cpp/shared_core/system/encryption/EncryptionVersion.cpp:54 — comment describes a path that no longer reaches this branch

auto macIndex = ENCRYPTION_VERSION_SIZE_BYTES + dataLength;
// avoid using unsigned comparisons here
const size_t v2_OVERHEAD_BYTES = ENCRYPTION_VERSION_SIZE_BYTES + MAC_SIZE_BYTES;
if (in_v2_data.size() <= v2_OVERHEAD_BYTES)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Encrypting an empty plaintext with v2 gives exactly 17 bytes ([0x02][tag]), which this guard now rejects, so that round-trip fails.

Use < here, and drop overhead from the rejected lengths in the new test (EncryptionVersionTests.cpp:347).

Why

v2::aesEncrypt on empty data: GCM emits 0 ciphertext bytes plus a 16-byte tag, so the output is 1 + MAC_SIZE_BYTES = 17 bytes. With <=, v2::aesDecrypt throws EncryptionVersionMismatchException. crypto::aesDecrypt then falls back to v0 (AES-128-CBC) on 17 bytes. That isn't a block multiple, so it errors. Before this PR dataLength came out to 0, GCM checked the tag, and decryption returned an empty vector.

A zero-length payload is still well-formed. Only a buffer shorter than the overhead needs rejecting. I found no caller in this repo that encrypts an empty value, which is why this isn't marked blocking, but encryptAndBase64Encode is public API and downstream callers may pass empty strings (a blank password, for example).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4b51ea4 — the guard is now <, and the new round-trip test covers the empty-plaintext case.

if (ec == 0)
{
log::logWarningMessage("getLastCryptoError called with no pending error");
// Some OpenSSL operations report failure only by return value - not adding an error

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 This comment says version detection leads here, but after this PR neither fallback path hits the empty-queue branch.

Consider rewording the comment to describe what still reaches this branch, or keep it at warning level now that the noisy caller is gone.

Why

The v2 tag mismatch now returns its own bad_message error without calling getLastCryptoError. A v1/v0 bad-padding failure in EVP_CipherFinal_ex queues an OpenSSL error (bad decrypt), so it takes the ec != 0 path. Anything left that hits ec == 0 is an unexpected OpenSSL failure, and at debug level it won't show up in logs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4b51ea4 — the reworded comment matches the code now. Thanks!

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
3133 0 190 3
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 787 0 39 0
✅ desktop-macos 791 0 34 2
✅ desktop-windows 788 0 43 1
✅ server-linux 737 0 44 0
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 4b51ea4ace9d9e4f54c45c987f51287a90ebb005 - Run #1155

@jeffvroom
jeffvroom requested a review from gtritchie September 23, 2026 21:25
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:37 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:37 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:38 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:38 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:39 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:39 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:39 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:39 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:39 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:39 — with GitHub Actions Active

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both findings addressed — LGTM.

@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:41 — with GitHub Actions Active
@jeffvroom
jeffvroom deployed to e2e-playwright September 23, 2026 21:41 — with GitHub Actions Active
@gtritchie

Copy link
Copy Markdown
Member

snyk-code-scan failure: existing findings, not from this PR's changes

The Snyk Code stage scans every changed file in full (jenkins/Jenkinsfile.pull-request:88). This is the first scanned PR to touch EncryptionVersion.cpp since it was added, so the scan picked up two findings that already existed:

✗ [MEDIUM] Inadequate Encryption Strength - Small Key Size
  Path: src/cpp/shared_core/system/encryption/EncryptionVersion.cpp, line 159
  Info: Key size of 128 bits used in EVP_aes_128_cbc could be increased to 256 bits for algorithm AES.

✗ [MEDIUM] Inadequate Encryption Strength - Small Key Size
  Path: src/cpp/shared_core/system/encryption/EncryptionVersion.cpp, line 196
  Info: Key size of 128 bits used in EVP_aes_128_cbc could be increased to 256 bits for algorithm AES.

These are the EVP_aes_128_cbc() calls in v1::aesDecrypt and v1::aesEncrypt, which v0 also uses. Nothing the PR changes was flagged, including the new test key and the new bounds checks.

The cipher can't be changed here. Crypto.cpp uses these functions to decrypt existing v0/v1 data, and still writes v0/v1 when those versions are configured. v2 already uses AES-256-GCM.

Recommended action: mark the two findings as ignored in the Snyk UI ("legacy backward-compatible encryption; v2 uses AES-256-GCM"). Without that, every future PR that touches this file will fail the same way. The check isn't required, so this PR can merge in the meantime.

@gtritchie
gtritchie merged commit 71c6f68 into main Sep 24, 2026
40 of 41 checks passed
@gtritchie
gtritchie deleted the bugfix-crypto-warning branch September 24, 2026 15:30

This branch was successfully deployed

1 active deployment
e2e-playwright — 4b51ea4a Deployed Sep 23, 2026 by jeffvroom via linux-desktop / E2E (ubuntu-24-x86_64) #1155
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.

Warnings logged intermittently with crypto utilities

2 participants