Package io.confluent.security.auth.mtls
Class CaCertificatesUtils
java.lang.Object
io.confluent.security.auth.mtls.CaCertificatesUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic Certificate[]buildCertChain(Certificate[] clientChain, Map<String, Set<Certificate>> providerToCaCertsMapping) Builds a complete certificate chain from the given client certificate chain, and CA certificates for all providers.static CertificatefindSigningCert(Certificate signedCert, Collection<Certificate> certificates) Find signing cert of a given certificate in a collection of certificates.static booleanWhether the certificate is a CA certificatestatic booleanisSelfSigned(Certificate cert) checks if the given Certificate is self-signed.static X509Certificate[]Parse PEM encoded certificates to X509Certificate objects.static X509Certificate[]x509CertificatesFromPemFile(Path pemFile) Parse PEM encoded certificates from a file to X509Certificate objectsstatic X509CRLx509CrlFromPem(String pem) Parse PEM encoded CRL to X509CRL objectstatic Stringx509CrlToPem(X509CRL crl) Convert X509CRL to PEM format
-
Method Details
-
x509CertificatesFromPem
public static X509Certificate[] x509CertificatesFromPem(String pem) throws CertificateException, IOException Parse PEM encoded certificates to X509Certificate objects.- Parameters:
pem- PEM encoded certificates- Returns:
- X509Certificate objects
- Throws:
CertificateException- if the certificate cannot be parsedIOException- if an I/O error occurs
-
x509CertificatesFromPemFile
public static X509Certificate[] x509CertificatesFromPemFile(Path pemFile) throws CertificateException, IOException Parse PEM encoded certificates from a file to X509Certificate objects- Parameters:
pemFile- Path to the PEM file- Returns:
- X509Certificate objects
- Throws:
CertificateException- if the certificate cannot be parsedIOException- if an I/O error occurs
-
isCertificateAuthority
Whether the certificate is a CA certificate- Parameters:
cert- X509Certificate- Returns:
- true if the certificate is a CA certificate, false otherwise
-
x509CrlFromPem
public static X509CRL x509CrlFromPem(String pem) throws CertificateException, IOException, CRLException Parse PEM encoded CRL to X509CRL object- Parameters:
pem- PEM encoded CRL- Returns:
- X509CRL object
- Throws:
CertificateException- if the CRL cannot be parsedIOException- if an I/O error occursCRLException- if the CRL is invalid
-
x509CrlToPem
Convert X509CRL to PEM format- Parameters:
crl- X509CRL object- Returns:
- PEM encoded CRL
- Throws:
CRLException- if the CRL cannot be encoded
-
isSelfSigned
checks if the given Certificate is self-signed.- Parameters:
cert- Certificate- Returns:
- true if the certificate is self-signed, false otherwise
- Throws:
IllegalArgumentException- if the certificate is null
-
findSigningCert
public static Certificate findSigningCert(Certificate signedCert, Collection<Certificate> certificates) Find signing cert of a given certificate in a collection of certificates. Return null if there is no signing cert in the collection or the certificate is self-signed- Parameters:
signedCert- certificate to find the signing cert for, must not be nullcertificates- collection of CA certificates which might sign the signedCert, must not be null- Returns:
- signing certificate or null if not found
- Throws:
IllegalArgumentException- if signedCert is nullIllegalArgumentException- if certificates are null
-
buildCertChain
public static Certificate[] buildCertChain(Certificate[] clientChain, Map<String, Set<Certificate>> providerToCaCertsMapping) Builds a complete certificate chain from the given client certificate chain, and CA certificates for all providers. Client chain is converted to a valid chain and extra certificates not belonging to the chain are dropped.- Parameters:
clientChain- partial cert chain must not be null or empty, and the first certificate must be the leaf certproviderToCaCertsMapping- map of providers to list of CA certificate for each provider- Returns:
- a valid certificate chain (complete if CA provider can be matched, otherwise incomplete)
- Throws:
IllegalArgumentException- if cert is nullIllegalArgumentException- if provider to CA certs map is null
-