Skip to content

feat(sdk): add DPoP client support with HTTP RoundTripper (DSPX-3397)#3581

Open
dmihalcik-virtru wants to merge 35 commits into
mainfrom
DSPX-3397-platform-go-sdk
Open

feat(sdk): add DPoP client support with HTTP RoundTripper (DSPX-3397)#3581
dmihalcik-virtru wants to merge 35 commits into
mainfrom
DSPX-3397-platform-go-sdk

Conversation

@dmihalcik-virtru

@dmihalcik-virtru dmihalcik-virtru commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Implements RFC 9449 DPoP (Demonstrating Proof-of-Possession) client support for the OpenTDF Go SDK.

This PR is part of the larger Keycloak v26 upgrade and comprehensive DPoP support feature tracked in DSPX-3397.

e2e Test

Changes

DPoP RoundTripper Implementation

  • sdk/auth/dpop_transport.go: New DPoPTransport that implements http.RoundTripper
    • Wraps any underlying transport (composable with existing HTTP clients)
    • Generates DPoP proofs for both token endpoint and resource requests
    • Proof claims: jti, htm, htu, iat (always); ath (resource calls only); nonce (when challenged)
    • URI normalization per RFC 9449 (lowercase scheme/host, strip default ports, no query/fragment)

Server-Issued Nonce Support

  • Handles DPoP-Nonce challenges per RFC 9449 §8
  • On 401 with DPoP-Nonce header: cache nonce, regenerate proof, retry once
  • Refresh cached nonces from successful 2xx responses
  • Per-origin nonce cache with thread-safe access

SDK Integration

  • sdk/sdk.go: Wrap HTTP client with DPoP transport during SDK construction
  • New getDPoPJWK() helper to convert ocrypto.RsaKeyPair to jwk.Key
  • NewDPoPHTTPClient() factory for wrapping clients with DPoP support
  • Automatically uses ephemeral EC P-256 key (ES256) when no key provided

Feature Detection

  • sdk/version.go: Add SupportedFeatures() function returning ["dpop", "connectrpc"]
  • Enables xtest integration harness to detect DPoP capability via supports dpop probe

Testing

  • sdk/auth/dpop_transport_test.go: Comprehensive unit tests
    • DPoP proof generation and validation
    • Nonce challenge/retry flow
    • URI normalization edge cases
    • Token endpoint vs resource endpoint behavior
    • Access token hash (ath) verification

Related Work

This PR implements the Go SDK cell of the DPoP feature. Related PRs:

  • tests: xtest integration tests and KC26 upgrade (see xtest/scenarios/DSPX-3397.yaml)
  • platform-service: Server-side DPoP validation middleware
  • java-sdk: Java SDK DPoP client support
  • web-sdk: Web SDK DPoP integration verification

Testing

All tests pass:

go test ./...
go test -run TestREADMECodeBlocks

Linting clean:

golangci-lint run ./...

Notes

  • The existing oauth.go already handles DPoP for token endpoint requests
  • The existing token_adding_interceptor.go already handles DPoP for gRPC/Connect
  • This PR adds the missing piece: DPoP for plain HTTP calls (KAS rewrap, etc.)
  • The RoundTripper pattern is idiomatic Go and composes with any http.Client

Jira: DSPX-3397
Test Scenario: xtest/scenarios/DSPX-3397.yaml

Summary by CodeRabbit

  • New Features
    • Added DPoP (RFC 9449) support for sender-constrained tokens and DPoP-bound requests, configurable via algorithm, PEM key, or JWK.
    • Added --dpop and --dpop-key flags to encrypt and decrypt commands.
    • Added exported SDK feature reporting for DPoP and Connect RPC.
  • Bug Fixes
    • Improved DPoP nonce challenge handling with a single safe retry and request-body replay.
    • Refined origin/URI normalization used for DPoP proof validation.
  • Documentation
    • Updated encrypt/decrypt manuals for new DPoP flags and interactions.
  • Tests
    • Added comprehensive coverage for DPoP transport, nonce retry, key handling, and validation HTTP client; extended xtest guidance.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds DPoP configuration, transport, and SDK/client wiring for token-bound requests, plus CLI flag plumbing and host-origin normalization in service auth.

Changes

DPoP Support

Layer / File(s) Summary
SDK config and key resolution
sdk/options.go, sdk/version.go, sdk/dpop_key.go, sdk/dpop_key_test.go
Adds DPoP option constructors and config fields, reports supported features, and implements key generation, PEM loading, algorithm validation, key resolution, and tests.
JWK-based token sources
sdk/idp_access_token_source.go, sdk/idp_cert_exchange.go, sdk/idp_oauth_access_token_source.go, sdk/idp_token_exchange_token_source.go
Adds constructors that build token sources from pre-resolved DPoP JWK keys.
DPoP HTTP transport
sdk/auth/dpop_transport.go, sdk/auth/dpop_transport_test.go, sdk/dpop_validation_client_test.go
Adds the DPoP transport, proof generation, nonce retry and body replay handling, client wrapping, and transport tests.
SDK DPoP wiring
sdk/sdk.go
Wraps SDK HTTP clients with the DPoP transport and routes token-source construction through JWK-based builders when needed.
Handler option plumbing
otdfctl/pkg/handlers/sdk.go, otdfctl/cmd/common/common.go, otdfctl/pkg/auth/auth.go
Exports handler option functions, threads extra SDK options into auth validation, and updates handler/auth client construction to accept the new option path.
CLI flags and docs
otdfctl/cmd/tdf/encrypt.go, otdfctl/cmd/tdf/decrypt.go, otdfctl/cmd/tdf/dpop.go, otdfctl/docs/man/..., AGENTS.md
Adds DPoP CLI flag parsing, passes the resulting SDK options into handler creation, updates the command manuals, and adds xtest branch-running instructions.
Host origin normalization
service/internal/auth/authn.go, service/internal/auth/authn_test.go
Adds normalized origin construction from Host headers and updates DPoP origin handling in the HTTP mux, with matching tests.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related issues

Possibly related PRs

  • opentdf/platform#3479: Also changes DPoP handling in service/internal/auth/authn.go, including validation-related origin and htu paths.

Suggested labels: comp:middleware:auth, docs

Suggested reviewers: elizabethhealy, jakedoublev, alkalescent

Poem

I packed up the proof in a carrot-lit jar,
Hopped through the nonce trail, near and far.
--dpop now sings with a tidy new tune,
And hosts line up under the moon.
🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding DPoP client support via an HTTP RoundTripper.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DSPX-3397-platform-go-sdk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 implements RFC 9449 DPoP (Demonstrating Proof-of-Possession) client support for the OpenTDF Go SDK. By introducing a custom HTTP RoundTripper, the SDK can now generate and attach DPoP proofs to HTTP requests, handle server-side nonce challenges, and perform URI normalization. This work is a key component of the broader Keycloak v26 upgrade, ensuring secure, proof-of-possession-based authentication for HTTP-based interactions within the platform.

Highlights

  • DPoP Transport Implementation: Introduced DPoPTransport, a new http.RoundTripper implementation that adds RFC 9449 DPoP proof tokens to HTTP requests, including support for server-issued nonce challenges and automatic retries.
  • SDK Integration: Updated the SDK to automatically wrap HTTP clients with DPoP support during construction, ensuring that resource requests are properly signed with DPoP proofs.
  • Feature Detection: Added a SupportedFeatures() function to sdk/version.go to allow integration harnesses to programmatically detect DPoP capability.
  • Testing: Added comprehensive unit tests for DPoP proof generation, nonce challenge flows, and URI normalization to ensure RFC 9449 compliance.
New Features

🧠 You can now enable Memory (public preview) 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.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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.


The proof is shown in token light, With DPoP we do it right. No replay here, the nonce is set, A secure path for the internet.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added comp:sdk A software development kit, including library, for client applications and inter-service communicati size/m labels Jun 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces RFC 9449 DPoP (Demonstrating Proof-of-Possession) support to the SDK by adding a new DPoPTransport and integrating it into the client setup. The code review identified several critical and high-severity issues in the transport implementation, including a potential bug where request bodies are consumed and not reset on retry, concurrency data races on shared fields like t.Base and t.nonceCache, and the bypass of custom transport configurations when retrieving access tokens. Additionally, optimizations were suggested to cache parsed token endpoint URLs and normalize URL origins to lowercase to prevent cache misses.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go
Comment thread sdk/auth/dpop_transport.go Outdated
Comment thread sdk/auth/dpop_transport.go
Comment thread sdk/auth/dpop_transport.go
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 203.008006ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 103.232466ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 423.703616ms
Throughput 236.01 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 50.220444104s
Average Latency 497.588923ms
Throughput 99.56 requests/second

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 270.01327ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 144.386555ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 443.855047ms
Throughput 225.30 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 49.03497246s
Average Latency 487.426932ms
Throughput 101.97 requests/second

@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-3397-platform-go-sdk branch from 441af7b to 61316ef Compare June 10, 2026 12:27
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 183.335287ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 101.378765ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 435.240452ms
Throughput 229.76 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 50.575675367s
Average Latency 503.106935ms
Throughput 98.86 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 173.859448ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 89.451113ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 443.962682ms
Throughput 225.24 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 49.774071866s
Average Latency 493.399511ms
Throughput 100.45 requests/second

@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-3397-platform-go-sdk branch from ebc3e40 to 37ed377 Compare June 11, 2026 17:47
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 189.365241ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 92.807389ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 458.733975ms
Throughput 217.99 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 50.627558901s
Average Latency 502.758805ms
Throughput 98.76 requests/second

@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-3397-platform-go-sdk branch from 37ed377 to b9dd8d8 Compare June 15, 2026 18:23
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 174.336781ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 87.925096ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 451.175969ms
Throughput 221.64 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 49.075520706s
Average Latency 488.0126ms
Throughput 101.88 requests/second

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 190.019238ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 100.783852ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 436.996106ms
Throughput 228.83 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 50.277491194s
Average Latency 498.407616ms
Throughput 99.45 requests/second

@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-3397-platform-go-sdk branch from 5c4f57a to 4cec258 Compare June 18, 2026 13:08
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 175.765414ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.303736ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 446.045553ms
Throughput 224.19 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 49.725004344s
Average Latency 495.004232ms
Throughput 100.55 requests/second

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 193.716094ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 106.047078ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 418.095248ms
Throughput 239.18 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 50.244870901s
Average Latency 499.255302ms
Throughput 99.51 requests/second

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 181.707776ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 99.144481ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 676.855143ms
Throughput 147.74 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 51.8725193s
Average Latency 515.398407ms
Throughput 96.39 requests/second

normalizeURI stripped default ports with strings.HasSuffix on the raw
host, which is brittle around IPv6 literals (e.g. [fe80::443]). Use
u.Hostname()/u.Port() compared against the scheme default instead, via a
shared normalizedHostPort helper reused by getOrigin so the nonce-cache
key and htu claim normalize consistently. isTokenEndpointRequest now
compares normalized URIs so an explicit :443 matches a portless endpoint.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Parse the request Host with url.Hostname()/Port() instead of trimming a
":443"/":80" suffix, so IPv6 literals and hosts that merely end in the
default port are handled correctly. Lowercase the host to match the SDK's
htu normalization, since the DPoP htu match is an exact string comparison.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Wrap the caller-supplied oauth2.TokenSource in oauth2.ReuseTokenSource so a
valid token is reused across calls instead of re-fetched. AccessToken is on
the request hot path (once per gRPC/Connect call, plus once more to compute
the DPoP ath claim), so an uncached source risked an IdP round-trip on every
request. Wrapping an already-caching source is harmless.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
- transport: fall through on successful nonce retry so a rotated DPoP-Nonce
  is cached instead of dropped by the early return
- transport: normalize htu with EscapedPath to preserve percent-encoded bytes
- dpop_key: reject public-only keys, ES*/RS* family mismatches, and EC
  curve/alg mismatches at resolution time via validateDPoPKey
- sdk: surface conflicting exchange config before the uncredentialed fast-path
- sdk/otdfctl: apply DPoP options during credential validation via
  NewDPoPValidationHTTPClient so pre-flight token requests carry a proof

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
The condition logic is intentionally written to be easily understood by
readers: don't append the port if it matches the default for its scheme.
De Morgan transformation would make this less readable.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
- dpop_transport: don't retry nonce challenge when body is non-replayable
  (streaming/unknown-length body consumed on first attempt); cache the
  nonce and return the original 401 instead of resending an empty body
- sdk: default to an ephemeral ES256/P-256 DPoP key instead of RSA when
  none is configured, matching documented behavior
- dpop_key_test: add regression case for RSA PEM overridden to ES256

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Replace the raw string parameter in WithDPoPAlgorithm with a named
SigningAlgorithm type (RFC 7518 §3.1) and export the six supported
constants (ES256, ES384, ES512, RS256, RS384, RS512) from the sdk
package.

This guides correct use via IDE autocomplete and prevents untyped
string variables from being passed without an explicit cast. Runtime
validation via generateDPoPKeyForAlg's default error case is
unchanged.

Remove the private dpopAlgES*/RS* string constants from dpop_key.go
in favour of the exported type. Update the otdfctl CLI caller to cast
the flag string.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
bufferRequestBody replaced io.ReadAll with a ContentLength-pre-sized
bytes.Buffer read, collapsing io.ReadAll's grow-by-doubling into a single
exact allocation. Behavior is unchanged (ReadFrom still reads to EOF); this
only trims allocation churn on the DPoP replay-buffering path.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…X-3397)

The SDK already enables DPoP by default for any authenticated client, so encrypt,
decrypt, and all policy CRUD commands are sender-constrained without a flag. Remove
the redundant --dpop/--dpop-key flags and their plumbing (dpopSDKOpts, NewHandlerWith,
WithExtraSDKOpts, the extra-opts credential-validation path) and the flag docs.

Align the pre-flight credential validation with the real client: when no DPoP key is
configured, NewDPoPValidationHTTPClient now defaults to an ephemeral ES256 key so the
validation token request is DPoP-bound against a DPoP-enforcing token endpoint.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…PX-3397)

Surface sdk.SupportedFeatures() in the otdfctl `--version --json` output as
`supported_features`, and add the `dpop_nonce_challenge` feature (the DPoP transport
handles RFC 9449 §8 server-issued nonce challenges). This gives the xtest harness a
machine-readable capability signal instead of grepping `--dpop` from help text. The
human `--version` string is unchanged.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
The default DPoP key is an ephemeral ES256 (P-256) key, not an
auto-generated RSA key as the comment previously stated.
- retry DPoP-Nonce challenges on token-endpoint 400, not just 401, so the
  otdfctl validation client works against a nonce-required token endpoint
- normalize the Host header in the Connect interceptor via originFromHost so
  the server's htu comparison matches the SDK's normalized signing input
- preserve the configured HTTP client timeout on the transport's internal
  access-token fetch so a hung IdP cannot stall a request indefinitely
- return an error (was: warn) when DPoP is configured without credentials,
  instead of silently building an unbound client
- otdfctl: print-access-token returns a non-sender-constrained bearer token
  for backward compatibility; credential validation keeps the DPoP-bound
  path. Reusable DPoP export tracked in DSPX-3998

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…o-creds

- token-endpoint 400+DPoP-Nonce triggers a single retry; plain 400 does not
- NewDPoPHTTPClient propagates the base client timeout to the token fetch
- Connect interceptor normalizes a mixed-case host with :443 for htu matching
- buildIDPTokenSource errors when DPoP is set without credentials

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
- NewDPoPHTTPClient validates the token endpoint and returns an error for an
  unparseable value instead of silently misclassifying token requests
- guard a nil DPoPKey in RoundTrip so the zero value returns an error rather
  than nil-panicking
- initialize the nonce cache in the constructor and guard direct construction
  with sync.Once, removing the per-request write-lock
- tests for the nil-key guard and invalid-endpoint rejection

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
- add SigningAlgorithm.Valid backed by a single validDPoPAlgs slice; derive the
  dpopAllowedAlgs error string from it so the enforced set cannot drift
- validateDPoPKey and the PEM algorithm override now consult Valid; the override
  rejects non-DPoP algorithms (e.g. HS256, none) instead of only jwa.Accept
- drop stale 'auto-generated' note from resolveDPoPKey; clarify PEM inference is
  only when unset; remove redundant WithDPoPKeyPEM line and rot-prone otdfctl ref

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Log at debug when originFromHost/normalizeURL fall back to an unnormalized value
so an otherwise inexplicable htu mismatch is traceable.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…y PEM

- parameterize the proof happy-path over RS256/ES256/ES384 so the default EC
  signing path is covered (was RSA-only)
- parseDPoPProof verifies with the key's own algorithm and uses assert+return
  instead of require, which is unsafe off the test goroutine
- assert the OAuth token source dpopPEM is public key material, guarding the
  private-to-public fix against regression

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…riant

Restore the exported GetTokenWithClientCreds to its original 6-parameter signature (plain bearer token, matching main) so the change is not a breaking Go API change. Add GetTokenWithClientCredsDPoP for the DPoP-bound credential-validation path; both delegate to an unexported getTokenWithClientCreds helper.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-3397-platform-go-sdk branch from b63168c to a3e9d1e Compare July 16, 2026 14:49
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 206.677998ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 104.761716ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 416.309284ms
Throughput 240.21 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 38.437832106s
Average Latency 383.719266ms
Throughput 130.08 requests/second

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 193.632311ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 109.645313ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 418.41419ms
Throughput 239.00 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 37.833409607s
Average Latency 377.429694ms
Throughput 132.16 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:sdk A software development kit, including library, for client applications and inter-service communicati size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants