Skip to content

Commit 147f3f6

Browse files
MatthiasValvekensiText-CI
authored andcommitted
Fix some confusing Javadoc about OCSP
A number of methods that expect to be passed a DER-encoded BasicOCSPResponse had confusing Javadoc suggesting that they expect a full OCSPResponse structure, but do not do any sanity checking. This causes iText to output botched ASN.1 structures without informing the user. RES-382
1 parent 377d5f5 commit 147f3f6

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

sign/src/main/java/com/itextpdf/signatures/IOcspClient.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,21 @@ This file is part of the iText (R) project.
5151
public interface IOcspClient {
5252

5353
/**
54-
* Gets an encoded byte array with OCSP validation. The method should not throw an exception.
54+
* Fetch a DER-encoded BasicOCSPResponse from an OCSP responder. The method should not throw
55+
* an exception.
56+
*
57+
* <p>
58+
* Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
59+
* only the DER-encoded BasicOCSPResponse value contained in the response data.
5560
*
5661
* @param checkCert Certificate to check.
5762
* @param issuerCert The parent certificate.
58-
* @param url The url to get the verification. It it's null it will be taken.
59-
* from the check cert or from other implementation specific source
60-
* @return A byte array with the validation or null if the validation could not be obtained
63+
* @param url The URL of the OCSP responder endpoint. If null, implementations can
64+
* attempt to obtain a URL from the AuthorityInformationAccess extension of
65+
* the certificate, or from another implementation-specific source.
66+
* @return a byte array containing a DER-encoded BasicOCSPResponse structure or null if one
67+
* could not be obtained
68+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a>
6169
*/
6270
byte[] getEncoded(X509Certificate checkCert, X509Certificate issuerCert, String url);
6371
}

sign/src/main/java/com/itextpdf/signatures/LtvVerification.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ private X509Certificate getParent(X509Certificate cert, Certificate[] certs) {
269269
* Adds verification to the signature.
270270
*
271271
* @param signatureName name of the signature
272-
* @param ocsps collection of ocsp responses
273-
* @param crls collection of crls
274-
* @param certs collection of certificates
272+
* @param ocsps collection of DER-encoded BasicOCSPResponses
273+
* @param crls collection of DER-encoded CRLs
274+
* @param certs collection of DER-encoded certificates
275275
* @return boolean
276276
* @throws IOException signals that an I/O exception has occurred
277277
* @throws GeneralSecurityException when requested cryptographic algorithm or security provider

sign/src/main/java/com/itextpdf/signatures/OcspClientBouncyCastle.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ public BasicOCSPResp getBasicOCSPResp(X509Certificate checkCert, X509Certificate
121121
}
122122

123123
/**
124-
* Gets an encoded byte array with OCSP validation. The method should not throw an exception.
125-
*
126-
* @param checkCert to certificate to check
127-
* @param rootCert the parent certificate
128-
* @param url to get the verification. It it's null it will be taken
129-
* from the check cert or from other implementation specific source
130-
* @return a byte array with the validation or null if the validation could not be obtained
124+
* {@inheritDoc}
131125
*/
132126
@Override
133127
public byte[] getEncoded(X509Certificate checkCert, X509Certificate rootCert, String url) {

sign/src/main/java/com/itextpdf/signatures/PdfPKCS7.java

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,20 @@ public byte[] getEncodedPKCS7(byte[] secondDigest) {
798798
* in the signerInfo can also be set, and/or a time-stamp-authority client
799799
* may be provided.
800800
*
801+
* <p>
802+
* Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
803+
* only the DER-encoded BasicOCSPResponse value contained in the response data.
804+
*
801805
* @param secondDigest the digest in the authenticatedAttributes
802806
* @param tsaClient TSAClient - null or an optional time stamp authority client
803-
* @param ocsp DER-encoded OCSP response for the first certificate in the signature certificates chain, or null if OCSP revocation data is not to be added.
804-
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
805-
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
807+
* @param ocsp DER-encoded BasicOCSPResponse for the first certificate in the signature certificates chain,
808+
* or null if OCSP revocation data is not to be added.
809+
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain,
810+
* or null if CRL revocation data is not to be added.
811+
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere:
812+
* either basic CMS or CAdES
806813
* @return byte[] the bytes for the PKCS7SignedData object
814+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a>
807815
* @deprecated This overload is deprecated, use {@link #getEncodedPKCS7(byte[], PdfSigner.CryptoStandard, ITSAClient, Collection, Collection)} instead.
808816
*/
809817
@Deprecated
@@ -816,11 +824,18 @@ public byte[] getEncodedPKCS7(byte[] secondDigest, ITSAClient tsaClient, byte[]
816824
* in the signerInfo can also be set, and/or a time-stamp-authority client
817825
* may be provided.
818826
*
827+
* <p>
828+
* Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
829+
* only the DER-encoded BasicOCSPResponse value contained in the response data.
830+
*
819831
* @param secondDigest the digest in the authenticatedAttributes
820832
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
821833
* @param tsaClient TSAClient - null or an optional time stamp authority client
822-
* @param ocsp collection of DER-encoded OCSP responses for the certificate in the signature certificates chain, or null if OCSP revocation data is not to be added.
823-
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
834+
* @param ocsp collection of DER-encoded BasicOCSPResponses for the certificate in the signature certificates
835+
* chain, or null if OCSP revocation data is not to be added.
836+
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain,
837+
* or null if CRL revocation data is not to be added.
838+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a>
824839
* @return byte[] the bytes for the PKCS7SignedData object
825840
*/
826841
public byte[] getEncodedPKCS7(byte[] secondDigest, PdfSigner.CryptoStandard sigtype, ITSAClient tsaClient, Collection<byte[]> ocsp, Collection<byte[]> crlBytes) {
@@ -978,6 +993,12 @@ private ASN1EncodableVector buildUnauthenticatedAttributes(byte[] timeStampToken
978993
* The document digest is generated and put inside the attribute. The signing is done over the DER encoded
979994
* authenticatedAttributes. This method provides that encoding and the parameters must be
980995
* exactly the same as in {@link #getEncodedPKCS7(byte[])}.
996+
*
997+
* <p>
998+
* Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
999+
* only the DER-encoded BasicOCSPResponse value contained in the response data.
1000+
*
1001+
*
9811002
* <p>
9821003
* A simple example:
9831004
* <pre>
@@ -997,10 +1018,14 @@ private ASN1EncodableVector buildUnauthenticatedAttributes(byte[] timeStampToken
9971018
* </pre>
9981019
*
9991020
* @param secondDigest the content digest
1000-
* @param ocsp collection of DER-encoded OCSP responses for the certificate in the signature certificates chain, or null if OCSP revocation data is not to be added.
1001-
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
1002-
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
1021+
* @param ocsp collection of DER-encoded BasicOCSPResponses for the certificate in the signature certificates
1022+
* chain, or null if OCSP revocation data is not to be added.
1023+
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain,
1024+
* or null if CRL revocation data is not to be added.
1025+
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere:
1026+
* either basic CMS or CAdES
10031027
* @return the byte array representation of the authenticatedAttributes ready to be signed
1028+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a>
10041029
* @deprecated This method overload is deprecated. Please use {@link #getAuthenticatedAttributeBytes(byte[], PdfSigner.CryptoStandard, Collection, Collection)}
10051030
*/
10061031
@Deprecated
@@ -1013,6 +1038,11 @@ public byte[] getAuthenticatedAttributeBytes(byte[] secondDigest, byte[] ocsp, C
10131038
* The document digest is generated and put inside the attribute. The signing is done over the DER encoded
10141039
* authenticatedAttributes. This method provides that encoding and the parameters must be
10151040
* exactly the same as in {@link #getEncodedPKCS7(byte[])}.
1041+
*
1042+
* <p>
1043+
* Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
1044+
* only the DER-encoded BasicOCSPResponse value contained in the response data.
1045+
*
10161046
* <p>
10171047
* A simple example:
10181048
* <pre>
@@ -1032,10 +1062,14 @@ public byte[] getAuthenticatedAttributeBytes(byte[] secondDigest, byte[] ocsp, C
10321062
* </pre>
10331063
*
10341064
* @param secondDigest the content digest
1035-
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
1036-
* @param ocsp collection of DER-encoded OCSP responses for the certificate in the signature certificates chain, or null if OCSP revocation data is not to be added.
1037-
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
1065+
* @param sigtype specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere:
1066+
* either basic CMS or CAdES
1067+
* @param ocsp collection of DER-encoded BasicOCSPResponses for the certificate in the signature certificates
1068+
* chain, or null if OCSP revocation data is not to be added.
1069+
* @param crlBytes collection of DER-encoded CRL for certificates from the signature certificates chain,
1070+
* or null if CRL revocation data is not to be added.
10381071
* @return the byte array representation of the authenticatedAttributes ready to be signed
1072+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a>
10391073
*/
10401074
public byte[] getAuthenticatedAttributeBytes(byte[] secondDigest, PdfSigner.CryptoStandard sigtype, Collection<byte[]> ocsp, Collection<byte[]> crlBytes) {
10411075
try {

0 commit comments

Comments
 (0)