257 lines
14 KiB
C#
257 lines
14 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.Cms.Ecc;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
|
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 Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
|
|
{
|
|
// Token: 0x02001D5A RID: 7514
|
|
[Token(Token = "0x2001D5A")]
|
|
public class KeyAgreeRecipientInformation : RecipientInformation
|
|
{
|
|
// Token: 0x0600BE56 RID: 48726 RVA: 0x002B5B84 File Offset: 0x002B3D84
|
|
[Token(Token = "0x600BE56")]
|
|
[Address(RVA = "0x2010CC0", Offset = "0x200FAC0", VA = "0x182010CC0")]
|
|
internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info, CmsSecureReadable secureReadable)
|
|
{
|
|
int num = 0;
|
|
IEnumerator enumerator = info.recipientEncryptedKeys.GetEnumerator();
|
|
if (enumerator != 0)
|
|
{
|
|
if (num < enumerator)
|
|
{
|
|
num += num;
|
|
num++;
|
|
}
|
|
ulong num2;
|
|
enumerator += num2;
|
|
if (enumerator == 0 || enumerator == 0)
|
|
{
|
|
throw new NullReferenceException();
|
|
}
|
|
RecipientID recipientID = new RecipientID();
|
|
RecipientEncryptedKey recipientEncryptedKey;
|
|
KeyAgreeRecipientIdentifier identifier = recipientEncryptedKey.identifier;
|
|
if (identifier.issuerSerial == 0)
|
|
{
|
|
Stream octetStream = identifier.rKeyID.subjectKeyIdentifier.GetOctetStream();
|
|
}
|
|
byte[] authorityKeyIdentifier = recipientID.authorityKeyIdentifier;
|
|
recipientID.issuer = authorityKeyIdentifier;
|
|
int basicConstraints = recipientID.basicConstraints;
|
|
BigInteger bigInteger;
|
|
recipientID.serialNumber = bigInteger;
|
|
}
|
|
KeyAgreeRecipientInformation keyAgreeRecipientInformation;
|
|
if (keyAgreeRecipientInformation != 0)
|
|
{
|
|
}
|
|
if (num == 0)
|
|
{
|
|
return;
|
|
}
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600BE57 RID: 48727 RVA: 0x002B5C68 File Offset: 0x002B3E68
|
|
[Token(Token = "0x600BE57")]
|
|
[Address(RVA = "0x20111A0", Offset = "0x200FFA0", VA = "0x1820111A0")]
|
|
internal KeyAgreeRecipientInformation(KeyAgreeRecipientInfo info, RecipientID rid, Asn1OctetString encryptedKey, CmsSecureReadable secureReadable)
|
|
{
|
|
this.rid = rid;
|
|
this.encryptedKey = encryptedKey;
|
|
this.info = info;
|
|
}
|
|
|
|
// Token: 0x0600BE58 RID: 48728 RVA: 0x002B5C90 File Offset: 0x002B3E90
|
|
[Token(Token = "0x600BE58")]
|
|
[Address(RVA = "0x2010760", Offset = "0x200F560", VA = "0x182010760")]
|
|
private AsymmetricKeyParameter GetSenderPublicKey(AsymmetricKeyParameter receiverPrivateKey, OriginatorIdentifierOrKey originator)
|
|
{
|
|
OriginatorPublicKey originatorPublicKey = originator.OriginatorPublicKey;
|
|
if (originatorPublicKey != 0)
|
|
{
|
|
return this.GetPublicKeyFromOriginatorPublicKey(receiverPrivateKey, originatorPublicKey);
|
|
}
|
|
OriginatorID originatorID = new OriginatorID();
|
|
IssuerAndSerialNumber issuerAndSerialNumber = originator.IssuerAndSerialNumber;
|
|
if (issuerAndSerialNumber == 0)
|
|
{
|
|
throw new NullReferenceException();
|
|
}
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600BE59 RID: 48729 RVA: 0x002B5D40 File Offset: 0x002B3F40
|
|
[Token(Token = "0x600BE59")]
|
|
[Address(RVA = "0x20106A0", Offset = "0x200F4A0", VA = "0x1820106A0")]
|
|
private AsymmetricKeyParameter GetPublicKeyFromOriginatorPublicKey(AsymmetricKeyParameter receiverPrivateKey, OriginatorPublicKey originatorPublicKey)
|
|
{
|
|
bool hasPublicKey = PrivateKeyInfoFactory.CreatePrivateKeyInfo(receiverPrivateKey).HasPublicKey;
|
|
byte[] octets = originatorPublicKey.mPublicKey.GetOctets();
|
|
SubjectPublicKeyInfo subjectPublicKeyInfo;
|
|
return PublicKeyFactory.CreateKey(subjectPublicKeyInfo);
|
|
}
|
|
|
|
// Token: 0x0600BE5A RID: 48730 RVA: 0x002B5D74 File Offset: 0x002B3F74
|
|
[Token(Token = "0x600BE5A")]
|
|
[Address(RVA = "0x2010640", Offset = "0x200F440", VA = "0x182010640")]
|
|
private AsymmetricKeyParameter GetPublicKeyFromOriginatorID(OriginatorID origID)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600BE5A)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.AsymmetricKeyParameter BestHTTP.SecureProtocol.Org.BouncyCastle.Cms.KeyAgreeRecipientInformation::GetPublicKeyFromOriginatorID(BestHTTP.SecureProtocol.Org.BouncyCastle.Cms.OriginatorID)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
Block_0:
|
|
stloc:CmsException(var_0_0A, newobj:CmsException(CmsException::.ctor, ldstr:string("No support for 'originator' as IssuerAndSerialNumber or SubjectKeyIdentifier")))
|
|
}
|
|
|
|
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 1660
|
|
*/;
|
|
}
|
|
|
|
// Token: 0x0600BE5B RID: 48731 RVA: 0x002B5D8C File Offset: 0x002B3F8C
|
|
[Token(Token = "0x600BE5B")]
|
|
[Address(RVA = "0x2010160", Offset = "0x200EF60", VA = "0x182010160")]
|
|
private KeyParameter CalculateAgreedWrapKey(string wrapAlg, AsymmetricKeyParameter senderPublicKey, AsymmetricKeyParameter receiverPrivateKey)
|
|
{
|
|
for (;;)
|
|
{
|
|
Asn1Object asn1Object = this.keyEncAlg.ToAsn1Object();
|
|
string ecmqvSha1Kdf = CmsEnvelopedGenerator.ECMqvSha1Kdf;
|
|
bool flag;
|
|
if (!flag)
|
|
{
|
|
break;
|
|
}
|
|
Stream octetStream = this.info.ukm.GetOctetStream();
|
|
Asn1Object asn1Object2;
|
|
OriginatorPublicKey ephemeralPublicKey = MQVuserKeyingMaterial.GetInstance(asn1Object2).ephemeralPublicKey;
|
|
AsymmetricKeyParameter publicKeyFromOriginatorPublicKey = this.GetPublicKeyFromOriginatorPublicKey(receiverPrivateKey, ephemeralPublicKey);
|
|
if (publicKeyFromOriginatorPublicKey == 0)
|
|
{
|
|
}
|
|
if (publicKeyFromOriginatorPublicKey != 0)
|
|
{
|
|
if (senderPublicKey == 0)
|
|
{
|
|
}
|
|
if (senderPublicKey != 0)
|
|
{
|
|
if (receiverPrivateKey == 0)
|
|
{
|
|
}
|
|
if (receiverPrivateKey != 0 && receiverPrivateKey != 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int num = 0;
|
|
int defaultKeySize = GeneratorUtilities.GetDefaultKeySize(wrapAlg);
|
|
num += defaultKeySize;
|
|
byte[] array;
|
|
return ParameterUtilities.CreateKeyParameter(wrapAlg, array);
|
|
}
|
|
|
|
// Token: 0x0600BE5C RID: 48732 RVA: 0x002B5E24 File Offset: 0x002B4024
|
|
[Token(Token = "0x600BE5C")]
|
|
[Address(RVA = "0x2011070", Offset = "0x200FE70", VA = "0x182011070")]
|
|
private KeyParameter UnwrapSessionKey(string wrapAlg, KeyParameter agreedKey)
|
|
{
|
|
Stream octetStream = this.encryptedKey.GetOctetStream();
|
|
IWrapper wrapper = WrapperUtilities.GetWrapper(wrapAlg);
|
|
Stream.ReadWriteTask activeReadWriteTask = octetStream._activeReadWriteTask;
|
|
string contentAlgorithmName = base.GetContentAlgorithmName();
|
|
KeyParameter keyParameter;
|
|
return keyParameter;
|
|
}
|
|
|
|
// Token: 0x0600BE5D RID: 48733 RVA: 0x002B5E5C File Offset: 0x002B405C
|
|
[Token(Token = "0x600BE5D")]
|
|
[Address(RVA = "0x20108C0", Offset = "0x200F6C0", VA = "0x1820108C0")]
|
|
internal KeyParameter GetSessionKey(AsymmetricKeyParameter receiverPrivateKey)
|
|
{
|
|
Asn1SequenceParser parser = Asn1Sequence.GetInstance(this.keyEncAlg.ObjectID).Parser;
|
|
DerObjectIdentifier derObjectIdentifier;
|
|
string identifier = derObjectIdentifier.identifier;
|
|
OriginatorIdentifierOrKey originator = this.info.originator;
|
|
OriginatorPublicKey originatorPublicKey = originator.OriginatorPublicKey;
|
|
if (originatorPublicKey != 0)
|
|
{
|
|
AsymmetricKeyParameter publicKeyFromOriginatorPublicKey = this.GetPublicKeyFromOriginatorPublicKey(receiverPrivateKey, originatorPublicKey);
|
|
KeyParameter keyParameter = this.CalculateAgreedWrapKey(identifier, publicKeyFromOriginatorPublicKey, receiverPrivateKey);
|
|
Stream octetStream = this.encryptedKey.GetOctetStream();
|
|
IWrapper wrapper = WrapperUtilities.GetWrapper(identifier);
|
|
Stream.ReadWriteTask activeReadWriteTask = octetStream._activeReadWriteTask;
|
|
string contentAlgorithmName = base.GetContentAlgorithmName();
|
|
KeyParameter keyParameter2;
|
|
return keyParameter2;
|
|
}
|
|
OriginatorID originatorID = new OriginatorID();
|
|
IssuerAndSerialNumber issuerAndSerialNumber = originator.IssuerAndSerialNumber;
|
|
if (issuerAndSerialNumber == 0)
|
|
{
|
|
throw new NullReferenceException();
|
|
}
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600BE5E RID: 48734 RVA: 0x002B5FC8 File Offset: 0x002B41C8
|
|
[Token(Token = "0x600BE5E")]
|
|
[Address(RVA = "0x20104E0", Offset = "0x200F2E0", VA = "0x1820104E0", Slot = "4")]
|
|
public override CmsTypedStream GetContentStream(ICipherParameters key)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600BE5E)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling BestHTTP.SecureProtocol.Org.BouncyCastle.Cms.CmsTypedStream BestHTTP.SecureProtocol.Org.BouncyCastle.Cms.KeyAgreeRecipientInformation::GetContentStream(BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.ICipherParameters)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_18:
|
|
stloc:ArgumentException(var_3_27, newobj:ArgumentException(ArgumentException::.ctor, ldstr:string("KeyAgreement requires asymmetric key"), ldstr:string("key")))
|
|
stloc:ArgumentException(var_4_37, newobj:ArgumentException(ArgumentException::.ctor, ldstr:string("Expected private key"), ldstr:string("key")))
|
|
}
|
|
|
|
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 1660
|
|
*/;
|
|
}
|
|
|
|
// Token: 0x04007921 RID: 31009
|
|
[FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x4007921")]
|
|
private KeyAgreeRecipientInfo info;
|
|
|
|
// Token: 0x04007922 RID: 31010
|
|
[FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x4007922")]
|
|
private Asn1OctetString encryptedKey;
|
|
}
|
|
}
|