Skip to content

Test Java encrypted compiled-model inference - #33217

Draft
Gopalakrishnan Nallasamy (GopalakrishnanN) wants to merge 7 commits into
mainfrom
GopalakrishnanN/test-encrypted-epcontext-java
Draft

Gopalakrishnan Nallasamy (GopalakrishnanN) wants to merge 7 commits into
mainfrom
GopalakrishnanN/test-encrypted-epcontext-java

Conversation

@GopalakrishnanN

@GopalakrishnanN Gopalakrishnan Nallasamy (GopalakrishnanN) commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a Java integration test for compile -> AES-GCM encrypt/store -> decrypt/load -> numerical inference with real external EPContext data.

  • Test two input sets and authentication/payload failure controls.
  • External context is persisted only as ciphertext.
  • Release compilation state before restored inference.

Java limitation: the compilation API only exposes model file output. The test temporarily writes plaintext compiled ONNX, then encrypts and deletes it before loading. This does not prove no-plaintext-at-any-time for the compiled ONNX model.

Depends on shared fixture #33216 and includes its identical prerequisite commit; merge #33216 first. Draft pending CI/review. Local test is Windows-gated.

Review follow-up

Reuse one SecureRandom for test keys and nonces. Clarify temporary plaintext model-file compilation in Java and pending companion availability. All branches also contain the shared generator import fix, native fixture regression, and qualified companion documentation.

October 23 approved-review follow-up

Load the shared two-input ONNX fixture directly, add persisted authenticated-but-invalid context through the real decrypt/read callback, and use JUnit tempdir for exception-safe cleanup.

Validation: From java, with an isolated JAVA_TOOL_OPTIONS=-Djava.io.tmpdir=<session-temp> and the matching API31 staged runtime: gradlew.bat --no-daemon --offline -DcmakeBuildDir=<matching-native-build> spotlessJavaCheck test --tests ai.onnxruntime.EncryptedEpContextTest --tests ai.onnxruntime.CompileApiTest.externalEpContextDataUsesCallbacks: 2 passed, zero skipped. Existing protobuf generated-code and Gradle deprecation warnings remain. The isolated temp directory avoids a pre-existing fallback context left in the shared system temp directory.

The shared fixture corrections are included on all six approved branches. git diff --check passed. Updated-head CI is pending; no old-head results are claimed for these changes.

Motivation and Context

Follow-up to #32265 and Java binding #32305. Existing callback tests lacked encrypted compiled-state inference.

Local validation (from java, using JNI rebuilt from source and matching staged native artifacts):

.\gradlew.bat --no-daemon --offline -DcmakeBuildDir=C:\Users\gnallasamy\Codes\ort-encryption-471c3cdf\build\Encryption spotlessJavaApply test --tests ai.onnxruntime.EncryptedEpContextTest --tests ai.onnxruntime.CompileApiTest.externalEpContextDataUsesCallbacks

Result: 2 passed, zero skips; Java source/JNI build passed. git diff --check passed. Publication branch cleanly cherry-picked onto current main; full current-main rebuild not run locally.

Not covered: Apple/mobile execution, production provider binaries, external initializer encryption.

Gopalakrishnan Nallasamy and others added 2 commits October 8, 2026 14:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread java/src/test/java/ai/onnxruntime/EncryptedEpContextTest.java Fixed
Comment thread java/src/test/java/ai/onnxruntime/EncryptedEpContextTest.java Fixed
Comment thread onnxruntime/test/testdata/encrypted_ep_context_mul.py Fixed

Copilot AI 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.

🟡 Changes recommended

The documentation contains an unconditional plaintext claim and references four tests not present in this branch.

2 open findings
What changed in this PR

Adds Java end-to-end validation for encrypted compiled-model and external EPContext inference using the example plugin EP.

Changes:

  • Adds an executable two-input Mul EPContext fixture.
  • Tests AES-GCM persistence, restoration, inference, and rejection cases.
  • Documents cross-binding encryption workflows.
File Description
.gitignore Allows the generated ONNX fixture.
onnxruntime/​test/​testdata/​encrypted_ep_context_mul.py Generates the shared Mul model.
onnxruntime/​test/​testdata/​encrypted_ep_context_mul.onnx Provides the generated fixture.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep.h Adds restored EPContext execution state.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep.cc Serializes and executes the test Mul descriptor.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep_factory.cc Parses the opt-in execution setting.
java/​src/​test/​java/​ai/​onnxruntime/​EncryptedEpContextTest.java Adds encrypted compile/load/inference coverage.
docs/​design/​Compiled_Model_Encryption.md Documents binding tests and commands.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/design/Compiled_Model_Encryption.md
Comment thread docs/design/Compiled_Model_Encryption.md Outdated
Gopalakrishnan Nallasamy and others added 3 commits October 8, 2026 15:32
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the existing unordered-map overload explicitly so GCC and Clang do not have to choose between the map and parallel-vector options overloads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@GopalakrishnanN

Copy link
Copy Markdown
Contributor Author

Fixed the common fixture compiler ambiguity by explicitly selecting the unordered-map provider-options overload (f8e377d). Corrected call passed MSVC C++17 /W4 /WX syntax validation. New-head CI is running; superseded old-head Windows jobs were not manually rerun.

@tianleiwu Tianlei Wu (tianleiwu) 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.

LGTM overall! Clean Java integration test covering EPContext write/read callbacks with AES-GCM encryption, restored multi-iteration inference, and authentication failure checks. Verified spotlessJavaCheck and compileTestJava locally.

Left a couple of non-blocking suggestions inline (adding an authenticated-but-invalid payload check and simplifying temp directory cleanup / fixture loading).

Comment thread java/src/test/java/ai/onnxruntime/EncryptedEpContextTest.java
Comment thread java/src/test/java/ai/onnxruntime/EncryptedEpContextTest.java
Comment thread java/src/test/java/ai/onnxruntime/EncryptedEpContextTest.java Outdated
Gopalakrishnan Nallasamy and others added 2 commits October 23, 2026 12:49
Validate boolean options consistently, defer kernel registration until context creation succeeds, clarify restricted execution and companion availability, and remove redundant ignore exception.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Delegate temporary-directory cleanup to JUnit and verify decrypted malformed payload reaches the EP validation path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

4 participants