Class ScepCodec
java.lang.Object
zeroecho.pkix.scep.ScepCodec
BouncyCastle-backed codec for SCEP (RFC 8894) CMS message encoding and decoding.
All operations in this class use BouncyCastle CMS directly; no BouncyCastle
types are exposed in the method signatures so that callers in other modules do not
need a requires org.bouncycastle.* clause.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAuthenticated outer request. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringfailInfo value for badCertId (certificate not found).static final StringfailInfo value for badRequest (challenge password mismatch).static final intMaximum accepted encoded request size, before CMS parsing or decryption.static final intSCEP messageType value for CertRep.static final intSCEP messageType value for GetCert.static final intSCEP messageType value for GetCertInitial.static final intSCEP messageType value for GetCRL.static final intSCEP messageType value for PKCSReq.static final StringpkiStatus value for failure.static final StringpkiStatus value for pending.static final StringpkiStatus value for success. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]buildCertRepFailure(String transactionId, byte[] recipientNonce, String failInfo, X509Certificate raCert, PrivateKey raKey) Builds a SCEP CertRep FAILURE response signed by the RA.static byte[]buildCertRepPending(String transactionId, byte[] recipientNonce, X509Certificate raCert, PrivateKey raKey) Builds a SCEP CertRep PENDING response signed by the RA.static byte[]buildCertRepSuccess(String transactionId, byte[] recipientNonce, byte[] issuedCertDer, X509Certificate requesterCert, X509Certificate raCert, PrivateKey raKey) Builds a SCEP CertRep SUCCESS response signed by the RA.static byte[]buildDegenerateCertsCms(List<byte[]> certsDer) Builds a degenerate CMS certs-onlySignedDatafrom the given DER-encoded certificates.static ScepPkiMessagedecryptRequest(ScepCodec.VerifiedRequest request, X509Certificate raCertificate, PrivateKey raPrivateKey) Decrypts an already verified request using one exact provisioned RA recipient.static StringextractChallengePassword(byte[] csrDer) Extracts the PKCS#9 challengePassword attribute string from a DER-encoded PKCS#10 CSR.static voidrequireIssuerAndSubject(byte[] encoded, X500Principal issuer, X500Principal subject) Validates an IssuerAndSubject poll against the frozen issuer and original CSR.static ScepCodec.VerifiedRequestverifyRequest(byte[] cmsDer) Verifies a bounded CMS request before any private-key decryption.
-
Field Details
-
MSG_PKCS_REQ
public static final int MSG_PKCS_REQSCEP messageType value for PKCSReq.- See Also:
-
MSG_CERT_REP
public static final int MSG_CERT_REPSCEP messageType value for CertRep.- See Also:
-
MSG_GET_CERT_INITIAL
public static final int MSG_GET_CERT_INITIALSCEP messageType value for GetCertInitial.- See Also:
-
MSG_GET_CERT
public static final int MSG_GET_CERTSCEP messageType value for GetCert.- See Also:
-
MSG_GET_CRL
public static final int MSG_GET_CRLSCEP messageType value for GetCRL.- See Also:
-
STATUS_SUCCESS
-
STATUS_FAILURE
-
STATUS_PENDING
-
FAIL_BAD_REQUEST
failInfo value for badRequest (challenge password mismatch).- See Also:
-
FAIL_BAD_CERT_ID
failInfo value for badCertId (certificate not found).- See Also:
-
MAXIMUM_REQUEST_BYTES
public static final int MAXIMUM_REQUEST_BYTESMaximum accepted encoded request size, before CMS parsing or decryption.- See Also:
-
-
Method Details
-
verifyRequest
Verifies a bounded CMS request before any private-key decryption. Requires one signer and one matching certificate, SHA-256/RSA, authenticated id-data content, and strictly typed singular SCEP attributes. Certificate possession is proven; identity authorization is the caller's job.- Parameters:
cmsDer- complete encoded CMS message- Returns:
- authenticated outer envelope
- Throws:
ScepCodecException- for malformed or unsupported messages or invalid signatures
-
decryptRequest
public static ScepPkiMessage decryptRequest(ScepCodec.VerifiedRequest request, X509Certificate raCertificate, PrivateKey raPrivateKey) throws ScepCodecException Decrypts an already verified request using one exact provisioned RA recipient. Requires AES-128-CBC, RSA key transport, and exactly one matching recipient; there is no trial decryption or fallback to another credential.- Parameters:
request- authenticated enveloperaCertificate- exact provisioned recipient certificateraPrivateKey- matching private key borrowed under its custody lease- Returns:
- verified attributes and independently owned plaintext request
- Throws:
ScepCodecException- for an invalid envelope, recipient or decryption
-
requireIssuerAndSubject
public static void requireIssuerAndSubject(byte[] encoded, X500Principal issuer, X500Principal subject) throws ScepCodecException Validates an IssuerAndSubject poll against the frozen issuer and original CSR.- Parameters:
encoded- exact decrypted pollissuer- frozen issuing CA subjectsubject- original CSR subject- Throws:
ScepCodecException- if either name differs or the encoding is malformed
-
extractChallengePassword
Extracts the PKCS#9 challengePassword attribute string from a DER-encoded PKCS#10 CSR. Returnsnullif the attribute is absent.- Parameters:
csrDer- DER-encoded PKCS#10 CSR- Returns:
- challengePassword string, or
nullif absent - Throws:
ScepCodecException- if the CSR cannot be parsed
-
buildCertRepSuccess
public static byte[] buildCertRepSuccess(String transactionId, byte[] recipientNonce, byte[] issuedCertDer, X509Certificate requesterCert, X509Certificate raCert, PrivateKey raKey) throws ScepCodecException Builds a SCEP CertRep SUCCESS response signed by the RA.The inner content is a CMS
EnvelopedDatawrapping a degenerateSignedDatacontaining the issued certificate, encrypted for the requester's certificate (from the original PKCSReq message).- Parameters:
transactionId- SCEP transaction identifier from the requestrecipientNonce- senderNonce from the request (becomes recipientNonce in response)issuedCertDer- DER-encoded issued certificaterequesterCert- requester's certificate (for encrypting the response)raCert- RA signing certificateraKey- RA private key for signing- Returns:
- DER-encoded CMS SignedData CertRep
- Throws:
ScepCodecException- if encoding fails
-
buildCertRepFailure
public static byte[] buildCertRepFailure(String transactionId, byte[] recipientNonce, String failInfo, X509Certificate raCert, PrivateKey raKey) throws ScepCodecException Builds a SCEP CertRep FAILURE response signed by the RA.- Parameters:
transactionId- SCEP transaction identifier from the requestrecipientNonce- senderNonce from the requestfailInfo- SCEP failInfo value string (e.g., "2" for badRequest)raCert- RA signing certificateraKey- RA private key for signing- Returns:
- DER-encoded CMS SignedData CertRep
- Throws:
ScepCodecException- if encoding fails
-
buildCertRepPending
public static byte[] buildCertRepPending(String transactionId, byte[] recipientNonce, X509Certificate raCert, PrivateKey raKey) throws ScepCodecException Builds a SCEP CertRep PENDING response signed by the RA.- Parameters:
transactionId- SCEP transaction identifier from the requestrecipientNonce- senderNonce from the requestraCert- RA signing certificateraKey- RA private key for signing- Returns:
- DER-encoded CMS SignedData CertRep
- Throws:
ScepCodecException- if encoding fails
-
buildDegenerateCertsCms
Builds a degenerate CMS certs-onlySignedDatafrom the given DER-encoded certificates. Used for GetCACert and GetCACertChain responses.- Parameters:
certsDer- list of DER-encoded certificates in presentation order- Returns:
- DER-encoded CMS
ContentInfowrappingSignedData - Throws:
ScepCodecException- if encoding fails
-