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

83 lines
4.6 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.jce.provider;
import java.io.IOException;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.PSSParameterSpec;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Null;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.RSASSAPSSparams;
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public class X509SignatureUtil {
private static final ASN1Null derNull = DERNull.INSTANCE;
/* JADX INFO: Access modifiers changed from: package-private */
public static void setSignatureParameters(Signature signature, ASN1Encodable aSN1Encodable) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException {
if (aSN1Encodable == null || derNull.equals(aSN1Encodable)) {
return;
}
AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(signature.getAlgorithm(), signature.getProvider());
try {
algorithmParameters.init(aSN1Encodable.toASN1Primitive().getEncoded());
if (signature.getAlgorithm().endsWith("MGF1")) {
try {
signature.setParameter(algorithmParameters.getParameterSpec(PSSParameterSpec.class));
} catch (GeneralSecurityException e) {
StringBuilder sb = new StringBuilder("Exception extracting parameters: ");
sb.append(e.getMessage());
throw new SignatureException(sb.toString());
}
}
} catch (IOException e2) {
StringBuilder sb2 = new StringBuilder("IOException decoding parameters: ");
sb2.append(e2.getMessage());
throw new SignatureException(sb2.toString());
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String getSignatureName(AlgorithmIdentifier algorithmIdentifier) {
ASN1Encodable parameters = algorithmIdentifier.getParameters();
if (parameters != null && !derNull.equals(parameters)) {
if (algorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
RSASSAPSSparams rSASSAPSSparams = RSASSAPSSparams.getInstance(parameters);
StringBuilder sb = new StringBuilder();
sb.append(getDigestAlgName(rSASSAPSSparams.getHashAlgorithm().getAlgorithm()));
sb.append("withRSAandMGF1");
return sb.toString();
}
if (algorithmIdentifier.getAlgorithm().equals(X9ObjectIdentifiers.ecdsa_with_SHA2)) {
ASN1Sequence aSN1Sequence = ASN1Sequence.getInstance(parameters);
StringBuilder sb2 = new StringBuilder();
sb2.append(getDigestAlgName(ASN1ObjectIdentifier.getInstance(aSN1Sequence.getObjectAt(0))));
sb2.append("withECDSA");
return sb2.toString();
}
}
return algorithmIdentifier.getAlgorithm().getId();
}
private static String getDigestAlgName(ASN1ObjectIdentifier aSN1ObjectIdentifier) {
return PKCSObjectIdentifiers.md5.equals(aSN1ObjectIdentifier) ? "MD5" : OIWObjectIdentifiers.idSHA1.equals(aSN1ObjectIdentifier) ? "SHA1" : NISTObjectIdentifiers.id_sha224.equals(aSN1ObjectIdentifier) ? "SHA224" : NISTObjectIdentifiers.id_sha256.equals(aSN1ObjectIdentifier) ? "SHA256" : NISTObjectIdentifiers.id_sha384.equals(aSN1ObjectIdentifier) ? "SHA384" : NISTObjectIdentifiers.id_sha512.equals(aSN1ObjectIdentifier) ? "SHA512" : TeleTrusTObjectIdentifiers.ripemd128.equals(aSN1ObjectIdentifier) ? "RIPEMD128" : TeleTrusTObjectIdentifiers.ripemd160.equals(aSN1ObjectIdentifier) ? "RIPEMD160" : TeleTrusTObjectIdentifiers.ripemd256.equals(aSN1ObjectIdentifier) ? "RIPEMD256" : CryptoProObjectIdentifiers.gostR3411.equals(aSN1ObjectIdentifier) ? "GOST3411" : aSN1ObjectIdentifier.getId();
}
X509SignatureUtil() {
}
}