what-the-bank/sources/org/bouncycastle/jce/provider/PKIXNameConstraintValidator...

1214 lines
44 KiB
Java

package org.bouncycastle.jce.provider;
import com.google.common.primitives.UnsignedBytes;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralSubtree;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Integers;
import org.bouncycastle.util.Strings;
/* loaded from: classes6.dex */
public class PKIXNameConstraintValidator {
private Set permittedSubtreesDN;
private Set permittedSubtreesDNS;
private Set permittedSubtreesEmail;
private Set permittedSubtreesIP;
private Set permittedSubtreesURI;
private Set excludedSubtreesDN = new HashSet();
private Set excludedSubtreesDNS = new HashSet();
private Set excludedSubtreesEmail = new HashSet();
private Set excludedSubtreesURI = new HashSet();
private Set excludedSubtreesIP = new HashSet();
protected Set unionDNS(Set set, String str) {
if (set.isEmpty()) {
if (str == null) {
return set;
}
set.add(str);
return set;
}
HashSet hashSet = new HashSet();
Iterator it = set.iterator();
while (it.hasNext()) {
String str2 = (String) it.next();
if (!withinDomain(str2, str)) {
boolean withinDomain = withinDomain(str, str2);
hashSet.add(str2);
if (withinDomain) {
}
}
hashSet.add(str);
}
return hashSet;
}
public String toString() {
String str;
if (this.permittedSubtreesDN != null) {
StringBuilder sb = new StringBuilder("permitted:\nDN:\n");
sb.append(this.permittedSubtreesDN.toString());
sb.append("\n");
str = sb.toString();
} else {
str = "permitted:\n";
}
if (this.permittedSubtreesDNS != null) {
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append("DNS:\n");
String obj = sb2.toString();
StringBuilder sb3 = new StringBuilder();
sb3.append(obj);
sb3.append(this.permittedSubtreesDNS.toString());
sb3.append("\n");
str = sb3.toString();
}
if (this.permittedSubtreesEmail != null) {
StringBuilder sb4 = new StringBuilder();
sb4.append(str);
sb4.append("Email:\n");
String obj2 = sb4.toString();
StringBuilder sb5 = new StringBuilder();
sb5.append(obj2);
sb5.append(this.permittedSubtreesEmail.toString());
sb5.append("\n");
str = sb5.toString();
}
if (this.permittedSubtreesURI != null) {
StringBuilder sb6 = new StringBuilder();
sb6.append(str);
sb6.append("URI:\n");
String obj3 = sb6.toString();
StringBuilder sb7 = new StringBuilder();
sb7.append(obj3);
sb7.append(this.permittedSubtreesURI.toString());
sb7.append("\n");
str = sb7.toString();
}
if (this.permittedSubtreesIP != null) {
StringBuilder sb8 = new StringBuilder();
sb8.append(str);
sb8.append("IP:\n");
String obj4 = sb8.toString();
StringBuilder sb9 = new StringBuilder();
sb9.append(obj4);
sb9.append(stringifyIPCollection(this.permittedSubtreesIP));
sb9.append("\n");
str = sb9.toString();
}
StringBuilder sb10 = new StringBuilder();
sb10.append(str);
sb10.append("excluded:\n");
String obj5 = sb10.toString();
if (!this.excludedSubtreesDN.isEmpty()) {
StringBuilder sb11 = new StringBuilder();
sb11.append(obj5);
sb11.append("DN:\n");
String obj6 = sb11.toString();
StringBuilder sb12 = new StringBuilder();
sb12.append(obj6);
sb12.append(this.excludedSubtreesDN.toString());
sb12.append("\n");
obj5 = sb12.toString();
}
if (!this.excludedSubtreesDNS.isEmpty()) {
StringBuilder sb13 = new StringBuilder();
sb13.append(obj5);
sb13.append("DNS:\n");
String obj7 = sb13.toString();
StringBuilder sb14 = new StringBuilder();
sb14.append(obj7);
sb14.append(this.excludedSubtreesDNS.toString());
sb14.append("\n");
obj5 = sb14.toString();
}
if (!this.excludedSubtreesEmail.isEmpty()) {
StringBuilder sb15 = new StringBuilder();
sb15.append(obj5);
sb15.append("Email:\n");
String obj8 = sb15.toString();
StringBuilder sb16 = new StringBuilder();
sb16.append(obj8);
sb16.append(this.excludedSubtreesEmail.toString());
sb16.append("\n");
obj5 = sb16.toString();
}
if (!this.excludedSubtreesURI.isEmpty()) {
StringBuilder sb17 = new StringBuilder();
sb17.append(obj5);
sb17.append("URI:\n");
String obj9 = sb17.toString();
StringBuilder sb18 = new StringBuilder();
sb18.append(obj9);
sb18.append(this.excludedSubtreesURI.toString());
sb18.append("\n");
obj5 = sb18.toString();
}
if (this.excludedSubtreesIP.isEmpty()) {
return obj5;
}
StringBuilder sb19 = new StringBuilder();
sb19.append(obj5);
sb19.append("IP:\n");
String obj10 = sb19.toString();
StringBuilder sb20 = new StringBuilder();
sb20.append(obj10);
sb20.append(stringifyIPCollection(this.excludedSubtreesIP));
sb20.append("\n");
return sb20.toString();
}
public void intersectPermittedSubtree(GeneralSubtree[] generalSubtreeArr) {
HashMap hashMap = new HashMap();
for (int i = 0; i != generalSubtreeArr.length; i++) {
GeneralSubtree generalSubtree = generalSubtreeArr[i];
Integer valueOf = Integers.valueOf(generalSubtree.getBase().getTagNo());
if (hashMap.get(valueOf) == null) {
hashMap.put(valueOf, new HashSet());
}
((Set) hashMap.get(valueOf)).add(generalSubtree);
}
for (Map.Entry entry : hashMap.entrySet()) {
int intValue = ((Integer) entry.getKey()).intValue();
if (intValue == 1) {
this.permittedSubtreesEmail = intersectEmail(this.permittedSubtreesEmail, (Set) entry.getValue());
} else if (intValue == 2) {
this.permittedSubtreesDNS = intersectDNS(this.permittedSubtreesDNS, (Set) entry.getValue());
} else if (intValue == 4) {
this.permittedSubtreesDN = intersectDN(this.permittedSubtreesDN, (Set) entry.getValue());
} else if (intValue == 6) {
this.permittedSubtreesURI = intersectURI(this.permittedSubtreesURI, (Set) entry.getValue());
} else if (intValue == 7) {
this.permittedSubtreesIP = intersectIP(this.permittedSubtreesIP, (Set) entry.getValue());
}
}
}
public void intersectPermittedSubtree(GeneralSubtree generalSubtree) {
intersectPermittedSubtree(new GeneralSubtree[]{generalSubtree});
}
public void intersectEmptyPermittedSubtree(int i) {
if (i == 1) {
this.permittedSubtreesEmail = new HashSet();
return;
}
if (i == 2) {
this.permittedSubtreesDNS = new HashSet();
return;
}
if (i == 4) {
this.permittedSubtreesDN = new HashSet();
} else if (i == 6) {
this.permittedSubtreesURI = new HashSet();
} else if (i == 7) {
this.permittedSubtreesIP = new HashSet();
}
}
public int hashCode() {
return hashCollection(this.excludedSubtreesDN) + hashCollection(this.excludedSubtreesDNS) + hashCollection(this.excludedSubtreesEmail) + hashCollection(this.excludedSubtreesIP) + hashCollection(this.excludedSubtreesURI) + hashCollection(this.permittedSubtreesDN) + hashCollection(this.permittedSubtreesDNS) + hashCollection(this.permittedSubtreesEmail) + hashCollection(this.permittedSubtreesIP) + hashCollection(this.permittedSubtreesURI);
}
public boolean equals(Object obj) {
if (!(obj instanceof PKIXNameConstraintValidator)) {
return false;
}
PKIXNameConstraintValidator pKIXNameConstraintValidator = (PKIXNameConstraintValidator) obj;
return collectionsAreEqual(pKIXNameConstraintValidator.excludedSubtreesDN, this.excludedSubtreesDN) && collectionsAreEqual(pKIXNameConstraintValidator.excludedSubtreesDNS, this.excludedSubtreesDNS) && collectionsAreEqual(pKIXNameConstraintValidator.excludedSubtreesEmail, this.excludedSubtreesEmail) && collectionsAreEqual(pKIXNameConstraintValidator.excludedSubtreesIP, this.excludedSubtreesIP) && collectionsAreEqual(pKIXNameConstraintValidator.excludedSubtreesURI, this.excludedSubtreesURI) && collectionsAreEqual(pKIXNameConstraintValidator.permittedSubtreesDN, this.permittedSubtreesDN) && collectionsAreEqual(pKIXNameConstraintValidator.permittedSubtreesDNS, this.permittedSubtreesDNS) && collectionsAreEqual(pKIXNameConstraintValidator.permittedSubtreesEmail, this.permittedSubtreesEmail) && collectionsAreEqual(pKIXNameConstraintValidator.permittedSubtreesIP, this.permittedSubtreesIP) && collectionsAreEqual(pKIXNameConstraintValidator.permittedSubtreesURI, this.permittedSubtreesURI);
}
public void checkPermittedDN(ASN1Sequence aSN1Sequence) throws PKIXNameConstraintValidatorException {
checkPermittedDN(this.permittedSubtreesDN, aSN1Sequence);
}
public void checkPermitted(GeneralName generalName) throws PKIXNameConstraintValidatorException {
int tagNo = generalName.getTagNo();
if (tagNo == 1) {
checkPermittedEmail(this.permittedSubtreesEmail, extractNameAsString(generalName));
return;
}
if (tagNo == 2) {
checkPermittedDNS(this.permittedSubtreesDNS, DERIA5String.getInstance(generalName.getName()).getString());
return;
}
if (tagNo == 4) {
checkPermittedDN(ASN1Sequence.getInstance(generalName.getName().toASN1Primitive()));
return;
}
if (tagNo == 6) {
checkPermittedURI(this.permittedSubtreesURI, DERIA5String.getInstance(generalName.getName()).getString());
} else if (tagNo == 7) {
checkPermittedIP(this.permittedSubtreesIP, ASN1OctetString.getInstance(generalName.getName()).getOctets());
}
}
public void checkExcludedDN(ASN1Sequence aSN1Sequence) throws PKIXNameConstraintValidatorException {
checkExcludedDN(this.excludedSubtreesDN, aSN1Sequence);
}
public void checkExcluded(GeneralName generalName) throws PKIXNameConstraintValidatorException {
int tagNo = generalName.getTagNo();
if (tagNo == 1) {
checkExcludedEmail(this.excludedSubtreesEmail, extractNameAsString(generalName));
return;
}
if (tagNo == 2) {
checkExcludedDNS(this.excludedSubtreesDNS, DERIA5String.getInstance(generalName.getName()).getString());
return;
}
if (tagNo == 4) {
checkExcludedDN(ASN1Sequence.getInstance(generalName.getName().toASN1Primitive()));
return;
}
if (tagNo == 6) {
checkExcludedURI(this.excludedSubtreesURI, DERIA5String.getInstance(generalName.getName()).getString());
} else if (tagNo == 7) {
checkExcludedIP(this.excludedSubtreesIP, ASN1OctetString.getInstance(generalName.getName()).getOctets());
}
}
public void addExcludedSubtree(GeneralSubtree generalSubtree) {
GeneralName base = generalSubtree.getBase();
int tagNo = base.getTagNo();
if (tagNo == 1) {
this.excludedSubtreesEmail = unionEmail(this.excludedSubtreesEmail, extractNameAsString(base));
return;
}
if (tagNo == 2) {
this.excludedSubtreesDNS = unionDNS(this.excludedSubtreesDNS, extractNameAsString(base));
return;
}
if (tagNo == 4) {
this.excludedSubtreesDN = unionDN(this.excludedSubtreesDN, (ASN1Sequence) base.getName().toASN1Primitive());
} else if (tagNo == 6) {
this.excludedSubtreesURI = unionURI(this.excludedSubtreesURI, extractNameAsString(base));
} else if (tagNo == 7) {
this.excludedSubtreesIP = unionIP(this.excludedSubtreesIP, ASN1OctetString.getInstance(base.getName()).getOctets());
}
}
private boolean withinDomain(String str, String str2) {
if (str2.startsWith(".")) {
str2 = str2.substring(1);
}
String[] split = Strings.split(str2, '.');
String[] split2 = Strings.split(str, '.');
if (split2.length <= split.length) {
return false;
}
int length = split2.length - split.length;
for (int i = -1; i < split.length; i++) {
if (i == -1) {
if (split2[i + length].equals("")) {
return false;
}
} else if (!split[i].equalsIgnoreCase(split2[i + length])) {
return false;
}
}
return true;
}
private static boolean withinDNSubtree(ASN1Sequence aSN1Sequence, ASN1Sequence aSN1Sequence2) {
if (aSN1Sequence2.size() <= 0 || aSN1Sequence2.size() > aSN1Sequence.size()) {
return false;
}
for (int size = aSN1Sequence2.size() - 1; size >= 0; size--) {
if (!aSN1Sequence2.getObjectAt(size).equals(aSN1Sequence.getObjectAt(size))) {
return false;
}
}
return true;
}
/* JADX WARN: Code restructure failed: missing block: B:11:0x00a0, code lost:
r7.add(r5);
*/
/* JADX WARN: Code restructure failed: missing block: B:12:0x00a3, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:24:0x0053, code lost:
if (withinDomain(r6.substring(r5.indexOf(64) + 1), r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:32:0x006c, code lost:
if (withinDomain(r6, r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:34:0x0073, code lost:
if (withinDomain(r6, r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:38:0x008a, code lost:
if (r6.substring(r5.indexOf(64) + 1).equalsIgnoreCase(r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:42:0x0097, code lost:
if (withinDomain(r5, r6) != false) goto L51;
*/
/* JADX WARN: Code restructure failed: missing block: B:44:0x009e, code lost:
if (r5.equalsIgnoreCase(r6) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:6:0x001f, code lost:
if (r5.equalsIgnoreCase(r6) != false) goto L48;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private void unionURI(java.lang.String r5, java.lang.String r6, java.util.Set r7) {
/*
r4 = this;
r0 = 64
int r1 = r5.indexOf(r0)
java.lang.String r2 = "."
r3 = -1
if (r1 == r3) goto L39
int r1 = r5.indexOf(r0)
int r1 = r1 + 1
java.lang.String r1 = r5.substring(r1)
int r0 = r6.indexOf(r0)
if (r0 == r3) goto L23
boolean r0 = r5.equalsIgnoreCase(r6)
if (r0 == 0) goto La4
goto La0
L23:
boolean r0 = r6.startsWith(r2)
if (r0 == 0) goto L31
boolean r0 = r4.withinDomain(r1, r6)
if (r0 == 0) goto La4
goto La7
L31:
boolean r0 = r1.equalsIgnoreCase(r6)
if (r0 == 0) goto La4
goto La7
L39:
boolean r1 = r5.startsWith(r2)
if (r1 == 0) goto L76
int r1 = r6.indexOf(r0)
if (r1 == r3) goto L56
int r0 = r5.indexOf(r0)
int r0 = r0 + 1
java.lang.String r0 = r6.substring(r0)
boolean r0 = r4.withinDomain(r0, r5)
if (r0 == 0) goto La4
goto La0
L56:
boolean r0 = r6.startsWith(r2)
if (r0 == 0) goto L6f
boolean r0 = r4.withinDomain(r5, r6)
if (r0 != 0) goto La7
boolean r0 = r5.equalsIgnoreCase(r6)
if (r0 != 0) goto La7
boolean r0 = r4.withinDomain(r6, r5)
if (r0 == 0) goto La4
goto La0
L6f:
boolean r0 = r4.withinDomain(r6, r5)
if (r0 == 0) goto La4
goto La0
L76:
int r1 = r6.indexOf(r0)
if (r1 == r3) goto L8d
int r0 = r5.indexOf(r0)
int r0 = r0 + 1
java.lang.String r0 = r6.substring(r0)
boolean r0 = r0.equalsIgnoreCase(r5)
if (r0 == 0) goto La4
goto La0
L8d:
boolean r0 = r6.startsWith(r2)
if (r0 == 0) goto L9a
boolean r0 = r4.withinDomain(r5, r6)
if (r0 == 0) goto La4
goto La7
L9a:
boolean r0 = r5.equalsIgnoreCase(r6)
if (r0 == 0) goto La4
La0:
r7.add(r5)
return
La4:
r7.add(r5)
La7:
r7.add(r6)
return
*/
throw new UnsupportedOperationException("Method not decompiled: org.bouncycastle.jce.provider.PKIXNameConstraintValidator.unionURI(java.lang.String, java.lang.String, java.util.Set):void");
}
private Set unionURI(Set set, String str) {
if (set.isEmpty()) {
if (str == null) {
return set;
}
set.add(str);
return set;
}
HashSet hashSet = new HashSet();
Iterator it = set.iterator();
while (it.hasNext()) {
unionURI((String) it.next(), str, hashSet);
}
return hashSet;
}
private Set unionIPRange(byte[] bArr, byte[] bArr2) {
HashSet hashSet = new HashSet();
boolean areEqual = Arrays.areEqual(bArr, bArr2);
hashSet.add(bArr);
if (!areEqual) {
hashSet.add(bArr2);
}
return hashSet;
}
private Set unionIP(Set set, byte[] bArr) {
if (set.isEmpty()) {
if (bArr == null) {
return set;
}
set.add(bArr);
return set;
}
HashSet hashSet = new HashSet();
Iterator it = set.iterator();
while (it.hasNext()) {
hashSet.addAll(unionIPRange((byte[]) it.next(), bArr));
}
return hashSet;
}
/* JADX WARN: Code restructure failed: missing block: B:11:0x00a0, code lost:
r7.add(r5);
*/
/* JADX WARN: Code restructure failed: missing block: B:12:0x00a3, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:24:0x0053, code lost:
if (withinDomain(r6.substring(r5.indexOf(64) + 1), r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:32:0x006c, code lost:
if (withinDomain(r6, r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:34:0x0073, code lost:
if (withinDomain(r6, r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:38:0x008a, code lost:
if (r6.substring(r5.indexOf(64) + 1).equalsIgnoreCase(r5) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:42:0x0097, code lost:
if (withinDomain(r5, r6) != false) goto L51;
*/
/* JADX WARN: Code restructure failed: missing block: B:44:0x009e, code lost:
if (r5.equalsIgnoreCase(r6) != false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:6:0x001f, code lost:
if (r5.equalsIgnoreCase(r6) != false) goto L48;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private void unionEmail(java.lang.String r5, java.lang.String r6, java.util.Set r7) {
/*
r4 = this;
r0 = 64
int r1 = r5.indexOf(r0)
java.lang.String r2 = "."
r3 = -1
if (r1 == r3) goto L39
int r1 = r5.indexOf(r0)
int r1 = r1 + 1
java.lang.String r1 = r5.substring(r1)
int r0 = r6.indexOf(r0)
if (r0 == r3) goto L23
boolean r0 = r5.equalsIgnoreCase(r6)
if (r0 == 0) goto La4
goto La0
L23:
boolean r0 = r6.startsWith(r2)
if (r0 == 0) goto L31
boolean r0 = r4.withinDomain(r1, r6)
if (r0 == 0) goto La4
goto La7
L31:
boolean r0 = r1.equalsIgnoreCase(r6)
if (r0 == 0) goto La4
goto La7
L39:
boolean r1 = r5.startsWith(r2)
if (r1 == 0) goto L76
int r1 = r6.indexOf(r0)
if (r1 == r3) goto L56
int r0 = r5.indexOf(r0)
int r0 = r0 + 1
java.lang.String r0 = r6.substring(r0)
boolean r0 = r4.withinDomain(r0, r5)
if (r0 == 0) goto La4
goto La0
L56:
boolean r0 = r6.startsWith(r2)
if (r0 == 0) goto L6f
boolean r0 = r4.withinDomain(r5, r6)
if (r0 != 0) goto La7
boolean r0 = r5.equalsIgnoreCase(r6)
if (r0 != 0) goto La7
boolean r0 = r4.withinDomain(r6, r5)
if (r0 == 0) goto La4
goto La0
L6f:
boolean r0 = r4.withinDomain(r6, r5)
if (r0 == 0) goto La4
goto La0
L76:
int r1 = r6.indexOf(r0)
if (r1 == r3) goto L8d
int r0 = r5.indexOf(r0)
int r0 = r0 + 1
java.lang.String r0 = r6.substring(r0)
boolean r0 = r0.equalsIgnoreCase(r5)
if (r0 == 0) goto La4
goto La0
L8d:
boolean r0 = r6.startsWith(r2)
if (r0 == 0) goto L9a
boolean r0 = r4.withinDomain(r5, r6)
if (r0 == 0) goto La4
goto La7
L9a:
boolean r0 = r5.equalsIgnoreCase(r6)
if (r0 == 0) goto La4
La0:
r7.add(r5)
return
La4:
r7.add(r5)
La7:
r7.add(r6)
return
*/
throw new UnsupportedOperationException("Method not decompiled: org.bouncycastle.jce.provider.PKIXNameConstraintValidator.unionEmail(java.lang.String, java.lang.String, java.util.Set):void");
}
private Set unionEmail(Set set, String str) {
if (set.isEmpty()) {
if (str == null) {
return set;
}
set.add(str);
return set;
}
HashSet hashSet = new HashSet();
Iterator it = set.iterator();
while (it.hasNext()) {
unionEmail((String) it.next(), str, hashSet);
}
return hashSet;
}
private Set unionDN(Set set, ASN1Sequence aSN1Sequence) {
if (set.isEmpty()) {
if (aSN1Sequence == null) {
return set;
}
set.add(aSN1Sequence);
return set;
}
HashSet hashSet = new HashSet();
Iterator it = set.iterator();
while (it.hasNext()) {
ASN1Sequence aSN1Sequence2 = (ASN1Sequence) it.next();
if (withinDNSubtree(aSN1Sequence, aSN1Sequence2)) {
hashSet.add(aSN1Sequence2);
} else {
if (!withinDNSubtree(aSN1Sequence2, aSN1Sequence)) {
hashSet.add(aSN1Sequence2);
}
hashSet.add(aSN1Sequence);
}
}
return hashSet;
}
private String stringifyIPCollection(Set set) {
Iterator it = set.iterator();
String str = "[";
while (it.hasNext()) {
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.append(stringifyIP((byte[]) it.next()));
sb.append(",");
str = sb.toString();
}
if (str.length() > 1) {
str = str.substring(0, str.length() - 1);
}
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append("]");
return sb2.toString();
}
private String stringifyIP(byte[] bArr) {
String str = "";
for (int i = 0; i < bArr.length / 2; i++) {
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.append(Integer.toString(bArr[i] & UnsignedBytes.MAX_VALUE));
sb.append(".");
str = sb.toString();
}
String substring = str.substring(0, str.length() - 1);
StringBuilder sb2 = new StringBuilder();
sb2.append(substring);
sb2.append("/");
String obj = sb2.toString();
for (int length = bArr.length / 2; length < bArr.length; length++) {
StringBuilder sb3 = new StringBuilder();
sb3.append(obj);
sb3.append(Integer.toString(bArr[length] & UnsignedBytes.MAX_VALUE));
sb3.append(".");
obj = sb3.toString();
}
return obj.substring(0, obj.length() - 1);
}
private static byte[] or(byte[] bArr, byte[] bArr2) {
byte[] bArr3 = new byte[bArr.length];
for (int i = 0; i < bArr.length; i++) {
bArr3[i] = (byte) (bArr[i] | bArr2[i]);
}
return bArr3;
}
private byte[][] minMaxIPs(byte[] bArr, byte[] bArr2, byte[] bArr3, byte[] bArr4) {
int length = bArr.length;
byte[] bArr5 = new byte[length];
byte[] bArr6 = new byte[length];
byte[] bArr7 = new byte[length];
byte[] bArr8 = new byte[length];
for (int i = 0; i < length; i++) {
bArr5[i] = (byte) (bArr[i] & bArr2[i]);
byte b = bArr[i];
byte b2 = bArr2[i];
bArr6[i] = (byte) ((b & b2) | (~b2));
bArr7[i] = (byte) (bArr3[i] & bArr4[i]);
byte b3 = bArr3[i];
byte b4 = bArr4[i];
bArr8[i] = (byte) ((b3 & b4) | (~b4));
}
return new byte[][]{bArr5, bArr6, bArr7, bArr8};
}
private static byte[] min(byte[] bArr, byte[] bArr2) {
for (int i = 0; i < bArr.length; i++) {
if ((bArr[i] & UnsignedBytes.MAX_VALUE) < (65535 & bArr2[i])) {
return bArr;
}
}
return bArr2;
}
private static byte[] max(byte[] bArr, byte[] bArr2) {
for (int i = 0; i < bArr.length; i++) {
if ((bArr[i] & UnsignedBytes.MAX_VALUE) > (65535 & bArr2[i])) {
return bArr;
}
}
return bArr2;
}
private boolean isUriConstrained(String str, String str2) {
String extractHostFromURL = extractHostFromURL(str);
return !str2.startsWith(".") ? extractHostFromURL.equalsIgnoreCase(str2) : withinDomain(extractHostFromURL, str2);
}
private boolean isIPConstrained(byte[] bArr, byte[] bArr2) {
int length = bArr.length;
if (length != bArr2.length / 2) {
return false;
}
byte[] bArr3 = new byte[length];
System.arraycopy(bArr2, length, bArr3, 0, length);
byte[] bArr4 = new byte[length];
byte[] bArr5 = new byte[length];
for (int i = 0; i < length; i++) {
bArr4[i] = (byte) (bArr2[i] & bArr3[i]);
bArr5[i] = (byte) (bArr[i] & bArr3[i]);
}
return Arrays.areEqual(bArr4, bArr5);
}
private byte[] ipWithSubnetMask(byte[] bArr, byte[] bArr2) {
int length = bArr.length;
byte[] bArr3 = new byte[length << 1];
System.arraycopy(bArr, 0, bArr3, 0, length);
System.arraycopy(bArr2, 0, bArr3, length, length);
return bArr3;
}
private void intersectURI(String str, String str2, Set set) {
if (str.indexOf(64) != -1) {
String substring = str.substring(str.indexOf(64) + 1);
if (str2.indexOf(64) != -1) {
if (!str.equalsIgnoreCase(str2)) {
return;
}
} else if (str2.startsWith(".")) {
if (!withinDomain(substring, str2)) {
return;
}
} else if (!substring.equalsIgnoreCase(str2)) {
return;
}
} else {
if (str.startsWith(".")) {
if (str2.indexOf(64) != -1) {
if (!withinDomain(str2.substring(str.indexOf(64) + 1), str)) {
return;
}
} else if (str2.startsWith(".")) {
if (!withinDomain(str, str2) && !str.equalsIgnoreCase(str2)) {
if (!withinDomain(str2, str)) {
return;
}
}
} else if (!withinDomain(str2, str)) {
return;
}
set.add(str2);
return;
}
if (str2.indexOf(64) != -1) {
if (!str2.substring(str2.indexOf(64) + 1).equalsIgnoreCase(str)) {
return;
}
set.add(str2);
return;
} else if (str2.startsWith(".")) {
if (!withinDomain(str, str2)) {
return;
}
} else if (!str.equalsIgnoreCase(str2)) {
return;
}
}
set.add(str);
}
private Set intersectURI(Set set, Set set2) {
HashSet hashSet = new HashSet();
Iterator it = set2.iterator();
while (it.hasNext()) {
String extractNameAsString = extractNameAsString(((GeneralSubtree) it.next()).getBase());
if (set != null) {
Iterator it2 = set.iterator();
while (it2.hasNext()) {
intersectURI((String) it2.next(), extractNameAsString, hashSet);
}
} else if (extractNameAsString != null) {
hashSet.add(extractNameAsString);
}
}
return hashSet;
}
private Set intersectIPRange(byte[] bArr, byte[] bArr2) {
if (bArr.length != bArr2.length) {
return Collections.EMPTY_SET;
}
byte[][] extractIPsAndSubnetMasks = extractIPsAndSubnetMasks(bArr, bArr2);
byte[] bArr3 = extractIPsAndSubnetMasks[0];
byte[] bArr4 = extractIPsAndSubnetMasks[1];
byte[] bArr5 = extractIPsAndSubnetMasks[2];
byte[] bArr6 = extractIPsAndSubnetMasks[3];
byte[][] minMaxIPs = minMaxIPs(bArr3, bArr4, bArr5, bArr6);
return compareTo(max(minMaxIPs[0], minMaxIPs[2]), min(minMaxIPs[1], minMaxIPs[3])) == 1 ? Collections.EMPTY_SET : Collections.singleton(ipWithSubnetMask(or(minMaxIPs[0], minMaxIPs[2]), or(bArr4, bArr6)));
}
private Set intersectIP(Set set, Set set2) {
HashSet hashSet = new HashSet();
Iterator it = set2.iterator();
while (it.hasNext()) {
byte[] octets = ASN1OctetString.getInstance(((GeneralSubtree) it.next()).getBase().getName()).getOctets();
if (set != null) {
Iterator it2 = set.iterator();
while (it2.hasNext()) {
hashSet.addAll(intersectIPRange((byte[]) it2.next(), octets));
}
} else if (octets != null) {
hashSet.add(octets);
}
}
return hashSet;
}
private void intersectEmail(String str, String str2, Set set) {
if (str.indexOf(64) != -1) {
String substring = str.substring(str.indexOf(64) + 1);
if (str2.indexOf(64) != -1) {
if (!str.equalsIgnoreCase(str2)) {
return;
}
} else if (str2.startsWith(".")) {
if (!withinDomain(substring, str2)) {
return;
}
} else if (!substring.equalsIgnoreCase(str2)) {
return;
}
} else {
if (str.startsWith(".")) {
if (str2.indexOf(64) != -1) {
if (!withinDomain(str2.substring(str.indexOf(64) + 1), str)) {
return;
}
} else if (str2.startsWith(".")) {
if (!withinDomain(str, str2) && !str.equalsIgnoreCase(str2)) {
if (!withinDomain(str2, str)) {
return;
}
}
} else if (!withinDomain(str2, str)) {
return;
}
set.add(str2);
return;
}
if (str2.indexOf(64) != -1) {
if (!str2.substring(str2.indexOf(64) + 1).equalsIgnoreCase(str)) {
return;
}
set.add(str2);
return;
} else if (str2.startsWith(".")) {
if (!withinDomain(str, str2)) {
return;
}
} else if (!str.equalsIgnoreCase(str2)) {
return;
}
}
set.add(str);
}
private Set intersectEmail(Set set, Set set2) {
HashSet hashSet = new HashSet();
Iterator it = set2.iterator();
while (it.hasNext()) {
String extractNameAsString = extractNameAsString(((GeneralSubtree) it.next()).getBase());
if (set != null) {
Iterator it2 = set.iterator();
while (it2.hasNext()) {
intersectEmail(extractNameAsString, (String) it2.next(), hashSet);
}
} else if (extractNameAsString != null) {
hashSet.add(extractNameAsString);
}
}
return hashSet;
}
private Set intersectDNS(Set set, Set set2) {
HashSet hashSet = new HashSet();
Iterator it = set2.iterator();
while (it.hasNext()) {
String extractNameAsString = extractNameAsString(((GeneralSubtree) it.next()).getBase());
if (set != null) {
Iterator it2 = set.iterator();
while (it2.hasNext()) {
String str = (String) it2.next();
if (withinDomain(str, extractNameAsString)) {
hashSet.add(str);
} else if (withinDomain(extractNameAsString, str)) {
hashSet.add(extractNameAsString);
}
}
} else if (extractNameAsString != null) {
hashSet.add(extractNameAsString);
}
}
return hashSet;
}
private Set intersectDN(Set set, Set set2) {
HashSet hashSet = new HashSet();
Iterator it = set2.iterator();
while (it.hasNext()) {
ASN1Sequence aSN1Sequence = ASN1Sequence.getInstance(((GeneralSubtree) it.next()).getBase().getName().toASN1Primitive());
if (set != null) {
Iterator it2 = set.iterator();
while (it2.hasNext()) {
ASN1Sequence aSN1Sequence2 = (ASN1Sequence) it2.next();
if (withinDNSubtree(aSN1Sequence, aSN1Sequence2)) {
hashSet.add(aSN1Sequence);
} else if (withinDNSubtree(aSN1Sequence2, aSN1Sequence)) {
hashSet.add(aSN1Sequence2);
}
}
} else if (aSN1Sequence != null) {
hashSet.add(aSN1Sequence);
}
}
return hashSet;
}
private int hashCollection(Collection collection) {
int i = 0;
if (collection == null) {
return 0;
}
for (Object obj : collection) {
i += obj instanceof byte[] ? Arrays.hashCode((byte[]) obj) : obj.hashCode();
}
return i;
}
private String extractNameAsString(GeneralName generalName) {
return DERIA5String.getInstance(generalName.getName()).getString();
}
private byte[][] extractIPsAndSubnetMasks(byte[] bArr, byte[] bArr2) {
int length = bArr.length / 2;
byte[] bArr3 = new byte[length];
byte[] bArr4 = new byte[length];
System.arraycopy(bArr, 0, bArr3, 0, length);
System.arraycopy(bArr, length, bArr4, 0, length);
byte[] bArr5 = new byte[length];
byte[] bArr6 = new byte[length];
System.arraycopy(bArr2, 0, bArr5, 0, length);
System.arraycopy(bArr2, length, bArr6, 0, length);
return new byte[][]{bArr3, bArr4, bArr5, bArr6};
}
private static String extractHostFromURL(String str) {
String substring = str.substring(str.indexOf(58) + 1);
if (substring.indexOf("//") != -1) {
substring = substring.substring(substring.indexOf("//") + 2);
}
if (substring.lastIndexOf(58) != -1) {
substring = substring.substring(0, substring.lastIndexOf(58));
}
String substring2 = substring.substring(substring.indexOf(58) + 1);
String substring3 = substring2.substring(substring2.indexOf(64) + 1);
return substring3.indexOf(47) != -1 ? substring3.substring(0, substring3.indexOf(47)) : substring3;
}
private boolean equals(Object obj, Object obj2) {
if (obj == obj2) {
return true;
}
if (obj == null || obj2 == null) {
return false;
}
return ((obj instanceof byte[]) && (obj2 instanceof byte[])) ? Arrays.areEqual((byte[]) obj, (byte[]) obj2) : obj.equals(obj2);
}
private boolean emailIsConstrained(String str, String str2) {
String substring = str.substring(str.indexOf(64) + 1);
if (str2.indexOf(64) != -1) {
if (str.equalsIgnoreCase(str2) || substring.equalsIgnoreCase(str2.substring(1))) {
return true;
}
} else if (str2.charAt(0) != '.') {
if (substring.equalsIgnoreCase(str2)) {
return true;
}
} else if (withinDomain(substring, str2)) {
return true;
}
return false;
}
private static int compareTo(byte[] bArr, byte[] bArr2) {
if (Arrays.areEqual(bArr, bArr2)) {
return 0;
}
return Arrays.areEqual(max(bArr, bArr2), bArr) ? 1 : -1;
}
private boolean collectionsAreEqual(Collection collection, Collection collection2) {
if (collection == collection2) {
return true;
}
if (collection == null || collection2 == null || collection.size() != collection2.size()) {
return false;
}
for (Object obj : collection) {
Iterator it = collection2.iterator();
while (it.hasNext()) {
if (equals(obj, it.next())) {
break;
}
}
return false;
}
return true;
}
private void checkPermittedURI(Set set, String str) throws PKIXNameConstraintValidatorException {
if (set == null) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (isUriConstrained(str, (String) it.next())) {
return;
}
}
if (str.length() != 0 || set.size() != 0) {
throw new PKIXNameConstraintValidatorException("URI is not from a permitted subtree.");
}
}
private void checkPermittedIP(Set set, byte[] bArr) throws PKIXNameConstraintValidatorException {
if (set == null) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (isIPConstrained(bArr, (byte[]) it.next())) {
return;
}
}
if (bArr.length != 0 || set.size() != 0) {
throw new PKIXNameConstraintValidatorException("IP is not from a permitted subtree.");
}
}
private void checkPermittedEmail(Set set, String str) throws PKIXNameConstraintValidatorException {
if (set == null) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (emailIsConstrained(str, (String) it.next())) {
return;
}
}
if (str.length() != 0 || set.size() != 0) {
throw new PKIXNameConstraintValidatorException("Subject email address is not from a permitted subtree.");
}
}
private void checkPermittedDNS(Set set, String str) throws PKIXNameConstraintValidatorException {
if (set == null) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
String str2 = (String) it.next();
if (withinDomain(str, str2) || str.equalsIgnoreCase(str2)) {
return;
}
}
if (str.length() != 0 || set.size() != 0) {
throw new PKIXNameConstraintValidatorException("DNS is not from a permitted subtree.");
}
}
private void checkPermittedDN(Set set, ASN1Sequence aSN1Sequence) throws PKIXNameConstraintValidatorException {
if (set == null) {
return;
}
if (set.isEmpty() && aSN1Sequence.size() == 0) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (withinDNSubtree(aSN1Sequence, (ASN1Sequence) it.next())) {
return;
}
}
throw new PKIXNameConstraintValidatorException("Subject distinguished name is not from a permitted subtree");
}
private void checkExcludedURI(Set set, String str) throws PKIXNameConstraintValidatorException {
if (set.isEmpty()) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (isUriConstrained(str, (String) it.next())) {
throw new PKIXNameConstraintValidatorException("URI is from an excluded subtree.");
}
}
}
private void checkExcludedIP(Set set, byte[] bArr) throws PKIXNameConstraintValidatorException {
if (set.isEmpty()) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (isIPConstrained(bArr, (byte[]) it.next())) {
throw new PKIXNameConstraintValidatorException("IP is from an excluded subtree.");
}
}
}
private void checkExcludedEmail(Set set, String str) throws PKIXNameConstraintValidatorException {
if (set.isEmpty()) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (emailIsConstrained(str, (String) it.next())) {
throw new PKIXNameConstraintValidatorException("Email address is from an excluded subtree.");
}
}
}
private void checkExcludedDNS(Set set, String str) throws PKIXNameConstraintValidatorException {
if (set.isEmpty()) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
String str2 = (String) it.next();
if (withinDomain(str, str2) || str.equalsIgnoreCase(str2)) {
throw new PKIXNameConstraintValidatorException("DNS is from an excluded subtree.");
}
}
}
private void checkExcludedDN(Set set, ASN1Sequence aSN1Sequence) throws PKIXNameConstraintValidatorException {
if (set.isEmpty()) {
return;
}
Iterator it = set.iterator();
while (it.hasNext()) {
if (withinDNSubtree(aSN1Sequence, (ASN1Sequence) it.next())) {
throw new PKIXNameConstraintValidatorException("Subject distinguished name is from an excluded subtree");
}
}
}
}