what-the-bank/sources/org/bouncycastle/jce/provider/X509CRLEntryObject.java

218 lines
8.4 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.jce.provider;
import java.io.IOException;
import java.math.BigInteger;
import java.security.cert.CRLException;
import java.security.cert.X509CRLEntry;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Enumerated;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.util.ASN1Dump;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.CRLReason;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.Extensions;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.asn1.x509.TBSCertList;
import org.bouncycastle.asn1.x509.X509Extension;
import org.bouncycastle.util.Strings;
/* loaded from: classes6.dex */
public class X509CRLEntryObject extends X509CRLEntry {
private TBSCertList.CRLEntry c;
private X500Name certificateIssuer;
private int hashValue;
private boolean isHashValueSet;
@Override // java.security.cert.X509CRLEntry
public String toString() {
StringBuffer append;
StringBuffer stringBuffer = new StringBuffer(" userCertificate: ");
String lineSeparator = Strings.lineSeparator();
stringBuffer.append(getSerialNumber()).append(lineSeparator);
stringBuffer.append(" revocationDate: ").append(getRevocationDate()).append(lineSeparator);
stringBuffer.append(" certificateIssuer: ").append(getCertificateIssuer()).append(lineSeparator);
Extensions extensions = this.c.getExtensions();
if (extensions != null) {
Enumeration oids = extensions.oids();
if (oids.hasMoreElements()) {
String str = " crlEntryExtensions:";
loop0: while (true) {
stringBuffer.append(str).append(lineSeparator);
while (oids.hasMoreElements()) {
ASN1ObjectIdentifier aSN1ObjectIdentifier = (ASN1ObjectIdentifier) oids.nextElement();
Extension extension = extensions.getExtension(aSN1ObjectIdentifier);
if (extension.getExtnValue() != null) {
ASN1InputStream aSN1InputStream = new ASN1InputStream(extension.getExtnValue().getOctets());
stringBuffer.append(" critical(").append(extension.isCritical()).append(") ");
try {
if (aSN1ObjectIdentifier.equals(X509Extension.reasonCode)) {
append = stringBuffer.append(CRLReason.getInstance(ASN1Enumerated.getInstance(aSN1InputStream.readObject())));
} else if (aSN1ObjectIdentifier.equals(X509Extension.certificateIssuer)) {
append = stringBuffer.append("Certificate issuer: ").append(GeneralNames.getInstance(aSN1InputStream.readObject()));
} else {
stringBuffer.append(aSN1ObjectIdentifier.getId());
append = stringBuffer.append(" value = ").append(ASN1Dump.dumpAsString(aSN1InputStream.readObject()));
}
append.append(lineSeparator);
} catch (Exception unused) {
stringBuffer.append(aSN1ObjectIdentifier.getId());
str = " value = *****";
}
} else {
stringBuffer.append(lineSeparator);
}
}
break loop0;
}
}
}
return stringBuffer.toString();
}
@Override // java.security.cert.X509CRLEntry
public int hashCode() {
if (!this.isHashValueSet) {
this.hashValue = super.hashCode();
this.isHashValueSet = true;
}
return this.hashValue;
}
@Override // java.security.cert.X509Extension
public boolean hasUnsupportedCriticalExtension() {
Set criticalExtensionOIDs = getCriticalExtensionOIDs();
return (criticalExtensionOIDs == null || criticalExtensionOIDs.isEmpty()) ? false : true;
}
@Override // java.security.cert.X509CRLEntry
public boolean hasExtensions() {
return this.c.getExtensions() != null;
}
@Override // java.security.cert.X509CRLEntry
public BigInteger getSerialNumber() {
return this.c.getUserCertificate().getValue();
}
@Override // java.security.cert.X509CRLEntry
public Date getRevocationDate() {
return this.c.getRevocationDate().getDate();
}
@Override // java.security.cert.X509Extension
public Set getNonCriticalExtensionOIDs() {
return getExtensionOIDs(false);
}
@Override // java.security.cert.X509Extension
public byte[] getExtensionValue(String str) {
Extension extension = getExtension(new ASN1ObjectIdentifier(str));
if (extension == null) {
return null;
}
try {
return extension.getExtnValue().getEncoded();
} catch (Exception e) {
StringBuilder sb = new StringBuilder("error encoding ");
sb.append(e.toString());
throw new RuntimeException(sb.toString());
}
}
@Override // java.security.cert.X509CRLEntry
public byte[] getEncoded() throws CRLException {
try {
return this.c.getEncoded(ASN1Encoding.DER);
} catch (IOException e) {
throw new CRLException(e.toString());
}
}
@Override // java.security.cert.X509Extension
public Set getCriticalExtensionOIDs() {
return getExtensionOIDs(true);
}
@Override // java.security.cert.X509CRLEntry
public X500Principal getCertificateIssuer() {
if (this.certificateIssuer == null) {
return null;
}
try {
return new X500Principal(this.certificateIssuer.getEncoded());
} catch (IOException unused) {
return null;
}
}
@Override // java.security.cert.X509CRLEntry
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
return obj instanceof X509CRLEntryObject ? this.c.equals(((X509CRLEntryObject) obj).c) : super.equals(this);
}
private X500Name loadCertificateIssuer(boolean z, X500Name x500Name) {
if (!z) {
return null;
}
Extension extension = getExtension(Extension.certificateIssuer);
if (extension == null) {
return x500Name;
}
try {
GeneralName[] names = GeneralNames.getInstance(extension.getParsedValue()).getNames();
for (int i = 0; i < names.length; i++) {
if (names[i].getTagNo() == 4) {
return X500Name.getInstance(names[i].getName());
}
}
} catch (Exception unused) {
}
return null;
}
private Set getExtensionOIDs(boolean z) {
Extensions extensions = this.c.getExtensions();
if (extensions == null) {
return null;
}
HashSet hashSet = new HashSet();
Enumeration oids = extensions.oids();
while (oids.hasMoreElements()) {
ASN1ObjectIdentifier aSN1ObjectIdentifier = (ASN1ObjectIdentifier) oids.nextElement();
if (z == extensions.getExtension(aSN1ObjectIdentifier).isCritical()) {
hashSet.add(aSN1ObjectIdentifier.getId());
}
}
return hashSet;
}
private Extension getExtension(ASN1ObjectIdentifier aSN1ObjectIdentifier) {
Extensions extensions = this.c.getExtensions();
if (extensions != null) {
return extensions.getExtension(aSN1ObjectIdentifier);
}
return null;
}
public X509CRLEntryObject(TBSCertList.CRLEntry cRLEntry, boolean z, X500Name x500Name) {
this.c = cRLEntry;
this.certificateIssuer = loadCertificateIssuer(z, x500Name);
}
public X509CRLEntryObject(TBSCertList.CRLEntry cRLEntry) {
this.c = cRLEntry;
this.certificateIssuer = null;
}
}