Package br.ufsc.labsec.utils
Class CertificateUtils
java.lang.Object
br.ufsc.labsec.utils.CertificateUtils
public class CertificateUtils extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CertificateUtils.AdditionalExtensionOIDS
static class
CertificateUtils.Usage
-
Field Summary
Fields Modifier and Type Field Description static String
UNABLE_TO_GET_CERTIFICATE_ENCODING
static String
X509_TYPE
-
Constructor Summary
Constructors Constructor Description CertificateUtils()
-
Method Summary
Modifier and Type Method Description static Collection<X509Certificate>
buildPathFromCollection(Collection<X509Certificate> certs, Object certificate)
static boolean
certificateInReference(Certificate certificate, List<org.apache.commons.lang3.tuple.Pair<String,byte[]>> references)
static byte[]
convertPEMtoDER(byte[] pemEncoded)
static Optional<TrustAnchor>
createTrustAnchor(byte[] bytes)
static Optional<TrustAnchor>
createTrustAnchor(InputStream inputStream)
static TrustAnchor
createTrustAnchor(Certificate certificate)
static TrustAnchor
createTrustAnchor(X509Certificate x509Certificate)
static List<TrustAnchor>
createTrustAnchors(byte[] bytes)
static Stream<TrustAnchor>
createTrustAnchors(InputStream inputStream)
static byte[]
digest(Object certificate)
static byte[]
digest(String algorithm, Object certificate)
static byte[]
digest(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, Object certificate)
static byte[]
DIGEST(Object certificate)
static byte[]
DIGEST(String algorithm, Object certificate)
static byte[]
DIGEST(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, Object certificate)
static boolean
expired(Time timeReference, Object certificate)
static X500Principal
generalNamesToX500Principal(org.bouncycastle.asn1.x509.GeneralNames generalNames)
static CertPath
generateCertPath(List<? extends Certificate> certificates)
static Optional<String>
getAlternativeNameByOid(Object certificate, org.bouncycastle.asn1.ASN1ObjectIdentifier oid)
static Optional<X509Certificate>
getAnchor(Certificate certificate, Collection<TrustAnchor> trustAnchors)
static Optional<X509Certificate>
getAnchor(CertPath certPath, Collection<TrustAnchor> trustAnchors)
static org.bouncycastle.asn1.x509.AuthorityInformationAccess
getAuthorityInformationAccess(Object certificate)
Optional<Certificate>
getCertificate(CertificateCollection collection, SignatureObject object, org.bouncycastle.util.Selector<Certificate> selector, CertificateCollectionCache cache)
static Optional<Certificate>
getCertificate(org.bouncycastle.cert.X509CertificateHolder holder)
static Collection<? extends Certificate>
getCertsFromX509Factory(InputStream certs)
static Optional<String>
getCNPJFromCertificate(Object certificate)
Deprecated.static String
getCountryFromCertificate(Object certificate)
static Optional<String>
getCPFFromCertificate(Object certificate)
Deprecated.static org.bouncycastle.asn1.x509.CRLDistPoint
getCRLDistributionPoints(Object certificate)
static List<org.bouncycastle.asn1.x509.GeneralNames>
getCRLIssuers(Object certificate)
static Collection<? extends CRL>
getCRLsFromX509Factory(InputStream crls)
static org.bouncycastle.asn1.x500.X500Name
getDirectoryName(org.bouncycastle.asn1.x509.GeneralNames generalNames)
static org.bouncycastle.asn1.x509.DistributionPoint[]
getDistributionPoints(Object certificate)
static org.bouncycastle.asn1.x509.GeneralName
getGeneralName(org.bouncycastle.asn1.x509.GeneralNames generalNames, int tag)
static org.bouncycastle.asn1.x509.GeneralNames
getGeneralNamesFromX500Name(org.bouncycastle.asn1.x500.X500Name name)
static List<Certificate>
getPathWithAnchor(CertPath certPath, SignaturePolicyInterface policyInterface)
static List<Certificate>
getPathWithAnchor(CertPath certPath, Collection<TrustAnchor> trustAnchors)
static Optional<X509Certificate>
getTrustPoint(Certificate certificate, SignaturePolicyInterface signaturePolicyInterface)
static Optional<X509Certificate>
getTrustPoint(Certificate certificate, Collection<TrustAnchor> anchors)
static CertificateFactory
getX509CertificateFactory()
static boolean
hasCRLIssuer(Object certificate)
static CertificateUtils.Usage
hasKeyUsage(Object certificate, int usage)
static boolean
hasNotSupportedExtensions(TrustAnchor anchor)
Verifica se a âncora de confiança contém a extensão namedConstraints.static boolean
hasTrustAnchorAsIssuer(Certificate certificate, Collection<TrustAnchor> anchors)
static boolean
isCACertificate(Object certificate)
static boolean
ISDIGEST(byte[] expectedDigest, Object certificate)
static boolean
ISDIGEST(String algorithm, byte[] expectedDigest, Object certificate)
static boolean
ISDIGEST(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, byte[] expectedDigest, Object certificate)
static boolean
isIssuer(Object subject, Object issuer)
static boolean
isPEM(CertificateInterface.Instance instance, byte[] encoded)
static boolean
isSelfSigned(Object certificate)
static boolean
isTrustAnchor(Certificate certificate, SignaturePolicyInterface signaturePolicyInterface)
static boolean
isTrustAnchor(Certificate certificate, Collection<TrustAnchor> anchors)
static boolean
noRevAvail(org.bouncycastle.cert.X509AttributeCertificateHolder certificate)
static boolean
notYetValid(Time timeReference, Object certificate)
static boolean
validOnPeriod(Time timeReference, Object certificate)
-
Field Details
-
X509_TYPE
- See Also:
- Constant Field Values
-
UNABLE_TO_GET_CERTIFICATE_ENCODING
- See Also:
- Constant Field Values
-
-
Constructor Details
-
CertificateUtils
public CertificateUtils()
-
-
Method Details
-
isIssuer
-
getX509CertificateFactory
- Throws:
CertificateException
-
getCertsFromX509Factory
-
getCRLsFromX509Factory
-
generateCertPath
-
getAuthorityInformationAccess
public static org.bouncycastle.asn1.x509.AuthorityInformationAccess getAuthorityInformationAccess(Object certificate) -
getCRLDistributionPoints
-
getDistributionPoints
public static org.bouncycastle.asn1.x509.DistributionPoint[] getDistributionPoints(Object certificate) -
getCRLIssuers
-
hasCRLIssuer
-
getGeneralName
public static org.bouncycastle.asn1.x509.GeneralName getGeneralName(org.bouncycastle.asn1.x509.GeneralNames generalNames, int tag) throws IOException- Throws:
IOException
-
getDirectoryName
public static org.bouncycastle.asn1.x500.X500Name getDirectoryName(org.bouncycastle.asn1.x509.GeneralNames generalNames) throws IOException- Throws:
IOException
-
generalNamesToX500Principal
public static X500Principal generalNamesToX500Principal(org.bouncycastle.asn1.x509.GeneralNames generalNames) throws IOException- Throws:
IOException
-
expired
-
notYetValid
-
validOnPeriod
-
getTrustPoint
public static Optional<X509Certificate> getTrustPoint(Certificate certificate, SignaturePolicyInterface signaturePolicyInterface) -
createTrustAnchor
-
createTrustAnchor
-
createTrustAnchors
-
createTrustAnchors
-
createTrustAnchor
-
getAnchor
public static Optional<X509Certificate> getAnchor(Certificate certificate, Collection<TrustAnchor> trustAnchors) -
getAnchor
public static Optional<X509Certificate> getAnchor(CertPath certPath, Collection<TrustAnchor> trustAnchors) -
getPathWithAnchor
public static List<Certificate> getPathWithAnchor(CertPath certPath, SignaturePolicyInterface policyInterface) -
getPathWithAnchor
public static List<Certificate> getPathWithAnchor(CertPath certPath, Collection<TrustAnchor> trustAnchors) -
createTrustAnchor
-
getTrustPoint
public static Optional<X509Certificate> getTrustPoint(Certificate certificate, Collection<TrustAnchor> anchors) -
hasTrustAnchorAsIssuer
public static boolean hasTrustAnchorAsIssuer(Certificate certificate, Collection<TrustAnchor> anchors) -
isSelfSigned
-
isTrustAnchor
public static boolean isTrustAnchor(Certificate certificate, SignaturePolicyInterface signaturePolicyInterface) -
getGeneralNamesFromX500Name
public static org.bouncycastle.asn1.x509.GeneralNames getGeneralNamesFromX500Name(org.bouncycastle.asn1.x500.X500Name name) -
hasKeyUsage
-
getCNPJFromCertificate
Deprecated.para uso no Validador de Documentos, utilizeExtensionsReport
Obtém o CNPJ do certificado pelo OID definido emBrazilianPKIObjectIdentifiers
, se presente- Parameters:
certificate
- certificado a ser obtido o CNPJ- Returns:
- o CNPJ em um
Optional
-
getCPFFromCertificate
Deprecated.Agora é obtido através do relatório de extensões, pois o campo pode não ser umDERPrintableString
, então, para o Validador de Documentos, useExtensionsReport
. -
getAlternativeNameByOid
-
certificateInReference
public static boolean certificateInReference(Certificate certificate, List<org.apache.commons.lang3.tuple.Pair<String,byte[]>> references) -
getCountryFromCertificate
-
isCACertificate
-
isTrustAnchor
-
hasNotSupportedExtensions
Verifica se a âncora de confiança contém a extensão namedConstraints.- Parameters:
anchor
- âncora de confiança.- Returns:
- valor lógico que indica se a âncora de confiança contém a extensão namedConstraints.
-
buildPathFromCollection
public static Collection<X509Certificate> buildPathFromCollection(Collection<X509Certificate> certs, Object certificate) -
getCertificate
public Optional<Certificate> getCertificate(CertificateCollection collection, SignatureObject object, org.bouncycastle.util.Selector<Certificate> selector, CertificateCollectionCache cache) -
getCertificate
public static Optional<Certificate> getCertificate(org.bouncycastle.cert.X509CertificateHolder holder) -
noRevAvail
public static boolean noRevAvail(org.bouncycastle.cert.X509AttributeCertificateHolder certificate) -
digest
- Throws:
NoSuchAlgorithmException
IOException
-
digest
public static byte[] digest(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, Object certificate) throws NoSuchAlgorithmException, IOException- Throws:
NoSuchAlgorithmException
IOException
-
digest
public static byte[] digest(String algorithm, Object certificate) throws NoSuchAlgorithmException, IOException- Throws:
NoSuchAlgorithmException
IOException
-
DIGEST
-
DIGEST
public static byte[] DIGEST(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, Object certificate) -
DIGEST
-
ISDIGEST
-
ISDIGEST
public static boolean ISDIGEST(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, byte[] expectedDigest, Object certificate) -
ISDIGEST
-
isPEM
-
convertPEMtoDER
- Throws:
IOException
-
ExtensionsReport