Files
Jan2021-Cpp2Il-Dump/Assembly-CSharp/BestHTTP/SecureProtocol/Org/BouncyCastle/OpenSsl/PemReader.cs
T
2026-04-08 23:40:05 +02:00

373 lines
15 KiB
C#

using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Sec;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Pkcs;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO.Pem;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
using Cpp2IlInjected;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.OpenSsl
{
// Token: 0x020013BB RID: 5051
[Token(Token = "0x20013BB")]
[StructLayout(3)]
public class PemReader : PemReader
{
// Token: 0x060080A5 RID: 32933 RVA: 0x0000220F File Offset: 0x0000040F
[Token(Token = "0x60080A5")]
[Address(RVA = "0x3C9F60", Offset = "0x3C8960", VA = "0x1803C9F60")]
static PemReader()
{
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
}
// Token: 0x060080A6 RID: 32934 RVA: 0x001B2DE4 File Offset: 0x001B0FE4
[Token(Token = "0x60080A6")]
[Address(RVA = "0x4DD360", Offset = "0x4DBD60", VA = "0x1804DD360")]
public PemReader(TextReader reader)
: base(reader)
{
this.pFinder = (ulong)0L;
}
// Token: 0x060080A7 RID: 32935 RVA: 0x001B2E04 File Offset: 0x001B1004
[Token(Token = "0x60080A7")]
[Address(RVA = "0x4DD330", Offset = "0x4DBD30", VA = "0x1804DD330")]
public PemReader(TextReader reader, IPasswordFinder pFinder)
: base(reader)
{
this.pFinder = pFinder;
}
// Token: 0x060080A8 RID: 32936 RVA: 0x001B2E20 File Offset: 0x001B1020
[Token(Token = "0x60080A8")]
[Address(RVA = "0x4DC0E0", Offset = "0x4DAAE0", VA = "0x1804DC0E0")]
public object ReadObject()
{
PemObject pemObject = base.ReadPemObject();
if (pemObject != 0)
{
if (!Platform.EndsWith(pemObject.type, "PRIVATE KEY"))
{
string type = pemObject.type;
uint num = <PrivateImplementationDetails>.ComputeStringHash(type);
if (num > (uint)1592636440)
{
if (num > (uint)(-2093939407))
{
if (num == (uint)(-1925861857))
{
if (!string.Equals(type, "PUBLIC KEY"))
{
goto IL_186;
}
AsymmetricKeyParameter asymmetricKeyParameter = PublicKeyFactory.CreateKey(pemObject.content);
}
bool flag;
if (num == (uint)(-1905462054))
{
flag = string.Equals(type, "CMS");
if (!flag)
{
goto IL_186;
}
}
if (!flag)
{
goto IL_186;
}
if (string.Equals(type, "NEW CERTIFICATE REQUEST"))
{
goto IL_10C;
}
}
if (num == (uint)1951606473)
{
if (!string.Equals(type, "RSA PUBLIC KEY"))
{
goto IL_186;
}
RsaPublicKeyStructure instance = RsaPublicKeyStructure.GetInstance(Asn1Object.FromByteArray(pemObject.content));
BigInteger modulus = instance.modulus;
BigInteger publicExponent = instance.publicExponent;
int num2;
RsaKeyParameters rsaKeyParameters = new RsaKeyParameters(num2 != 0, modulus, publicExponent);
num2 = 0;
}
if (num != (uint)(-2093939407) || !string.Equals(type, "CERTIFICATE REQUEST"))
{
goto IL_186;
}
IL_10C:
Pkcs10CertificationRequest pkcs10CertificationRequest = this.ReadCertificateRequest(pemObject);
}
if (num > (uint)479209360)
{
X509Crl x509Crl;
if (num == (uint)1514293038)
{
if (!string.Equals(type, "X509 CRL"))
{
goto IL_186;
}
x509Crl = this.ReadCrl(pemObject);
}
BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.ContentInfo contentInfo;
if ((x509Crl == (ulong)1517936775L && x509Crl == 0) || contentInfo != (ulong)1592636440L || contentInfo == 0)
{
goto IL_186;
}
}
X509V2AttributeCertificate x509V2AttributeCertificate;
if ((x509V2AttributeCertificate != (ulong)368575810L || x509V2AttributeCertificate == 0) && (x509V2AttributeCertificate != (ulong)479209360L || x509V2AttributeCertificate == 0))
{
goto IL_186;
}
}
return this.ReadPrivateKey(pemObject);
}
IL_186:
throw new NullReferenceException();
}
// Token: 0x060080A9 RID: 32937 RVA: 0x001B2FC4 File Offset: 0x001B11C4
[Token(Token = "0x60080A9")]
[Address(RVA = "0x4DD290", Offset = "0x4DBC90", VA = "0x1804DD290")]
private AsymmetricKeyParameter ReadRsaPublicKey(PemObject pemObject)
{
RsaPublicKeyStructure instance = RsaPublicKeyStructure.GetInstance(Asn1Object.FromByteArray(pemObject.content));
BigInteger publicExponent = instance.publicExponent;
BigInteger modulus = instance.modulus;
int num;
RsaKeyParameters rsaKeyParameters = new RsaKeyParameters(num != 0, modulus, publicExponent);
num = 0;
throw new NullReferenceException();
}
// Token: 0x060080AA RID: 32938 RVA: 0x001B3004 File Offset: 0x001B1204
[Token(Token = "0x60080AA")]
[Address(RVA = "0x4DD260", Offset = "0x4DBC60", VA = "0x1804DD260")]
private AsymmetricKeyParameter ReadPublicKey(PemObject pemObject)
{
return PublicKeyFactory.CreateKey(pemObject.content);
}
// Token: 0x060080AB RID: 32939 RVA: 0x001B3024 File Offset: 0x001B1224
[Token(Token = "0x60080AB")]
[Address(RVA = "0x4DBF00", Offset = "0x4DA900", VA = "0x1804DBF00")]
private X509Certificate ReadCertificate(PemObject pemObject)
{
X509CertificateParser x509CertificateParser = new X509CertificateParser();
byte[] content = pemObject.content;
return x509CertificateParser.ReadCertificate(content);
}
// Token: 0x060080AC RID: 32940 RVA: 0x001B3060 File Offset: 0x001B1260
[Token(Token = "0x60080AC")]
[Address(RVA = "0x4DBFF0", Offset = "0x4DA9F0", VA = "0x1804DBFF0")]
private X509Crl ReadCrl(PemObject pemObject)
{
X509CrlParser x509CrlParser = new X509CrlParser();
byte[] content = pemObject.content;
return x509CrlParser.ReadCrl(content);
}
// Token: 0x060080AD RID: 32941 RVA: 0x001B309C File Offset: 0x001B129C
[Token(Token = "0x60080AD")]
[Address(RVA = "0x4DBE20", Offset = "0x4DA820", VA = "0x1804DBE20")]
private Pkcs10CertificationRequest ReadCertificateRequest(PemObject pemObject)
{
return new Pkcs10CertificationRequest(pemObject.content);
}
// Token: 0x060080AE RID: 32942 RVA: 0x001B30C8 File Offset: 0x001B12C8
[Token(Token = "0x60080AE")]
[Address(RVA = "0x4DBDB0", Offset = "0x4DA7B0", VA = "0x1804DBDB0")]
private IX509AttributeCertificate ReadAttributeCertificate(PemObject pemObject)
{
X509V2AttributeCertificate x509V2AttributeCertificate = new X509V2AttributeCertificate(pemObject.content);
throw new NullReferenceException();
}
// Token: 0x060080AF RID: 32943 RVA: 0x001B30E8 File Offset: 0x001B12E8
[Token(Token = "0x60080AF")]
[Address(RVA = "0x4DC4D0", Offset = "0x4DAED0", VA = "0x1804DC4D0")]
private BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.ContentInfo ReadPkcs7(PemObject pemObject)
{
return BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.ContentInfo.GetInstance(Asn1Object.FromByteArray(pemObject.content));
}
// Token: 0x060080B0 RID: 32944 RVA: 0x001B3118 File Offset: 0x001B1318
[Token(Token = "0x60080B0")]
[Address(RVA = "0x4DC5A0", Offset = "0x4DAFA0", VA = "0x1804DC5A0")]
private object ReadPrivateKey(PemObject pemObject)
{
AsymmetricCipherKeyPair asymmetricCipherKeyPair;
for (;;)
{
int num = 0;
string type = pemObject.type;
int stringLength = type.m_stringLength;
int num2 = 0;
string text = type.Substring(num2, stringLength).Trim();
IDictionary dictionary = Platform.CreateHashtable();
IList headers = pemObject.headers;
if (dictionary != 0)
{
if (num < dictionary)
{
num += num;
num++;
}
ulong num3;
num3 += (ulong)1L;
if (dictionary == 0)
{
goto IL_1F4;
}
if (num < dictionary)
{
num += num;
num++;
}
num++;
num += 19;
}
if (num != 0)
{
}
if (num != -1)
{
}
if (num == 0 && (num == 0 || num != 0))
{
int num4 = 0;
if (num != 0)
{
if (num4 == 0 || num == 0)
{
continue;
}
uint num5;
(new char[1])[0] = (char)num5;
if (num == 0)
{
continue;
}
string[] array;
string text2 = array[0].Trim();
byte[] array2 = Hex.Decode(array[1].Trim());
}
byte[] array3;
Asn1Sequence instance = Asn1Sequence.GetInstance(array3);
if (instance != 0)
{
Asn1Encodable asn1Encodable;
if (asn1Encodable != (ulong)9L)
{
continue;
}
RsaPrivateKeyStructure instance2 = RsaPrivateKeyStructure.GetInstance(instance);
BigInteger modulus = instance2.modulus;
BigInteger publicExponent = instance2.publicExponent;
int num6;
RsaKeyParameters rsaKeyParameters = new RsaKeyParameters(num6 != 0, modulus, publicExponent);
num6 = 0;
BigInteger privateExponent = instance2.privateExponent;
BigInteger prime = instance2.prime1;
BigInteger coefficient = instance2.coefficient;
}
RsaPrivateCrtKeyParameters rsaPrivateCrtKeyParameters;
if (rsaPrivateCrtKeyParameters != 0)
{
BigInteger bigInteger;
BigInteger bigInteger2;
BigInteger bigInteger3;
DsaParameters dsaParameters = new DsaParameters(bigInteger, bigInteger2, bigInteger3);
BigInteger bigInteger4;
DsaPrivateKeyParameters dsaPrivateKeyParameters = new DsaPrivateKeyParameters(bigInteger4, dsaParameters);
BigInteger bigInteger5;
if (new DsaPublicKeyParameters(bigInteger5, dsaParameters) != 0)
{
ECPrivateKeyStructure instance3 = ECPrivateKeyStructure.GetInstance(dsaParameters);
DerObjectIdentifier idECPublicKey = X9ObjectIdentifiers.IdECPublicKey;
DerBitString publicKey = instance3.GetPublicKey();
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(idECPublicKey, publicKey);
Asn1Object asn1Object = instance3.ToAsn1Object();
AsymmetricKeyParameter asymmetricKeyParameter = PrivateKeyFactory.CreateKey(new PrivateKeyInfo(algorithmIdentifier, asn1Object));
if (instance3.GetKey() == 0)
{
}
SubjectPublicKeyInfo subjectPublicKeyInfo;
asymmetricCipherKeyPair = new AsymmetricCipherKeyPair(PublicKeyFactory.CreateKey(subjectPublicKeyInfo), asymmetricKeyParameter);
}
if (asymmetricCipherKeyPair == 0)
{
goto IL_1DA;
}
int sign = bigInteger.sign;
if (asymmetricCipherKeyPair != 0)
{
break;
}
}
}
}
EncryptedPrivateKeyInfo instance4 = EncryptedPrivateKeyInfo.GetInstance(asymmetricCipherKeyPair);
IL_1DA:
AsymmetricKeyParameter asymmetricKeyParameter3;
AsymmetricKeyParameter asymmetricKeyParameter2 = PrivateKeyFactory.CreateKey(PrivateKeyInfo.GetInstance(asymmetricKeyParameter3));
throw new NullReferenceException();
IL_1F4:
throw new NullReferenceException();
}
// Token: 0x060080B1 RID: 32945 RVA: 0x001B3324 File Offset: 0x001B1524
[Token(Token = "0x60080B1")]
[Address(RVA = "0x4DBCF0", Offset = "0x4DA6F0", VA = "0x1804DBCF0")]
private static X9ECParameters GetCurveParameters(string name)
{
/*
An exception occurred when decompiling this method (060080B1)
ICSharpCode.Decompiler.DecompilerException: Error decompiling BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9.X9ECParameters BestHTTP.SecureProtocol.Org.BouncyCastle.OpenSsl.PemReader::GetCurveParameters(System.String)
---> System.Exception: Basic block has to end with unconditional control flow.
{
IL_16:
stloc:Exception(var_1_26, newobj:Exception(Exception::.ctor, call:string(string::Concat, ldstr:string("unknown curve name: "), ldloc:string(name))))
}
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1852
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1846
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.Optimize(DecompilerContext context, ILBlock method, AutoPropertyProvider autoPropertyProvider, StateMachineKind& stateMachineKind, MethodDef& inlinedMethod, AsyncMethodDebugInfo& asyncInfo, ILAstOptimizationStep abortBeforeStep) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 355
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters, MethodDebugInfoBuilder& builder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 123
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 88
--- End of inner exception stack trace ---
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 92
at ICSharpCode.Decompiler.Ast.AstBuilder.AddMethodBody(EntityDeclaration methodNode, EntityDeclaration& updatedNode, MethodDef method, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, MethodKind methodKind) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstBuilder.cs:line 1663
*/;
}
// Token: 0x04005AF8 RID: 23288
[global::Cpp2IlInjected.FieldOffset(Offset = "0x18")]
[Token(Token = "0x4005AF8")]
private readonly IPasswordFinder pFinder;
}
}