Skip to content

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

Draft
dmihalcik-virtru wants to merge 3 commits into
mainfrom
DSPX-3397-platform-go-sdk
Draft

feat(sdk): add DPoP client support with HTTP RoundTripper (DSPX-3397)#3581
dmihalcik-virtru wants to merge 3 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.

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

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ef0bb1ab-bb71-4b22-9417-7f8afc81c6fd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 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 and usage tips.

@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
Comment thread sdk/auth/dpop_transport.go Outdated
Comment on lines +47 to +57
if t.Base == nil {
t.Base = http.DefaultTransport
}

if t.nonceCache == nil {
t.nonceMu.Lock()
if t.nonceCache == nil {
t.nonceCache = make(map[string]string)
}
t.nonceMu.Unlock()
}

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.

high

Concurrency Data Race on t.Base and t.nonceCache

Concurrently modifying t.Base and performing a double-checked lock read on t.nonceCache without synchronization can lead to data races when multiple goroutines use the same DPoPTransport instance.

To resolve this:

  1. Use a local variable base instead of modifying the struct field t.Base.
  2. Perform the initialization of t.nonceCache under an unconditional lock to avoid the data race on the initial read.
	base := t.Base
	if base == nil {
		base = http.DefaultTransport
	}

	t.nonceMu.Lock()
	if t.nonceCache == nil {
		t.nonceCache = make(map[string]string)
	}
	t.nonceMu.Unlock()

Comment thread sdk/auth/dpop_transport.go Outdated
nonce := t.getCachedNonce(origin)

// Generate and add DPoP proof
if err := t.addDPoPProof(req2, nonce, isTokenRequest); err != nil {

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.

high

Pass the local base transport to addDPoPProof to avoid concurrent read/write data races on t.Base.

Suggested change
if err := t.addDPoPProof(req2, nonce, isTokenRequest); err != nil {
if err := t.addDPoPProof(req2, base, nonce, isTokenRequest); err != nil {

Comment thread sdk/auth/dpop_transport.go Outdated
}

// Make the request
resp, err := t.Base.RoundTrip(req2)

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.

high

Use the local base variable to avoid data races on t.Base.

Suggested change
resp, err := t.Base.RoundTrip(req2)
resp, err := base.RoundTrip(req2)

Comment thread sdk/auth/dpop_transport.go Outdated
req3 := cloneRequest(req)

// Regenerate proof with nonce
if err := t.addDPoPProof(req3, newNonce, isTokenRequest); err != nil {

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.

high

Pass the local base transport to addDPoPProof to avoid concurrent read/write data races on t.Base.

Suggested change
if err := t.addDPoPProof(req3, newNonce, isTokenRequest); err != nil {
if err := t.addDPoPProof(req3, base, newNonce, isTokenRequest); err != nil {

Comment thread sdk/auth/dpop_transport.go Outdated
}

// addDPoPProof generates and adds DPoP proof to the request headers.
func (t *DPoPTransport) addDPoPProof(req *http.Request, nonce string, isTokenRequest bool) error {

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.

high

Update the signature of addDPoPProof to accept the base transport.

Suggested change
func (t *DPoPTransport) addDPoPProof(req *http.Request, nonce string, isTokenRequest bool) error {
func (t *DPoPTransport) addDPoPProof(req *http.Request, base http.RoundTripper, nonce string, isTokenRequest bool) error {

Comment thread sdk/auth/dpop_transport.go
Comment thread sdk/auth/dpop_transport.go Outdated
Comment on lines +40 to +42
nonceMu sync.RWMutex
// nonceCache stores server-issued nonces by origin (scheme://host:port)
nonceCache map[string]string

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.

medium

Optimize Token Endpoint URL Parsing (Struct Fields)

Add cached fields for the parsed token endpoint URL to avoid parsing it on every request.

	nonceMu sync.RWMutex
	// nonceCache stores server-issued nonces by origin (scheme://host:port)
	nonceCache map[string]string

	cachedTokenURL    *url.URL
	cachedTokenURLStr string

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 and others added 3 commits June 11, 2026 13:47
Implements RFC 9449 DPoP (Demonstrating Proof-of-Possession) for the Go SDK:

- Add DPoPTransport as an http.RoundTripper that wraps any transport
- Generate ES256/RS256 proofs with jti, htm, htu, iat claims for all requests
- Add ath claim (access token hash) for resource endpoint calls
- Handle server-issued DPoP-Nonce challenges with automatic retry
- Cache nonces per-origin and refresh from successful responses
- Normalize URIs per RFC 9449 (lowercase scheme/host, strip default ports)
- Integrate into SDK's HTTP client construction via NewDPoPHTTPClient
- Add SupportedFeatures() function for xtest feature detection

All requests through the SDK now include DPoP proofs when credentials are
configured. Token endpoint requests omit the ath claim; resource requests
include both Authorization: DPoP <token> header and the DPoP proof header.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…PX-3397)

Exposes DPoP algorithm/key selection via CLI flags on `otdfctl encrypt`
and `otdfctl decrypt`, supporting ES256 (default), ES384, ES512, RS256,
RS384, and RS512. Bare `--dpop` defaults to ES256 per RFC 9449 §4.2.
`--dpop-key <path>` loads a PEM private key (algorithm inferred from key
type). Both flags can be combined to override the inferred algorithm.

SDK changes:
- Add sdk/dpop_key.go: generateDPoPKeyForAlg, loadDPoPKeyFromPEM,
  resolveDPoPKey helpers
- Add WithDPoPAlgorithm, WithDPoPKeyPEM, WithDPoPJWK SDK options
- Thread custom JWK through buildIDPTokenSource and DPoPTransport setup;
  falls back to auto-generated RSA when no custom key is configured
- Add JWK-accepting token source constructors for all four source types

otdfctl changes:
- Register --dpop (NoOptDefVal="ES256") and --dpop-key flags on
  encrypt/decrypt; update man docs accordingly
- handlers.WithExtraSDKOpts appends (not replaces) SDK options
- common.NewHandler accepts variadic extraSDKOpts (backward compatible)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Fixes critical and high-priority issues identified in PR review:
- Fix request body consumed on retry: reset body using GetBody() before retrying
- Fix data races: use local base variable instead of modifying t.Base
- Fix nonce cache initialization: unconditional lock instead of double-checked lock
- Fix missing HTTP client for token source: pass client with base transport to preserve custom configs
- Optimize token endpoint URL parsing: cache parsed URL to avoid parsing on every request
- Normalize origin casing: lowercase origin in cache to ensure consistent hits on uppercase URLs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • lib/fixtures

See the workflow run for details.

@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

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.

1 participant