Package co.ankatech.ankasecure.sdk.security
package co.ankatech.ankasecure.sdk.security
The ANKASecure SDK secure-memory layer.
This package is the single sanctioned place in the SDK and CLI for handling sensitive
material on the client side: cryptographic keys, passwords, JWT bearer tokens, and any
byte[] or char[] that holds secrets after construction.
Public API
Zeroization— null-safe overwrite helpers forbyte[]andchar[], plus best-effortDestroyable.destroy()that swallowsDestroyFailedException.SecretBuffer—AutoCloseablewrapper for an ownedbyte[]. Zeroizes and nulls the field onSecretBuffer.close().SecretChars— same pattern forchar[]. Use for password / passphrase / sensitive char material.BearerToken— JWT holder backed bychar[]with a redactedtoString()(<first6>…[REDACTED]).EnvScrubber— best-effort removal of an env-var entry from the JVM's in-memoryProcessEnvironmentmap after read.
What this layer CAN guarantee
- Caller-owned
byte[]returned byCipher.doFinal(...),SecretKey.getEncoded(), etc., is overwritten with0x00when wrapped inSecretBufferand closed. - Caller-owned
char[]fromSystem.console().readPassword()is space-filled when wrapped inSecretCharsand closed. char[]insidePBEKeySpeccan be cleared viaclearPassword()(used in CLI Slice 5 helpers).- Bouncy Castle
MLKEMPrivateKeySpecandMLDSAPrivateKeycan be passed todestroyIfPossible(Object); both implementDestroyablein BC 1.83.
What this layer CANNOT guarantee
- Bouncy Castle internal byte-array pools (released to the pool and reused without zeroization).
- JCA scratch buffers inside
Cipher.update / doFinal. - JIT register spills and stack-frame retention.
- OkHttp
okio.Buffersegment pool, JVM TLAB / young-gen retention, OS swap / hibernation files, native heap (BC PQC native implementations). Stringinterning and reachability — once secret material is wrapped in aString(e.g., vianew String(charArray)), it cannot be reliably erased. The cutover avoidsStringfor all sensitive material.
See SECURE_MEMORY.md at the SDK root for the complete capability matrix and the
threat model behind these limits.
ArchUnit enforcement
From Slice 7 onwards, ArchUnit rules in
co.ankatech.ankasecure.sdk.architecture.SecurityArchUnitTest fail the build on:
Stringfields with names matchingpassword|secret|token|jwt|bearer| clientSecretoutside this package;SecretKey.getEncoded()invocations outside this package not consumed inside a try-with-resources ofSecretBuffer;- Picocli
@Optionfields of typeStringwith names matchingpassword|secret|token|key.
-
ClassesClassDescriptionHolder for a JWT bearer token represented as
char[]rather thanString, with a redactedBearerToken.toString()so accidental log statements do not leak the token verbatim.Best-effort removal of an environment variable from the JVM's process environment map after the variable has been read.Owning wrapper for a sensitivebyte[].Owning wrapper for a sensitivechar[](typically passwords, passphrases, or other character-secret material returned bySystem.console().readPassword()or by JCA APIs that operate onchar[]).Centralized zeroization helpers for the ANKASecure secure-memory layer.