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;
}
}
@@ -0,0 +1,20 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake
{
// Token: 0x020000A4 RID: 164
[Serializable]
internal enum ClientCertificateType
{
// Token: 0x04000306 RID: 774
RSA = 1,
// Token: 0x04000307 RID: 775
DSS,
// Token: 0x04000308 RID: 776
RSAFixed,
// Token: 0x04000309 RID: 777
DSSFixed,
// Token: 0x0400030A RID: 778
Unknown = 255
}
}
@@ -0,0 +1,156 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake
{
// Token: 0x020000A5 RID: 165
internal abstract class HandshakeMessage : TlsStream
{
// Token: 0x06000652 RID: 1618 RVA: 0x00023558 File Offset: 0x00021758
public HandshakeMessage(Context context, HandshakeType handshakeType)
: this(context, handshakeType, ContentType.Handshake)
{
}
// Token: 0x06000653 RID: 1619 RVA: 0x00023564 File Offset: 0x00021764
public HandshakeMessage(Context context, HandshakeType handshakeType, ContentType contentType)
{
this.context = context;
this.handshakeType = handshakeType;
this.contentType = contentType;
}
// Token: 0x06000654 RID: 1620 RVA: 0x00023584 File Offset: 0x00021784
public HandshakeMessage(Context context, HandshakeType handshakeType, byte[] data)
: base(data)
{
this.context = context;
this.handshakeType = handshakeType;
}
// Token: 0x170001A0 RID: 416
// (get) Token: 0x06000655 RID: 1621 RVA: 0x0002359C File Offset: 0x0002179C
public Context Context
{
get
{
return this.context;
}
}
// Token: 0x170001A1 RID: 417
// (get) Token: 0x06000656 RID: 1622 RVA: 0x000235A4 File Offset: 0x000217A4
public HandshakeType HandshakeType
{
get
{
return this.handshakeType;
}
}
// Token: 0x170001A2 RID: 418
// (get) Token: 0x06000657 RID: 1623 RVA: 0x000235AC File Offset: 0x000217AC
public ContentType ContentType
{
get
{
return this.contentType;
}
}
// Token: 0x06000658 RID: 1624
protected abstract void ProcessAsTls1();
// Token: 0x06000659 RID: 1625
protected abstract void ProcessAsSsl3();
// Token: 0x0600065A RID: 1626 RVA: 0x000235B4 File Offset: 0x000217B4
public void Process()
{
SecurityProtocolType securityProtocol = this.Context.SecurityProtocol;
if (securityProtocol != SecurityProtocolType.Default)
{
if (securityProtocol != SecurityProtocolType.Ssl2)
{
if (securityProtocol == SecurityProtocolType.Ssl3)
{
this.ProcessAsSsl3();
return;
}
if (securityProtocol == SecurityProtocolType.Tls)
{
goto IL_37;
}
}
throw new NotSupportedException("Unsupported security protocol type");
}
IL_37:
this.ProcessAsTls1();
}
// Token: 0x0600065B RID: 1627 RVA: 0x0002361C File Offset: 0x0002181C
public virtual void Update()
{
if (this.CanWrite)
{
if (this.cache == null)
{
this.cache = this.EncodeMessage();
}
this.context.HandshakeMessages.Write(this.cache);
base.Reset();
this.cache = null;
}
}
// Token: 0x0600065C RID: 1628 RVA: 0x00023670 File Offset: 0x00021870
public virtual byte[] EncodeMessage()
{
this.cache = null;
if (this.CanWrite)
{
byte[] array = base.ToArray();
int num = array.Length;
this.cache = new byte[4 + num];
this.cache[0] = (byte)this.HandshakeType;
this.cache[1] = (byte)(num >> 16);
this.cache[2] = (byte)(num >> 8);
this.cache[3] = (byte)num;
Buffer.BlockCopy(array, 0, this.cache, 4, num);
}
return this.cache;
}
// Token: 0x0600065D RID: 1629 RVA: 0x000236F0 File Offset: 0x000218F0
public static bool Compare(byte[] buffer1, byte[] buffer2)
{
if (buffer1 == null || buffer2 == null)
{
return false;
}
if (buffer1.Length != buffer2.Length)
{
return false;
}
for (int i = 0; i < buffer1.Length; i++)
{
if (buffer1[i] != buffer2[i])
{
return false;
}
}
return true;
}
// Token: 0x0400030B RID: 779
private Context context;
// Token: 0x0400030C RID: 780
private HandshakeType handshakeType;
// Token: 0x0400030D RID: 781
private ContentType contentType;
// Token: 0x0400030E RID: 782
private byte[] cache;
}
}
@@ -0,0 +1,32 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake
{
// Token: 0x020000A6 RID: 166
[Serializable]
internal enum HandshakeType : byte
{
// Token: 0x04000310 RID: 784
HelloRequest,
// Token: 0x04000311 RID: 785
ClientHello,
// Token: 0x04000312 RID: 786
ServerHello,
// Token: 0x04000313 RID: 787
Certificate = 11,
// Token: 0x04000314 RID: 788
ServerKeyExchange,
// Token: 0x04000315 RID: 789
CertificateRequest,
// Token: 0x04000316 RID: 790
ServerHelloDone,
// Token: 0x04000317 RID: 791
CertificateVerify,
// Token: 0x04000318 RID: 792
ClientKeyExchange,
// Token: 0x04000319 RID: 793
Finished = 20,
// Token: 0x0400031A RID: 794
None = 255
}
}
@@ -0,0 +1,218 @@
using System;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
using Mono.Security.X509;
using Mono.Security.X509.Extensions;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B2 RID: 178
internal class TlsClientCertificate : HandshakeMessage
{
// Token: 0x06000699 RID: 1689 RVA: 0x00024D90 File Offset: 0x00022F90
public TlsClientCertificate(Context context, byte[] buffer)
: base(context, HandshakeType.Certificate, buffer)
{
}
// Token: 0x0600069A RID: 1690 RVA: 0x00024D9C File Offset: 0x00022F9C
public override void Update()
{
foreach (Mono.Security.X509.X509Certificate x509Certificate in this.clientCertificates)
{
base.Context.ClientSettings.Certificates.Add(new global::System.Security.Cryptography.X509Certificates.X509Certificate(x509Certificate.RawData));
}
}
// Token: 0x0600069B RID: 1691 RVA: 0x00024E20 File Offset: 0x00023020
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x0600069C RID: 1692 RVA: 0x00024E28 File Offset: 0x00023028
protected override void ProcessAsTls1()
{
int num = 0;
int i = base.ReadInt24();
this.clientCertificates = new Mono.Security.X509.X509CertificateCollection();
while (i > num)
{
int num2 = base.ReadInt24();
num += num2 + 3;
byte[] array = base.ReadBytes(num2);
this.clientCertificates.Add(new Mono.Security.X509.X509Certificate(array));
}
if (this.clientCertificates.Count > 0)
{
this.validateCertificates(this.clientCertificates);
}
else if ((base.Context as ServerContext).ClientCertificateRequired)
{
throw new TlsException(AlertDescription.NoCertificate);
}
}
// Token: 0x0600069D RID: 1693 RVA: 0x00024EBC File Offset: 0x000230BC
private bool checkCertificateUsage(Mono.Security.X509.X509Certificate cert)
{
ServerContext serverContext = (ServerContext)base.Context;
if (cert.Version < 3)
{
return true;
}
KeyUsages keyUsages = KeyUsages.none;
switch (serverContext.Negotiating.Cipher.ExchangeAlgorithmType)
{
case ExchangeAlgorithmType.DiffieHellman:
keyUsages = KeyUsages.keyAgreement;
break;
case ExchangeAlgorithmType.Fortezza:
return false;
case ExchangeAlgorithmType.RsaKeyX:
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.2");
}
if (keyUsageExtension != null)
{
return keyUsageExtension.Support(keyUsages);
}
if (extendedKeyUsageExtension != null)
{
return extendedKeyUsageExtension.KeyPurpose.Contains("1.3.6.1.5.5.7.3.2");
}
x509Extension = cert.Extensions["2.16.840.1.113730.1.1"];
if (x509Extension != null)
{
NetscapeCertTypeExtension netscapeCertTypeExtension = new NetscapeCertTypeExtension(x509Extension);
return netscapeCertTypeExtension.Support(NetscapeCertTypeExtension.CertTypes.SslClient);
}
return false;
}
// Token: 0x0600069E RID: 1694 RVA: 0x00024FF4 File Offset: 0x000231F4
private void validateCertificates(Mono.Security.X509.X509CertificateCollection certificates)
{
ServerContext serverContext = (ServerContext)base.Context;
AlertDescription alertDescription = AlertDescription.BadCertificate;
global::System.Security.Cryptography.X509Certificates.X509Certificate x509Certificate = null;
int[] array = null;
if (certificates.Count > 0)
{
Mono.Security.X509.X509Certificate x509Certificate2 = certificates[0];
ArrayList arrayList = new ArrayList();
if (!this.checkCertificateUsage(x509Certificate2))
{
arrayList.Add(-2146762490);
}
Mono.Security.X509.X509Chain x509Chain;
if (certificates.Count > 1)
{
Mono.Security.X509.X509CertificateCollection x509CertificateCollection = new Mono.Security.X509.X509CertificateCollection(certificates);
x509CertificateCollection.Remove(x509Certificate2);
x509Chain = new Mono.Security.X509.X509Chain(x509CertificateCollection);
}
else
{
x509Chain = new Mono.Security.X509.X509Chain();
}
bool flag = false;
try
{
flag = x509Chain.Build(x509Certificate2);
}
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);
}
}
x509Certificate = new global::System.Security.Cryptography.X509Certificates.X509Certificate(x509Certificate2.RawData);
array = (int[])arrayList.ToArray(typeof(int));
}
else
{
array = new int[0];
}
global::System.Security.Cryptography.X509Certificates.X509CertificateCollection x509CertificateCollection2 = new global::System.Security.Cryptography.X509Certificates.X509CertificateCollection();
foreach (Mono.Security.X509.X509Certificate x509Certificate3 in certificates)
{
x509CertificateCollection2.Add(new global::System.Security.Cryptography.X509Certificates.X509Certificate(x509Certificate3.RawData));
}
if (!serverContext.SslStream.RaiseClientCertificateValidation(x509Certificate, array))
{
throw new TlsException(alertDescription, "Invalid certificate received from client.");
}
base.Context.ClientSettings.ClientCertificate = x509Certificate;
}
// Token: 0x04000329 RID: 809
private Mono.Security.X509.X509CertificateCollection clientCertificates;
}
}
@@ -0,0 +1,43 @@
using System;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B3 RID: 179
internal class TlsClientCertificateVerify : HandshakeMessage
{
// Token: 0x0600069F RID: 1695 RVA: 0x00025288 File Offset: 0x00023488
public TlsClientCertificateVerify(Context context, byte[] buffer)
: base(context, HandshakeType.CertificateVerify, buffer)
{
}
// Token: 0x060006A0 RID: 1696 RVA: 0x00025294 File Offset: 0x00023494
protected override void ProcessAsSsl3()
{
ServerContext serverContext = (ServerContext)base.Context;
int num = (int)base.ReadInt16();
byte[] array = base.ReadBytes(num);
SslHandshakeHash sslHandshakeHash = new SslHandshakeHash(serverContext.MasterSecret);
sslHandshakeHash.TransformFinalBlock(serverContext.HandshakeMessages.ToArray(), 0, (int)serverContext.HandshakeMessages.Length);
if (!sslHandshakeHash.VerifySignature(serverContext.ClientSettings.CertificateRSA, array))
{
throw new TlsException(AlertDescription.HandshakeFailiure, "Handshake Failure.");
}
}
// Token: 0x060006A1 RID: 1697 RVA: 0x0002530C File Offset: 0x0002350C
protected override void ProcessAsTls1()
{
ServerContext serverContext = (ServerContext)base.Context;
int num = (int)base.ReadInt16();
byte[] array = base.ReadBytes(num);
MD5SHA1 md5SHA = new MD5SHA1();
md5SHA.ComputeHash(serverContext.HandshakeMessages.ToArray(), 0, (int)serverContext.HandshakeMessages.Length);
if (!md5SHA.VerifySignature(serverContext.ClientSettings.CertificateRSA, array))
{
throw new TlsException(AlertDescription.HandshakeFailiure, "Handshake Failure.");
}
}
}
}
@@ -0,0 +1,47 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B4 RID: 180
internal class TlsClientFinished : HandshakeMessage
{
// Token: 0x060006A2 RID: 1698 RVA: 0x00025380 File Offset: 0x00023580
public TlsClientFinished(Context context, byte[] buffer)
: base(context, HandshakeType.Finished, buffer)
{
}
// Token: 0x060006A3 RID: 1699 RVA: 0x0002538C File Offset: 0x0002358C
protected override void ProcessAsSsl3()
{
HashAlgorithm hashAlgorithm = new SslHandshakeHash(base.Context.MasterSecret);
TlsStream tlsStream = new TlsStream();
tlsStream.Write(base.Context.HandshakeMessages.ToArray());
tlsStream.Write(1129074260);
hashAlgorithm.TransformFinalBlock(tlsStream.ToArray(), 0, (int)tlsStream.Length);
tlsStream.Reset();
byte[] array = base.ReadBytes((int)this.Length);
byte[] hash = hashAlgorithm.Hash;
if (!HandshakeMessage.Compare(array, hash))
{
throw new TlsException(AlertDescription.DecryptError, "Decrypt error.");
}
}
// Token: 0x060006A4 RID: 1700 RVA: 0x0002541C File Offset: 0x0002361C
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, "client finished", array3, 12);
if (!HandshakeMessage.Compare(array, array4))
{
throw new TlsException(AlertDescription.DecryptError, "Decrypt error.");
}
}
}
}
@@ -0,0 +1,100 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B5 RID: 181
internal class TlsClientHello : HandshakeMessage
{
// Token: 0x060006A5 RID: 1701 RVA: 0x000254A0 File Offset: 0x000236A0
public TlsClientHello(Context context, byte[] buffer)
: base(context, HandshakeType.ClientHello, buffer)
{
}
// Token: 0x060006A6 RID: 1702 RVA: 0x000254AC File Offset: 0x000236AC
public override void Update()
{
base.Update();
this.selectCipherSuite();
this.selectCompressionMethod();
base.Context.SessionId = this.sessionId;
base.Context.ClientRandom = this.random;
base.Context.ProtocolNegotiated = true;
}
// Token: 0x060006A7 RID: 1703 RVA: 0x000254FC File Offset: 0x000236FC
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x060006A8 RID: 1704 RVA: 0x00025504 File Offset: 0x00023704
protected override void ProcessAsTls1()
{
this.processProtocol(base.ReadInt16());
this.random = base.ReadBytes(32);
this.sessionId = base.ReadBytes((int)base.ReadByte());
this.cipherSuites = new short[(int)(base.ReadInt16() / 2)];
for (int i = 0; i < this.cipherSuites.Length; i++)
{
this.cipherSuites[i] = base.ReadInt16();
}
this.compressionMethods = new byte[(int)base.ReadByte()];
for (int j = 0; j < this.compressionMethods.Length; j++)
{
this.compressionMethods[j] = base.ReadByte();
}
}
// Token: 0x060006A9 RID: 1705 RVA: 0x000255B0 File Offset: 0x000237B0
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: 0x060006AA RID: 1706 RVA: 0x00025644 File Offset: 0x00023844
private void selectCipherSuite()
{
for (int i = 0; i < this.cipherSuites.Length; i++)
{
int num;
if ((num = base.Context.SupportedCiphers.IndexOf(this.cipherSuites[i])) != -1)
{
base.Context.Negotiating.Cipher = base.Context.SupportedCiphers[num];
break;
}
}
if (base.Context.Negotiating.Cipher == null)
{
throw new TlsException(AlertDescription.InsuficientSecurity, "Insuficient Security");
}
}
// Token: 0x060006AB RID: 1707 RVA: 0x000256D4 File Offset: 0x000238D4
private void selectCompressionMethod()
{
base.Context.CompressionMethod = SecurityCompressionType.None;
}
// Token: 0x0400032A RID: 810
private byte[] random;
// Token: 0x0400032B RID: 811
private byte[] sessionId;
// Token: 0x0400032C RID: 812
private short[] cipherSuites;
// Token: 0x0400032D RID: 813
private byte[] compressionMethods;
}
}
@@ -0,0 +1,50 @@
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B6 RID: 182
internal class TlsClientKeyExchange : HandshakeMessage
{
// Token: 0x060006AC RID: 1708 RVA: 0x000256E4 File Offset: 0x000238E4
public TlsClientKeyExchange(Context context, byte[] buffer)
: base(context, HandshakeType.ClientKeyExchange, buffer)
{
}
// Token: 0x060006AD RID: 1709 RVA: 0x000256F0 File Offset: 0x000238F0
protected override void ProcessAsSsl3()
{
ServerContext serverContext = (ServerContext)base.Context;
AsymmetricAlgorithm asymmetricAlgorithm = serverContext.SslStream.RaisePrivateKeySelection(new X509Certificate(serverContext.ServerSettings.Certificates[0].RawData), null);
if (asymmetricAlgorithm == null)
{
throw new TlsException(AlertDescription.UserCancelled, "Server certificate Private Key unavailable.");
}
byte[] array = base.ReadBytes((int)this.Length);
RSAPKCS1KeyExchangeDeformatter rsapkcs1KeyExchangeDeformatter = new RSAPKCS1KeyExchangeDeformatter(asymmetricAlgorithm);
byte[] array2 = rsapkcs1KeyExchangeDeformatter.DecryptKeyExchange(array);
base.Context.Negotiating.Cipher.ComputeMasterSecret(array2);
base.Context.Negotiating.Cipher.ComputeKeys();
base.Context.Negotiating.Cipher.InitializeCipher();
}
// Token: 0x060006AE RID: 1710 RVA: 0x000257A8 File Offset: 0x000239A8
protected override void ProcessAsTls1()
{
ServerContext serverContext = (ServerContext)base.Context;
AsymmetricAlgorithm asymmetricAlgorithm = serverContext.SslStream.RaisePrivateKeySelection(new X509Certificate(serverContext.ServerSettings.Certificates[0].RawData), null);
if (asymmetricAlgorithm == null)
{
throw new TlsException(AlertDescription.UserCancelled, "Server certificate Private Key unavailable.");
}
byte[] array = base.ReadBytes((int)base.ReadInt16());
RSAPKCS1KeyExchangeDeformatter rsapkcs1KeyExchangeDeformatter = new RSAPKCS1KeyExchangeDeformatter(asymmetricAlgorithm);
byte[] array2 = rsapkcs1KeyExchangeDeformatter.DecryptKeyExchange(array);
base.Context.Negotiating.Cipher.ComputeMasterSecret(array2);
base.Context.Negotiating.Cipher.ComputeKeys();
base.Context.Negotiating.Cipher.InitializeCipher();
}
}
}
@@ -0,0 +1,35 @@
using System;
using Mono.Security.X509;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B7 RID: 183
internal class TlsServerCertificate : HandshakeMessage
{
// Token: 0x060006AF RID: 1711 RVA: 0x0002585C File Offset: 0x00023A5C
public TlsServerCertificate(Context context)
: base(context, HandshakeType.Certificate)
{
}
// Token: 0x060006B0 RID: 1712 RVA: 0x00025868 File Offset: 0x00023A68
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x060006B1 RID: 1713 RVA: 0x00025870 File Offset: 0x00023A70
protected override void ProcessAsTls1()
{
TlsStream tlsStream = new TlsStream();
foreach (X509Certificate x509Certificate in base.Context.ServerSettings.Certificates)
{
tlsStream.WriteInt24(x509Certificate.RawData.Length);
tlsStream.Write(x509Certificate.RawData);
}
base.WriteInt24(Convert.ToInt32(tlsStream.Length));
base.Write(tlsStream.ToArray());
tlsStream.Close();
}
}
}
@@ -0,0 +1,49 @@
using System;
using Mono.Security.X509;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B8 RID: 184
internal class TlsServerCertificateRequest : HandshakeMessage
{
// Token: 0x060006B2 RID: 1714 RVA: 0x00025920 File Offset: 0x00023B20
public TlsServerCertificateRequest(Context context)
: base(context, HandshakeType.CertificateRequest)
{
}
// Token: 0x060006B3 RID: 1715 RVA: 0x0002592C File Offset: 0x00023B2C
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x060006B4 RID: 1716 RVA: 0x00025934 File Offset: 0x00023B34
protected override void ProcessAsTls1()
{
ServerContext serverContext = (ServerContext)base.Context;
int num = serverContext.ServerSettings.CertificateTypes.Length;
this.WriteByte(Convert.ToByte(num));
for (int i = 0; i < num; i++)
{
this.WriteByte((byte)serverContext.ServerSettings.CertificateTypes[i]);
}
if (serverContext.ServerSettings.DistinguisedNames.Length > 0)
{
TlsStream tlsStream = new TlsStream();
foreach (string text in serverContext.ServerSettings.DistinguisedNames)
{
byte[] bytes = X501.FromString(text).GetBytes();
tlsStream.Write((short)bytes.Length);
tlsStream.Write(bytes);
}
base.Write((short)tlsStream.Length);
base.Write(tlsStream.ToArray());
}
else
{
base.Write(0);
}
}
}
}
@@ -0,0 +1,39 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000B9 RID: 185
internal class TlsServerFinished : HandshakeMessage
{
// Token: 0x060006B5 RID: 1717 RVA: 0x00025A1C File Offset: 0x00023C1C
public TlsServerFinished(Context context)
: base(context, HandshakeType.Finished)
{
}
// Token: 0x060006B7 RID: 1719 RVA: 0x00025A40 File Offset: 0x00023C40
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);
base.Write(hashAlgorithm.Hash);
}
// Token: 0x060006B8 RID: 1720 RVA: 0x00025AB4 File Offset: 0x00023CB4
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.Current.Cipher.PRF(base.Context.MasterSecret, "server finished", array2, 12));
}
// Token: 0x0400032E RID: 814
private static byte[] Ssl3Marker = new byte[] { 83, 82, 86, 82 };
}
}
@@ -0,0 +1,66 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000BA RID: 186
internal class TlsServerHello : HandshakeMessage
{
// Token: 0x060006B9 RID: 1721 RVA: 0x00025B14 File Offset: 0x00023D14
public TlsServerHello(Context context)
: base(context, HandshakeType.ServerHello)
{
}
// Token: 0x060006BA RID: 1722 RVA: 0x00025B20 File Offset: 0x00023D20
public override void Update()
{
base.Update();
TlsStream tlsStream = new TlsStream();
tlsStream.Write(this.unixTime);
tlsStream.Write(this.random);
base.Context.ServerRandom = tlsStream.ToArray();
tlsStream.Reset();
tlsStream.Write(base.Context.ClientRandom);
tlsStream.Write(base.Context.ServerRandom);
base.Context.RandomCS = tlsStream.ToArray();
tlsStream.Reset();
tlsStream.Write(base.Context.ServerRandom);
tlsStream.Write(base.Context.ClientRandom);
base.Context.RandomSC = tlsStream.ToArray();
tlsStream.Reset();
}
// Token: 0x060006BB RID: 1723 RVA: 0x00025BDC File Offset: 0x00023DDC
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x060006BC RID: 1724 RVA: 0x00025BE4 File Offset: 0x00023DE4
protected override void ProcessAsTls1()
{
base.Write(base.Context.Protocol);
this.unixTime = base.Context.GetUnixTime();
base.Write(this.unixTime);
this.random = base.Context.GetSecureRandomBytes(28);
base.Write(this.random);
if (base.Context.SessionId == null)
{
this.WriteByte(0);
}
else
{
this.WriteByte((byte)base.Context.SessionId.Length);
base.Write(base.Context.SessionId);
}
base.Write(base.Context.Negotiating.Cipher.Code);
this.WriteByte((byte)base.Context.CompressionMethod);
}
// Token: 0x0400032F RID: 815
private int unixTime;
// Token: 0x04000330 RID: 816
private byte[] random;
}
}
@@ -0,0 +1,24 @@
using System;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000BB RID: 187
internal class TlsServerHelloDone : HandshakeMessage
{
// Token: 0x060006BD RID: 1725 RVA: 0x00025CAC File Offset: 0x00023EAC
public TlsServerHelloDone(Context context)
: base(context, HandshakeType.ServerHelloDone)
{
}
// Token: 0x060006BE RID: 1726 RVA: 0x00025CB8 File Offset: 0x00023EB8
protected override void ProcessAsSsl3()
{
}
// Token: 0x060006BF RID: 1727 RVA: 0x00025CBC File Offset: 0x00023EBC
protected override void ProcessAsTls1()
{
}
}
}
@@ -0,0 +1,56 @@
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls.Handshake.Server
{
// Token: 0x020000BC RID: 188
internal class TlsServerKeyExchange : HandshakeMessage
{
// Token: 0x060006C0 RID: 1728 RVA: 0x00025CC0 File Offset: 0x00023EC0
public TlsServerKeyExchange(Context context)
: base(context, HandshakeType.ServerKeyExchange)
{
}
// Token: 0x060006C1 RID: 1729 RVA: 0x00025CCC File Offset: 0x00023ECC
public override void Update()
{
throw new NotSupportedException();
}
// Token: 0x060006C2 RID: 1730 RVA: 0x00025CD4 File Offset: 0x00023ED4
protected override void ProcessAsSsl3()
{
this.ProcessAsTls1();
}
// Token: 0x060006C3 RID: 1731 RVA: 0x00025CDC File Offset: 0x00023EDC
protected override void ProcessAsTls1()
{
ServerContext serverContext = (ServerContext)base.Context;
RSA rsa = (RSA)serverContext.SslStream.PrivateKeyCertSelectionDelegate(new X509Certificate(serverContext.ServerSettings.Certificates[0].RawData), null);
RSAParameters rsaparameters = rsa.ExportParameters(false);
base.WriteInt24(rsaparameters.Modulus.Length);
this.Write(rsaparameters.Modulus, 0, rsaparameters.Modulus.Length);
base.WriteInt24(rsaparameters.Exponent.Length);
this.Write(rsaparameters.Exponent, 0, rsaparameters.Exponent.Length);
byte[] array = this.createSignature(rsa, base.ToArray());
base.WriteInt24(array.Length);
base.Write(array);
}
// Token: 0x060006C4 RID: 1732 RVA: 0x00025D9C File Offset: 0x00023F9C
private byte[] createSignature(RSA rsa, byte[] buffer)
{
MD5SHA1 md5SHA = new MD5SHA1();
TlsStream tlsStream = new TlsStream();
tlsStream.Write(base.Context.RandomCS);
tlsStream.Write(buffer, 0, buffer.Length);
md5SHA.ComputeHash(tlsStream.ToArray());
tlsStream.Reset();
return md5SHA.CreateSignature(rsa);
}
}
}