what-the-bank/sources/org/bouncycastle/x509/X509V2CRLGenerator.java

229 lines
9.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.x509;
import java.io.IOException;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.SignatureException;
import java.security.cert.CRLException;
import java.security.cert.X509CRL;
import java.security.cert.X509CRLEntry;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.CertificateList;
import org.bouncycastle.asn1.x509.Extensions;
import org.bouncycastle.asn1.x509.TBSCertList;
import org.bouncycastle.asn1.x509.Time;
import org.bouncycastle.asn1.x509.V2TBSCertListGenerator;
import org.bouncycastle.asn1.x509.X509Extensions;
import org.bouncycastle.asn1.x509.X509ExtensionsGenerator;
import org.bouncycastle.asn1.x509.X509Name;
import org.bouncycastle.jcajce.util.BCJcaJceHelper;
import org.bouncycastle.jcajce.util.JcaJceHelper;
import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.provider.X509CRLObject;
/* loaded from: classes6.dex */
public class X509V2CRLGenerator {
private AlgorithmIdentifier sigAlgId;
private ASN1ObjectIdentifier sigOID;
private String signatureAlgorithm;
private final JcaJceHelper bcHelper = new BCJcaJceHelper();
private V2TBSCertListGenerator tbsGen = new V2TBSCertListGenerator();
private X509ExtensionsGenerator extGenerator = new X509ExtensionsGenerator();
public void setThisUpdate(Date date) {
this.tbsGen.setThisUpdate(new Time(date));
}
public void setSignatureAlgorithm(String str) {
this.signatureAlgorithm = str;
try {
ASN1ObjectIdentifier algorithmOID = X509Util.getAlgorithmOID(str);
this.sigOID = algorithmOID;
AlgorithmIdentifier sigAlgID = X509Util.getSigAlgID(algorithmOID, str);
this.sigAlgId = sigAlgID;
this.tbsGen.setSignature(sigAlgID);
} catch (Exception unused) {
throw new IllegalArgumentException("Unknown signature type requested");
}
}
public void setNextUpdate(Date date) {
this.tbsGen.setNextUpdate(new Time(date));
}
public void setIssuerDN(X509Name x509Name) {
this.tbsGen.setIssuer(x509Name);
}
public void setIssuerDN(X500Principal x500Principal) {
try {
this.tbsGen.setIssuer(new X509Principal(x500Principal.getEncoded()));
} catch (IOException e) {
throw new IllegalArgumentException("can't process principal: ".concat(String.valueOf(e)));
}
}
public void reset() {
this.tbsGen = new V2TBSCertListGenerator();
this.extGenerator.reset();
}
public Iterator getSignatureAlgNames() {
return X509Util.getAlgNames();
}
public X509CRL generateX509CRL(PrivateKey privateKey, SecureRandom secureRandom) throws SecurityException, SignatureException, InvalidKeyException {
try {
return generateX509CRL(privateKey, BouncyCastleProvider.PROVIDER_NAME, secureRandom);
} catch (NoSuchProviderException unused) {
throw new SecurityException("BC provider not installed!");
}
}
public X509CRL generateX509CRL(PrivateKey privateKey, String str, SecureRandom secureRandom) throws NoSuchProviderException, SecurityException, SignatureException, InvalidKeyException {
try {
return generate(privateKey, str, secureRandom);
} catch (InvalidKeyException e) {
throw e;
} catch (NoSuchProviderException e2) {
throw e2;
} catch (SignatureException e3) {
throw e3;
} catch (GeneralSecurityException e4) {
throw new SecurityException("exception: ".concat(String.valueOf(e4)));
}
}
public X509CRL generateX509CRL(PrivateKey privateKey, String str) throws NoSuchProviderException, SecurityException, SignatureException, InvalidKeyException {
return generateX509CRL(privateKey, str, null);
}
public X509CRL generateX509CRL(PrivateKey privateKey) throws SecurityException, SignatureException, InvalidKeyException {
try {
return generateX509CRL(privateKey, BouncyCastleProvider.PROVIDER_NAME, null);
} catch (NoSuchProviderException unused) {
throw new SecurityException("BC provider not installed!");
}
}
public X509CRL generate(PrivateKey privateKey, SecureRandom secureRandom) throws CRLException, IllegalStateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
TBSCertList generateCertList = generateCertList();
try {
return generateJcaObject(generateCertList, X509Util.calculateSignature(this.sigOID, this.signatureAlgorithm, privateKey, secureRandom, generateCertList));
} catch (IOException e) {
throw new ExtCRLException("cannot generate CRL encoding", e);
}
}
public X509CRL generate(PrivateKey privateKey, String str, SecureRandom secureRandom) throws CRLException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
TBSCertList generateCertList = generateCertList();
try {
return generateJcaObject(generateCertList, X509Util.calculateSignature(this.sigOID, this.signatureAlgorithm, str, privateKey, secureRandom, generateCertList));
} catch (IOException e) {
throw new ExtCRLException("cannot generate CRL encoding", e);
}
}
public X509CRL generate(PrivateKey privateKey, String str) throws CRLException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
return generate(privateKey, str, null);
}
public X509CRL generate(PrivateKey privateKey) throws CRLException, IllegalStateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
return generate(privateKey, (SecureRandom) null);
}
public void addExtension(ASN1ObjectIdentifier aSN1ObjectIdentifier, boolean z, byte[] bArr) {
this.extGenerator.addExtension(new ASN1ObjectIdentifier(aSN1ObjectIdentifier.getId()), z, bArr);
}
public void addExtension(ASN1ObjectIdentifier aSN1ObjectIdentifier, boolean z, ASN1Encodable aSN1Encodable) {
this.extGenerator.addExtension(new ASN1ObjectIdentifier(aSN1ObjectIdentifier.getId()), z, aSN1Encodable);
}
public void addExtension(String str, boolean z, byte[] bArr) {
addExtension(new ASN1ObjectIdentifier(str), z, bArr);
}
public void addExtension(String str, boolean z, ASN1Encodable aSN1Encodable) {
addExtension(new ASN1ObjectIdentifier(str), z, aSN1Encodable);
}
public void addCRLEntry(BigInteger bigInteger, Date date, X509Extensions x509Extensions) {
this.tbsGen.addCRLEntry(new ASN1Integer(bigInteger), new Time(date), Extensions.getInstance(x509Extensions));
}
public void addCRLEntry(BigInteger bigInteger, Date date, int i, Date date2) {
this.tbsGen.addCRLEntry(new ASN1Integer(bigInteger), new Time(date), i, new ASN1GeneralizedTime(date2));
}
public void addCRLEntry(BigInteger bigInteger, Date date, int i) {
this.tbsGen.addCRLEntry(new ASN1Integer(bigInteger), new Time(date), i);
}
public void addCRL(X509CRL x509crl) throws CRLException {
Set<? extends X509CRLEntry> revokedCertificates = x509crl.getRevokedCertificates();
if (revokedCertificates != null) {
Iterator<? extends X509CRLEntry> it = revokedCertificates.iterator();
while (it.hasNext()) {
try {
this.tbsGen.addCRLEntry(ASN1Sequence.getInstance(new ASN1InputStream(it.next().getEncoded()).readObject()));
} catch (IOException e) {
StringBuilder sb = new StringBuilder("exception processing encoding of CRL: ");
sb.append(e.toString());
throw new CRLException(sb.toString());
}
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public static class ExtCRLException extends CRLException {
Throwable cause;
@Override // java.lang.Throwable
public Throwable getCause() {
return this.cause;
}
ExtCRLException(String str, Throwable th) {
super(str);
this.cause = th;
}
}
private X509CRL generateJcaObject(TBSCertList tBSCertList, byte[] bArr) throws CRLException {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
aSN1EncodableVector.add(tBSCertList);
aSN1EncodableVector.add(this.sigAlgId);
aSN1EncodableVector.add(new DERBitString(bArr));
return new X509CRLObject(new CertificateList(new DERSequence(aSN1EncodableVector)));
}
private TBSCertList generateCertList() {
if (!this.extGenerator.isEmpty()) {
this.tbsGen.setExtensions(this.extGenerator.generate());
}
return this.tbsGen.generateTBSCertList();
}
}