Files
niko c12fbe3fc6 m
2026-04-12 16:51:38 +02:00

486 lines
17 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.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: 0x02001E27 RID: 7719
[Token(Token = "0x2001E27")]
public class CmsSignedDataParser : CmsContentInfoParser
{
// Token: 0x0600C18E RID: 49550 RVA: 0x002BB398 File Offset: 0x002B9598
[Token(Token = "0x600C18E")]
[Address(RVA = "0x214B980", Offset = "0x214A980", VA = "0x18214B980")]
public CmsSignedDataParser(byte[] sigBlock)
{
int num;
MemoryStream memoryStream = new MemoryStream(sigBlock, num != 0);
num = 0;
}
// Token: 0x0600C18F RID: 49551 RVA: 0x002BB3B4 File Offset: 0x002B95B4
[Token(Token = "0x600C18F")]
[Address(RVA = "0x214B4C0", Offset = "0x214A4C0", VA = "0x18214B4C0")]
public CmsSignedDataParser(CmsTypedStream signedContent, byte[] sigBlock)
{
int num;
MemoryStream memoryStream = new MemoryStream(sigBlock, num != 0);
num = 0;
}
// Token: 0x0600C190 RID: 49552 RVA: 0x002BB3CC File Offset: 0x002B95CC
[Token(Token = "0x600C190")]
[Address(RVA = "0x214B970", Offset = "0x214A970", VA = "0x18214B970")]
public CmsSignedDataParser(Stream sigData)
{
}
// Token: 0x0600C191 RID: 49553 RVA: 0x002BB3DC File Offset: 0x002B95DC
[Token(Token = "0x600C191")]
[Address(RVA = "0x214B540", Offset = "0x214A540", VA = "0x18214B540")]
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_DF;
}
CmsTypedStream cmsTypedStream;
cmsTypedStream.Drain();
}
CmsTypedStream signedContent2 = this._signedContent;
if (signedContent2 == 0)
{
DerObjectIdentifier contentType2 = encapContentInfo.contentType;
}
IL_DF:
DerObjectIdentifier derObjectIdentifier = new DerObjectIdentifier(signedContent2._oid);
this._signedContentType = derObjectIdentifier;
}
// Token: 0x17001E06 RID: 7686
// (get) Token: 0x0600C192 RID: 49554 RVA: 0x002BB540 File Offset: 0x002B9740
[Token(Token = "0x17001E06")]
public int Version
{
[Token(Token = "0x600C192")]
[Address(RVA = "0x214BA50", Offset = "0x214AA50", VA = "0x18214BA50")]
get
{
return this._signedData._version.Value.IntValue;
}
}
// Token: 0x17001E07 RID: 7687
// (get) Token: 0x0600C193 RID: 49555 RVA: 0x002BB568 File Offset: 0x002B9768
[Token(Token = "0x17001E07")]
public ISet DigestOids
{
[Token(Token = "0x600C193")]
[Address(RVA = "0x214B9F0", Offset = "0x214A9F0", VA = "0x18214B9F0")]
get
{
/*
An exception occurred when decompiling this method (0600C193)
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: 0x0600C194 RID: 49556 RVA: 0x002BB580 File Offset: 0x002B9780
[Token(Token = "0x600C194")]
[Address(RVA = "0x214A9A0", Offset = "0x21499A0", VA = "0x18214A9A0")]
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;
}
byte[] array;
if (array != 0)
{
}
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 num2;
SignerInformation signerInformation = new SignerInformation(signerInfo, signedContentType, num2, baseDigestCalculator);
num2 = 0;
}
SignerInformationStore signerInformationStore;
this._signerInfoStore = signerInformationStore;
}
return signerInfoStore;
}
// Token: 0x0600C195 RID: 49557 RVA: 0x002BB680 File Offset: 0x002B9880
[Token(Token = "0x600C195")]
[Address(RVA = "0x214A560", Offset = "0x2149560", VA = "0x18214A560")]
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: 0x0600C196 RID: 49558 RVA: 0x002BB6C4 File Offset: 0x002B98C4
[Token(Token = "0x600C196")]
[Address(RVA = "0x214A600", Offset = "0x2149600", VA = "0x18214A600")]
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: 0x0600C197 RID: 49559 RVA: 0x002BB708 File Offset: 0x002B9908
[Token(Token = "0x600C197")]
[Address(RVA = "0x214A6A0", Offset = "0x21496A0", VA = "0x18214A6A0")]
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: 0x0600C198 RID: 49560 RVA: 0x002BB74C File Offset: 0x002B994C
[Token(Token = "0x600C198")]
[Address(RVA = "0x214AE00", Offset = "0x2149E00", VA = "0x18214AE00")]
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: 0x17001E08 RID: 7688
// (get) Token: 0x0600C199 RID: 49561 RVA: 0x002BB7A0 File Offset: 0x002B99A0
[Token(Token = "0x17001E08")]
public DerObjectIdentifier SignedContentType
{
[Token(Token = "0x600C199")]
[Address(RVA = "0x4157D0", Offset = "0x4147D0", VA = "0x1804157D0")]
get
{
return this._signedContentType;
}
}
// Token: 0x0600C19A RID: 49562 RVA: 0x002BB7B4 File Offset: 0x002B99B4
[Token(Token = "0x600C19A")]
[Address(RVA = "0x214A740", Offset = "0x2149740", VA = "0x18214A740")]
public CmsTypedStream GetSignedContent()
{
int num;
CmsTypedStream signedContent;
DigestStream digestStream;
do
{
num = 0;
signedContent = this._signedContent;
if (signedContent == 0)
{
return signedContent;
}
Stream @in = signedContent._in;
IDictionary digests = this._digests;
if (signedContent != 0)
{
if (num < signedContent)
{
num += num;
num++;
}
if (num == 0)
{
num++;
num += 19;
}
if (num == 0)
{
goto IL_6F;
}
int num2;
digestStream = new DigestStream(@in, num, num2);
num2 = 0;
}
if (digestStream != 0)
{
}
}
while (num != 0);
CmsTypedStream cmsTypedStream = new CmsTypedStream(this._signedContent._oid, digestStream);
return signedContent;
IL_6F:
throw new NullReferenceException();
}
// Token: 0x0600C19B RID: 49563 RVA: 0x002BB838 File Offset: 0x002B9A38
[Token(Token = "0x600C19B")]
[Address(RVA = "0x214B160", Offset = "0x214A160", VA = "0x18214B160")]
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;
Stream stream = cmsSignedDataStreamGenerator.Open(outStr, identifier, flag);
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;
}
cmsSignedDataStreamGenerator.AddCertificates(ix509Store2);
IX509Store ix509Store3;
if (cmsSignedDataParser._crlStore == 0)
{
cmsSignedDataParser.PopulateCertCrlSets();
CmsSignedHelper helper3 = CmsSignedDataParser.Helper;
Asn1Set crlSet = cmsSignedDataParser._crlSet;
ix509Store3 = helper3.CreateCrlStore("Collection", crlSet);
cmsSignedDataParser._crlStore = ix509Store3;
}
cmsSignedDataStreamGenerator.AddCrls(ix509Store3);
Platform.Dispose(stream);
return outStr;
}
// Token: 0x0600C19C RID: 49564 RVA: 0x002BB964 File Offset: 0x002B9B64
[Token(Token = "0x600C19C")]
[Address(RVA = "0x214AF80", Offset = "0x2149F80", VA = "0x18214AF80")]
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;
Streams.PipeAll(signedContent._in, stream);
if (x509AttrCerts != 0)
{
cmsSignedDataStreamGenerator.AddAttributeCertificates(x509AttrCerts);
}
if (x509Certs != 0)
{
cmsSignedDataStreamGenerator.AddCertificates(x509Certs);
}
if (x509Crls != 0)
{
cmsSignedDataStreamGenerator.AddCrls(x509Crls);
}
SignerInformationStore signerInfos = cmsSignedDataParser.GetSignerInfos();
cmsSignedDataStreamGenerator.AddSigners(signerInfos);
throw new NullReferenceException();
}
// Token: 0x0600C19D RID: 49565 RVA: 0x002BB9F4 File Offset: 0x002B9BF4
[Token(Token = "0x600C19D")]
[Address(RVA = "0x214A500", Offset = "0x2149500", VA = "0x18214A500")]
private static Asn1Set GetAsn1Set(Asn1SetParser asn1SetParser)
{
if (asn1SetParser == 0)
{
}
return Asn1Set.GetInstance(0);
}
// Token: 0x04007A7F RID: 31359
[Token(Token = "0x4007A7F")]
private static readonly CmsSignedHelper Helper = CmsSignedHelper.Instance;
// Token: 0x04007A80 RID: 31360
[FieldOffset(Offset = "0x20")]
[Token(Token = "0x4007A80")]
private SignedDataParser _signedData;
// Token: 0x04007A81 RID: 31361
[FieldOffset(Offset = "0x28")]
[Token(Token = "0x4007A81")]
private DerObjectIdentifier _signedContentType;
// Token: 0x04007A82 RID: 31362
[FieldOffset(Offset = "0x30")]
[Token(Token = "0x4007A82")]
private CmsTypedStream _signedContent;
// Token: 0x04007A83 RID: 31363
[FieldOffset(Offset = "0x38")]
[Token(Token = "0x4007A83")]
private IDictionary _digests;
// Token: 0x04007A84 RID: 31364
[FieldOffset(Offset = "0x40")]
[Token(Token = "0x4007A84")]
private ISet _digestOids;
// Token: 0x04007A85 RID: 31365
[FieldOffset(Offset = "0x48")]
[Token(Token = "0x4007A85")]
private SignerInformationStore _signerInfoStore;
// Token: 0x04007A86 RID: 31366
[FieldOffset(Offset = "0x50")]
[Token(Token = "0x4007A86")]
private Asn1Set _certSet;
// Token: 0x04007A87 RID: 31367
[FieldOffset(Offset = "0x58")]
[Token(Token = "0x4007A87")]
private Asn1Set _crlSet;
// Token: 0x04007A88 RID: 31368
[FieldOffset(Offset = "0x60")]
[Token(Token = "0x4007A88")]
private bool _isCertCrlParsed;
// Token: 0x04007A89 RID: 31369
[FieldOffset(Offset = "0x68")]
[Token(Token = "0x4007A89")]
private IX509Store _attributeStore;
// Token: 0x04007A8A RID: 31370
[FieldOffset(Offset = "0x70")]
[Token(Token = "0x4007A8A")]
private IX509Store _certificateStore;
// Token: 0x04007A8B RID: 31371
[FieldOffset(Offset = "0x78")]
[Token(Token = "0x4007A8B")]
private IX509Store _crlStore;
}
}