Class X509CertSelector
- All Implemented Interfaces:
Cloneable,CertSelector
- Direct Known Subclasses:
X509CertStoreSelector
public class X509CertSelector extends Object implements CertSelector
CertSelector for selecting
X509Certificates that match the specified criteria.-
Constructor Summary
Constructors Constructor Description X509CertSelector()Creates a newX509CertSelector. -
Method Summary
Modifier and Type Method Description voidaddPathToName(int type, byte[] name)Adds a "pathToName" to the respective criterion.voidaddPathToName(int type, String name)Adds a "pathToName" to the respective criterion.voidaddSubjectAlternativeName(int tag, byte[] name)Adds a subject alternative name to the respective criterion.voidaddSubjectAlternativeName(int tag, String name)Adds a subject alternative name to the respective criterion.Objectclone()Clones thisX509CertSelectorinstance.byte[]getAuthorityKeyIdentifier()Returns the criterion for the AuthorityKeyIdentifier extension.intgetBasicConstraints()Returns the criterion for the basic constraints extension.X509CertificategetCertificate()Returns the certificate that a matching certificate must be equal to.DategetCertificateValid()Returns the criterion for the validity date of the certificate.Set<String>getExtendedKeyUsage()Returns the criterion for the ExtendedKeyUsage extension.X500PrincipalgetIssuer()Returns the issuer that a certificate must match.byte[]getIssuerAsBytes()Returns the issuer that a certificate must match.StringgetIssuerAsString()Do not use, usegetIssuer()orgetIssuerAsBytes()instead.boolean[]getKeyUsage()Returns the criterion for the KeyUsage extension.booleangetMatchAllSubjectAltNames()Returns the flag for the matching behavior for subject alternative names.byte[]getNameConstraints()Returns the criterion for the name constraints.Collection<List<?>>getPathToNames()Returns the criterion for the pathToNames constraint.Set<String>getPolicy()Returns the criterion for the policy constraint.DategetPrivateKeyValid()Returns the criterion for the validity date of the private key.BigIntegergetSerialNumber()Returns the serial number that a certificate must match.X500PrincipalgetSubject()Returns the subject that a certificate must match.Collection<List<?>>getSubjectAlternativeNames()Returns the criterion for subject alternative names.byte[]getSubjectAsBytes()Returns the subject that a certificate must match.StringgetSubjectAsString()Do not use, usegetSubject()orgetSubjectAsBytes()instead.byte[]getSubjectKeyIdentifier()Returns the criterion for the SubjectKeyIdentifier extension.PublicKeygetSubjectPublicKey()Returns the criterion for the subject public key.StringgetSubjectPublicKeyAlgID()Returns the criterion for the subject public key signature algorithm.booleanmatch(Certificate certificate)Returns whether the specified certificate matches all the criteria collected in this instance.voidsetAuthorityKeyIdentifier(byte[] authorityKeyIdentifier)Sets the criterion for the AuthorityKeyIdentifier extension.voidsetBasicConstraints(int pathLen)Sets the criterion for the basic constraints extension.voidsetCertificate(X509Certificate certificate)Sets the certificate that a matching certificate must be equal to.voidsetCertificateValid(Date certificateValid)Sets the criterion for the validity date of the certificate.voidsetExtendedKeyUsage(Set<String> keyUsage)Sets the criterion for the ExtendedKeyUsage extension.voidsetIssuer(byte[] issuerDN)Sets the issuer that a certificate must match.voidsetIssuer(String issuerName)Do not use, usegetIssuer()orgetIssuerAsBytes()instead.voidsetIssuer(X500Principal issuer)Sets the issuer that a certificate must match.voidsetKeyUsage(boolean[] keyUsage)Sets the criterion for the KeyUsage extension.voidsetMatchAllSubjectAltNames(boolean matchAllNames)Sets the flag for the matching behavior for subject alternative names.voidsetNameConstraints(byte[] bytes)Sets the criterion for the name constraints.voidsetPathToNames(Collection<List<?>> names)Sets the criterion for the pathToNames constraint.voidsetPolicy(Set<String> policies)Sets the criterion for the policy constraint.voidsetPrivateKeyValid(Date privateKeyValid)Sets the criterion for the validity date of the private key.voidsetSerialNumber(BigInteger serialNumber)Sets the serial number that a certificate must match.voidsetSubject(byte[] subjectDN)Sets the subject that a certificate must match.voidsetSubject(String subjectDN)Do not use, usesetSubject(byte[])orsetSubject(X500Principal)instead.voidsetSubject(X500Principal subject)Set the subject that a certificate must match.voidsetSubjectAlternativeNames(Collection<List<?>> names)Sets the criterion for subject alternative names.voidsetSubjectKeyIdentifier(byte[] subjectKeyIdentifier)Sets the criterion for the SubjectKeyIdentifier extension.voidsetSubjectPublicKey(byte[] key)Sets the criterion for the subject public key.voidsetSubjectPublicKey(PublicKey key)Sets the criterion for the subject public key.voidsetSubjectPublicKeyAlgID(String oid)Sets the criterion for the subject public key signature algorithm.StringtoString()Returns a string representation of thisX509CertSelectorinstance.
-
Constructor Details
-
X509CertSelector
public X509CertSelector()Creates a newX509CertSelector.
-
-
Method Details
-
setCertificate
Sets the certificate that a matching certificate must be equal to.- Parameters:
certificate- the certificate to match, or null to not check this criteria.
-
getCertificate
Returns the certificate that a matching certificate must be equal to.- Returns:
- the certificate to match, or null if this criteria is not checked.
-
setSerialNumber
Sets the serial number that a certificate must match.- Parameters:
serialNumber- the serial number to match, ornullto not check the serial number.
-
getSerialNumber
Returns the serial number that a certificate must match.- Returns:
- the serial number to match, or
nullif the serial number is not to be checked.
-
setIssuer
Sets the issuer that a certificate must match.- Parameters:
issuer- the issuer to match, ornullif the issuer is not to be checked.
-
getIssuer
Returns the issuer that a certificate must match.- Returns:
- the issuer that a certificate must match, or
nullif the issuer is not to be checked.
-
setIssuer
Do not use, usegetIssuer()orgetIssuerAsBytes()instead. Sets the issuer that a certificate must match.- Parameters:
issuerName- the issuer in a RFC 2253 format string, ornullto not check the issuer.- Throws:
IOException- if parsing the issuer fails.
-
getIssuerAsString
Do not use, usegetIssuer()orgetIssuerAsBytes()instead. Returns the issuer that a certificate must match in a RFC 2253 format string.- Returns:
- the issuer in a RFC 2253 format string, or
nullif the issuer is not to be checked.
-
setIssuer
Sets the issuer that a certificate must match.- Parameters:
issuerDN- the distinguished issuer name in ASN.1 DER encoded format, ornullto not check the issuer.- Throws:
IOException- if decoding the issuer fail.
-
getIssuerAsBytes
Returns the issuer that a certificate must match.- Returns:
- the distinguished issuer name in ASN.1 DER encoded format, or
nullif the issuer is not to be checked. - Throws:
IOException- if encoding the issuer fails.
-
setSubject
Set the subject that a certificate must match.- Parameters:
subject- the subject distinguished name ornullto not check the subject.
-
getSubject
Returns the subject that a certificate must match.- Returns:
- the subject distinguished name, or null if the subject is not to be checked.
-
setSubject
Do not use, usesetSubject(byte[])orsetSubject(X500Principal)instead. Returns the subject that a certificate must match.- Parameters:
subjectDN- the subject distinguished name in RFC 2253 format ornullto not check the subject.- Throws:
IOException- if decoding the subject fails.
-
getSubjectAsString
Do not use, usegetSubject()orgetSubjectAsBytes()instead. Returns the subject that a certificate must match.- Returns:
- the subject distinguished name in RFC 2253 format, or
nullif the subject is not to be checked.
-
setSubject
Sets the subject that a certificate must match.- Parameters:
subjectDN- the subject distinguished name in ASN.1 DER format, ornullto not check the subject.- Throws:
IOException- if decoding the subject fails.
-
getSubjectAsBytes
Returns the subject that a certificate must match.- Returns:
- the subject distinguished name in ASN.1 DER format, or
nullif the subject is not to be checked. - Throws:
IOException- if encoding the subject fails.
-
setSubjectKeyIdentifier
public void setSubjectKeyIdentifier(byte[] subjectKeyIdentifier)Sets the criterion for the SubjectKeyIdentifier extension.The
subjectKeyIdentifiershould be a single DER encoded value.- Parameters:
subjectKeyIdentifier- the subject key identifier ornullto disable this check.
-
getSubjectKeyIdentifier
public byte[] getSubjectKeyIdentifier()Returns the criterion for the SubjectKeyIdentifier extension.- Returns:
- the subject key identifier or
nullif it is not to be checked.
-
setAuthorityKeyIdentifier
public void setAuthorityKeyIdentifier(byte[] authorityKeyIdentifier)Sets the criterion for the AuthorityKeyIdentifier extension.- Parameters:
authorityKeyIdentifier- the authority key identifier, ornullto disable this check.
-
getAuthorityKeyIdentifier
public byte[] getAuthorityKeyIdentifier()Returns the criterion for the AuthorityKeyIdentifier extension.- Returns:
- the authority key identifier, or
nullif it is not to be checked.
-
setCertificateValid
Sets the criterion for the validity date of the certificate.The certificate must be valid at the specified date.
- Parameters:
certificateValid- the validity date ornullto not check the date.
-
getCertificateValid
Returns the criterion for the validity date of the certificate.- Returns:
- the validity date or
nullif the date is not to be checked.
-
setPrivateKeyValid
Sets the criterion for the validity date of the private key.The private key must be valid at the specified date.
- Parameters:
privateKeyValid- the validity date ornullto not check the date.
-
getPrivateKeyValid
Returns the criterion for the validity date of the private key.The private key must be valid at the specified date.
- Returns:
- the validity date or
nullif the date is not to be checked.
-
setSubjectPublicKeyAlgID
Sets the criterion for the subject public key signature algorithm.The certificate must contain a subject public key with the algorithm specified.
- Parameters:
oid- the OID (object identifier) of the signature algorithm ornullto not check the OID.- Throws:
IOException- if the specified object identifier is invalid.
-
getSubjectPublicKeyAlgID
Returns the criterion for the subject public key signature algorithm.- Returns:
- the OID (object identifier) or the signature algorithm or
nullif it's not to be checked.
-
setSubjectPublicKey
Sets the criterion for the subject public key.- Parameters:
key- the subject public key ornullto not check the key.
-
setSubjectPublicKey
Sets the criterion for the subject public key.- Parameters:
key- the subject public key in ASN.1 DER encoded format ornullto not check the key.- Throws:
IOException- if decoding the the public key fails.
-
getSubjectPublicKey
Returns the criterion for the subject public key.- Returns:
- the subject public key or
nullif the key is not to be checked.
-
setKeyUsage
public void setKeyUsage(boolean[] keyUsage)Sets the criterion for the KeyUsage extension.- Parameters:
keyUsage- the boolean array in the format as returned byX509Certificate.getKeyUsage(), ornullto not check the key usage.
-
getKeyUsage
public boolean[] getKeyUsage()Returns the criterion for the KeyUsage extension.- Returns:
- the boolean array in the format as returned by
X509Certificate.getKeyUsage(), ornullif the key usage is not to be checked.
-
setExtendedKeyUsage
Sets the criterion for the ExtendedKeyUsage extension.- Parameters:
keyUsage- the set of key usage OIDs, ornullto not check it.- Throws:
IOException- if one of the OIDs is invalid.
-
getExtendedKeyUsage
Returns the criterion for the ExtendedKeyUsage extension.- Returns:
- the set of key usage OIDs, or
nullif it's not to be checked.
-
setMatchAllSubjectAltNames
public void setMatchAllSubjectAltNames(boolean matchAllNames)Sets the flag for the matching behavior for subject alternative names.The flag indicates whether a certificate must contain all or at least one of the subject alternative names specified by
setSubjectAlternativeNames(java.util.Collection<java.util.List<?>>)oraddSubjectAlternativeName(int, java.lang.String).- Parameters:
matchAllNames-trueif a certificate must contain all of the specified subject alternative names, otherwisefalse.
-
getMatchAllSubjectAltNames
public boolean getMatchAllSubjectAltNames()Returns the flag for the matching behavior for subject alternative names.The flag indicates whether a certificate must contain all or at least one of the subject alternative names specified by
setSubjectAlternativeNames(java.util.Collection<java.util.List<?>>)oraddSubjectAlternativeName(int, java.lang.String).- Returns:
trueif a certificate must contain all of the specified subject alternative names, otherwisefalse.
-
setSubjectAlternativeNames
Sets the criterion for subject alternative names.the certificate must contain all or at least one of the specified subject alternative names. The behavior is specified by
getMatchAllSubjectAltNames().The specified parameter
namesis a collection with an entry for each name to be included in the criterion. The name is specified as aList, the first entry must be anIntegerspecifying the name type (0-8), the second entry must be aStringor a byte array specifying the name (in string or ASN.1 DER encoded form)- Parameters:
names- the names collection ornullto not perform this check.- Throws:
IOException- if the decoding of a name fails.
-
addSubjectAlternativeName
Adds a subject alternative name to the respective criterion.- Parameters:
tag- the type of the namename- the name in string format.- Throws:
IOException- if parsing the name fails.
-
addSubjectAlternativeName
Adds a subject alternative name to the respective criterion.- Parameters:
tag- the type of the name.name- the name in ASN.1 DER encoded form.- Throws:
IOException- if the decoding of the name fails.
-
getSubjectAlternativeNames
Returns the criterion for subject alternative names.the certificate must contain all or at least one of the specified subject alternative names. The behavior is specified by
getMatchAllSubjectAltNames().The subject alternative names is a collection with an entry for each name included in the criterion. The name is specified as a
List, the first entry is anIntegerspecifying the name type (0-8), the second entry is byte array specifying the name in ASN.1 DER encoded form)- Returns:
- the names collection or
nullif none specified.
-
setNameConstraints
Sets the criterion for the name constraints.The certificate must constraint subject and subject alternative names that match the specified name constraints.
The name constraints in ASN.1:
NameConstraints ::= SEQUENCE { permittedSubtrees [0] GeneralSubtrees OPTIONAL, excludedSubtrees [1] GeneralSubtrees OPTIONAL } GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree GeneralSubtree ::= SEQUENCE { base GeneralName, minimum [0] BaseDistance DEFAULT 0, maximum [1] BaseDistance OPTIONAL } BaseDistance ::= INTEGER (0..MAX) GeneralName ::= CHOICE { otherName [0] OtherName, rfc822Name [1] IA5String, dNSName [2] IA5String, x400Address [3] ORAddress, directoryName [4] Name, ediPartyName [5] EDIPartyName, uniformResourceIdentifier [6] IA5String, iPAddress [7] OCTET STRING, registeredID [8] OBJECT IDENTIFIER}- Parameters:
bytes- the name constraints in ASN.1 DER encoded format, or null to not check any constraints.- Throws:
IOException- if decoding the name constraints fail.
-
getNameConstraints
public byte[] getNameConstraints()Returns the criterion for the name constraints.- Returns:
- the name constraints or
nullif none specified. - See Also:
setNameConstraints(byte[])
-
setBasicConstraints
public void setBasicConstraints(int pathLen)Sets the criterion for the basic constraints extension.A value greater than or equal to zero indicates that a certificate must include a basic constraints extension with a path length of a least that value. A value of
-2indicates that only end-entity certificates are accepted. A value of-1indicates that no check is done.- Parameters:
pathLen- the value specifying the criterion.- Throws:
IllegalArgumentException- ifpathLenis less than-2.
-
getBasicConstraints
public int getBasicConstraints()Returns the criterion for the basic constraints extension.A value greater than or equal to zero indicates that a certificate must include a basic constraints extension with a path length of a least that value. A value of
-2indicates that only end-entity certificates are accepted. A value of-1indicates that no check is done.- Returns:
- the value of the criterion.
-
setPolicy
Sets the criterion for the policy constraint.The certificate must have at least one of the specified certificate policy extensions. For an empty set the certificate must have at least some policies in its policy extension.
- Parameters:
policies- the certificate policy OIDs, an empty set, ornullto not perform this check.- Throws:
IOException- if parsing the specified OIDs fails.
-
getPolicy
Returns the criterion for the policy constraint.The certificate must have at least one of the certificate policy extensions. For an empty set the certificate must have at least some policies in its policy extension.
- Returns:
- the certificate policy OIDs, an empty set, or
nullif not to be checked.
-
addPathToName
Adds a "pathToName" to the respective criterion.- Parameters:
type- the type of the name.name- the name in string format.- Throws:
IOException- if parsing fails.- See Also:
setPathToNames(java.util.Collection<java.util.List<?>>)
-
setPathToNames
Sets the criterion for the pathToNames constraint.This allows to specify the complete set of names, a certificate's name constraints must permit.
The specified parameter
namesis a collection with an entry for each name to be included in the criterion. The name is specified as aList, the first entry must be anIntegerspecifying the name type (0-8), the second entry must be aStringor a byte array specifying the name (in string or ASN.1 DER encoded form)- Parameters:
names- the names collection ornullto not perform this check.- Throws:
IOException- if decoding fails.
-
addPathToName
Adds a "pathToName" to the respective criterion.- Parameters:
type- the type of the namename- the name in ASN.1 DER encoded form.- Throws:
IOException- if decoding fails.- See Also:
setPathToNames(java.util.Collection<java.util.List<?>>)
-
getPathToNames
Returns the criterion for the pathToNames constraint.The constraint is a collection with an entry for each name to be included in the criterion. The name is specified as a
List, the first entry is anIntegerspecifying the name type (0-8), the second entry is a byte array specifying the name in ASN.1 DER encoded form.- Returns:
- the pathToNames constraint or
nullif none specified.
-
toString
Returns a string representation of thisX509CertSelectorinstance. -
match
Returns whether the specified certificate matches all the criteria collected in this instance.- Specified by:
matchin interfaceCertSelector- Parameters:
certificate- the certificate to check.- Returns:
trueif the certificate matches all the criteria, otherwisefalse.
-
clone
Clones thisX509CertSelectorinstance.- Specified by:
clonein interfaceCertSelector- Overrides:
clonein classObject- Returns:
- the cloned instance.
-