public class CertificateUtil extends Object
| Constructor and Description |
|---|
CertificateUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkIfIssuersMatch(com.itextpdf.commons.bouncycastle.cert.ocsp.ICertificateID certID,
X509Certificate issuerCert)
Checks if the issuer of the provided certID (specified in the OCSP response) and provided issuer of the
certificate in question matches, i.e.
|
static X509Certificate |
createCertificateFromEncodedData(String encodedCertificateBytes)
Reads certificate from der encoded string.
|
static com.itextpdf.commons.bouncycastle.asn1.IDERSet |
createRevocationInfoChoices(Collection<CRL> crls,
Collection<com.itextpdf.commons.bouncycastle.asn1.ocsp.IBasicOCSPResponse> ocsps,
Collection<com.itextpdf.commons.bouncycastle.asn1.IASN1Sequence> otherRevocationInfoFormats)
Creates the revocation info (crls field) for SignedData structure:
RevocationInfoChoices ::= SET OF RevocationInfoChoice
RevocationInfoChoice ::= CHOICE {
crl CertificateList,
other [1] IMPLICIT OtherRevocationInfoFormat }
OtherRevocationInfoFormat ::= SEQUENCE {
otherRevInfoFormat OBJECT IDENTIFIER,
otherRevInfo ANY DEFINED BY otherRevInfoFormat }
CertificateList ::= SEQUENCE {
tbsCertList TBSCertList,
signatureAlgorithm AlgorithmIdentifier,
signatureValue BIT STRING }
|
static Certificate |
generateCertificate(InputStream data)
Generates a certificate object and initializes it with the data read from the input stream inStream.
|
static CRL |
getCRL(String url)
Gets the CRL object using a CRL URL.
|
static List<CRL> |
getCRLs(X509Certificate certificate)
Gets a CRLs from the X509 certificate.
|
static List<String> |
getCRLURLs(X509Certificate certificate)
Gets the list of the Certificate Revocation List URLs for a Certificate.
|
static com.itextpdf.commons.bouncycastle.asn1.x509.IDistributionPoint |
getDistributionPointByName(X509Certificate certificate,
com.itextpdf.commons.bouncycastle.asn1.x509.IDistributionPointName issuingDistributionPointName)
Gets the Distribution Point from the certificate by name specified in the Issuing Distribution Point from the
Certificate Revocation List for a Certificate.
|
static com.itextpdf.commons.bouncycastle.asn1.IASN1Primitive |
getExtensionValue(CRL crl,
String oid)
Gets CRL extension value.
|
static com.itextpdf.commons.bouncycastle.asn1.IASN1Primitive |
getExtensionValue(X509Certificate certificate,
String oid)
Gets certificate extension value.
|
static byte[] |
getExtensionValueByOid(X509Certificate certificate,
String id)
Retrieves certificate extension value by its OID.
|
static String |
getIssuerCertURL(CRL crl)
Retrieves the URL for the issuer certificate for the given CRL.
|
static String |
getIssuerCertURL(X509Certificate certificate)
Retrieves the URL for the issuer lists certificates for the given certificate.
|
static String |
getOCSPURL(X509Certificate certificate)
Retrieves the OCSP URL from the given certificate.
|
static String |
getTSAURL(X509Certificate certificate)
Gets the URL of the TSA if it's available on the certificate
|
static boolean |
isSelfSigned(X509Certificate certificate)
Checks if the certificate is self-signed.
|
static boolean |
isSignatureValid(com.itextpdf.commons.bouncycastle.cert.ocsp.IBasicOCSPResp ocspResp,
Certificate responderCert)
Checks if an OCSP response is genuine.
|
static CRL |
parseCrlFromBytes(byte[] crlBytes)
Parses a CRL from bytes.
|
static CRL |
parseCrlFromStream(InputStream input)
Parses a CRL from an InputStream.
|
static Certificate[] |
readCertificatesFromPem(InputStream pemFileStream)
Read all certificates from an input stream in PEM format.
|
static void |
retrieveRevocationInfoFromSignedData(com.itextpdf.commons.bouncycastle.asn1.IASN1TaggedObject taggedObj,
Collection<CRL> crls,
Collection<com.itextpdf.commons.bouncycastle.asn1.ocsp.IBasicOCSPResponse> ocsps,
Collection<com.itextpdf.commons.bouncycastle.asn1.IASN1Sequence> otherRevocationInfoFormats)
Try to retrieve CRL and OCSP responses from the signed data crls field.
|
public static List<CRL> getCRLs(X509Certificate certificate) throws CertificateException, CRLException, IOException
certificate - the X509Certificate to extract the CRLs fromIOException - thrown when the URL couldn't be opened properly.CertificateException - thrown if there's no X509 implementation in the provider.CRLException - thrown when encountering errors when parsing the CRL.public static List<String> getCRLURLs(X509Certificate certificate)
certificate - the Certificate to get CRL URLs forpublic static com.itextpdf.commons.bouncycastle.asn1.x509.IDistributionPoint getDistributionPointByName(X509Certificate certificate, com.itextpdf.commons.bouncycastle.asn1.x509.IDistributionPointName issuingDistributionPointName)
certificate - the certificate to retrieve Distribution PointsissuingDistributionPointName - distributionPointName retrieved from the IDP of the CRLpublic static CRL getCRL(String url) throws IOException, CertificateException, CRLException
url - the URL where the CRL is locatedIOException - thrown when the URL couldn't be opened properly.CertificateException - thrown if there's no X509 implementation in the provider.CRLException - thrown when encountering errors when parsing the CRL.public static CRL parseCrlFromStream(InputStream input) throws CertificateException, CRLException
input - the InputStream holding the unparsed CRLCertificateException - thrown if there's no X509 implementation in the provider.CRLException - thrown when encountering errors when parsing the CRL.public static CRL parseCrlFromBytes(byte[] crlBytes) throws CertificateException, CRLException
crlBytes - the bytes holding the unparsed CRLCertificateException - thrown if there's no X509 implementation in the provider.CRLException - thrown when encountering errors when parsing the CRL.public static String getIssuerCertURL(CRL crl)
crl - the CRL responsepublic static String getOCSPURL(X509Certificate certificate)
certificate - the certificatepublic static String getIssuerCertURL(X509Certificate certificate)
certificate - the certificatepublic static String getTSAURL(X509Certificate certificate)
certificate - a certificatepublic static Certificate generateCertificate(InputStream data) throws CertificateException
data - the input stream with the certificates.CertificateException - on parsing errors.public static void retrieveRevocationInfoFromSignedData(com.itextpdf.commons.bouncycastle.asn1.IASN1TaggedObject taggedObj,
Collection<CRL> crls,
Collection<com.itextpdf.commons.bouncycastle.asn1.ocsp.IBasicOCSPResponse> ocsps,
Collection<com.itextpdf.commons.bouncycastle.asn1.IASN1Sequence> otherRevocationInfoFormats)
throws IOException,
CertificateException
taggedObj - signed data crls field as IASN1TaggedObject.crls - collection to store retrieved CRL responses.ocsps - collection of IBasicOCSPResponse wrappers to store retrieved
OCSP responses.otherRevocationInfoFormats - collection of revocation info other than OCSP and CRL responses,
e.g. SCVP Request and Response, stored as IASN1Sequence.IOException - if some I/O error occurred.CertificateException - if CertificateFactory instance wasn't created.public static com.itextpdf.commons.bouncycastle.asn1.IDERSet createRevocationInfoChoices(Collection<CRL> crls, Collection<com.itextpdf.commons.bouncycastle.asn1.ocsp.IBasicOCSPResponse> ocsps, Collection<com.itextpdf.commons.bouncycastle.asn1.IASN1Sequence> otherRevocationInfoFormats) throws CRLException, IOException
crls - collection of CRL revocation status information.ocsps - collection of OCSP revocation status information.otherRevocationInfoFormats - collection of revocation info other than OCSP and CRL responses,
e.g. SCVP Request and Response, stored as IASN1Sequence.crls [1] RevocationInfoChoices field of SignedData structure. Null if SignedData has
no revocation data.CRLException - if an encoding error occurs.IOException - if an I/O error occurs.public static boolean checkIfIssuersMatch(com.itextpdf.commons.bouncycastle.cert.ocsp.ICertificateID certID,
X509Certificate issuerCert)
throws com.itextpdf.commons.bouncycastle.operator.AbstractOperatorCreationException,
com.itextpdf.commons.bouncycastle.cert.ocsp.AbstractOCSPException,
CertificateEncodingException,
IOException
SingleResp contains the basic information of the status of the certificate identified by the certID. The issuer name and serial number identify a unique certificate, so if serial numbers of the certificate in question and certID serial number are equals and issuers match, then SingleResp contains the information about the status of the certificate in question.
certID - certID specified in the OCSP responseissuerCert - the issuer of the certificate in questioncom.itextpdf.commons.bouncycastle.operator.AbstractOperatorCreationException - in case some digest calculator creation error.com.itextpdf.commons.bouncycastle.cert.ocsp.AbstractOCSPException - in case some digest calculator creation error.CertificateEncodingException - if an encoding error occurs.IOException - if input-output exception occurs.public static byte[] getExtensionValueByOid(X509Certificate certificate, String id)
certificate - to get extension fromid - extension OID to retrievepublic static boolean isSignatureValid(com.itextpdf.commons.bouncycastle.cert.ocsp.IBasicOCSPResp ocspResp,
Certificate responderCert)
ocspResp - IBasicOCSPResp the OCSP response wrapperresponderCert - the responder certificatepublic static boolean isSelfSigned(X509Certificate certificate)
certificate - a certificate to checkpublic static com.itextpdf.commons.bouncycastle.asn1.IASN1Primitive getExtensionValue(X509Certificate certificate, String oid) throws IOException
certificate - the certificate from which we need the ExtensionValueoid - the Object Identifier value for the extensionIASN1Primitive object.IOException - on processing exception.public static com.itextpdf.commons.bouncycastle.asn1.IASN1Primitive getExtensionValue(CRL crl, String oid) throws IOException
crl - the CRL from which we need the ExtensionValueoid - the Object Identifier value for the extensionIASN1Primitive object.IOException - on processing exception.public static X509Certificate createCertificateFromEncodedData(String encodedCertificateBytes)
encodedCertificateBytes - der encoded dataX509Certificate objectpublic static Certificate[] readCertificatesFromPem(InputStream pemFileStream)
pemFileStream - InputStream in PEM formatCertificate arrayCopyright © 1998–2025 Apryse Group NV. All rights reserved.