This commit is contained in:
niko
2026-06-04 11:42:34 +02:00
parent f39ba70a9f
commit e720b98cd1
7488 changed files with 2493818 additions and 0 deletions
@@ -0,0 +1,107 @@
using System;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000A7 RID: 167
internal class TlsClientCertificate : HandshakeMessage
{
// Token: 0x0600065E RID: 1630 RVA: 0x0002373C File Offset: 0x0002193C
public TlsClientCertificate(Context context)
: base(context, HandshakeType.Certificate)
{
}
// Token: 0x170001A3 RID: 419
// (get) Token: 0x0600065F RID: 1631 RVA: 0x00023748 File Offset: 0x00021948
public X509Certificate ClientCertificate
{
get
{
if (!this.clientCertSelected)
{
this.GetClientCertificate();
this.clientCertSelected = true;
}
return this.clientCert;
}
}
// Token: 0x06000660 RID: 1632 RVA: 0x00023768 File Offset: 0x00021968
public override void Update()
{
base.Update();
base.Reset();
}
// Token: 0x06000661 RID: 1633 RVA: 0x00023778 File Offset: 0x00021978
private void GetClientCertificate()
{
ClientContext clientContext = (ClientContext)base.Context;
if (clientContext.ClientSettings.Certificates != null && clientContext.ClientSettings.Certificates.Count > 0)
{
this.clientCert = clientContext.SslStream.RaiseClientCertificateSelection(base.Context.ClientSettings.Certificates, new X509Certificate(base.Context.ServerSettings.Certificates[0].RawData), base.Context.ClientSettings.TargetHost, null);
}
clientContext.ClientSettings.ClientCertificate = this.clientCert;
}
// Token: 0x06000662 RID: 1634 RVA: 0x0002381C File Offset: 0x00021A1C
private void SendCertificates()
{
TlsStream tlsStream = new TlsStream();
for (X509Certificate x509Certificate = this.ClientCertificate; x509Certificate != null; x509Certificate = this.FindParentCertificate(x509Certificate))
{
byte[] rawCertData = x509Certificate.GetRawCertData();
tlsStream.WriteInt24(rawCertData.Length);
tlsStream.Write(rawCertData);
}
base.WriteInt24((int)tlsStream.Length);
base.Write(tlsStream.ToArray());
}
// Token: 0x06000663 RID: 1635 RVA: 0x0002387C File Offset: 0x00021A7C
protected override void ProcessAsSsl3()
{
if (this.ClientCertificate != null)
{
this.SendCertificates();
}
}
// Token: 0x06000664 RID: 1636 RVA: 0x00023894 File Offset: 0x00021A94
protected override void ProcessAsTls1()
{
if (this.ClientCertificate != null)
{
this.SendCertificates();
}
else
{
base.WriteInt24(0);
}
}
// Token: 0x06000665 RID: 1637 RVA: 0x000238B4 File Offset: 0x00021AB4
private X509Certificate FindParentCertificate(X509Certificate cert)
{
if (cert.GetName() == cert.GetIssuerName())
{
return null;
}
foreach (X509Certificate x509Certificate in base.Context.ClientSettings.Certificates)
{
if (cert.GetName() == cert.GetIssuerName())
{
return x509Certificate;
}
}
return null;
}
// Token: 0x0400031B RID: 795
private bool clientCertSelected;
// Token: 0x0400031C RID: 796
private X509Certificate clientCert;
}
}
@@ -0,0 +1,130 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000A8 RID: 168
internal class TlsClientCertificateVerify : HandshakeMessage
{
// Token: 0x06000666 RID: 1638 RVA: 0x0002395C File Offset: 0x00021B5C
public TlsClientCertificateVerify(Context context)
: base(context, HandshakeType.CertificateVerify)
{
}
// Token: 0x06000667 RID: 1639 RVA: 0x00023968 File Offset: 0x00021B68
public override void Update()
{
base.Update();
base.Reset();
}
// Token: 0x06000668 RID: 1640 RVA: 0x00023978 File Offset: 0x00021B78
protected override void ProcessAsSsl3()
{
AsymmetricAlgorithm asymmetricAlgorithm = null;
ClientContext clientContext = (ClientContext)base.Context;
asymmetricAlgorithm = clientContext.SslStream.RaisePrivateKeySelection(clientContext.ClientSettings.ClientCertificate, clientContext.ClientSettings.TargetHost);
if (asymmetricAlgorithm == null)
{
throw new TlsException(AlertDescription.UserCancelled, "Client certificate Private Key unavailable.");
}
SslHandshakeHash sslHandshakeHash = new SslHandshakeHash(clientContext.MasterSecret);
sslHandshakeHash.TransformFinalBlock(clientContext.HandshakeMessages.ToArray(), 0, (int)clientContext.HandshakeMessages.Length);
byte[] array = null;
if (!(asymmetricAlgorithm is RSACryptoServiceProvider))
{
try
{
array = sslHandshakeHash.CreateSignature((RSA)asymmetricAlgorithm);
}
catch (NotImplementedException)
{
}
}
if (array == null)
{
RSA clientCertRSA = this.getClientCertRSA((RSA)asymmetricAlgorithm);
array = sslHandshakeHash.CreateSignature(clientCertRSA);
}
base.Write((short)array.Length);
this.Write(array, 0, array.Length);
}
// Token: 0x06000669 RID: 1641 RVA: 0x00023A68 File Offset: 0x00021C68
protected override void ProcessAsTls1()
{
AsymmetricAlgorithm asymmetricAlgorithm = null;
ClientContext clientContext = (ClientContext)base.Context;
asymmetricAlgorithm = clientContext.SslStream.RaisePrivateKeySelection(clientContext.ClientSettings.ClientCertificate, clientContext.ClientSettings.TargetHost);
if (asymmetricAlgorithm == null)
{
throw new TlsException(AlertDescription.UserCancelled, "Client certificate Private Key unavailable.");
}
MD5SHA1 md5SHA = new MD5SHA1();
md5SHA.ComputeHash(clientContext.HandshakeMessages.ToArray(), 0, (int)clientContext.HandshakeMessages.Length);
byte[] array = null;
if (!(asymmetricAlgorithm is RSACryptoServiceProvider))
{
try
{
array = md5SHA.CreateSignature((RSA)asymmetricAlgorithm);
}
catch (NotImplementedException)
{
}
}
if (array == null)
{
RSA clientCertRSA = this.getClientCertRSA((RSA)asymmetricAlgorithm);
array = md5SHA.CreateSignature(clientCertRSA);
}
base.Write((short)array.Length);
this.Write(array, 0, array.Length);
}
// Token: 0x0600066A RID: 1642 RVA: 0x00023B50 File Offset: 0x00021D50
private RSA getClientCertRSA(RSA privKey)
{
RSAParameters rsaparameters = default(RSAParameters);
RSAParameters rsaparameters2 = privKey.ExportParameters(true);
ASN1 asn = new ASN1(base.Context.ClientSettings.Certificates[0].GetPublicKey());
ASN1 asn2 = asn[0];
if (asn2 == null || asn2.Tag != 2)
{
return null;
}
ASN1 asn3 = asn[1];
if (asn3.Tag != 2)
{
return null;
}
rsaparameters.Modulus = this.getUnsignedBigInteger(asn2.Value);
rsaparameters.Exponent = asn3.Value;
rsaparameters.D = rsaparameters2.D;
rsaparameters.DP = rsaparameters2.DP;
rsaparameters.DQ = rsaparameters2.DQ;
rsaparameters.InverseQ = rsaparameters2.InverseQ;
rsaparameters.P = rsaparameters2.P;
rsaparameters.Q = rsaparameters2.Q;
int num = rsaparameters.Modulus.Length << 3;
RSAManaged rsamanaged = new RSAManaged(num);
rsamanaged.ImportParameters(rsaparameters);
return rsamanaged;
}
// Token: 0x0600066B RID: 1643 RVA: 0x00023C58 File Offset: 0x00021E58
private byte[] getUnsignedBigInteger(byte[] integer)
{
if (integer[0] == 0)
{
int num = integer.Length - 1;
byte[] array = new byte[num];
Buffer.BlockCopy(integer, 1, array, 0, num);
return array;
}
return integer;
}
}
}
@@ -0,0 +1,46 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000A9 RID: 169
internal class TlsClientFinished : HandshakeMessage
{
// Token: 0x0600066C RID: 1644 RVA: 0x00023C88 File Offset: 0x00021E88
public TlsClientFinished(Context context)
: base(context, HandshakeType.Finished)
{
}
// Token: 0x0600066E RID: 1646 RVA: 0x00023CAC File Offset: 0x00021EAC
public override void Update()
{
base.Update();
base.Reset();
}
// Token: 0x0600066F RID: 1647 RVA: 0x00023CBC File Offset: 0x00021EBC
protected override void ProcessAsSsl3()
{
HashAlgorithm hashAlgorithm = new SslHandshakeHash(base.Context.MasterSecret);
byte[] array = base.Context.HandshakeMessages.ToArray();
hashAlgorithm.TransformBlock(array, 0, array.Length, array, 0);
hashAlgorithm.TransformBlock(TlsClientFinished.Ssl3Marker, 0, TlsClientFinished.Ssl3Marker.Length, TlsClientFinished.Ssl3Marker, 0);
hashAlgorithm.TransformFinalBlock(CipherSuite.EmptyArray, 0, 0);
base.Write(hashAlgorithm.Hash);
}
// Token: 0x06000670 RID: 1648 RVA: 0x00023D30 File Offset: 0x00021F30
protected override void ProcessAsTls1()
{
HashAlgorithm hashAlgorithm = new MD5SHA1();
byte[] array = base.Context.HandshakeMessages.ToArray();
byte[] array2 = hashAlgorithm.ComputeHash(array, 0, array.Length);
base.Write(base.Context.Write.Cipher.PRF(base.Context.MasterSecret, "client finished", array2, 12));
}
// Token: 0x0400031D RID: 797
private static byte[] Ssl3Marker = new byte[] { 67, 76, 78, 84 };
}
}
@@ -0,0 +1,65 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000AA RID: 170
internal class TlsClientHello : HandshakeMessage
{
// Token: 0x06000671 RID: 1649 RVA: 0x00023D90 File Offset: 0x00021F90
public TlsClientHello(Context context)
: base(context, HandshakeType.ClientHello)
{
}
// Token: 0x06000672 RID: 1650 RVA: 0x00023D9C File Offset: 0x00021F9C
public override void Update()
{
ClientContext clientContext = (ClientContext)base.Context;
base.Update();
clientContext.ClientRandom = this.random;
clientContext.ClientHelloProtocol = base.Context.Protocol;
this.random = null;
}
// Token: 0x06000673 RID: 1651 RVA: 0x00023DE0 File Offset: 0x00021FE0
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x06000674 RID: 1652 RVA: 0x00023DE8 File Offset: 0x00021FE8
protected override void ProcessAsTls1()
{
base.Write(base.Context.Protocol);
TlsStream tlsStream = new TlsStream();
tlsStream.Write(base.Context.GetUnixTime());
tlsStream.Write(base.Context.GetSecureRandomBytes(28));
this.random = tlsStream.ToArray();
tlsStream.Reset();
base.Write(this.random);
base.Context.SessionId = ClientSessionCache.FromHost(base.Context.ClientSettings.TargetHost);
if (base.Context.SessionId != null)
{
base.Write((byte)base.Context.SessionId.Length);
if (base.Context.SessionId.Length > 0)
{
base.Write(base.Context.SessionId);
}
}
else
{
base.Write(0);
}
base.Write((short)(base.Context.SupportedCiphers.Count * 2));
for (int i = 0; i < base.Context.SupportedCiphers.Count; i++)
{
base.Write(base.Context.SupportedCiphers[i].Code);
}
base.Write(1);
base.Write((byte)base.Context.CompressionMethod);
}
// Token: 0x0400031E RID: 798
private byte[] random;
}
}
@@ -0,0 +1,54 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000AB RID: 171
internal class TlsClientKeyExchange : HandshakeMessage
{
// Token: 0x06000675 RID: 1653 RVA: 0x00023F34 File Offset: 0x00022134
public TlsClientKeyExchange(Context context)
: base(context, HandshakeType.ClientKeyExchange)
{
}
// Token: 0x06000676 RID: 1654 RVA: 0x00023F40 File Offset: 0x00022140
protected override void ProcessAsSsl3()
{
this.ProcessCommon(false);
}
// Token: 0x06000677 RID: 1655 RVA: 0x00023F4C File Offset: 0x0002214C
protected override void ProcessAsTls1()
{
this.ProcessCommon(true);
}
// Token: 0x06000678 RID: 1656 RVA: 0x00023F58 File Offset: 0x00022158
public void ProcessCommon(bool sendLength)
{
byte[] array = base.Context.Negotiating.Cipher.CreatePremasterSecret();
RSA rsa;
if (base.Context.ServerSettings.ServerKeyExchange)
{
rsa = new RSAManaged();
rsa.ImportParameters(base.Context.ServerSettings.RsaParameters);
}
else
{
rsa = base.Context.ServerSettings.CertificateRSA;
}
RSAPKCS1KeyExchangeFormatter rsapkcs1KeyExchangeFormatter = new RSAPKCS1KeyExchangeFormatter(rsa);
byte[] array2 = rsapkcs1KeyExchangeFormatter.CreateKeyExchange(array);
if (sendLength)
{
base.Write((short)array2.Length);
}
base.Write(array2);
base.Context.Negotiating.Cipher.ComputeMasterSecret(array);
base.Context.Negotiating.Cipher.ComputeKeys();
rsa.Clear();
}
}
}
@@ -0,0 +1,320 @@
using System;
using System.Collections;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Mono.Security.X509;
using Mono.Security.X509.Extensions;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000AC RID: 172
internal class TlsServerCertificate : HandshakeMessage
{
// Token: 0x06000679 RID: 1657 RVA: 0x0002401C File Offset: 0x0002221C
public TlsServerCertificate(Context context, byte[] buffer)
: base(context, HandshakeType.Certificate, buffer)
{
}
// Token: 0x0600067A RID: 1658 RVA: 0x00024028 File Offset: 0x00022228
public override void Update()
{
base.Update();
base.Context.ServerSettings.Certificates = this.certificates;
base.Context.ServerSettings.UpdateCertificateRSA();
}
// Token: 0x0600067B RID: 1659 RVA: 0x00024064 File Offset: 0x00022264
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x0600067C RID: 1660 RVA: 0x0002406C File Offset: 0x0002226C
protected override void ProcessAsTls1()
{
this.certificates = new Mono.Security.X509.X509CertificateCollection();
int i = 0;
int num = base.ReadInt24();
while (i < num)
{
int num2 = base.ReadInt24();
i += 3;
if (num2 > 0)
{
byte[] array = base.ReadBytes(num2);
Mono.Security.X509.X509Certificate x509Certificate = new Mono.Security.X509.X509Certificate(array);
this.certificates.Add(x509Certificate);
i += num2;
}
}
this.validateCertificates(this.certificates);
}
// Token: 0x0600067D RID: 1661 RVA: 0x000240DC File Offset: 0x000222DC
private bool checkCertificateUsage(Mono.Security.X509.X509Certificate cert)
{
ClientContext clientContext = (ClientContext)base.Context;
if (cert.Version < 3)
{
return true;
}
KeyUsages keyUsages = KeyUsages.none;
switch (clientContext.Negotiating.Cipher.ExchangeAlgorithmType)
{
case ExchangeAlgorithmType.DiffieHellman:
keyUsages = KeyUsages.keyAgreement;
break;
case ExchangeAlgorithmType.Fortezza:
return false;
case ExchangeAlgorithmType.RsaKeyX:
keyUsages = KeyUsages.keyEncipherment;
break;
case ExchangeAlgorithmType.RsaSign:
keyUsages = KeyUsages.digitalSignature;
break;
}
KeyUsageExtension keyUsageExtension = null;
ExtendedKeyUsageExtension extendedKeyUsageExtension = null;
Mono.Security.X509.X509Extension x509Extension = cert.Extensions["2.5.29.15"];
if (x509Extension != null)
{
keyUsageExtension = new KeyUsageExtension(x509Extension);
}
x509Extension = cert.Extensions["2.5.29.37"];
if (x509Extension != null)
{
extendedKeyUsageExtension = new ExtendedKeyUsageExtension(x509Extension);
}
if (keyUsageExtension != null && extendedKeyUsageExtension != null)
{
return keyUsageExtension.Support(keyUsages) && (extendedKeyUsageExtension.KeyPurpose.Contains("1.3.6.1.5.5.7.3.1") || extendedKeyUsageExtension.KeyPurpose.Contains("2.16.840.1.113730.4.1"));
}
if (keyUsageExtension != null)
{
return keyUsageExtension.Support(keyUsages);
}
if (extendedKeyUsageExtension != null)
{
return extendedKeyUsageExtension.KeyPurpose.Contains("1.3.6.1.5.5.7.3.1") || extendedKeyUsageExtension.KeyPurpose.Contains("2.16.840.1.113730.4.1");
}
x509Extension = cert.Extensions["2.16.840.1.113730.1.1"];
if (x509Extension != null)
{
NetscapeCertTypeExtension netscapeCertTypeExtension = new NetscapeCertTypeExtension(x509Extension);
return netscapeCertTypeExtension.Support(NetscapeCertTypeExtension.CertTypes.SslServer);
}
return true;
}
// Token: 0x0600067E RID: 1662 RVA: 0x00024248 File Offset: 0x00022448
private static void VerifyOSX(Mono.Security.X509.X509CertificateCollection certificates)
{
}
// Token: 0x0600067F RID: 1663 RVA: 0x0002424C File Offset: 0x0002244C
private void validateCertificates(Mono.Security.X509.X509CertificateCollection certificates)
{
ClientContext clientContext = (ClientContext)base.Context;
AlertDescription alertDescription = AlertDescription.BadCertificate;
if (clientContext.SslStream.HaveRemoteValidation2Callback)
{
ValidationResult validationResult = clientContext.SslStream.RaiseServerCertificateValidation2(certificates);
if (validationResult.Trusted)
{
return;
}
long num = (long)validationResult.ErrorCode;
long num2 = num;
if (num2 != (long)((ulong)(-2146762487)))
{
if (num2 != (long)((ulong)(-2146762486)))
{
if (num2 != (long)((ulong)(-2146762495)))
{
alertDescription = AlertDescription.CertificateUnknown;
}
else
{
alertDescription = AlertDescription.CertificateExpired;
}
}
else
{
alertDescription = AlertDescription.UnknownCA;
}
}
else
{
alertDescription = AlertDescription.UnknownCA;
}
string text = string.Format("0x{0:x}", num);
throw new TlsException(alertDescription, "Invalid certificate received from server. Error code: " + text);
}
else
{
Mono.Security.X509.X509Certificate x509Certificate = certificates[0];
global::System.Security.Cryptography.X509Certificates.X509Certificate x509Certificate2 = new global::System.Security.Cryptography.X509Certificates.X509Certificate(x509Certificate.RawData);
ArrayList arrayList = new ArrayList();
if (!this.checkCertificateUsage(x509Certificate))
{
arrayList.Add(-2146762490);
}
if (!this.checkServerIdentity(x509Certificate))
{
arrayList.Add(-2146762481);
}
Mono.Security.X509.X509CertificateCollection x509CertificateCollection = new Mono.Security.X509.X509CertificateCollection(certificates);
x509CertificateCollection.Remove(x509Certificate);
Mono.Security.X509.X509Chain x509Chain = new Mono.Security.X509.X509Chain(x509CertificateCollection);
bool flag = false;
try
{
flag = x509Chain.Build(x509Certificate);
}
catch (Exception)
{
flag = false;
}
if (!flag)
{
Mono.Security.X509.X509ChainStatusFlags status = x509Chain.Status;
if (status != Mono.Security.X509.X509ChainStatusFlags.NotTimeValid)
{
if (status != Mono.Security.X509.X509ChainStatusFlags.NotTimeNested)
{
if (status != Mono.Security.X509.X509ChainStatusFlags.NotSignatureValid)
{
if (status != Mono.Security.X509.X509ChainStatusFlags.UntrustedRoot)
{
if (status != Mono.Security.X509.X509ChainStatusFlags.InvalidBasicConstraints)
{
if (status != Mono.Security.X509.X509ChainStatusFlags.PartialChain)
{
alertDescription = AlertDescription.CertificateUnknown;
arrayList.Add((int)x509Chain.Status);
}
else
{
alertDescription = AlertDescription.UnknownCA;
arrayList.Add(-2146762486);
}
}
else
{
arrayList.Add(-2146869223);
}
}
else
{
alertDescription = AlertDescription.UnknownCA;
arrayList.Add(-2146762487);
}
}
else
{
arrayList.Add(-2146869232);
}
}
else
{
arrayList.Add(-2146762494);
}
}
else
{
alertDescription = AlertDescription.CertificateExpired;
arrayList.Add(-2146762495);
}
}
int[] array = (int[])arrayList.ToArray(typeof(int));
if (!clientContext.SslStream.RaiseServerCertificateValidation(x509Certificate2, array))
{
throw new TlsException(alertDescription, "Invalid certificate received from server.");
}
return;
}
}
// Token: 0x06000680 RID: 1664 RVA: 0x000244F0 File Offset: 0x000226F0
private bool checkServerIdentity(Mono.Security.X509.X509Certificate cert)
{
ClientContext clientContext = (ClientContext)base.Context;
string targetHost = clientContext.ClientSettings.TargetHost;
Mono.Security.X509.X509Extension x509Extension = cert.Extensions["2.5.29.17"];
if (x509Extension != null)
{
SubjectAltNameExtension subjectAltNameExtension = new SubjectAltNameExtension(x509Extension);
foreach (string text in subjectAltNameExtension.DNSNames)
{
if (TlsServerCertificate.Match(targetHost, text))
{
return true;
}
}
foreach (string text2 in subjectAltNameExtension.IPAddresses)
{
if (text2 == targetHost)
{
return true;
}
}
}
return this.checkDomainName(cert.SubjectName);
}
// Token: 0x06000681 RID: 1665 RVA: 0x000245B0 File Offset: 0x000227B0
private bool checkDomainName(string subjectName)
{
ClientContext clientContext = (ClientContext)base.Context;
string text = string.Empty;
Regex regex = new Regex("CN\\s*=\\s*([^,]*)");
MatchCollection matchCollection = regex.Matches(subjectName);
if (matchCollection.Count == 1 && matchCollection[0].Success)
{
text = matchCollection[0].Groups[1].Value.ToString();
}
return TlsServerCertificate.Match(clientContext.ClientSettings.TargetHost, text);
}
// Token: 0x06000682 RID: 1666 RVA: 0x00024630 File Offset: 0x00022830
private static bool Match(string hostname, string pattern)
{
int num = pattern.IndexOf('*');
if (num == -1)
{
return string.Compare(hostname, pattern, true, CultureInfo.InvariantCulture) == 0;
}
if (num != pattern.Length - 1 && pattern[num + 1] != '.')
{
return false;
}
int num2 = pattern.IndexOf('*', num + 1);
if (num2 != -1)
{
return false;
}
string text = pattern.Substring(num + 1);
int num3 = hostname.Length - text.Length;
if (num3 <= 0)
{
return false;
}
if (string.Compare(hostname, num3, text, 0, text.Length, true, CultureInfo.InvariantCulture) != 0)
{
return false;
}
if (num == 0)
{
int num4 = hostname.IndexOf('.');
return num4 == -1 || num4 >= hostname.Length - text.Length;
}
string text2 = pattern.Substring(0, num);
return string.Compare(hostname, 0, text2, 0, text2.Length, true, CultureInfo.InvariantCulture) == 0;
}
// Token: 0x0400031F RID: 799
private Mono.Security.X509.X509CertificateCollection certificates;
}
}
@@ -0,0 +1,57 @@
using System;
using System.Text;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000AD RID: 173
internal class TlsServerCertificateRequest : HandshakeMessage
{
// Token: 0x06000683 RID: 1667 RVA: 0x00024724 File Offset: 0x00022924
public TlsServerCertificateRequest(Context context, byte[] buffer)
: base(context, HandshakeType.CertificateRequest, buffer)
{
}
// Token: 0x06000684 RID: 1668 RVA: 0x00024730 File Offset: 0x00022930
public override void Update()
{
base.Update();
base.Context.ServerSettings.CertificateTypes = this.certificateTypes;
base.Context.ServerSettings.DistinguisedNames = this.distinguisedNames;
base.Context.ServerSettings.CertificateRequest = true;
}
// Token: 0x06000685 RID: 1669 RVA: 0x00024780 File Offset: 0x00022980
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x06000686 RID: 1670 RVA: 0x00024788 File Offset: 0x00022988
protected override void ProcessAsTls1()
{
int num = (int)base.ReadByte();
this.certificateTypes = new ClientCertificateType[num];
for (int i = 0; i < num; i++)
{
this.certificateTypes[i] = (ClientCertificateType)base.ReadByte();
}
if (base.ReadInt16() != 0)
{
ASN1 asn = new ASN1(base.ReadBytes((int)base.ReadInt16()));
this.distinguisedNames = new string[asn.Count];
for (int j = 0; j < asn.Count; j++)
{
ASN1 asn2 = new ASN1(asn[j].Value);
this.distinguisedNames[j] = Encoding.UTF8.GetString(asn2[1].Value);
}
}
}
// Token: 0x04000320 RID: 800
private ClientCertificateType[] certificateTypes;
// Token: 0x04000321 RID: 801
private string[] distinguisedNames;
}
}
@@ -0,0 +1,56 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000AE RID: 174
internal class TlsServerFinished : HandshakeMessage
{
// Token: 0x06000687 RID: 1671 RVA: 0x00024840 File Offset: 0x00022A40
public TlsServerFinished(Context context, byte[] buffer)
: base(context, HandshakeType.Finished, buffer)
{
}
// Token: 0x06000689 RID: 1673 RVA: 0x00024864 File Offset: 0x00022A64
public override void Update()
{
base.Update();
base.Context.HandshakeState = HandshakeState.Finished;
}
// Token: 0x0600068A RID: 1674 RVA: 0x00024878 File Offset: 0x00022A78
protected override void ProcessAsSsl3()
{
HashAlgorithm hashAlgorithm = new SslHandshakeHash(base.Context.MasterSecret);
byte[] array = base.Context.HandshakeMessages.ToArray();
hashAlgorithm.TransformBlock(array, 0, array.Length, array, 0);
hashAlgorithm.TransformBlock(TlsServerFinished.Ssl3Marker, 0, TlsServerFinished.Ssl3Marker.Length, TlsServerFinished.Ssl3Marker, 0);
hashAlgorithm.TransformFinalBlock(CipherSuite.EmptyArray, 0, 0);
byte[] array2 = base.ReadBytes((int)this.Length);
byte[] hash = hashAlgorithm.Hash;
if (!HandshakeMessage.Compare(hash, array2))
{
throw new TlsException(AlertDescription.InsuficientSecurity, "Invalid ServerFinished message received.");
}
}
// Token: 0x0600068B RID: 1675 RVA: 0x0002490C File Offset: 0x00022B0C
protected override void ProcessAsTls1()
{
byte[] array = base.ReadBytes((int)this.Length);
HashAlgorithm hashAlgorithm = new MD5SHA1();
byte[] array2 = base.Context.HandshakeMessages.ToArray();
byte[] array3 = hashAlgorithm.ComputeHash(array2, 0, array2.Length);
byte[] array4 = base.Context.Current.Cipher.PRF(base.Context.MasterSecret, "server finished", array3, 12);
if (!HandshakeMessage.Compare(array4, array))
{
throw new TlsException("Invalid ServerFinished message received.");
}
}
// Token: 0x04000322 RID: 802
private static byte[] Ssl3Marker = new byte[] { 83, 82, 86, 82 };
}
}
@@ -0,0 +1,94 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000AF RID: 175
internal class TlsServerHello : HandshakeMessage
{
// Token: 0x0600068C RID: 1676 RVA: 0x0002498C File Offset: 0x00022B8C
public TlsServerHello(Context context, byte[] buffer)
: base(context, HandshakeType.ServerHello, buffer)
{
}
// Token: 0x0600068D RID: 1677 RVA: 0x00024998 File Offset: 0x00022B98
public override void Update()
{
base.Update();
base.Context.SessionId = this.sessionId;
base.Context.ServerRandom = this.random;
base.Context.Negotiating.Cipher = this.cipherSuite;
base.Context.CompressionMethod = this.compressionMethod;
base.Context.ProtocolNegotiated = true;
int num = base.Context.ClientRandom.Length;
int num2 = base.Context.ServerRandom.Length;
int num3 = num + num2;
byte[] array = new byte[num3];
Buffer.BlockCopy(base.Context.ClientRandom, 0, array, 0, num);
Buffer.BlockCopy(base.Context.ServerRandom, 0, array, num, num2);
base.Context.RandomCS = array;
byte[] array2 = new byte[num3];
Buffer.BlockCopy(base.Context.ServerRandom, 0, array2, 0, num2);
Buffer.BlockCopy(base.Context.ClientRandom, 0, array2, num2, num);
base.Context.RandomSC = array2;
}
// Token: 0x0600068E RID: 1678 RVA: 0x00024A9C File Offset: 0x00022C9C
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x0600068F RID: 1679 RVA: 0x00024AA4 File Offset: 0x00022CA4
protected override void ProcessAsTls1()
{
this.processProtocol(base.ReadInt16());
this.random = base.ReadBytes(32);
int num = (int)base.ReadByte();
if (num > 0)
{
this.sessionId = base.ReadBytes(num);
ClientSessionCache.Add(base.Context.ClientSettings.TargetHost, this.sessionId);
base.Context.AbbreviatedHandshake = HandshakeMessage.Compare(this.sessionId, base.Context.SessionId);
}
else
{
base.Context.AbbreviatedHandshake = false;
}
short num2 = base.ReadInt16();
if (base.Context.SupportedCiphers.IndexOf(num2) == -1)
{
throw new TlsException(AlertDescription.InsuficientSecurity, "Invalid cipher suite received from server");
}
this.cipherSuite = base.Context.SupportedCiphers[num2];
this.compressionMethod = (SecurityCompressionType)base.ReadByte();
}
// Token: 0x06000690 RID: 1680 RVA: 0x00024B84 File Offset: 0x00022D84
private void processProtocol(short protocol)
{
SecurityProtocolType securityProtocolType = base.Context.DecodeProtocolCode(protocol);
if ((securityProtocolType & base.Context.SecurityProtocolFlags) == securityProtocolType || (base.Context.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
{
base.Context.SecurityProtocol = securityProtocolType;
base.Context.SupportedCiphers.Clear();
base.Context.SupportedCiphers = null;
base.Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(securityProtocolType);
return;
}
throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
}
// Token: 0x04000323 RID: 803
private SecurityCompressionType compressionMethod;
// Token: 0x04000324 RID: 804
private byte[] random;
// Token: 0x04000325 RID: 805
private byte[] sessionId;
// Token: 0x04000326 RID: 806
private CipherSuite cipherSuite;
}
}
@@ -0,0 +1,24 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000B0 RID: 176
internal class TlsServerHelloDone : HandshakeMessage
{
// Token: 0x06000691 RID: 1681 RVA: 0x00024C18 File Offset: 0x00022E18
public TlsServerHelloDone(Context context, byte[] buffer)
: base(context, HandshakeType.ServerHelloDone, buffer)
{
}
// Token: 0x06000692 RID: 1682 RVA: 0x00024C24 File Offset: 0x00022E24
protected override void ProcessAsSsl3()
{
}
// Token: 0x06000693 RID: 1683 RVA: 0x00024C28 File Offset: 0x00022E28
protected override void ProcessAsTls1()
{
}
}
}
@@ -0,0 +1,63 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
// Token: 0x020000B1 RID: 177
internal class TlsServerKeyExchange : HandshakeMessage
{
// Token: 0x06000694 RID: 1684 RVA: 0x00024C2C File Offset: 0x00022E2C
public TlsServerKeyExchange(Context context, byte[] buffer)
: base(context, HandshakeType.ServerKeyExchange, buffer)
{
this.verifySignature();
}
// Token: 0x06000695 RID: 1685 RVA: 0x00024C40 File Offset: 0x00022E40
public override void Update()
{
base.Update();
base.Context.ServerSettings.ServerKeyExchange = true;
base.Context.ServerSettings.RsaParameters = this.rsaParams;
base.Context.ServerSettings.SignedParams = this.signedParams;
}
// Token: 0x06000696 RID: 1686 RVA: 0x00024C90 File Offset: 0x00022E90
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x06000697 RID: 1687 RVA: 0x00024C98 File Offset: 0x00022E98
protected override void ProcessAsTls1()
{
this.rsaParams = default(RSAParameters);
this.rsaParams.Modulus = base.ReadBytes((int)base.ReadInt16());
this.rsaParams.Exponent = base.ReadBytes((int)base.ReadInt16());
this.signedParams = base.ReadBytes((int)base.ReadInt16());
}
// Token: 0x06000698 RID: 1688 RVA: 0x00024CF4 File Offset: 0x00022EF4
private void verifySignature()
{
MD5SHA1 md5SHA = new MD5SHA1();
int num = this.rsaParams.Modulus.Length + this.rsaParams.Exponent.Length + 4;
TlsStream tlsStream = new TlsStream();
tlsStream.Write(base.Context.RandomCS);
tlsStream.Write(base.ToArray(), 0, num);
md5SHA.ComputeHash(tlsStream.ToArray());
tlsStream.Reset();
if (!md5SHA.VerifySignature(base.Context.ServerSettings.CertificateRSA, this.signedParams))
{
throw new TlsException(AlertDescription.DecodeError, "Data was not signed with the server certificate.");
}
}
// Token: 0x04000327 RID: 807
private RSAParameters rsaParams;
// Token: 0x04000328 RID: 808
private byte[] signedParams;
}
}