Top Description Inners Fields Constructors Methods
org.apache.pdfbox.examples.signature.validation

public Class CertInformationCollector

extends Object
Class Inheritance
Imports
java.io.FileInputStream, .IOException, .InputStream, java.net.URISyntaxException, java.security.GeneralSecurityException, java.security.cert.CertificateException, .CertificateFactory, .X509Certificate, java.util.Arrays, .Collection, .HashSet, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.examples.signature.SigUtils, org.apache.pdfbox.examples.signature.cert.CertificateVerifier, org.apache.pdfbox.pdmodel.encryption.SecurityProvider, org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature, org.bouncycastle.asn1.ASN1Encodable, .ASN1Object, org.bouncycastle.asn1.cms.Attribute, .AttributeTable, org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers, org.bouncycastle.asn1.x509.Extension, org.bouncycastle.cert.X509CertificateHolder, org.bouncycastle.cert.jcajce.JcaX509CertificateConverter, org.bouncycastle.cms.CMSException, .CMSSignedData, .SignerInformation, org.bouncycastle.util.Store

This class helps to extract data/information from a signature. The information is held in CertSignatureInformation. Some information is needed for validation processing of the participating certificates.
Author
Alexis Suter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CertInformationCollector.CertSignatureInformation

Data class to hold Signature, Certificate (and its chain(s)) and revocation Information

Field Summary

Modifier and TypeField and Description
private final JcaX509CertificateConverter
private final Set<X509Certificate>
private static final Log
private static final int
private CertInformationCollector.CertSignatureInformation
private final Set<String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
addAllCerts(Collection<X509CertificateHolder>
Collection of X509CertificateHolder
certHolders
)

Adds multiple Certificates out of a Collection of X509CertificateHolder into certificateSet.

public void
addAllCertsFromHolders(X509CertificateHolder[]
Array of X509CertificateHolder
certHolders
)

Gets a list of X509Certificate out of an array of X509CertificateHolder.

private void
addTimestampCerts(SignerInformation
of the signature, to get unsigned attributes from it.
signerInformation
)

Processes an embedded signed timestamp, that has been placed into a signature.

private void
getAlternativeIssuerCertificate(CertInformationCollector.CertSignatureInformation
base Certificate Information, on which to put the alternative Certificate
certInfo
,
int
Maximum depth to dig through the chain from here on.
maxDepth
)

Get alternative certificate chain, from the Authority Information (a url).

private X509Certificate

Returns:

a X509Certificate or null when there was an Error with the Certificate
getCertFromHolder
(X509CertificateHolder
to get the certificate from
certificateHolder
)

Gets the X509Certificate out of the X509CertificateHolder.

public Set<X509Certificate>

Returns:

a set of serial numbers to certificates.
getCertificateSet
()

Get the set of all processed certificates until now.

private CertInformationCollector.CertSignatureInformation

Returns:

the CertSignatureInformation for this signature
getCertInfo
(byte[]
the byte[]-Content of the signature
signatureContent
)

Processes one signature and its including certificates.

pack-priv CertInformationCollector.CertSignatureInformation
getCertInfo(X509Certificate certificate)

Traverse a certificate.

public CertInformationCollector.CertSignatureInformation

Returns:

the CertSignatureInformation containing all certificate information
getLastCertInfo
(PDSignature
the signature of the document.
signature
,
String
of the document.
fileName
)

Gets the certificate information of a signature.

private SignerInformation

Returns:

Signer Information of the processed certificatesStore for further usage.
processSignerStore
(CMSSignedData
data from which to get the SignerInformation
signedData
,
CertInformationCollector.CertSignatureInformation
where to add certificate information
certInfo
)

Processes a signer store and goes through the signers certificate-chain.

private void
traverseChain(X509Certificate
Actual Certificate to be processed
certificate
,
CertInformationCollector.CertSignatureInformation
where to add the Certificate (and chain) information
certInfo
,
int
Max depth from this point to go through CertChain (could be infinite)
maxDepth
)

Traverse through the Cert-Chain of the given Certificate and add it to the CertInfo recursively.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

certConverterback to summary
private final JcaX509CertificateConverter certConverter
certificateSetback to summary
private final Set<X509Certificate> certificateSet
LOGback to summary
private static final Log LOG
MAX_CERTIFICATE_CHAIN_DEPTHback to summary
private static final int MAX_CERTIFICATE_CHAIN_DEPTH
rootCertInfoback to summary
private CertInformationCollector.CertSignatureInformation rootCertInfo
urlSetback to summary
private final Set<String> urlSet

Constructor Detail

CertInformationCollectorback to summary
public CertInformationCollector()

Method Detail

addAllCertsback to summary
private void addAllCerts(Collection<X509CertificateHolder> certHolders)

Adds multiple Certificates out of a Collection of X509CertificateHolder into certificateSet.

Parameters
certHolders:Collection<X509CertificateHolder>

Collection of X509CertificateHolder

addAllCertsFromHoldersback to summary
public void addAllCertsFromHolders(X509CertificateHolder[] certHolders) throws CertificateProccessingException

Gets a list of X509Certificate out of an array of X509CertificateHolder. The certificates will be added to certificateSet.

Parameters
certHolders:X509CertificateHolder[]

Array of X509CertificateHolder

Exceptions
CertificateProccessingException:
when one of the Certificates could not be parsed.
addTimestampCertsback to summary
private void addTimestampCerts(SignerInformation signerInformation) throws IOException, CertificateProccessingException

Processes an embedded signed timestamp, that has been placed into a signature. The certificates and its chain(s) will be processed the same way as the signature itself.

Parameters
signerInformation:SignerInformation

of the signature, to get unsigned attributes from it.

getAlternativeIssuerCertificateback to summary
private void getAlternativeIssuerCertificate(CertInformationCollector.CertSignatureInformation certInfo, int maxDepth) throws CertificateProccessingException

Get alternative certificate chain, from the Authority Information (a url). If the chain is not included in the signature, this is the main chain. Otherwise there might be a second chain. Exceptions which happen on this chain will be logged and ignored, because the cert might not be available at the time or other reasons.

Parameters
certInfo:CertInformationCollector.CertSignatureInformation

base Certificate Information, on which to put the alternative Certificate

maxDepth:int

Maximum depth to dig through the chain from here on.

Exceptions
CertificateProccessingException:
on a specific error with a certificate
getCertFromHolderback to summary
private X509Certificate getCertFromHolder(X509CertificateHolder certificateHolder) throws CertificateProccessingException

Gets the X509Certificate out of the X509CertificateHolder.

Parameters
certificateHolder:X509CertificateHolder

to get the certificate from

Returns:X509Certificate

a X509Certificate or null when there was an Error with the Certificate

Exceptions
CertificateProccessingException:
on failed conversion from X509CertificateHolder to X509Certificate
getCertificateSetback to summary
public Set<X509Certificate> getCertificateSet()

Get the set of all processed certificates until now.

Returns:Set<X509Certificate>

a set of serial numbers to certificates.

getCertInfoback to summary
private CertInformationCollector.CertSignatureInformation getCertInfo(byte[] signatureContent) throws CertificateProccessingException, IOException

Processes one signature and its including certificates.

Parameters
signatureContent:byte[]

the byte[]-Content of the signature

Returns:CertInformationCollector.CertSignatureInformation

the CertSignatureInformation for this signature

getCertInfoback to summary
pack-priv CertInformationCollector.CertSignatureInformation getCertInfo(X509Certificate certificate) throws CertificateProccessingException

Traverse a certificate.

getLastCertInfoback to summary
public CertInformationCollector.CertSignatureInformation getLastCertInfo(PDSignature signature, String fileName) throws CertificateProccessingException, IOException

Gets the certificate information of a signature.

Parameters
signature:PDSignature

the signature of the document.

fileName:String

of the document.

Returns:CertInformationCollector.CertSignatureInformation

the CertSignatureInformation containing all certificate information

Exceptions
CertificateProccessingException:
when there is an error processing the certificates
IOException:
on a data processing error
processSignerStoreback to summary
private SignerInformation processSignerStore(CMSSignedData signedData, CertInformationCollector.CertSignatureInformation certInfo) throws IOException, CertificateProccessingException

Processes a signer store and goes through the signers certificate-chain. Adds the found data to the certInfo. Handles only the first signer, although multiple would be possible, but is not yet practicable.

Parameters
signedData:CMSSignedData

data from which to get the SignerInformation

certInfo:CertInformationCollector.CertSignatureInformation

where to add certificate information

Returns:SignerInformation

Signer Information of the processed certificatesStore for further usage.

Exceptions
IOException:
on data-processing error
CertificateProccessingException:
on a specific error with a certificate
traverseChainback to summary
private void traverseChain(X509Certificate certificate, CertInformationCollector.CertSignatureInformation certInfo, int maxDepth) throws IOException, CertificateProccessingException

Traverse through the Cert-Chain of the given Certificate and add it to the CertInfo recursively.

Parameters
certificate:X509Certificate

Actual Certificate to be processed

certInfo:CertInformationCollector.CertSignatureInformation

where to add the Certificate (and chain) information

maxDepth:int

Max depth from this point to go through CertChain (could be infinite)

Exceptions
IOException:
on data-processing error
CertificateProccessingException:
on a specific error with a certificate
org.apache.pdfbox.examples.signature.validation back to summary

public Class CertInformationCollector.CertSignatureInformation

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.pdfbox.examples.signature.validation.CertInformationCollector.CertSignatureInformation

Data class to hold Signature, Certificate (and its chain(s)) and revocation Information

Field Summary

Modifier and TypeField and Description
private CertInformationCollector.CertSignatureInformation
private CertInformationCollector.CertSignatureInformation
private X509Certificate
private String
private boolean
private final Set<X509Certificate>
private String
private String
private String
private CertInformationCollector.CertSignatureInformation

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CertInformationCollector.CertSignatureInformation
public CertInformationCollector.CertSignatureInformation
public X509Certificate
public String
public Set<X509Certificate>
public String
public String
public CertInformationCollector.CertSignatureInformation
public boolean
public void
setIssuerUrl(String issuerUrl)

public void
setOcspUrl(String ocspUrl)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alternativeCertChainback to summary
private CertInformationCollector.CertSignatureInformation alternativeCertChain
certChainback to summary
private CertInformationCollector.CertSignatureInformation certChain
certificateback to summary
private X509Certificate certificate
crlUrlback to summary
private String crlUrl
isSelfSignedback to summary
private boolean isSelfSigned
issuerCertificatesback to summary
private final Set<X509Certificate> issuerCertificates
issuerUrlback to summary
private String issuerUrl
ocspUrlback to summary
private String ocspUrl
signatureHashback to summary
private String signatureHash
tsaCertsback to summary
private CertInformationCollector.CertSignatureInformation tsaCerts

Constructor Detail

CertSignatureInformationback to summary
public CertSignatureInformation()

Method Detail

getAlternativeCertChainback to summary
public CertInformationCollector.CertSignatureInformation getAlternativeCertChain()
getCertChainback to summary
public CertInformationCollector.CertSignatureInformation getCertChain()
getCertificateback to summary
public X509Certificate getCertificate()
getCrlUrlback to summary
public String getCrlUrl()
getIssuerCertificatesback to summary
public Set<X509Certificate> getIssuerCertificates()
getOcspUrlback to summary
public String getOcspUrl()
getSignatureHashback to summary
public String getSignatureHash()
getTsaCertsback to summary
public CertInformationCollector.CertSignatureInformation getTsaCerts()
isSelfSignedback to summary
public boolean isSelfSigned()
setIssuerUrlback to summary
public void setIssuerUrl(String issuerUrl)
setOcspUrlback to summary
public void setOcspUrl(String ocspUrl)