Top Description Fields Constructors Methods
org.apache.pdfbox.examples.signature.cert

public final Class CertificateVerifier

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URISyntaxException, java.security.GeneralSecurityException, .InvalidKeyException, .PublicKey, .SignatureException, java.security.cert.CertPathBuilder, .CertPathBuilderException, .CertStore, .Certificate, .CertificateException, .CertificateFactory, .CollectionCertStoreParameters, .PKIXBuilderParameters, .PKIXCertPathBuilderResult, .TrustAnchor, .X509CertSelector, .X509Certificate, .X509Extension, java.util.Calendar, .Collection, .Date, .Enumeration, .HashSet, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.examples.signature.SigUtils, org.apache.pdfbox.pdmodel.encryption.SecurityProvider, org.bouncycastle.asn1.ASN1Encodable, .ASN1OctetString, .ASN1Primitive, .ASN1Sequence, .ASN1TaggedObject, org.bouncycastle.asn1.ocsp.OCSPObjectIdentifiers, org.bouncycastle.asn1.x509.Extension, .GeneralName, .X509ObjectIdentifiers, org.bouncycastle.cert.X509CertificateHolder, org.bouncycastle.cert.jcajce.JcaX509CertificateConverter, .JcaX509ExtensionUtils, org.bouncycastle.cert.ocsp.BasicOCSPResp, .OCSPException, .OCSPResp

Copied from Apache CXF 2.4.9, initial version: https://svn.apache.org/repos/asf/cxf/tags/cxf-2.4.9/distribution/src/main/release/samples/sts_issue_operation/src/main/java/demo/sts/provider/cert/

Field Summary

Modifier and TypeField and Description
private static final Log

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
checkRevocations(X509Certificate cert, Set<X509Certificate> additionalCerts, Date signDate)

private static void
checkRevocationsWithIssuer(X509Certificate cert, X509Certificate issuerCert, Set<X509Certificate> additionalCerts, Date signDate)

public static Set<X509Certificate>

Returns:

a certificate set, never null.
downloadExtraCertificates
(X509Extension
an X509 object that can have extensions.
ext
)

Download extra certificates from the URI mentioned in id-ad-caIssuers in the "authority information access" extension.

private static String

Returns:

the URL of the OCSP validation service
extractOCSPURL
(X509Certificate
X.509 certificate
cert
)

Extract the OCSP URL from an X.509 certificate if available.

public static boolean

Returns:

true if the certificate is self-signed, false if not.
isSelfSigned
(X509Certificate
The X.509 certificate to check.
cert
)

Checks whether given X.509 certificate is self-signed.

public static PKIXCertPathBuilderResult

Returns:

the certification chain (if verification is successful)
verifyCertificate
(X509Certificate
- certificate for validation
cert
,
Set<X509Certificate>
- set of trusted root CA certificates that will be used as "trust anchors" and intermediate CA certificates that will be used as part of the certification chain. All self-signed certificates are considered to be trusted root CA certificates. All the rest are considered to be intermediate CA certificates.
additionalCerts
,
boolean
true if a self-signed certificate is accepted, false if not.
verifySelfSignedCert
,
Date
the date when the signing took place
signDate
)

Attempts to build a certification chain for given certificate and to verify it.

private static PKIXCertPathBuilderResult

Returns:

the certification chain (if verification is successful)
verifyCertificate
(X509Certificate
- certificate for validation
cert
,
Set<TrustAnchor>
- set of trust anchors
trustAnchors
,
Set<X509Certificate>
- set of intermediate certificates
intermediateCerts
,
Date
the date when the signing took place
signDate
)

Attempts to build a certification chain for given certificate and to verify it.

private static void
verifyOCSP(OcspHelper
the OCSP helper.
ocspHelper
,
Set<X509Certificate> additionalCerts)

Verify whether the certificate has been revoked at signing date, and verify whether the certificate of the responder has been revoked now.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG

Constructor Detail

CertificateVerifierback to summary
private CertificateVerifier()

Method Detail

checkRevocationsback to summary
private static void checkRevocations(X509Certificate cert, Set<X509Certificate> additionalCerts, Date signDate) throws IOException, CertificateVerificationException, OCSPException, RevokedCertificateException, GeneralSecurityException, URISyntaxException
checkRevocationsWithIssuerback to summary
private static void checkRevocationsWithIssuer(X509Certificate cert, X509Certificate issuerCert, Set<X509Certificate> additionalCerts, Date signDate) throws OCSPException, CertificateVerificationException, RevokedCertificateException, GeneralSecurityException, IOException, URISyntaxException
downloadExtraCertificatesback to summary
public static Set<X509Certificate> downloadExtraCertificates(X509Extension ext)

Download extra certificates from the URI mentioned in id-ad-caIssuers in the "authority information access" extension. The method is lenient, i.e. catches all exceptions.

Parameters
ext:X509Extension

an X509 object that can have extensions.

Returns:Set<X509Certificate>

a certificate set, never null.

extractOCSPURLback to summary
private static String extractOCSPURL(X509Certificate cert) throws IOException

Extract the OCSP URL from an X.509 certificate if available.

Parameters
cert:X509Certificate

X.509 certificate

Returns:String

the URL of the OCSP validation service

isSelfSignedback to summary
public static boolean isSelfSigned(X509Certificate cert) throws GeneralSecurityException

Checks whether given X.509 certificate is self-signed.

Parameters
cert:X509Certificate

The X.509 certificate to check.

Returns:boolean

true if the certificate is self-signed, false if not.

verifyCertificateback to summary
public static PKIXCertPathBuilderResult verifyCertificate(X509Certificate cert, Set<X509Certificate> additionalCerts, boolean verifySelfSignedCert, Date signDate) throws CertificateVerificationException

Attempts to build a certification chain for given certificate and to verify it. Relies on a set of root CA certificates and intermediate certificates that will be used for building the certification chain. The verification process assumes that all self-signed certificates in the set are trusted root CA certificates and all other certificates in the set are intermediate certificates.

Parameters
cert:X509Certificate

- certificate for validation

additionalCerts:Set<X509Certificate>

- set of trusted root CA certificates that will be used as "trust anchors" and intermediate CA certificates that will be used as part of the certification chain. All self-signed certificates are considered to be trusted root CA certificates. All the rest are considered to be intermediate CA certificates.

verifySelfSignedCert:boolean

true if a self-signed certificate is accepted, false if not.

signDate:Date

the date when the signing took place

Returns:PKIXCertPathBuilderResult

the certification chain (if verification is successful)

Exceptions
CertificateVerificationException:
- if the certification is not successful (e.g. certification path cannot be built or some certificate in the chain is expired or CRL checks are failed)
verifyCertificateback to summary
private static PKIXCertPathBuilderResult verifyCertificate(X509Certificate cert, Set<TrustAnchor> trustAnchors, Set<X509Certificate> intermediateCerts, Date signDate) throws GeneralSecurityException

Attempts to build a certification chain for given certificate and to verify it. Relies on a set of root CA certificates (trust anchors) and a set of intermediate certificates (to be used as part of the chain).

Parameters
cert:X509Certificate

- certificate for validation

trustAnchors:Set<TrustAnchor>

- set of trust anchors

intermediateCerts:Set<X509Certificate>

- set of intermediate certificates

signDate:Date

the date when the signing took place

Returns:PKIXCertPathBuilderResult

the certification chain (if verification is successful)

Exceptions
GeneralSecurityException:
- if the verification is not successful (e.g. certification path cannot be built or some certificate in the chain is expired)
verifyOCSPback to summary
private static void verifyOCSP(OcspHelper ocspHelper, Set<X509Certificate> additionalCerts) throws RevokedCertificateException, IOException, OCSPException, CertificateVerificationException, URISyntaxException

Verify whether the certificate has been revoked at signing date, and verify whether the certificate of the responder has been revoked now.

Parameters
ocspHelper:OcspHelper

the OCSP helper.