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

389 lines
12 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.Ess;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Tsp;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
using Cpp2IlInjected;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tsp
{
// Token: 0x02001A4E RID: 6734
[Token(Token = "0x2001A4E")]
public class TimeStampToken
{
// Token: 0x06009E94 RID: 40596 RVA: 0x00209F34 File Offset: 0x00208134
[Token(Token = "0x6009E94")]
[Address(RVA = "0x5F26C0", Offset = "0x5F16C0", VA = "0x1805F26C0")]
public TimeStampToken(BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.ContentInfo contentInfo)
{
CmsSignedData cmsSignedData = new CmsSignedData(contentInfo);
}
// Token: 0x06009E95 RID: 40597 RVA: 0x00209F48 File Offset: 0x00208148
[Token(Token = "0x6009E95")]
[Address(RVA = "0x5F2730", Offset = "0x5F1730", VA = "0x1805F2730")]
public TimeStampToken(CmsSignedData signedData)
{
this.tsToken = signedData;
DerObjectIdentifier signedContentType = signedData.SignedContentType;
ICollection signers = this.tsToken.GetSignerInfos().GetSigners();
if (signers == (ulong)1L)
{
if (signers == 0)
{
}
int num = 0;
if (signers != 0)
{
this.tsaSignerInfo = signers;
CmsProcessable signedContent = this.tsToken.signedContent;
MemoryStream memoryStream = new MemoryStream();
if (num < signers)
{
num += num;
num++;
}
Asn1Object asn1Object;
TimeStampTokenInfo timeStampTokenInfo = new TimeStampTokenInfo(TstInfo.GetInstance(asn1Object));
this.tstInfo = timeStampTokenInfo;
BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.AttributeTable signedAttributes = this.tsaSignerInfo.SignedAttributes;
DerObjectIdentifier idAASigningCertificate = PkcsObjectIdentifiers.IdAASigningCertificate;
TimeStampToken.CertID certID;
if (signedAttributes[idAASigningCertificate] == 0)
{
BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.AttributeTable signedAttributes2 = this.tsaSignerInfo.SignedAttributes;
DerObjectIdentifier idAASigningCertificateV = PkcsObjectIdentifiers.IdAASigningCertificateV2;
BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.Attribute attribute = signedAttributes2[idAASigningCertificateV];
if (attribute == 0)
{
TspValidationException ex = new TspValidationException("no signing certificate attribute found, time stamp invalid.");
throw new NullReferenceException();
}
IEnumerator enumerator = attribute.attrValues.GetEnumerator();
int num2 = 0;
SigningCertificateV2 signingCertificateV;
EssCertIDv2[] certs = signingCertificateV.GetCerts();
num2 += num2;
EssCertIDv2 instance = EssCertIDv2.GetInstance(certs[0]);
certID.certIDv2 = instance;
certID.certID = num;
}
EssCertIDv2 certIDv = certID.certIDv2;
SigningCertificate signingCertificate;
EssCertID instance2 = EssCertID.GetInstance(signingCertificate.GetCerts()[0]);
TimeStampToken.CertID certID2;
certID2.certID = instance2;
certID2.certIDv2 = num;
this.certID = certID2;
return;
}
}
throw new NullReferenceException();
}
// Token: 0x1700195F RID: 6495
// (get) Token: 0x06009E96 RID: 40598 RVA: 0x0020A130 File Offset: 0x00208330
[Token(Token = "0x1700195F")]
public TimeStampTokenInfo TimeStampInfo
{
[Token(Token = "0x6009E96")]
[Address(RVA = "0x4157C0", Offset = "0x4147C0", VA = "0x1804157C0")]
get
{
return this.tstInfo;
}
}
// Token: 0x17001960 RID: 6496
// (get) Token: 0x06009E97 RID: 40599 RVA: 0x0020A144 File Offset: 0x00208344
[Token(Token = "0x17001960")]
public SignerID SignerID
{
[Token(Token = "0x6009E97")]
[Address(RVA = "0x5F2DD0", Offset = "0x5F1DD0", VA = "0x1805F2DD0")]
get
{
return this.tsaSignerInfo.sid;
}
}
// Token: 0x17001961 RID: 6497
// (get) Token: 0x06009E98 RID: 40600 RVA: 0x0020A164 File Offset: 0x00208364
[Token(Token = "0x17001961")]
public BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.AttributeTable SignedAttributes
{
[Token(Token = "0x6009E98")]
[Address(RVA = "0x5F2DB0", Offset = "0x5F1DB0", VA = "0x1805F2DB0")]
get
{
return this.tsaSignerInfo.SignedAttributes;
}
}
// Token: 0x17001962 RID: 6498
// (get) Token: 0x06009E99 RID: 40601 RVA: 0x0020A184 File Offset: 0x00208384
[Token(Token = "0x17001962")]
public BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.AttributeTable UnsignedAttributes
{
[Token(Token = "0x6009E99")]
[Address(RVA = "0x5F2DF0", Offset = "0x5F1DF0", VA = "0x1805F2DF0")]
get
{
return this.tsaSignerInfo.UnsignedAttributes;
}
}
// Token: 0x06009E9A RID: 40602 RVA: 0x0020A1A4 File Offset: 0x002083A4
[Token(Token = "0x6009E9A")]
[Address(RVA = "0x5F1F70", Offset = "0x5F0F70", VA = "0x1805F1F70")]
public IX509Store GetCertificates(string type)
{
return this.tsToken.GetCertificates(type);
}
// Token: 0x06009E9B RID: 40603 RVA: 0x0020A1C4 File Offset: 0x002083C4
[Token(Token = "0x6009E9B")]
[Address(RVA = "0x5F1F90", Offset = "0x5F0F90", VA = "0x1805F1F90")]
public IX509Store GetCrls(string type)
{
return this.tsToken.GetCrls(type);
}
// Token: 0x06009E9C RID: 40604 RVA: 0x0020A1E4 File Offset: 0x002083E4
[Token(Token = "0x6009E9C")]
[Address(RVA = "0x5F1F50", Offset = "0x5F0F50", VA = "0x1805F1F50")]
public IX509Store GetAttributeCertificates(string type)
{
return this.tsToken.GetAttributeCertificates(type);
}
// Token: 0x06009E9D RID: 40605 RVA: 0x0020A204 File Offset: 0x00208404
[Token(Token = "0x6009E9D")]
[Address(RVA = "0x5F1FD0", Offset = "0x5F0FD0", VA = "0x1805F1FD0")]
public void Validate(X509Certificate cert)
{
EssCertID essCertID3;
for (;;)
{
TimeStampToken.CertID certID = this.certID;
if (certID.certID == (ulong)0L)
{
DerObjectIdentifier idSha = NistObjectIdentifiers.IdSha256;
if (certID.certIDv2.hashAlgorithm.ToAsn1Object() == 0)
{
Asn1Object asn1Object = certID.certIDv2.hashAlgorithm.ToAsn1Object();
}
}
AsymmetricKeyParameter publicKey = cert.GetPublicKey();
EssCertID essCertID = this.certID.certID;
if (essCertID != 0)
{
int length = essCertID.GetCertHash().Length;
byte[] array;
byte[] array2;
if (!Arrays.ConstantTimeAreEqual(array, array2))
{
goto IL_21A;
}
TimeStampToken.CertID certID2 = this.certID;
EssCertID essCertID2 = certID2.certID;
if (essCertID2 != 0)
{
}
if (certID2.certIDv2.issuerSerial == 0)
{
goto IL_12E;
}
if (essCertID2 != 0)
{
DerInteger serial = essCertID2.issuerSerial.serial;
if (cert.Version == 0)
{
goto IL_1C6;
}
essCertID3 = this.certID.certID;
if (essCertID3 != 0)
{
break;
}
}
}
}
byte[] bytes = essCertID3.issuerSerial.serial.bytes;
X509Name issuerX509Principal = PrincipalUtilities.GetIssuerX509Principal(cert);
int num = 0;
GeneralName[] array3;
if (num == array3.Length)
{
TspValidationException ex = new TspValidationException("certificate name does not match certID for signature. ");
throw new NullReferenceException();
}
GeneralName generalName = array3[num];
if (generalName.tag != 4 || !X509Name.GetInstance(generalName.obj).Equivalent(issuerX509Principal))
{
num++;
}
IL_12E:
TspUtil.ValidateCertificate(cert);
DateTime genTime = this.tstInfo.genTime;
if (!this.tsaSignerInfo.Verify(cert))
{
TspValidationException ex2 = new TspValidationException("signature not created by certificate.");
throw new NullReferenceException();
}
if (!cert.hashValueSet)
{
return;
}
throw new NullReferenceException();
IL_1C6:
TspValidationException ex3 = new TspValidationException("certificate serial number does not match certID for signature.");
throw new NullReferenceException();
IL_21A:
TspValidationException ex4 = new TspValidationException("certificate hash does not match certID hash.");
throw new NullReferenceException();
}
// Token: 0x06009E9E RID: 40606 RVA: 0x0020A468 File Offset: 0x00208668
[Token(Token = "0x6009E9E")]
[Address(RVA = "0x411530", Offset = "0x410530", VA = "0x180411530")]
public CmsSignedData ToCmsSignedData()
{
return this.tsToken;
}
// Token: 0x06009E9F RID: 40607 RVA: 0x0020A47C File Offset: 0x0020867C
[Token(Token = "0x6009E9F")]
[Address(RVA = "0x5F1FB0", Offset = "0x5F0FB0", VA = "0x1805F1FB0")]
public byte[] GetEncoded()
{
return this.tsToken.GetEncoded();
}
// Token: 0x04006A77 RID: 27255
[FieldOffset(Offset = "0x10")]
[Token(Token = "0x4006A77")]
private readonly CmsSignedData tsToken;
// Token: 0x04006A78 RID: 27256
[FieldOffset(Offset = "0x18")]
[Token(Token = "0x4006A78")]
private readonly SignerInformation tsaSignerInfo;
// Token: 0x04006A79 RID: 27257
[FieldOffset(Offset = "0x20")]
[Token(Token = "0x4006A79")]
private readonly TimeStampTokenInfo tstInfo;
// Token: 0x04006A7A RID: 27258
[FieldOffset(Offset = "0x28")]
[Token(Token = "0x4006A7A")]
private readonly TimeStampToken.CertID certID;
// Token: 0x02001A4F RID: 6735
[Token(Token = "0x2001A4F")]
private class CertID
{
// Token: 0x06009EA0 RID: 40608 RVA: 0x0020A49C File Offset: 0x0020869C
[Token(Token = "0x6009EA0")]
[Address(RVA = "0x5DAC50", Offset = "0x5D9C50", VA = "0x1805DAC50")]
internal CertID(EssCertID certID)
{
this.certID = certID;
this.certIDv2 = (ulong)0L;
}
// Token: 0x06009EA1 RID: 40609 RVA: 0x0020A4C0 File Offset: 0x002086C0
[Token(Token = "0x6009EA1")]
[Address(RVA = "0x5DAC80", Offset = "0x5D9C80", VA = "0x1805DAC80")]
internal CertID(EssCertIDv2 certID)
{
this.certIDv2 = certID;
this.certID = (ulong)0L;
}
// Token: 0x06009EA2 RID: 40610 RVA: 0x0020A4E4 File Offset: 0x002086E4
[Token(Token = "0x6009EA2")]
[Address(RVA = "0x5DAA90", Offset = "0x5D9A90", VA = "0x1805DAA90")]
public string GetHashAlgorithmName()
{
if (this.certID == (ulong)0L)
{
EssCertIDv2 essCertIDv = this.certIDv2;
DerObjectIdentifier idSha = NistObjectIdentifiers.IdSha256;
if (essCertIDv.hashAlgorithm.ToAsn1Object() == 0)
{
Asn1Object asn1Object = this.certIDv2.hashAlgorithm.ToAsn1Object();
}
return "SHA-256";
}
return "SHA-1";
}
// Token: 0x06009EA3 RID: 40611 RVA: 0x0020A53C File Offset: 0x0020873C
[Token(Token = "0x6009EA3")]
[Address(RVA = "0x5DABA0", Offset = "0x5D9BA0", VA = "0x1805DABA0")]
public AlgorithmIdentifier GetHashAlgorithm()
{
if (this.certID != (ulong)0L)
{
return new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1);
}
return this.certIDv2.hashAlgorithm;
}
// Token: 0x06009EA4 RID: 40612 RVA: 0x0020A570 File Offset: 0x00208770
[Token(Token = "0x6009EA4")]
[Address(RVA = "0x5DAA50", Offset = "0x5D9A50", VA = "0x1805DAA50")]
public byte[] GetCertHash()
{
EssCertID essCertID = this.certID;
if (essCertID != 0)
{
return essCertID.GetCertHash();
}
return this.certIDv2.GetCertHash();
}
// Token: 0x17001963 RID: 6499
// (get) Token: 0x06009EA5 RID: 40613 RVA: 0x0020A5A0 File Offset: 0x002087A0
[Token(Token = "0x17001963")]
public IssuerSerial IssuerSerial
{
[Token(Token = "0x6009EA5")]
[Address(RVA = "0x5DACB0", Offset = "0x5D9CB0", VA = "0x1805DACB0")]
get
{
EssCertID essCertID = this.certID;
if (essCertID != 0)
{
return essCertID.issuerSerial;
}
return this.certIDv2.issuerSerial;
}
}
// Token: 0x04006A7B RID: 27259
[FieldOffset(Offset = "0x10")]
[Token(Token = "0x4006A7B")]
private EssCertID certID;
// Token: 0x04006A7C RID: 27260
[FieldOffset(Offset = "0x18")]
[Token(Token = "0x4006A7C")]
private EssCertIDv2 certIDv2;
}
}
}