368 lines
15 KiB
C#
368 lines
15 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
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: 0x02001A78 RID: 6776
|
|
[Token(Token = "0x2001A78")]
|
|
public class PemReader : PemReader
|
|
{
|
|
// Token: 0x0600A04D RID: 41037 RVA: 0x0000220F File Offset: 0x0000040F
|
|
[Token(Token = "0x600A04D")]
|
|
[Address(RVA = "0x4242D0", Offset = "0x4232D0", VA = "0x1804242D0")]
|
|
static PemReader()
|
|
{
|
|
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
|
|
}
|
|
|
|
// Token: 0x0600A04E RID: 41038 RVA: 0x002130E4 File Offset: 0x002112E4
|
|
[Token(Token = "0x600A04E")]
|
|
[Address(RVA = "0xD05980", Offset = "0xD04980", VA = "0x180D05980")]
|
|
public PemReader(TextReader reader)
|
|
: base(reader)
|
|
{
|
|
this.pFinder = (ulong)0L;
|
|
}
|
|
|
|
// Token: 0x0600A04F RID: 41039 RVA: 0x00213104 File Offset: 0x00211304
|
|
[Token(Token = "0x600A04F")]
|
|
[Address(RVA = "0xD05950", Offset = "0xD04950", VA = "0x180D05950")]
|
|
public PemReader(TextReader reader, IPasswordFinder pFinder)
|
|
: base(reader)
|
|
{
|
|
this.pFinder = pFinder;
|
|
}
|
|
|
|
// Token: 0x0600A050 RID: 41040 RVA: 0x00213120 File Offset: 0x00211320
|
|
[Token(Token = "0x600A050")]
|
|
[Address(RVA = "0xD04720", Offset = "0xD03720", VA = "0x180D04720")]
|
|
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: 0x0600A051 RID: 41041 RVA: 0x002132C4 File Offset: 0x002114C4
|
|
[Token(Token = "0x600A051")]
|
|
[Address(RVA = "0xD058B0", Offset = "0xD048B0", VA = "0x180D058B0")]
|
|
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: 0x0600A052 RID: 41042 RVA: 0x00213304 File Offset: 0x00211504
|
|
[Token(Token = "0x600A052")]
|
|
[Address(RVA = "0xD05880", Offset = "0xD04880", VA = "0x180D05880")]
|
|
private AsymmetricKeyParameter ReadPublicKey(PemObject pemObject)
|
|
{
|
|
return PublicKeyFactory.CreateKey(pemObject.content);
|
|
}
|
|
|
|
// Token: 0x0600A053 RID: 41043 RVA: 0x00213324 File Offset: 0x00211524
|
|
[Token(Token = "0x600A053")]
|
|
[Address(RVA = "0xD04540", Offset = "0xD03540", VA = "0x180D04540")]
|
|
private X509Certificate ReadCertificate(PemObject pemObject)
|
|
{
|
|
X509CertificateParser x509CertificateParser = new X509CertificateParser();
|
|
byte[] content = pemObject.content;
|
|
return x509CertificateParser.ReadCertificate(content);
|
|
}
|
|
|
|
// Token: 0x0600A054 RID: 41044 RVA: 0x00213360 File Offset: 0x00211560
|
|
[Token(Token = "0x600A054")]
|
|
[Address(RVA = "0xD04630", Offset = "0xD03630", VA = "0x180D04630")]
|
|
private X509Crl ReadCrl(PemObject pemObject)
|
|
{
|
|
X509CrlParser x509CrlParser = new X509CrlParser();
|
|
byte[] content = pemObject.content;
|
|
return x509CrlParser.ReadCrl(content);
|
|
}
|
|
|
|
// Token: 0x0600A055 RID: 41045 RVA: 0x0021339C File Offset: 0x0021159C
|
|
[Token(Token = "0x600A055")]
|
|
[Address(RVA = "0xD04460", Offset = "0xD03460", VA = "0x180D04460")]
|
|
private Pkcs10CertificationRequest ReadCertificateRequest(PemObject pemObject)
|
|
{
|
|
return new Pkcs10CertificationRequest(pemObject.content);
|
|
}
|
|
|
|
// Token: 0x0600A056 RID: 41046 RVA: 0x002133C8 File Offset: 0x002115C8
|
|
[Token(Token = "0x600A056")]
|
|
[Address(RVA = "0xD043F0", Offset = "0xD033F0", VA = "0x180D043F0")]
|
|
private IX509AttributeCertificate ReadAttributeCertificate(PemObject pemObject)
|
|
{
|
|
X509V2AttributeCertificate x509V2AttributeCertificate = new X509V2AttributeCertificate(pemObject.content);
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600A057 RID: 41047 RVA: 0x002133E8 File Offset: 0x002115E8
|
|
[Token(Token = "0x600A057")]
|
|
[Address(RVA = "0xD04B10", Offset = "0xD03B10", VA = "0x180D04B10")]
|
|
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: 0x0600A058 RID: 41048 RVA: 0x00213418 File Offset: 0x00211618
|
|
[Token(Token = "0x600A058")]
|
|
[Address(RVA = "0xD04BE0", Offset = "0xD03BE0", VA = "0x180D04BE0")]
|
|
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_1F0;
|
|
}
|
|
if (num < dictionary)
|
|
{
|
|
num += num;
|
|
num++;
|
|
}
|
|
num++;
|
|
num += 19;
|
|
}
|
|
if (num != 0)
|
|
{
|
|
}
|
|
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_1D6;
|
|
}
|
|
int sign = bigInteger.sign;
|
|
if (asymmetricCipherKeyPair != 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
EncryptedPrivateKeyInfo instance4 = EncryptedPrivateKeyInfo.GetInstance(asymmetricCipherKeyPair);
|
|
IL_1D6:
|
|
AsymmetricKeyParameter asymmetricKeyParameter3;
|
|
AsymmetricKeyParameter asymmetricKeyParameter2 = PrivateKeyFactory.CreateKey(PrivateKeyInfo.GetInstance(asymmetricKeyParameter3));
|
|
throw new NullReferenceException();
|
|
IL_1F0:
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600A059 RID: 41049 RVA: 0x00213620 File Offset: 0x00211820
|
|
[Token(Token = "0x600A059")]
|
|
[Address(RVA = "0xD04330", Offset = "0xD03330", VA = "0x180D04330")]
|
|
private static X9ECParameters GetCurveParameters(string name)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600A059)
|
|
|
|
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: 0x04006AF4 RID: 27380
|
|
[FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x4006AF4")]
|
|
private readonly IPasswordFinder pFinder;
|
|
}
|
|
}
|