edu.vt.middleware.crypt.x509
Class X509Utils

java.lang.Object
  extended by edu.vt.middleware.crypt.x509.X509Utils

public final class X509Utils
extends Object

Utility class providing convenience methods for common operations on X.509 certificates.

Version:
$Revision: 2744 $
Author:
Middleware Services

Method Summary
static X509Certificate findEntityCertificate(Collection<X509Certificate> candidates, PrivateKey key)
          Finds a certificate whose public key is paired with the given private key.
static X509Certificate findEntityCertificate(X509Certificate[] candidates, PrivateKey key)
          Finds a certificate whose public key is paired with the given private key.
static List<GeneralName> getSubjectAltNames(X509Certificate cert)
          Gets all subject alternative names defined on the given certificate.
static List<GeneralName> getSubjectAltNames(X509Certificate cert, GeneralNameType... types)
          Gets all subject alternative names of the given type(s) on the given cert.
static List<String> getSubjectNames(X509Certificate cert)
          Gets all subject names present on the given certificate, i.e.
static List<String> getSubjectNames(X509Certificate cert, GeneralNameType... types)
          Gets CN from the subject DN and the set of all alternative names of the given type.
static Object readExtension(X509Certificate cert, ExtensionType type)
          Reads a single extension field from the given X.509 certificate.
static Map<ExtensionType,Object> readExtensions(X509Certificate cert)
          Reads all the X.509 extension fields from the certificate and makes them available as a map of types to values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSubjectAltNames

public static List<GeneralName> getSubjectAltNames(X509Certificate cert)
Gets all subject alternative names defined on the given certificate.

Parameters:
cert - X.509 certificate to examine.
Returns:
List of subject alternative names or an empty list if no subject alt names are defined.

getSubjectAltNames

public static List<GeneralName> getSubjectAltNames(X509Certificate cert,
                                                   GeneralNameType... types)
Gets all subject alternative names of the given type(s) on the given cert.

Parameters:
cert - X.509 certificate to examine.
types - One or more name types to fetch.
Returns:
List of subject alternative names of the matching type(s) or an empty list if no subject alt names are defined or none match given type.

getSubjectNames

public static List<String> getSubjectNames(X509Certificate cert)
Gets all subject names present on the given certificate, i.e. the set of first subject CN and all alternative names.

Parameters:
cert - X.509 certificate to examine.
Returns:
List of subject names.

getSubjectNames

public static List<String> getSubjectNames(X509Certificate cert,
                                           GeneralNameType... types)
Gets CN from the subject DN and the set of all alternative names of the given type.

Parameters:
cert - X.509 certificate to examine.
types - One or more name types to fetch.
Returns:
List of subject names.

findEntityCertificate

public static X509Certificate findEntityCertificate(X509Certificate[] candidates,
                                                    PrivateKey key)
Finds a certificate whose public key is paired with the given private key.

Parameters:
candidates - Array of candidate certificates.
key - Private key used to find matching public key.
Returns:
Certificate among candidates whose public key that forms a keypair with the given private key or null if no match is found.

findEntityCertificate

public static X509Certificate findEntityCertificate(Collection<X509Certificate> candidates,
                                                    PrivateKey key)
Finds a certificate whose public key is paired with the given private key.

Parameters:
candidates - Collection of candidate certificates.
key - Private key used to find matching public key.
Returns:
Certificate among candidates whose public key that forms a keypair with the given private key or null if no match is found.

readExtension

public static Object readExtension(X509Certificate cert,
                                   ExtensionType type)
Reads a single extension field from the given X.509 certificate.

Parameters:
cert - Certificate from which to read extensions.
type - Type that describes the extension to read.
Returns:
Value type of extension from the edu.vt.middleware.crypt.x509.types package or null if no such extension is defined.

readExtensions

public static Map<ExtensionType,Object> readExtensions(X509Certificate cert)
Reads all the X.509 extension fields from the certificate and makes them available as a map of types to values.

Parameters:
cert - Certificate to read.
Returns:
Map of X.509 extension types to the corresponding value object in the edu.vt.middleware.crypt.x509.types package.


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.