Skip to content

Commit c70cbbb

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 Autoported commit. Original commit hash: [147f3f6e1]
1 parent 658457e commit c70cbbb

File tree

5 files changed

+81
-40
lines changed

5 files changed

+81
-40
lines changed

itext/itext.sign/itext/signatures/IOcspClient.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,26 @@ source product.
4747
namespace iText.Signatures {
4848
/// <summary>Interface for the Online Certificate Status Protocol (OCSP) Client.</summary>
4949
public interface IOcspClient {
50-
/// <summary>Gets an encoded byte array with OCSP validation.</summary>
51-
/// <remarks>Gets an encoded byte array with OCSP validation. The method should not throw an exception.</remarks>
50+
/// <summary>Fetch a DER-encoded BasicOCSPResponse from an OCSP responder.</summary>
51+
/// <remarks>
52+
/// Fetch a DER-encoded BasicOCSPResponse from an OCSP responder. The method should not throw
53+
/// an exception.
54+
/// <para />
55+
/// Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
56+
/// only the DER-encoded BasicOCSPResponse value contained in the response data.
57+
/// </remarks>
5258
/// <param name="checkCert">Certificate to check.</param>
5359
/// <param name="issuerCert">The parent certificate.</param>
5460
/// <param name="url">
55-
/// The url to get the verification. It it's null it will be taken.
56-
/// from the check cert or from other implementation specific source
61+
/// The URL of the OCSP responder endpoint. If null, implementations can
62+
/// attempt to obtain a URL from the AuthorityInformationAccess extension of
63+
/// the certificate, or from another implementation-specific source.
5764
/// </param>
58-
/// <returns>A byte array with the validation or null if the validation could not be obtained</returns>
65+
/// <returns>
66+
/// a byte array containing a DER-encoded BasicOCSPResponse structure or null if one
67+
/// could not be obtained
68+
/// </returns>
69+
/// <seealso><a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a></seealso>
5970
byte[] GetEncoded(X509Certificate checkCert, X509Certificate issuerCert, String url);
6071
}
6172
}

itext/itext.sign/itext/signatures/LtvVerification.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ private X509Certificate GetParent(X509Certificate cert, X509Certificate[] certs)
210210

211211
/// <summary>Adds verification to the signature.</summary>
212212
/// <param name="signatureName">name of the signature</param>
213-
/// <param name="ocsps">collection of ocsp responses</param>
214-
/// <param name="crls">collection of crls</param>
215-
/// <param name="certs">collection of certificates</param>
213+
/// <param name="ocsps">collection of DER-encoded BasicOCSPResponses</param>
214+
/// <param name="crls">collection of DER-encoded CRLs</param>
215+
/// <param name="certs">collection of DER-encoded certificates</param>
216216
/// <returns>boolean</returns>
217217
public virtual bool AddVerification(String signatureName, ICollection<byte[]> ocsps, ICollection<byte[]> crls
218218
, ICollection<byte[]> certs) {

itext/itext.sign/itext/signatures/OcspClientBouncyCastle.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,7 @@ public virtual BasicOcspResp GetBasicOCSPResp(X509Certificate checkCert, X509Cer
101101
return null;
102102
}
103103

104-
/// <summary>Gets an encoded byte array with OCSP validation.</summary>
105-
/// <remarks>Gets an encoded byte array with OCSP validation. The method should not throw an exception.</remarks>
106-
/// <param name="checkCert">to certificate to check</param>
107-
/// <param name="rootCert">the parent certificate</param>
108-
/// <param name="url">
109-
/// to get the verification. It it's null it will be taken
110-
/// from the check cert or from other implementation specific source
111-
/// </param>
112-
/// <returns>a byte array with the validation or null if the validation could not be obtained</returns>
104+
/// <summary><inheritDoc/></summary>
113105
public virtual byte[] GetEncoded(X509Certificate checkCert, X509Certificate rootCert, String url) {
114106
try {
115107
BasicOcspResp basicResponse = GetBasicOCSPResp(checkCert, rootCert, url);

itext/itext.sign/itext/signatures/PdfPKCS7.cs

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,26 @@ public virtual byte[] GetEncodedPKCS7(byte[] secondDigest) {
664664
/// Gets the bytes for the PKCS7SignedData object. Optionally the authenticatedAttributes
665665
/// in the signerInfo can also be set, and/or a time-stamp-authority client
666666
/// may be provided.
667+
/// <para />
668+
/// Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
669+
/// only the DER-encoded BasicOCSPResponse value contained in the response data.
667670
/// </remarks>
668671
/// <param name="secondDigest">the digest in the authenticatedAttributes</param>
669672
/// <param name="tsaClient">TSAClient - null or an optional time stamp authority client</param>
670-
/// <param name="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.
671-
/// </param>
672-
/// <param name="crlBytes">collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
673-
/// </param>
674-
/// <param name="sigtype">specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
675-
/// </param>
673+
/// <param name="ocsp">
674+
/// DER-encoded BasicOCSPResponse for the first certificate in the signature certificates chain,
675+
/// or null if OCSP revocation data is not to be added.
676+
/// </param>
677+
/// <param name="crlBytes">
678+
/// collection of DER-encoded CRL for certificates from the signature certificates chain,
679+
/// or null if CRL revocation data is not to be added.
680+
/// </param>
681+
/// <param name="sigtype">
682+
/// specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere:
683+
/// either basic CMS or CAdES
684+
/// </param>
676685
/// <returns>byte[] the bytes for the PKCS7SignedData object</returns>
686+
/// <seealso><a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a></seealso>
677687
[System.ObsoleteAttribute(@"This overload is deprecated, use GetEncodedPKCS7(byte[], CryptoStandard, ITSAClient, System.Collections.Generic.ICollection{E}, System.Collections.Generic.ICollection{E}) instead."
678688
)]
679689
public virtual byte[] GetEncodedPKCS7(byte[] secondDigest, ITSAClient tsaClient, byte[] ocsp, ICollection<
@@ -687,15 +697,23 @@ public virtual byte[] GetEncodedPKCS7(byte[] secondDigest, ITSAClient tsaClient,
687697
/// Gets the bytes for the PKCS7SignedData object. Optionally the authenticatedAttributes
688698
/// in the signerInfo can also be set, and/or a time-stamp-authority client
689699
/// may be provided.
700+
/// <para />
701+
/// Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
702+
/// only the DER-encoded BasicOCSPResponse value contained in the response data.
690703
/// </remarks>
691704
/// <param name="secondDigest">the digest in the authenticatedAttributes</param>
692705
/// <param name="sigtype">specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
693706
/// </param>
694707
/// <param name="tsaClient">TSAClient - null or an optional time stamp authority client</param>
695-
/// <param name="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.
696-
/// </param>
697-
/// <param name="crlBytes">collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
698-
/// </param>
708+
/// <param name="ocsp">
709+
/// collection of DER-encoded BasicOCSPResponses for the certificate in the signature certificates
710+
/// chain, or null if OCSP revocation data is not to be added.
711+
/// </param>
712+
/// <param name="crlBytes">
713+
/// collection of DER-encoded CRL for certificates from the signature certificates chain,
714+
/// or null if CRL revocation data is not to be added.
715+
/// </param>
716+
/// <seealso><a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a></seealso>
699717
/// <returns>byte[] the bytes for the PKCS7SignedData object</returns>
700718
public virtual byte[] GetEncodedPKCS7(byte[] secondDigest, PdfSigner.CryptoStandard sigtype, ITSAClient tsaClient
701719
, ICollection<byte[]> ocsp, ICollection<byte[]> crlBytes) {
@@ -848,6 +866,9 @@ private Asn1EncodableVector BuildUnauthenticatedAttributes(byte[] timeStampToken
848866
/// exactly the same as in
849867
/// <see cref="GetEncodedPKCS7(byte[])"/>.
850868
/// <para />
869+
/// Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
870+
/// only the DER-encoded BasicOCSPResponse value contained in the response data.
871+
/// <para />
851872
/// A simple example:
852873
/// <pre>
853874
/// Calendar cal = Calendar.getInstance();
@@ -866,13 +887,20 @@ private Asn1EncodableVector BuildUnauthenticatedAttributes(byte[] timeStampToken
866887
/// </pre>
867888
/// </remarks>
868889
/// <param name="secondDigest">the content digest</param>
869-
/// <param name="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.
870-
/// </param>
871-
/// <param name="crlBytes">collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
872-
/// </param>
873-
/// <param name="sigtype">specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
874-
/// </param>
890+
/// <param name="ocsp">
891+
/// collection of DER-encoded BasicOCSPResponses for the certificate in the signature certificates
892+
/// chain, or null if OCSP revocation data is not to be added.
893+
/// </param>
894+
/// <param name="crlBytes">
895+
/// collection of DER-encoded CRL for certificates from the signature certificates chain,
896+
/// or null if CRL revocation data is not to be added.
897+
/// </param>
898+
/// <param name="sigtype">
899+
/// specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere:
900+
/// either basic CMS or CAdES
901+
/// </param>
875902
/// <returns>the byte array representation of the authenticatedAttributes ready to be signed</returns>
903+
/// <seealso><a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a></seealso>
876904
[System.ObsoleteAttribute(@"This method overload is deprecated. Please use GetAuthenticatedAttributeBytes(byte[], CryptoStandard, System.Collections.Generic.ICollection{E}, System.Collections.Generic.ICollection{E})"
877905
)]
878906
public virtual byte[] GetAuthenticatedAttributeBytes(byte[] secondDigest, byte[] ocsp, ICollection<byte[]>
@@ -889,6 +917,9 @@ public virtual byte[] GetAuthenticatedAttributeBytes(byte[] secondDigest, byte[]
889917
/// exactly the same as in
890918
/// <see cref="GetEncodedPKCS7(byte[])"/>.
891919
/// <para />
920+
/// Note: do not pass in the full DER-encoded OCSPResponse object obtained from the responder,
921+
/// only the DER-encoded BasicOCSPResponse value contained in the response data.
922+
/// <para />
892923
/// A simple example:
893924
/// <pre>
894925
/// Calendar cal = Calendar.getInstance();
@@ -907,13 +938,20 @@ public virtual byte[] GetAuthenticatedAttributeBytes(byte[] secondDigest, byte[]
907938
/// </pre>
908939
/// </remarks>
909940
/// <param name="secondDigest">the content digest</param>
910-
/// <param name="sigtype">specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere: either basic CMS or CAdES
911-
/// </param>
912-
/// <param name="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.
913-
/// </param>
914-
/// <param name="crlBytes">collection of DER-encoded CRL for certificates from the signature certificates chain, or null if CRL revocation data is not to be added.
915-
/// </param>
941+
/// <param name="sigtype">
942+
/// specifies the PKCS7 standard flavor to which created PKCS7SignedData object will adhere:
943+
/// either basic CMS or CAdES
944+
/// </param>
945+
/// <param name="ocsp">
946+
/// collection of DER-encoded BasicOCSPResponses for the certificate in the signature certificates
947+
/// chain, or null if OCSP revocation data is not to be added.
948+
/// </param>
949+
/// <param name="crlBytes">
950+
/// collection of DER-encoded CRL for certificates from the signature certificates chain,
951+
/// or null if CRL revocation data is not to be added.
952+
/// </param>
916953
/// <returns>the byte array representation of the authenticatedAttributes ready to be signed</returns>
954+
/// <seealso><a href="https://datatracker.ietf.org/doc/html/rfc6960#section-4.2.1">RFC 6960 § 4.2.1</a></seealso>
917955
public virtual byte[] GetAuthenticatedAttributeBytes(byte[] secondDigest, PdfSigner.CryptoStandard sigtype
918956
, ICollection<byte[]> ocsp, ICollection<byte[]> crlBytes) {
919957
try {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
377d5f5dd9988723b09077fcbc85c35a3df04f73
1+
147f3f6e1532b9dc5244ec8156c5e4c75a191e08

0 commit comments

Comments
 (0)