Class CertificateUtils
java.lang.Object
br.ufsc.labsec.utils.CertificateUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic CertificateFactorystatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<X509Certificate> buildPathFromCollection(Collection<X509Certificate> certs, Object certificate) static booleancertificateInReference(Certificate certificate, List<org.apache.commons.lang3.tuple.Pair<String, byte[]>> references) static StringcertificateToBase64String(Object object) static StringcertPathToBase64String(Object object) static byte[]convertPEMtoDER(byte[] pemEncoded) static Optional<TrustAnchor> createTrustAnchor(byte[] bytes) static Optional<TrustAnchor> createTrustAnchor(InputStream inputStream) static TrustAnchorcreateTrustAnchor(Certificate certificate) static TrustAnchorcreateTrustAnchor(X509Certificate x509Certificate) static List<TrustAnchor> createTrustAnchors(byte[] bytes) static Stream<TrustAnchor> createTrustAnchors(InputStream inputStream) static byte[]static byte[]static byte[]static byte[]static byte[]static byte[]static booleanstatic X500PrincipalgeneralNamesToX500Principal(org.bouncycastle.asn1.x509.GeneralNames generalNames) static CertPathgenerateCertPath(List<? extends Certificate> certificates) getAlternativeNameByOid(Object certificate, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) static Optional<TrustAnchor> getAnchor(CertPath certPath, Collection<TrustAnchor> trustAnchors) static Optional<X509Certificate> getAnchorCertificate(Certificate certificate, Collection<TrustAnchor> trustAnchors) static Optional<X509Certificate> getAnchorCertificate(CertPath certPath, Collection<TrustAnchor> trustAnchors) static org.bouncycastle.asn1.x509.AuthorityInformationAccessgetAuthorityInformationAccess(Object certificate) getCertificate(CertificateCollection collection, SignatureObject object, org.bouncycastle.util.Selector<Certificate> selector, CertificateCollectionCache cache) static Optional<Certificate> getCertificate(org.bouncycastle.cert.X509CertificateHolder holder) static List<X509Certificate> getCertificatesInCertPath(X509Certificate certificate, CertStore certStore, Set<TrustAnchor> trustAnchors) static Collection<? extends Certificate> getCNPJFromCertificate(Object certificate) Deprecated.static StringgetCountryFromCertificate(Object certificate) getCPFFromCertificate(Object certificate) Deprecated.static org.bouncycastle.asn1.x509.CRLDistPointgetCRLDistributionPoints(Object certificate) static org.bouncycastle.asn1.x500.X500NamegetCRLIssuerName(org.bouncycastle.asn1.x509.CRLDistPoint crlDistPoint) static List<org.bouncycastle.asn1.x509.GeneralNames> getCRLIssuers(Object certificate) static Collection<? extends CRL> static org.bouncycastle.asn1.x500.X500NamegetDirectoryName(org.bouncycastle.asn1.x509.GeneralNames generalNames) static org.bouncycastle.asn1.x509.DistributionPoint[]getDistributionPoints(Object certificate) static org.bouncycastle.asn1.x509.GeneralNamegetGeneralName(org.bouncycastle.asn1.x509.GeneralNames generalNames, int tag) static org.bouncycastle.asn1.x509.GeneralNamesgetGeneralNamesFromX500Name(org.bouncycastle.asn1.x500.X500Name name) static intRetorna o tamanho da chave públicastatic 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 CertificateFactorystatic booleanhasCRLIssuer(Object certificate) static CertificateUtils.UsagehasKeyUsage(Object certificate, int usage) static booleanhasNotSupportedExtensions(TrustAnchor anchor) Verifica se a âncora de confiança contém a extensão namedConstraints.static booleanhasTrustAnchorAsIssuer(Certificate certificate, Collection<TrustAnchor> anchors) static booleanisCACertificate(Object certificate) static booleanstatic booleanstatic booleanISDIGEST(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, byte[] expectedDigest, Object certificate) static booleanstatic booleanstatic booleanisIssuer(org.bouncycastle.cert.X509AttributeCertificateHolder subject, org.bouncycastle.cert.X509CertificateHolder issuer) static booleanisPEM(CertificateInterface.Instance instance, byte[] encoded) static booleanisSelfSigned(Object certificate) static booleanisTrustAnchor(Certificate certificate, SignaturePolicyInterface signaturePolicyInterface) static booleanisTrustAnchor(Certificate certificate, Collection<TrustAnchor> anchors) static booleannoRevAvail(org.bouncycastle.cert.X509AttributeCertificateHolder certificate) Indica se o certificado de atributo contém a extensão noRevAvail e se ela é válida.static booleannotYetValid(Time timeReference, Object certificate) static Optional<Certificate> parseCertificate(String certificateB64) static booleanvalidOnPeriod(Time timeReference, Object certificate)
-
Field Details
-
X509_TYPE
- See Also:
-
UNABLE_TO_GET_CERTIFICATE_ENCODING
- See Also:
-
factory
-
-
Constructor Details
-
CertificateUtils
public CertificateUtils()
-
-
Method Details
-
isIssuer
-
isIssuer
public static boolean isIssuer(org.bouncycastle.cert.X509AttributeCertificateHolder subject, org.bouncycastle.cert.X509CertificateHolder issuer) -
getX509CertificateFactory
- Throws:
CertificateException
-
getCertsFromX509Factory
-
getCRLsFromX509Factory
-
generateCertPath
-
getAuthorityInformationAccess
public static org.bouncycastle.asn1.x509.AuthorityInformationAccess getAuthorityInformationAccess(Object certificate) -
getCRLDistributionPoints
-
getCRLIssuerName
public static org.bouncycastle.asn1.x500.X500Name getCRLIssuerName(org.bouncycastle.asn1.x509.CRLDistPoint crlDistPoint) -
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
-
getAnchorCertificate
public static Optional<X509Certificate> getAnchorCertificate(Certificate certificate, Collection<TrustAnchor> trustAnchors) -
getAnchorCertificate
public static Optional<X509Certificate> getAnchorCertificate(CertPath certPath, Collection<TrustAnchor> trustAnchors) -
getAnchor
public static Optional<TrustAnchor> 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, utilizeExtensionsReportObté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) -
certificateToBase64String
-
certPathToBase64String
-
noRevAvail
public static boolean noRevAvail(org.bouncycastle.cert.X509AttributeCertificateHolder certificate) Indica se o certificado de atributo contém a extensão noRevAvail e se ela é válida.- Parameters:
certificate- certificado de atributo- Returns:
- valor lógico que indica se o certificado de atributo contém a extensão noRevAvail e se ela é válida.
-
digest
- Throws:
NoSuchAlgorithmExceptionIOException
-
digest
public static byte[] digest(org.bouncycastle.asn1.ASN1ObjectIdentifier identifier, Object certificate) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-
digest
public static byte[] digest(String algorithm, Object certificate) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-
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
-
isICPBr
-
getKeyLength
Retorna o tamanho da chave pública- Parameters:
pk- A chave pública- Returns:
- O tamanho da chave ou -1 se a chave não for suportada
-
getCertificatesInCertPath
public static List<X509Certificate> getCertificatesInCertPath(X509Certificate certificate, CertStore certStore, Set<TrustAnchor> trustAnchors) -
parseCertificate
-
ExtensionsReport