test(ocrypto): add failing tests for EC P-384/P-521 ECDH bug#3071
test(ocrypto): add failing tests for EC P-384/P-521 ECDH bug#3071pflynn-virtru wants to merge 4 commits intomainfrom
Conversation
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Summary of ChangesHello @pflynn-virtru, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a set of failing tests designed to expose a critical bug in the handling of Elliptic Curve (EC) public keys, specifically when uncompressing P-384 and P-521 curves. By adding these targeted tests, the PR establishes a clear, reproducible scenario for the bug, paving the way for a robust fix that ensures correct curve parameter usage during key operations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. A curve, a key, a hidden flaw, Tests now reveal what's out of law. P-384, P-521, they cry, For proper curve, or else they die. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds two well-designed failing tests, TestUncompressECPubKey_CurvePreservation and TestDecryptWithCompressedEphemeralKey, to expose a bug in UncompressECPubKey related to handling different elliptic curves. The tests are clear, use a table-driven approach effectively, and are a great example of Test-Driven Development by establishing the "red" phase. The overall changes are excellent for identifying and documenting the bug. I have one minor suggestion to improve conciseness in one of the new tests.
| curve, err := GetECCurveFromECCMode(tc.mode) | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
The curve object can be retrieved directly from the keyPair that was just created, which already holds the curve information. This avoids a redundant call to GetECCurveFromECCMode and makes the test setup slightly more concise.
| curve, err := GetECCurveFromECCMode(tc.mode) | |
| require.NoError(t, err) | |
| curve := keyPair.PrivateKey.Curve |
e4cd4dc to
d518915
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
d518915 to
07c992e
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Add two TDD red-phase tests that reproduce issue #3070 where UncompressECPubKey hardcodes elliptic.P256() instead of using the curve parameter, breaking P-384 and P-521 decrypt operations. - TestUncompressECPubKey_CurvePreservation: verifies the returned key's curve matches the input curve after compress/uncompress - TestDecryptWithCompressedEphemeralKey: end-to-end encrypt/decrypt with compressed ephemeral keys simulating the rewrap code path P-256 subtests pass; P-384 and P-521 subtests fail as expected. Closes #3070 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn@virtru.com>
07c992e to
6ed8791
Compare
X-Test Failure Reportopentdf |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Add two new test functions that reproduce issue #3070 in the BasicManager layer (service/internal/security): - TestBasicManager_Decrypt_ECAllCurves: Tests Decrypt() for P-256, P-384, and P-521 with **compressed** ephemeral keys. The existing EC decrypt test only covers P-256 and passes the ephemeral key in DER format (which bypasses UncompressECPubKey entirely). - TestBasicManager_DeriveKey_ECAllCurves: Tests DeriveKey() for all three curves. DeriveKey calls UncompressECPubKey directly (not via DecryptWithEphemeralKey), exercising a separate code path affected by the hardcoded P-256 curve. Both tests: P-256 passes, P-384/P-521 fail with the exact production errors — "ecdsa: invalid public key" and "x509: invalid elliptic curve public key" respectively. Refs: #3070 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn@virtru.com>
X-Test Failure Report |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
- Drop sdk/ec_wrap_test.go: mirrored rewrap.go internals - Drop TestECRewrapKeyGenerateAllCurves: doesn't exercise the bug (PEM-based ECDH never calls UncompressECPubKey) - Simplify TestDecryptWithCompressedEphemeralKey: use FromPublicPEMWithSalt for encryption instead of manual ECDH+HKDF+AES-GCM; extract compressEphemeralDER helper - Simplify TestBasicManager_DeriveKey_ECAllCurves: generate client key via NewECKeyPair instead of marshal→parse round-trip; drop ecdh.Curve from test table Refs: #3070 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn@virtru.com>
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
70319e5 to
5e4daad
Compare
X-Test Failure Report |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Add round-trip tests that prove FormatAlg and getKasKeyAlg share the same ocrypto.KeyType contract: - service/pkg/db: FormatAlg(enum) → reverse-map lookup → assert original enum. EC-P521 subtest fails (typo: "ec:secp512r1" vs "ec:secp521r1"). - sdk: formatAlg(enum) → getKasKeyAlg(result) → assert original enum. All pass (SDK formatAlg is correct). Refs: #3070 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn@virtru.com>
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Summary
TDD red-phase tests that reproduce #3070 — covers both the
UncompressECPubKeyP-256 hardcoding bug and theFormatAlgP-521 typo ("ec:secp512r1"instead of"ec:secp521r1").ocrypto / security layer tests
Four tests across two layers, exercising three distinct code paths:
TestUncompressECPubKey_CurvePreservationTestDecryptWithCompressedEphemeralKeyDecryptWithEphemeralKeycompressed-key fallback pathTestBasicManager_Decrypt_ECAllCurvesBasicManager.Decrypt→NewECDecryptor→DecryptWithEphemeralKeywith compressed ephemeral keysTestBasicManager_DeriveKey_ECAllCurvesBasicManager.DeriveKey→UncompressECPubKey(separate call site, fails atx509.MarshalPKIXPublicKey)All P-256 subtests pass. P-384 and P-521 subtests fail as expected with the production error signatures:
ecdh failure: ecdsa: invalid public keyx509: invalid elliptic curve public keyFormatAlg round-trip tests
Two tests that prove
FormatAlg(server) andgetKasKeyAlg(SDK) share the sameocrypto.KeyTypecontract:TestFormatAlg_RoundTripFormatAlg(enum)→ reverse-map lookup → must equal original enum. EC-P521 fails (typo returns"ec:secp512r1")TestFormatAlg_GetKasKeyAlg_RoundTripformatAlg(enum)→getKasKeyAlg(result)→ must equal original enum. All pass (SDK is correct)Refs: #3070
Test plan
formatAlgis correct)🤖 Generated with Claude Code