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

504 lines
18 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.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
using Cpp2IlInjected;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
// Token: 0x0200176A RID: 5994
[Token(Token = "0x200176A")]
[StructLayout(3)]
public class CmsSignedDataParser : CmsContentInfoParser
{
// Token: 0x0600A1E6 RID: 41446 RVA: 0x0025A70C File Offset: 0x0025890C
[Token(Token = "0x600A1E6")]
[Address(RVA = "0x1C7D9E0", Offset = "0x1C7C3E0", VA = "0x181C7D9E0")]
public CmsSignedDataParser(byte[] sigBlock)
{
int num;
MemoryStream memoryStream = new MemoryStream(sigBlock, num != 0);
num = 0;
}
// Token: 0x0600A1E7 RID: 41447 RVA: 0x0025A728 File Offset: 0x00258928
[Token(Token = "0x600A1E7")]
[Address(RVA = "0x1C7D4C0", Offset = "0x1C7BEC0", VA = "0x181C7D4C0")]
public CmsSignedDataParser(CmsTypedStream signedContent, byte[] sigBlock)
{
int num;
MemoryStream memoryStream = new MemoryStream(sigBlock, num != 0);
num = 0;
}
// Token: 0x0600A1E8 RID: 41448 RVA: 0x0025A740 File Offset: 0x00258940
[Token(Token = "0x600A1E8")]
[Address(RVA = "0x1C7D9D0", Offset = "0x1C7C3D0", VA = "0x181C7D9D0")]
public CmsSignedDataParser(Stream sigData)
{
}
// Token: 0x0600A1E9 RID: 41449 RVA: 0x0025A750 File Offset: 0x00258950
[Token(Token = "0x600A1E9")]
[Address(RVA = "0x1C7D540", Offset = "0x1C7BF40", VA = "0x181C7D540")]
public CmsSignedDataParser(CmsTypedStream signedContent, Stream sigData)
: base(sigData)
{
this._signedContent = signedContent;
IAsn1Convertible content = this.contentInfo.GetContent(16);
SignedDataParser signedDataParser;
this._signedData = signedDataParser;
IDictionary dictionary = Platform.CreateHashtable();
this._digests = dictionary;
HashSet hashSet = new HashSet();
this._digestOids = hashSet;
if (this._signedData.GetDigestAlgorithms() != 0)
{
AlgorithmIdentifier algorithmIdentifier;
Asn1Object asn1Object = algorithmIdentifier.ToAsn1Object();
CmsSignedHelper helper = CmsSignedDataParser.Helper;
IDictionary digests = this._digests;
string text;
if (text == 0)
{
IDictionary digests2 = this._digests;
IDigest digestInstance = CmsSignedDataParser.Helper.GetDigestInstance(text);
ISet digestOids = this._digestOids;
}
}
ContentInfoParser encapContentInfo = this._signedData.GetEncapContentInfo();
IAsn1Convertible content2 = encapContentInfo.GetContent(4);
if (content2 != 0)
{
if (content2 == 0)
{
throw new NullReferenceException();
}
DerObjectIdentifier contentType = encapContentInfo.contentType;
if (this._signedContent == (ulong)0L)
{
goto IL_F0;
}
CmsTypedStream cmsTypedStream;
Streams.Drain(cmsTypedStream._in);
Platform.Dispose(cmsTypedStream._in);
}
CmsTypedStream signedContent2 = this._signedContent;
if (signedContent2 == 0)
{
DerObjectIdentifier contentType2 = encapContentInfo.contentType;
}
IL_F0:
DerObjectIdentifier derObjectIdentifier = new DerObjectIdentifier(signedContent2._oid);
this._signedContentType = derObjectIdentifier;
}
// Token: 0x17001968 RID: 6504
// (get) Token: 0x0600A1EA RID: 41450 RVA: 0x0025A8C4 File Offset: 0x00258AC4
[Token(Token = "0x17001968")]
public int Version
{
[Token(Token = "0x600A1EA")]
[Address(RVA = "0x1C7DAB0", Offset = "0x1C7C4B0", VA = "0x181C7DAB0")]
get
{
return this._signedData._version.Value.IntValue;
}
}
// Token: 0x17001969 RID: 6505
// (get) Token: 0x0600A1EB RID: 41451 RVA: 0x0025A8EC File Offset: 0x00258AEC
[Token(Token = "0x17001969")]
public ISet DigestOids
{
[Token(Token = "0x600A1EB")]
[Address(RVA = "0x1C7DA50", Offset = "0x1C7C450", VA = "0x181C7DA50")]
get
{
/*
An exception occurred when decompiling this method (0600A1EB)
ICSharpCode.Decompiler.DecompilerException: Error decompiling BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections.ISet BestHTTP.SecureProtocol.Org.BouncyCastle.Cms.CmsSignedDataParser::get_DigestOids()
---> System.Exception: Basic block has to end with unconditional control flow.
{
Block_0:
stloc:HashSet(var_0_0B, newobj:HashSet(HashSet::.ctor, ldfld:ISet[exp:IEnumerable](CmsSignedDataParser::_digestOids, ldloc:CmsSignedDataParser(this))))
}
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.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: 0x0600A1EC RID: 41452 RVA: 0x0025A904 File Offset: 0x00258B04
[Token(Token = "0x600A1EC")]
[Address(RVA = "0x1C7C930", Offset = "0x1C7B330", VA = "0x181C7C930")]
public SignerInformationStore GetSignerInfos()
{
int num = 0;
SignerInformationStore signerInfoStore = this._signerInfoStore;
if (signerInfoStore == 0)
{
this.PopulateCertCrlSets();
IList list = Platform.CreateArrayList();
IDictionary dictionary = Platform.CreateHashtable();
IDictionary digests = this._digests;
if (dictionary != 0)
{
IDictionary digests2 = this._digests;
}
int num2 = 0;
byte[] array;
if (array != 0)
{
}
if (num2 != -1)
{
}
if (num != 0)
{
throw new NullReferenceException();
}
if (this._signedData.GetSignerInfos() != 0)
{
CmsSignedHelper helper = CmsSignedDataParser.Helper;
SignerInfo signerInfo;
Asn1Object asn1Object = signerInfo.digAlgorithm.ToAsn1Object();
DerObjectIdentifier signedContentType = this._signedContentType;
BaseDigestCalculator baseDigestCalculator;
string text;
baseDigestCalculator.digest = text;
int num3;
SignerInformation signerInformation = new SignerInformation(signerInfo, signedContentType, num3, baseDigestCalculator);
num3 = 0;
}
SignerInformationStore signerInformationStore;
this._signerInfoStore = signerInformationStore;
}
return signerInfoStore;
}
// Token: 0x0600A1ED RID: 41453 RVA: 0x0025AA0C File Offset: 0x00258C0C
[Token(Token = "0x600A1ED")]
[Address(RVA = "0x1C7C4A0", Offset = "0x1C7AEA0", VA = "0x181C7C4A0")]
public IX509Store GetAttributeCertificates(string type)
{
IX509Store attributeStore = this._attributeStore;
if (attributeStore == 0)
{
this.PopulateCertCrlSets();
CmsSignedHelper helper = CmsSignedDataParser.Helper;
Asn1Set certSet = this._certSet;
IX509Store ix509Store = helper.CreateAttributeStore(type, certSet);
this._attributeStore = ix509Store;
}
return attributeStore;
}
// Token: 0x0600A1EE RID: 41454 RVA: 0x0025AA50 File Offset: 0x00258C50
[Token(Token = "0x600A1EE")]
[Address(RVA = "0x1C7C540", Offset = "0x1C7AF40", VA = "0x181C7C540")]
public IX509Store GetCertificates(string type)
{
IX509Store certificateStore = this._certificateStore;
if (certificateStore == 0)
{
this.PopulateCertCrlSets();
CmsSignedHelper helper = CmsSignedDataParser.Helper;
Asn1Set certSet = this._certSet;
IX509Store ix509Store = helper.CreateCertificateStore(type, certSet);
this._certificateStore = ix509Store;
}
return certificateStore;
}
// Token: 0x0600A1EF RID: 41455 RVA: 0x0025AA94 File Offset: 0x00258C94
[Token(Token = "0x600A1EF")]
[Address(RVA = "0x1C7C5E0", Offset = "0x1C7AFE0", VA = "0x181C7C5E0")]
public IX509Store GetCrls(string type)
{
IX509Store crlStore = this._crlStore;
if (crlStore == 0)
{
this.PopulateCertCrlSets();
CmsSignedHelper helper = CmsSignedDataParser.Helper;
Asn1Set crlSet = this._crlSet;
IX509Store ix509Store = helper.CreateCrlStore(type, crlSet);
this._crlStore = ix509Store;
}
return crlStore;
}
// Token: 0x0600A1F0 RID: 41456 RVA: 0x0025AAD8 File Offset: 0x00258CD8
[Token(Token = "0x600A1F0")]
[Address(RVA = "0x1C7CDC0", Offset = "0x1C7B7C0", VA = "0x181C7CDC0")]
private void PopulateCertCrlSets()
{
if (!this._isCertCrlParsed)
{
this._isCertCrlParsed = true;
if (this._signedData.GetCertificates() == 0)
{
}
Asn1Set asn1Set;
this._certSet = asn1Set;
if (this._signedData.GetCrls() != 0)
{
}
Asn1Set asn1Set2;
this._crlSet = asn1Set2;
}
}
// Token: 0x1700196A RID: 6506
// (get) Token: 0x0600A1F1 RID: 41457 RVA: 0x0025AB2C File Offset: 0x00258D2C
[Token(Token = "0x1700196A")]
public DerObjectIdentifier SignedContentType
{
[Token(Token = "0x600A1F1")]
[Address(RVA = "0x3C1230", Offset = "0x3BFC30", VA = "0x1803C1230")]
get
{
return this._signedContentType;
}
}
// Token: 0x0600A1F2 RID: 41458 RVA: 0x0025AB40 File Offset: 0x00258D40
[Token(Token = "0x600A1F2")]
[Address(RVA = "0x1C7C680", Offset = "0x1C7B080", VA = "0x181C7C680")]
public CmsTypedStream GetSignedContent()
{
int num;
CmsTypedStream signedContent;
DigestStream digestStream;
do
{
num = 0;
signedContent = this._signedContent;
if (signedContent == 0)
{
return signedContent;
}
IDictionary digests = this._digests;
if (signedContent != 0)
{
if (num < signedContent)
{
num += num;
num++;
}
if (signedContent == 0)
{
}
if (signedContent == 0)
{
goto IL_58;
}
}
if (digestStream != 0)
{
}
if (num != -1)
{
}
}
while (num != 0);
uint num2;
CmsTypedStream cmsTypedStream = new CmsTypedStream(this._signedContent._oid, digestStream, (int)num2);
return signedContent;
IL_58:
throw new NullReferenceException();
}
// Token: 0x0600A1F3 RID: 41459 RVA: 0x0025ABAC File Offset: 0x00258DAC
[Token(Token = "0x600A1F3")]
[Address(RVA = "0x1C7D140", Offset = "0x1C7BB40", VA = "0x181C7D140")]
public static Stream ReplaceSigners(Stream original, SignerInformationStore signerInformationStore, Stream outStr)
{
CmsSignedDataStreamGenerator cmsSignedDataStreamGenerator = new CmsSignedDataStreamGenerator();
int num;
CmsSignedDataParser cmsSignedDataParser = new CmsSignedDataParser(num, original);
num = 0;
cmsSignedDataStreamGenerator.AddSigners(signerInformationStore);
CmsTypedStream signedContent = cmsSignedDataParser.GetSignedContent();
DerObjectIdentifier signedContentType = cmsSignedDataParser._signedContentType;
bool flag = signedContent != 0;
string identifier = signedContentType.identifier;
int num2 = 0;
Stream stream = cmsSignedDataStreamGenerator.Open(outStr, identifier, flag, num2);
if (flag)
{
Streams.PipeAll(signedContent._in, stream);
}
IX509Store ix509Store;
if (cmsSignedDataParser._attributeStore == 0)
{
cmsSignedDataParser.PopulateCertCrlSets();
CmsSignedHelper helper = CmsSignedDataParser.Helper;
Asn1Set certSet = cmsSignedDataParser._certSet;
ix509Store = helper.CreateAttributeStore("Collection", certSet);
cmsSignedDataParser._attributeStore = ix509Store;
}
cmsSignedDataStreamGenerator.AddAttributeCertificates(ix509Store);
IX509Store ix509Store2;
if (cmsSignedDataParser._certificateStore == 0)
{
cmsSignedDataParser.PopulateCertCrlSets();
CmsSignedHelper helper2 = CmsSignedDataParser.Helper;
Asn1Set certSet2 = cmsSignedDataParser._certSet;
ix509Store2 = helper2.CreateCertificateStore("Collection", certSet2);
cmsSignedDataParser._certificateStore = ix509Store2;
}
IList certs = cmsSignedDataStreamGenerator._certs;
IList certificatesFromStore = CmsUtilities.GetCertificatesFromStore(ix509Store2);
CollectionUtilities.AddRange(certs, certificatesFromStore);
IX509Store ix509Store3;
if (cmsSignedDataParser._crlStore == 0)
{
cmsSignedDataParser.PopulateCertCrlSets();
CmsSignedHelper helper3 = CmsSignedDataParser.Helper;
Asn1Set crlSet = cmsSignedDataParser._crlSet;
ix509Store3 = helper3.CreateCrlStore("Collection", crlSet);
cmsSignedDataParser._crlStore = ix509Store3;
}
IList crls = cmsSignedDataStreamGenerator._crls;
IList crlsFromStore = CmsUtilities.GetCrlsFromStore(ix509Store3);
CollectionUtilities.AddRange(crls, crlsFromStore);
Platform.Dispose(stream);
return outStr;
}
// Token: 0x0600A1F4 RID: 41460 RVA: 0x0025AD04 File Offset: 0x00258F04
[Token(Token = "0x600A1F4")]
[Address(RVA = "0x1C7CF40", Offset = "0x1C7B940", VA = "0x181C7CF40")]
public static Stream ReplaceCertificatesAndCrls(Stream original, IX509Store x509Certs, IX509Store x509Crls, IX509Store x509AttrCerts, Stream outStr)
{
CmsSignedDataStreamGenerator cmsSignedDataStreamGenerator = new CmsSignedDataStreamGenerator();
int num;
CmsSignedDataParser cmsSignedDataParser = new CmsSignedDataParser(num, original);
num = 0;
HashSet hashSet = new HashSet(cmsSignedDataParser._digestOids);
cmsSignedDataStreamGenerator.AddDigests(hashSet);
CmsTypedStream signedContent = cmsSignedDataParser.GetSignedContent();
DerObjectIdentifier signedContentType = cmsSignedDataParser._signedContentType;
bool flag = signedContent != 0;
Stream stream;
if (flag)
{
Streams.PipeAll(signedContent._in, stream);
}
if (x509AttrCerts != 0)
{
cmsSignedDataStreamGenerator.AddAttributeCertificates(x509AttrCerts);
}
if (x509Certs != 0)
{
IList certs = cmsSignedDataStreamGenerator._certs;
IList certificatesFromStore = CmsUtilities.GetCertificatesFromStore(x509Certs);
CollectionUtilities.AddRange(certs, certificatesFromStore);
}
if (x509Crls != 0)
{
IList crls = cmsSignedDataStreamGenerator._crls;
IList crlsFromStore = CmsUtilities.GetCrlsFromStore(x509Crls);
CollectionUtilities.AddRange(crls, crlsFromStore);
}
SignerInformationStore signerInfos = cmsSignedDataParser.GetSignerInfos();
cmsSignedDataStreamGenerator.AddSigners(signerInfos);
Platform.Dispose(stream);
throw new NullReferenceException();
}
// Token: 0x0600A1F5 RID: 41461 RVA: 0x0025ADC8 File Offset: 0x00258FC8
[Token(Token = "0x600A1F5")]
[Address(RVA = "0x1C7C440", Offset = "0x1C7AE40", VA = "0x181C7C440")]
private static Asn1Set GetAsn1Set(Asn1SetParser asn1SetParser)
{
if (asn1SetParser == 0)
{
}
return Asn1Set.GetInstance(0);
}
// Token: 0x04006A83 RID: 27267
[Token(Token = "0x4006A83")]
private static readonly CmsSignedHelper Helper = CmsSignedHelper.Instance;
// Token: 0x04006A84 RID: 27268
[global::Cpp2IlInjected.FieldOffset(Offset = "0x20")]
[Token(Token = "0x4006A84")]
private SignedDataParser _signedData;
// Token: 0x04006A85 RID: 27269
[global::Cpp2IlInjected.FieldOffset(Offset = "0x28")]
[Token(Token = "0x4006A85")]
private DerObjectIdentifier _signedContentType;
// Token: 0x04006A86 RID: 27270
[global::Cpp2IlInjected.FieldOffset(Offset = "0x30")]
[Token(Token = "0x4006A86")]
private CmsTypedStream _signedContent;
// Token: 0x04006A87 RID: 27271
[global::Cpp2IlInjected.FieldOffset(Offset = "0x38")]
[Token(Token = "0x4006A87")]
private IDictionary _digests;
// Token: 0x04006A88 RID: 27272
[global::Cpp2IlInjected.FieldOffset(Offset = "0x40")]
[Token(Token = "0x4006A88")]
private ISet _digestOids;
// Token: 0x04006A89 RID: 27273
[global::Cpp2IlInjected.FieldOffset(Offset = "0x48")]
[Token(Token = "0x4006A89")]
private SignerInformationStore _signerInfoStore;
// Token: 0x04006A8A RID: 27274
[global::Cpp2IlInjected.FieldOffset(Offset = "0x50")]
[Token(Token = "0x4006A8A")]
private Asn1Set _certSet;
// Token: 0x04006A8B RID: 27275
[global::Cpp2IlInjected.FieldOffset(Offset = "0x58")]
[Token(Token = "0x4006A8B")]
private Asn1Set _crlSet;
// Token: 0x04006A8C RID: 27276
[global::Cpp2IlInjected.FieldOffset(Offset = "0x60")]
[Token(Token = "0x4006A8C")]
private bool _isCertCrlParsed;
// Token: 0x04006A8D RID: 27277
[global::Cpp2IlInjected.FieldOffset(Offset = "0x68")]
[Token(Token = "0x4006A8D")]
private IX509Store _attributeStore;
// Token: 0x04006A8E RID: 27278
[global::Cpp2IlInjected.FieldOffset(Offset = "0x70")]
[Token(Token = "0x4006A8E")]
private IX509Store _certificateStore;
// Token: 0x04006A8F RID: 27279
[global::Cpp2IlInjected.FieldOffset(Offset = "0x78")]
[Token(Token = "0x4006A8F")]
private IX509Store _crlStore;
}
}