Package tigase.cert

# Class CertificateUtil

java.lang.Object
tigase.cert.CertificateUtil

public abstract class CertificateUtil extends Object
Created: Sep 22, 2010 3:09:01 PM

Version:
  $Rev$
Author:
  Artur Hefczyc

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `CertificateUtil.KeyPairSupplier`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final byte[]`
  `ID_ON_XMPPADDR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CertificateUtil()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static KeyPair`
  `createKeyPair(int size, String password)`
  `static X509Certificate`
  `createSelfSignedCertificate(String email, String domain, String organizationUnit, String organization, String city, String state, String country, KeyPair keyPair)`
  Deprecated.
  `static CertificateEntry`
  `createSelfSignedCertificate(String email, String domain, String organizationUnit, String organization, String city, String state, String country, CertificateUtil.KeyPairSupplier keyPairSupplier)`
  `static String`
  `exportToPemFormat(CertificateEntry entry)`
  `protected static String`
  `extractCN(X500Principal principal)`
  `static List<String>`
  `extractXmppAddrs(X509Certificate x509Certificate)`
  `static List<String>`
  `getCertAltCName(X509Certificate cert)`
  `static String`
  `getCertCName(X509Certificate cert)`
  `static StringBuilder`
  `getCertificateBasicInfo(StringBuilder sb, Certificate cert)`
  `static String`
  `getCertificateBasicInfo(Certificate cert)`
  `static String`
  `getCertificateFingerprint(Certificate cert)`
  `static Optional<BigInteger>`
  `getCertificateSerialNumber(Certificate cert)`
  `static boolean`
  `isExpired(X509Certificate cert)`
  `static boolean`
  `isSelfSigned(X509Certificate cert)`
  `static CertificateEntry`
  `loadCertificate(byte[] bytes)`
  Deprecated.
  `static CertificateEntry`
  `loadCertificate(File file)`
  `static CertificateEntry`
  `loadCertificate(String file)`
  `static PrivateKey`
  `loadPrivateKeyFromDER(File file)`
  `static void`
  `main(String[] args)`
  `static boolean`
  `match(String hostname, String altName)`
  Checks if hostname matches name or wildcard
  `static CertificateEntry`
  `parseCertificate(Reader data)`
  `static Certificate[]`
  `removeRootCACertificate(Certificate[] certChain)`
  `static Certificate[]`
  `sort(Certificate[] chain)`
  `static List<Certificate>`
  `sort(List<Certificate> certs)`
  `static void`
  `storeCertificate(String file, CertificateEntry entry)`
  `static CertCheckResult`
  `validateCertificate(Certificate[] chain, KeyStore trustKeystore, boolean revocationEnabled)`
  `static boolean`
  `verifyCertificateForDomain(X509Certificate cert, String hostname)`
  Method used to verify if certificate if valid for particular domain (if domain matches CN or ALT of certificate)
  `protected static boolean`
  `verifyCertificateForHostname(String hostname, X509Certificate x509Certificate)`
  `protected static boolean`
  `verifyCertificateForIp(String ipAddr, X509Certificate x509Certificate)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ID_ON_XMPPADDR

    protected static final byte[] ID_ON_XMPPADDR

- ## Constructor Details

  - ### CertificateUtil

    public CertificateUtil()

- ## Method Details

  - ### createKeyPair

    public static KeyPair createKeyPair(int size, String password) throws NoSuchAlgorithmException
    Throws:
      `NoSuchAlgorithmException`

  - ### createSelfSignedCertificate

    @Deprecated public static X509Certificate createSelfSignedCertificate(String email, String domain, String organizationUnit, String organization, String city, String state, String country, KeyPair keyPair) throws CertificateException, IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
    Deprecated.
    Throws:
      `CertificateException`
      `IOException`
      `NoSuchAlgorithmException`
      `InvalidKeyException`
      `NoSuchProviderException`
      `SignatureException`

  - ### createSelfSignedCertificate

    public static CertificateEntry createSelfSignedCertificate(String email, String domain, String organizationUnit, String organization, String city, String state, String country, CertificateUtil.KeyPairSupplier keyPairSupplier) throws CertificateException, IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
    Throws:
      `CertificateException`
      `IOException`
      `NoSuchAlgorithmException`
      `InvalidKeyException`
      `NoSuchProviderException`
      `SignatureException`

  - ### exportToPemFormat

    public static String exportToPemFormat(CertificateEntry entry) throws CertificateEncodingException
    Throws:
      `CertificateEncodingException`

  - ### extractCN

    protected static String extractCN(X500Principal principal)

  - ### extractXmppAddrs

    public static List<String> extractXmppAddrs(X509Certificate x509Certificate)

  - ### getCertAltCName

    public static List<String> getCertAltCName(X509Certificate cert)

  - ### getCertCName

    public static String getCertCName(X509Certificate cert)

  - ### getCertificateBasicInfo

    public static String getCertificateBasicInfo(Certificate cert)

  - ### getCertificateBasicInfo

    public static StringBuilder getCertificateBasicInfo(StringBuilder sb, Certificate cert)

  - ### getCertificateFingerprint

    public static String getCertificateFingerprint(Certificate cert) throws CertificateEncodingException, NoSuchAlgorithmException
    Throws:
      `CertificateEncodingException`
      `NoSuchAlgorithmException`

  - ### getCertificateSerialNumber

    public static Optional<BigInteger> getCertificateSerialNumber(Certificate cert)

  - ### isExpired

    public static boolean isExpired(X509Certificate cert)

  - ### isSelfSigned

    public static boolean isSelfSigned(X509Certificate cert)

  - ### loadCertificate

    public static CertificateEntry loadCertificate(File file) throws FileNotFoundException, IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException
    Throws:
      `FileNotFoundException`
      `IOException`
      `CertificateException`
      `NoSuchAlgorithmException`
      `InvalidKeySpecException`

  - ### loadCertificate

    @Deprecated public static CertificateEntry loadCertificate(byte[] bytes) throws CertificateException, NoSuchProviderException
    Deprecated.
    Loads a certificate from a DER byte buffer.
    Throws:
      `CertificateException`
      `NoSuchProviderException`

  - ### loadCertificate

    public static CertificateEntry loadCertificate(String file) throws FileNotFoundException, IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException
    Throws:
      `FileNotFoundException`
      `IOException`
      `CertificateException`
      `NoSuchAlgorithmException`
      `InvalidKeySpecException`

  - ### loadPrivateKeyFromDER

    public static PrivateKey loadPrivateKeyFromDER(File file) throws FileNotFoundException, IOException, NoSuchAlgorithmException, InvalidKeySpecException
    Throws:
      `FileNotFoundException`
      `IOException`
      `NoSuchAlgorithmException`
      `InvalidKeySpecException`

  - ### main

    public static void main(String[] args) throws Exception
    Throws:
      `Exception`

  - ### match

    public static boolean match(String hostname, String altName)
    Checks if hostname matches name or wildcard
    Returns:
      true if there is a match

  - ### parseCertificate

    public static CertificateEntry parseCertificate(Reader data) throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException
    Throws:
      `IOException`
      `CertificateException`
      `NoSuchAlgorithmException`
      `InvalidKeySpecException`

  - ### removeRootCACertificate

    public static Certificate[] removeRootCACertificate(Certificate[] certChain)

  - ### sort

    public static Certificate[] sort(Certificate[] chain)

  - ### sort

    public static List<Certificate> sort(List<Certificate> certs)

  - ### storeCertificate

    public static void storeCertificate(String file, CertificateEntry entry) throws CertificateEncodingException, IOException
    Throws:
      `CertificateEncodingException`
      `IOException`

  - ### validateCertificate

    public static CertCheckResult validateCertificate(Certificate[] chain, KeyStore trustKeystore, boolean revocationEnabled) throws NoSuchAlgorithmException, KeyStoreException, InvalidAlgorithmParameterException, CertificateException
    Throws:
      `NoSuchAlgorithmException`
      `KeyStoreException`
      `InvalidAlgorithmParameterException`
      `CertificateException`

  - ### verifyCertificateForDomain

    public static boolean verifyCertificateForDomain(X509Certificate cert, String hostname) throws CertificateParsingException
    Method used to verify if certificate if valid for particular domain (if domain matches CN or ALT of certificate)
    Returns:
      true if certificate is valid
    Throws:
      `CertificateParsingException`

  - ### verifyCertificateForHostname

    protected static boolean verifyCertificateForHostname(String hostname, X509Certificate x509Certificate) throws CertificateParsingException
    Throws:
      `CertificateParsingException`

  - ### verifyCertificateForIp

    protected static boolean verifyCertificateForIp(String ipAddr, X509Certificate x509Certificate) throws CertificateParsingException
    Throws:
      `CertificateParsingException`