Top Fields Constructors Methods
org.bouncycastle.pkix

pack-priv Class ASN1PKIXNameConstraintValidator

extends Object
implements NameConstraintValidator
Class Inheritance
All Implemented Interfaces
org.bouncycastle.asn1.x509.NameConstraintValidator
Imports
java.io.IOException, java.util.Collection, .Collections, .HashMap, .HashSet, .Iterator, .Map, .Set, org.bouncycastle.asn1.ASN1OctetString, .ASN1Sequence, .DERIA5String, org.bouncycastle.asn1.x500.RDN, .X500Name, org.bouncycastle.asn1.x500.style.IETFUtils, .RFC4519Style, org.bouncycastle.asn1.x509.GeneralName, .GeneralSubtree, .NameConstraintValidator, .NameConstraintValidatorException, .OtherName, org.bouncycastle.util.Arrays, .Integers, .Strings, org.bouncycastle.util.encoders.Hex

Field Summary

Modifier and TypeField and Description
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>
private Set<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addExcludedSubtree(GeneralSubtree
A subtree with an excluded GeneralName.
subtree
)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.addExcludedSubtree.

Adds a subtree to the excluded set of these name constraints.
private final void
public void
checkExcluded(GeneralName
The GeneralName.
name
)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.checkExcluded.

Check if the given GeneralName is contained in the excluded set.
public void
private void
checkExcludedDN(Set<E> excluded, ASN1Sequence dns)

private void
checkExcludedDNS(Set<E> excluded, String dns)

private void
checkExcludedEmail(Set<E> excluded, String email)

private void
checkExcludedIP(Set<E>
A Set of excluded IP addresses with their subnet mask as byte arrays.
excluded
,
byte[]
The IP address.
ip
)

Checks if the IP ip is included in the excluded set excluded.

private void
private void
checkExcludedURI(Set<E> excluded, String uri)

public void
checkPermitted(GeneralName
The GeneralName
name
)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.checkPermitted.

Checks if the given GeneralName is in the permitted set.
public void
private void
checkPermittedDN(Set<E> permitted, ASN1Sequence dns)

private void
checkPermittedDNS(Set<E> permitted, String dns)

private void
checkPermittedEmail(Set<E> permitted, String email)

private void
checkPermittedIP(Set<E>
A Set of permitted IP addresses with their subnet mask as byte arrays.
permitted
,
byte[]
The IP address.
ip
)

Checks if the IP ip is included in the permitted set permitted.

private void
private void
checkPermittedURI(Set<E> permitted, String uri)

private boolean
private static int

Returns:

0 if ip1 is equal to ip2, 1 if ip1 is bigger, -1 otherwise.
compareTo
(byte[]
The first IP address.
ip1
,
byte[]
The second IP address.
ip2
)

Compares IP address ip1 with ip2.

private boolean
emailIsConstrained(String email, String constraint)

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private boolean
private static String
private byte[][]

Returns:

An array with two elements. Each element contains the IP address and the subnet mask in this order.
extractIPsAndSubnetMasks
(byte[]
The first IP address with the subnet mask.
ipWithSubmask1
,
byte[]
The second IP address with the subnet mask.
ipWithSubmask2
)

Splits the IP addresses and their subnet mask.

private String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
private int
private Set<E>
intersectDN(Set<E> permitted, Set<E> dns)

private Set<E>
intersectDNS(Set<E> permitted, Set<E> dnss)

private Set<E>
intersectEmail(Set<E> permitted, Set<E> emails)

private void
intersectEmail(String
Email address constraint 1.
email1
,
String
Email address constraint 2.
email2
,
Set<E>
The intersection.
intersect
)

The most restricting part from email1 and email2 is added to the intersection intersect.

public void
private Set<E>

Returns:

The Set of permitted IP ranges intersected with ip.
intersectIP
(Set<E>
A Set of permitted IP addresses with their subnet mask as byte arrays.
permitted
,
Set<E>
The IP address with its subnet mask.
ips
)

Returns the intersection of the permitted IP ranges in permitted with ip.

private Set<E>

Returns:

A Set with the single IP address with its subnet mask as a byte array or an empty Set.
intersectIPRange
(byte[]
The first IP address with its subnet mask.
ipWithSubmask1
,
byte[]
The second IP address with its subnet mask.
ipWithSubmask2
)

Calculates the intersection if two IP ranges.

private Set<E>
intersectOtherName(Set<E> permitted, Set<E> otherNames)

public void
public void
intersectPermittedSubtree(GeneralSubtree[]
The permitted subtrees
permitted
)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.intersectPermittedSubtree.

Updates the permitted set of these name constraints with the intersection with the given subtree.
private Set<E>
intersectURI(Set<E> permitted, Set<E> uris)

private void
intersectURI(String email1, String email2, Set<E> intersect)

private byte[]

Returns:

The concatenated IP address with its subnet mask.
ipWithSubnetMask
(byte[]
The IP address.
ip
,
byte[]
Its subnet mask.
subnetMask
)

Concatenates the IP address with its subnet mask.

private boolean

Returns:

true if constrained, false otherwise.
isIPConstrained
(byte[]
The IP address.
ip
,
byte[]
The constraint. This is an IP address concatenated with its subnetmask.
constraint
)

Checks if the IP address ip is constrained by constraint.

private boolean
isUriConstrained(String uri, String constraint)

private static byte[]

Returns:

The maximum IP address.
max
(byte[]
The first IP address.
ip1
,
byte[]
The second IP address.
ip2
)

Returns the maximum IP address.

private static byte[]

Returns:

The minimum IP address.
min
(byte[]
The first IP address.
ip1
,
byte[]
The second IP address.
ip2
)

Returns the minimum IP address.

private byte[][]

Returns:

A array with two elements. The first/second element contains the min and max IP address of the first/second IP address and its subnet mask.
minMaxIPs
(byte[]
The first IP address.
ip1
,
byte[]
The subnet mask of the first IP address.
subnetmask1
,
byte[]
The second IP address.
ip2
,
byte[]
The subnet mask of the second IP address.
subnetmask2
)

Based on the two IP addresses and their subnet masks the IP range is computed for each IP address - subnet mask pair and returned as the minimum IP address and the maximum address of the range.

private static byte[]

Returns:

The OR of ip1 and ip2.
or
(byte[]
The first IP address.
ip1
,
byte[]
The second IP address.
ip2
)

Returns the logical OR of the IP addresses ip1 and ip2.

private boolean
private String

Returns:

The stringified IP address.
stringifyIP
(byte[]
The IP with subnet mask.
ip
)

Stringifies an IPv4 or v6 address with subnet mask.

private String
private String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private Set<E>
unionDN(Set<E> excluded, ASN1Sequence dn)

private Set<E>
unionDNS(Set<E> excluded, String dns)

private Set<E>
unionEmail(Set<E> excluded, String email)

private void
unionEmail(String
Email address constraint 1.
email1
,
String
Email address constraint 2.
email2
,
Set<E>
The union.
union
)

The common part of email1 and email2 is added to the union union.

private Set<E>

Returns:

The Set of excluded IP ranges unified with ip as byte arrays.
unionIP
(Set<E>
A Set of excluded IP addresses with their subnet mask as byte arrays.
excluded
,
byte[]
The IP address with its subnet mask.
ip
)

Returns the union of the excluded IP ranges in excluded with ip.

private Set<E>

Returns:

A Set with the union of both addresses.
unionIPRange
(byte[]
The first IP address with its subnet mask.
ipWithSubmask1
,
byte[]
The second IP address with its subnet mask.
ipWithSubmask2
)

Calculates the union if two IP ranges.

private Set<E>
unionOtherName(Set<E> permitted, OtherName otherName)

private void
unionURI(String email1, String email2, Set<E> union)

private Set<E>
unionURI(Set<E> excluded, String uri)

private static boolean
private boolean
withinDomain(String testDomain, String domain)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

excludedSubtreesDNback to summary
private Set<E> excludedSubtreesDN
excludedSubtreesDNSback to summary
private Set<E> excludedSubtreesDNS
excludedSubtreesEmailback to summary
private Set<E> excludedSubtreesEmail
excludedSubtreesIPback to summary
private Set<E> excludedSubtreesIP
excludedSubtreesOtherNameback to summary
private Set<E> excludedSubtreesOtherName
excludedSubtreesURIback to summary
private Set<E> excludedSubtreesURI
permittedSubtreesDNback to summary
private Set<E> permittedSubtreesDN
permittedSubtreesDNSback to summary
private Set<E> permittedSubtreesDNS
permittedSubtreesEmailback to summary
private Set<E> permittedSubtreesEmail
permittedSubtreesIPback to summary
private Set<E> permittedSubtreesIP
permittedSubtreesOtherNameback to summary
private Set<E> permittedSubtreesOtherName
permittedSubtreesURIback to summary
private Set<E> permittedSubtreesURI

Constructor Detail

ASN1PKIXNameConstraintValidatorback to summary
public ASN1PKIXNameConstraintValidator()

Method Detail

addExcludedSubtreeback to summary
public void addExcludedSubtree(GeneralSubtree subtree)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.addExcludedSubtree.

Adds a subtree to the excluded set of these name constraints.

Parameters
subtree:GeneralSubtree

A subtree with an excluded GeneralName.

addLineback to summary
private final void addLine(StringBuilder sb, String str)
checkExcludedback to summary
public void checkExcluded(GeneralName name) throws NameConstraintValidatorException

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.checkExcluded.

Check if the given GeneralName is contained in the excluded set.

Parameters
name:GeneralName

The GeneralName.

Exceptions
NameConstraintValidatorException:
If the name is excluded.
checkExcludedDNback to summary
public void checkExcludedDN(X500Name dns) throws NameConstraintValidatorException
checkExcludedDNback to summary
private void checkExcludedDN(Set<E> excluded, ASN1Sequence dns) throws NameConstraintValidatorException
checkExcludedDNSback to summary
private void checkExcludedDNS(Set<E> excluded, String dns) throws NameConstraintValidatorException
checkExcludedEmailback to summary
private void checkExcludedEmail(Set<E> excluded, String email) throws NameConstraintValidatorException
checkExcludedIPback to summary
private void checkExcludedIP(Set<E> excluded, byte[] ip) throws NameConstraintValidatorException

Checks if the IP ip is included in the excluded set excluded.

Parameters
excluded:Set<E>

A Set of excluded IP addresses with their subnet mask as byte arrays.

ip:byte[]

The IP address.

Exceptions
NameConstraintValidatorException:
if the IP is excluded.
checkExcludedOtherNameback to summary
private void checkExcludedOtherName(Set<E> excluded, OtherName name) throws NameConstraintValidatorException
checkExcludedURIback to summary
private void checkExcludedURI(Set<E> excluded, String uri) throws NameConstraintValidatorException
checkPermittedback to summary
public void checkPermitted(GeneralName name) throws NameConstraintValidatorException

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.checkPermitted.

Checks if the given GeneralName is in the permitted set.

Parameters
name:GeneralName

The GeneralName

Exceptions
NameConstraintValidatorException:
If the name
checkPermittedDNback to summary
public void checkPermittedDN(X500Name dns) throws NameConstraintValidatorException
checkPermittedDNback to summary
private void checkPermittedDN(Set<E> permitted, ASN1Sequence dns) throws NameConstraintValidatorException
checkPermittedDNSback to summary
private void checkPermittedDNS(Set<E> permitted, String dns) throws NameConstraintValidatorException
checkPermittedEmailback to summary
private void checkPermittedEmail(Set<E> permitted, String email) throws NameConstraintValidatorException
checkPermittedIPback to summary
private void checkPermittedIP(Set<E> permitted, byte[] ip) throws NameConstraintValidatorException

Checks if the IP ip is included in the permitted set permitted.

Parameters
permitted:Set<E>

A Set of permitted IP addresses with their subnet mask as byte arrays.

ip:byte[]

The IP address.

Exceptions
NameConstraintValidatorException:
if the IP is not permitted.
checkPermittedOtherNameback to summary
private void checkPermittedOtherName(Set<E> permitted, OtherName name) throws NameConstraintValidatorException
checkPermittedURIback to summary
private void checkPermittedURI(Set<E> permitted, String uri) throws NameConstraintValidatorException
collectionsAreEqualback to summary
private boolean collectionsAreEqual(Collection<E> coll1, Collection<E> coll2)
compareToback to summary
private static int compareTo(byte[] ip1, byte[] ip2)

Compares IP address ip1 with ip2. If ip1 is equal to ip2 0 is returned. If ip1 is bigger 1 is returned, -1 otherwise.

Parameters
ip1:byte[]

The first IP address.

ip2:byte[]

The second IP address.

Returns:int

0 if ip1 is equal to ip2, 1 if ip1 is bigger, -1 otherwise.

emailIsConstrainedback to summary
private boolean emailIsConstrained(String email, String constraint)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

equalsback to summary
private boolean equals(Object o1, Object o2)
extractHostFromURLback to summary
private static String extractHostFromURL(String url)
extractIPsAndSubnetMasksback to summary
private byte[][] extractIPsAndSubnetMasks(byte[] ipWithSubmask1, byte[] ipWithSubmask2)

Splits the IP addresses and their subnet mask.

Parameters
ipWithSubmask1:byte[]

The first IP address with the subnet mask.

ipWithSubmask2:byte[]

The second IP address with the subnet mask.

Returns:byte[][]

An array with two elements. Each element contains the IP address and the subnet mask in this order.

extractNameAsStringback to summary
private String extractNameAsString(GeneralName name)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

hashCollectionback to summary
private int hashCollection(Collection<E> coll)
intersectDNback to summary
private Set<E> intersectDN(Set<E> permitted, Set<E> dns)
intersectDNSback to summary
private Set<E> intersectDNS(Set<E> permitted, Set<E> dnss)
intersectEmailback to summary
private Set<E> intersectEmail(Set<E> permitted, Set<E> emails)
intersectEmailback to summary
private void intersectEmail(String email1, String email2, Set<E> intersect)

The most restricting part from email1 and email2 is added to the intersection intersect.

Parameters
email1:String

Email address constraint 1.

email2:String

Email address constraint 2.

intersect:Set<E>

The intersection.

intersectEmptyPermittedSubtreeback to summary
public void intersectEmptyPermittedSubtree(int nameType)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.intersectEmptyPermittedSubtree.

intersectIPback to summary
private Set<E> intersectIP(Set<E> permitted, Set<E> ips)

Returns the intersection of the permitted IP ranges in permitted with ip.

Parameters
permitted:Set<E>

A Set of permitted IP addresses with their subnet mask as byte arrays.

ips:Set<E>

The IP address with its subnet mask.

Returns:Set<E>

The Set of permitted IP ranges intersected with ip.

intersectIPRangeback to summary
private Set<E> intersectIPRange(byte[] ipWithSubmask1, byte[] ipWithSubmask2)

Calculates the intersection if two IP ranges.

Parameters
ipWithSubmask1:byte[]

The first IP address with its subnet mask.

ipWithSubmask2:byte[]

The second IP address with its subnet mask.

Returns:Set<E>

A Set with the single IP address with its subnet mask as a byte array or an empty Set.

intersectOtherNameback to summary
private Set<E> intersectOtherName(Set<E> permitted, Set<E> otherNames)
intersectPermittedSubtreeback to summary
public void intersectPermittedSubtree(GeneralSubtree permitted)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.intersectPermittedSubtree.

intersectPermittedSubtreeback to summary
public void intersectPermittedSubtree(GeneralSubtree[] permitted)

Implements org.bouncycastle.asn1.x509.NameConstraintValidator.intersectPermittedSubtree.

Updates the permitted set of these name constraints with the intersection with the given subtree.

Parameters
permitted:GeneralSubtree[]

The permitted subtrees

intersectURIback to summary
private Set<E> intersectURI(Set<E> permitted, Set<E> uris)
intersectURIback to summary
private void intersectURI(String email1, String email2, Set<E> intersect)
ipWithSubnetMaskback to summary
private byte[] ipWithSubnetMask(byte[] ip, byte[] subnetMask)

Concatenates the IP address with its subnet mask.

Parameters
ip:byte[]

The IP address.

subnetMask:byte[]

Its subnet mask.

Returns:byte[]

The concatenated IP address with its subnet mask.

isIPConstrainedback to summary
private boolean isIPConstrained(byte[] ip, byte[] constraint)

Checks if the IP address ip is constrained by constraint.

Parameters
ip:byte[]

The IP address.

constraint:byte[]

The constraint. This is an IP address concatenated with its subnetmask.

Returns:boolean

true if constrained, false otherwise.

isUriConstrainedback to summary
private boolean isUriConstrained(String uri, String constraint)
maxback to summary
private static byte[] max(byte[] ip1, byte[] ip2)

Returns the maximum IP address.

Parameters
ip1:byte[]

The first IP address.

ip2:byte[]

The second IP address.

Returns:byte[]

The maximum IP address.

minback to summary
private static byte[] min(byte[] ip1, byte[] ip2)

Returns the minimum IP address.

Parameters
ip1:byte[]

The first IP address.

ip2:byte[]

The second IP address.

Returns:byte[]

The minimum IP address.

minMaxIPsback to summary
private byte[][] minMaxIPs(byte[] ip1, byte[] subnetmask1, byte[] ip2, byte[] subnetmask2)

Based on the two IP addresses and their subnet masks the IP range is computed for each IP address - subnet mask pair and returned as the minimum IP address and the maximum address of the range.

Parameters
ip1:byte[]

The first IP address.

subnetmask1:byte[]

The subnet mask of the first IP address.

ip2:byte[]

The second IP address.

subnetmask2:byte[]

The subnet mask of the second IP address.

Returns:byte[][]

A array with two elements. The first/second element contains the min and max IP address of the first/second IP address and its subnet mask.

orback to summary
private static byte[] or(byte[] ip1, byte[] ip2)

Returns the logical OR of the IP addresses ip1 and ip2.

Parameters
ip1:byte[]

The first IP address.

ip2:byte[]

The second IP address.

Returns:byte[]

The OR of ip1 and ip2.

otherNameIsConstrainedback to summary
private boolean otherNameIsConstrained(OtherName name, OtherName constraint)
stringifyIPback to summary
private String stringifyIP(byte[] ip)

Stringifies an IPv4 or v6 address with subnet mask.

Parameters
ip:byte[]

The IP with subnet mask.

Returns:String

The stringified IP address.

stringifyIPCollectionback to summary
private String stringifyIPCollection(Set<E> ips)
stringifyOtherNameCollectionback to summary
private String stringifyOtherNameCollection(Set<E> otherNames)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

unionDNback to summary
private Set<E> unionDN(Set<E> excluded, ASN1Sequence dn)
unionDNSback to summary
private Set<E> unionDNS(Set<E> excluded, String dns)
unionEmailback to summary
private Set<E> unionEmail(Set<E> excluded, String email)
unionEmailback to summary
private void unionEmail(String email1, String email2, Set<E> union)

The common part of email1 and email2 is added to the union union. If email1 and email2 have nothing in common they are added both.

Parameters
email1:String

Email address constraint 1.

email2:String

Email address constraint 2.

union:Set<E>

The union.

unionIPback to summary
private Set<E> unionIP(Set<E> excluded, byte[] ip)

Returns the union of the excluded IP ranges in excluded with ip.

Parameters
excluded:Set<E>

A Set of excluded IP addresses with their subnet mask as byte arrays.

ip:byte[]

The IP address with its subnet mask.

Returns:Set<E>

The Set of excluded IP ranges unified with ip as byte arrays.

unionIPRangeback to summary
private Set<E> unionIPRange(byte[] ipWithSubmask1, byte[] ipWithSubmask2)

Calculates the union if two IP ranges.

Parameters
ipWithSubmask1:byte[]

The first IP address with its subnet mask.

ipWithSubmask2:byte[]

The second IP address with its subnet mask.

Returns:Set<E>

A Set with the union of both addresses.

unionOtherNameback to summary
private Set<E> unionOtherName(Set<E> permitted, OtherName otherName)
unionURIback to summary
private void unionURI(String email1, String email2, Set<E> union)
unionURIback to summary
private Set<E> unionURI(Set<E> excluded, String uri)
withinDNSubtreeback to summary
private static boolean withinDNSubtree(ASN1Sequence dns, ASN1Sequence subtree)
withinDomainback to summary
private boolean withinDomain(String testDomain, String domain)