Class CmpProtectedMessage
java.lang.Object
zeroecho.pkix.cmp.CmpProtectedMessage
Immutable bounded CMP request with exact canonical protected bytes. Parsing
grants no authentication; only a successful verification creates
CmpProtectedMessage.Verified.
A verified proof still grants no certificate trust, ownership or RA authority.
The server must apply those policies separately before any durable mutation.
Supports singular ir/cr/kur, rr, caCerts genm, pollReq and certConf requests under CMP versions 2 and 3. Signature protection supports RSA 2048..8192 with SHA-256/384/512 and named P-256/P-384/P-521 ECDSA with those digests. PSS, explicit EC and alternative protection modes are rejected without fallback.
Parsing and owned memory are O(N), bounded by one MiB and 64 ASN.1 levels. PBM work is O(I + N), for configured bounded iterations I; no secret is retained. Instances are thread-safe; callers exclusively own every returned byte array.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable unsigned response bound to one verified request.static final classImmutable proof token constructed only after exact message protection verification. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum supported request certificate candidates.static final intMaximum complete incoming message size. -
Method Summary
Modifier and TypeMethodDescriptionintbodyType()Returns the CMP body tag.static byte[]certificateConfirmationHash(byte[] certificateDer) Computes the CMP certificate-confirmation hash using the hash component of a supported RSA or ECDSA certificate signature.static byte[]certificateConfirmationHash(byte[] certificateDer, Optional<String> explicitDigest) Hashes an exact certificate for confirmation.static byte[]certificateKeyId(X509Certificate certificate) Returns the exact certificate key identifier used by signature protection.Optional<byte[]> Returns the exact original CertReqMsg, when this is an enrollment request.booleanReturns whether a certConf accepts rather than rejects the certificate.Optional<byte[]> Returns a defensive confirmation hash, when this is certConf.Returns the explicit RFC 9480 confirmation hash name, present only in version-three certConf.byte[]encoded()Returns a defensive copy of the complete canonical request.List<byte[]> Returns untrusted certificate candidates; these are outside the protected bytes.booleanisPbm()Returns whether the declared protection mode is standard PBM; not proof validity.Returns the optional sender time; the server applies its freshness policy.static CmpProtectedMessageparse(byte[] der) Parses exactly one canonical DER request and the closed supported grammar.Returns the recipient's immutable distinguished name.Optional<byte[]> Returns the optional defensive recipient key identifier for exact credential selection.Optional<byte[]> Returns the optional defensive recipient nonce.Returns the bounded request ID, or zero for requests without a CertReqId.booleanReturns whether this enrollment explicitly requested implicit confirmation.intReturns the requested permanent revocation reason, or unspecified zero.Returns the immutable revocation reference, when this is rr.sender()Returns the sender's immutable distinguished name.Optional<byte[]> Returns the optional defensive sender key identifier.byte[]Returns a defensive sender nonce.toString()Returns a redacted diagnostic representation.byte[]Returns a defensive transaction identifier.verifyPbm(CmpPbmPolicy policy, byte[] secret, CancellationSignal cancellation) Verifies binary-secret PBM after validating all work and algorithm bounds.verifySignature(X509Certificate certificate) Verifies the exact protected bytes using one explicitly selected certificate.
-
Field Details
-
MAXIMUM_MESSAGE_BYTES
public static final int MAXIMUM_MESSAGE_BYTESMaximum complete incoming message size.- See Also:
-
MAXIMUM_EXTRA_CERTIFICATES
public static final int MAXIMUM_EXTRA_CERTIFICATESMaximum supported request certificate candidates.- See Also:
-
-
Method Details
-
parse
Parses exactly one canonical DER request and the closed supported grammar. Unknown fields, multiple requests, missing protection and trailing data fail.- Parameters:
der- bounded caller-owned message, defensively copied- Returns:
- immutable unauthenticated message
- Throws:
IllegalArgumentException- if the message is malformed or unsupported
-
encoded
public byte[] encoded()Returns a defensive copy of the complete canonical request.- Returns:
- a defensive copy of the complete canonical request
-
bodyType
public int bodyType()Returns the CMP body tag.- Returns:
- the CMP body tag
-
requestId
Returns the bounded request ID, or zero for requests without a CertReqId.- Returns:
- the bounded request ID, or zero for requests without a CertReqId
-
certificationRequest
Returns the exact original CertReqMsg, when this is an enrollment request.- Returns:
- the exact original CertReqMsg, when this is an enrollment request
-
revokedCertificate
Returns the immutable revocation reference, when this is rr.- Returns:
- the immutable revocation reference, when this is rr
-
revocationReason
public int revocationReason()Returns the requested permanent revocation reason, or unspecified zero.- Returns:
- the requested permanent revocation reason, or unspecified zero
-
confirmationHash
Returns a defensive confirmation hash, when this is certConf.- Returns:
- a defensive confirmation hash, when this is certConf
-
confirmationHashAlgorithm
-
confirmationAccepted
public boolean confirmationAccepted()Returns whether a certConf accepts rather than rejects the certificate.- Returns:
- whether a certConf accepts rather than rejects the certificate
-
requestsImplicitConfirmation
public boolean requestsImplicitConfirmation()Returns whether this enrollment explicitly requested implicit confirmation.- Returns:
- whether this enrollment explicitly requested implicit confirmation
-
isPbm
public boolean isPbm()Returns whether the declared protection mode is standard PBM; not proof validity.- Returns:
- whether the declared protection mode is standard PBM; not proof validity
-
transactionId
public byte[] transactionId()Returns a defensive transaction identifier.- Returns:
- a defensive transaction identifier
-
senderNonce
public byte[] senderNonce()Returns a defensive sender nonce.- Returns:
- a defensive sender nonce
-
recipientNonce
Returns the optional defensive recipient nonce.- Returns:
- the optional defensive recipient nonce
-
senderKid
Returns the optional defensive sender key identifier.- Returns:
- the optional defensive sender key identifier
-
recipientKid
Returns the optional defensive recipient key identifier for exact credential selection.- Returns:
- the optional defensive recipient key identifier for exact credential selection
-
sender
Returns the sender's immutable distinguished name.- Returns:
- the sender's immutable distinguished name
-
recipient
Returns the recipient's immutable distinguished name.- Returns:
- the recipient's immutable distinguished name
-
messageTime
-
extraCertificates
Returns untrusted certificate candidates; these are outside the protected bytes.- Returns:
- immutable list of defensive certificate DER arrays
-
certificateKeyId
Returns the exact certificate key identifier used by signature protection. A present subjectKeyIdentifier extension takes precedence and must contain one through 128 bytes. If absent, SHA-256 of the exact encoded SPKI is used. This identifier is only a routing constraint, never a trust assertion.- Parameters:
certificate- selected certificate- Returns:
- caller-owned key identifier
- Throws:
IllegalArgumentException- if the extension or public key is malformed
-
certificateConfirmationHash
public static byte[] certificateConfirmationHash(byte[] certificateDer) Computes the CMP certificate-confirmation hash using the hash component of a supported RSA or ECDSA certificate signature. RSA-PSS uses its explicit digest parameters. This operation does not verify certificate trust.- Parameters:
certificateDer- exact issued DER certificate, at most one MiB- Returns:
- defensive SHA-256, SHA-384 or SHA-512 digest
- Throws:
IllegalArgumentException- if the certificate or digest selection is unsupported
-
certificateConfirmationHash
public static byte[] certificateConfirmationHash(byte[] certificateDer, Optional<String> explicitDigest) Hashes an exact certificate for confirmation. RSA, ECDSA and RSA-PSS use their signature digest and any explicit choice must agree. Supported signatures without an encoded digest require an explicit SHA-256, SHA-384 or SHA-512 choice from a version-three certConf message. This operation does not establish certificate trust or protocol authentication.- Parameters:
certificateDer- exact DER certificate, at most one MiBexplicitDigest- validated confirmation hash name, if supplied- Returns:
- digest of the complete original certificate DER
- Throws:
IllegalArgumentException- for malformed, inconsistent or unsupported input
-
verifySignature
Verifies the exact protected bytes using one explicitly selected certificate. Checks its key strength and algorithm grammar; trust, usage, validity, sender binding and authority remain the caller's responsibility.- Parameters:
certificate- externally selected candidate, never an implicit trust anchor- Returns:
- unforgeable proof token for this exact message
- Throws:
IllegalArgumentException- if mode, algorithm or signature is invalid
-
verifyPbm
public CmpProtectedMessage.Verified verifyPbm(CmpPbmPolicy policy, byte[] secret, CancellationSignal cancellation) Verifies binary-secret PBM after validating all work and algorithm bounds. Secret bytes are never interpreted as characters or retained by the token.- Parameters:
policy- explicit configured boundssecret- caller-owned 32..128 bytes, copied and never modifiedcancellation- cooperative signal checked during iterative derivation- Returns:
- proof token for this exact message
- Throws:
IllegalArgumentException- if bounds, mode, protection or cancellation fail
-
toString
-