391 lines
13 KiB
C#
391 lines
13 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.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: 0x02001391 RID: 5009
|
|
[Token(Token = "0x2001391")]
|
|
[StructLayout(3)]
|
|
public class TimeStampToken
|
|
{
|
|
// Token: 0x06007EEC RID: 32492 RVA: 0x001A9878 File Offset: 0x001A7A78
|
|
[Token(Token = "0x6007EEC")]
|
|
[Address(RVA = "0x1C6C970", Offset = "0x1C6B370", VA = "0x181C6C970")]
|
|
public TimeStampToken(BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.ContentInfo contentInfo)
|
|
{
|
|
CmsSignedData cmsSignedData = new CmsSignedData(contentInfo);
|
|
}
|
|
|
|
// Token: 0x06007EED RID: 32493 RVA: 0x001A988C File Offset: 0x001A7A8C
|
|
[Token(Token = "0x6007EED")]
|
|
[Address(RVA = "0x1C6C9E0", Offset = "0x1C6B3E0", VA = "0x181C6C9E0")]
|
|
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: 0x170014C1 RID: 5313
|
|
// (get) Token: 0x06007EEE RID: 32494 RVA: 0x001A9A74 File Offset: 0x001A7C74
|
|
[Token(Token = "0x170014C1")]
|
|
public TimeStampTokenInfo TimeStampInfo
|
|
{
|
|
[Token(Token = "0x6007EEE")]
|
|
[Address(RVA = "0x3C1220", Offset = "0x3BFC20", VA = "0x1803C1220")]
|
|
get
|
|
{
|
|
return this.tstInfo;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170014C2 RID: 5314
|
|
// (get) Token: 0x06007EEF RID: 32495 RVA: 0x001A9A88 File Offset: 0x001A7C88
|
|
[Token(Token = "0x170014C2")]
|
|
public SignerID SignerID
|
|
{
|
|
[Token(Token = "0x6007EEF")]
|
|
[Address(RVA = "0x540790", Offset = "0x53F190", VA = "0x180540790")]
|
|
get
|
|
{
|
|
return this.tsaSignerInfo.sid;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170014C3 RID: 5315
|
|
// (get) Token: 0x06007EF0 RID: 32496 RVA: 0x001A9AA8 File Offset: 0x001A7CA8
|
|
[Token(Token = "0x170014C3")]
|
|
public BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.AttributeTable SignedAttributes
|
|
{
|
|
[Token(Token = "0x6007EF0")]
|
|
[Address(RVA = "0x1C6D060", Offset = "0x1C6BA60", VA = "0x181C6D060")]
|
|
get
|
|
{
|
|
return this.tsaSignerInfo.SignedAttributes;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170014C4 RID: 5316
|
|
// (get) Token: 0x06007EF1 RID: 32497 RVA: 0x001A9AC8 File Offset: 0x001A7CC8
|
|
[Token(Token = "0x170014C4")]
|
|
public BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.AttributeTable UnsignedAttributes
|
|
{
|
|
[Token(Token = "0x6007EF1")]
|
|
[Address(RVA = "0x1C6D080", Offset = "0x1C6BA80", VA = "0x181C6D080")]
|
|
get
|
|
{
|
|
return this.tsaSignerInfo.UnsignedAttributes;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06007EF2 RID: 32498 RVA: 0x001A9AE8 File Offset: 0x001A7CE8
|
|
[Token(Token = "0x6007EF2")]
|
|
[Address(RVA = "0x1C6C220", Offset = "0x1C6AC20", VA = "0x181C6C220")]
|
|
public IX509Store GetCertificates(string type)
|
|
{
|
|
return this.tsToken.GetCertificates(type);
|
|
}
|
|
|
|
// Token: 0x06007EF3 RID: 32499 RVA: 0x001A9B08 File Offset: 0x001A7D08
|
|
[Token(Token = "0x6007EF3")]
|
|
[Address(RVA = "0x1C6C240", Offset = "0x1C6AC40", VA = "0x181C6C240")]
|
|
public IX509Store GetCrls(string type)
|
|
{
|
|
return this.tsToken.GetCrls(type);
|
|
}
|
|
|
|
// Token: 0x06007EF4 RID: 32500 RVA: 0x001A9B28 File Offset: 0x001A7D28
|
|
[Token(Token = "0x6007EF4")]
|
|
[Address(RVA = "0x1C6C200", Offset = "0x1C6AC00", VA = "0x181C6C200")]
|
|
public IX509Store GetAttributeCertificates(string type)
|
|
{
|
|
return this.tsToken.GetAttributeCertificates(type);
|
|
}
|
|
|
|
// Token: 0x06007EF5 RID: 32501 RVA: 0x001A9B48 File Offset: 0x001A7D48
|
|
[Token(Token = "0x6007EF5")]
|
|
[Address(RVA = "0x1C6C280", Offset = "0x1C6AC80", VA = "0x181C6C280")]
|
|
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: 0x06007EF6 RID: 32502 RVA: 0x001A9DAC File Offset: 0x001A7FAC
|
|
[Token(Token = "0x6007EF6")]
|
|
[Address(RVA = "0x3C39A0", Offset = "0x3C23A0", VA = "0x1803C39A0")]
|
|
public CmsSignedData ToCmsSignedData()
|
|
{
|
|
return this.tsToken;
|
|
}
|
|
|
|
// Token: 0x06007EF7 RID: 32503 RVA: 0x001A9DC0 File Offset: 0x001A7FC0
|
|
[Token(Token = "0x6007EF7")]
|
|
[Address(RVA = "0x1C6C260", Offset = "0x1C6AC60", VA = "0x181C6C260")]
|
|
public byte[] GetEncoded()
|
|
{
|
|
return this.tsToken.GetEncoded();
|
|
}
|
|
|
|
// Token: 0x04005A7B RID: 23163
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x4005A7B")]
|
|
private readonly CmsSignedData tsToken;
|
|
|
|
// Token: 0x04005A7C RID: 23164
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x4005A7C")]
|
|
private readonly SignerInformation tsaSignerInfo;
|
|
|
|
// Token: 0x04005A7D RID: 23165
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x4005A7D")]
|
|
private readonly TimeStampTokenInfo tstInfo;
|
|
|
|
// Token: 0x04005A7E RID: 23166
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x4005A7E")]
|
|
private readonly TimeStampToken.CertID certID;
|
|
|
|
// Token: 0x02001392 RID: 5010
|
|
[Token(Token = "0x2001392")]
|
|
private class CertID
|
|
{
|
|
// Token: 0x06007EF8 RID: 32504 RVA: 0x001A9DE0 File Offset: 0x001A7FE0
|
|
[Token(Token = "0x6007EF8")]
|
|
[Address(RVA = "0xC25EB0", Offset = "0xC248B0", VA = "0x180C25EB0")]
|
|
internal CertID(EssCertID certID)
|
|
{
|
|
this.certID = certID;
|
|
this.certIDv2 = (ulong)0L;
|
|
}
|
|
|
|
// Token: 0x06007EF9 RID: 32505 RVA: 0x001A9E04 File Offset: 0x001A8004
|
|
[Token(Token = "0x6007EF9")]
|
|
[Address(RVA = "0x1C5E760", Offset = "0x1C5D160", VA = "0x181C5E760")]
|
|
internal CertID(EssCertIDv2 certID)
|
|
{
|
|
this.certIDv2 = certID;
|
|
this.certID = (ulong)0L;
|
|
}
|
|
|
|
// Token: 0x06007EFA RID: 32506 RVA: 0x001A9E28 File Offset: 0x001A8028
|
|
[Token(Token = "0x6007EFA")]
|
|
[Address(RVA = "0x1C5E5A0", Offset = "0x1C5CFA0", VA = "0x181C5E5A0")]
|
|
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: 0x06007EFB RID: 32507 RVA: 0x001A9E80 File Offset: 0x001A8080
|
|
[Token(Token = "0x6007EFB")]
|
|
[Address(RVA = "0x1C5E6B0", Offset = "0x1C5D0B0", VA = "0x181C5E6B0")]
|
|
public AlgorithmIdentifier GetHashAlgorithm()
|
|
{
|
|
if (this.certID != (ulong)0L)
|
|
{
|
|
return new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1);
|
|
}
|
|
return this.certIDv2.hashAlgorithm;
|
|
}
|
|
|
|
// Token: 0x06007EFC RID: 32508 RVA: 0x001A9EB4 File Offset: 0x001A80B4
|
|
[Token(Token = "0x6007EFC")]
|
|
[Address(RVA = "0x1C5E560", Offset = "0x1C5CF60", VA = "0x181C5E560")]
|
|
public byte[] GetCertHash()
|
|
{
|
|
EssCertID essCertID = this.certID;
|
|
if (essCertID != 0)
|
|
{
|
|
return essCertID.GetCertHash();
|
|
}
|
|
return this.certIDv2.GetCertHash();
|
|
}
|
|
|
|
// Token: 0x170014C5 RID: 5317
|
|
// (get) Token: 0x06007EFD RID: 32509 RVA: 0x001A9EE4 File Offset: 0x001A80E4
|
|
[Token(Token = "0x170014C5")]
|
|
public IssuerSerial IssuerSerial
|
|
{
|
|
[Token(Token = "0x6007EFD")]
|
|
[Address(RVA = "0x1C5E790", Offset = "0x1C5D190", VA = "0x181C5E790")]
|
|
get
|
|
{
|
|
EssCertID essCertID = this.certID;
|
|
if (essCertID != 0)
|
|
{
|
|
return essCertID.issuerSerial;
|
|
}
|
|
return this.certIDv2.issuerSerial;
|
|
}
|
|
}
|
|
|
|
// Token: 0x04005A7F RID: 23167
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x4005A7F")]
|
|
private EssCertID certID;
|
|
|
|
// Token: 0x04005A80 RID: 23168
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x4005A80")]
|
|
private EssCertIDv2 certIDv2;
|
|
}
|
|
}
|
|
}
|