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
+92
View File
@@ -0,0 +1,92 @@
using System;
// Token: 0x02000002 RID: 2
internal static class Consts
{
// Token: 0x04000001 RID: 1
public const string MonoVersion = "2.6.5.0";
// Token: 0x04000002 RID: 2
public const string MonoCompany = "MONO development team";
// Token: 0x04000003 RID: 3
public const string MonoProduct = "MONO Common language infrastructure";
// Token: 0x04000004 RID: 4
public const string MonoCopyright = "(c) various MONO Authors";
// Token: 0x04000005 RID: 5
public const string FxVersion = "2.0.0.0";
// Token: 0x04000006 RID: 6
public const string VsVersion = "8.0.0.0";
// Token: 0x04000007 RID: 7
public const string FxFileVersion = "2.0.50727.1433";
// Token: 0x04000008 RID: 8
public const string VsFileVersion = "8.0.50727.1433";
// Token: 0x04000009 RID: 9
public const string AssemblyI18N = "I18N, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
// Token: 0x0400000A RID: 10
public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x0400000B RID: 11
public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x0400000C RID: 12
public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x0400000D RID: 13
public const string AssemblyMono_Http = "Mono.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
// Token: 0x0400000E RID: 14
public const string AssemblyMono_Posix = "Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
// Token: 0x0400000F RID: 15
public const string AssemblyMono_Security = "Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
// Token: 0x04000010 RID: 16
public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
// Token: 0x04000011 RID: 17
public const string AssemblyCorlib = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
// Token: 0x04000012 RID: 18
public const string AssemblySystem = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
// Token: 0x04000013 RID: 19
public const string AssemblySystem_Data = "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
// Token: 0x04000014 RID: 20
public const string AssemblySystem_Design = "System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x04000015 RID: 21
public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x04000016 RID: 22
public const string AssemblySystem_Drawing = "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x04000017 RID: 23
public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x04000018 RID: 24
public const string AssemblySystem_Messaging = "System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x04000019 RID: 25
public const string AssemblySystem_Security = "System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x0400001A RID: 26
public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x0400001B RID: 27
public const string AssemblySystem_Web = "System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
// Token: 0x0400001C RID: 28
public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
// Token: 0x0400001D RID: 29
public const string AssemblySystem_Core = "System.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
+22
View File
@@ -0,0 +1,22 @@
using System;
// Token: 0x02000003 RID: 3
internal sealed class Locale
{
// Token: 0x06000001 RID: 1 RVA: 0x000020EC File Offset: 0x000002EC
private Locale()
{
}
// Token: 0x06000002 RID: 2 RVA: 0x000020F4 File Offset: 0x000002F4
public static string GetText(string msg)
{
return msg;
}
// Token: 0x06000003 RID: 3 RVA: 0x000020F8 File Offset: 0x000002F8
public static string GetText(string fmt, params object[] args)
{
return string.Format(fmt, args);
}
}
+1948
View File
@@ -0,0 +1,1948 @@
using System;
using System.Security.Cryptography;
using Mono.Math.Prime;
using Mono.Math.Prime.Generator;
namespace Mono.Math
{
// Token: 0x02000004 RID: 4
public class BigInteger
{
// Token: 0x06000004 RID: 4 RVA: 0x00002104 File Offset: 0x00000304
public BigInteger()
{
this.data = new uint[20];
this.length = 20U;
}
// Token: 0x06000005 RID: 5 RVA: 0x0000212C File Offset: 0x0000032C
[CLSCompliant(false)]
public BigInteger(BigInteger.Sign sign, uint len)
{
this.data = new uint[len];
this.length = len;
}
// Token: 0x06000006 RID: 6 RVA: 0x00002150 File Offset: 0x00000350
public BigInteger(BigInteger bi)
{
this.data = (uint[])bi.data.Clone();
this.length = bi.length;
}
// Token: 0x06000007 RID: 7 RVA: 0x00002184 File Offset: 0x00000384
[CLSCompliant(false)]
public BigInteger(BigInteger bi, uint len)
{
this.data = new uint[len];
for (uint num = 0U; num < bi.length; num += 1U)
{
this.data[(int)((UIntPtr)num)] = bi.data[(int)((UIntPtr)num)];
}
this.length = bi.length;
}
// Token: 0x06000008 RID: 8 RVA: 0x000021E0 File Offset: 0x000003E0
public BigInteger(byte[] inData)
{
this.length = (uint)inData.Length >> 2;
int num = inData.Length & 3;
if (num != 0)
{
this.length += 1U;
}
this.data = new uint[this.length];
int i = inData.Length - 1;
int num2 = 0;
while (i >= 3)
{
this.data[num2] = (uint)(((int)inData[i - 3] << 24) | ((int)inData[i - 2] << 16) | ((int)inData[i - 1] << 8) | (int)inData[i]);
i -= 4;
num2++;
}
switch (num)
{
case 1:
this.data[(int)((UIntPtr)(this.length - 1U))] = (uint)inData[0];
break;
case 2:
this.data[(int)((UIntPtr)(this.length - 1U))] = (uint)(((int)inData[0] << 8) | (int)inData[1]);
break;
case 3:
this.data[(int)((UIntPtr)(this.length - 1U))] = (uint)(((int)inData[0] << 16) | ((int)inData[1] << 8) | (int)inData[2]);
break;
}
this.Normalize();
}
// Token: 0x06000009 RID: 9 RVA: 0x000022F0 File Offset: 0x000004F0
[CLSCompliant(false)]
public BigInteger(uint[] inData)
{
this.length = (uint)inData.Length;
this.data = new uint[this.length];
int i = (int)(this.length - 1U);
int num = 0;
while (i >= 0)
{
this.data[num] = inData[i];
i--;
num++;
}
this.Normalize();
}
// Token: 0x0600000A RID: 10 RVA: 0x00002358 File Offset: 0x00000558
[CLSCompliant(false)]
public BigInteger(uint ui)
{
this.data = new uint[] { ui };
}
// Token: 0x0600000B RID: 11 RVA: 0x00002378 File Offset: 0x00000578
[CLSCompliant(false)]
public BigInteger(ulong ul)
{
this.data = new uint[]
{
(uint)ul,
(uint)(ul >> 32)
};
this.length = 2U;
this.Normalize();
}
// Token: 0x0600000D RID: 13 RVA: 0x000023D4 File Offset: 0x000005D4
public static BigInteger Parse(string number)
{
if (number == null)
{
throw new ArgumentNullException("number");
}
int i = 0;
int num = number.Length;
bool flag = false;
BigInteger bigInteger = new BigInteger(0U);
if (number[i] == '+')
{
i++;
}
else if (number[i] == '-')
{
throw new FormatException("Operation would return a negative value");
}
while (i < num)
{
char c = number[i];
if (c == '\0')
{
i = num;
}
else if (c >= '0' && c <= '9')
{
bigInteger = bigInteger * 10 + (int)(c - '0');
flag = true;
}
else
{
if (char.IsWhiteSpace(c))
{
for (i++; i < num; i++)
{
if (!char.IsWhiteSpace(number[i]))
{
throw new FormatException();
}
}
break;
}
throw new FormatException();
}
i++;
}
if (!flag)
{
throw new FormatException();
}
return bigInteger;
}
// Token: 0x0600000E RID: 14 RVA: 0x000024DC File Offset: 0x000006DC
public static BigInteger Add(BigInteger bi1, BigInteger bi2)
{
return bi1 + bi2;
}
// Token: 0x0600000F RID: 15 RVA: 0x000024E8 File Offset: 0x000006E8
public static BigInteger Subtract(BigInteger bi1, BigInteger bi2)
{
return bi1 - bi2;
}
// Token: 0x06000010 RID: 16 RVA: 0x000024F4 File Offset: 0x000006F4
public static int Modulus(BigInteger bi, int i)
{
return bi % i;
}
// Token: 0x06000011 RID: 17 RVA: 0x00002500 File Offset: 0x00000700
[CLSCompliant(false)]
public static uint Modulus(BigInteger bi, uint ui)
{
return bi % ui;
}
// Token: 0x06000012 RID: 18 RVA: 0x0000250C File Offset: 0x0000070C
public static BigInteger Modulus(BigInteger bi1, BigInteger bi2)
{
return bi1 % bi2;
}
// Token: 0x06000013 RID: 19 RVA: 0x00002518 File Offset: 0x00000718
public static BigInteger Divid(BigInteger bi, int i)
{
return bi / i;
}
// Token: 0x06000014 RID: 20 RVA: 0x00002524 File Offset: 0x00000724
public static BigInteger Divid(BigInteger bi1, BigInteger bi2)
{
return bi1 / bi2;
}
// Token: 0x06000015 RID: 21 RVA: 0x00002530 File Offset: 0x00000730
public static BigInteger Multiply(BigInteger bi1, BigInteger bi2)
{
return bi1 * bi2;
}
// Token: 0x06000016 RID: 22 RVA: 0x0000253C File Offset: 0x0000073C
public static BigInteger Multiply(BigInteger bi, int i)
{
return bi * i;
}
// Token: 0x17000001 RID: 1
// (get) Token: 0x06000017 RID: 23 RVA: 0x00002548 File Offset: 0x00000748
private static RandomNumberGenerator Rng
{
get
{
if (BigInteger.rng == null)
{
BigInteger.rng = RandomNumberGenerator.Create();
}
return BigInteger.rng;
}
}
// Token: 0x06000018 RID: 24 RVA: 0x00002564 File Offset: 0x00000764
public static BigInteger GenerateRandom(int bits, RandomNumberGenerator rng)
{
int num = bits >> 5;
int num2 = bits & 31;
if (num2 != 0)
{
num++;
}
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, (uint)(num + 1));
byte[] array = new byte[num << 2];
rng.GetBytes(array);
Buffer.BlockCopy(array, 0, bigInteger.data, 0, num << 2);
if (num2 != 0)
{
uint num3 = 1U << num2 - 1;
bigInteger.data[num - 1] |= num3;
num3 = uint.MaxValue >> 32 - num2;
bigInteger.data[num - 1] &= num3;
}
else
{
bigInteger.data[num - 1] |= 2147483648U;
}
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x06000019 RID: 25 RVA: 0x00002618 File Offset: 0x00000818
public static BigInteger GenerateRandom(int bits)
{
return BigInteger.GenerateRandom(bits, BigInteger.Rng);
}
// Token: 0x0600001A RID: 26 RVA: 0x00002628 File Offset: 0x00000828
public void Randomize(RandomNumberGenerator rng)
{
if (this == 0U)
{
return;
}
int num = this.BitCount();
int num2 = num >> 5;
int num3 = num & 31;
if (num3 != 0)
{
num2++;
}
byte[] array = new byte[num2 << 2];
rng.GetBytes(array);
Buffer.BlockCopy(array, 0, this.data, 0, num2 << 2);
if (num3 != 0)
{
uint num4 = 1U << num3 - 1;
this.data[num2 - 1] |= num4;
num4 = uint.MaxValue >> 32 - num3;
this.data[num2 - 1] &= num4;
}
else
{
this.data[num2 - 1] |= 2147483648U;
}
this.Normalize();
}
// Token: 0x0600001B RID: 27 RVA: 0x000026E4 File Offset: 0x000008E4
public void Randomize()
{
this.Randomize(BigInteger.Rng);
}
// Token: 0x0600001C RID: 28 RVA: 0x000026F4 File Offset: 0x000008F4
public int BitCount()
{
this.Normalize();
uint num = this.data[(int)((UIntPtr)(this.length - 1U))];
uint num2 = 2147483648U;
uint num3 = 32U;
while (num3 > 0U && (num & num2) == 0U)
{
num3 -= 1U;
num2 >>= 1;
}
return (int)(num3 + (this.length - 1U << 5));
}
// Token: 0x0600001D RID: 29 RVA: 0x0000274C File Offset: 0x0000094C
[CLSCompliant(false)]
public bool TestBit(uint bitNum)
{
uint num = bitNum >> 5;
byte b = (byte)(bitNum & 31U);
uint num2 = 1U << (int)b;
return (this.data[(int)((UIntPtr)num)] & num2) != 0U;
}
// Token: 0x0600001E RID: 30 RVA: 0x0000277C File Offset: 0x0000097C
public bool TestBit(int bitNum)
{
if (bitNum < 0)
{
throw new IndexOutOfRangeException("bitNum out of range");
}
uint num = (uint)bitNum >> 5;
byte b = (byte)(bitNum & 31);
uint num2 = 1U << (int)b;
return (this.data[(int)((UIntPtr)num)] | num2) == this.data[(int)((UIntPtr)num)];
}
// Token: 0x0600001F RID: 31 RVA: 0x000027C4 File Offset: 0x000009C4
[CLSCompliant(false)]
public void SetBit(uint bitNum)
{
this.SetBit(bitNum, true);
}
// Token: 0x06000020 RID: 32 RVA: 0x000027D0 File Offset: 0x000009D0
[CLSCompliant(false)]
public void ClearBit(uint bitNum)
{
this.SetBit(bitNum, false);
}
// Token: 0x06000021 RID: 33 RVA: 0x000027DC File Offset: 0x000009DC
[CLSCompliant(false)]
public void SetBit(uint bitNum, bool value)
{
uint num = bitNum >> 5;
if (num < this.length)
{
uint num2 = 1U << (int)bitNum;
if (value)
{
this.data[(int)((UIntPtr)num)] |= num2;
}
else
{
this.data[(int)((UIntPtr)num)] &= ~num2;
}
}
}
// Token: 0x06000022 RID: 34 RVA: 0x00002834 File Offset: 0x00000A34
public int LowestSetBit()
{
if (this == 0U)
{
return -1;
}
int num = 0;
while (!this.TestBit(num))
{
num++;
}
return num;
}
// Token: 0x06000023 RID: 35 RVA: 0x00002868 File Offset: 0x00000A68
public byte[] GetBytes()
{
if (this == 0U)
{
return new byte[1];
}
int num = this.BitCount();
int num2 = num >> 3;
if ((num & 7) != 0)
{
num2++;
}
byte[] array = new byte[num2];
int num3 = num2 & 3;
if (num3 == 0)
{
num3 = 4;
}
int num4 = 0;
for (int i = (int)(this.length - 1U); i >= 0; i--)
{
uint num5 = this.data[i];
for (int j = num3 - 1; j >= 0; j--)
{
array[num4 + j] = (byte)(num5 & 255U);
num5 >>= 8;
}
num4 += num3;
num3 = 4;
}
return array;
}
// Token: 0x06000024 RID: 36 RVA: 0x00002914 File Offset: 0x00000B14
public BigInteger.Sign Compare(BigInteger bi)
{
return BigInteger.Kernel.Compare(this, bi);
}
// Token: 0x06000025 RID: 37 RVA: 0x00002920 File Offset: 0x00000B20
[CLSCompliant(false)]
public string ToString(uint radix)
{
return this.ToString(radix, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
// Token: 0x06000026 RID: 38 RVA: 0x00002930 File Offset: 0x00000B30
[CLSCompliant(false)]
public string ToString(uint radix, string characterSet)
{
if ((long)characterSet.Length < (long)((ulong)radix))
{
throw new ArgumentException("charSet length less than radix", "characterSet");
}
if (radix == 1U)
{
throw new ArgumentException("There is no such thing as radix one notation", "radix");
}
if (this == 0U)
{
return "0";
}
if (this == 1U)
{
return "1";
}
string text = string.Empty;
BigInteger bigInteger = new BigInteger(this);
while (bigInteger != 0U)
{
uint num = BigInteger.Kernel.SingleByteDivideInPlace(bigInteger, radix);
text = characterSet[(int)num] + text;
}
return text;
}
// Token: 0x06000027 RID: 39 RVA: 0x000029D0 File Offset: 0x00000BD0
private void Normalize()
{
while (this.length > 0U && this.data[(int)((UIntPtr)(this.length - 1U))] == 0U)
{
this.length -= 1U;
}
if (this.length == 0U)
{
this.length += 1U;
}
}
// Token: 0x06000028 RID: 40 RVA: 0x00002A2C File Offset: 0x00000C2C
public void Clear()
{
int num = 0;
while ((long)num < (long)((ulong)this.length))
{
this.data[num] = 0U;
num++;
}
}
// Token: 0x06000029 RID: 41 RVA: 0x00002A5C File Offset: 0x00000C5C
public override int GetHashCode()
{
uint num = 0U;
for (uint num2 = 0U; num2 < this.length; num2 += 1U)
{
num ^= this.data[(int)((UIntPtr)num2)];
}
return (int)num;
}
// Token: 0x0600002A RID: 42 RVA: 0x00002A90 File Offset: 0x00000C90
public override string ToString()
{
return this.ToString(10U);
}
// Token: 0x0600002B RID: 43 RVA: 0x00002A9C File Offset: 0x00000C9C
public override bool Equals(object o)
{
if (o == null)
{
return false;
}
if (o is int)
{
return (int)o >= 0 && this == (uint)o;
}
BigInteger bigInteger = o as BigInteger;
return !(bigInteger == null) && BigInteger.Kernel.Compare(this, bigInteger) == BigInteger.Sign.Zero;
}
// Token: 0x0600002C RID: 44 RVA: 0x00002AF8 File Offset: 0x00000CF8
public BigInteger GCD(BigInteger bi)
{
return BigInteger.Kernel.gcd(this, bi);
}
// Token: 0x0600002D RID: 45 RVA: 0x00002B04 File Offset: 0x00000D04
public BigInteger ModInverse(BigInteger modulus)
{
return BigInteger.Kernel.modInverse(this, modulus);
}
// Token: 0x0600002E RID: 46 RVA: 0x00002B10 File Offset: 0x00000D10
public BigInteger ModPow(BigInteger exp, BigInteger n)
{
BigInteger.ModulusRing modulusRing = new BigInteger.ModulusRing(n);
return modulusRing.Pow(this, exp);
}
// Token: 0x0600002F RID: 47 RVA: 0x00002B2C File Offset: 0x00000D2C
public bool IsProbablePrime()
{
if (this <= BigInteger.smallPrimes[BigInteger.smallPrimes.Length - 1])
{
for (int i = 0; i < BigInteger.smallPrimes.Length; i++)
{
if (this == BigInteger.smallPrimes[i])
{
return true;
}
}
return false;
}
for (int j = 0; j < BigInteger.smallPrimes.Length; j++)
{
if (this % BigInteger.smallPrimes[j] == 0U)
{
return false;
}
}
return PrimalityTests.Test(this, ConfidenceFactor.Medium);
}
// Token: 0x06000030 RID: 48 RVA: 0x00002BBC File Offset: 0x00000DBC
public static BigInteger NextHighestPrime(BigInteger bi)
{
NextPrimeFinder nextPrimeFinder = new NextPrimeFinder();
return nextPrimeFinder.GenerateNewPrime(0, bi);
}
// Token: 0x06000031 RID: 49 RVA: 0x00002BD8 File Offset: 0x00000DD8
public static BigInteger GeneratePseudoPrime(int bits)
{
SequentialSearchPrimeGeneratorBase sequentialSearchPrimeGeneratorBase = new SequentialSearchPrimeGeneratorBase();
return sequentialSearchPrimeGeneratorBase.GenerateNewPrime(bits);
}
// Token: 0x06000032 RID: 50 RVA: 0x00002BF4 File Offset: 0x00000DF4
public void Incr2()
{
int num = 0;
this.data[0] += 2U;
if (this.data[0] < 2U)
{
this.data[++num] += 1U;
while (this.data[num++] == 0U)
{
this.data[num] += 1U;
}
if (this.length == (uint)num)
{
this.length += 1U;
}
}
}
// Token: 0x06000033 RID: 51 RVA: 0x00002C78 File Offset: 0x00000E78
[CLSCompliant(false)]
public static implicit operator BigInteger(uint value)
{
return new BigInteger(value);
}
// Token: 0x06000034 RID: 52 RVA: 0x00002C80 File Offset: 0x00000E80
public static implicit operator BigInteger(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("value");
}
return new BigInteger((uint)value);
}
// Token: 0x06000035 RID: 53 RVA: 0x00002C9C File Offset: 0x00000E9C
[CLSCompliant(false)]
public static implicit operator BigInteger(ulong value)
{
return new BigInteger(value);
}
// Token: 0x06000036 RID: 54 RVA: 0x00002CA4 File Offset: 0x00000EA4
public static BigInteger operator +(BigInteger bi1, BigInteger bi2)
{
if (bi1 == 0U)
{
return new BigInteger(bi2);
}
if (bi2 == 0U)
{
return new BigInteger(bi1);
}
return BigInteger.Kernel.AddSameSign(bi1, bi2);
}
// Token: 0x06000037 RID: 55 RVA: 0x00002CD4 File Offset: 0x00000ED4
public static BigInteger operator -(BigInteger bi1, BigInteger bi2)
{
if (bi2 == 0U)
{
return new BigInteger(bi1);
}
if (bi1 == 0U)
{
throw new ArithmeticException("Operation would return a negative value");
}
BigInteger.Sign sign = BigInteger.Kernel.Compare(bi1, bi2);
switch (sign + 1)
{
case BigInteger.Sign.Zero:
throw new ArithmeticException("Operation would return a negative value");
case BigInteger.Sign.Positive:
return 0;
case (BigInteger.Sign)2:
return BigInteger.Kernel.Subtract(bi1, bi2);
default:
throw new Exception();
}
}
// Token: 0x06000038 RID: 56 RVA: 0x00002D4C File Offset: 0x00000F4C
public static int operator %(BigInteger bi, int i)
{
if (i > 0)
{
return (int)BigInteger.Kernel.DwordMod(bi, (uint)i);
}
return (int)(-(int)BigInteger.Kernel.DwordMod(bi, (uint)(-(uint)i)));
}
// Token: 0x06000039 RID: 57 RVA: 0x00002D68 File Offset: 0x00000F68
[CLSCompliant(false)]
public static uint operator %(BigInteger bi, uint ui)
{
return BigInteger.Kernel.DwordMod(bi, ui);
}
// Token: 0x0600003A RID: 58 RVA: 0x00002D74 File Offset: 0x00000F74
public static BigInteger operator %(BigInteger bi1, BigInteger bi2)
{
return BigInteger.Kernel.multiByteDivide(bi1, bi2)[1];
}
// Token: 0x0600003B RID: 59 RVA: 0x00002D80 File Offset: 0x00000F80
public static BigInteger operator /(BigInteger bi, int i)
{
if (i > 0)
{
return BigInteger.Kernel.DwordDiv(bi, (uint)i);
}
throw new ArithmeticException("Operation would return a negative value");
}
// Token: 0x0600003C RID: 60 RVA: 0x00002D9C File Offset: 0x00000F9C
public static BigInteger operator /(BigInteger bi1, BigInteger bi2)
{
return BigInteger.Kernel.multiByteDivide(bi1, bi2)[0];
}
// Token: 0x0600003D RID: 61 RVA: 0x00002DA8 File Offset: 0x00000FA8
public static BigInteger operator *(BigInteger bi1, BigInteger bi2)
{
if (bi1 == 0U || bi2 == 0U)
{
return 0;
}
if ((long)bi1.data.Length < (long)((ulong)bi1.length))
{
throw new IndexOutOfRangeException("bi1 out of range");
}
if ((long)bi2.data.Length < (long)((ulong)bi2.length))
{
throw new IndexOutOfRangeException("bi2 out of range");
}
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, bi1.length + bi2.length);
BigInteger.Kernel.Multiply(bi1.data, 0U, bi1.length, bi2.data, 0U, bi2.length, bigInteger.data, 0U);
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x0600003E RID: 62 RVA: 0x00002E58 File Offset: 0x00001058
public static BigInteger operator *(BigInteger bi, int i)
{
if (i < 0)
{
throw new ArithmeticException("Operation would return a negative value");
}
if (i == 0)
{
return 0;
}
if (i == 1)
{
return new BigInteger(bi);
}
return BigInteger.Kernel.MultiplyByDword(bi, (uint)i);
}
// Token: 0x0600003F RID: 63 RVA: 0x00002E9C File Offset: 0x0000109C
public static BigInteger operator <<(BigInteger bi1, int shiftVal)
{
return BigInteger.Kernel.LeftShift(bi1, shiftVal);
}
// Token: 0x06000040 RID: 64 RVA: 0x00002EA8 File Offset: 0x000010A8
public static BigInteger operator >>(BigInteger bi1, int shiftVal)
{
return BigInteger.Kernel.RightShift(bi1, shiftVal);
}
// Token: 0x06000041 RID: 65 RVA: 0x00002EB4 File Offset: 0x000010B4
[CLSCompliant(false)]
public static bool operator ==(BigInteger bi1, uint ui)
{
if (bi1.length != 1U)
{
bi1.Normalize();
}
return bi1.length == 1U && bi1.data[0] == ui;
}
// Token: 0x06000042 RID: 66 RVA: 0x00002EF0 File Offset: 0x000010F0
[CLSCompliant(false)]
public static bool operator !=(BigInteger bi1, uint ui)
{
if (bi1.length != 1U)
{
bi1.Normalize();
}
return bi1.length != 1U || bi1.data[0] != ui;
}
// Token: 0x06000043 RID: 67 RVA: 0x00002F24 File Offset: 0x00001124
public static bool operator ==(BigInteger bi1, BigInteger bi2)
{
return bi1 == bi2 || (!(null == bi1) && !(null == bi2) && BigInteger.Kernel.Compare(bi1, bi2) == BigInteger.Sign.Zero);
}
// Token: 0x06000044 RID: 68 RVA: 0x00002F54 File Offset: 0x00001154
public static bool operator !=(BigInteger bi1, BigInteger bi2)
{
return bi1 != bi2 && (null == bi1 || null == bi2 || BigInteger.Kernel.Compare(bi1, bi2) != BigInteger.Sign.Zero);
}
// Token: 0x06000045 RID: 69 RVA: 0x00002F94 File Offset: 0x00001194
public static bool operator >(BigInteger bi1, BigInteger bi2)
{
return BigInteger.Kernel.Compare(bi1, bi2) > BigInteger.Sign.Zero;
}
// Token: 0x06000046 RID: 70 RVA: 0x00002FA0 File Offset: 0x000011A0
public static bool operator <(BigInteger bi1, BigInteger bi2)
{
return BigInteger.Kernel.Compare(bi1, bi2) < BigInteger.Sign.Zero;
}
// Token: 0x06000047 RID: 71 RVA: 0x00002FAC File Offset: 0x000011AC
public static bool operator >=(BigInteger bi1, BigInteger bi2)
{
return BigInteger.Kernel.Compare(bi1, bi2) >= BigInteger.Sign.Zero;
}
// Token: 0x06000048 RID: 72 RVA: 0x00002FBC File Offset: 0x000011BC
public static bool operator <=(BigInteger bi1, BigInteger bi2)
{
return BigInteger.Kernel.Compare(bi1, bi2) <= BigInteger.Sign.Zero;
}
// Token: 0x0400001E RID: 30
private const uint DEFAULT_LEN = 20U;
// Token: 0x0400001F RID: 31
private const string WouldReturnNegVal = "Operation would return a negative value";
// Token: 0x04000020 RID: 32
private uint length = 1U;
// Token: 0x04000021 RID: 33
private uint[] data;
// Token: 0x04000022 RID: 34
internal static readonly uint[] smallPrimes = new uint[]
{
2U, 3U, 5U, 7U, 11U, 13U, 17U, 19U, 23U, 29U,
31U, 37U, 41U, 43U, 47U, 53U, 59U, 61U, 67U, 71U,
73U, 79U, 83U, 89U, 97U, 101U, 103U, 107U, 109U, 113U,
127U, 131U, 137U, 139U, 149U, 151U, 157U, 163U, 167U, 173U,
179U, 181U, 191U, 193U, 197U, 199U, 211U, 223U, 227U, 229U,
233U, 239U, 241U, 251U, 257U, 263U, 269U, 271U, 277U, 281U,
283U, 293U, 307U, 311U, 313U, 317U, 331U, 337U, 347U, 349U,
353U, 359U, 367U, 373U, 379U, 383U, 389U, 397U, 401U, 409U,
419U, 421U, 431U, 433U, 439U, 443U, 449U, 457U, 461U, 463U,
467U, 479U, 487U, 491U, 499U, 503U, 509U, 521U, 523U, 541U,
547U, 557U, 563U, 569U, 571U, 577U, 587U, 593U, 599U, 601U,
607U, 613U, 617U, 619U, 631U, 641U, 643U, 647U, 653U, 659U,
661U, 673U, 677U, 683U, 691U, 701U, 709U, 719U, 727U, 733U,
739U, 743U, 751U, 757U, 761U, 769U, 773U, 787U, 797U, 809U,
811U, 821U, 823U, 827U, 829U, 839U, 853U, 857U, 859U, 863U,
877U, 881U, 883U, 887U, 907U, 911U, 919U, 929U, 937U, 941U,
947U, 953U, 967U, 971U, 977U, 983U, 991U, 997U, 1009U, 1013U,
1019U, 1021U, 1031U, 1033U, 1039U, 1049U, 1051U, 1061U, 1063U, 1069U,
1087U, 1091U, 1093U, 1097U, 1103U, 1109U, 1117U, 1123U, 1129U, 1151U,
1153U, 1163U, 1171U, 1181U, 1187U, 1193U, 1201U, 1213U, 1217U, 1223U,
1229U, 1231U, 1237U, 1249U, 1259U, 1277U, 1279U, 1283U, 1289U, 1291U,
1297U, 1301U, 1303U, 1307U, 1319U, 1321U, 1327U, 1361U, 1367U, 1373U,
1381U, 1399U, 1409U, 1423U, 1427U, 1429U, 1433U, 1439U, 1447U, 1451U,
1453U, 1459U, 1471U, 1481U, 1483U, 1487U, 1489U, 1493U, 1499U, 1511U,
1523U, 1531U, 1543U, 1549U, 1553U, 1559U, 1567U, 1571U, 1579U, 1583U,
1597U, 1601U, 1607U, 1609U, 1613U, 1619U, 1621U, 1627U, 1637U, 1657U,
1663U, 1667U, 1669U, 1693U, 1697U, 1699U, 1709U, 1721U, 1723U, 1733U,
1741U, 1747U, 1753U, 1759U, 1777U, 1783U, 1787U, 1789U, 1801U, 1811U,
1823U, 1831U, 1847U, 1861U, 1867U, 1871U, 1873U, 1877U, 1879U, 1889U,
1901U, 1907U, 1913U, 1931U, 1933U, 1949U, 1951U, 1973U, 1979U, 1987U,
1993U, 1997U, 1999U, 2003U, 2011U, 2017U, 2027U, 2029U, 2039U, 2053U,
2063U, 2069U, 2081U, 2083U, 2087U, 2089U, 2099U, 2111U, 2113U, 2129U,
2131U, 2137U, 2141U, 2143U, 2153U, 2161U, 2179U, 2203U, 2207U, 2213U,
2221U, 2237U, 2239U, 2243U, 2251U, 2267U, 2269U, 2273U, 2281U, 2287U,
2293U, 2297U, 2309U, 2311U, 2333U, 2339U, 2341U, 2347U, 2351U, 2357U,
2371U, 2377U, 2381U, 2383U, 2389U, 2393U, 2399U, 2411U, 2417U, 2423U,
2437U, 2441U, 2447U, 2459U, 2467U, 2473U, 2477U, 2503U, 2521U, 2531U,
2539U, 2543U, 2549U, 2551U, 2557U, 2579U, 2591U, 2593U, 2609U, 2617U,
2621U, 2633U, 2647U, 2657U, 2659U, 2663U, 2671U, 2677U, 2683U, 2687U,
2689U, 2693U, 2699U, 2707U, 2711U, 2713U, 2719U, 2729U, 2731U, 2741U,
2749U, 2753U, 2767U, 2777U, 2789U, 2791U, 2797U, 2801U, 2803U, 2819U,
2833U, 2837U, 2843U, 2851U, 2857U, 2861U, 2879U, 2887U, 2897U, 2903U,
2909U, 2917U, 2927U, 2939U, 2953U, 2957U, 2963U, 2969U, 2971U, 2999U,
3001U, 3011U, 3019U, 3023U, 3037U, 3041U, 3049U, 3061U, 3067U, 3079U,
3083U, 3089U, 3109U, 3119U, 3121U, 3137U, 3163U, 3167U, 3169U, 3181U,
3187U, 3191U, 3203U, 3209U, 3217U, 3221U, 3229U, 3251U, 3253U, 3257U,
3259U, 3271U, 3299U, 3301U, 3307U, 3313U, 3319U, 3323U, 3329U, 3331U,
3343U, 3347U, 3359U, 3361U, 3371U, 3373U, 3389U, 3391U, 3407U, 3413U,
3433U, 3449U, 3457U, 3461U, 3463U, 3467U, 3469U, 3491U, 3499U, 3511U,
3517U, 3527U, 3529U, 3533U, 3539U, 3541U, 3547U, 3557U, 3559U, 3571U,
3581U, 3583U, 3593U, 3607U, 3613U, 3617U, 3623U, 3631U, 3637U, 3643U,
3659U, 3671U, 3673U, 3677U, 3691U, 3697U, 3701U, 3709U, 3719U, 3727U,
3733U, 3739U, 3761U, 3767U, 3769U, 3779U, 3793U, 3797U, 3803U, 3821U,
3823U, 3833U, 3847U, 3851U, 3853U, 3863U, 3877U, 3881U, 3889U, 3907U,
3911U, 3917U, 3919U, 3923U, 3929U, 3931U, 3943U, 3947U, 3967U, 3989U,
4001U, 4003U, 4007U, 4013U, 4019U, 4021U, 4027U, 4049U, 4051U, 4057U,
4073U, 4079U, 4091U, 4093U, 4099U, 4111U, 4127U, 4129U, 4133U, 4139U,
4153U, 4157U, 4159U, 4177U, 4201U, 4211U, 4217U, 4219U, 4229U, 4231U,
4241U, 4243U, 4253U, 4259U, 4261U, 4271U, 4273U, 4283U, 4289U, 4297U,
4327U, 4337U, 4339U, 4349U, 4357U, 4363U, 4373U, 4391U, 4397U, 4409U,
4421U, 4423U, 4441U, 4447U, 4451U, 4457U, 4463U, 4481U, 4483U, 4493U,
4507U, 4513U, 4517U, 4519U, 4523U, 4547U, 4549U, 4561U, 4567U, 4583U,
4591U, 4597U, 4603U, 4621U, 4637U, 4639U, 4643U, 4649U, 4651U, 4657U,
4663U, 4673U, 4679U, 4691U, 4703U, 4721U, 4723U, 4729U, 4733U, 4751U,
4759U, 4783U, 4787U, 4789U, 4793U, 4799U, 4801U, 4813U, 4817U, 4831U,
4861U, 4871U, 4877U, 4889U, 4903U, 4909U, 4919U, 4931U, 4933U, 4937U,
4943U, 4951U, 4957U, 4967U, 4969U, 4973U, 4987U, 4993U, 4999U, 5003U,
5009U, 5011U, 5021U, 5023U, 5039U, 5051U, 5059U, 5077U, 5081U, 5087U,
5099U, 5101U, 5107U, 5113U, 5119U, 5147U, 5153U, 5167U, 5171U, 5179U,
5189U, 5197U, 5209U, 5227U, 5231U, 5233U, 5237U, 5261U, 5273U, 5279U,
5281U, 5297U, 5303U, 5309U, 5323U, 5333U, 5347U, 5351U, 5381U, 5387U,
5393U, 5399U, 5407U, 5413U, 5417U, 5419U, 5431U, 5437U, 5441U, 5443U,
5449U, 5471U, 5477U, 5479U, 5483U, 5501U, 5503U, 5507U, 5519U, 5521U,
5527U, 5531U, 5557U, 5563U, 5569U, 5573U, 5581U, 5591U, 5623U, 5639U,
5641U, 5647U, 5651U, 5653U, 5657U, 5659U, 5669U, 5683U, 5689U, 5693U,
5701U, 5711U, 5717U, 5737U, 5741U, 5743U, 5749U, 5779U, 5783U, 5791U,
5801U, 5807U, 5813U, 5821U, 5827U, 5839U, 5843U, 5849U, 5851U, 5857U,
5861U, 5867U, 5869U, 5879U, 5881U, 5897U, 5903U, 5923U, 5927U, 5939U,
5953U, 5981U, 5987U
};
// Token: 0x04000023 RID: 35
private static RandomNumberGenerator rng;
// Token: 0x02000005 RID: 5
public enum Sign
{
// Token: 0x04000025 RID: 37
Negative = -1,
// Token: 0x04000026 RID: 38
Zero,
// Token: 0x04000027 RID: 39
Positive
}
// Token: 0x02000006 RID: 6
public sealed class ModulusRing
{
// Token: 0x06000049 RID: 73 RVA: 0x00002FCC File Offset: 0x000011CC
public ModulusRing(BigInteger modulus)
{
this.mod = modulus;
uint num = this.mod.length << 1;
this.constant = new BigInteger(BigInteger.Sign.Positive, num + 1U);
this.constant.data[(int)((UIntPtr)num)] = 1U;
this.constant /= this.mod;
}
// Token: 0x0600004A RID: 74 RVA: 0x0000302C File Offset: 0x0000122C
public void BarrettReduction(BigInteger x)
{
BigInteger bigInteger = this.mod;
uint length = bigInteger.length;
uint num = length + 1U;
uint num2 = length - 1U;
if (x.length < length)
{
return;
}
if ((long)x.data.Length < (long)((ulong)x.length))
{
throw new IndexOutOfRangeException("x out of range");
}
BigInteger bigInteger2 = new BigInteger(BigInteger.Sign.Positive, x.length - num2 + this.constant.length);
BigInteger.Kernel.Multiply(x.data, num2, x.length - num2, this.constant.data, 0U, this.constant.length, bigInteger2.data, 0U);
uint num3 = ((x.length <= num) ? x.length : num);
x.length = num3;
x.Normalize();
BigInteger bigInteger3 = new BigInteger(BigInteger.Sign.Positive, num);
BigInteger.Kernel.MultiplyMod2p32pmod(bigInteger2.data, (int)num, (int)(bigInteger2.length - num), bigInteger.data, 0, (int)bigInteger.length, bigInteger3.data, 0, (int)num);
bigInteger3.Normalize();
if (bigInteger3 <= x)
{
BigInteger.Kernel.MinusEq(x, bigInteger3);
}
else
{
BigInteger bigInteger4 = new BigInteger(BigInteger.Sign.Positive, num + 1U);
bigInteger4.data[(int)((UIntPtr)num)] = 1U;
BigInteger.Kernel.MinusEq(bigInteger4, bigInteger3);
BigInteger.Kernel.PlusEq(x, bigInteger4);
}
while (x >= bigInteger)
{
BigInteger.Kernel.MinusEq(x, bigInteger);
}
}
// Token: 0x0600004B RID: 75 RVA: 0x00003188 File Offset: 0x00001388
public BigInteger Multiply(BigInteger a, BigInteger b)
{
if (a == 0U || b == 0U)
{
return 0;
}
if (a > this.mod)
{
a %= this.mod;
}
if (b > this.mod)
{
b %= this.mod;
}
BigInteger bigInteger = new BigInteger(a * b);
this.BarrettReduction(bigInteger);
return bigInteger;
}
// Token: 0x0600004C RID: 76 RVA: 0x00003208 File Offset: 0x00001408
public BigInteger Difference(BigInteger a, BigInteger b)
{
BigInteger.Sign sign = BigInteger.Kernel.Compare(a, b);
BigInteger.Sign sign2 = sign;
BigInteger bigInteger;
switch (sign2 + 1)
{
case BigInteger.Sign.Zero:
bigInteger = b - a;
break;
case BigInteger.Sign.Positive:
return 0;
case (BigInteger.Sign)2:
bigInteger = a - b;
break;
default:
throw new Exception();
}
if (bigInteger >= this.mod)
{
if (bigInteger.length >= this.mod.length << 1)
{
bigInteger %= this.mod;
}
else
{
this.BarrettReduction(bigInteger);
}
}
if (sign == BigInteger.Sign.Negative)
{
bigInteger = this.mod - bigInteger;
}
return bigInteger;
}
// Token: 0x0600004D RID: 77 RVA: 0x000032B8 File Offset: 0x000014B8
public BigInteger Pow(BigInteger a, BigInteger k)
{
BigInteger bigInteger = new BigInteger(1U);
if (k == 0U)
{
return bigInteger;
}
BigInteger bigInteger2 = a;
if (k.TestBit(0))
{
bigInteger = a;
}
for (int i = 1; i < k.BitCount(); i++)
{
bigInteger2 = this.Multiply(bigInteger2, bigInteger2);
if (k.TestBit(i))
{
bigInteger = this.Multiply(bigInteger2, bigInteger);
}
}
return bigInteger;
}
// Token: 0x0600004E RID: 78 RVA: 0x00003320 File Offset: 0x00001520
[CLSCompliant(false)]
public BigInteger Pow(uint b, BigInteger exp)
{
return this.Pow(new BigInteger(b), exp);
}
// Token: 0x04000028 RID: 40
private BigInteger mod;
// Token: 0x04000029 RID: 41
private BigInteger constant;
}
// Token: 0x02000007 RID: 7
internal sealed class Montgomery
{
// Token: 0x0600004F RID: 79 RVA: 0x00003330 File Offset: 0x00001530
private Montgomery()
{
}
// Token: 0x06000050 RID: 80 RVA: 0x00003338 File Offset: 0x00001538
public static uint Inverse(uint n)
{
uint num = n;
uint num2;
while ((num2 = n * num) != 1U)
{
num *= 2U - num2;
}
return (uint)(-(uint)((ulong)num));
}
// Token: 0x06000051 RID: 81 RVA: 0x00003364 File Offset: 0x00001564
public static BigInteger ToMont(BigInteger n, BigInteger m)
{
n.Normalize();
m.Normalize();
n <<= (int)(m.length * 32U);
n %= m;
return n;
}
// Token: 0x06000052 RID: 82 RVA: 0x00003390 File Offset: 0x00001590
public unsafe static BigInteger Reduce(BigInteger n, BigInteger m, uint mPrime)
{
fixed (uint* ptr = (ref n.data != null && n.data.Length != 0 ? ref n.data[0] : ref *null), ptr2 = (ref m.data != null && m.data.Length != 0 ? ref m.data[0] : ref *null))
{
for (uint num = 0U; num < m.length; num += 1U)
{
uint num2 = *ptr * mPrime;
uint* ptr3 = ptr2;
uint* ptr4 = ptr;
uint* ptr5 = ptr;
ulong num3 = (ulong)num2 * (ulong)(*(ptr3++)) + (ulong)(*(ptr4++));
num3 >>= 32;
uint num4;
for (num4 = 1U; num4 < m.length; num4 += 1U)
{
num3 += (ulong)num2 * (ulong)(*(ptr3++)) + (ulong)(*(ptr4++));
*(ptr5++) = (uint)num3;
num3 >>= 32;
}
while (num4 < n.length)
{
num3 += (ulong)(*(ptr4++));
*(ptr5++) = (uint)num3;
num3 >>= 32;
if (num3 == 0UL)
{
num4 += 1U;
break;
}
num4 += 1U;
}
while (num4 < n.length)
{
*(ptr5++) = *(ptr4++);
num4 += 1U;
}
*(ptr5++) = (uint)num3;
}
while (n.length > 1U && ptr[n.length - 1U] == 0U)
{
n.length -= 1U;
}
}
if (n >= m)
{
BigInteger.Kernel.MinusEq(n, m);
}
return n;
}
}
// Token: 0x02000008 RID: 8
private sealed class Kernel
{
// Token: 0x06000054 RID: 84 RVA: 0x00003564 File Offset: 0x00001764
public static BigInteger AddSameSign(BigInteger bi1, BigInteger bi2)
{
uint num = 0U;
uint[] array;
uint num2;
uint[] array2;
uint num3;
if (bi1.length < bi2.length)
{
array = bi2.data;
num2 = bi2.length;
array2 = bi1.data;
num3 = bi1.length;
}
else
{
array = bi1.data;
num2 = bi1.length;
array2 = bi2.data;
num3 = bi2.length;
}
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, num2 + 1U);
uint[] data = bigInteger.data;
ulong num4 = 0UL;
do
{
num4 = (ulong)array[(int)((UIntPtr)num)] + (ulong)array2[(int)((UIntPtr)num)] + num4;
data[(int)((UIntPtr)num)] = (uint)num4;
num4 >>= 32;
}
while ((num += 1U) < num3);
bool flag = num4 != 0UL;
if (flag)
{
if (num < num2)
{
do
{
flag = (data[(int)((UIntPtr)num)] = array[(int)((UIntPtr)num)] + 1U) == 0U;
}
while ((num += 1U) < num2 && flag);
}
if (flag)
{
data[(int)((UIntPtr)num)] = 1U;
bigInteger.length = num + 1U;
return bigInteger;
}
}
if (num < num2)
{
do
{
data[(int)((UIntPtr)num)] = array[(int)((UIntPtr)num)];
}
while ((num += 1U) < num2);
}
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x06000055 RID: 85 RVA: 0x00003698 File Offset: 0x00001898
public static BigInteger Subtract(BigInteger big, BigInteger small)
{
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, big.length);
uint[] data = bigInteger.data;
uint[] data2 = big.data;
uint[] data3 = small.data;
uint num = 0U;
uint num2 = 0U;
do
{
uint num3 = data3[(int)((UIntPtr)num)];
if (((num3 += num2) < num2) | ((data[(int)((UIntPtr)num)] = data2[(int)((UIntPtr)num)] - num3) > ~num3))
{
num2 = 1U;
}
else
{
num2 = 0U;
}
}
while ((num += 1U) < small.length);
if (num != big.length)
{
if (num2 == 1U)
{
do
{
data[(int)((UIntPtr)num)] = data2[(int)((UIntPtr)num)] - 1U;
}
while (data2[(int)((UIntPtr)(num++))] == 0U && num < big.length);
if (num == big.length)
{
goto IL_E5;
}
}
do
{
data[(int)((UIntPtr)num)] = data2[(int)((UIntPtr)num)];
}
while ((num += 1U) < big.length);
}
IL_E5:
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x06000056 RID: 86 RVA: 0x00003794 File Offset: 0x00001994
public static void MinusEq(BigInteger big, BigInteger small)
{
uint[] data = big.data;
uint[] data2 = small.data;
uint num = 0U;
uint num2 = 0U;
do
{
uint num3 = data2[(int)((UIntPtr)num)];
if (((num3 += num2) < num2) | ((data[(int)((UIntPtr)num)] -= num3) > ~num3))
{
num2 = 1U;
}
else
{
num2 = 0U;
}
}
while ((num += 1U) < small.length);
if (num != big.length)
{
if (num2 == 1U)
{
do
{
data[(int)((UIntPtr)num)] -= 1U;
}
while (data[(int)((UIntPtr)(num++))] == 0U && num < big.length);
}
}
while (big.length > 0U && big.data[(int)((UIntPtr)(big.length - 1U))] == 0U)
{
big.length -= 1U;
}
if (big.length == 0U)
{
big.length += 1U;
}
}
// Token: 0x06000057 RID: 87 RVA: 0x00003888 File Offset: 0x00001A88
public static void PlusEq(BigInteger bi1, BigInteger bi2)
{
uint num = 0U;
bool flag = false;
uint[] array;
uint num2;
uint[] array2;
uint num3;
if (bi1.length < bi2.length)
{
flag = true;
array = bi2.data;
num2 = bi2.length;
array2 = bi1.data;
num3 = bi1.length;
}
else
{
array = bi1.data;
num2 = bi1.length;
array2 = bi2.data;
num3 = bi2.length;
}
uint[] data = bi1.data;
ulong num4 = 0UL;
do
{
num4 += (ulong)array[(int)((UIntPtr)num)] + (ulong)array2[(int)((UIntPtr)num)];
data[(int)((UIntPtr)num)] = (uint)num4;
num4 >>= 32;
}
while ((num += 1U) < num3);
bool flag2 = num4 != 0UL;
if (flag2)
{
if (num < num2)
{
do
{
flag2 = (data[(int)((UIntPtr)num)] = array[(int)((UIntPtr)num)] + 1U) == 0U;
}
while ((num += 1U) < num2 && flag2);
}
if (flag2)
{
data[(int)((UIntPtr)num)] = 1U;
bi1.length = num + 1U;
return;
}
}
if (flag && num < num2 - 1U)
{
do
{
data[(int)((UIntPtr)num)] = array[(int)((UIntPtr)num)];
}
while ((num += 1U) < num2);
}
bi1.length = num2 + 1U;
bi1.Normalize();
}
// Token: 0x06000058 RID: 88 RVA: 0x000039C0 File Offset: 0x00001BC0
public static BigInteger.Sign Compare(BigInteger bi1, BigInteger bi2)
{
uint num = bi1.length;
uint num2 = bi2.length;
while (num > 0U && bi1.data[(int)((UIntPtr)(num - 1U))] == 0U)
{
num -= 1U;
}
while (num2 > 0U && bi2.data[(int)((UIntPtr)(num2 - 1U))] == 0U)
{
num2 -= 1U;
}
if (num == 0U && num2 == 0U)
{
return BigInteger.Sign.Zero;
}
if (num < num2)
{
return BigInteger.Sign.Negative;
}
if (num > num2)
{
return BigInteger.Sign.Positive;
}
uint num3 = num - 1U;
while (num3 != 0U && bi1.data[(int)((UIntPtr)num3)] == bi2.data[(int)((UIntPtr)num3)])
{
num3 -= 1U;
}
if (bi1.data[(int)((UIntPtr)num3)] < bi2.data[(int)((UIntPtr)num3)])
{
return BigInteger.Sign.Negative;
}
if (bi1.data[(int)((UIntPtr)num3)] > bi2.data[(int)((UIntPtr)num3)])
{
return BigInteger.Sign.Positive;
}
return BigInteger.Sign.Zero;
}
// Token: 0x06000059 RID: 89 RVA: 0x00003A98 File Offset: 0x00001C98
public static uint SingleByteDivideInPlace(BigInteger n, uint d)
{
ulong num = 0UL;
uint length = n.length;
while (length-- > 0U)
{
num <<= 32;
num |= (ulong)n.data[(int)((UIntPtr)length)];
n.data[(int)((UIntPtr)length)] = (uint)(num / (ulong)d);
num %= (ulong)d;
}
n.Normalize();
return (uint)num;
}
// Token: 0x0600005A RID: 90 RVA: 0x00003AEC File Offset: 0x00001CEC
public static uint DwordMod(BigInteger n, uint d)
{
ulong num = 0UL;
uint length = n.length;
while (length-- > 0U)
{
num <<= 32;
num |= (ulong)n.data[(int)((UIntPtr)length)];
num %= (ulong)d;
}
return (uint)num;
}
// Token: 0x0600005B RID: 91 RVA: 0x00003B2C File Offset: 0x00001D2C
public static BigInteger DwordDiv(BigInteger n, uint d)
{
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, n.length);
ulong num = 0UL;
uint length = n.length;
while (length-- > 0U)
{
num <<= 32;
num |= (ulong)n.data[(int)((UIntPtr)length)];
bigInteger.data[(int)((UIntPtr)length)] = (uint)(num / (ulong)d);
num %= (ulong)d;
}
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x0600005C RID: 92 RVA: 0x00003B8C File Offset: 0x00001D8C
public static BigInteger[] DwordDivMod(BigInteger n, uint d)
{
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, n.length);
ulong num = 0UL;
uint length = n.length;
while (length-- > 0U)
{
num <<= 32;
num |= (ulong)n.data[(int)((UIntPtr)length)];
bigInteger.data[(int)((UIntPtr)length)] = (uint)(num / (ulong)d);
num %= (ulong)d;
}
bigInteger.Normalize();
BigInteger bigInteger2 = (uint)num;
return new BigInteger[] { bigInteger, bigInteger2 };
}
// Token: 0x0600005D RID: 93 RVA: 0x00003C04 File Offset: 0x00001E04
public static BigInteger[] multiByteDivide(BigInteger bi1, BigInteger bi2)
{
if (BigInteger.Kernel.Compare(bi1, bi2) == BigInteger.Sign.Negative)
{
return new BigInteger[]
{
0,
new BigInteger(bi1)
};
}
bi1.Normalize();
bi2.Normalize();
if (bi2.length == 1U)
{
return BigInteger.Kernel.DwordDivMod(bi1, bi2.data[0]);
}
uint num = bi1.length + 1U;
int num2 = (int)(bi2.length + 1U);
uint num3 = 2147483648U;
uint num4 = bi2.data[(int)((UIntPtr)(bi2.length - 1U))];
int num5 = 0;
int num6 = (int)(bi1.length - bi2.length);
while (num3 != 0U && (num4 & num3) == 0U)
{
num5++;
num3 >>= 1;
}
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, bi1.length - bi2.length + 1U);
BigInteger bigInteger2 = bi1 << num5;
uint[] data = bigInteger2.data;
bi2 <<= num5;
int i = (int)(num - bi2.length);
int num7 = (int)(num - 1U);
uint num8 = bi2.data[(int)((UIntPtr)(bi2.length - 1U))];
ulong num9 = (ulong)bi2.data[(int)((UIntPtr)(bi2.length - 2U))];
while (i > 0)
{
ulong num10 = ((ulong)data[num7] << 32) + (ulong)data[num7 - 1];
ulong num11 = num10 / (ulong)num8;
ulong num12 = num10 % (ulong)num8;
while (num11 == 4294967296UL || num11 * num9 > (num12 << 32) + (ulong)data[num7 - 2])
{
num11 -= 1UL;
num12 += (ulong)num8;
if (num12 >= 4294967296UL)
{
break;
}
}
uint num13 = 0U;
int num14 = num7 - num2 + 1;
ulong num15 = 0UL;
uint num16 = (uint)num11;
do
{
num15 += (ulong)bi2.data[(int)((UIntPtr)num13)] * (ulong)num16;
uint num17 = data[num14];
data[num14] -= (uint)num15;
num15 >>= 32;
if (data[num14] > num17)
{
num15 += 1UL;
}
num13 += 1U;
num14++;
}
while ((ulong)num13 < (ulong)((long)num2));
num14 = num7 - num2 + 1;
num13 = 0U;
if (num15 != 0UL)
{
num16 -= 1U;
ulong num18 = 0UL;
do
{
num18 = (ulong)data[num14] + (ulong)bi2.data[(int)((UIntPtr)num13)] + num18;
data[num14] = (uint)num18;
num18 >>= 32;
num13 += 1U;
num14++;
}
while ((ulong)num13 < (ulong)((long)num2));
}
bigInteger.data[num6--] = num16;
num7--;
i--;
}
bigInteger.Normalize();
bigInteger2.Normalize();
BigInteger[] array = new BigInteger[] { bigInteger, bigInteger2 };
if (num5 != 0)
{
BigInteger[] array2 = array;
int num19 = 1;
array2[num19] >>= num5;
}
return array;
}
// Token: 0x0600005E RID: 94 RVA: 0x00003EC4 File Offset: 0x000020C4
public static BigInteger LeftShift(BigInteger bi, int n)
{
if (n == 0)
{
return new BigInteger(bi, bi.length + 1U);
}
int num = n >> 5;
n &= 31;
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, bi.length + 1U + (uint)num);
uint num2 = 0U;
uint length = bi.length;
if (n != 0)
{
uint num3 = 0U;
while (num2 < length)
{
uint num4 = bi.data[(int)((UIntPtr)num2)];
checked
{
bigInteger.data[(int)((IntPtr)(unchecked((ulong)num2 + (ulong)((long)num))))] = (num4 << n) | num3;
}
num3 = num4 >> 32 - n;
num2 += 1U;
}
checked
{
bigInteger.data[(int)((IntPtr)(unchecked((ulong)num2 + (ulong)((long)num))))] = num3;
}
}
else
{
while (num2 < length)
{
bigInteger.data[(int)(checked((IntPtr)(unchecked((ulong)num2 + (ulong)((long)num)))))] = bi.data[(int)((UIntPtr)num2)];
num2 += 1U;
}
}
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x0600005F RID: 95 RVA: 0x00003F94 File Offset: 0x00002194
public static BigInteger RightShift(BigInteger bi, int n)
{
if (n == 0)
{
return new BigInteger(bi);
}
int num = n >> 5;
int num2 = n & 31;
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, bi.length - (uint)num + 1U);
uint num3 = (uint)(bigInteger.data.Length - 1);
if (num2 != 0)
{
uint num4 = 0U;
while (num3-- > 0U)
{
uint num5;
checked
{
num5 = bi.data[(int)((IntPtr)(unchecked((ulong)num3 + (ulong)((long)num))))];
}
bigInteger.data[(int)((UIntPtr)num3)] = (num5 >> n) | num4;
num4 = num5 << 32 - n;
}
}
else
{
while (num3-- > 0U)
{
bigInteger.data[(int)((UIntPtr)num3)] = bi.data[(int)(checked((IntPtr)(unchecked((ulong)num3 + (ulong)((long)num)))))];
}
}
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x06000060 RID: 96 RVA: 0x0000404C File Offset: 0x0000224C
public static BigInteger MultiplyByDword(BigInteger n, uint f)
{
BigInteger bigInteger = new BigInteger(BigInteger.Sign.Positive, n.length + 1U);
uint num = 0U;
ulong num2 = 0UL;
do
{
num2 += (ulong)n.data[(int)((UIntPtr)num)] * (ulong)f;
bigInteger.data[(int)((UIntPtr)num)] = (uint)num2;
num2 >>= 32;
}
while ((num += 1U) < n.length);
bigInteger.data[(int)((UIntPtr)num)] = (uint)num2;
bigInteger.Normalize();
return bigInteger;
}
// Token: 0x06000061 RID: 97 RVA: 0x000040B0 File Offset: 0x000022B0
public unsafe static void Multiply(uint[] x, uint xOffset, uint xLen, uint[] y, uint yOffset, uint yLen, uint[] d, uint dOffset)
{
fixed (uint* ptr = (ref x != null && x.Length != 0 ? ref x[0] : ref *null), ptr2 = (ref y != null && y.Length != 0 ? ref y[0] : ref *null), ptr3 = (ref d != null && d.Length != 0 ? ref d[0] : ref *null))
{
uint* ptr4 = ptr + xOffset;
uint* ptr5 = ptr4 + xLen;
uint* ptr6 = ptr2 + yOffset;
uint* ptr7 = ptr6 + yLen;
uint* ptr8 = ptr3 + dOffset;
while (ptr4 < ptr5)
{
if (*ptr4 != 0U)
{
ulong num = 0UL;
uint* ptr9 = ptr8;
uint* ptr10 = ptr6;
while (ptr10 < ptr7)
{
num += (ulong)(*ptr4) * (ulong)(*ptr10) + (ulong)(*ptr9);
*ptr9 = (uint)num;
num >>= 32;
ptr10++;
ptr9++;
}
if (num != 0UL)
{
*ptr9 = (uint)num;
}
}
ptr4++;
ptr8++;
}
}
}
// Token: 0x06000062 RID: 98 RVA: 0x000041C4 File Offset: 0x000023C4
public unsafe static void MultiplyMod2p32pmod(uint[] x, int xOffset, int xLen, uint[] y, int yOffest, int yLen, uint[] d, int dOffset, int mod)
{
fixed (uint* ptr = (ref x != null && x.Length != 0 ? ref x[0] : ref *null), ptr2 = (ref y != null && y.Length != 0 ? ref y[0] : ref *null), ptr3 = (ref d != null && d.Length != 0 ? ref d[0] : ref *null))
{
uint* ptr4 = ptr + xOffset;
uint* ptr5 = ptr4 + xLen;
uint* ptr6 = ptr2 + yOffest;
uint* ptr7 = ptr6 + yLen;
uint* ptr8 = ptr3 + dOffset;
uint* ptr9 = ptr8 + mod;
while (ptr4 < ptr5)
{
if (*ptr4 != 0U)
{
ulong num = 0UL;
uint* ptr10 = ptr8;
uint* ptr11 = ptr6;
while (ptr11 < ptr7 && ptr10 < ptr9)
{
num += (ulong)(*ptr4) * (ulong)(*ptr11) + (ulong)(*ptr10);
*ptr10 = (uint)num;
num >>= 32;
ptr11++;
ptr10++;
}
if (num != 0UL && ptr10 < ptr9)
{
*ptr10 = (uint)num;
}
}
ptr4++;
ptr8++;
}
}
}
// Token: 0x06000063 RID: 99 RVA: 0x000042F0 File Offset: 0x000024F0
public unsafe static void SquarePositive(BigInteger bi, ref uint[] wkSpace)
{
uint[] array = wkSpace;
wkSpace = bi.data;
uint[] data = bi.data;
uint length = bi.length;
bi.data = array;
fixed (uint* ptr = (ref data != null && data.Length != 0 ? ref data[0] : ref *null), ptr2 = (ref array != null && array.Length != 0 ? ref array[0] : ref *null))
{
uint* ptr3 = ptr2 + array.Length;
for (uint* ptr4 = ptr2; ptr4 < ptr3; ptr4++)
{
*ptr4 = 0U;
}
uint* ptr5 = ptr;
uint* ptr6 = ptr2;
uint num = 0U;
while (num < length)
{
if (*ptr5 != 0U)
{
ulong num2 = 0UL;
uint num3 = *ptr5;
uint* ptr7 = ptr5 + 1;
uint* ptr8 = ptr6 + 2U * num + 1;
uint num4 = num + 1U;
while (num4 < length)
{
num2 += (ulong)num3 * (ulong)(*ptr7) + (ulong)(*ptr8);
*ptr8 = (uint)num2;
num2 >>= 32;
num4 += 1U;
ptr8++;
ptr7++;
}
if (num2 != 0UL)
{
*ptr8 = (uint)num2;
}
}
num += 1U;
ptr5++;
}
ptr6 = ptr2;
uint num5 = 0U;
while (ptr6 < ptr3)
{
uint num6 = *ptr6;
*ptr6 = (num6 << 1) | num5;
num5 = num6 >> 31;
ptr6++;
}
if (num5 != 0U)
{
*ptr6 = num5;
}
ptr5 = ptr;
ptr6 = ptr2;
uint* ptr9 = ptr5 + length;
while (ptr5 < ptr9)
{
ulong num7 = (ulong)(*ptr5) * (ulong)(*ptr5) + (ulong)(*ptr6);
*ptr6 = (uint)num7;
num7 >>= 32;
*(++ptr6) += (uint)num7;
if (*ptr6 < (uint)num7)
{
uint* ptr10 = ptr6;
*(++ptr10) += 1U;
while (*(ptr10++) == 0U)
{
*ptr10 += 1U;
}
}
ptr5++;
ptr6++;
}
bi.length <<= 1;
while (ptr2[bi.length - 1U] == 0U && bi.length > 1U)
{
bi.length -= 1U;
}
}
}
// Token: 0x06000064 RID: 100 RVA: 0x00004534 File Offset: 0x00002734
public static BigInteger gcd(BigInteger a, BigInteger b)
{
BigInteger bigInteger = a;
BigInteger bigInteger2 = b;
BigInteger bigInteger3 = bigInteger2;
while (bigInteger.length > 1U)
{
bigInteger3 = bigInteger;
bigInteger = bigInteger2 % bigInteger;
bigInteger2 = bigInteger3;
}
if (bigInteger == 0U)
{
return bigInteger3;
}
uint num = bigInteger.data[0];
uint num2 = bigInteger2 % num;
int num3 = 0;
while (((num2 | num) & 1U) == 0U)
{
num2 >>= 1;
num >>= 1;
num3++;
}
while (num2 != 0U)
{
while ((num2 & 1U) == 0U)
{
num2 >>= 1;
}
while ((num & 1U) == 0U)
{
num >>= 1;
}
if (num2 >= num)
{
num2 = num2 - num >> 1;
}
else
{
num = num - num2 >> 1;
}
}
return num << num3;
}
// Token: 0x06000065 RID: 101 RVA: 0x00004600 File Offset: 0x00002800
public static uint modInverse(BigInteger bi, uint modulus)
{
uint num = modulus;
uint num2 = bi % modulus;
uint num3 = 0U;
uint num4 = 1U;
while (num2 != 0U)
{
if (num2 == 1U)
{
return num4;
}
num3 += num / num2 * num4;
num %= num2;
if (num == 0U)
{
break;
}
if (num == 1U)
{
return modulus - num3;
}
num4 += num2 / num * num3;
num2 %= num;
}
return 0U;
}
// Token: 0x06000066 RID: 102 RVA: 0x00004660 File Offset: 0x00002860
public static BigInteger modInverse(BigInteger bi, BigInteger modulus)
{
if (modulus.length == 1U)
{
return BigInteger.Kernel.modInverse(bi, modulus.data[0]);
}
BigInteger[] array = new BigInteger[] { 0, 1 };
BigInteger[] array2 = new BigInteger[2];
BigInteger[] array3 = new BigInteger[] { 0, 0 };
int num = 0;
BigInteger bigInteger = modulus;
BigInteger bigInteger2 = bi;
BigInteger.ModulusRing modulusRing = new BigInteger.ModulusRing(modulus);
while (bigInteger2 != 0U)
{
if (num > 1)
{
BigInteger bigInteger3 = modulusRing.Difference(array[0], array[1] * array2[0]);
array[0] = array[1];
array[1] = bigInteger3;
}
BigInteger[] array4 = BigInteger.Kernel.multiByteDivide(bigInteger, bigInteger2);
array2[0] = array2[1];
array2[1] = array4[0];
array3[0] = array3[1];
array3[1] = array4[1];
bigInteger = bigInteger2;
bigInteger2 = array4[1];
num++;
}
if (array3[0] != 1U)
{
throw new ArithmeticException("No inverse!");
}
return modulusRing.Difference(array[0], array[1] * array2[0]);
}
}
}
}
@@ -0,0 +1,21 @@
using System;
namespace Mono.Math.Prime
{
// Token: 0x02000009 RID: 9
public enum ConfidenceFactor
{
// Token: 0x0400002B RID: 43
ExtraLow,
// Token: 0x0400002C RID: 44
Low,
// Token: 0x0400002D RID: 45
Medium,
// Token: 0x0400002E RID: 46
High,
// Token: 0x0400002F RID: 47
ExtraHigh,
// Token: 0x04000030 RID: 48
Provable
}
}
@@ -0,0 +1,20 @@
using System;
namespace Mono.Math.Prime.Generator
{
// Token: 0x0200000B RID: 11
public class NextPrimeFinder : SequentialSearchPrimeGeneratorBase
{
// Token: 0x0600006D RID: 109 RVA: 0x00004AD4 File Offset: 0x00002CD4
protected override BigInteger GenerateSearchBase(int bits, object Context)
{
if (Context == null)
{
throw new ArgumentNullException("Context");
}
BigInteger bigInteger = new BigInteger((BigInteger)Context);
bigInteger.SetBit(0U);
return bigInteger;
}
}
}
@@ -0,0 +1,47 @@
using System;
namespace Mono.Math.Prime.Generator
{
// Token: 0x0200000C RID: 12
public abstract class PrimeGeneratorBase
{
// Token: 0x17000002 RID: 2
// (get) Token: 0x0600006F RID: 111 RVA: 0x00004B10 File Offset: 0x00002D10
public virtual ConfidenceFactor Confidence
{
get
{
return ConfidenceFactor.Medium;
}
}
// Token: 0x17000003 RID: 3
// (get) Token: 0x06000070 RID: 112 RVA: 0x00004B14 File Offset: 0x00002D14
public virtual PrimalityTest PrimalityTest
{
get
{
return new PrimalityTest(PrimalityTests.RabinMillerTest);
}
}
// Token: 0x17000004 RID: 4
// (get) Token: 0x06000071 RID: 113 RVA: 0x00004B24 File Offset: 0x00002D24
public virtual int TrialDivisionBounds
{
get
{
return 4000;
}
}
// Token: 0x06000072 RID: 114 RVA: 0x00004B2C File Offset: 0x00002D2C
protected bool PostTrialDivisionTests(BigInteger bi)
{
return this.PrimalityTest(bi, this.Confidence);
}
// Token: 0x06000073 RID: 115
public abstract BigInteger GenerateNewPrime(int bits);
}
}
@@ -0,0 +1,91 @@
using System;
namespace Mono.Math.Prime.Generator
{
// Token: 0x0200000D RID: 13
public class SequentialSearchPrimeGeneratorBase : PrimeGeneratorBase
{
// Token: 0x06000075 RID: 117 RVA: 0x00004B48 File Offset: 0x00002D48
protected virtual BigInteger GenerateSearchBase(int bits, object context)
{
BigInteger bigInteger = BigInteger.GenerateRandom(bits);
bigInteger.SetBit(0U);
return bigInteger;
}
// Token: 0x06000076 RID: 118 RVA: 0x00004B64 File Offset: 0x00002D64
public override BigInteger GenerateNewPrime(int bits)
{
return this.GenerateNewPrime(bits, null);
}
// Token: 0x06000077 RID: 119 RVA: 0x00004B70 File Offset: 0x00002D70
public virtual BigInteger GenerateNewPrime(int bits, object context)
{
BigInteger bigInteger = this.GenerateSearchBase(bits, context);
uint num = bigInteger % 3234846615U;
int trialDivisionBounds = this.TrialDivisionBounds;
uint[] smallPrimes = BigInteger.smallPrimes;
for (;;)
{
if (num % 3U != 0U)
{
if (num % 5U != 0U)
{
if (num % 7U != 0U)
{
if (num % 11U != 0U)
{
if (num % 13U != 0U)
{
if (num % 17U != 0U)
{
if (num % 19U != 0U)
{
if (num % 23U != 0U)
{
if (num % 29U != 0U)
{
int num2 = 10;
while (num2 < smallPrimes.Length && (ulong)smallPrimes[num2] <= (ulong)((long)trialDivisionBounds))
{
if (bigInteger % smallPrimes[num2] == 0U)
{
goto IL_105;
}
num2++;
}
if (this.IsPrimeAcceptable(bigInteger, context))
{
if (this.PrimalityTest(bigInteger, this.Confidence))
{
break;
}
}
}
}
}
}
}
}
}
}
}
IL_105:
num += 2U;
if (num >= 3234846615U)
{
num -= 3234846615U;
}
bigInteger.Incr2();
}
return bigInteger;
}
// Token: 0x06000078 RID: 120 RVA: 0x00004CA4 File Offset: 0x00002EA4
protected virtual bool IsPrimeAcceptable(BigInteger bi, object context)
{
return true;
}
}
}
@@ -0,0 +1,8 @@
using System;
namespace Mono.Math.Prime
{
// Token: 0x020000CA RID: 202
// (Invoke) Token: 0x0600070D RID: 1805
public delegate bool PrimalityTest(BigInteger bi, ConfidenceFactor confidence);
}
+176
View File
@@ -0,0 +1,176 @@
using System;
namespace Mono.Math.Prime
{
// Token: 0x0200000A RID: 10
public sealed class PrimalityTests
{
// Token: 0x06000067 RID: 103 RVA: 0x00004774 File Offset: 0x00002974
private PrimalityTests()
{
}
// Token: 0x06000068 RID: 104 RVA: 0x0000477C File Offset: 0x0000297C
private static int GetSPPRounds(BigInteger bi, ConfidenceFactor confidence)
{
int num = bi.BitCount();
int num2;
if (num <= 100)
{
num2 = 27;
}
else if (num <= 150)
{
num2 = 18;
}
else if (num <= 200)
{
num2 = 15;
}
else if (num <= 250)
{
num2 = 12;
}
else if (num <= 300)
{
num2 = 9;
}
else if (num <= 350)
{
num2 = 8;
}
else if (num <= 400)
{
num2 = 7;
}
else if (num <= 500)
{
num2 = 6;
}
else if (num <= 600)
{
num2 = 5;
}
else if (num <= 800)
{
num2 = 4;
}
else if (num <= 1250)
{
num2 = 3;
}
else
{
num2 = 2;
}
switch (confidence)
{
case ConfidenceFactor.ExtraLow:
num2 >>= 2;
return (num2 == 0) ? 1 : num2;
case ConfidenceFactor.Low:
num2 >>= 1;
return (num2 == 0) ? 1 : num2;
case ConfidenceFactor.Medium:
return num2;
case ConfidenceFactor.High:
return num2 << 1;
case ConfidenceFactor.ExtraHigh:
return num2 << 2;
case ConfidenceFactor.Provable:
throw new Exception("The Rabin-Miller test can not be executed in a way such that its results are provable");
default:
throw new ArgumentOutOfRangeException("confidence");
}
}
// Token: 0x06000069 RID: 105 RVA: 0x000048C4 File Offset: 0x00002AC4
public static bool Test(BigInteger n, ConfidenceFactor confidence)
{
if (n.BitCount() < 33)
{
return PrimalityTests.SmallPrimeSppTest(n, confidence);
}
return PrimalityTests.RabinMillerTest(n, confidence);
}
// Token: 0x0600006A RID: 106 RVA: 0x000048E4 File Offset: 0x00002AE4
public static bool RabinMillerTest(BigInteger n, ConfidenceFactor confidence)
{
int num = n.BitCount();
int spprounds = PrimalityTests.GetSPPRounds(num, confidence);
BigInteger bigInteger = n - 1;
int num2 = bigInteger.LowestSetBit();
BigInteger bigInteger2 = bigInteger >> num2;
BigInteger.ModulusRing modulusRing = new BigInteger.ModulusRing(n);
BigInteger bigInteger3 = null;
if (n.BitCount() > 100)
{
bigInteger3 = modulusRing.Pow(2U, bigInteger2);
}
for (int i = 0; i < spprounds; i++)
{
if (i > 0 || bigInteger3 == null)
{
BigInteger bigInteger4;
do
{
bigInteger4 = BigInteger.GenerateRandom(num);
}
while (bigInteger4 <= 2 && bigInteger4 >= bigInteger);
bigInteger3 = modulusRing.Pow(bigInteger4, bigInteger2);
}
if (!(bigInteger3 == 1U))
{
int num3 = 0;
while (num3 < num2 && bigInteger3 != bigInteger)
{
bigInteger3 = modulusRing.Pow(bigInteger3, 2);
if (bigInteger3 == 1U)
{
return false;
}
num3++;
}
if (bigInteger3 != bigInteger)
{
return false;
}
}
}
return true;
}
// Token: 0x0600006B RID: 107 RVA: 0x00004A10 File Offset: 0x00002C10
public static bool SmallPrimeSppTest(BigInteger bi, ConfidenceFactor confidence)
{
int spprounds = PrimalityTests.GetSPPRounds(bi, confidence);
BigInteger bigInteger = bi - 1;
int num = bigInteger.LowestSetBit();
BigInteger bigInteger2 = bigInteger >> num;
BigInteger.ModulusRing modulusRing = new BigInteger.ModulusRing(bi);
for (int i = 0; i < spprounds; i++)
{
BigInteger bigInteger3 = modulusRing.Pow(BigInteger.smallPrimes[i], bigInteger2);
if (!(bigInteger3 == 1U))
{
bool flag = false;
for (int j = 0; j < num; j++)
{
if (bigInteger3 == bigInteger)
{
flag = true;
break;
}
bigInteger3 = bigInteger3 * bigInteger3 % bi;
}
if (!flag)
{
return false;
}
}
}
return true;
}
}
}
+203
View File
@@ -0,0 +1,203 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{99604A24-13D0-4C83-A3AA-9A315339FA4B}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Mono</RootNamespace>
<AssemblyName>Mono.Security</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup />
<ItemGroup>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Consts.cs" />
<Compile Include="Locale.cs" />
<Compile Include="Math\BigInteger.cs" />
<Compile Include="Math\Prime\ConfidenceFactor.cs" />
<Compile Include="Math\Prime\Generator\NextPrimeFinder.cs" />
<Compile Include="Math\Prime\Generator\PrimeGeneratorBase.cs" />
<Compile Include="Math\Prime\Generator\SequentialSearchPrimeGeneratorBase.cs" />
<Compile Include="Math\Prime\PrimalityTest.cs" />
<Compile Include="Math\Prime\PrimalityTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Security\ASN1.cs" />
<Compile Include="Security\ASN1Convert.cs" />
<Compile Include="Security\Authenticode\AuthenticodeBase.cs" />
<Compile Include="Security\Authenticode\AuthenticodeDeformatter.cs" />
<Compile Include="Security\Authenticode\AuthenticodeFormatter.cs" />
<Compile Include="Security\Authenticode\Authority.cs" />
<Compile Include="Security\Authenticode\PrivateKey.cs" />
<Compile Include="Security\Authenticode\SoftwarePublisherCertificate.cs" />
<Compile Include="Security\BitConverterLE.cs" />
<Compile Include="Security\Cryptography\ARC4Managed.cs" />
<Compile Include="Security\Cryptography\BlockProcessor.cs" />
<Compile Include="Security\Cryptography\CryptoConvert.cs" />
<Compile Include="Security\Cryptography\DHKeyGeneration.cs" />
<Compile Include="Security\Cryptography\DHParameters.cs" />
<Compile Include="Security\Cryptography\DiffieHellman.cs" />
<Compile Include="Security\Cryptography\DiffieHellmanManaged.cs" />
<Compile Include="Security\Cryptography\HMAC.cs" />
<Compile Include="Security\Cryptography\KeyBuilder.cs" />
<Compile Include="Security\Cryptography\KeyPairPersistence.cs" />
<Compile Include="Security\Cryptography\MD2.cs" />
<Compile Include="Security\Cryptography\MD2Managed.cs" />
<Compile Include="Security\Cryptography\MD4.cs" />
<Compile Include="Security\Cryptography\MD4Managed.cs" />
<Compile Include="Security\Cryptography\MD5SHA1.cs" />
<Compile Include="Security\Cryptography\PKCS1.cs" />
<Compile Include="Security\Cryptography\PKCS8.cs" />
<Compile Include="Security\Cryptography\RC4.cs" />
<Compile Include="Security\Cryptography\RSAManaged.cs" />
<Compile Include="Security\Cryptography\SHA224.cs" />
<Compile Include="Security\Cryptography\SHA224Managed.cs" />
<Compile Include="Security\Cryptography\SHAConstants.cs" />
<Compile Include="Security\Cryptography\SymmetricTransform.cs" />
<Compile Include="Security\PKCS7.cs" />
<Compile Include="Security\Protocol\Ntlm\ChallengeResponse.cs" />
<Compile Include="Security\Protocol\Ntlm\MessageBase.cs" />
<Compile Include="Security\Protocol\Ntlm\NtlmFlags.cs" />
<Compile Include="Security\Protocol\Ntlm\Type1Message.cs" />
<Compile Include="Security\Protocol\Ntlm\Type2Message.cs" />
<Compile Include="Security\Protocol\Ntlm\Type3Message.cs" />
<Compile Include="Security\Protocol\Tls\Alert.cs" />
<Compile Include="Security\Protocol\Tls\AlertDescription.cs" />
<Compile Include="Security\Protocol\Tls\AlertLevel.cs" />
<Compile Include="Security\Protocol\Tls\CertificateSelectionCallback.cs" />
<Compile Include="Security\Protocol\Tls\CertificateValidationCallback.cs" />
<Compile Include="Security\Protocol\Tls\CertificateValidationCallback2.cs" />
<Compile Include="Security\Protocol\Tls\CipherAlgorithmType.cs" />
<Compile Include="Security\Protocol\Tls\CipherSuite.cs" />
<Compile Include="Security\Protocol\Tls\CipherSuiteCollection.cs" />
<Compile Include="Security\Protocol\Tls\CipherSuiteFactory.cs" />
<Compile Include="Security\Protocol\Tls\ClientContext.cs" />
<Compile Include="Security\Protocol\Tls\ClientRecordProtocol.cs" />
<Compile Include="Security\Protocol\Tls\ClientSessionCache.cs" />
<Compile Include="Security\Protocol\Tls\ClientSessionInfo.cs" />
<Compile Include="Security\Protocol\Tls\ContentType.cs" />
<Compile Include="Security\Protocol\Tls\Context.cs" />
<Compile Include="Security\Protocol\Tls\DebugHelper.cs" />
<Compile Include="Security\Protocol\Tls\ExchangeAlgorithmType.cs" />
<Compile Include="Security\Protocol\Tls\HandshakeState.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\ClientCertificateType.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsClientCertificate.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsClientCertificateVerify.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsClientFinished.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsClientHello.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsClientKeyExchange.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsServerCertificate.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsServerCertificateRequest.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsServerFinished.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsServerHello.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsServerHelloDone.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Client\TlsServerKeyExchange.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\HandshakeMessage.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\HandshakeType.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsClientCertificate.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsClientCertificateVerify.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsClientFinished.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsClientHello.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsClientKeyExchange.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsServerCertificate.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsServerCertificateRequest.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsServerFinished.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsServerHello.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsServerHelloDone.cs" />
<Compile Include="Security\Protocol\Tls\Handshake\Server\TlsServerKeyExchange.cs" />
<Compile Include="Security\Protocol\Tls\HashAlgorithmType.cs" />
<Compile Include="Security\Protocol\Tls\HttpsClientStream.cs" />
<Compile Include="Security\Protocol\Tls\PrivateKeySelectionCallback.cs" />
<Compile Include="Security\Protocol\Tls\RecordProtocol.cs" />
<Compile Include="Security\Protocol\Tls\RSASslSignatureDeformatter.cs" />
<Compile Include="Security\Protocol\Tls\RSASslSignatureFormatter.cs" />
<Compile Include="Security\Protocol\Tls\SecurityCompressionType.cs" />
<Compile Include="Security\Protocol\Tls\SecurityParameters.cs" />
<Compile Include="Security\Protocol\Tls\SecurityProtocolType.cs" />
<Compile Include="Security\Protocol\Tls\ServerContext.cs" />
<Compile Include="Security\Protocol\Tls\ServerRecordProtocol.cs" />
<Compile Include="Security\Protocol\Tls\SslCipherSuite.cs" />
<Compile Include="Security\Protocol\Tls\SslClientStream.cs" />
<Compile Include="Security\Protocol\Tls\SslHandshakeHash.cs" />
<Compile Include="Security\Protocol\Tls\SslServerStream.cs" />
<Compile Include="Security\Protocol\Tls\SslStreamBase.cs" />
<Compile Include="Security\Protocol\Tls\TlsCipherSuite.cs" />
<Compile Include="Security\Protocol\Tls\TlsClientSettings.cs" />
<Compile Include="Security\Protocol\Tls\TlsException.cs" />
<Compile Include="Security\Protocol\Tls\TlsServerSettings.cs" />
<Compile Include="Security\Protocol\Tls\TlsStream.cs" />
<Compile Include="Security\Protocol\Tls\ValidationResult.cs" />
<Compile Include="Security\StrongName.cs" />
<Compile Include="Security\X509\Extensions\AuthorityKeyIdentifierExtension.cs" />
<Compile Include="Security\X509\Extensions\BasicConstraintsExtension.cs" />
<Compile Include="Security\X509\Extensions\CertificatePoliciesExtension.cs" />
<Compile Include="Security\X509\Extensions\CRLDistributionPointsExtension.cs" />
<Compile Include="Security\X509\Extensions\ExtendedKeyUsageExtension.cs" />
<Compile Include="Security\X509\Extensions\GeneralNames.cs" />
<Compile Include="Security\X509\Extensions\KeyAttributesExtension.cs" />
<Compile Include="Security\X509\Extensions\KeyUsageExtension.cs" />
<Compile Include="Security\X509\Extensions\KeyUsages.cs" />
<Compile Include="Security\X509\Extensions\NetscapeCertTypeExtension.cs" />
<Compile Include="Security\X509\Extensions\PrivateKeyUsagePeriodExtension.cs" />
<Compile Include="Security\X509\Extensions\SubjectAltNameExtension.cs" />
<Compile Include="Security\X509\Extensions\SubjectKeyIdentifierExtension.cs" />
<Compile Include="Security\X509\PKCS12.cs" />
<Compile Include="Security\X509\PKCS5.cs" />
<Compile Include="Security\X509\PKCS9.cs" />
<Compile Include="Security\X509\SafeBag.cs" />
<Compile Include="Security\X509\X501.cs" />
<Compile Include="Security\X509\X509Builder.cs" />
<Compile Include="Security\X509\X509Certificate.cs" />
<Compile Include="Security\X509\X509CertificateBuilder.cs" />
<Compile Include="Security\X509\X509CertificateCollection.cs" />
<Compile Include="Security\X509\X509Chain.cs" />
<Compile Include="Security\X509\X509ChainStatusFlags.cs" />
<Compile Include="Security\X509\X509Crl.cs" />
<Compile Include="Security\X509\X509Extension.cs" />
<Compile Include="Security\X509\X509ExtensionCollection.cs" />
<Compile Include="Security\X509\X509Store.cs" />
<Compile Include="Security\X509\X509StoreManager.cs" />
<Compile Include="Security\X509\X509Stores.cs" />
<Compile Include="Security\X509\X520.cs" />
<Compile Include="Xml\MiniParser.cs" />
<Compile Include="Xml\SecurityParser.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\mscorlib\mscorlib.csproj">
<Project>{99604a24-13d0-4c83-a3aa-9a315339fa4c}</Project>
<Name>mscorlib</Name>
</ProjectReference>
<ProjectReference Include="..\System\System.csproj">
<Project>{99604a24-13d0-4c83-a3aa-9a315339fa56}</Project>
<Name>System</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+18
View File
@@ -0,0 +1,18 @@
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyCopyright("(c) 2003-2004 Various Authors")]
[assembly: AssemblyDescription("Mono.Security.dll")]
[assembly: AssemblyProduct("MONO CLI")]
[assembly: AssemblyTitle("Mono.Security.dll")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyCompany("MONO development team")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../mono.pub")]
[assembly: ComVisible(false)]
+389
View File
@@ -0,0 +1,389 @@
using System;
using System.Collections;
using System.IO;
using System.Text;
namespace Mono.Security
{
// Token: 0x0200000E RID: 14
public class ASN1
{
// Token: 0x06000079 RID: 121 RVA: 0x00004CA8 File Offset: 0x00002EA8
public ASN1()
: this(0, null)
{
}
// Token: 0x0600007A RID: 122 RVA: 0x00004CB4 File Offset: 0x00002EB4
public ASN1(byte tag)
: this(tag, null)
{
}
// Token: 0x0600007B RID: 123 RVA: 0x00004CC0 File Offset: 0x00002EC0
public ASN1(byte tag, byte[] data)
{
this.m_nTag = tag;
this.m_aValue = data;
}
// Token: 0x0600007C RID: 124 RVA: 0x00004CD8 File Offset: 0x00002ED8
public ASN1(byte[] data)
{
this.m_nTag = data[0];
int num = 0;
int num2 = (int)data[1];
if (num2 > 128)
{
num = num2 - 128;
num2 = 0;
for (int i = 0; i < num; i++)
{
num2 *= 256;
num2 += (int)data[i + 2];
}
}
else if (num2 == 128)
{
throw new NotSupportedException("Undefined length encoding.");
}
this.m_aValue = new byte[num2];
Buffer.BlockCopy(data, 2 + num, this.m_aValue, 0, num2);
if ((this.m_nTag & 32) == 32)
{
int num3 = 2 + num;
this.Decode(data, ref num3, data.Length);
}
}
// Token: 0x17000005 RID: 5
// (get) Token: 0x0600007D RID: 125 RVA: 0x00004D8C File Offset: 0x00002F8C
public int Count
{
get
{
if (this.elist == null)
{
return 0;
}
return this.elist.Count;
}
}
// Token: 0x17000006 RID: 6
// (get) Token: 0x0600007E RID: 126 RVA: 0x00004DA8 File Offset: 0x00002FA8
public byte Tag
{
get
{
return this.m_nTag;
}
}
// Token: 0x17000007 RID: 7
// (get) Token: 0x0600007F RID: 127 RVA: 0x00004DB0 File Offset: 0x00002FB0
public int Length
{
get
{
if (this.m_aValue != null)
{
return this.m_aValue.Length;
}
return 0;
}
}
// Token: 0x17000008 RID: 8
// (get) Token: 0x06000080 RID: 128 RVA: 0x00004DC8 File Offset: 0x00002FC8
// (set) Token: 0x06000081 RID: 129 RVA: 0x00004DF8 File Offset: 0x00002FF8
public byte[] Value
{
get
{
if (this.m_aValue == null)
{
this.GetBytes();
}
return (byte[])this.m_aValue.Clone();
}
set
{
if (value != null)
{
this.m_aValue = (byte[])value.Clone();
}
}
}
// Token: 0x06000082 RID: 130 RVA: 0x00004E14 File Offset: 0x00003014
private bool CompareArray(byte[] array1, byte[] array2)
{
bool flag = array1.Length == array2.Length;
if (flag)
{
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
{
return false;
}
}
}
return flag;
}
// Token: 0x06000083 RID: 131 RVA: 0x00004E54 File Offset: 0x00003054
public bool Equals(byte[] asn1)
{
return this.CompareArray(this.GetBytes(), asn1);
}
// Token: 0x06000084 RID: 132 RVA: 0x00004E64 File Offset: 0x00003064
public bool CompareValue(byte[] value)
{
return this.CompareArray(this.m_aValue, value);
}
// Token: 0x06000085 RID: 133 RVA: 0x00004E74 File Offset: 0x00003074
public ASN1 Add(ASN1 asn1)
{
if (asn1 != null)
{
if (this.elist == null)
{
this.elist = new ArrayList();
}
this.elist.Add(asn1);
}
return asn1;
}
// Token: 0x06000086 RID: 134 RVA: 0x00004EAC File Offset: 0x000030AC
public virtual byte[] GetBytes()
{
byte[] array = null;
if (this.Count > 0)
{
int num = 0;
ArrayList arrayList = new ArrayList();
foreach (object obj in this.elist)
{
ASN1 asn = (ASN1)obj;
byte[] bytes = asn.GetBytes();
arrayList.Add(bytes);
num += bytes.Length;
}
array = new byte[num];
int num2 = 0;
for (int i = 0; i < this.elist.Count; i++)
{
byte[] array2 = (byte[])arrayList[i];
Buffer.BlockCopy(array2, 0, array, num2, array2.Length);
num2 += array2.Length;
}
}
else if (this.m_aValue != null)
{
array = this.m_aValue;
}
int num3 = 0;
byte[] array3;
if (array != null)
{
int num4 = array.Length;
if (num4 > 127)
{
if (num4 <= 255)
{
array3 = new byte[3 + num4];
Buffer.BlockCopy(array, 0, array3, 3, num4);
num3 = 129;
array3[2] = (byte)num4;
}
else if (num4 <= 65535)
{
array3 = new byte[4 + num4];
Buffer.BlockCopy(array, 0, array3, 4, num4);
num3 = 130;
array3[2] = (byte)(num4 >> 8);
array3[3] = (byte)num4;
}
else if (num4 <= 16777215)
{
array3 = new byte[5 + num4];
Buffer.BlockCopy(array, 0, array3, 5, num4);
num3 = 131;
array3[2] = (byte)(num4 >> 16);
array3[3] = (byte)(num4 >> 8);
array3[4] = (byte)num4;
}
else
{
array3 = new byte[6 + num4];
Buffer.BlockCopy(array, 0, array3, 6, num4);
num3 = 132;
array3[2] = (byte)(num4 >> 24);
array3[3] = (byte)(num4 >> 16);
array3[4] = (byte)(num4 >> 8);
array3[5] = (byte)num4;
}
}
else
{
array3 = new byte[2 + num4];
Buffer.BlockCopy(array, 0, array3, 2, num4);
num3 = num4;
}
if (this.m_aValue == null)
{
this.m_aValue = array;
}
}
else
{
array3 = new byte[2];
}
array3[0] = this.m_nTag;
array3[1] = (byte)num3;
return array3;
}
// Token: 0x06000087 RID: 135 RVA: 0x0000511C File Offset: 0x0000331C
protected void Decode(byte[] asn1, ref int anPos, int anLength)
{
while (anPos < anLength - 1)
{
byte b;
int num;
byte[] array;
this.DecodeTLV(asn1, ref anPos, out b, out num, out array);
if (b != 0)
{
ASN1 asn2 = this.Add(new ASN1(b, array));
if ((b & 32) == 32)
{
int num2 = anPos;
asn2.Decode(asn1, ref num2, num2 + num);
}
anPos += num;
}
}
}
// Token: 0x06000088 RID: 136 RVA: 0x00005184 File Offset: 0x00003384
protected void DecodeTLV(byte[] asn1, ref int pos, out byte tag, out int length, out byte[] content)
{
tag = asn1[pos++];
length = (int)asn1[pos++];
if ((length & 128) == 128)
{
int num = length & 127;
length = 0;
for (int i = 0; i < num; i++)
{
length = length * 256 + (int)asn1[pos++];
}
}
content = new byte[length];
Buffer.BlockCopy(asn1, pos, content, 0, length);
}
// Token: 0x17000009 RID: 9
public ASN1 this[int index]
{
get
{
ASN1 asn;
try
{
if (this.elist == null || index >= this.elist.Count)
{
asn = null;
}
else
{
asn = (ASN1)this.elist[index];
}
}
catch (ArgumentOutOfRangeException)
{
asn = null;
}
return asn;
}
}
// Token: 0x0600008A RID: 138 RVA: 0x00005288 File Offset: 0x00003488
public ASN1 Element(int index, byte anTag)
{
ASN1 asn;
try
{
if (this.elist == null || index >= this.elist.Count)
{
asn = null;
}
else
{
ASN1 asn2 = (ASN1)this.elist[index];
if (asn2.Tag == anTag)
{
asn = asn2;
}
else
{
asn = null;
}
}
}
catch (ArgumentOutOfRangeException)
{
asn = null;
}
return asn;
}
// Token: 0x0600008B RID: 139 RVA: 0x00005314 File Offset: 0x00003514
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("Tag: {0} {1}", this.m_nTag.ToString("X2"), Environment.NewLine);
stringBuilder.AppendFormat("Length: {0} {1}", this.Value.Length, Environment.NewLine);
stringBuilder.Append("Value: ");
stringBuilder.Append(Environment.NewLine);
for (int i = 0; i < this.Value.Length; i++)
{
stringBuilder.AppendFormat("{0} ", this.Value[i].ToString("X2"));
if ((i + 1) % 16 == 0)
{
stringBuilder.AppendFormat(Environment.NewLine, new object[0]);
}
}
return stringBuilder.ToString();
}
// Token: 0x0600008C RID: 140 RVA: 0x000053DC File Offset: 0x000035DC
public void SaveToFile(string filename)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
using (FileStream fileStream = File.Create(filename))
{
byte[] bytes = this.GetBytes();
fileStream.Write(bytes, 0, bytes.Length);
}
}
// Token: 0x04000031 RID: 49
private byte m_nTag;
// Token: 0x04000032 RID: 50
private byte[] m_aValue;
// Token: 0x04000033 RID: 51
private ArrayList elist;
}
}
+187
View File
@@ -0,0 +1,187 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
namespace Mono.Security
{
// Token: 0x0200000F RID: 15
public static class ASN1Convert
{
// Token: 0x0600008D RID: 141 RVA: 0x00005444 File Offset: 0x00003644
public static ASN1 FromDateTime(DateTime dt)
{
if (dt.Year < 2050)
{
return new ASN1(23, Encoding.ASCII.GetBytes(dt.ToUniversalTime().ToString("yyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"));
}
return new ASN1(24, Encoding.ASCII.GetBytes(dt.ToUniversalTime().ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"));
}
// Token: 0x0600008E RID: 142 RVA: 0x000054CC File Offset: 0x000036CC
public static ASN1 FromInt32(int value)
{
byte[] bytes = BitConverterLE.GetBytes(value);
Array.Reverse(bytes);
int num = 0;
while (num < bytes.Length && bytes[num] == 0)
{
num++;
}
ASN1 asn = new ASN1(2);
int num2 = num;
if (num2 != 0)
{
if (num2 != 4)
{
byte[] array = new byte[4 - num];
Buffer.BlockCopy(bytes, num, array, 0, array.Length);
asn.Value = array;
}
else
{
asn.Value = new byte[1];
}
}
else
{
asn.Value = bytes;
}
return asn;
}
// Token: 0x0600008F RID: 143 RVA: 0x00005560 File Offset: 0x00003760
public static ASN1 FromOid(string oid)
{
if (oid == null)
{
throw new ArgumentNullException("oid");
}
return new ASN1(CryptoConfig.EncodeOID(oid));
}
// Token: 0x06000090 RID: 144 RVA: 0x00005580 File Offset: 0x00003780
public static ASN1 FromUnsignedBigInteger(byte[] big)
{
if (big == null)
{
throw new ArgumentNullException("big");
}
if (big[0] >= 128)
{
int num = big.Length + 1;
byte[] array = new byte[num];
Buffer.BlockCopy(big, 0, array, 1, num - 1);
big = array;
}
return new ASN1(2, big);
}
// Token: 0x06000091 RID: 145 RVA: 0x000055D0 File Offset: 0x000037D0
public static int ToInt32(ASN1 asn1)
{
if (asn1 == null)
{
throw new ArgumentNullException("asn1");
}
if (asn1.Tag != 2)
{
throw new FormatException("Only integer can be converted");
}
int num = 0;
for (int i = 0; i < asn1.Value.Length; i++)
{
num = (num << 8) + (int)asn1.Value[i];
}
return num;
}
// Token: 0x06000092 RID: 146 RVA: 0x00005630 File Offset: 0x00003830
public static string ToOid(ASN1 asn1)
{
if (asn1 == null)
{
throw new ArgumentNullException("asn1");
}
byte[] value = asn1.Value;
StringBuilder stringBuilder = new StringBuilder();
byte b = value[0] / 40;
byte b2 = value[0] % 40;
if (b > 2)
{
b2 += (b - 2) * 40;
b = 2;
}
stringBuilder.Append(b.ToString(CultureInfo.InvariantCulture));
stringBuilder.Append(".");
stringBuilder.Append(b2.ToString(CultureInfo.InvariantCulture));
ulong num = 0UL;
b = 1;
while ((int)b < value.Length)
{
num = (num << 7) | (ulong)(value[(int)b] & 127);
if ((value[(int)b] & 128) != 128)
{
stringBuilder.Append(".");
stringBuilder.Append(num.ToString(CultureInfo.InvariantCulture));
num = 0UL;
}
b += 1;
}
return stringBuilder.ToString();
}
// Token: 0x06000093 RID: 147 RVA: 0x00005718 File Offset: 0x00003918
public static DateTime ToDateTime(ASN1 time)
{
if (time == null)
{
throw new ArgumentNullException("time");
}
string text = Encoding.ASCII.GetString(time.Value);
string text2 = null;
switch (text.Length)
{
case 11:
text2 = "yyMMddHHmmZ";
break;
case 13:
{
int num = (int)Convert.ToInt16(text.Substring(0, 2), CultureInfo.InvariantCulture);
if (num >= 50)
{
text = "19" + text;
}
else
{
text = "20" + text;
}
text2 = "yyyyMMddHHmmssZ";
break;
}
case 15:
text2 = "yyyyMMddHHmmssZ";
break;
case 17:
{
int num = (int)Convert.ToInt16(text.Substring(0, 2), CultureInfo.InvariantCulture);
string text3 = ((num < 50) ? "20" : "19");
char c = ((text[12] != '+') ? '+' : '-');
text = string.Format("{0}{1}{2}{3}{4}:{5}{6}", new object[]
{
text3,
text.Substring(0, 12),
c,
text[13],
text[14],
text[15],
text[16]
});
text2 = "yyyyMMddHHmmsszzz";
break;
}
}
return DateTime.ParseExact(text, text2, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
}
}
}
@@ -0,0 +1,289 @@
using System;
using System.IO;
using System.Security.Cryptography;
namespace Mono.Security.Authenticode
{
// Token: 0x0200001E RID: 30
public class AuthenticodeBase
{
// Token: 0x0600012D RID: 301 RVA: 0x00007CF8 File Offset: 0x00005EF8
public AuthenticodeBase()
{
this.fileblock = new byte[4096];
}
// Token: 0x1700003E RID: 62
// (get) Token: 0x0600012E RID: 302 RVA: 0x00007D10 File Offset: 0x00005F10
internal int PEOffset
{
get
{
if (this.blockNo < 1)
{
this.ReadFirstBlock();
}
return this.peOffset;
}
}
// Token: 0x1700003F RID: 63
// (get) Token: 0x0600012F RID: 303 RVA: 0x00007D2C File Offset: 0x00005F2C
internal int CoffSymbolTableOffset
{
get
{
if (this.blockNo < 1)
{
this.ReadFirstBlock();
}
return this.coffSymbolTableOffset;
}
}
// Token: 0x17000040 RID: 64
// (get) Token: 0x06000130 RID: 304 RVA: 0x00007D48 File Offset: 0x00005F48
internal int SecurityOffset
{
get
{
if (this.blockNo < 1)
{
this.ReadFirstBlock();
}
return this.dirSecurityOffset;
}
}
// Token: 0x06000131 RID: 305 RVA: 0x00007D64 File Offset: 0x00005F64
internal void Open(string filename)
{
if (this.fs != null)
{
this.Close();
}
this.fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
this.blockNo = 0;
}
// Token: 0x06000132 RID: 306 RVA: 0x00007D90 File Offset: 0x00005F90
internal void Close()
{
if (this.fs != null)
{
this.fs.Close();
this.fs = null;
}
}
// Token: 0x06000133 RID: 307 RVA: 0x00007DB0 File Offset: 0x00005FB0
internal void ReadFirstBlock()
{
int num = this.ProcessFirstBlock();
if (num != 0)
{
string text = Locale.GetText("Cannot sign non PE files, e.g. .CAB or .MSI files (error {0}).", new object[] { num });
throw new NotSupportedException(text);
}
}
// Token: 0x06000134 RID: 308 RVA: 0x00007DEC File Offset: 0x00005FEC
internal int ProcessFirstBlock()
{
if (this.fs == null)
{
return 1;
}
this.fs.Position = 0L;
this.blockLength = this.fs.Read(this.fileblock, 0, this.fileblock.Length);
this.blockNo = 1;
if (this.blockLength < 64)
{
return 2;
}
if (BitConverterLE.ToUInt16(this.fileblock, 0) != 23117)
{
return 3;
}
this.peOffset = BitConverterLE.ToInt32(this.fileblock, 60);
if (this.peOffset > this.fileblock.Length)
{
string text = string.Format(Locale.GetText("Header size too big (> {0} bytes)."), this.fileblock.Length);
throw new NotSupportedException(text);
}
if ((long)this.peOffset > this.fs.Length)
{
return 4;
}
if (BitConverterLE.ToUInt32(this.fileblock, this.peOffset) != 17744U)
{
return 5;
}
this.dirSecurityOffset = BitConverterLE.ToInt32(this.fileblock, this.peOffset + 152);
this.dirSecuritySize = BitConverterLE.ToInt32(this.fileblock, this.peOffset + 156);
this.coffSymbolTableOffset = BitConverterLE.ToInt32(this.fileblock, this.peOffset + 12);
return 0;
}
// Token: 0x06000135 RID: 309 RVA: 0x00007F38 File Offset: 0x00006138
internal byte[] GetSecurityEntry()
{
if (this.blockNo < 1)
{
this.ReadFirstBlock();
}
if (this.dirSecuritySize > 8)
{
byte[] array = new byte[this.dirSecuritySize - 8];
this.fs.Position = (long)(this.dirSecurityOffset + 8);
this.fs.Read(array, 0, array.Length);
return array;
}
return null;
}
// Token: 0x06000136 RID: 310 RVA: 0x00007F9C File Offset: 0x0000619C
internal byte[] GetHash(HashAlgorithm hash)
{
if (this.blockNo < 1)
{
this.ReadFirstBlock();
}
this.fs.Position = (long)this.blockLength;
int num = 0;
long num2;
if (this.dirSecurityOffset > 0)
{
if (this.dirSecurityOffset < this.blockLength)
{
this.blockLength = this.dirSecurityOffset;
num2 = 0L;
}
else
{
num2 = (long)(this.dirSecurityOffset - this.blockLength);
}
}
else if (this.coffSymbolTableOffset > 0)
{
this.fileblock[this.PEOffset + 12] = 0;
this.fileblock[this.PEOffset + 13] = 0;
this.fileblock[this.PEOffset + 14] = 0;
this.fileblock[this.PEOffset + 15] = 0;
this.fileblock[this.PEOffset + 16] = 0;
this.fileblock[this.PEOffset + 17] = 0;
this.fileblock[this.PEOffset + 18] = 0;
this.fileblock[this.PEOffset + 19] = 0;
if (this.coffSymbolTableOffset < this.blockLength)
{
this.blockLength = this.coffSymbolTableOffset;
num2 = 0L;
}
else
{
num2 = (long)(this.coffSymbolTableOffset - this.blockLength);
}
}
else
{
num = (int)(this.fs.Length & 7L);
if (num > 0)
{
num = 8 - num;
}
num2 = this.fs.Length - (long)this.blockLength;
}
int num3 = this.peOffset + 88;
hash.TransformBlock(this.fileblock, 0, num3, this.fileblock, 0);
num3 += 4;
hash.TransformBlock(this.fileblock, num3, 60, this.fileblock, num3);
num3 += 68;
if (num2 == 0L)
{
hash.TransformFinalBlock(this.fileblock, num3, this.blockLength - num3);
}
else
{
hash.TransformBlock(this.fileblock, num3, this.blockLength - num3, this.fileblock, num3);
long num4 = num2 >> 12;
int num5 = (int)(num2 - (num4 << 12));
if (num5 == 0)
{
num4 -= 1L;
num5 = 4096;
}
for (;;)
{
long num6 = num4;
num4 = num6 - 1L;
if (num6 <= 0L)
{
break;
}
this.fs.Read(this.fileblock, 0, this.fileblock.Length);
hash.TransformBlock(this.fileblock, 0, this.fileblock.Length, this.fileblock, 0);
}
if (this.fs.Read(this.fileblock, 0, num5) != num5)
{
return null;
}
if (num > 0)
{
hash.TransformBlock(this.fileblock, 0, num5, this.fileblock, 0);
hash.TransformFinalBlock(new byte[num], 0, num);
}
else
{
hash.TransformFinalBlock(this.fileblock, 0, num5);
}
}
return hash.Hash;
}
// Token: 0x06000137 RID: 311 RVA: 0x00008260 File Offset: 0x00006460
protected byte[] HashFile(string fileName, string hashName)
{
byte[] array;
try
{
this.Open(fileName);
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(hashName);
byte[] hash = this.GetHash(hashAlgorithm);
this.Close();
array = hash;
}
catch
{
array = null;
}
return array;
}
// Token: 0x04000076 RID: 118
public const string spcIndirectDataContext = "1.3.6.1.4.1.311.2.1.4";
// Token: 0x04000077 RID: 119
private byte[] fileblock;
// Token: 0x04000078 RID: 120
private FileStream fs;
// Token: 0x04000079 RID: 121
private int blockNo;
// Token: 0x0400007A RID: 122
private int blockLength;
// Token: 0x0400007B RID: 123
private int peOffset;
// Token: 0x0400007C RID: 124
private int dirSecurityOffset;
// Token: 0x0400007D RID: 125
private int dirSecuritySize;
// Token: 0x0400007E RID: 126
private int coffSymbolTableOffset;
}
}
@@ -0,0 +1,486 @@
using System;
using System.Collections.Generic;
using System.Security;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
using Mono.Security.X509;
namespace Mono.Security.Authenticode
{
// Token: 0x0200001F RID: 31
public class AuthenticodeDeformatter : AuthenticodeBase
{
// Token: 0x06000138 RID: 312 RVA: 0x000082C0 File Offset: 0x000064C0
public AuthenticodeDeformatter()
{
this.reason = -1;
this.signerChain = new X509Chain();
this.timestampChain = new X509Chain();
}
// Token: 0x06000139 RID: 313 RVA: 0x000082E8 File Offset: 0x000064E8
public AuthenticodeDeformatter(string fileName)
: this()
{
this.FileName = fileName;
}
// Token: 0x17000041 RID: 65
// (get) Token: 0x0600013A RID: 314 RVA: 0x000082F8 File Offset: 0x000064F8
// (set) Token: 0x0600013B RID: 315 RVA: 0x00008300 File Offset: 0x00006500
public string FileName
{
get
{
return this.filename;
}
set
{
this.Reset();
try
{
this.CheckSignature(value);
}
catch (SecurityException)
{
throw;
}
catch (Exception)
{
this.reason = 1;
}
}
}
// Token: 0x17000042 RID: 66
// (get) Token: 0x0600013C RID: 316 RVA: 0x0000836C File Offset: 0x0000656C
public byte[] Hash
{
get
{
if (this.signedHash == null)
{
return null;
}
return (byte[])this.signedHash.Value.Clone();
}
}
// Token: 0x17000043 RID: 67
// (get) Token: 0x0600013D RID: 317 RVA: 0x0000839C File Offset: 0x0000659C
public int Reason
{
get
{
if (this.reason == -1)
{
this.IsTrusted();
}
return this.reason;
}
}
// Token: 0x0600013E RID: 318 RVA: 0x000083B8 File Offset: 0x000065B8
public bool IsTrusted()
{
if (this.entry == null)
{
this.reason = 1;
return false;
}
if (this.signingCertificate == null)
{
this.reason = 7;
return false;
}
if (this.signerChain.Root == null || !this.trustedRoot)
{
this.reason = 6;
return false;
}
if (this.timestamp != DateTime.MinValue)
{
if (this.timestampChain.Root == null || !this.trustedTimestampRoot)
{
this.reason = 6;
return false;
}
if (!this.signingCertificate.WasCurrent(this.Timestamp))
{
this.reason = 4;
return false;
}
}
else if (!this.signingCertificate.IsCurrent)
{
this.reason = 8;
return false;
}
if (this.reason == -1)
{
this.reason = 0;
}
return true;
}
// Token: 0x17000044 RID: 68
// (get) Token: 0x0600013F RID: 319 RVA: 0x0000849C File Offset: 0x0000669C
public byte[] Signature
{
get
{
if (this.entry == null)
{
return null;
}
return (byte[])this.entry.Clone();
}
}
// Token: 0x17000045 RID: 69
// (get) Token: 0x06000140 RID: 320 RVA: 0x000084BC File Offset: 0x000066BC
public DateTime Timestamp
{
get
{
return this.timestamp;
}
}
// Token: 0x17000046 RID: 70
// (get) Token: 0x06000141 RID: 321 RVA: 0x000084C4 File Offset: 0x000066C4
public X509CertificateCollection Certificates
{
get
{
return this.coll;
}
}
// Token: 0x17000047 RID: 71
// (get) Token: 0x06000142 RID: 322 RVA: 0x000084CC File Offset: 0x000066CC
public X509Certificate SigningCertificate
{
get
{
return this.signingCertificate;
}
}
// Token: 0x06000143 RID: 323 RVA: 0x000084D4 File Offset: 0x000066D4
private bool CheckSignature(string fileName)
{
this.filename = fileName;
base.Open(this.filename);
this.entry = base.GetSecurityEntry();
if (this.entry == null)
{
this.reason = 1;
base.Close();
return false;
}
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(this.entry);
if (contentInfo.ContentType != "1.2.840.113549.1.7.2")
{
base.Close();
return false;
}
PKCS7.SignedData signedData = new PKCS7.SignedData(contentInfo.Content);
if (signedData.ContentInfo.ContentType != "1.3.6.1.4.1.311.2.1.4")
{
base.Close();
return false;
}
this.coll = signedData.Certificates;
ASN1 content = signedData.ContentInfo.Content;
this.signedHash = content[0][1][1];
int length = this.signedHash.Length;
HashAlgorithm hashAlgorithm;
if (length != 16)
{
if (length != 20)
{
this.reason = 5;
base.Close();
return false;
}
hashAlgorithm = HashAlgorithm.Create("SHA1");
this.hash = base.GetHash(hashAlgorithm);
}
else
{
hashAlgorithm = HashAlgorithm.Create("MD5");
this.hash = base.GetHash(hashAlgorithm);
}
base.Close();
if (!this.signedHash.CompareValue(this.hash))
{
this.reason = 2;
}
byte[] value = content[0].Value;
hashAlgorithm.Initialize();
byte[] array = hashAlgorithm.ComputeHash(value);
bool flag = this.VerifySignature(signedData, array, hashAlgorithm);
return flag && this.reason == 0;
}
// Token: 0x06000144 RID: 324 RVA: 0x00008674 File Offset: 0x00006874
private bool CompareIssuerSerial(string issuer, byte[] serial, X509Certificate x509)
{
if (issuer != x509.IssuerName)
{
return false;
}
if (serial.Length != x509.SerialNumber.Length)
{
return false;
}
int num = serial.Length;
for (int i = 0; i < serial.Length; i++)
{
if (serial[i] != x509.SerialNumber[--num])
{
return false;
}
}
return true;
}
// Token: 0x06000145 RID: 325 RVA: 0x000086D8 File Offset: 0x000068D8
private bool VerifySignature(PKCS7.SignedData sd, byte[] calculatedMessageDigest, HashAlgorithm ha)
{
string text = null;
ASN1 asn = null;
int i = 0;
while (i < sd.SignerInfo.AuthenticatedAttributes.Count)
{
ASN1 asn2 = (ASN1)sd.SignerInfo.AuthenticatedAttributes[i];
string text2 = ASN1Convert.ToOid(asn2[0]);
string text3 = text2;
switch (text3)
{
case "1.2.840.113549.1.9.3":
text = ASN1Convert.ToOid(asn2[1][0]);
break;
case "1.2.840.113549.1.9.4":
asn = asn2[1][0];
break;
}
IL_F1:
i++;
continue;
goto IL_F1;
}
if (text != "1.3.6.1.4.1.311.2.1.4")
{
return false;
}
if (asn == null)
{
return false;
}
if (!asn.CompareValue(calculatedMessageDigest))
{
return false;
}
string text4 = CryptoConfig.MapNameToOID(ha.ToString());
ASN1 asn3 = new ASN1(49);
foreach (object obj in sd.SignerInfo.AuthenticatedAttributes)
{
ASN1 asn4 = (ASN1)obj;
asn3.Add(asn4);
}
ha.Initialize();
byte[] array = ha.ComputeHash(asn3.GetBytes());
byte[] signature = sd.SignerInfo.Signature;
string issuerName = sd.SignerInfo.IssuerName;
byte[] serialNumber = sd.SignerInfo.SerialNumber;
foreach (X509Certificate x509Certificate in this.coll)
{
if (this.CompareIssuerSerial(issuerName, serialNumber, x509Certificate) && x509Certificate.PublicKey.Length > signature.Length >> 3)
{
this.signingCertificate = x509Certificate;
RSACryptoServiceProvider rsacryptoServiceProvider = (RSACryptoServiceProvider)x509Certificate.RSA;
if (rsacryptoServiceProvider.VerifyHash(array, text4, signature))
{
this.signerChain.LoadCertificates(this.coll);
this.trustedRoot = this.signerChain.Build(x509Certificate);
break;
}
}
}
if (sd.SignerInfo.UnauthenticatedAttributes.Count == 0)
{
this.trustedTimestampRoot = true;
}
else
{
int j = 0;
while (j < sd.SignerInfo.UnauthenticatedAttributes.Count)
{
ASN1 asn5 = (ASN1)sd.SignerInfo.UnauthenticatedAttributes[j];
string text5 = ASN1Convert.ToOid(asn5[0]);
string text3 = text5;
if (text3 != null)
{
if (AuthenticodeDeformatter.<>f__switch$map2 == null)
{
AuthenticodeDeformatter.<>f__switch$map2 = new Dictionary<string, int>(1) { { "1.2.840.113549.1.9.6", 0 } };
}
int num;
if (AuthenticodeDeformatter.<>f__switch$map2.TryGetValue(text3, out num))
{
if (num == 0)
{
PKCS7.SignerInfo signerInfo = new PKCS7.SignerInfo(asn5[1]);
this.trustedTimestampRoot = this.VerifyCounterSignature(signerInfo, signature);
}
}
}
IL_35D:
j++;
continue;
goto IL_35D;
}
}
return this.trustedRoot && this.trustedTimestampRoot;
}
// Token: 0x06000146 RID: 326 RVA: 0x00008AA8 File Offset: 0x00006CA8
private bool VerifyCounterSignature(PKCS7.SignerInfo cs, byte[] signature)
{
if (cs.Version != 1)
{
return false;
}
string text = null;
ASN1 asn = null;
int i = 0;
while (i < cs.AuthenticatedAttributes.Count)
{
ASN1 asn2 = (ASN1)cs.AuthenticatedAttributes[i];
string text2 = ASN1Convert.ToOid(asn2[0]);
string text3 = text2;
switch (text3)
{
case "1.2.840.113549.1.9.3":
text = ASN1Convert.ToOid(asn2[1][0]);
break;
case "1.2.840.113549.1.9.4":
asn = asn2[1][0];
break;
case "1.2.840.113549.1.9.5":
this.timestamp = ASN1Convert.ToDateTime(asn2[1][0]);
break;
}
IL_FC:
i++;
continue;
goto IL_FC;
}
if (text != "1.2.840.113549.1.7.1")
{
return false;
}
if (asn == null)
{
return false;
}
string text4 = null;
int length = asn.Length;
if (length != 16)
{
if (length == 20)
{
text4 = "SHA1";
}
}
else
{
text4 = "MD5";
}
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(text4);
if (!asn.CompareValue(hashAlgorithm.ComputeHash(signature)))
{
return false;
}
byte[] signature2 = cs.Signature;
ASN1 asn3 = new ASN1(49);
foreach (object obj in cs.AuthenticatedAttributes)
{
ASN1 asn4 = (ASN1)obj;
asn3.Add(asn4);
}
byte[] array = hashAlgorithm.ComputeHash(asn3.GetBytes());
string issuerName = cs.IssuerName;
byte[] serialNumber = cs.SerialNumber;
foreach (X509Certificate x509Certificate in this.coll)
{
if (this.CompareIssuerSerial(issuerName, serialNumber, x509Certificate) && x509Certificate.PublicKey.Length > signature2.Length)
{
RSACryptoServiceProvider rsacryptoServiceProvider = (RSACryptoServiceProvider)x509Certificate.RSA;
RSAManaged rsamanaged = new RSAManaged();
rsamanaged.ImportParameters(rsacryptoServiceProvider.ExportParameters(false));
if (PKCS1.Verify_v15(rsamanaged, hashAlgorithm, array, signature2, true))
{
this.timestampChain.LoadCertificates(this.coll);
return this.timestampChain.Build(x509Certificate);
}
}
}
return false;
}
// Token: 0x06000147 RID: 327 RVA: 0x00008DB4 File Offset: 0x00006FB4
private void Reset()
{
this.filename = null;
this.entry = null;
this.hash = null;
this.signedHash = null;
this.signingCertificate = null;
this.reason = -1;
this.trustedRoot = false;
this.trustedTimestampRoot = false;
this.signerChain.Reset();
this.timestampChain.Reset();
this.timestamp = DateTime.MinValue;
}
// Token: 0x0400007F RID: 127
private string filename;
// Token: 0x04000080 RID: 128
private byte[] hash;
// Token: 0x04000081 RID: 129
private X509CertificateCollection coll;
// Token: 0x04000082 RID: 130
private ASN1 signedHash;
// Token: 0x04000083 RID: 131
private DateTime timestamp;
// Token: 0x04000084 RID: 132
private X509Certificate signingCertificate;
// Token: 0x04000085 RID: 133
private int reason;
// Token: 0x04000086 RID: 134
private bool trustedRoot;
// Token: 0x04000087 RID: 135
private bool trustedTimestampRoot;
// Token: 0x04000088 RID: 136
private byte[] entry;
// Token: 0x04000089 RID: 137
private X509Chain signerChain;
// Token: 0x0400008A RID: 138
private X509Chain timestampChain;
}
}
@@ -0,0 +1,464 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using Mono.Security.X509;
namespace Mono.Security.Authenticode
{
// Token: 0x02000020 RID: 32
public class AuthenticodeFormatter : AuthenticodeBase
{
// Token: 0x06000148 RID: 328 RVA: 0x00008E1C File Offset: 0x0000701C
public AuthenticodeFormatter()
{
this.certs = new X509CertificateCollection();
this.crls = new ArrayList();
this.authority = Authority.Maximum;
this.pkcs7 = new PKCS7.SignedData();
}
// Token: 0x17000048 RID: 72
// (get) Token: 0x0600014A RID: 330 RVA: 0x00008E74 File Offset: 0x00007074
// (set) Token: 0x0600014B RID: 331 RVA: 0x00008E7C File Offset: 0x0000707C
public Authority Authority
{
get
{
return this.authority;
}
set
{
this.authority = value;
}
}
// Token: 0x17000049 RID: 73
// (get) Token: 0x0600014C RID: 332 RVA: 0x00008E88 File Offset: 0x00007088
public X509CertificateCollection Certificates
{
get
{
return this.certs;
}
}
// Token: 0x1700004A RID: 74
// (get) Token: 0x0600014D RID: 333 RVA: 0x00008E90 File Offset: 0x00007090
public ArrayList Crl
{
get
{
return this.crls;
}
}
// Token: 0x1700004B RID: 75
// (get) Token: 0x0600014E RID: 334 RVA: 0x00008E98 File Offset: 0x00007098
// (set) Token: 0x0600014F RID: 335 RVA: 0x00008EB8 File Offset: 0x000070B8
public string Hash
{
get
{
if (this.hash == null)
{
this.hash = "MD5";
}
return this.hash;
}
set
{
if (value == null)
{
throw new ArgumentNullException("Hash");
}
string text = value.ToUpper(CultureInfo.InvariantCulture);
string text2 = text;
if (text2 != null)
{
if (AuthenticodeFormatter.<>f__switch$map4 == null)
{
AuthenticodeFormatter.<>f__switch$map4 = new Dictionary<string, int>(2)
{
{ "MD5", 0 },
{ "SHA1", 0 }
};
}
int num;
if (AuthenticodeFormatter.<>f__switch$map4.TryGetValue(text2, out num))
{
if (num == 0)
{
this.hash = text;
return;
}
}
}
throw new ArgumentException("Invalid Authenticode hash algorithm");
}
}
// Token: 0x1700004C RID: 76
// (get) Token: 0x06000150 RID: 336 RVA: 0x00008F50 File Offset: 0x00007150
// (set) Token: 0x06000151 RID: 337 RVA: 0x00008F58 File Offset: 0x00007158
public RSA RSA
{
get
{
return this.rsa;
}
set
{
this.rsa = value;
}
}
// Token: 0x1700004D RID: 77
// (get) Token: 0x06000152 RID: 338 RVA: 0x00008F64 File Offset: 0x00007164
// (set) Token: 0x06000153 RID: 339 RVA: 0x00008F6C File Offset: 0x0000716C
public Uri TimestampUrl
{
get
{
return this.timestamp;
}
set
{
this.timestamp = value;
}
}
// Token: 0x1700004E RID: 78
// (get) Token: 0x06000154 RID: 340 RVA: 0x00008F78 File Offset: 0x00007178
// (set) Token: 0x06000155 RID: 341 RVA: 0x00008F80 File Offset: 0x00007180
public string Description
{
get
{
return this.description;
}
set
{
this.description = value;
}
}
// Token: 0x1700004F RID: 79
// (get) Token: 0x06000156 RID: 342 RVA: 0x00008F8C File Offset: 0x0000718C
// (set) Token: 0x06000157 RID: 343 RVA: 0x00008F94 File Offset: 0x00007194
public Uri Url
{
get
{
return this.url;
}
set
{
this.url = value;
}
}
// Token: 0x06000158 RID: 344 RVA: 0x00008FA0 File Offset: 0x000071A0
private ASN1 AlgorithmIdentifier(string oid)
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(oid));
asn.Add(new ASN1(5));
return asn;
}
// Token: 0x06000159 RID: 345 RVA: 0x00008FD0 File Offset: 0x000071D0
private ASN1 Attribute(string oid, ASN1 value)
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(oid));
ASN1 asn2 = asn.Add(new ASN1(49));
asn2.Add(value);
return asn;
}
// Token: 0x0600015A RID: 346 RVA: 0x0000900C File Offset: 0x0000720C
private ASN1 Opus(string description, string url)
{
ASN1 asn = new ASN1(48);
if (description != null)
{
ASN1 asn2 = asn.Add(new ASN1(160));
asn2.Add(new ASN1(128, Encoding.BigEndianUnicode.GetBytes(description)));
}
if (url != null)
{
ASN1 asn3 = asn.Add(new ASN1(161));
asn3.Add(new ASN1(128, Encoding.ASCII.GetBytes(url)));
}
return asn;
}
// Token: 0x0600015B RID: 347 RVA: 0x00009088 File Offset: 0x00007288
private byte[] Header(byte[] fileHash, string hashAlgorithm)
{
string text = CryptoConfig.MapNameToOID(hashAlgorithm);
ASN1 asn = new ASN1(48);
ASN1 asn2 = asn.Add(new ASN1(48));
asn2.Add(ASN1Convert.FromOid("1.3.6.1.4.1.311.2.1.15"));
asn2.Add(new ASN1(48, AuthenticodeFormatter.obsolete));
ASN1 asn3 = asn.Add(new ASN1(48));
asn3.Add(this.AlgorithmIdentifier(text));
asn3.Add(new ASN1(4, fileHash));
this.pkcs7.HashName = hashAlgorithm;
this.pkcs7.Certificates.AddRange(this.certs);
this.pkcs7.ContentInfo.ContentType = "1.3.6.1.4.1.311.2.1.4";
this.pkcs7.ContentInfo.Content.Add(asn);
this.pkcs7.SignerInfo.Certificate = this.certs[0];
this.pkcs7.SignerInfo.Key = this.rsa;
ASN1 asn4;
if (this.url == null)
{
asn4 = this.Attribute("1.3.6.1.4.1.311.2.1.12", this.Opus(this.description, null));
}
else
{
asn4 = this.Attribute("1.3.6.1.4.1.311.2.1.12", this.Opus(this.description, this.url.ToString()));
}
this.pkcs7.SignerInfo.AuthenticatedAttributes.Add(asn4);
this.pkcs7.GetASN1();
return this.pkcs7.SignerInfo.Signature;
}
// Token: 0x0600015C RID: 348 RVA: 0x0000920C File Offset: 0x0000740C
public ASN1 TimestampRequest(byte[] signature)
{
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo("1.2.840.113549.1.7.1");
contentInfo.Content.Add(new ASN1(4, signature));
return PKCS7.AlgorithmIdentifier("1.3.6.1.4.1.311.3.2.1", contentInfo.ASN1);
}
// Token: 0x0600015D RID: 349 RVA: 0x00009248 File Offset: 0x00007448
public void ProcessTimestamp(byte[] response)
{
ASN1 asn = new ASN1(Convert.FromBase64String(Encoding.ASCII.GetString(response)));
for (int i = 0; i < asn[1][0][3].Count; i++)
{
this.pkcs7.Certificates.Add(new X509Certificate(asn[1][0][3][i].GetBytes()));
}
this.pkcs7.SignerInfo.UnauthenticatedAttributes.Add(this.Attribute("1.2.840.113549.1.9.6", asn[1][0][4][0]));
}
// Token: 0x0600015E RID: 350 RVA: 0x00009304 File Offset: 0x00007504
private byte[] Timestamp(byte[] signature)
{
ASN1 asn = this.TimestampRequest(signature);
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/octet-stream");
webClient.Headers.Add("Accept", "application/octet-stream");
byte[] bytes = Encoding.ASCII.GetBytes(Convert.ToBase64String(asn.GetBytes()));
return webClient.UploadData(this.timestamp.ToString(), bytes);
}
// Token: 0x0600015F RID: 351 RVA: 0x00009374 File Offset: 0x00007574
private bool Save(string fileName, byte[] asn)
{
File.Copy(fileName, fileName + ".bak", true);
using (FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.ReadWrite))
{
int num;
if (base.SecurityOffset > 0)
{
num = base.SecurityOffset;
}
else if (base.CoffSymbolTableOffset > 0)
{
fileStream.Seek((long)(base.PEOffset + 12), SeekOrigin.Begin);
for (int i = 0; i < 8; i++)
{
fileStream.WriteByte(0);
}
num = base.CoffSymbolTableOffset;
}
else
{
num = (int)fileStream.Length;
}
int num2 = num & 7;
if (num2 > 0)
{
num2 = 8 - num2;
}
byte[] array = BitConverterLE.GetBytes(num + num2);
fileStream.Seek((long)(base.PEOffset + 152), SeekOrigin.Begin);
fileStream.Write(array, 0, 4);
int num3 = asn.Length + 8;
int num4 = num3 & 7;
if (num4 > 0)
{
num4 = 8 - num4;
}
array = BitConverterLE.GetBytes(num3 + num4);
fileStream.Seek((long)(base.PEOffset + 156), SeekOrigin.Begin);
fileStream.Write(array, 0, 4);
fileStream.Seek((long)num, SeekOrigin.Begin);
if (num2 > 0)
{
byte[] array2 = new byte[num2];
fileStream.Write(array2, 0, array2.Length);
}
fileStream.Write(array, 0, array.Length);
array = BitConverterLE.GetBytes(131584);
fileStream.Write(array, 0, array.Length);
fileStream.Write(asn, 0, asn.Length);
if (num4 > 0)
{
byte[] array3 = new byte[num4];
fileStream.Write(array3, 0, array3.Length);
}
fileStream.Close();
}
return true;
}
// Token: 0x06000160 RID: 352 RVA: 0x00009528 File Offset: 0x00007728
public bool Sign(string fileName)
{
try
{
base.Open(fileName);
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.Hash);
byte[] array = base.GetHash(hashAlgorithm);
byte[] array2 = this.Header(array, this.Hash);
if (this.timestamp != null)
{
byte[] array3 = this.Timestamp(array2);
this.ProcessTimestamp(array3);
}
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo("1.2.840.113549.1.7.2");
contentInfo.Content.Add(this.pkcs7.ASN1);
this.authenticode = contentInfo.ASN1;
base.Close();
return this.Save(fileName, this.authenticode.GetBytes());
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return false;
}
// Token: 0x06000161 RID: 353 RVA: 0x00009604 File Offset: 0x00007804
public bool Timestamp(string fileName)
{
try
{
AuthenticodeDeformatter authenticodeDeformatter = new AuthenticodeDeformatter(fileName);
byte[] signature = authenticodeDeformatter.Signature;
if (signature != null)
{
base.Open(fileName);
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(signature);
this.pkcs7 = new PKCS7.SignedData(contentInfo.Content);
byte[] array = this.Timestamp(this.pkcs7.SignerInfo.Signature);
ASN1 asn = new ASN1(Convert.FromBase64String(Encoding.ASCII.GetString(array)));
ASN1 asn2 = new ASN1(signature);
ASN1 asn3 = asn2.Element(1, 160);
if (asn3 == null)
{
return false;
}
ASN1 asn4 = asn3.Element(0, 48);
if (asn4 == null)
{
return false;
}
ASN1 asn5 = asn4.Element(3, 160);
if (asn5 == null)
{
asn5 = new ASN1(160);
asn4.Add(asn5);
}
for (int i = 0; i < asn[1][0][3].Count; i++)
{
asn5.Add(asn[1][0][3][i]);
}
ASN1 asn6 = asn4[asn4.Count - 1];
ASN1 asn7 = asn6[0];
ASN1 asn8 = asn7[asn7.Count - 1];
if (asn8.Tag != 161)
{
asn8 = new ASN1(161);
asn7.Add(asn8);
}
asn8.Add(this.Attribute("1.2.840.113549.1.9.6", asn[1][0][4][0]));
return this.Save(fileName, asn2.GetBytes());
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return false;
}
// Token: 0x0400008E RID: 142
private const string signedData = "1.2.840.113549.1.7.2";
// Token: 0x0400008F RID: 143
private const string countersignature = "1.2.840.113549.1.9.6";
// Token: 0x04000090 RID: 144
private const string spcStatementType = "1.3.6.1.4.1.311.2.1.11";
// Token: 0x04000091 RID: 145
private const string spcSpOpusInfo = "1.3.6.1.4.1.311.2.1.12";
// Token: 0x04000092 RID: 146
private const string spcPelmageData = "1.3.6.1.4.1.311.2.1.15";
// Token: 0x04000093 RID: 147
private const string commercialCodeSigning = "1.3.6.1.4.1.311.2.1.22";
// Token: 0x04000094 RID: 148
private const string timestampCountersignature = "1.3.6.1.4.1.311.3.2.1";
// Token: 0x04000095 RID: 149
private Authority authority;
// Token: 0x04000096 RID: 150
private X509CertificateCollection certs;
// Token: 0x04000097 RID: 151
private ArrayList crls;
// Token: 0x04000098 RID: 152
private string hash;
// Token: 0x04000099 RID: 153
private RSA rsa;
// Token: 0x0400009A RID: 154
private Uri timestamp;
// Token: 0x0400009B RID: 155
private ASN1 authenticode;
// Token: 0x0400009C RID: 156
private PKCS7.SignedData pkcs7;
// Token: 0x0400009D RID: 157
private string description;
// Token: 0x0400009E RID: 158
private Uri url;
// Token: 0x0400009F RID: 159
private static byte[] obsolete = new byte[]
{
3, 1, 0, 160, 32, 162, 30, 128, 28, 0,
60, 0, 60, 0, 60, 0, 79, 0, 98, 0,
115, 0, 111, 0, 108, 0, 101, 0, 116, 0,
101, 0, 62, 0, 62, 0, 62
};
}
}
@@ -0,0 +1,15 @@
using System;
namespace Mono.Security.Authenticode
{
// Token: 0x0200001D RID: 29
public enum Authority
{
// Token: 0x04000073 RID: 115
Individual,
// Token: 0x04000074 RID: 116
Commercial,
// Token: 0x04000075 RID: 117
Maximum
}
}
@@ -0,0 +1,266 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Mono.Security.Cryptography;
namespace Mono.Security.Authenticode
{
// Token: 0x02000022 RID: 34
public class PrivateKey
{
// Token: 0x06000169 RID: 361 RVA: 0x00009A30 File Offset: 0x00007C30
public PrivateKey()
{
this.keyType = 2;
}
// Token: 0x0600016A RID: 362 RVA: 0x00009A40 File Offset: 0x00007C40
public PrivateKey(byte[] data, string password)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (!this.Decode(data, password))
{
throw new CryptographicException(Locale.GetText("Invalid data and/or password"));
}
}
// Token: 0x17000052 RID: 82
// (get) Token: 0x0600016B RID: 363 RVA: 0x00009A84 File Offset: 0x00007C84
public bool Encrypted
{
get
{
return this.encrypted;
}
}
// Token: 0x17000053 RID: 83
// (get) Token: 0x0600016C RID: 364 RVA: 0x00009A8C File Offset: 0x00007C8C
// (set) Token: 0x0600016D RID: 365 RVA: 0x00009A94 File Offset: 0x00007C94
public int KeyType
{
get
{
return this.keyType;
}
set
{
this.keyType = value;
}
}
// Token: 0x17000054 RID: 84
// (get) Token: 0x0600016E RID: 366 RVA: 0x00009AA0 File Offset: 0x00007CA0
// (set) Token: 0x0600016F RID: 367 RVA: 0x00009AA8 File Offset: 0x00007CA8
public RSA RSA
{
get
{
return this.rsa;
}
set
{
this.rsa = value;
}
}
// Token: 0x17000055 RID: 85
// (get) Token: 0x06000170 RID: 368 RVA: 0x00009AB4 File Offset: 0x00007CB4
// (set) Token: 0x06000171 RID: 369 RVA: 0x00009AD0 File Offset: 0x00007CD0
public bool Weak
{
get
{
return !this.encrypted || this.weak;
}
set
{
this.weak = value;
}
}
// Token: 0x06000172 RID: 370 RVA: 0x00009ADC File Offset: 0x00007CDC
private byte[] DeriveKey(byte[] salt, string password)
{
byte[] bytes = Encoding.ASCII.GetBytes(password);
SHA1 sha = SHA1.Create();
sha.TransformBlock(salt, 0, salt.Length, salt, 0);
sha.TransformFinalBlock(bytes, 0, bytes.Length);
byte[] array = new byte[16];
Buffer.BlockCopy(sha.Hash, 0, array, 0, 16);
sha.Clear();
Array.Clear(bytes, 0, bytes.Length);
return array;
}
// Token: 0x06000173 RID: 371 RVA: 0x00009B40 File Offset: 0x00007D40
private bool Decode(byte[] pvk, string password)
{
if (BitConverterLE.ToUInt32(pvk, 0) != 2964713758U)
{
return false;
}
if (BitConverterLE.ToUInt32(pvk, 4) != 0U)
{
return false;
}
this.keyType = BitConverterLE.ToInt32(pvk, 8);
this.encrypted = BitConverterLE.ToUInt32(pvk, 12) == 1U;
int num = BitConverterLE.ToInt32(pvk, 16);
int num2 = BitConverterLE.ToInt32(pvk, 20);
byte[] array = new byte[num2];
Buffer.BlockCopy(pvk, 24 + num, array, 0, num2);
if (num > 0)
{
if (password == null)
{
return false;
}
byte[] array2 = new byte[num];
Buffer.BlockCopy(pvk, 24, array2, 0, num);
byte[] array3 = this.DeriveKey(array2, password);
RC4 rc = RC4.Create();
ICryptoTransform cryptoTransform = rc.CreateDecryptor(array3, null);
cryptoTransform.TransformBlock(array, 8, array.Length - 8, array, 8);
try
{
this.rsa = CryptoConvert.FromCapiPrivateKeyBlob(array);
this.weak = false;
}
catch (CryptographicException)
{
this.weak = true;
Buffer.BlockCopy(pvk, 24 + num, array, 0, num2);
Array.Clear(array3, 5, 11);
RC4 rc2 = RC4.Create();
cryptoTransform = rc2.CreateDecryptor(array3, null);
cryptoTransform.TransformBlock(array, 8, array.Length - 8, array, 8);
this.rsa = CryptoConvert.FromCapiPrivateKeyBlob(array);
}
Array.Clear(array3, 0, array3.Length);
}
else
{
this.weak = true;
this.rsa = CryptoConvert.FromCapiPrivateKeyBlob(array);
Array.Clear(array, 0, array.Length);
}
Array.Clear(pvk, 0, pvk.Length);
return this.rsa != null;
}
// Token: 0x06000174 RID: 372 RVA: 0x00009CD0 File Offset: 0x00007ED0
public void Save(string filename)
{
this.Save(filename, null);
}
// Token: 0x06000175 RID: 373 RVA: 0x00009CDC File Offset: 0x00007EDC
public void Save(string filename, string password)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
byte[] array = null;
FileStream fileStream = File.Open(filename, FileMode.Create, FileAccess.Write);
try
{
byte[] array2 = new byte[4];
byte[] array3 = BitConverterLE.GetBytes(2964713758U);
fileStream.Write(array3, 0, 4);
fileStream.Write(array2, 0, 4);
array3 = BitConverterLE.GetBytes(this.keyType);
fileStream.Write(array3, 0, 4);
this.encrypted = password != null;
array = CryptoConvert.ToCapiPrivateKeyBlob(this.rsa);
if (this.encrypted)
{
array3 = BitConverterLE.GetBytes(1);
fileStream.Write(array3, 0, 4);
array3 = BitConverterLE.GetBytes(16);
fileStream.Write(array3, 0, 4);
array3 = BitConverterLE.GetBytes(array.Length);
fileStream.Write(array3, 0, 4);
byte[] array4 = new byte[16];
RC4 rc = RC4.Create();
byte[] array5 = null;
try
{
RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
randomNumberGenerator.GetBytes(array4);
fileStream.Write(array4, 0, array4.Length);
array5 = this.DeriveKey(array4, password);
if (this.Weak)
{
Array.Clear(array5, 5, 11);
}
ICryptoTransform cryptoTransform = rc.CreateEncryptor(array5, null);
cryptoTransform.TransformBlock(array, 8, array.Length - 8, array, 8);
}
finally
{
Array.Clear(array4, 0, array4.Length);
Array.Clear(array5, 0, array5.Length);
rc.Clear();
}
}
else
{
fileStream.Write(array2, 0, 4);
fileStream.Write(array2, 0, 4);
array3 = BitConverterLE.GetBytes(array.Length);
fileStream.Write(array3, 0, 4);
}
fileStream.Write(array, 0, array.Length);
}
finally
{
Array.Clear(array, 0, array.Length);
fileStream.Close();
}
}
// Token: 0x06000176 RID: 374 RVA: 0x00009EA8 File Offset: 0x000080A8
public static PrivateKey CreateFromFile(string filename)
{
return PrivateKey.CreateFromFile(filename, null);
}
// Token: 0x06000177 RID: 375 RVA: 0x00009EB4 File Offset: 0x000080B4
public static PrivateKey CreateFromFile(string filename, string password)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
byte[] array = null;
using (FileStream fileStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
array = new byte[fileStream.Length];
fileStream.Read(array, 0, array.Length);
fileStream.Close();
}
return new PrivateKey(array, password);
}
// Token: 0x040000A4 RID: 164
private const uint magic = 2964713758U;
// Token: 0x040000A5 RID: 165
private bool encrypted;
// Token: 0x040000A6 RID: 166
private RSA rsa;
// Token: 0x040000A7 RID: 167
private bool weak;
// Token: 0x040000A8 RID: 168
private int keyType;
}
}
@@ -0,0 +1,115 @@
using System;
using System.Collections;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Mono.Security.X509;
namespace Mono.Security.Authenticode
{
// Token: 0x02000021 RID: 33
public class SoftwarePublisherCertificate
{
// Token: 0x06000162 RID: 354 RVA: 0x000097FC File Offset: 0x000079FC
public SoftwarePublisherCertificate()
{
this.pkcs7 = new PKCS7.SignedData();
this.pkcs7.ContentInfo.ContentType = "1.2.840.113549.1.7.1";
}
// Token: 0x06000163 RID: 355 RVA: 0x00009830 File Offset: 0x00007A30
public SoftwarePublisherCertificate(byte[] data)
: this()
{
if (data == null)
{
throw new ArgumentNullException("data");
}
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(data);
if (contentInfo.ContentType != "1.2.840.113549.1.7.2")
{
throw new ArgumentException(Locale.GetText("Unsupported ContentType"));
}
this.pkcs7 = new PKCS7.SignedData(contentInfo.Content);
}
// Token: 0x17000050 RID: 80
// (get) Token: 0x06000164 RID: 356 RVA: 0x00009894 File Offset: 0x00007A94
public X509CertificateCollection Certificates
{
get
{
return this.pkcs7.Certificates;
}
}
// Token: 0x17000051 RID: 81
// (get) Token: 0x06000165 RID: 357 RVA: 0x000098A4 File Offset: 0x00007AA4
public ArrayList Crls
{
get
{
return this.pkcs7.Crls;
}
}
// Token: 0x06000166 RID: 358 RVA: 0x000098B4 File Offset: 0x00007AB4
public byte[] GetBytes()
{
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo("1.2.840.113549.1.7.2");
contentInfo.Content.Add(this.pkcs7.ASN1);
return contentInfo.GetBytes();
}
// Token: 0x06000167 RID: 359 RVA: 0x000098EC File Offset: 0x00007AEC
public static SoftwarePublisherCertificate CreateFromFile(string filename)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
byte[] array = null;
using (FileStream fileStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
array = new byte[fileStream.Length];
fileStream.Read(array, 0, array.Length);
fileStream.Close();
}
if (array.Length < 2)
{
return null;
}
if (array[0] != 48)
{
try
{
array = SoftwarePublisherCertificate.PEM(array);
}
catch (Exception ex)
{
throw new CryptographicException("Invalid encoding", ex);
}
}
return new SoftwarePublisherCertificate(array);
}
// Token: 0x06000168 RID: 360 RVA: 0x000099B4 File Offset: 0x00007BB4
private static byte[] PEM(byte[] data)
{
string text = ((data[1] != 0) ? Encoding.ASCII.GetString(data) : Encoding.Unicode.GetString(data));
int num = text.IndexOf("-----BEGIN PKCS7-----") + "-----BEGIN PKCS7-----".Length;
int num2 = text.IndexOf("-----END PKCS7-----", num);
string text2 = ((num != -1 && num2 != -1) ? text.Substring(num, num2 - num) : text);
return Convert.FromBase64String(text2);
}
// Token: 0x040000A1 RID: 161
private const string header = "-----BEGIN PKCS7-----";
// Token: 0x040000A2 RID: 162
private const string footer = "-----END PKCS7-----";
// Token: 0x040000A3 RID: 163
private PKCS7.SignedData pkcs7;
}
}
+274
View File
@@ -0,0 +1,274 @@
using System;
namespace Mono.Security
{
// Token: 0x02000010 RID: 16
internal sealed class BitConverterLE
{
// Token: 0x06000094 RID: 148 RVA: 0x000058A0 File Offset: 0x00003AA0
private BitConverterLE()
{
}
// Token: 0x06000095 RID: 149 RVA: 0x000058A8 File Offset: 0x00003AA8
private unsafe static byte[] GetUShortBytes(byte* bytes)
{
if (BitConverter.IsLittleEndian)
{
return new byte[]
{
*bytes,
bytes[1]
};
}
return new byte[]
{
bytes[1],
*bytes
};
}
// Token: 0x06000096 RID: 150 RVA: 0x000058DC File Offset: 0x00003ADC
private unsafe static byte[] GetUIntBytes(byte* bytes)
{
if (BitConverter.IsLittleEndian)
{
return new byte[]
{
*bytes,
bytes[1],
bytes[2],
bytes[3]
};
}
return new byte[]
{
bytes[3],
bytes[2],
bytes[1],
*bytes
};
}
// Token: 0x06000097 RID: 151 RVA: 0x00005934 File Offset: 0x00003B34
private unsafe static byte[] GetULongBytes(byte* bytes)
{
if (BitConverter.IsLittleEndian)
{
return new byte[]
{
*bytes,
bytes[1],
bytes[2],
bytes[3],
bytes[4],
bytes[5],
bytes[6],
bytes[7]
};
}
return new byte[]
{
bytes[7],
bytes[6],
bytes[5],
bytes[4],
bytes[3],
bytes[2],
bytes[1],
*bytes
};
}
// Token: 0x06000098 RID: 152 RVA: 0x000059C4 File Offset: 0x00003BC4
internal static byte[] GetBytes(bool value)
{
return new byte[] { (!value) ? 0 : 1 };
}
// Token: 0x06000099 RID: 153 RVA: 0x000059DC File Offset: 0x00003BDC
internal unsafe static byte[] GetBytes(char value)
{
return BitConverterLE.GetUShortBytes((byte*)(&value));
}
// Token: 0x0600009A RID: 154 RVA: 0x000059E8 File Offset: 0x00003BE8
internal unsafe static byte[] GetBytes(short value)
{
return BitConverterLE.GetUShortBytes((byte*)(&value));
}
// Token: 0x0600009B RID: 155 RVA: 0x000059F4 File Offset: 0x00003BF4
internal unsafe static byte[] GetBytes(int value)
{
return BitConverterLE.GetUIntBytes((byte*)(&value));
}
// Token: 0x0600009C RID: 156 RVA: 0x00005A00 File Offset: 0x00003C00
internal unsafe static byte[] GetBytes(long value)
{
return BitConverterLE.GetULongBytes((byte*)(&value));
}
// Token: 0x0600009D RID: 157 RVA: 0x00005A0C File Offset: 0x00003C0C
internal unsafe static byte[] GetBytes(ushort value)
{
return BitConverterLE.GetUShortBytes((byte*)(&value));
}
// Token: 0x0600009E RID: 158 RVA: 0x00005A18 File Offset: 0x00003C18
internal unsafe static byte[] GetBytes(uint value)
{
return BitConverterLE.GetUIntBytes((byte*)(&value));
}
// Token: 0x0600009F RID: 159 RVA: 0x00005A24 File Offset: 0x00003C24
internal unsafe static byte[] GetBytes(ulong value)
{
return BitConverterLE.GetULongBytes((byte*)(&value));
}
// Token: 0x060000A0 RID: 160 RVA: 0x00005A30 File Offset: 0x00003C30
internal unsafe static byte[] GetBytes(float value)
{
return BitConverterLE.GetUIntBytes((byte*)(&value));
}
// Token: 0x060000A1 RID: 161 RVA: 0x00005A3C File Offset: 0x00003C3C
internal unsafe static byte[] GetBytes(double value)
{
return BitConverterLE.GetULongBytes((byte*)(&value));
}
// Token: 0x060000A2 RID: 162 RVA: 0x00005A48 File Offset: 0x00003C48
private unsafe static void UShortFromBytes(byte* dst, byte[] src, int startIndex)
{
if (BitConverter.IsLittleEndian)
{
*dst = src[startIndex];
dst[1] = src[startIndex + 1];
}
else
{
*dst = src[startIndex + 1];
dst[1] = src[startIndex];
}
}
// Token: 0x060000A3 RID: 163 RVA: 0x00005A78 File Offset: 0x00003C78
private unsafe static void UIntFromBytes(byte* dst, byte[] src, int startIndex)
{
if (BitConverter.IsLittleEndian)
{
*dst = src[startIndex];
dst[1] = src[startIndex + 1];
dst[2] = src[startIndex + 2];
dst[3] = src[startIndex + 3];
}
else
{
*dst = src[startIndex + 3];
dst[1] = src[startIndex + 2];
dst[2] = src[startIndex + 1];
dst[3] = src[startIndex];
}
}
// Token: 0x060000A4 RID: 164 RVA: 0x00005AD4 File Offset: 0x00003CD4
private unsafe static void ULongFromBytes(byte* dst, byte[] src, int startIndex)
{
if (BitConverter.IsLittleEndian)
{
for (int i = 0; i < 8; i++)
{
dst[i] = src[startIndex + i];
}
}
else
{
for (int j = 0; j < 8; j++)
{
dst[j] = src[startIndex + (7 - j)];
}
}
}
// Token: 0x060000A5 RID: 165 RVA: 0x00005B28 File Offset: 0x00003D28
internal static bool ToBoolean(byte[] value, int startIndex)
{
return value[startIndex] != 0;
}
// Token: 0x060000A6 RID: 166 RVA: 0x00005B34 File Offset: 0x00003D34
internal unsafe static char ToChar(byte[] value, int startIndex)
{
char c;
BitConverterLE.UShortFromBytes((byte*)(&c), value, startIndex);
return c;
}
// Token: 0x060000A7 RID: 167 RVA: 0x00005B4C File Offset: 0x00003D4C
internal unsafe static short ToInt16(byte[] value, int startIndex)
{
short num;
BitConverterLE.UShortFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000A8 RID: 168 RVA: 0x00005B64 File Offset: 0x00003D64
internal unsafe static int ToInt32(byte[] value, int startIndex)
{
int num;
BitConverterLE.UIntFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000A9 RID: 169 RVA: 0x00005B7C File Offset: 0x00003D7C
internal unsafe static long ToInt64(byte[] value, int startIndex)
{
long num;
BitConverterLE.ULongFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000AA RID: 170 RVA: 0x00005B94 File Offset: 0x00003D94
internal unsafe static ushort ToUInt16(byte[] value, int startIndex)
{
ushort num;
BitConverterLE.UShortFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000AB RID: 171 RVA: 0x00005BAC File Offset: 0x00003DAC
internal unsafe static uint ToUInt32(byte[] value, int startIndex)
{
uint num;
BitConverterLE.UIntFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000AC RID: 172 RVA: 0x00005BC4 File Offset: 0x00003DC4
internal unsafe static ulong ToUInt64(byte[] value, int startIndex)
{
ulong num;
BitConverterLE.ULongFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000AD RID: 173 RVA: 0x00005BDC File Offset: 0x00003DDC
internal unsafe static float ToSingle(byte[] value, int startIndex)
{
float num;
BitConverterLE.UIntFromBytes((byte*)(&num), value, startIndex);
return num;
}
// Token: 0x060000AE RID: 174 RVA: 0x00005BF4 File Offset: 0x00003DF4
internal unsafe static double ToDouble(byte[] value, int startIndex)
{
double num;
BitConverterLE.ULongFromBytes((byte*)(&num), value, startIndex);
return num;
}
}
}
@@ -0,0 +1,224 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000023 RID: 35
public class ARC4Managed : RC4, IDisposable, ICryptoTransform
{
// Token: 0x06000178 RID: 376 RVA: 0x00009F34 File Offset: 0x00008134
public ARC4Managed()
{
this.state = new byte[256];
this.m_disposed = false;
}
// Token: 0x06000179 RID: 377 RVA: 0x00009F54 File Offset: 0x00008154
~ARC4Managed()
{
this.Dispose(true);
}
// Token: 0x0600017A RID: 378 RVA: 0x00009F90 File Offset: 0x00008190
protected override void Dispose(bool disposing)
{
if (!this.m_disposed)
{
this.x = 0;
this.y = 0;
if (this.key != null)
{
Array.Clear(this.key, 0, this.key.Length);
this.key = null;
}
Array.Clear(this.state, 0, this.state.Length);
this.state = null;
GC.SuppressFinalize(this);
this.m_disposed = true;
}
}
// Token: 0x17000056 RID: 86
// (get) Token: 0x0600017B RID: 379 RVA: 0x0000A004 File Offset: 0x00008204
// (set) Token: 0x0600017C RID: 380 RVA: 0x0000A018 File Offset: 0x00008218
public override byte[] Key
{
get
{
return (byte[])this.key.Clone();
}
set
{
this.key = (byte[])value.Clone();
this.KeySetup(this.key);
}
}
// Token: 0x17000057 RID: 87
// (get) Token: 0x0600017D RID: 381 RVA: 0x0000A038 File Offset: 0x00008238
public bool CanReuseTransform
{
get
{
return false;
}
}
// Token: 0x0600017E RID: 382 RVA: 0x0000A03C File Offset: 0x0000823C
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgvIV)
{
this.Key = rgbKey;
return this;
}
// Token: 0x0600017F RID: 383 RVA: 0x0000A048 File Offset: 0x00008248
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgvIV)
{
this.Key = rgbKey;
return this.CreateEncryptor();
}
// Token: 0x06000180 RID: 384 RVA: 0x0000A058 File Offset: 0x00008258
public override void GenerateIV()
{
this.IV = new byte[0];
}
// Token: 0x06000181 RID: 385 RVA: 0x0000A068 File Offset: 0x00008268
public override void GenerateKey()
{
this.Key = KeyBuilder.Key(this.KeySizeValue >> 3);
}
// Token: 0x17000058 RID: 88
// (get) Token: 0x06000182 RID: 386 RVA: 0x0000A080 File Offset: 0x00008280
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
// Token: 0x17000059 RID: 89
// (get) Token: 0x06000183 RID: 387 RVA: 0x0000A084 File Offset: 0x00008284
public int InputBlockSize
{
get
{
return 1;
}
}
// Token: 0x1700005A RID: 90
// (get) Token: 0x06000184 RID: 388 RVA: 0x0000A088 File Offset: 0x00008288
public int OutputBlockSize
{
get
{
return 1;
}
}
// Token: 0x06000185 RID: 389 RVA: 0x0000A08C File Offset: 0x0000828C
private void KeySetup(byte[] key)
{
byte b = 0;
byte b2 = 0;
for (int i = 0; i < 256; i++)
{
this.state[i] = (byte)i;
}
this.x = 0;
this.y = 0;
for (int j = 0; j < 256; j++)
{
b2 = key[(int)b] + this.state[j] + b2;
byte b3 = this.state[j];
this.state[j] = this.state[(int)b2];
this.state[(int)b2] = b3;
b = (byte)((int)(b + 1) % key.Length);
}
}
// Token: 0x06000186 RID: 390 RVA: 0x0000A120 File Offset: 0x00008320
private void CheckInput(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (inputBuffer == null)
{
throw new ArgumentNullException("inputBuffer");
}
if (inputOffset < 0)
{
throw new ArgumentOutOfRangeException("inputOffset", "< 0");
}
if (inputCount < 0)
{
throw new ArgumentOutOfRangeException("inputCount", "< 0");
}
if (inputOffset > inputBuffer.Length - inputCount)
{
throw new ArgumentException("inputBuffer", Locale.GetText("Overflow"));
}
}
// Token: 0x06000187 RID: 391 RVA: 0x0000A18C File Offset: 0x0000838C
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
this.CheckInput(inputBuffer, inputOffset, inputCount);
if (outputBuffer == null)
{
throw new ArgumentNullException("outputBuffer");
}
if (outputOffset < 0)
{
throw new ArgumentOutOfRangeException("outputOffset", "< 0");
}
if (outputOffset > outputBuffer.Length - inputCount)
{
throw new ArgumentException("outputBuffer", Locale.GetText("Overflow"));
}
return this.InternalTransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
}
// Token: 0x06000188 RID: 392 RVA: 0x0000A1FC File Offset: 0x000083FC
private int InternalTransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
for (int i = 0; i < inputCount; i++)
{
this.x += 1;
this.y = this.state[(int)this.x] + this.y;
byte b = this.state[(int)this.x];
this.state[(int)this.x] = this.state[(int)this.y];
this.state[(int)this.y] = b;
byte b2 = this.state[(int)this.x] + this.state[(int)this.y];
outputBuffer[outputOffset + i] = inputBuffer[inputOffset + i] ^ this.state[(int)b2];
}
return inputCount;
}
// Token: 0x06000189 RID: 393 RVA: 0x0000A2B0 File Offset: 0x000084B0
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
this.CheckInput(inputBuffer, inputOffset, inputCount);
byte[] array = new byte[inputCount];
this.InternalTransformBlock(inputBuffer, inputOffset, inputCount, array, 0);
return array;
}
// Token: 0x040000A9 RID: 169
private byte[] key;
// Token: 0x040000AA RID: 170
private byte[] state;
// Token: 0x040000AB RID: 171
private byte x;
// Token: 0x040000AC RID: 172
private byte y;
// Token: 0x040000AD RID: 173
private bool m_disposed;
}
}
@@ -0,0 +1,83 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000026 RID: 38
public class BlockProcessor
{
// Token: 0x060001A9 RID: 425 RVA: 0x0000B510 File Offset: 0x00009710
public BlockProcessor(ICryptoTransform transform)
: this(transform, transform.InputBlockSize)
{
}
// Token: 0x060001AA RID: 426 RVA: 0x0000B520 File Offset: 0x00009720
public BlockProcessor(ICryptoTransform transform, int blockSize)
{
this.transform = transform;
this.blockSize = blockSize;
this.block = new byte[blockSize];
}
// Token: 0x060001AB RID: 427 RVA: 0x0000B550 File Offset: 0x00009750
~BlockProcessor()
{
Array.Clear(this.block, 0, this.blockSize);
}
// Token: 0x060001AC RID: 428 RVA: 0x0000B598 File Offset: 0x00009798
public void Initialize()
{
Array.Clear(this.block, 0, this.blockSize);
this.blockCount = 0;
}
// Token: 0x060001AD RID: 429 RVA: 0x0000B5B4 File Offset: 0x000097B4
public void Core(byte[] rgb)
{
this.Core(rgb, 0, rgb.Length);
}
// Token: 0x060001AE RID: 430 RVA: 0x0000B5C4 File Offset: 0x000097C4
public void Core(byte[] rgb, int ib, int cb)
{
int num = Math.Min(this.blockSize - this.blockCount, cb);
Buffer.BlockCopy(rgb, ib, this.block, this.blockCount, num);
this.blockCount += num;
if (this.blockCount == this.blockSize)
{
this.transform.TransformBlock(this.block, 0, this.blockSize, this.block, 0);
int num2 = (cb - num) / this.blockSize;
for (int i = 0; i < num2; i++)
{
this.transform.TransformBlock(rgb, num + ib, this.blockSize, this.block, 0);
num += this.blockSize;
}
this.blockCount = cb - num;
if (this.blockCount > 0)
{
Buffer.BlockCopy(rgb, num + ib, this.block, 0, this.blockCount);
}
}
}
// Token: 0x060001AF RID: 431 RVA: 0x0000B6A8 File Offset: 0x000098A8
public byte[] Final()
{
return this.transform.TransformFinalBlock(this.block, 0, this.blockCount);
}
// Token: 0x040000AF RID: 175
private ICryptoTransform transform;
// Token: 0x040000B0 RID: 176
private byte[] block;
// Token: 0x040000B1 RID: 177
private int blockSize;
// Token: 0x040000B2 RID: 178
private int blockCount;
}
}
@@ -0,0 +1,692 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
namespace Mono.Security.Cryptography
{
// Token: 0x02000024 RID: 36
public sealed class CryptoConvert
{
// Token: 0x0600018A RID: 394 RVA: 0x0000A2DC File Offset: 0x000084DC
private CryptoConvert()
{
}
// Token: 0x0600018B RID: 395 RVA: 0x0000A2E4 File Offset: 0x000084E4
private static int ToInt32LE(byte[] bytes, int offset)
{
return ((int)bytes[offset + 3] << 24) | ((int)bytes[offset + 2] << 16) | ((int)bytes[offset + 1] << 8) | (int)bytes[offset];
}
// Token: 0x0600018C RID: 396 RVA: 0x0000A304 File Offset: 0x00008504
private static uint ToUInt32LE(byte[] bytes, int offset)
{
return (uint)(((int)bytes[offset + 3] << 24) | ((int)bytes[offset + 2] << 16) | ((int)bytes[offset + 1] << 8) | (int)bytes[offset]);
}
// Token: 0x0600018D RID: 397 RVA: 0x0000A324 File Offset: 0x00008524
private static byte[] GetBytesLE(int val)
{
return new byte[]
{
(byte)(val & 255),
(byte)((val >> 8) & 255),
(byte)((val >> 16) & 255),
(byte)((val >> 24) & 255)
};
}
// Token: 0x0600018E RID: 398 RVA: 0x0000A36C File Offset: 0x0000856C
private static byte[] Trim(byte[] array)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i] != 0)
{
byte[] array2 = new byte[array.Length - i];
Buffer.BlockCopy(array, i, array2, 0, array2.Length);
return array2;
}
}
return null;
}
// Token: 0x0600018F RID: 399 RVA: 0x0000A3B0 File Offset: 0x000085B0
public static RSA FromCapiPrivateKeyBlob(byte[] blob)
{
return CryptoConvert.FromCapiPrivateKeyBlob(blob, 0);
}
// Token: 0x06000190 RID: 400 RVA: 0x0000A3BC File Offset: 0x000085BC
public static RSA FromCapiPrivateKeyBlob(byte[] blob, int offset)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
if (offset >= blob.Length)
{
throw new ArgumentException("blob is too small.");
}
RSAParameters rsaparameters = default(RSAParameters);
try
{
if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 843141970U)
{
throw new CryptographicException("Invalid blob header");
}
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
byte[] array = new byte[4];
Buffer.BlockCopy(blob, offset + 16, array, 0, 4);
Array.Reverse(array);
rsaparameters.Exponent = CryptoConvert.Trim(array);
int num2 = offset + 20;
int num3 = num >> 3;
rsaparameters.Modulus = new byte[num3];
Buffer.BlockCopy(blob, num2, rsaparameters.Modulus, 0, num3);
Array.Reverse(rsaparameters.Modulus);
num2 += num3;
int num4 = num3 >> 1;
rsaparameters.P = new byte[num4];
Buffer.BlockCopy(blob, num2, rsaparameters.P, 0, num4);
Array.Reverse(rsaparameters.P);
num2 += num4;
rsaparameters.Q = new byte[num4];
Buffer.BlockCopy(blob, num2, rsaparameters.Q, 0, num4);
Array.Reverse(rsaparameters.Q);
num2 += num4;
rsaparameters.DP = new byte[num4];
Buffer.BlockCopy(blob, num2, rsaparameters.DP, 0, num4);
Array.Reverse(rsaparameters.DP);
num2 += num4;
rsaparameters.DQ = new byte[num4];
Buffer.BlockCopy(blob, num2, rsaparameters.DQ, 0, num4);
Array.Reverse(rsaparameters.DQ);
num2 += num4;
rsaparameters.InverseQ = new byte[num4];
Buffer.BlockCopy(blob, num2, rsaparameters.InverseQ, 0, num4);
Array.Reverse(rsaparameters.InverseQ);
num2 += num4;
rsaparameters.D = new byte[num3];
if (num2 + num3 + offset <= blob.Length)
{
Buffer.BlockCopy(blob, num2, rsaparameters.D, 0, num3);
Array.Reverse(rsaparameters.D);
}
}
catch (Exception ex)
{
throw new CryptographicException("Invalid blob.", ex);
}
RSA rsa = null;
try
{
rsa = RSA.Create();
rsa.ImportParameters(rsaparameters);
}
catch (CryptographicException ex2)
{
try
{
rsa = new RSACryptoServiceProvider(new CspParameters
{
Flags = CspProviderFlags.UseMachineKeyStore
});
rsa.ImportParameters(rsaparameters);
}
catch
{
throw ex2;
}
}
return rsa;
}
// Token: 0x06000191 RID: 401 RVA: 0x0000A68C File Offset: 0x0000888C
public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob)
{
return CryptoConvert.FromCapiPrivateKeyBlobDSA(blob, 0);
}
// Token: 0x06000192 RID: 402 RVA: 0x0000A698 File Offset: 0x00008898
public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob, int offset)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
if (offset >= blob.Length)
{
throw new ArgumentException("blob is too small.");
}
DSAParameters dsaparameters = default(DSAParameters);
try
{
if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 844321604U)
{
throw new CryptographicException("Invalid blob header");
}
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
int num2 = num >> 3;
int num3 = offset + 16;
dsaparameters.P = new byte[num2];
Buffer.BlockCopy(blob, num3, dsaparameters.P, 0, num2);
Array.Reverse(dsaparameters.P);
num3 += num2;
dsaparameters.Q = new byte[20];
Buffer.BlockCopy(blob, num3, dsaparameters.Q, 0, 20);
Array.Reverse(dsaparameters.Q);
num3 += 20;
dsaparameters.G = new byte[num2];
Buffer.BlockCopy(blob, num3, dsaparameters.G, 0, num2);
Array.Reverse(dsaparameters.G);
num3 += num2;
dsaparameters.X = new byte[20];
Buffer.BlockCopy(blob, num3, dsaparameters.X, 0, 20);
Array.Reverse(dsaparameters.X);
num3 += 20;
dsaparameters.Counter = CryptoConvert.ToInt32LE(blob, num3);
num3 += 4;
dsaparameters.Seed = new byte[20];
Buffer.BlockCopy(blob, num3, dsaparameters.Seed, 0, 20);
Array.Reverse(dsaparameters.Seed);
num3 += 20;
}
catch (Exception ex)
{
throw new CryptographicException("Invalid blob.", ex);
}
DSA dsa = null;
try
{
dsa = DSA.Create();
dsa.ImportParameters(dsaparameters);
}
catch (CryptographicException ex2)
{
try
{
dsa = new DSACryptoServiceProvider(new CspParameters
{
Flags = CspProviderFlags.UseMachineKeyStore
});
dsa.ImportParameters(dsaparameters);
}
catch
{
throw ex2;
}
}
return dsa;
}
// Token: 0x06000193 RID: 403 RVA: 0x0000A8DC File Offset: 0x00008ADC
public static byte[] ToCapiPrivateKeyBlob(RSA rsa)
{
RSAParameters rsaparameters = rsa.ExportParameters(true);
int num = rsaparameters.Modulus.Length;
byte[] array = new byte[20 + (num << 2) + (num >> 1)];
array[0] = 7;
array[1] = 2;
array[5] = 36;
array[8] = 82;
array[9] = 83;
array[10] = 65;
array[11] = 50;
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
array[12] = bytesLE[0];
array[13] = bytesLE[1];
array[14] = bytesLE[2];
array[15] = bytesLE[3];
int num2 = 16;
int i = rsaparameters.Exponent.Length;
while (i > 0)
{
array[num2++] = rsaparameters.Exponent[--i];
}
num2 = 20;
byte[] array2 = rsaparameters.Modulus;
int num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
num2 += num3;
array2 = rsaparameters.P;
num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
num2 += num3;
array2 = rsaparameters.Q;
num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
num2 += num3;
array2 = rsaparameters.DP;
num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
num2 += num3;
array2 = rsaparameters.DQ;
num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
num2 += num3;
array2 = rsaparameters.InverseQ;
num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
num2 += num3;
array2 = rsaparameters.D;
num3 = array2.Length;
Array.Reverse(array2, 0, num3);
Buffer.BlockCopy(array2, 0, array, num2, num3);
return array;
}
// Token: 0x06000194 RID: 404 RVA: 0x0000AAC4 File Offset: 0x00008CC4
public static byte[] ToCapiPrivateKeyBlob(DSA dsa)
{
DSAParameters dsaparameters = dsa.ExportParameters(true);
int num = dsaparameters.P.Length;
byte[] array = new byte[16 + num + 20 + num + 20 + 4 + 20];
array[0] = 7;
array[1] = 2;
array[5] = 34;
array[8] = 68;
array[9] = 83;
array[10] = 83;
array[11] = 50;
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
array[12] = bytesLE[0];
array[13] = bytesLE[1];
array[14] = bytesLE[2];
array[15] = bytesLE[3];
int num2 = 16;
byte[] array2 = dsaparameters.P;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, num);
num2 += num;
array2 = dsaparameters.Q;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, 20);
num2 += 20;
array2 = dsaparameters.G;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, num);
num2 += num;
array2 = dsaparameters.X;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, 20);
num2 += 20;
Buffer.BlockCopy(CryptoConvert.GetBytesLE(dsaparameters.Counter), 0, array, num2, 4);
num2 += 4;
array2 = dsaparameters.Seed;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, 20);
return array;
}
// Token: 0x06000195 RID: 405 RVA: 0x0000AC10 File Offset: 0x00008E10
public static RSA FromCapiPublicKeyBlob(byte[] blob)
{
return CryptoConvert.FromCapiPublicKeyBlob(blob, 0);
}
// Token: 0x06000196 RID: 406 RVA: 0x0000AC1C File Offset: 0x00008E1C
public static RSA FromCapiPublicKeyBlob(byte[] blob, int offset)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
if (offset >= blob.Length)
{
throw new ArgumentException("blob is too small.");
}
RSA rsa2;
try
{
if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 826364754U)
{
throw new CryptographicException("Invalid blob header");
}
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
RSAParameters rsaparameters = default(RSAParameters);
rsaparameters.Exponent = new byte[3];
rsaparameters.Exponent[0] = blob[offset + 18];
rsaparameters.Exponent[1] = blob[offset + 17];
rsaparameters.Exponent[2] = blob[offset + 16];
int num2 = offset + 20;
int num3 = num >> 3;
rsaparameters.Modulus = new byte[num3];
Buffer.BlockCopy(blob, num2, rsaparameters.Modulus, 0, num3);
Array.Reverse(rsaparameters.Modulus);
RSA rsa = null;
try
{
rsa = RSA.Create();
rsa.ImportParameters(rsaparameters);
}
catch (CryptographicException)
{
rsa = new RSACryptoServiceProvider(new CspParameters
{
Flags = CspProviderFlags.UseMachineKeyStore
});
rsa.ImportParameters(rsaparameters);
}
rsa2 = rsa;
}
catch (Exception ex)
{
throw new CryptographicException("Invalid blob.", ex);
}
return rsa2;
}
// Token: 0x06000197 RID: 407 RVA: 0x0000ADA8 File Offset: 0x00008FA8
public static DSA FromCapiPublicKeyBlobDSA(byte[] blob)
{
return CryptoConvert.FromCapiPublicKeyBlobDSA(blob, 0);
}
// Token: 0x06000198 RID: 408 RVA: 0x0000ADB4 File Offset: 0x00008FB4
public static DSA FromCapiPublicKeyBlobDSA(byte[] blob, int offset)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
if (offset >= blob.Length)
{
throw new ArgumentException("blob is too small.");
}
DSA dsa2;
try
{
if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 827544388U)
{
throw new CryptographicException("Invalid blob header");
}
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
DSAParameters dsaparameters = default(DSAParameters);
int num2 = num >> 3;
int num3 = offset + 16;
dsaparameters.P = new byte[num2];
Buffer.BlockCopy(blob, num3, dsaparameters.P, 0, num2);
Array.Reverse(dsaparameters.P);
num3 += num2;
dsaparameters.Q = new byte[20];
Buffer.BlockCopy(blob, num3, dsaparameters.Q, 0, 20);
Array.Reverse(dsaparameters.Q);
num3 += 20;
dsaparameters.G = new byte[num2];
Buffer.BlockCopy(blob, num3, dsaparameters.G, 0, num2);
Array.Reverse(dsaparameters.G);
num3 += num2;
dsaparameters.Y = new byte[num2];
Buffer.BlockCopy(blob, num3, dsaparameters.Y, 0, num2);
Array.Reverse(dsaparameters.Y);
num3 += num2;
dsaparameters.Counter = CryptoConvert.ToInt32LE(blob, num3);
num3 += 4;
dsaparameters.Seed = new byte[20];
Buffer.BlockCopy(blob, num3, dsaparameters.Seed, 0, 20);
Array.Reverse(dsaparameters.Seed);
num3 += 20;
DSA dsa = DSA.Create();
dsa.ImportParameters(dsaparameters);
dsa2 = dsa;
}
catch (Exception ex)
{
throw new CryptographicException("Invalid blob.", ex);
}
return dsa2;
}
// Token: 0x06000199 RID: 409 RVA: 0x0000AF90 File Offset: 0x00009190
public static byte[] ToCapiPublicKeyBlob(RSA rsa)
{
RSAParameters rsaparameters = rsa.ExportParameters(false);
int num = rsaparameters.Modulus.Length;
byte[] array = new byte[20 + num];
array[0] = 6;
array[1] = 2;
array[5] = 36;
array[8] = 82;
array[9] = 83;
array[10] = 65;
array[11] = 49;
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
array[12] = bytesLE[0];
array[13] = bytesLE[1];
array[14] = bytesLE[2];
array[15] = bytesLE[3];
int num2 = 16;
int i = rsaparameters.Exponent.Length;
while (i > 0)
{
array[num2++] = rsaparameters.Exponent[--i];
}
num2 = 20;
byte[] modulus = rsaparameters.Modulus;
int num3 = modulus.Length;
Array.Reverse(modulus, 0, num3);
Buffer.BlockCopy(modulus, 0, array, num2, num3);
num2 += num3;
return array;
}
// Token: 0x0600019A RID: 410 RVA: 0x0000B068 File Offset: 0x00009268
public static byte[] ToCapiPublicKeyBlob(DSA dsa)
{
DSAParameters dsaparameters = dsa.ExportParameters(false);
int num = dsaparameters.P.Length;
byte[] array = new byte[16 + num + 20 + num + num + 4 + 20];
array[0] = 6;
array[1] = 2;
array[5] = 34;
array[8] = 68;
array[9] = 83;
array[10] = 83;
array[11] = 49;
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
array[12] = bytesLE[0];
array[13] = bytesLE[1];
array[14] = bytesLE[2];
array[15] = bytesLE[3];
int num2 = 16;
byte[] array2 = dsaparameters.P;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, num);
num2 += num;
array2 = dsaparameters.Q;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, 20);
num2 += 20;
array2 = dsaparameters.G;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, num);
num2 += num;
array2 = dsaparameters.Y;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, num);
num2 += num;
Buffer.BlockCopy(CryptoConvert.GetBytesLE(dsaparameters.Counter), 0, array, num2, 4);
num2 += 4;
array2 = dsaparameters.Seed;
Array.Reverse(array2);
Buffer.BlockCopy(array2, 0, array, num2, 20);
return array;
}
// Token: 0x0600019B RID: 411 RVA: 0x0000B1B0 File Offset: 0x000093B0
public static RSA FromCapiKeyBlob(byte[] blob)
{
return CryptoConvert.FromCapiKeyBlob(blob, 0);
}
// Token: 0x0600019C RID: 412 RVA: 0x0000B1BC File Offset: 0x000093BC
public static RSA FromCapiKeyBlob(byte[] blob, int offset)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
if (offset >= blob.Length)
{
throw new ArgumentException("blob is too small.");
}
byte b = blob[offset];
if (b == 6)
{
return CryptoConvert.FromCapiPublicKeyBlob(blob, offset);
}
if (b != 7)
{
if (b == 0)
{
if (blob[offset + 12] == 6)
{
return CryptoConvert.FromCapiPublicKeyBlob(blob, offset + 12);
}
}
throw new CryptographicException("Unknown blob format.");
}
return CryptoConvert.FromCapiPrivateKeyBlob(blob, offset);
}
// Token: 0x0600019D RID: 413 RVA: 0x0000B244 File Offset: 0x00009444
public static DSA FromCapiKeyBlobDSA(byte[] blob)
{
return CryptoConvert.FromCapiKeyBlobDSA(blob, 0);
}
// Token: 0x0600019E RID: 414 RVA: 0x0000B250 File Offset: 0x00009450
public static DSA FromCapiKeyBlobDSA(byte[] blob, int offset)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
if (offset >= blob.Length)
{
throw new ArgumentException("blob is too small.");
}
byte b = blob[offset];
if (b == 6)
{
return CryptoConvert.FromCapiPublicKeyBlobDSA(blob, offset);
}
if (b != 7)
{
throw new CryptographicException("Unknown blob format.");
}
return CryptoConvert.FromCapiPrivateKeyBlobDSA(blob, offset);
}
// Token: 0x0600019F RID: 415 RVA: 0x0000B2B4 File Offset: 0x000094B4
public static byte[] ToCapiKeyBlob(AsymmetricAlgorithm keypair, bool includePrivateKey)
{
if (keypair == null)
{
throw new ArgumentNullException("keypair");
}
if (keypair is RSA)
{
return CryptoConvert.ToCapiKeyBlob((RSA)keypair, includePrivateKey);
}
if (keypair is DSA)
{
return CryptoConvert.ToCapiKeyBlob((DSA)keypair, includePrivateKey);
}
return null;
}
// Token: 0x060001A0 RID: 416 RVA: 0x0000B304 File Offset: 0x00009504
public static byte[] ToCapiKeyBlob(RSA rsa, bool includePrivateKey)
{
if (rsa == null)
{
throw new ArgumentNullException("rsa");
}
if (includePrivateKey)
{
return CryptoConvert.ToCapiPrivateKeyBlob(rsa);
}
return CryptoConvert.ToCapiPublicKeyBlob(rsa);
}
// Token: 0x060001A1 RID: 417 RVA: 0x0000B338 File Offset: 0x00009538
public static byte[] ToCapiKeyBlob(DSA dsa, bool includePrivateKey)
{
if (dsa == null)
{
throw new ArgumentNullException("dsa");
}
if (includePrivateKey)
{
return CryptoConvert.ToCapiPrivateKeyBlob(dsa);
}
return CryptoConvert.ToCapiPublicKeyBlob(dsa);
}
// Token: 0x060001A2 RID: 418 RVA: 0x0000B36C File Offset: 0x0000956C
public static string ToHex(byte[] input)
{
if (input == null)
{
return null;
}
StringBuilder stringBuilder = new StringBuilder(input.Length * 2);
foreach (byte b in input)
{
stringBuilder.Append(b.ToString("X2", CultureInfo.InvariantCulture));
}
return stringBuilder.ToString();
}
// Token: 0x060001A3 RID: 419 RVA: 0x0000B3C4 File Offset: 0x000095C4
private static byte FromHexChar(char c)
{
if (c >= 'a' && c <= 'f')
{
return (byte)(c - 'a' + '\n');
}
if (c >= 'A' && c <= 'F')
{
return (byte)(c - 'A' + '\n');
}
if (c >= '0' && c <= '9')
{
return (byte)(c - '0');
}
throw new ArgumentException("invalid hex char");
}
// Token: 0x060001A4 RID: 420 RVA: 0x0000B424 File Offset: 0x00009624
public static byte[] FromHex(string hex)
{
if (hex == null)
{
return null;
}
if ((hex.Length & 1) == 1)
{
throw new ArgumentException("Length must be a multiple of 2");
}
byte[] array = new byte[hex.Length >> 1];
int i = 0;
int num = 0;
while (i < array.Length)
{
array[i] = (byte)(CryptoConvert.FromHexChar(hex[num++]) << 4);
byte[] array2 = array;
int num2 = i++;
array2[num2] += CryptoConvert.FromHexChar(hex[num++]);
}
return array;
}
}
}
@@ -0,0 +1,13 @@
using System;
namespace Mono.Security.Cryptography
{
// Token: 0x02000027 RID: 39
public enum DHKeyGeneration
{
// Token: 0x040000B4 RID: 180
Random,
// Token: 0x040000B5 RID: 181
Static
}
}
@@ -0,0 +1,19 @@
using System;
namespace Mono.Security.Cryptography
{
// Token: 0x02000028 RID: 40
[Serializable]
public struct DHParameters
{
// Token: 0x040000B6 RID: 182
public byte[] P;
// Token: 0x040000B7 RID: 183
public byte[] G;
// Token: 0x040000B8 RID: 184
[NonSerialized]
public byte[] X;
}
}
@@ -0,0 +1,120 @@
using System;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using Mono.Xml;
namespace Mono.Security.Cryptography
{
// Token: 0x02000029 RID: 41
public abstract class DiffieHellman : AsymmetricAlgorithm
{
// Token: 0x060001B1 RID: 433 RVA: 0x0000B6CC File Offset: 0x000098CC
public new static DiffieHellman Create()
{
return DiffieHellman.Create("Mono.Security.Cryptography.DiffieHellman");
}
// Token: 0x060001B2 RID: 434 RVA: 0x0000B6D8 File Offset: 0x000098D8
public new static DiffieHellman Create(string algName)
{
return (DiffieHellman)CryptoConfig.CreateFromName(algName);
}
// Token: 0x060001B3 RID: 435
public abstract byte[] CreateKeyExchange();
// Token: 0x060001B4 RID: 436
public abstract byte[] DecryptKeyExchange(byte[] keyex);
// Token: 0x060001B5 RID: 437
public abstract DHParameters ExportParameters(bool includePrivate);
// Token: 0x060001B6 RID: 438
public abstract void ImportParameters(DHParameters parameters);
// Token: 0x060001B7 RID: 439 RVA: 0x0000B6E8 File Offset: 0x000098E8
private byte[] GetNamedParam(SecurityElement se, string param)
{
SecurityElement securityElement = se.SearchForChildByTag(param);
if (securityElement == null)
{
return null;
}
return Convert.FromBase64String(securityElement.Text);
}
// Token: 0x060001B8 RID: 440 RVA: 0x0000B710 File Offset: 0x00009910
public override void FromXmlString(string xmlString)
{
if (xmlString == null)
{
throw new ArgumentNullException("xmlString");
}
DHParameters dhparameters = default(DHParameters);
try
{
SecurityParser securityParser = new SecurityParser();
securityParser.LoadXml(xmlString);
SecurityElement securityElement = securityParser.ToXml();
if (securityElement.Tag != "DHKeyValue")
{
throw new CryptographicException();
}
dhparameters.P = this.GetNamedParam(securityElement, "P");
dhparameters.G = this.GetNamedParam(securityElement, "G");
dhparameters.X = this.GetNamedParam(securityElement, "X");
this.ImportParameters(dhparameters);
}
finally
{
if (dhparameters.P != null)
{
Array.Clear(dhparameters.P, 0, dhparameters.P.Length);
}
if (dhparameters.G != null)
{
Array.Clear(dhparameters.G, 0, dhparameters.G.Length);
}
if (dhparameters.X != null)
{
Array.Clear(dhparameters.X, 0, dhparameters.X.Length);
}
}
}
// Token: 0x060001B9 RID: 441 RVA: 0x0000B830 File Offset: 0x00009A30
public override string ToXmlString(bool includePrivateParameters)
{
StringBuilder stringBuilder = new StringBuilder();
DHParameters dhparameters = this.ExportParameters(includePrivateParameters);
try
{
stringBuilder.Append("<DHKeyValue>");
stringBuilder.Append("<P>");
stringBuilder.Append(Convert.ToBase64String(dhparameters.P));
stringBuilder.Append("</P>");
stringBuilder.Append("<G>");
stringBuilder.Append(Convert.ToBase64String(dhparameters.G));
stringBuilder.Append("</G>");
if (includePrivateParameters)
{
stringBuilder.Append("<X>");
stringBuilder.Append(Convert.ToBase64String(dhparameters.X));
stringBuilder.Append("</X>");
}
stringBuilder.Append("</DHKeyValue>");
}
finally
{
Array.Clear(dhparameters.P, 0, dhparameters.P.Length);
Array.Clear(dhparameters.G, 0, dhparameters.G.Length);
if (dhparameters.X != null)
{
Array.Clear(dhparameters.X, 0, dhparameters.X.Length);
}
}
return stringBuilder.ToString();
}
}
}
@@ -0,0 +1,279 @@
using System;
using System.Security.Cryptography;
using Mono.Math;
namespace Mono.Security.Cryptography
{
// Token: 0x0200002A RID: 42
public sealed class DiffieHellmanManaged : DiffieHellman
{
// Token: 0x060001BA RID: 442 RVA: 0x0000B960 File Offset: 0x00009B60
public DiffieHellmanManaged()
: this(1024, 160, DHKeyGeneration.Static)
{
}
// Token: 0x060001BB RID: 443 RVA: 0x0000B974 File Offset: 0x00009B74
public DiffieHellmanManaged(int bitLength, int l, DHKeyGeneration method)
{
if (bitLength < 256 || l < 0)
{
throw new ArgumentException();
}
BigInteger bigInteger;
BigInteger bigInteger2;
this.GenerateKey(bitLength, method, out bigInteger, out bigInteger2);
this.Initialize(bigInteger, bigInteger2, null, l, false);
}
// Token: 0x060001BC RID: 444 RVA: 0x0000B9B8 File Offset: 0x00009BB8
public DiffieHellmanManaged(byte[] p, byte[] g, byte[] x)
{
if (p == null || g == null)
{
throw new ArgumentNullException();
}
if (x == null)
{
this.Initialize(new BigInteger(p), new BigInteger(g), null, 0, true);
}
else
{
this.Initialize(new BigInteger(p), new BigInteger(g), new BigInteger(x), 0, true);
}
}
// Token: 0x060001BD RID: 445 RVA: 0x0000BA18 File Offset: 0x00009C18
public DiffieHellmanManaged(byte[] p, byte[] g, int l)
{
if (p == null || g == null)
{
throw new ArgumentNullException();
}
if (l < 0)
{
throw new ArgumentException();
}
this.Initialize(new BigInteger(p), new BigInteger(g), null, l, true);
}
// Token: 0x060001BF RID: 447 RVA: 0x0000BAB8 File Offset: 0x00009CB8
private void Initialize(BigInteger p, BigInteger g, BigInteger x, int secretLen, bool checkInput)
{
if (checkInput && (!p.IsProbablePrime() || g <= 0 || g >= p || (x != null && (x <= 0 || x > p - 2))))
{
throw new CryptographicException();
}
if (secretLen == 0)
{
secretLen = p.BitCount();
}
this.m_P = p;
this.m_G = g;
if (x == null)
{
BigInteger bigInteger = this.m_P - 1;
this.m_X = BigInteger.GenerateRandom(secretLen);
while (this.m_X >= bigInteger || this.m_X == 0U)
{
this.m_X = BigInteger.GenerateRandom(secretLen);
}
}
else
{
this.m_X = x;
}
}
// Token: 0x060001C0 RID: 448 RVA: 0x0000BBB8 File Offset: 0x00009DB8
public override byte[] CreateKeyExchange()
{
BigInteger bigInteger = this.m_G.ModPow(this.m_X, this.m_P);
byte[] bytes = bigInteger.GetBytes();
bigInteger.Clear();
return bytes;
}
// Token: 0x060001C1 RID: 449 RVA: 0x0000BBEC File Offset: 0x00009DEC
public override byte[] DecryptKeyExchange(byte[] keyEx)
{
BigInteger bigInteger = new BigInteger(keyEx);
BigInteger bigInteger2 = bigInteger.ModPow(this.m_X, this.m_P);
byte[] bytes = bigInteger2.GetBytes();
bigInteger2.Clear();
return bytes;
}
// Token: 0x1700005C RID: 92
// (get) Token: 0x060001C2 RID: 450 RVA: 0x0000BC24 File Offset: 0x00009E24
public override string KeyExchangeAlgorithm
{
get
{
return "1.2.840.113549.1.3";
}
}
// Token: 0x1700005D RID: 93
// (get) Token: 0x060001C3 RID: 451 RVA: 0x0000BC2C File Offset: 0x00009E2C
public override string SignatureAlgorithm
{
get
{
return null;
}
}
// Token: 0x060001C4 RID: 452 RVA: 0x0000BC30 File Offset: 0x00009E30
protected override void Dispose(bool disposing)
{
if (!this.m_Disposed)
{
this.m_P.Clear();
this.m_G.Clear();
this.m_X.Clear();
}
this.m_Disposed = true;
}
// Token: 0x060001C5 RID: 453 RVA: 0x0000BC68 File Offset: 0x00009E68
public override DHParameters ExportParameters(bool includePrivateParameters)
{
DHParameters dhparameters = default(DHParameters);
dhparameters.P = this.m_P.GetBytes();
dhparameters.G = this.m_G.GetBytes();
if (includePrivateParameters)
{
dhparameters.X = this.m_X.GetBytes();
}
return dhparameters;
}
// Token: 0x060001C6 RID: 454 RVA: 0x0000BCBC File Offset: 0x00009EBC
public override void ImportParameters(DHParameters parameters)
{
if (parameters.P == null)
{
throw new CryptographicException("Missing P value.");
}
if (parameters.G == null)
{
throw new CryptographicException("Missing G value.");
}
BigInteger bigInteger = new BigInteger(parameters.P);
BigInteger bigInteger2 = new BigInteger(parameters.G);
BigInteger bigInteger3 = null;
if (parameters.X != null)
{
bigInteger3 = new BigInteger(parameters.X);
}
this.Initialize(bigInteger, bigInteger2, bigInteger3, 0, true);
}
// Token: 0x060001C7 RID: 455 RVA: 0x0000BD38 File Offset: 0x00009F38
~DiffieHellmanManaged()
{
this.Dispose(false);
}
// Token: 0x060001C8 RID: 456 RVA: 0x0000BD74 File Offset: 0x00009F74
private void GenerateKey(int bitlen, DHKeyGeneration keygen, out BigInteger p, out BigInteger g)
{
if (keygen == DHKeyGeneration.Static)
{
if (bitlen == 768)
{
p = new BigInteger(DiffieHellmanManaged.m_OAKLEY768);
}
else if (bitlen == 1024)
{
p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1024);
}
else
{
if (bitlen != 1536)
{
throw new ArgumentException("Invalid bit size.");
}
p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1536);
}
g = new BigInteger(22U);
}
else
{
p = BigInteger.GeneratePseudoPrime(bitlen);
g = new BigInteger(3U);
}
}
// Token: 0x040000B9 RID: 185
private BigInteger m_P;
// Token: 0x040000BA RID: 186
private BigInteger m_G;
// Token: 0x040000BB RID: 187
private BigInteger m_X;
// Token: 0x040000BC RID: 188
private bool m_Disposed;
// Token: 0x040000BD RID: 189
private static byte[] m_OAKLEY768 = new byte[]
{
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, 201, 15,
218, 162, 33, 104, 194, 52, 196, 198, 98, 139,
128, 220, 28, 209, 41, 2, 78, 8, 138, 103,
204, 116, 2, 11, 190, 166, 59, 19, 155, 34,
81, 74, 8, 121, 142, 52, 4, 221, 239, 149,
25, 179, 205, 58, 67, 27, 48, 43, 10, 109,
242, 95, 20, 55, 79, 225, 53, 109, 109, 81,
194, 69, 228, 133, 181, 118, 98, 94, 126, 198,
244, 76, 66, 233, 166, 58, 54, 32, byte.MaxValue, byte.MaxValue,
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue
};
// Token: 0x040000BE RID: 190
private static byte[] m_OAKLEY1024 = new byte[]
{
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, 201, 15,
218, 162, 33, 104, 194, 52, 196, 198, 98, 139,
128, 220, 28, 209, 41, 2, 78, 8, 138, 103,
204, 116, 2, 11, 190, 166, 59, 19, 155, 34,
81, 74, 8, 121, 142, 52, 4, 221, 239, 149,
25, 179, 205, 58, 67, 27, 48, 43, 10, 109,
242, 95, 20, 55, 79, 225, 53, 109, 109, 81,
194, 69, 228, 133, 181, 118, 98, 94, 126, 198,
244, 76, 66, 233, 166, 55, 237, 107, 11, byte.MaxValue,
92, 182, 244, 6, 183, 237, 238, 56, 107, 251,
90, 137, 159, 165, 174, 159, 36, 17, 124, 75,
31, 230, 73, 40, 102, 81, 236, 230, 83, 129,
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue
};
// Token: 0x040000BF RID: 191
private static byte[] m_OAKLEY1536 = new byte[]
{
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, 201, 15,
218, 162, 33, 104, 194, 52, 196, 198, 98, 139,
128, 220, 28, 209, 41, 2, 78, 8, 138, 103,
204, 116, 2, 11, 190, 166, 59, 19, 155, 34,
81, 74, 8, 121, 142, 52, 4, 221, 239, 149,
25, 179, 205, 58, 67, 27, 48, 43, 10, 109,
242, 95, 20, 55, 79, 225, 53, 109, 109, 81,
194, 69, 228, 133, 181, 118, 98, 94, 126, 198,
244, 76, 66, 233, 166, 55, 237, 107, 11, byte.MaxValue,
92, 182, 244, 6, 183, 237, 238, 56, 107, 251,
90, 137, 159, 165, 174, 159, 36, 17, 124, 75,
31, 230, 73, 40, 102, 81, 236, 228, 91, 61,
194, 0, 124, 184, 161, 99, 191, 5, 152, 218,
72, 54, 28, 85, 211, 154, 105, 22, 63, 168,
253, 36, 207, 95, 131, 101, 93, 35, 220, 163,
173, 150, 28, 98, 243, 86, 32, 133, 82, 187,
158, 213, 41, 7, 112, 150, 150, 109, 103, 12,
53, 78, 74, 188, 152, 4, 241, 116, 108, 8,
202, 35, 115, 39, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue,
byte.MaxValue, byte.MaxValue
};
}
}
+133
View File
@@ -0,0 +1,133 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000074 RID: 116
internal class HMAC : KeyedHashAlgorithm
{
// Token: 0x06000429 RID: 1065 RVA: 0x0001AE98 File Offset: 0x00019098
public HMAC()
{
this.hash = MD5.Create();
this.HashSizeValue = this.hash.HashSize;
byte[] array = new byte[64];
RNGCryptoServiceProvider rngcryptoServiceProvider = new RNGCryptoServiceProvider();
rngcryptoServiceProvider.GetNonZeroBytes(array);
this.KeyValue = (byte[])array.Clone();
this.Initialize();
}
// Token: 0x0600042A RID: 1066 RVA: 0x0001AEF4 File Offset: 0x000190F4
public HMAC(string hashName, byte[] rgbKey)
{
if (hashName == null || hashName.Length == 0)
{
hashName = "MD5";
}
this.hash = HashAlgorithm.Create(hashName);
this.HashSizeValue = this.hash.HashSize;
if (rgbKey.Length > 64)
{
this.KeyValue = this.hash.ComputeHash(rgbKey);
}
else
{
this.KeyValue = (byte[])rgbKey.Clone();
}
this.Initialize();
}
// Token: 0x170000F4 RID: 244
// (get) Token: 0x0600042B RID: 1067 RVA: 0x0001AF74 File Offset: 0x00019174
// (set) Token: 0x0600042C RID: 1068 RVA: 0x0001AF88 File Offset: 0x00019188
public override byte[] Key
{
get
{
return (byte[])this.KeyValue.Clone();
}
set
{
if (this.hashing)
{
throw new Exception("Cannot change key during hash operation.");
}
if (value.Length > 64)
{
this.KeyValue = this.hash.ComputeHash(value);
}
else
{
this.KeyValue = (byte[])value.Clone();
}
this.initializePad();
}
}
// Token: 0x0600042D RID: 1069 RVA: 0x0001AFE4 File Offset: 0x000191E4
public override void Initialize()
{
this.hash.Initialize();
this.initializePad();
this.hashing = false;
}
// Token: 0x0600042E RID: 1070 RVA: 0x0001B000 File Offset: 0x00019200
protected override byte[] HashFinal()
{
if (!this.hashing)
{
this.hash.TransformBlock(this.innerPad, 0, this.innerPad.Length, this.innerPad, 0);
this.hashing = true;
}
this.hash.TransformFinalBlock(new byte[0], 0, 0);
byte[] array = this.hash.Hash;
this.hash.Initialize();
this.hash.TransformBlock(this.outerPad, 0, this.outerPad.Length, this.outerPad, 0);
this.hash.TransformFinalBlock(array, 0, array.Length);
this.Initialize();
return this.hash.Hash;
}
// Token: 0x0600042F RID: 1071 RVA: 0x0001B0B0 File Offset: 0x000192B0
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
if (!this.hashing)
{
this.hash.TransformBlock(this.innerPad, 0, this.innerPad.Length, this.innerPad, 0);
this.hashing = true;
}
this.hash.TransformBlock(array, ibStart, cbSize, array, ibStart);
}
// Token: 0x06000430 RID: 1072 RVA: 0x0001B104 File Offset: 0x00019304
private void initializePad()
{
this.innerPad = new byte[64];
this.outerPad = new byte[64];
for (int i = 0; i < this.KeyValue.Length; i++)
{
this.innerPad[i] = this.KeyValue[i] ^ 54;
this.outerPad[i] = this.KeyValue[i] ^ 92;
}
for (int j = this.KeyValue.Length; j < 64; j++)
{
this.innerPad[j] = 54;
this.outerPad[j] = 92;
}
}
// Token: 0x040001F1 RID: 497
private HashAlgorithm hash;
// Token: 0x040001F2 RID: 498
private bool hashing;
// Token: 0x040001F3 RID: 499
private byte[] innerPad;
// Token: 0x040001F4 RID: 500
private byte[] outerPad;
}
}
@@ -0,0 +1,47 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000025 RID: 37
public sealed class KeyBuilder
{
// Token: 0x060001A5 RID: 421 RVA: 0x0000B4AC File Offset: 0x000096AC
private KeyBuilder()
{
}
// Token: 0x1700005B RID: 91
// (get) Token: 0x060001A6 RID: 422 RVA: 0x0000B4B4 File Offset: 0x000096B4
private static RandomNumberGenerator Rng
{
get
{
if (KeyBuilder.rng == null)
{
KeyBuilder.rng = RandomNumberGenerator.Create();
}
return KeyBuilder.rng;
}
}
// Token: 0x060001A7 RID: 423 RVA: 0x0000B4D0 File Offset: 0x000096D0
public static byte[] Key(int size)
{
byte[] array = new byte[size];
KeyBuilder.Rng.GetBytes(array);
return array;
}
// Token: 0x060001A8 RID: 424 RVA: 0x0000B4F0 File Offset: 0x000096F0
public static byte[] IV(int size)
{
byte[] array = new byte[size];
KeyBuilder.Rng.GetBytes(array);
return array;
}
// Token: 0x040000AE RID: 174
private static RandomNumberGenerator rng;
}
}
@@ -0,0 +1,395 @@
using System;
using System.Globalization;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using Mono.Xml;
namespace Mono.Security.Cryptography
{
// Token: 0x0200002B RID: 43
public class KeyPairPersistence
{
// Token: 0x060001C9 RID: 457 RVA: 0x0000BE08 File Offset: 0x0000A008
public KeyPairPersistence(CspParameters parameters)
: this(parameters, null)
{
}
// Token: 0x060001CA RID: 458 RVA: 0x0000BE14 File Offset: 0x0000A014
public KeyPairPersistence(CspParameters parameters, string keyPair)
{
if (parameters == null)
{
throw new ArgumentNullException("parameters");
}
this._params = this.Copy(parameters);
this._keyvalue = keyPair;
}
// Token: 0x1700005E RID: 94
// (get) Token: 0x060001CC RID: 460 RVA: 0x0000BE5C File Offset: 0x0000A05C
public string Filename
{
get
{
if (this._filename == null)
{
this._filename = string.Format(CultureInfo.InvariantCulture, "[{0}][{1}][{2}].xml", new object[]
{
this._params.ProviderType,
this.ContainerName,
this._params.KeyNumber
});
if (this.UseMachineKeyStore)
{
this._filename = Path.Combine(KeyPairPersistence.MachinePath, this._filename);
}
else
{
this._filename = Path.Combine(KeyPairPersistence.UserPath, this._filename);
}
}
return this._filename;
}
}
// Token: 0x1700005F RID: 95
// (get) Token: 0x060001CD RID: 461 RVA: 0x0000BF00 File Offset: 0x0000A100
// (set) Token: 0x060001CE RID: 462 RVA: 0x0000BF08 File Offset: 0x0000A108
public string KeyValue
{
get
{
return this._keyvalue;
}
set
{
if (this.CanChange)
{
this._keyvalue = value;
}
}
}
// Token: 0x17000060 RID: 96
// (get) Token: 0x060001CF RID: 463 RVA: 0x0000BF1C File Offset: 0x0000A11C
public CspParameters Parameters
{
get
{
return this.Copy(this._params);
}
}
// Token: 0x060001D0 RID: 464 RVA: 0x0000BF2C File Offset: 0x0000A12C
public bool Load()
{
bool flag = File.Exists(this.Filename);
if (flag)
{
using (StreamReader streamReader = File.OpenText(this.Filename))
{
this.FromXml(streamReader.ReadToEnd());
}
}
return flag;
}
// Token: 0x060001D1 RID: 465 RVA: 0x0000BF94 File Offset: 0x0000A194
public void Save()
{
using (FileStream fileStream = File.Open(this.Filename, FileMode.Create))
{
StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8);
streamWriter.Write(this.ToXml());
streamWriter.Close();
}
if (this.UseMachineKeyStore)
{
KeyPairPersistence.ProtectMachine(this.Filename);
}
else
{
KeyPairPersistence.ProtectUser(this.Filename);
}
}
// Token: 0x060001D2 RID: 466 RVA: 0x0000C024 File Offset: 0x0000A224
public void Remove()
{
File.Delete(this.Filename);
}
// Token: 0x17000061 RID: 97
// (get) Token: 0x060001D3 RID: 467 RVA: 0x0000C034 File Offset: 0x0000A234
private static string UserPath
{
get
{
object obj = KeyPairPersistence.lockobj;
lock (obj)
{
if (KeyPairPersistence._userPath == null || !KeyPairPersistence._userPathExists)
{
KeyPairPersistence._userPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".mono");
KeyPairPersistence._userPath = Path.Combine(KeyPairPersistence._userPath, "keypairs");
KeyPairPersistence._userPathExists = Directory.Exists(KeyPairPersistence._userPath);
if (!KeyPairPersistence._userPathExists)
{
try
{
Directory.CreateDirectory(KeyPairPersistence._userPath);
KeyPairPersistence.ProtectUser(KeyPairPersistence._userPath);
KeyPairPersistence._userPathExists = true;
}
catch (Exception ex)
{
string text = Locale.GetText("Could not create user key store '{0}'.");
throw new CryptographicException(string.Format(text, KeyPairPersistence._userPath), ex);
}
}
}
}
if (!KeyPairPersistence.IsUserProtected(KeyPairPersistence._userPath))
{
string text2 = Locale.GetText("Improperly protected user's key pairs in '{0}'.");
throw new CryptographicException(string.Format(text2, KeyPairPersistence._userPath));
}
return KeyPairPersistence._userPath;
}
}
// Token: 0x17000062 RID: 98
// (get) Token: 0x060001D4 RID: 468 RVA: 0x0000C158 File Offset: 0x0000A358
private static string MachinePath
{
get
{
object obj = KeyPairPersistence.lockobj;
lock (obj)
{
if (KeyPairPersistence._machinePath == null || !KeyPairPersistence._machinePathExists)
{
KeyPairPersistence._machinePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), ".mono");
KeyPairPersistence._machinePath = Path.Combine(KeyPairPersistence._machinePath, "keypairs");
KeyPairPersistence._machinePathExists = Directory.Exists(KeyPairPersistence._machinePath);
if (!KeyPairPersistence._machinePathExists)
{
try
{
Directory.CreateDirectory(KeyPairPersistence._machinePath);
KeyPairPersistence.ProtectMachine(KeyPairPersistence._machinePath);
KeyPairPersistence._machinePathExists = true;
}
catch (Exception ex)
{
string text = Locale.GetText("Could not create machine key store '{0}'.");
throw new CryptographicException(string.Format(text, KeyPairPersistence._machinePath), ex);
}
}
}
}
if (!KeyPairPersistence.IsMachineProtected(KeyPairPersistence._machinePath))
{
string text2 = Locale.GetText("Improperly protected machine's key pairs in '{0}'.");
throw new CryptographicException(string.Format(text2, KeyPairPersistence._machinePath));
}
return KeyPairPersistence._machinePath;
}
}
// Token: 0x060001D5 RID: 469 RVA: 0x0000C27C File Offset: 0x0000A47C
internal static bool _CanSecure(string root)
{
return true;
}
// Token: 0x060001D6 RID: 470 RVA: 0x0000C280 File Offset: 0x0000A480
internal static bool _ProtectUser(string path)
{
return true;
}
// Token: 0x060001D7 RID: 471 RVA: 0x0000C284 File Offset: 0x0000A484
internal static bool _ProtectMachine(string path)
{
return true;
}
// Token: 0x060001D8 RID: 472 RVA: 0x0000C288 File Offset: 0x0000A488
internal static bool _IsUserProtected(string path)
{
return true;
}
// Token: 0x060001D9 RID: 473 RVA: 0x0000C28C File Offset: 0x0000A48C
internal static bool _IsMachineProtected(string path)
{
return true;
}
// Token: 0x060001DA RID: 474 RVA: 0x0000C290 File Offset: 0x0000A490
private static bool CanSecure(string path)
{
int platform = (int)Environment.OSVersion.Platform;
return platform == 4 || platform == 128 || platform == 6 || KeyPairPersistence._CanSecure(Path.GetPathRoot(path));
}
// Token: 0x060001DB RID: 475 RVA: 0x0000C2D0 File Offset: 0x0000A4D0
private static bool ProtectUser(string path)
{
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectUser(path);
}
// Token: 0x060001DC RID: 476 RVA: 0x0000C2E8 File Offset: 0x0000A4E8
private static bool ProtectMachine(string path)
{
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectMachine(path);
}
// Token: 0x060001DD RID: 477 RVA: 0x0000C300 File Offset: 0x0000A500
private static bool IsUserProtected(string path)
{
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsUserProtected(path);
}
// Token: 0x060001DE RID: 478 RVA: 0x0000C318 File Offset: 0x0000A518
private static bool IsMachineProtected(string path)
{
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsMachineProtected(path);
}
// Token: 0x17000063 RID: 99
// (get) Token: 0x060001DF RID: 479 RVA: 0x0000C330 File Offset: 0x0000A530
private bool CanChange
{
get
{
return this._keyvalue == null;
}
}
// Token: 0x17000064 RID: 100
// (get) Token: 0x060001E0 RID: 480 RVA: 0x0000C33C File Offset: 0x0000A53C
private bool UseDefaultKeyContainer
{
get
{
return (this._params.Flags & CspProviderFlags.UseDefaultKeyContainer) == CspProviderFlags.UseDefaultKeyContainer;
}
}
// Token: 0x17000065 RID: 101
// (get) Token: 0x060001E1 RID: 481 RVA: 0x0000C350 File Offset: 0x0000A550
private bool UseMachineKeyStore
{
get
{
return (this._params.Flags & CspProviderFlags.UseMachineKeyStore) == CspProviderFlags.UseMachineKeyStore;
}
}
// Token: 0x17000066 RID: 102
// (get) Token: 0x060001E2 RID: 482 RVA: 0x0000C364 File Offset: 0x0000A564
private string ContainerName
{
get
{
if (this._container == null)
{
if (this.UseDefaultKeyContainer)
{
this._container = "default";
}
else if (this._params.KeyContainerName == null || this._params.KeyContainerName.Length == 0)
{
this._container = Guid.NewGuid().ToString();
}
else
{
byte[] bytes = Encoding.UTF8.GetBytes(this._params.KeyContainerName);
MD5 md = MD5.Create();
byte[] array = md.ComputeHash(bytes);
Guid guid = new Guid(array);
this._container = guid.ToString();
}
}
return this._container;
}
}
// Token: 0x060001E3 RID: 483 RVA: 0x0000C414 File Offset: 0x0000A614
private CspParameters Copy(CspParameters p)
{
return new CspParameters(p.ProviderType, p.ProviderName, p.KeyContainerName)
{
KeyNumber = p.KeyNumber,
Flags = p.Flags
};
}
// Token: 0x060001E4 RID: 484 RVA: 0x0000C454 File Offset: 0x0000A654
private void FromXml(string xml)
{
SecurityParser securityParser = new SecurityParser();
securityParser.LoadXml(xml);
SecurityElement securityElement = securityParser.ToXml();
if (securityElement.Tag == "KeyPair")
{
SecurityElement securityElement2 = securityElement.SearchForChildByTag("KeyValue");
if (securityElement2.Children.Count > 0)
{
this._keyvalue = securityElement2.Children[0].ToString();
}
}
}
// Token: 0x060001E5 RID: 485 RVA: 0x0000C4C0 File Offset: 0x0000A6C0
private string ToXml()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("<KeyPair>{0}\t<Properties>{0}\t\t<Provider ", Environment.NewLine);
if (this._params.ProviderName != null && this._params.ProviderName.Length != 0)
{
stringBuilder.AppendFormat("Name=\"{0}\" ", this._params.ProviderName);
}
stringBuilder.AppendFormat("Type=\"{0}\" />{1}\t\t<Container ", this._params.ProviderType, Environment.NewLine);
stringBuilder.AppendFormat("Name=\"{0}\" />{1}\t</Properties>{1}\t<KeyValue", this.ContainerName, Environment.NewLine);
if (this._params.KeyNumber != -1)
{
stringBuilder.AppendFormat(" Id=\"{0}\" ", this._params.KeyNumber);
}
stringBuilder.AppendFormat(">{1}\t\t{0}{1}\t</KeyValue>{1}</KeyPair>{1}", this.KeyValue, Environment.NewLine);
return stringBuilder.ToString();
}
// Token: 0x040000C0 RID: 192
private static bool _userPathExists = false;
// Token: 0x040000C1 RID: 193
private static string _userPath;
// Token: 0x040000C2 RID: 194
private static bool _machinePathExists = false;
// Token: 0x040000C3 RID: 195
private static string _machinePath;
// Token: 0x040000C4 RID: 196
private CspParameters _params;
// Token: 0x040000C5 RID: 197
private string _keyvalue;
// Token: 0x040000C6 RID: 198
private string _filename;
// Token: 0x040000C7 RID: 199
private string _container;
// Token: 0x040000C8 RID: 200
private static object lockobj = new object();
}
}
@@ -0,0 +1,32 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x0200002C RID: 44
public abstract class MD2 : HashAlgorithm
{
// Token: 0x060001E6 RID: 486 RVA: 0x0000C5A4 File Offset: 0x0000A7A4
protected MD2()
{
this.HashSizeValue = 128;
}
// Token: 0x060001E7 RID: 487 RVA: 0x0000C5B8 File Offset: 0x0000A7B8
public new static MD2 Create()
{
return MD2.Create("MD2");
}
// Token: 0x060001E8 RID: 488 RVA: 0x0000C5C4 File Offset: 0x0000A7C4
public new static MD2 Create(string hashName)
{
object obj = CryptoConfig.CreateFromName(hashName);
if (obj == null)
{
obj = new MD2Managed();
}
return (MD2)obj;
}
}
}
@@ -0,0 +1,159 @@
using System;
namespace Mono.Security.Cryptography
{
// Token: 0x0200002D RID: 45
public class MD2Managed : MD2
{
// Token: 0x060001E9 RID: 489 RVA: 0x0000C5EC File Offset: 0x0000A7EC
public MD2Managed()
{
this.state = new byte[16];
this.checksum = new byte[16];
this.buffer = new byte[16];
this.x = new byte[48];
this.Initialize();
}
// Token: 0x060001EB RID: 491 RVA: 0x0000C658 File Offset: 0x0000A858
private byte[] Padding(int nLength)
{
if (nLength > 0)
{
byte[] array = new byte[nLength];
for (int i = 0; i < array.Length; i++)
{
array[i] = (byte)nLength;
}
return array;
}
return null;
}
// Token: 0x060001EC RID: 492 RVA: 0x0000C690 File Offset: 0x0000A890
public override void Initialize()
{
this.count = 0;
Array.Clear(this.state, 0, 16);
Array.Clear(this.checksum, 0, 16);
Array.Clear(this.buffer, 0, 16);
Array.Clear(this.x, 0, 48);
}
// Token: 0x060001ED RID: 493 RVA: 0x0000C6DC File Offset: 0x0000A8DC
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
int num = this.count;
this.count = (num + cbSize) & 15;
int num2 = 16 - num;
int num3;
if (cbSize >= num2)
{
Buffer.BlockCopy(array, ibStart, this.buffer, num, num2);
this.MD2Transform(this.state, this.checksum, this.buffer, 0);
num3 = num2;
while (num3 + 15 < cbSize)
{
this.MD2Transform(this.state, this.checksum, array, num3);
num3 += 16;
}
num = 0;
}
else
{
num3 = 0;
}
Buffer.BlockCopy(array, ibStart + num3, this.buffer, num, cbSize - num3);
}
// Token: 0x060001EE RID: 494 RVA: 0x0000C778 File Offset: 0x0000A978
protected override byte[] HashFinal()
{
int num = this.count;
int num2 = 16 - num;
if (num2 > 0)
{
this.HashCore(this.Padding(num2), 0, num2);
}
this.HashCore(this.checksum, 0, 16);
byte[] array = (byte[])this.state.Clone();
this.Initialize();
return array;
}
// Token: 0x060001EF RID: 495 RVA: 0x0000C7D0 File Offset: 0x0000A9D0
private void MD2Transform(byte[] state, byte[] checksum, byte[] block, int index)
{
Buffer.BlockCopy(state, 0, this.x, 0, 16);
Buffer.BlockCopy(block, index, this.x, 16, 16);
for (int i = 0; i < 16; i++)
{
this.x[i + 32] = state[i] ^ block[index + i];
}
int num = 0;
for (int j = 0; j < 18; j++)
{
for (int k = 0; k < 48; k++)
{
byte[] array = this.x;
int num2 = k;
num = (int)(array[num2] ^= MD2Managed.PI_SUBST[num]);
}
num = (num + j) & 255;
}
Buffer.BlockCopy(this.x, 0, state, 0, 16);
num = (int)checksum[15];
for (int l = 0; l < 16; l++)
{
int num3 = l;
num = (int)(checksum[num3] ^= MD2Managed.PI_SUBST[(int)block[index + l] ^ num]);
}
}
// Token: 0x040000C9 RID: 201
private byte[] state;
// Token: 0x040000CA RID: 202
private byte[] checksum;
// Token: 0x040000CB RID: 203
private byte[] buffer;
// Token: 0x040000CC RID: 204
private int count;
// Token: 0x040000CD RID: 205
private byte[] x;
// Token: 0x040000CE RID: 206
private static readonly byte[] PI_SUBST = new byte[]
{
41, 46, 67, 201, 162, 216, 124, 1, 61, 54,
84, 161, 236, 240, 6, 19, 98, 167, 5, 243,
192, 199, 115, 140, 152, 147, 43, 217, 188, 76,
130, 202, 30, 155, 87, 60, 253, 212, 224, 22,
103, 66, 111, 24, 138, 23, 229, 18, 190, 78,
196, 214, 218, 158, 222, 73, 160, 251, 245, 142,
187, 47, 238, 122, 169, 104, 121, 145, 21, 178,
7, 63, 148, 194, 16, 137, 11, 34, 95, 33,
128, 127, 93, 154, 90, 144, 50, 39, 53, 62,
204, 231, 191, 247, 151, 3, byte.MaxValue, 25, 48, 179,
72, 165, 181, 209, 215, 94, 146, 42, 172, 86,
170, 198, 79, 184, 56, 210, 150, 164, 125, 182,
118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
112, 89, 100, 113, 135, 32, 134, 91, 207, 101,
230, 45, 168, 2, 27, 96, 37, 173, 174, 176,
185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
85, 71, 163, 35, 221, 81, 175, 58, 195, 92,
249, 206, 186, 197, 234, 38, 44, 83, 13, 110,
133, 40, 132, 9, 211, 223, 205, 244, 65, 129,
77, 82, 106, 220, 55, 200, 108, 193, 171, 250,
36, 225, 123, 8, 12, 189, 177, 74, 120, 136,
149, 139, 227, 99, 232, 109, 233, 203, 213, 254,
59, 0, 29, 57, 242, 239, 183, 14, 102, 88,
208, 228, 166, 119, 114, 248, 235, 117, 75, 10,
49, 68, 80, 180, 143, 237, 31, 26, 219, 153,
141, 51, 159, 17, 131, 20
};
}
}
@@ -0,0 +1,32 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x0200002E RID: 46
public abstract class MD4 : HashAlgorithm
{
// Token: 0x060001F0 RID: 496 RVA: 0x0000C8C8 File Offset: 0x0000AAC8
protected MD4()
{
this.HashSizeValue = 128;
}
// Token: 0x060001F1 RID: 497 RVA: 0x0000C8DC File Offset: 0x0000AADC
public new static MD4 Create()
{
return MD4.Create("MD4");
}
// Token: 0x060001F2 RID: 498 RVA: 0x0000C8E8 File Offset: 0x0000AAE8
public new static MD4 Create(string hashName)
{
object obj = CryptoConfig.CreateFromName(hashName);
if (obj == null)
{
obj = new MD4Managed();
}
return (MD4)obj;
}
}
}
@@ -0,0 +1,270 @@
using System;
namespace Mono.Security.Cryptography
{
// Token: 0x0200002F RID: 47
public class MD4Managed : MD4
{
// Token: 0x060001F3 RID: 499 RVA: 0x0000C910 File Offset: 0x0000AB10
public MD4Managed()
{
this.state = new uint[4];
this.count = new uint[2];
this.buffer = new byte[64];
this.digest = new byte[16];
this.x = new uint[16];
this.Initialize();
}
// Token: 0x060001F4 RID: 500 RVA: 0x0000C968 File Offset: 0x0000AB68
public override void Initialize()
{
this.count[0] = 0U;
this.count[1] = 0U;
this.state[0] = 1732584193U;
this.state[1] = 4023233417U;
this.state[2] = 2562383102U;
this.state[3] = 271733878U;
Array.Clear(this.buffer, 0, 64);
Array.Clear(this.x, 0, 16);
}
// Token: 0x060001F5 RID: 501 RVA: 0x0000C9D8 File Offset: 0x0000ABD8
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
int num = (int)((this.count[0] >> 3) & 63U);
this.count[0] += (uint)((uint)cbSize << 3);
if ((ulong)this.count[0] < (ulong)((long)((long)cbSize << 3)))
{
this.count[1] += 1U;
}
this.count[1] += (uint)(cbSize >> 29);
int num2 = 64 - num;
int num3 = 0;
if (cbSize >= num2)
{
Buffer.BlockCopy(array, ibStart, this.buffer, num, num2);
this.MD4Transform(this.state, this.buffer, 0);
num3 = num2;
while (num3 + 63 < cbSize)
{
this.MD4Transform(this.state, array, num3);
num3 += 64;
}
num = 0;
}
Buffer.BlockCopy(array, ibStart + num3, this.buffer, num, cbSize - num3);
}
// Token: 0x060001F6 RID: 502 RVA: 0x0000CAA8 File Offset: 0x0000ACA8
protected override byte[] HashFinal()
{
byte[] array = new byte[8];
this.Encode(array, this.count);
uint num = (this.count[0] >> 3) & 63U;
int num2 = (int)((num >= 56U) ? (120U - num) : (56U - num));
this.HashCore(this.Padding(num2), 0, num2);
this.HashCore(array, 0, 8);
this.Encode(this.digest, this.state);
this.Initialize();
return this.digest;
}
// Token: 0x060001F7 RID: 503 RVA: 0x0000CB24 File Offset: 0x0000AD24
private byte[] Padding(int nLength)
{
if (nLength > 0)
{
byte[] array = new byte[nLength];
array[0] = 128;
return array;
}
return null;
}
// Token: 0x060001F8 RID: 504 RVA: 0x0000CB4C File Offset: 0x0000AD4C
private uint F(uint x, uint y, uint z)
{
return (x & y) | (~x & z);
}
// Token: 0x060001F9 RID: 505 RVA: 0x0000CB58 File Offset: 0x0000AD58
private uint G(uint x, uint y, uint z)
{
return (x & y) | (x & z) | (y & z);
}
// Token: 0x060001FA RID: 506 RVA: 0x0000CB68 File Offset: 0x0000AD68
private uint H(uint x, uint y, uint z)
{
return x ^ y ^ z;
}
// Token: 0x060001FB RID: 507 RVA: 0x0000CB70 File Offset: 0x0000AD70
private uint ROL(uint x, byte n)
{
return (x << (int)n) | (x >> (int)(32 - n));
}
// Token: 0x060001FC RID: 508 RVA: 0x0000CB84 File Offset: 0x0000AD84
private void FF(ref uint a, uint b, uint c, uint d, uint x, byte s)
{
a += this.F(b, c, d) + x;
a = this.ROL(a, s);
}
// Token: 0x060001FD RID: 509 RVA: 0x0000CBA4 File Offset: 0x0000ADA4
private void GG(ref uint a, uint b, uint c, uint d, uint x, byte s)
{
a += this.G(b, c, d) + x + 1518500249U;
a = this.ROL(a, s);
}
// Token: 0x060001FE RID: 510 RVA: 0x0000CBD8 File Offset: 0x0000ADD8
private void HH(ref uint a, uint b, uint c, uint d, uint x, byte s)
{
a += this.H(b, c, d) + x + 1859775393U;
a = this.ROL(a, s);
}
// Token: 0x060001FF RID: 511 RVA: 0x0000CC0C File Offset: 0x0000AE0C
private void Encode(byte[] output, uint[] input)
{
int num = 0;
for (int i = 0; i < output.Length; i += 4)
{
output[i] = (byte)input[num];
output[i + 1] = (byte)(input[num] >> 8);
output[i + 2] = (byte)(input[num] >> 16);
output[i + 3] = (byte)(input[num] >> 24);
num++;
}
}
// Token: 0x06000200 RID: 512 RVA: 0x0000CC60 File Offset: 0x0000AE60
private void Decode(uint[] output, byte[] input, int index)
{
int i = 0;
int num = index;
while (i < output.Length)
{
output[i] = (uint)((int)input[num] | ((int)input[num + 1] << 8) | ((int)input[num + 2] << 16) | ((int)input[num + 3] << 24));
i++;
num += 4;
}
}
// Token: 0x06000201 RID: 513 RVA: 0x0000CCA8 File Offset: 0x0000AEA8
private void MD4Transform(uint[] state, byte[] block, int index)
{
uint num = state[0];
uint num2 = state[1];
uint num3 = state[2];
uint num4 = state[3];
this.Decode(this.x, block, index);
this.FF(ref num, num2, num3, num4, this.x[0], 3);
this.FF(ref num4, num, num2, num3, this.x[1], 7);
this.FF(ref num3, num4, num, num2, this.x[2], 11);
this.FF(ref num2, num3, num4, num, this.x[3], 19);
this.FF(ref num, num2, num3, num4, this.x[4], 3);
this.FF(ref num4, num, num2, num3, this.x[5], 7);
this.FF(ref num3, num4, num, num2, this.x[6], 11);
this.FF(ref num2, num3, num4, num, this.x[7], 19);
this.FF(ref num, num2, num3, num4, this.x[8], 3);
this.FF(ref num4, num, num2, num3, this.x[9], 7);
this.FF(ref num3, num4, num, num2, this.x[10], 11);
this.FF(ref num2, num3, num4, num, this.x[11], 19);
this.FF(ref num, num2, num3, num4, this.x[12], 3);
this.FF(ref num4, num, num2, num3, this.x[13], 7);
this.FF(ref num3, num4, num, num2, this.x[14], 11);
this.FF(ref num2, num3, num4, num, this.x[15], 19);
this.GG(ref num, num2, num3, num4, this.x[0], 3);
this.GG(ref num4, num, num2, num3, this.x[4], 5);
this.GG(ref num3, num4, num, num2, this.x[8], 9);
this.GG(ref num2, num3, num4, num, this.x[12], 13);
this.GG(ref num, num2, num3, num4, this.x[1], 3);
this.GG(ref num4, num, num2, num3, this.x[5], 5);
this.GG(ref num3, num4, num, num2, this.x[9], 9);
this.GG(ref num2, num3, num4, num, this.x[13], 13);
this.GG(ref num, num2, num3, num4, this.x[2], 3);
this.GG(ref num4, num, num2, num3, this.x[6], 5);
this.GG(ref num3, num4, num, num2, this.x[10], 9);
this.GG(ref num2, num3, num4, num, this.x[14], 13);
this.GG(ref num, num2, num3, num4, this.x[3], 3);
this.GG(ref num4, num, num2, num3, this.x[7], 5);
this.GG(ref num3, num4, num, num2, this.x[11], 9);
this.GG(ref num2, num3, num4, num, this.x[15], 13);
this.HH(ref num, num2, num3, num4, this.x[0], 3);
this.HH(ref num4, num, num2, num3, this.x[8], 9);
this.HH(ref num3, num4, num, num2, this.x[4], 11);
this.HH(ref num2, num3, num4, num, this.x[12], 15);
this.HH(ref num, num2, num3, num4, this.x[2], 3);
this.HH(ref num4, num, num2, num3, this.x[10], 9);
this.HH(ref num3, num4, num, num2, this.x[6], 11);
this.HH(ref num2, num3, num4, num, this.x[14], 15);
this.HH(ref num, num2, num3, num4, this.x[1], 3);
this.HH(ref num4, num, num2, num3, this.x[9], 9);
this.HH(ref num3, num4, num, num2, this.x[5], 11);
this.HH(ref num2, num3, num4, num, this.x[13], 15);
this.HH(ref num, num2, num3, num4, this.x[3], 3);
this.HH(ref num4, num, num2, num3, this.x[11], 9);
this.HH(ref num3, num4, num, num2, this.x[7], 11);
this.HH(ref num2, num3, num4, num, this.x[15], 15);
state[0] += num;
state[1] += num2;
state[2] += num3;
state[3] += num4;
}
// Token: 0x040000CF RID: 207
private const int S11 = 3;
// Token: 0x040000D0 RID: 208
private const int S12 = 7;
// Token: 0x040000D1 RID: 209
private const int S13 = 11;
// Token: 0x040000D2 RID: 210
private const int S14 = 19;
// Token: 0x040000D3 RID: 211
private const int S21 = 3;
// Token: 0x040000D4 RID: 212
private const int S22 = 5;
// Token: 0x040000D5 RID: 213
private const int S23 = 9;
// Token: 0x040000D6 RID: 214
private const int S24 = 13;
// Token: 0x040000D7 RID: 215
private const int S31 = 3;
// Token: 0x040000D8 RID: 216
private const int S32 = 9;
// Token: 0x040000D9 RID: 217
private const int S33 = 11;
// Token: 0x040000DA RID: 218
private const int S34 = 15;
// Token: 0x040000DB RID: 219
private uint[] state;
// Token: 0x040000DC RID: 220
private byte[] buffer;
// Token: 0x040000DD RID: 221
private uint[] count;
// Token: 0x040000DE RID: 222
private uint[] x;
// Token: 0x040000DF RID: 223
private byte[] digest;
}
}
@@ -0,0 +1,89 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Protocol.Tls;
namespace Mono.Security.Cryptography
{
// Token: 0x02000075 RID: 117
internal class MD5SHA1 : HashAlgorithm
{
// Token: 0x06000431 RID: 1073 RVA: 0x0001B19C File Offset: 0x0001939C
public MD5SHA1()
{
this.md5 = MD5.Create();
this.sha = SHA1.Create();
this.HashSizeValue = this.md5.HashSize + this.sha.HashSize;
}
// Token: 0x06000432 RID: 1074 RVA: 0x0001B1E4 File Offset: 0x000193E4
public override void Initialize()
{
this.md5.Initialize();
this.sha.Initialize();
this.hashing = false;
}
// Token: 0x06000433 RID: 1075 RVA: 0x0001B204 File Offset: 0x00019404
protected override byte[] HashFinal()
{
if (!this.hashing)
{
this.hashing = true;
}
this.md5.TransformFinalBlock(new byte[0], 0, 0);
this.sha.TransformFinalBlock(new byte[0], 0, 0);
byte[] array = new byte[36];
Buffer.BlockCopy(this.md5.Hash, 0, array, 0, 16);
Buffer.BlockCopy(this.sha.Hash, 0, array, 16, 20);
return array;
}
// Token: 0x06000434 RID: 1076 RVA: 0x0001B280 File Offset: 0x00019480
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
if (!this.hashing)
{
this.hashing = true;
}
this.md5.TransformBlock(array, ibStart, cbSize, array, ibStart);
this.sha.TransformBlock(array, ibStart, cbSize, array, ibStart);
}
// Token: 0x06000435 RID: 1077 RVA: 0x0001B2C4 File Offset: 0x000194C4
public byte[] CreateSignature(RSA rsa)
{
if (rsa == null)
{
throw new CryptographicUnexpectedOperationException("missing key");
}
RSASslSignatureFormatter rsasslSignatureFormatter = new RSASslSignatureFormatter(rsa);
rsasslSignatureFormatter.SetHashAlgorithm("MD5SHA1");
return rsasslSignatureFormatter.CreateSignature(this.Hash);
}
// Token: 0x06000436 RID: 1078 RVA: 0x0001B300 File Offset: 0x00019500
public bool VerifySignature(RSA rsa, byte[] rgbSignature)
{
if (rsa == null)
{
throw new CryptographicUnexpectedOperationException("missing key");
}
if (rgbSignature == null)
{
throw new ArgumentNullException("rgbSignature");
}
RSASslSignatureDeformatter rsasslSignatureDeformatter = new RSASslSignatureDeformatter(rsa);
rsasslSignatureDeformatter.SetHashAlgorithm("MD5SHA1");
return rsasslSignatureDeformatter.VerifySignature(this.Hash, rgbSignature);
}
// Token: 0x040001F5 RID: 501
private HashAlgorithm md5;
// Token: 0x040001F6 RID: 502
private HashAlgorithm sha;
// Token: 0x040001F7 RID: 503
private bool hashing;
}
}
@@ -0,0 +1,394 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000030 RID: 48
public sealed class PKCS1
{
// Token: 0x06000202 RID: 514 RVA: 0x0000D0F4 File Offset: 0x0000B2F4
private PKCS1()
{
}
// Token: 0x06000204 RID: 516 RVA: 0x0000D168 File Offset: 0x0000B368
private static bool Compare(byte[] array1, byte[] array2)
{
bool flag = array1.Length == array2.Length;
if (flag)
{
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
{
return false;
}
}
}
return flag;
}
// Token: 0x06000205 RID: 517 RVA: 0x0000D1A8 File Offset: 0x0000B3A8
private static byte[] xor(byte[] array1, byte[] array2)
{
byte[] array3 = new byte[array1.Length];
for (int i = 0; i < array3.Length; i++)
{
array3[i] = array1[i] ^ array2[i];
}
return array3;
}
// Token: 0x06000206 RID: 518 RVA: 0x0000D1E0 File Offset: 0x0000B3E0
private static byte[] GetEmptyHash(HashAlgorithm hash)
{
if (hash is SHA1)
{
return PKCS1.emptySHA1;
}
if (hash is SHA256)
{
return PKCS1.emptySHA256;
}
if (hash is SHA384)
{
return PKCS1.emptySHA384;
}
if (hash is SHA512)
{
return PKCS1.emptySHA512;
}
return hash.ComputeHash(null);
}
// Token: 0x06000207 RID: 519 RVA: 0x0000D238 File Offset: 0x0000B438
public static byte[] I2OSP(int x, int size)
{
byte[] bytes = BitConverterLE.GetBytes(x);
Array.Reverse(bytes, 0, bytes.Length);
return PKCS1.I2OSP(bytes, size);
}
// Token: 0x06000208 RID: 520 RVA: 0x0000D260 File Offset: 0x0000B460
public static byte[] I2OSP(byte[] x, int size)
{
byte[] array = new byte[size];
Buffer.BlockCopy(x, 0, array, array.Length - x.Length, x.Length);
return array;
}
// Token: 0x06000209 RID: 521 RVA: 0x0000D288 File Offset: 0x0000B488
public static byte[] OS2IP(byte[] x)
{
int num = 0;
while (x[num++] == 0 && num < x.Length)
{
}
num--;
if (num > 0)
{
byte[] array = new byte[x.Length - num];
Buffer.BlockCopy(x, num, array, 0, array.Length);
return array;
}
return x;
}
// Token: 0x0600020A RID: 522 RVA: 0x0000D2D8 File Offset: 0x0000B4D8
public static byte[] RSAEP(RSA rsa, byte[] m)
{
return rsa.EncryptValue(m);
}
// Token: 0x0600020B RID: 523 RVA: 0x0000D2E4 File Offset: 0x0000B4E4
public static byte[] RSADP(RSA rsa, byte[] c)
{
return rsa.DecryptValue(c);
}
// Token: 0x0600020C RID: 524 RVA: 0x0000D2F0 File Offset: 0x0000B4F0
public static byte[] RSASP1(RSA rsa, byte[] m)
{
return rsa.DecryptValue(m);
}
// Token: 0x0600020D RID: 525 RVA: 0x0000D2FC File Offset: 0x0000B4FC
public static byte[] RSAVP1(RSA rsa, byte[] s)
{
return rsa.EncryptValue(s);
}
// Token: 0x0600020E RID: 526 RVA: 0x0000D308 File Offset: 0x0000B508
public static byte[] Encrypt_OAEP(RSA rsa, HashAlgorithm hash, RandomNumberGenerator rng, byte[] M)
{
int num = rsa.KeySize / 8;
int num2 = hash.HashSize / 8;
if (M.Length > num - 2 * num2 - 2)
{
throw new CryptographicException("message too long");
}
byte[] emptyHash = PKCS1.GetEmptyHash(hash);
int num3 = num - M.Length - 2 * num2 - 2;
byte[] array = new byte[emptyHash.Length + num3 + 1 + M.Length];
Buffer.BlockCopy(emptyHash, 0, array, 0, emptyHash.Length);
array[emptyHash.Length + num3] = 1;
Buffer.BlockCopy(M, 0, array, array.Length - M.Length, M.Length);
byte[] array2 = new byte[num2];
rng.GetBytes(array2);
byte[] array3 = PKCS1.MGF1(hash, array2, num - num2 - 1);
byte[] array4 = PKCS1.xor(array, array3);
byte[] array5 = PKCS1.MGF1(hash, array4, num2);
byte[] array6 = PKCS1.xor(array2, array5);
byte[] array7 = new byte[array6.Length + array4.Length + 1];
Buffer.BlockCopy(array6, 0, array7, 1, array6.Length);
Buffer.BlockCopy(array4, 0, array7, array6.Length + 1, array4.Length);
byte[] array8 = PKCS1.OS2IP(array7);
byte[] array9 = PKCS1.RSAEP(rsa, array8);
return PKCS1.I2OSP(array9, num);
}
// Token: 0x0600020F RID: 527 RVA: 0x0000D420 File Offset: 0x0000B620
public static byte[] Decrypt_OAEP(RSA rsa, HashAlgorithm hash, byte[] C)
{
int num = rsa.KeySize / 8;
int num2 = hash.HashSize / 8;
if (num < 2 * num2 + 2 || C.Length != num)
{
throw new CryptographicException("decryption error");
}
byte[] array = PKCS1.OS2IP(C);
byte[] array2 = PKCS1.RSADP(rsa, array);
byte[] array3 = PKCS1.I2OSP(array2, num);
byte[] array4 = new byte[num2];
Buffer.BlockCopy(array3, 1, array4, 0, array4.Length);
byte[] array5 = new byte[num - num2 - 1];
Buffer.BlockCopy(array3, array3.Length - array5.Length, array5, 0, array5.Length);
byte[] array6 = PKCS1.MGF1(hash, array5, num2);
byte[] array7 = PKCS1.xor(array4, array6);
byte[] array8 = PKCS1.MGF1(hash, array7, num - num2 - 1);
byte[] array9 = PKCS1.xor(array5, array8);
byte[] emptyHash = PKCS1.GetEmptyHash(hash);
byte[] array10 = new byte[emptyHash.Length];
Buffer.BlockCopy(array9, 0, array10, 0, array10.Length);
bool flag = PKCS1.Compare(emptyHash, array10);
int num3 = emptyHash.Length;
while (array9[num3] == 0)
{
num3++;
}
int num4 = array9.Length - num3 - 1;
byte[] array11 = new byte[num4];
Buffer.BlockCopy(array9, num3 + 1, array11, 0, num4);
if (array3[0] != 0 || !flag || array9[num3] != 1)
{
return null;
}
return array11;
}
// Token: 0x06000210 RID: 528 RVA: 0x0000D56C File Offset: 0x0000B76C
public static byte[] Encrypt_v15(RSA rsa, RandomNumberGenerator rng, byte[] M)
{
int num = rsa.KeySize / 8;
if (M.Length > num - 11)
{
throw new CryptographicException("message too long");
}
int num2 = Math.Max(8, num - M.Length - 3);
byte[] array = new byte[num2];
rng.GetNonZeroBytes(array);
byte[] array2 = new byte[num];
array2[1] = 2;
Buffer.BlockCopy(array, 0, array2, 2, num2);
Buffer.BlockCopy(M, 0, array2, num - M.Length, M.Length);
byte[] array3 = PKCS1.OS2IP(array2);
byte[] array4 = PKCS1.RSAEP(rsa, array3);
return PKCS1.I2OSP(array4, num);
}
// Token: 0x06000211 RID: 529 RVA: 0x0000D5F8 File Offset: 0x0000B7F8
public static byte[] Decrypt_v15(RSA rsa, byte[] C)
{
int num = rsa.KeySize >> 3;
if (num < 11 || C.Length > num)
{
throw new CryptographicException("decryption error");
}
byte[] array = PKCS1.OS2IP(C);
byte[] array2 = PKCS1.RSADP(rsa, array);
byte[] array3 = PKCS1.I2OSP(array2, num);
if (array3[0] != 0 || array3[1] != 2)
{
return null;
}
int num2 = 10;
while (array3[num2] != 0 && num2 < array3.Length)
{
num2++;
}
if (array3[num2] != 0)
{
return null;
}
num2++;
byte[] array4 = new byte[array3.Length - num2];
Buffer.BlockCopy(array3, num2, array4, 0, array4.Length);
return array4;
}
// Token: 0x06000212 RID: 530 RVA: 0x0000D6A8 File Offset: 0x0000B8A8
public static byte[] Sign_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue)
{
int num = rsa.KeySize >> 3;
byte[] array = PKCS1.Encode_v15(hash, hashValue, num);
byte[] array2 = PKCS1.OS2IP(array);
byte[] array3 = PKCS1.RSASP1(rsa, array2);
return PKCS1.I2OSP(array3, num);
}
// Token: 0x06000213 RID: 531 RVA: 0x0000D6E4 File Offset: 0x0000B8E4
public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature)
{
return PKCS1.Verify_v15(rsa, hash, hashValue, signature, false);
}
// Token: 0x06000214 RID: 532 RVA: 0x0000D6F0 File Offset: 0x0000B8F0
public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature, bool tryNonStandardEncoding)
{
int num = rsa.KeySize >> 3;
byte[] array = PKCS1.OS2IP(signature);
byte[] array2 = PKCS1.RSAVP1(rsa, array);
byte[] array3 = PKCS1.I2OSP(array2, num);
byte[] array4 = PKCS1.Encode_v15(hash, hashValue, num);
bool flag = PKCS1.Compare(array4, array3);
if (flag || !tryNonStandardEncoding)
{
return flag;
}
if (array3[0] != 0 || array3[1] != 1)
{
return false;
}
int i;
for (i = 2; i < array3.Length - hashValue.Length - 1; i++)
{
if (array3[i] != 255)
{
return false;
}
}
if (array3[i++] != 0)
{
return false;
}
byte[] array5 = new byte[hashValue.Length];
Buffer.BlockCopy(array3, i, array5, 0, array5.Length);
return PKCS1.Compare(array5, hashValue);
}
// Token: 0x06000215 RID: 533 RVA: 0x0000D7B4 File Offset: 0x0000B9B4
public static byte[] Encode_v15(HashAlgorithm hash, byte[] hashValue, int emLength)
{
if (hashValue.Length != hash.HashSize >> 3)
{
throw new CryptographicException("bad hash length for " + hash.ToString());
}
string text = CryptoConfig.MapNameToOID(hash.ToString());
byte[] array;
if (text != null)
{
ASN1 asn = new ASN1(48);
asn.Add(new ASN1(CryptoConfig.EncodeOID(text)));
asn.Add(new ASN1(5));
ASN1 asn2 = new ASN1(4, hashValue);
ASN1 asn3 = new ASN1(48);
asn3.Add(asn);
asn3.Add(asn2);
array = asn3.GetBytes();
}
else
{
array = hashValue;
}
Buffer.BlockCopy(hashValue, 0, array, array.Length - hashValue.Length, hashValue.Length);
int num = Math.Max(8, emLength - array.Length - 3);
byte[] array2 = new byte[num + array.Length + 3];
array2[1] = 1;
for (int i = 2; i < num + 2; i++)
{
array2[i] = byte.MaxValue;
}
Buffer.BlockCopy(array, 0, array2, num + 3, array.Length);
return array2;
}
// Token: 0x06000216 RID: 534 RVA: 0x0000D8C0 File Offset: 0x0000BAC0
public static byte[] MGF1(HashAlgorithm hash, byte[] mgfSeed, int maskLen)
{
if (maskLen < 0)
{
throw new OverflowException();
}
int num = mgfSeed.Length;
int num2 = hash.HashSize >> 3;
int num3 = maskLen / num2;
if (maskLen % num2 != 0)
{
num3++;
}
byte[] array = new byte[num3 * num2];
byte[] array2 = new byte[num + 4];
int num4 = 0;
for (int i = 0; i < num3; i++)
{
byte[] array3 = PKCS1.I2OSP(i, 4);
Buffer.BlockCopy(mgfSeed, 0, array2, 0, num);
Buffer.BlockCopy(array3, 0, array2, num, 4);
byte[] array4 = hash.ComputeHash(array2);
Buffer.BlockCopy(array4, 0, array, num4, num2);
num4 += num;
}
byte[] array5 = new byte[maskLen];
Buffer.BlockCopy(array, 0, array5, 0, maskLen);
return array5;
}
// Token: 0x040000E0 RID: 224
private static byte[] emptySHA1 = new byte[]
{
218, 57, 163, 238, 94, 107, 75, 13, 50, 85,
191, 239, 149, 96, 24, 144, 175, 216, 7, 9
};
// Token: 0x040000E1 RID: 225
private static byte[] emptySHA256 = new byte[]
{
227, 176, 196, 66, 152, 252, 28, 20, 154, 251,
244, 200, 153, 111, 185, 36, 39, 174, 65, 228,
100, 155, 147, 76, 164, 149, 153, 27, 120, 82,
184, 85
};
// Token: 0x040000E2 RID: 226
private static byte[] emptySHA384 = new byte[]
{
56, 176, 96, 167, 81, 172, 150, 56, 76, 217,
50, 126, 177, 177, 227, 106, 33, 253, 183, 17,
20, 190, 7, 67, 76, 12, 199, 191, 99, 246,
225, 218, 39, 78, 222, 191, 231, 111, 101, 251,
213, 26, 210, 241, 72, 152, 185, 91
};
// Token: 0x040000E3 RID: 227
private static byte[] emptySHA512 = new byte[]
{
207, 131, 225, 53, 126, 239, 184, 189, 241, 84,
40, 80, 214, 109, 128, 7, 214, 32, 228, 5,
11, 87, 21, 220, 131, 244, 169, 33, 211, 108,
233, 206, 71, 208, 209, 60, 93, 133, 242, 176,
byte.MaxValue, 131, 24, 210, 135, 126, 236, 47, 99, 185,
49, 189, 71, 65, 122, 129, 165, 56, 50, 122,
249, 39, 218, 62
};
}
}
@@ -0,0 +1,515 @@
using System;
using System.Collections;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000031 RID: 49
public sealed class PKCS8
{
// Token: 0x06000217 RID: 535 RVA: 0x0000D978 File Offset: 0x0000BB78
private PKCS8()
{
}
// Token: 0x06000218 RID: 536 RVA: 0x0000D980 File Offset: 0x0000BB80
public static PKCS8.KeyInfo GetType(byte[] data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
PKCS8.KeyInfo keyInfo = PKCS8.KeyInfo.Unknown;
try
{
ASN1 asn = new ASN1(data);
if (asn.Tag == 48 && asn.Count > 0)
{
ASN1 asn2 = asn[0];
byte tag = asn2.Tag;
if (tag != 2)
{
if (tag == 48)
{
keyInfo = PKCS8.KeyInfo.EncryptedPrivateKey;
}
}
else
{
keyInfo = PKCS8.KeyInfo.PrivateKey;
}
}
}
catch
{
throw new CryptographicException("invalid ASN.1 data");
}
return keyInfo;
}
// Token: 0x02000032 RID: 50
public enum KeyInfo
{
// Token: 0x040000E5 RID: 229
PrivateKey,
// Token: 0x040000E6 RID: 230
EncryptedPrivateKey,
// Token: 0x040000E7 RID: 231
Unknown
}
// Token: 0x02000033 RID: 51
public class PrivateKeyInfo
{
// Token: 0x06000219 RID: 537 RVA: 0x0000DA24 File Offset: 0x0000BC24
public PrivateKeyInfo()
{
this._version = 0;
this._list = new ArrayList();
}
// Token: 0x0600021A RID: 538 RVA: 0x0000DA40 File Offset: 0x0000BC40
public PrivateKeyInfo(byte[] data)
: this()
{
this.Decode(data);
}
// Token: 0x17000067 RID: 103
// (get) Token: 0x0600021B RID: 539 RVA: 0x0000DA50 File Offset: 0x0000BC50
// (set) Token: 0x0600021C RID: 540 RVA: 0x0000DA58 File Offset: 0x0000BC58
public string Algorithm
{
get
{
return this._algorithm;
}
set
{
this._algorithm = value;
}
}
// Token: 0x17000068 RID: 104
// (get) Token: 0x0600021D RID: 541 RVA: 0x0000DA64 File Offset: 0x0000BC64
public ArrayList Attributes
{
get
{
return this._list;
}
}
// Token: 0x17000069 RID: 105
// (get) Token: 0x0600021E RID: 542 RVA: 0x0000DA6C File Offset: 0x0000BC6C
// (set) Token: 0x0600021F RID: 543 RVA: 0x0000DA8C File Offset: 0x0000BC8C
public byte[] PrivateKey
{
get
{
if (this._key == null)
{
return null;
}
return (byte[])this._key.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("PrivateKey");
}
this._key = (byte[])value.Clone();
}
}
// Token: 0x1700006A RID: 106
// (get) Token: 0x06000220 RID: 544 RVA: 0x0000DABC File Offset: 0x0000BCBC
// (set) Token: 0x06000221 RID: 545 RVA: 0x0000DAC4 File Offset: 0x0000BCC4
public int Version
{
get
{
return this._version;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("negative version");
}
this._version = value;
}
}
// Token: 0x06000222 RID: 546 RVA: 0x0000DAE0 File Offset: 0x0000BCE0
private void Decode(byte[] data)
{
ASN1 asn = new ASN1(data);
if (asn.Tag != 48)
{
throw new CryptographicException("invalid PrivateKeyInfo");
}
ASN1 asn2 = asn[0];
if (asn2.Tag != 2)
{
throw new CryptographicException("invalid version");
}
this._version = (int)asn2.Value[0];
ASN1 asn3 = asn[1];
if (asn3.Tag != 48)
{
throw new CryptographicException("invalid algorithm");
}
ASN1 asn4 = asn3[0];
if (asn4.Tag != 6)
{
throw new CryptographicException("missing algorithm OID");
}
this._algorithm = ASN1Convert.ToOid(asn4);
ASN1 asn5 = asn[2];
this._key = asn5.Value;
if (asn.Count > 3)
{
ASN1 asn6 = asn[3];
for (int i = 0; i < asn6.Count; i++)
{
this._list.Add(asn6[i]);
}
}
}
// Token: 0x06000223 RID: 547 RVA: 0x0000DBE0 File Offset: 0x0000BDE0
public byte[] GetBytes()
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(this._algorithm));
asn.Add(new ASN1(5));
ASN1 asn2 = new ASN1(48);
asn2.Add(new ASN1(2, new byte[] { (byte)this._version }));
asn2.Add(asn);
asn2.Add(new ASN1(4, this._key));
if (this._list.Count > 0)
{
ASN1 asn3 = new ASN1(160);
foreach (object obj in this._list)
{
ASN1 asn4 = (ASN1)obj;
asn3.Add(asn4);
}
asn2.Add(asn3);
}
return asn2.GetBytes();
}
// Token: 0x06000224 RID: 548 RVA: 0x0000DCE8 File Offset: 0x0000BEE8
private static byte[] RemoveLeadingZero(byte[] bigInt)
{
int num = 0;
int num2 = bigInt.Length;
if (bigInt[0] == 0)
{
num = 1;
num2--;
}
byte[] array = new byte[num2];
Buffer.BlockCopy(bigInt, num, array, 0, num2);
return array;
}
// Token: 0x06000225 RID: 549 RVA: 0x0000DD1C File Offset: 0x0000BF1C
private static byte[] Normalize(byte[] bigInt, int length)
{
if (bigInt.Length == length)
{
return bigInt;
}
if (bigInt.Length > length)
{
return PKCS8.PrivateKeyInfo.RemoveLeadingZero(bigInt);
}
byte[] array = new byte[length];
Buffer.BlockCopy(bigInt, 0, array, length - bigInt.Length, bigInt.Length);
return array;
}
// Token: 0x06000226 RID: 550 RVA: 0x0000DD5C File Offset: 0x0000BF5C
public static RSA DecodeRSA(byte[] keypair)
{
ASN1 asn = new ASN1(keypair);
if (asn.Tag != 48)
{
throw new CryptographicException("invalid private key format");
}
ASN1 asn2 = asn[0];
if (asn2.Tag != 2)
{
throw new CryptographicException("missing version");
}
if (asn.Count < 9)
{
throw new CryptographicException("not enough key parameters");
}
RSAParameters rsaparameters = default(RSAParameters);
rsaparameters.Modulus = PKCS8.PrivateKeyInfo.RemoveLeadingZero(asn[1].Value);
int num = rsaparameters.Modulus.Length;
int num2 = num >> 1;
rsaparameters.D = PKCS8.PrivateKeyInfo.Normalize(asn[3].Value, num);
rsaparameters.DP = PKCS8.PrivateKeyInfo.Normalize(asn[6].Value, num2);
rsaparameters.DQ = PKCS8.PrivateKeyInfo.Normalize(asn[7].Value, num2);
rsaparameters.Exponent = PKCS8.PrivateKeyInfo.RemoveLeadingZero(asn[2].Value);
rsaparameters.InverseQ = PKCS8.PrivateKeyInfo.Normalize(asn[8].Value, num2);
rsaparameters.P = PKCS8.PrivateKeyInfo.Normalize(asn[4].Value, num2);
rsaparameters.Q = PKCS8.PrivateKeyInfo.Normalize(asn[5].Value, num2);
RSA rsa = null;
try
{
rsa = RSA.Create();
rsa.ImportParameters(rsaparameters);
}
catch (CryptographicException)
{
rsa = new RSACryptoServiceProvider(new CspParameters
{
Flags = CspProviderFlags.UseMachineKeyStore
});
rsa.ImportParameters(rsaparameters);
}
return rsa;
}
// Token: 0x06000227 RID: 551 RVA: 0x0000DEFC File Offset: 0x0000C0FC
public static byte[] Encode(RSA rsa)
{
RSAParameters rsaparameters = rsa.ExportParameters(true);
ASN1 asn = new ASN1(48);
asn.Add(new ASN1(2, new byte[1]));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.Modulus));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.Exponent));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.D));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.P));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.Q));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.DP));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.DQ));
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.InverseQ));
return asn.GetBytes();
}
// Token: 0x06000228 RID: 552 RVA: 0x0000DFCC File Offset: 0x0000C1CC
public static DSA DecodeDSA(byte[] privateKey, DSAParameters dsaParameters)
{
ASN1 asn = new ASN1(privateKey);
if (asn.Tag != 2)
{
throw new CryptographicException("invalid private key format");
}
dsaParameters.X = PKCS8.PrivateKeyInfo.Normalize(asn.Value, 20);
DSA dsa = DSA.Create();
dsa.ImportParameters(dsaParameters);
return dsa;
}
// Token: 0x06000229 RID: 553 RVA: 0x0000E01C File Offset: 0x0000C21C
public static byte[] Encode(DSA dsa)
{
return ASN1Convert.FromUnsignedBigInteger(dsa.ExportParameters(true).X).GetBytes();
}
// Token: 0x0600022A RID: 554 RVA: 0x0000E044 File Offset: 0x0000C244
public static byte[] Encode(AsymmetricAlgorithm aa)
{
if (aa is RSA)
{
return PKCS8.PrivateKeyInfo.Encode((RSA)aa);
}
if (aa is DSA)
{
return PKCS8.PrivateKeyInfo.Encode((DSA)aa);
}
throw new CryptographicException("Unknown asymmetric algorithm {0}", aa.ToString());
}
// Token: 0x040000E8 RID: 232
private int _version;
// Token: 0x040000E9 RID: 233
private string _algorithm;
// Token: 0x040000EA RID: 234
private byte[] _key;
// Token: 0x040000EB RID: 235
private ArrayList _list;
}
// Token: 0x02000034 RID: 52
public class EncryptedPrivateKeyInfo
{
// Token: 0x0600022B RID: 555 RVA: 0x0000E090 File Offset: 0x0000C290
public EncryptedPrivateKeyInfo()
{
}
// Token: 0x0600022C RID: 556 RVA: 0x0000E098 File Offset: 0x0000C298
public EncryptedPrivateKeyInfo(byte[] data)
: this()
{
this.Decode(data);
}
// Token: 0x1700006B RID: 107
// (get) Token: 0x0600022D RID: 557 RVA: 0x0000E0A8 File Offset: 0x0000C2A8
// (set) Token: 0x0600022E RID: 558 RVA: 0x0000E0B0 File Offset: 0x0000C2B0
public string Algorithm
{
get
{
return this._algorithm;
}
set
{
this._algorithm = value;
}
}
// Token: 0x1700006C RID: 108
// (get) Token: 0x0600022F RID: 559 RVA: 0x0000E0BC File Offset: 0x0000C2BC
// (set) Token: 0x06000230 RID: 560 RVA: 0x0000E0E0 File Offset: 0x0000C2E0
public byte[] EncryptedData
{
get
{
return (this._data != null) ? ((byte[])this._data.Clone()) : null;
}
set
{
this._data = ((value != null) ? ((byte[])value.Clone()) : null);
}
}
// Token: 0x1700006D RID: 109
// (get) Token: 0x06000231 RID: 561 RVA: 0x0000E100 File Offset: 0x0000C300
// (set) Token: 0x06000232 RID: 562 RVA: 0x0000E148 File Offset: 0x0000C348
public byte[] Salt
{
get
{
if (this._salt == null)
{
RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
this._salt = new byte[8];
randomNumberGenerator.GetBytes(this._salt);
}
return (byte[])this._salt.Clone();
}
set
{
this._salt = (byte[])value.Clone();
}
}
// Token: 0x1700006E RID: 110
// (get) Token: 0x06000233 RID: 563 RVA: 0x0000E15C File Offset: 0x0000C35C
// (set) Token: 0x06000234 RID: 564 RVA: 0x0000E164 File Offset: 0x0000C364
public int IterationCount
{
get
{
return this._iterations;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("IterationCount", "Negative");
}
this._iterations = value;
}
}
// Token: 0x06000235 RID: 565 RVA: 0x0000E184 File Offset: 0x0000C384
private void Decode(byte[] data)
{
ASN1 asn = new ASN1(data);
if (asn.Tag != 48)
{
throw new CryptographicException("invalid EncryptedPrivateKeyInfo");
}
ASN1 asn2 = asn[0];
if (asn2.Tag != 48)
{
throw new CryptographicException("invalid encryptionAlgorithm");
}
ASN1 asn3 = asn2[0];
if (asn3.Tag != 6)
{
throw new CryptographicException("invalid algorithm");
}
this._algorithm = ASN1Convert.ToOid(asn3);
if (asn2.Count > 1)
{
ASN1 asn4 = asn2[1];
if (asn4.Tag != 48)
{
throw new CryptographicException("invalid parameters");
}
ASN1 asn5 = asn4[0];
if (asn5.Tag != 4)
{
throw new CryptographicException("invalid salt");
}
this._salt = asn5.Value;
ASN1 asn6 = asn4[1];
if (asn6.Tag != 2)
{
throw new CryptographicException("invalid iterationCount");
}
this._iterations = ASN1Convert.ToInt32(asn6);
}
ASN1 asn7 = asn[1];
if (asn7.Tag != 4)
{
throw new CryptographicException("invalid EncryptedData");
}
this._data = asn7.Value;
}
// Token: 0x06000236 RID: 566 RVA: 0x0000E2B4 File Offset: 0x0000C4B4
public byte[] GetBytes()
{
if (this._algorithm == null)
{
throw new CryptographicException("No algorithm OID specified");
}
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(this._algorithm));
if (this._iterations > 0 || this._salt != null)
{
ASN1 asn2 = new ASN1(4, this._salt);
ASN1 asn3 = ASN1Convert.FromInt32(this._iterations);
ASN1 asn4 = new ASN1(48);
asn4.Add(asn2);
asn4.Add(asn3);
asn.Add(asn4);
}
ASN1 asn5 = new ASN1(4, this._data);
ASN1 asn6 = new ASN1(48);
asn6.Add(asn);
asn6.Add(asn5);
return asn6.GetBytes();
}
// Token: 0x040000EC RID: 236
private string _algorithm;
// Token: 0x040000ED RID: 237
private byte[] _salt;
// Token: 0x040000EE RID: 238
private int _iterations;
// Token: 0x040000EF RID: 239
private byte[] _data;
}
}
}
@@ -0,0 +1,62 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000035 RID: 53
public abstract class RC4 : SymmetricAlgorithm
{
// Token: 0x06000237 RID: 567 RVA: 0x0000E374 File Offset: 0x0000C574
public RC4()
{
this.KeySizeValue = 128;
this.BlockSizeValue = 64;
this.FeedbackSizeValue = this.BlockSizeValue;
this.LegalBlockSizesValue = RC4.s_legalBlockSizes;
this.LegalKeySizesValue = RC4.s_legalKeySizes;
}
// Token: 0x1700006F RID: 111
// (get) Token: 0x06000239 RID: 569 RVA: 0x0000E3EC File Offset: 0x0000C5EC
// (set) Token: 0x0600023A RID: 570 RVA: 0x0000E3F4 File Offset: 0x0000C5F4
public override byte[] IV
{
get
{
return new byte[0];
}
set
{
}
}
// Token: 0x0600023B RID: 571 RVA: 0x0000E3F8 File Offset: 0x0000C5F8
public new static RC4 Create()
{
return RC4.Create("RC4");
}
// Token: 0x0600023C RID: 572 RVA: 0x0000E404 File Offset: 0x0000C604
public new static RC4 Create(string algName)
{
object obj = CryptoConfig.CreateFromName(algName);
if (obj == null)
{
obj = new ARC4Managed();
}
return (RC4)obj;
}
// Token: 0x040000F0 RID: 240
private static KeySizes[] s_legalBlockSizes = new KeySizes[]
{
new KeySizes(64, 64, 0)
};
// Token: 0x040000F1 RID: 241
private static KeySizes[] s_legalKeySizes = new KeySizes[]
{
new KeySizes(40, 2048, 8)
};
}
}
@@ -0,0 +1,524 @@
using System;
using System.Security.Cryptography;
using System.Text;
using Mono.Math;
namespace Mono.Security.Cryptography
{
// Token: 0x02000036 RID: 54
public class RSAManaged : RSA
{
// Token: 0x0600023D RID: 573 RVA: 0x0000E42C File Offset: 0x0000C62C
public RSAManaged()
: this(1024)
{
}
// Token: 0x0600023E RID: 574 RVA: 0x0000E43C File Offset: 0x0000C63C
public RSAManaged(int keySize)
{
this.LegalKeySizesValue = new KeySizes[1];
this.LegalKeySizesValue[0] = new KeySizes(384, 16384, 8);
base.KeySize = keySize;
}
// Token: 0x14000001 RID: 1
// (add) Token: 0x0600023F RID: 575 RVA: 0x0000E484 File Offset: 0x0000C684
// (remove) Token: 0x06000240 RID: 576 RVA: 0x0000E4A0 File Offset: 0x0000C6A0
public event RSAManaged.KeyGeneratedEventHandler KeyGenerated;
// Token: 0x06000241 RID: 577 RVA: 0x0000E4BC File Offset: 0x0000C6BC
~RSAManaged()
{
this.Dispose(false);
}
// Token: 0x06000242 RID: 578 RVA: 0x0000E4F8 File Offset: 0x0000C6F8
private void GenerateKeyPair()
{
int num = this.KeySize + 1 >> 1;
int num2 = this.KeySize - num;
this.e = 17U;
do
{
this.p = BigInteger.GeneratePseudoPrime(num);
}
while (this.p % 17U == 1U);
for (;;)
{
do
{
this.q = BigInteger.GeneratePseudoPrime(num2);
}
while (this.q % 17U == 1U || !(this.p != this.q));
this.n = this.p * this.q;
if (this.n.BitCount() == this.KeySize)
{
break;
}
if (this.p < this.q)
{
this.p = this.q;
}
}
BigInteger bigInteger = this.p - 1;
BigInteger bigInteger2 = this.q - 1;
BigInteger bigInteger3 = bigInteger * bigInteger2;
this.d = this.e.ModInverse(bigInteger3);
this.dp = this.d % bigInteger;
this.dq = this.d % bigInteger2;
this.qInv = this.q.ModInverse(this.p);
this.keypairGenerated = true;
this.isCRTpossible = true;
if (this.KeyGenerated != null)
{
this.KeyGenerated(this, null);
}
}
// Token: 0x17000070 RID: 112
// (get) Token: 0x06000243 RID: 579 RVA: 0x0000E69C File Offset: 0x0000C89C
public override int KeySize
{
get
{
if (this.keypairGenerated)
{
int num = this.n.BitCount();
if ((num & 7) != 0)
{
num += 8 - (num & 7);
}
return num;
}
return base.KeySize;
}
}
// Token: 0x17000071 RID: 113
// (get) Token: 0x06000244 RID: 580 RVA: 0x0000E6D8 File Offset: 0x0000C8D8
public override string KeyExchangeAlgorithm
{
get
{
return "RSA-PKCS1-KeyEx";
}
}
// Token: 0x17000072 RID: 114
// (get) Token: 0x06000245 RID: 581 RVA: 0x0000E6E0 File Offset: 0x0000C8E0
public bool PublicOnly
{
get
{
return this.keypairGenerated && (this.d == null || this.n == null);
}
}
// Token: 0x17000073 RID: 115
// (get) Token: 0x06000246 RID: 582 RVA: 0x0000E71C File Offset: 0x0000C91C
public override string SignatureAlgorithm
{
get
{
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
}
}
// Token: 0x06000247 RID: 583 RVA: 0x0000E724 File Offset: 0x0000C924
public override byte[] DecryptValue(byte[] rgb)
{
if (this.m_disposed)
{
throw new ObjectDisposedException("private key");
}
if (!this.keypairGenerated)
{
this.GenerateKeyPair();
}
BigInteger bigInteger = new BigInteger(rgb);
BigInteger bigInteger2 = null;
if (this.keyBlinding)
{
bigInteger2 = BigInteger.GenerateRandom(this.n.BitCount());
bigInteger = bigInteger2.ModPow(this.e, this.n) * bigInteger % this.n;
}
BigInteger bigInteger6;
if (this.isCRTpossible)
{
BigInteger bigInteger3 = bigInteger.ModPow(this.dp, this.p);
BigInteger bigInteger4 = bigInteger.ModPow(this.dq, this.q);
if (bigInteger4 > bigInteger3)
{
BigInteger bigInteger5 = this.p - (bigInteger4 - bigInteger3) * this.qInv % this.p;
bigInteger6 = bigInteger4 + this.q * bigInteger5;
}
else
{
BigInteger bigInteger5 = (bigInteger3 - bigInteger4) * this.qInv % this.p;
bigInteger6 = bigInteger4 + this.q * bigInteger5;
}
}
else
{
if (this.PublicOnly)
{
throw new CryptographicException(Locale.GetText("Missing private key to decrypt value."));
}
bigInteger6 = bigInteger.ModPow(this.d, this.n);
}
if (this.keyBlinding)
{
bigInteger6 = bigInteger6 * bigInteger2.ModInverse(this.n) % this.n;
bigInteger2.Clear();
}
byte[] paddedValue = this.GetPaddedValue(bigInteger6, this.KeySize >> 3);
bigInteger.Clear();
bigInteger6.Clear();
return paddedValue;
}
// Token: 0x06000248 RID: 584 RVA: 0x0000E8E0 File Offset: 0x0000CAE0
public override byte[] EncryptValue(byte[] rgb)
{
if (this.m_disposed)
{
throw new ObjectDisposedException("public key");
}
if (!this.keypairGenerated)
{
this.GenerateKeyPair();
}
BigInteger bigInteger = new BigInteger(rgb);
BigInteger bigInteger2 = bigInteger.ModPow(this.e, this.n);
byte[] paddedValue = this.GetPaddedValue(bigInteger2, this.KeySize >> 3);
bigInteger.Clear();
bigInteger2.Clear();
return paddedValue;
}
// Token: 0x06000249 RID: 585 RVA: 0x0000E94C File Offset: 0x0000CB4C
public override RSAParameters ExportParameters(bool includePrivateParameters)
{
if (this.m_disposed)
{
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
}
if (!this.keypairGenerated)
{
this.GenerateKeyPair();
}
RSAParameters rsaparameters = default(RSAParameters);
rsaparameters.Exponent = this.e.GetBytes();
rsaparameters.Modulus = this.n.GetBytes();
if (includePrivateParameters)
{
if (this.d == null)
{
throw new CryptographicException("Missing private key");
}
rsaparameters.D = this.d.GetBytes();
if (rsaparameters.D.Length != rsaparameters.Modulus.Length)
{
byte[] array = new byte[rsaparameters.Modulus.Length];
Buffer.BlockCopy(rsaparameters.D, 0, array, array.Length - rsaparameters.D.Length, rsaparameters.D.Length);
rsaparameters.D = array;
}
if (this.p != null && this.q != null && this.dp != null && this.dq != null && this.qInv != null)
{
int num = this.KeySize >> 4;
rsaparameters.P = this.GetPaddedValue(this.p, num);
rsaparameters.Q = this.GetPaddedValue(this.q, num);
rsaparameters.DP = this.GetPaddedValue(this.dp, num);
rsaparameters.DQ = this.GetPaddedValue(this.dq, num);
rsaparameters.InverseQ = this.GetPaddedValue(this.qInv, num);
}
}
return rsaparameters;
}
// Token: 0x0600024A RID: 586 RVA: 0x0000EAFC File Offset: 0x0000CCFC
public override void ImportParameters(RSAParameters parameters)
{
if (this.m_disposed)
{
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
}
if (parameters.Exponent == null)
{
throw new CryptographicException(Locale.GetText("Missing Exponent"));
}
if (parameters.Modulus == null)
{
throw new CryptographicException(Locale.GetText("Missing Modulus"));
}
this.e = new BigInteger(parameters.Exponent);
this.n = new BigInteger(parameters.Modulus);
if (parameters.D != null)
{
this.d = new BigInteger(parameters.D);
}
if (parameters.DP != null)
{
this.dp = new BigInteger(parameters.DP);
}
if (parameters.DQ != null)
{
this.dq = new BigInteger(parameters.DQ);
}
if (parameters.InverseQ != null)
{
this.qInv = new BigInteger(parameters.InverseQ);
}
if (parameters.P != null)
{
this.p = new BigInteger(parameters.P);
}
if (parameters.Q != null)
{
this.q = new BigInteger(parameters.Q);
}
this.keypairGenerated = true;
bool flag = this.p != null && this.q != null && this.dp != null;
this.isCRTpossible = flag && this.dq != null && this.qInv != null;
if (!flag)
{
return;
}
bool flag2 = this.n == this.p * this.q;
if (flag2)
{
BigInteger bigInteger = this.p - 1;
BigInteger bigInteger2 = this.q - 1;
BigInteger bigInteger3 = bigInteger * bigInteger2;
BigInteger bigInteger4 = this.e.ModInverse(bigInteger3);
flag2 = this.d == bigInteger4;
if (!flag2 && this.isCRTpossible)
{
flag2 = this.dp == bigInteger4 % bigInteger && this.dq == bigInteger4 % bigInteger2 && this.qInv == this.q.ModInverse(this.p);
}
}
if (!flag2)
{
throw new CryptographicException(Locale.GetText("Private/public key mismatch"));
}
}
// Token: 0x0600024B RID: 587 RVA: 0x0000ED84 File Offset: 0x0000CF84
protected override void Dispose(bool disposing)
{
if (!this.m_disposed)
{
if (this.d != null)
{
this.d.Clear();
this.d = null;
}
if (this.p != null)
{
this.p.Clear();
this.p = null;
}
if (this.q != null)
{
this.q.Clear();
this.q = null;
}
if (this.dp != null)
{
this.dp.Clear();
this.dp = null;
}
if (this.dq != null)
{
this.dq.Clear();
this.dq = null;
}
if (this.qInv != null)
{
this.qInv.Clear();
this.qInv = null;
}
if (disposing)
{
if (this.e != null)
{
this.e.Clear();
this.e = null;
}
if (this.n != null)
{
this.n.Clear();
this.n = null;
}
}
}
this.m_disposed = true;
}
// Token: 0x0600024C RID: 588 RVA: 0x0000EEC4 File Offset: 0x0000D0C4
public override string ToXmlString(bool includePrivateParameters)
{
StringBuilder stringBuilder = new StringBuilder();
RSAParameters rsaparameters = this.ExportParameters(includePrivateParameters);
try
{
stringBuilder.Append("<RSAKeyValue>");
stringBuilder.Append("<Modulus>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Modulus));
stringBuilder.Append("</Modulus>");
stringBuilder.Append("<Exponent>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Exponent));
stringBuilder.Append("</Exponent>");
if (includePrivateParameters)
{
if (rsaparameters.P != null)
{
stringBuilder.Append("<P>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.P));
stringBuilder.Append("</P>");
}
if (rsaparameters.Q != null)
{
stringBuilder.Append("<Q>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Q));
stringBuilder.Append("</Q>");
}
if (rsaparameters.DP != null)
{
stringBuilder.Append("<DP>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.DP));
stringBuilder.Append("</DP>");
}
if (rsaparameters.DQ != null)
{
stringBuilder.Append("<DQ>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.DQ));
stringBuilder.Append("</DQ>");
}
if (rsaparameters.InverseQ != null)
{
stringBuilder.Append("<InverseQ>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.InverseQ));
stringBuilder.Append("</InverseQ>");
}
stringBuilder.Append("<D>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.D));
stringBuilder.Append("</D>");
}
stringBuilder.Append("</RSAKeyValue>");
}
catch
{
if (rsaparameters.P != null)
{
Array.Clear(rsaparameters.P, 0, rsaparameters.P.Length);
}
if (rsaparameters.Q != null)
{
Array.Clear(rsaparameters.Q, 0, rsaparameters.Q.Length);
}
if (rsaparameters.DP != null)
{
Array.Clear(rsaparameters.DP, 0, rsaparameters.DP.Length);
}
if (rsaparameters.DQ != null)
{
Array.Clear(rsaparameters.DQ, 0, rsaparameters.DQ.Length);
}
if (rsaparameters.InverseQ != null)
{
Array.Clear(rsaparameters.InverseQ, 0, rsaparameters.InverseQ.Length);
}
if (rsaparameters.D != null)
{
Array.Clear(rsaparameters.D, 0, rsaparameters.D.Length);
}
throw;
}
return stringBuilder.ToString();
}
// Token: 0x17000074 RID: 116
// (get) Token: 0x0600024D RID: 589 RVA: 0x0000F18C File Offset: 0x0000D38C
// (set) Token: 0x0600024E RID: 590 RVA: 0x0000F194 File Offset: 0x0000D394
public bool UseKeyBlinding
{
get
{
return this.keyBlinding;
}
set
{
this.keyBlinding = value;
}
}
// Token: 0x17000075 RID: 117
// (get) Token: 0x0600024F RID: 591 RVA: 0x0000F1A0 File Offset: 0x0000D3A0
public bool IsCrtPossible
{
get
{
return !this.keypairGenerated || this.isCRTpossible;
}
}
// Token: 0x06000250 RID: 592 RVA: 0x0000F1B8 File Offset: 0x0000D3B8
private byte[] GetPaddedValue(BigInteger value, int length)
{
byte[] bytes = value.GetBytes();
if (bytes.Length >= length)
{
return bytes;
}
byte[] array = new byte[length];
Buffer.BlockCopy(bytes, 0, array, length - bytes.Length, bytes.Length);
Array.Clear(bytes, 0, bytes.Length);
return array;
}
// Token: 0x040000F2 RID: 242
private const int defaultKeySize = 1024;
// Token: 0x040000F3 RID: 243
private bool isCRTpossible;
// Token: 0x040000F4 RID: 244
private bool keyBlinding = true;
// Token: 0x040000F5 RID: 245
private bool keypairGenerated;
// Token: 0x040000F6 RID: 246
private bool m_disposed;
// Token: 0x040000F7 RID: 247
private BigInteger d;
// Token: 0x040000F8 RID: 248
private BigInteger p;
// Token: 0x040000F9 RID: 249
private BigInteger q;
// Token: 0x040000FA RID: 250
private BigInteger dp;
// Token: 0x040000FB RID: 251
private BigInteger dq;
// Token: 0x040000FC RID: 252
private BigInteger qInv;
// Token: 0x040000FD RID: 253
private BigInteger n;
// Token: 0x040000FE RID: 254
private BigInteger e;
// Token: 0x020000C8 RID: 200
// (Invoke) Token: 0x06000705 RID: 1797
public delegate void KeyGeneratedEventHandler(object sender, EventArgs e);
}
}
@@ -0,0 +1,32 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x02000038 RID: 56
public abstract class SHA224 : HashAlgorithm
{
// Token: 0x06000253 RID: 595 RVA: 0x0000F220 File Offset: 0x0000D420
public SHA224()
{
this.HashSizeValue = 224;
}
// Token: 0x06000254 RID: 596 RVA: 0x0000F234 File Offset: 0x0000D434
public new static SHA224 Create()
{
return SHA224.Create("SHA224");
}
// Token: 0x06000255 RID: 597 RVA: 0x0000F240 File Offset: 0x0000D440
public new static SHA224 Create(string hashName)
{
object obj = CryptoConfig.CreateFromName(hashName);
if (obj == null)
{
obj = new SHA224Managed();
}
return (SHA224)obj;
}
}
}
@@ -0,0 +1,213 @@
using System;
namespace Mono.Security.Cryptography
{
// Token: 0x02000039 RID: 57
public class SHA224Managed : SHA224
{
// Token: 0x06000256 RID: 598 RVA: 0x0000F268 File Offset: 0x0000D468
public SHA224Managed()
{
this._H = new uint[8];
this._ProcessingBuffer = new byte[64];
this.Initialize();
}
// Token: 0x06000257 RID: 599 RVA: 0x0000F290 File Offset: 0x0000D490
private uint Ch(uint u, uint v, uint w)
{
return (u & v) ^ (~u & w);
}
// Token: 0x06000258 RID: 600 RVA: 0x0000F29C File Offset: 0x0000D49C
private uint Maj(uint u, uint v, uint w)
{
return (u & v) ^ (u & w) ^ (v & w);
}
// Token: 0x06000259 RID: 601 RVA: 0x0000F2AC File Offset: 0x0000D4AC
private uint Ro0(uint x)
{
return ((x >> 7) | (x << 25)) ^ ((x >> 18) | (x << 14)) ^ (x >> 3);
}
// Token: 0x0600025A RID: 602 RVA: 0x0000F2C4 File Offset: 0x0000D4C4
private uint Ro1(uint x)
{
return ((x >> 17) | (x << 15)) ^ ((x >> 19) | (x << 13)) ^ (x >> 10);
}
// Token: 0x0600025B RID: 603 RVA: 0x0000F2E0 File Offset: 0x0000D4E0
private uint Sig0(uint x)
{
return ((x >> 2) | (x << 30)) ^ ((x >> 13) | (x << 19)) ^ ((x >> 22) | (x << 10));
}
// Token: 0x0600025C RID: 604 RVA: 0x0000F300 File Offset: 0x0000D500
private uint Sig1(uint x)
{
return ((x >> 6) | (x << 26)) ^ ((x >> 11) | (x << 21)) ^ ((x >> 25) | (x << 7));
}
// Token: 0x0600025D RID: 605 RVA: 0x0000F320 File Offset: 0x0000D520
protected override void HashCore(byte[] rgb, int start, int size)
{
this.State = 1;
if (this._ProcessingBufferCount != 0)
{
if (size < 64 - this._ProcessingBufferCount)
{
Buffer.BlockCopy(rgb, start, this._ProcessingBuffer, this._ProcessingBufferCount, size);
this._ProcessingBufferCount += size;
return;
}
int i = 64 - this._ProcessingBufferCount;
Buffer.BlockCopy(rgb, start, this._ProcessingBuffer, this._ProcessingBufferCount, i);
this.ProcessBlock(this._ProcessingBuffer, 0);
this._ProcessingBufferCount = 0;
start += i;
size -= i;
}
for (int i = 0; i < size - size % 64; i += 64)
{
this.ProcessBlock(rgb, start + i);
}
if (size % 64 != 0)
{
Buffer.BlockCopy(rgb, size - size % 64 + start, this._ProcessingBuffer, 0, size % 64);
this._ProcessingBufferCount = size % 64;
}
}
// Token: 0x0600025E RID: 606 RVA: 0x0000F3FC File Offset: 0x0000D5FC
protected override byte[] HashFinal()
{
byte[] array = new byte[28];
this.ProcessFinalBlock(this._ProcessingBuffer, 0, this._ProcessingBufferCount);
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++)
{
array[i * 4 + j] = (byte)(this._H[i] >> 24 - j * 8);
}
}
this.State = 0;
return array;
}
// Token: 0x0600025F RID: 607 RVA: 0x0000F46C File Offset: 0x0000D66C
public override void Initialize()
{
this.count = 0UL;
this._ProcessingBufferCount = 0;
this._H[0] = 3238371032U;
this._H[1] = 914150663U;
this._H[2] = 812702999U;
this._H[3] = 4144912697U;
this._H[4] = 4290775857U;
this._H[5] = 1750603025U;
this._H[6] = 1694076839U;
this._H[7] = 3204075428U;
}
// Token: 0x06000260 RID: 608 RVA: 0x0000F4F0 File Offset: 0x0000D6F0
private void ProcessBlock(byte[] inputBuffer, int inputOffset)
{
this.count += 64UL;
uint[] array = new uint[64];
for (int i = 0; i < 16; i++)
{
array[i] = (uint)(((int)inputBuffer[inputOffset + 4 * i] << 24) | ((int)inputBuffer[inputOffset + 4 * i + 1] << 16) | ((int)inputBuffer[inputOffset + 4 * i + 2] << 8) | (int)inputBuffer[inputOffset + 4 * i + 3]);
}
for (int i = 16; i < 64; i++)
{
array[i] = this.Ro1(array[i - 2]) + array[i - 7] + this.Ro0(array[i - 15]) + array[i - 16];
}
uint num = this._H[0];
uint num2 = this._H[1];
uint num3 = this._H[2];
uint num4 = this._H[3];
uint num5 = this._H[4];
uint num6 = this._H[5];
uint num7 = this._H[6];
uint num8 = this._H[7];
for (int i = 0; i < 64; i++)
{
uint num9 = num8 + this.Sig1(num5) + this.Ch(num5, num6, num7) + SHAConstants.K1[i] + array[i];
uint num10 = this.Sig0(num) + this.Maj(num, num2, num3);
num8 = num7;
num7 = num6;
num6 = num5;
num5 = num4 + num9;
num4 = num3;
num3 = num2;
num2 = num;
num = num9 + num10;
}
this._H[0] += num;
this._H[1] += num2;
this._H[2] += num3;
this._H[3] += num4;
this._H[4] += num5;
this._H[5] += num6;
this._H[6] += num7;
this._H[7] += num8;
}
// Token: 0x06000261 RID: 609 RVA: 0x0000F6F8 File Offset: 0x0000D8F8
private void ProcessFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
ulong num = this.count + (ulong)((long)inputCount);
int num2 = 56 - (int)(num % 64UL);
if (num2 < 1)
{
num2 += 64;
}
byte[] array = new byte[inputCount + num2 + 8];
for (int i = 0; i < inputCount; i++)
{
array[i] = inputBuffer[i + inputOffset];
}
array[inputCount] = 128;
for (int j = inputCount + 1; j < inputCount + num2; j++)
{
array[j] = 0;
}
ulong num3 = num << 3;
this.AddLength(num3, array, inputCount + num2);
this.ProcessBlock(array, 0);
if (inputCount + num2 + 8 == 128)
{
this.ProcessBlock(array, 64);
}
}
// Token: 0x06000262 RID: 610 RVA: 0x0000F7A4 File Offset: 0x0000D9A4
internal void AddLength(ulong length, byte[] buffer, int position)
{
buffer[position++] = (byte)(length >> 56);
buffer[position++] = (byte)(length >> 48);
buffer[position++] = (byte)(length >> 40);
buffer[position++] = (byte)(length >> 32);
buffer[position++] = (byte)(length >> 24);
buffer[position++] = (byte)(length >> 16);
buffer[position++] = (byte)(length >> 8);
buffer[position] = (byte)length;
}
// Token: 0x04000101 RID: 257
private const int BLOCK_SIZE_BYTES = 64;
// Token: 0x04000102 RID: 258
private uint[] _H;
// Token: 0x04000103 RID: 259
private ulong count;
// Token: 0x04000104 RID: 260
private byte[] _ProcessingBuffer;
// Token: 0x04000105 RID: 261
private int _ProcessingBufferCount;
}
}
@@ -0,0 +1,25 @@
using System;
namespace Mono.Security.Cryptography
{
// Token: 0x02000037 RID: 55
internal sealed class SHAConstants
{
// Token: 0x06000251 RID: 593 RVA: 0x0000F1FC File Offset: 0x0000D3FC
private SHAConstants()
{
}
// Token: 0x04000100 RID: 256
public static readonly uint[] K1 = new uint[]
{
1116352408U, 1899447441U, 3049323471U, 3921009573U, 961987163U, 1508970993U, 2453635748U, 2870763221U, 3624381080U, 310598401U,
607225278U, 1426881987U, 1925078388U, 2162078206U, 2614888103U, 3248222580U, 3835390401U, 4022224774U, 264347078U, 604807628U,
770255983U, 1249150122U, 1555081692U, 1996064986U, 2554220882U, 2821834349U, 2952996808U, 3210313671U, 3336571891U, 3584528711U,
113926993U, 338241895U, 666307205U, 773529912U, 1294757372U, 1396182291U, 1695183700U, 1986661051U, 2177026350U, 2456956037U,
2730485921U, 2820302411U, 3259730800U, 3345764771U, 3516065817U, 3600352804U, 4094571909U, 275423344U, 430227734U, 506948616U,
659060556U, 883997877U, 958139571U, 1322822218U, 1537002063U, 1747873779U, 1955562222U, 2024104815U, 2227730452U, 2361852424U,
2428436474U, 2756734187U, 3204031479U, 3329325298U
};
}
}
@@ -0,0 +1,556 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Cryptography
{
// Token: 0x0200003A RID: 58
internal abstract class SymmetricTransform : IDisposable, ICryptoTransform
{
// Token: 0x06000263 RID: 611 RVA: 0x0000F810 File Offset: 0x0000DA10
public SymmetricTransform(SymmetricAlgorithm symmAlgo, bool encryption, byte[] rgbIV)
{
this.algo = symmAlgo;
this.encrypt = encryption;
this.BlockSizeByte = this.algo.BlockSize >> 3;
if (rgbIV == null)
{
rgbIV = KeyBuilder.IV(this.BlockSizeByte);
}
else
{
rgbIV = (byte[])rgbIV.Clone();
}
if (rgbIV.Length < this.BlockSizeByte)
{
string text = Locale.GetText("IV is too small ({0} bytes), it should be {1} bytes long.", new object[] { rgbIV.Length, this.BlockSizeByte });
throw new CryptographicException(text);
}
this.temp = new byte[this.BlockSizeByte];
Buffer.BlockCopy(rgbIV, 0, this.temp, 0, Math.Min(this.BlockSizeByte, rgbIV.Length));
this.temp2 = new byte[this.BlockSizeByte];
this.FeedBackByte = this.algo.FeedbackSize >> 3;
if (this.FeedBackByte != 0)
{
this.FeedBackIter = this.BlockSizeByte / this.FeedBackByte;
}
this.workBuff = new byte[this.BlockSizeByte];
this.workout = new byte[this.BlockSizeByte];
}
// Token: 0x06000264 RID: 612 RVA: 0x0000F93C File Offset: 0x0000DB3C
void IDisposable.Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
// Token: 0x06000265 RID: 613 RVA: 0x0000F94C File Offset: 0x0000DB4C
~SymmetricTransform()
{
this.Dispose(false);
}
// Token: 0x06000266 RID: 614 RVA: 0x0000F988 File Offset: 0x0000DB88
protected virtual void Dispose(bool disposing)
{
if (!this.m_disposed)
{
if (disposing)
{
Array.Clear(this.temp, 0, this.BlockSizeByte);
this.temp = null;
Array.Clear(this.temp2, 0, this.BlockSizeByte);
this.temp2 = null;
}
this.m_disposed = true;
}
}
// Token: 0x17000076 RID: 118
// (get) Token: 0x06000267 RID: 615 RVA: 0x0000F9E0 File Offset: 0x0000DBE0
public virtual bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
// Token: 0x17000077 RID: 119
// (get) Token: 0x06000268 RID: 616 RVA: 0x0000F9E4 File Offset: 0x0000DBE4
public virtual bool CanReuseTransform
{
get
{
return false;
}
}
// Token: 0x17000078 RID: 120
// (get) Token: 0x06000269 RID: 617 RVA: 0x0000F9E8 File Offset: 0x0000DBE8
public virtual int InputBlockSize
{
get
{
return this.BlockSizeByte;
}
}
// Token: 0x17000079 RID: 121
// (get) Token: 0x0600026A RID: 618 RVA: 0x0000F9F0 File Offset: 0x0000DBF0
public virtual int OutputBlockSize
{
get
{
return this.BlockSizeByte;
}
}
// Token: 0x0600026B RID: 619 RVA: 0x0000F9F8 File Offset: 0x0000DBF8
protected virtual void Transform(byte[] input, byte[] output)
{
switch (this.algo.Mode)
{
case CipherMode.CBC:
this.CBC(input, output);
break;
case CipherMode.ECB:
this.ECB(input, output);
break;
case CipherMode.OFB:
this.OFB(input, output);
break;
case CipherMode.CFB:
this.CFB(input, output);
break;
case CipherMode.CTS:
this.CTS(input, output);
break;
default:
throw new NotImplementedException("Unkown CipherMode" + this.algo.Mode.ToString());
}
}
// Token: 0x0600026C RID: 620
protected abstract void ECB(byte[] input, byte[] output);
// Token: 0x0600026D RID: 621 RVA: 0x0000FA98 File Offset: 0x0000DC98
protected virtual void CBC(byte[] input, byte[] output)
{
if (this.encrypt)
{
for (int i = 0; i < this.BlockSizeByte; i++)
{
byte[] array = this.temp;
int num = i;
array[num] ^= input[i];
}
this.ECB(this.temp, output);
Buffer.BlockCopy(output, 0, this.temp, 0, this.BlockSizeByte);
}
else
{
Buffer.BlockCopy(input, 0, this.temp2, 0, this.BlockSizeByte);
this.ECB(input, output);
for (int j = 0; j < this.BlockSizeByte; j++)
{
int num2 = j;
output[num2] ^= this.temp[j];
}
Buffer.BlockCopy(this.temp2, 0, this.temp, 0, this.BlockSizeByte);
}
}
// Token: 0x0600026E RID: 622 RVA: 0x0000FB64 File Offset: 0x0000DD64
protected virtual void CFB(byte[] input, byte[] output)
{
if (this.encrypt)
{
for (int i = 0; i < this.FeedBackIter; i++)
{
this.ECB(this.temp, this.temp2);
for (int j = 0; j < this.FeedBackByte; j++)
{
output[j + i] = this.temp2[j] ^ input[j + i];
}
Buffer.BlockCopy(this.temp, this.FeedBackByte, this.temp, 0, this.BlockSizeByte - this.FeedBackByte);
Buffer.BlockCopy(output, i, this.temp, this.BlockSizeByte - this.FeedBackByte, this.FeedBackByte);
}
}
else
{
for (int k = 0; k < this.FeedBackIter; k++)
{
this.encrypt = true;
this.ECB(this.temp, this.temp2);
this.encrypt = false;
Buffer.BlockCopy(this.temp, this.FeedBackByte, this.temp, 0, this.BlockSizeByte - this.FeedBackByte);
Buffer.BlockCopy(input, k, this.temp, this.BlockSizeByte - this.FeedBackByte, this.FeedBackByte);
for (int l = 0; l < this.FeedBackByte; l++)
{
output[l + k] = this.temp2[l] ^ input[l + k];
}
}
}
}
// Token: 0x0600026F RID: 623 RVA: 0x0000FCC4 File Offset: 0x0000DEC4
protected virtual void OFB(byte[] input, byte[] output)
{
throw new CryptographicException("OFB isn't supported by the framework");
}
// Token: 0x06000270 RID: 624 RVA: 0x0000FCD0 File Offset: 0x0000DED0
protected virtual void CTS(byte[] input, byte[] output)
{
throw new CryptographicException("CTS isn't supported by the framework");
}
// Token: 0x06000271 RID: 625 RVA: 0x0000FCDC File Offset: 0x0000DEDC
private void CheckInput(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (inputBuffer == null)
{
throw new ArgumentNullException("inputBuffer");
}
if (inputOffset < 0)
{
throw new ArgumentOutOfRangeException("inputOffset", "< 0");
}
if (inputCount < 0)
{
throw new ArgumentOutOfRangeException("inputCount", "< 0");
}
if (inputOffset > inputBuffer.Length - inputCount)
{
throw new ArgumentException("inputBuffer", Locale.GetText("Overflow"));
}
}
// Token: 0x06000272 RID: 626 RVA: 0x0000FD48 File Offset: 0x0000DF48
public virtual int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (this.m_disposed)
{
throw new ObjectDisposedException("Object is disposed");
}
this.CheckInput(inputBuffer, inputOffset, inputCount);
if (outputBuffer == null)
{
throw new ArgumentNullException("outputBuffer");
}
if (outputOffset < 0)
{
throw new ArgumentOutOfRangeException("outputOffset", "< 0");
}
int num = outputBuffer.Length - inputCount - outputOffset;
if (!this.encrypt && 0 > num && (this.algo.Padding == PaddingMode.None || this.algo.Padding == PaddingMode.Zeros))
{
throw new CryptographicException("outputBuffer", Locale.GetText("Overflow"));
}
if (this.KeepLastBlock)
{
if (0 > num + this.BlockSizeByte)
{
throw new CryptographicException("outputBuffer", Locale.GetText("Overflow"));
}
}
else if (0 > num)
{
if (inputBuffer.Length - inputOffset - outputBuffer.Length != this.BlockSizeByte)
{
throw new CryptographicException("outputBuffer", Locale.GetText("Overflow"));
}
inputCount = outputBuffer.Length - outputOffset;
}
return this.InternalTransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
}
// Token: 0x1700007A RID: 122
// (get) Token: 0x06000273 RID: 627 RVA: 0x0000FE70 File Offset: 0x0000E070
private bool KeepLastBlock
{
get
{
return !this.encrypt && this.algo.Padding != PaddingMode.None && this.algo.Padding != PaddingMode.Zeros;
}
}
// Token: 0x06000274 RID: 628 RVA: 0x0000FEB0 File Offset: 0x0000E0B0
private int InternalTransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
int num = inputOffset;
int num2;
if (inputCount != this.BlockSizeByte)
{
if (inputCount % this.BlockSizeByte != 0)
{
throw new CryptographicException("Invalid input block size.");
}
num2 = inputCount / this.BlockSizeByte;
}
else
{
num2 = 1;
}
if (this.KeepLastBlock)
{
num2--;
}
int num3 = 0;
if (this.lastBlock)
{
this.Transform(this.workBuff, this.workout);
Buffer.BlockCopy(this.workout, 0, outputBuffer, outputOffset, this.BlockSizeByte);
outputOffset += this.BlockSizeByte;
num3 += this.BlockSizeByte;
this.lastBlock = false;
}
for (int i = 0; i < num2; i++)
{
Buffer.BlockCopy(inputBuffer, num, this.workBuff, 0, this.BlockSizeByte);
this.Transform(this.workBuff, this.workout);
Buffer.BlockCopy(this.workout, 0, outputBuffer, outputOffset, this.BlockSizeByte);
num += this.BlockSizeByte;
outputOffset += this.BlockSizeByte;
num3 += this.BlockSizeByte;
}
if (this.KeepLastBlock)
{
Buffer.BlockCopy(inputBuffer, num, this.workBuff, 0, this.BlockSizeByte);
this.lastBlock = true;
}
return num3;
}
// Token: 0x06000275 RID: 629 RVA: 0x0000FFE4 File Offset: 0x0000E1E4
private void Random(byte[] buffer, int start, int length)
{
if (this._rng == null)
{
this._rng = RandomNumberGenerator.Create();
}
byte[] array = new byte[length];
this._rng.GetBytes(array);
Buffer.BlockCopy(array, 0, buffer, start, length);
}
// Token: 0x06000276 RID: 630 RVA: 0x00010024 File Offset: 0x0000E224
private void ThrowBadPaddingException(PaddingMode padding, int length, int position)
{
string text = string.Format(Locale.GetText("Bad {0} padding."), padding);
if (length >= 0)
{
text += string.Format(Locale.GetText(" Invalid length {0}."), length);
}
if (position >= 0)
{
text += string.Format(Locale.GetText(" Error found at position {0}."), position);
}
throw new CryptographicException(text);
}
// Token: 0x06000277 RID: 631 RVA: 0x00010094 File Offset: 0x0000E294
private byte[] FinalEncrypt(byte[] inputBuffer, int inputOffset, int inputCount)
{
int num = inputCount / this.BlockSizeByte * this.BlockSizeByte;
int num2 = inputCount - num;
int i = num;
switch (this.algo.Padding)
{
case PaddingMode.PKCS7:
case PaddingMode.ANSIX923:
case PaddingMode.ISO10126:
i += this.BlockSizeByte;
goto IL_A8;
}
if (inputCount == 0)
{
return new byte[0];
}
if (num2 != 0)
{
if (this.algo.Padding == PaddingMode.None)
{
throw new CryptographicException("invalid block length");
}
byte[] array = new byte[num + this.BlockSizeByte];
Buffer.BlockCopy(inputBuffer, inputOffset, array, 0, inputCount);
inputBuffer = array;
inputOffset = 0;
inputCount = array.Length;
i = inputCount;
}
IL_A8:
byte[] array2 = new byte[i];
int num3 = 0;
while (i > this.BlockSizeByte)
{
this.InternalTransformBlock(inputBuffer, inputOffset, this.BlockSizeByte, array2, num3);
inputOffset += this.BlockSizeByte;
num3 += this.BlockSizeByte;
i -= this.BlockSizeByte;
}
byte b = (byte)(this.BlockSizeByte - num2);
switch (this.algo.Padding)
{
case PaddingMode.PKCS7:
{
int num4 = array2.Length;
while (--num4 >= array2.Length - (int)b)
{
array2[num4] = b;
}
Buffer.BlockCopy(inputBuffer, inputOffset, array2, num, num2);
this.InternalTransformBlock(array2, num, this.BlockSizeByte, array2, num);
return array2;
}
case PaddingMode.ANSIX923:
array2[array2.Length - 1] = b;
Buffer.BlockCopy(inputBuffer, inputOffset, array2, num, num2);
this.InternalTransformBlock(array2, num, this.BlockSizeByte, array2, num);
return array2;
case PaddingMode.ISO10126:
this.Random(array2, array2.Length - (int)b, (int)(b - 1));
array2[array2.Length - 1] = b;
Buffer.BlockCopy(inputBuffer, inputOffset, array2, num, num2);
this.InternalTransformBlock(array2, num, this.BlockSizeByte, array2, num);
return array2;
}
this.InternalTransformBlock(inputBuffer, inputOffset, this.BlockSizeByte, array2, num3);
return array2;
}
// Token: 0x06000278 RID: 632 RVA: 0x000102A0 File Offset: 0x0000E4A0
private byte[] FinalDecrypt(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (inputCount % this.BlockSizeByte > 0)
{
throw new CryptographicException("Invalid input block size.");
}
int num = inputCount;
if (this.lastBlock)
{
num += this.BlockSizeByte;
}
byte[] array = new byte[num];
int num2 = 0;
while (inputCount > 0)
{
int num3 = this.InternalTransformBlock(inputBuffer, inputOffset, this.BlockSizeByte, array, num2);
inputOffset += this.BlockSizeByte;
num2 += num3;
inputCount -= this.BlockSizeByte;
}
if (this.lastBlock)
{
this.Transform(this.workBuff, this.workout);
Buffer.BlockCopy(this.workout, 0, array, num2, this.BlockSizeByte);
num2 += this.BlockSizeByte;
this.lastBlock = false;
}
byte b = ((num <= 0) ? 0 : array[num - 1]);
switch (this.algo.Padding)
{
case PaddingMode.PKCS7:
{
if (b == 0 || (int)b > this.BlockSizeByte)
{
this.ThrowBadPaddingException(this.algo.Padding, (int)b, -1);
}
for (int i = (int)(b - 1); i > 0; i--)
{
if (array[num - 1 - i] != b)
{
this.ThrowBadPaddingException(this.algo.Padding, -1, i);
}
}
num -= (int)b;
break;
}
case PaddingMode.ANSIX923:
{
if (b == 0 || (int)b > this.BlockSizeByte)
{
this.ThrowBadPaddingException(this.algo.Padding, (int)b, -1);
}
for (int j = (int)(b - 1); j > 0; j--)
{
if (array[num - 1 - j] != 0)
{
this.ThrowBadPaddingException(this.algo.Padding, -1, j);
}
}
num -= (int)b;
break;
}
case PaddingMode.ISO10126:
if (b == 0 || (int)b > this.BlockSizeByte)
{
this.ThrowBadPaddingException(this.algo.Padding, (int)b, -1);
}
num -= (int)b;
break;
}
if (num > 0)
{
byte[] array2 = new byte[num];
Buffer.BlockCopy(array, 0, array2, 0, num);
Array.Clear(array, 0, array.Length);
return array2;
}
return new byte[0];
}
// Token: 0x06000279 RID: 633 RVA: 0x000104DC File Offset: 0x0000E6DC
public virtual byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (this.m_disposed)
{
throw new ObjectDisposedException("Object is disposed");
}
this.CheckInput(inputBuffer, inputOffset, inputCount);
if (this.encrypt)
{
return this.FinalEncrypt(inputBuffer, inputOffset, inputCount);
}
return this.FinalDecrypt(inputBuffer, inputOffset, inputCount);
}
// Token: 0x04000106 RID: 262
protected SymmetricAlgorithm algo;
// Token: 0x04000107 RID: 263
protected bool encrypt;
// Token: 0x04000108 RID: 264
private int BlockSizeByte;
// Token: 0x04000109 RID: 265
private byte[] temp;
// Token: 0x0400010A RID: 266
private byte[] temp2;
// Token: 0x0400010B RID: 267
private byte[] workBuff;
// Token: 0x0400010C RID: 268
private byte[] workout;
// Token: 0x0400010D RID: 269
private int FeedBackByte;
// Token: 0x0400010E RID: 270
private int FeedBackIter;
// Token: 0x0400010F RID: 271
private bool m_disposed;
// Token: 0x04000110 RID: 272
private bool lastBlock;
// Token: 0x04000111 RID: 273
private RandomNumberGenerator _rng;
}
}
+1314
View File
@@ -0,0 +1,1314 @@
using System;
using System.Collections;
using System.Security.Cryptography;
using Mono.Security.X509;
namespace Mono.Security
{
// Token: 0x02000011 RID: 17
public sealed class PKCS7
{
// Token: 0x060000AF RID: 175 RVA: 0x00005C0C File Offset: 0x00003E0C
private PKCS7()
{
}
// Token: 0x060000B0 RID: 176 RVA: 0x00005C14 File Offset: 0x00003E14
public static ASN1 Attribute(string oid, ASN1 value)
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(oid));
ASN1 asn2 = asn.Add(new ASN1(49));
asn2.Add(value);
return asn;
}
// Token: 0x060000B1 RID: 177 RVA: 0x00005C50 File Offset: 0x00003E50
public static ASN1 AlgorithmIdentifier(string oid)
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(oid));
asn.Add(new ASN1(5));
return asn;
}
// Token: 0x060000B2 RID: 178 RVA: 0x00005C80 File Offset: 0x00003E80
public static ASN1 AlgorithmIdentifier(string oid, ASN1 parameters)
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(oid));
asn.Add(parameters);
return asn;
}
// Token: 0x060000B3 RID: 179 RVA: 0x00005CAC File Offset: 0x00003EAC
public static ASN1 IssuerAndSerialNumber(X509Certificate x509)
{
ASN1 asn = null;
ASN1 asn2 = null;
ASN1 asn3 = new ASN1(x509.RawData);
int i = 0;
bool flag = false;
while (i < asn3[0].Count)
{
ASN1 asn4 = asn3[0][i++];
if (asn4.Tag == 2)
{
asn2 = asn4;
}
else if (asn4.Tag == 48)
{
if (flag)
{
asn = asn4;
break;
}
flag = true;
}
}
ASN1 asn5 = new ASN1(48);
asn5.Add(asn);
asn5.Add(asn2);
return asn5;
}
// Token: 0x02000012 RID: 18
public class Oid
{
// Token: 0x04000034 RID: 52
public const string rsaEncryption = "1.2.840.113549.1.1.1";
// Token: 0x04000035 RID: 53
public const string data = "1.2.840.113549.1.7.1";
// Token: 0x04000036 RID: 54
public const string signedData = "1.2.840.113549.1.7.2";
// Token: 0x04000037 RID: 55
public const string envelopedData = "1.2.840.113549.1.7.3";
// Token: 0x04000038 RID: 56
public const string signedAndEnvelopedData = "1.2.840.113549.1.7.4";
// Token: 0x04000039 RID: 57
public const string digestedData = "1.2.840.113549.1.7.5";
// Token: 0x0400003A RID: 58
public const string encryptedData = "1.2.840.113549.1.7.6";
// Token: 0x0400003B RID: 59
public const string contentType = "1.2.840.113549.1.9.3";
// Token: 0x0400003C RID: 60
public const string messageDigest = "1.2.840.113549.1.9.4";
// Token: 0x0400003D RID: 61
public const string signingTime = "1.2.840.113549.1.9.5";
// Token: 0x0400003E RID: 62
public const string countersignature = "1.2.840.113549.1.9.6";
}
// Token: 0x02000013 RID: 19
public class ContentInfo
{
// Token: 0x060000B5 RID: 181 RVA: 0x00005D54 File Offset: 0x00003F54
public ContentInfo()
{
this.content = new ASN1(160);
}
// Token: 0x060000B6 RID: 182 RVA: 0x00005D6C File Offset: 0x00003F6C
public ContentInfo(string oid)
: this()
{
this.contentType = oid;
}
// Token: 0x060000B7 RID: 183 RVA: 0x00005D7C File Offset: 0x00003F7C
public ContentInfo(byte[] data)
: this(new ASN1(data))
{
}
// Token: 0x060000B8 RID: 184 RVA: 0x00005D8C File Offset: 0x00003F8C
public ContentInfo(ASN1 asn1)
{
if (asn1.Tag != 48 || (asn1.Count < 1 && asn1.Count > 2))
{
throw new ArgumentException("Invalid ASN1");
}
if (asn1[0].Tag != 6)
{
throw new ArgumentException("Invalid contentType");
}
this.contentType = ASN1Convert.ToOid(asn1[0]);
if (asn1.Count > 1)
{
if (asn1[1].Tag != 160)
{
throw new ArgumentException("Invalid content");
}
this.content = asn1[1];
}
}
// Token: 0x1700000A RID: 10
// (get) Token: 0x060000B9 RID: 185 RVA: 0x00005E38 File Offset: 0x00004038
public ASN1 ASN1
{
get
{
return this.GetASN1();
}
}
// Token: 0x1700000B RID: 11
// (get) Token: 0x060000BA RID: 186 RVA: 0x00005E40 File Offset: 0x00004040
// (set) Token: 0x060000BB RID: 187 RVA: 0x00005E48 File Offset: 0x00004048
public ASN1 Content
{
get
{
return this.content;
}
set
{
this.content = value;
}
}
// Token: 0x1700000C RID: 12
// (get) Token: 0x060000BC RID: 188 RVA: 0x00005E54 File Offset: 0x00004054
// (set) Token: 0x060000BD RID: 189 RVA: 0x00005E5C File Offset: 0x0000405C
public string ContentType
{
get
{
return this.contentType;
}
set
{
this.contentType = value;
}
}
// Token: 0x060000BE RID: 190 RVA: 0x00005E68 File Offset: 0x00004068
internal ASN1 GetASN1()
{
ASN1 asn = new ASN1(48);
asn.Add(ASN1Convert.FromOid(this.contentType));
if (this.content != null && this.content.Count > 0)
{
asn.Add(this.content);
}
return asn;
}
// Token: 0x060000BF RID: 191 RVA: 0x00005EBC File Offset: 0x000040BC
public byte[] GetBytes()
{
return this.GetASN1().GetBytes();
}
// Token: 0x0400003F RID: 63
private string contentType;
// Token: 0x04000040 RID: 64
private ASN1 content;
}
// Token: 0x02000014 RID: 20
public class EncryptedData
{
// Token: 0x060000C0 RID: 192 RVA: 0x00005ECC File Offset: 0x000040CC
public EncryptedData()
{
this._version = 0;
}
// Token: 0x060000C1 RID: 193 RVA: 0x00005EDC File Offset: 0x000040DC
public EncryptedData(byte[] data)
: this(new ASN1(data))
{
}
// Token: 0x060000C2 RID: 194 RVA: 0x00005EEC File Offset: 0x000040EC
public EncryptedData(ASN1 asn1)
: this()
{
if (asn1.Tag != 48 || asn1.Count < 2)
{
throw new ArgumentException("Invalid EncryptedData");
}
if (asn1[0].Tag != 2)
{
throw new ArgumentException("Invalid version");
}
this._version = asn1[0].Value[0];
ASN1 asn2 = asn1[1];
if (asn2.Tag != 48)
{
throw new ArgumentException("missing EncryptedContentInfo");
}
ASN1 asn3 = asn2[0];
if (asn3.Tag != 6)
{
throw new ArgumentException("missing EncryptedContentInfo.ContentType");
}
this._content = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn3));
ASN1 asn4 = asn2[1];
if (asn4.Tag != 48)
{
throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
}
this._encryptionAlgorithm = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn4[0]));
this._encryptionAlgorithm.Content = asn4[1];
ASN1 asn5 = asn2[2];
if (asn5.Tag != 128)
{
throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
}
this._encrypted = asn5.Value;
}
// Token: 0x1700000D RID: 13
// (get) Token: 0x060000C3 RID: 195 RVA: 0x0000601C File Offset: 0x0000421C
public ASN1 ASN1
{
get
{
return this.GetASN1();
}
}
// Token: 0x1700000E RID: 14
// (get) Token: 0x060000C4 RID: 196 RVA: 0x00006024 File Offset: 0x00004224
public PKCS7.ContentInfo ContentInfo
{
get
{
return this._content;
}
}
// Token: 0x1700000F RID: 15
// (get) Token: 0x060000C5 RID: 197 RVA: 0x0000602C File Offset: 0x0000422C
public PKCS7.ContentInfo EncryptionAlgorithm
{
get
{
return this._encryptionAlgorithm;
}
}
// Token: 0x17000010 RID: 16
// (get) Token: 0x060000C6 RID: 198 RVA: 0x00006034 File Offset: 0x00004234
public byte[] EncryptedContent
{
get
{
if (this._encrypted == null)
{
return null;
}
return (byte[])this._encrypted.Clone();
}
}
// Token: 0x17000011 RID: 17
// (get) Token: 0x060000C7 RID: 199 RVA: 0x00006054 File Offset: 0x00004254
// (set) Token: 0x060000C8 RID: 200 RVA: 0x0000605C File Offset: 0x0000425C
public byte Version
{
get
{
return this._version;
}
set
{
this._version = value;
}
}
// Token: 0x060000C9 RID: 201 RVA: 0x00006068 File Offset: 0x00004268
internal ASN1 GetASN1()
{
return null;
}
// Token: 0x060000CA RID: 202 RVA: 0x0000606C File Offset: 0x0000426C
public byte[] GetBytes()
{
return this.GetASN1().GetBytes();
}
// Token: 0x04000041 RID: 65
private byte _version;
// Token: 0x04000042 RID: 66
private PKCS7.ContentInfo _content;
// Token: 0x04000043 RID: 67
private PKCS7.ContentInfo _encryptionAlgorithm;
// Token: 0x04000044 RID: 68
private byte[] _encrypted;
}
// Token: 0x02000015 RID: 21
public class EnvelopedData
{
// Token: 0x060000CB RID: 203 RVA: 0x0000607C File Offset: 0x0000427C
public EnvelopedData()
{
this._version = 0;
this._content = new PKCS7.ContentInfo();
this._encryptionAlgorithm = new PKCS7.ContentInfo();
this._recipientInfos = new ArrayList();
}
// Token: 0x060000CC RID: 204 RVA: 0x000060B8 File Offset: 0x000042B8
public EnvelopedData(byte[] data)
: this(new ASN1(data))
{
}
// Token: 0x060000CD RID: 205 RVA: 0x000060C8 File Offset: 0x000042C8
public EnvelopedData(ASN1 asn1)
: this()
{
if (asn1[0].Tag != 48 || asn1[0].Count < 3)
{
throw new ArgumentException("Invalid EnvelopedData");
}
if (asn1[0][0].Tag != 2)
{
throw new ArgumentException("Invalid version");
}
this._version = asn1[0][0].Value[0];
ASN1 asn2 = asn1[0][1];
if (asn2.Tag != 49)
{
throw new ArgumentException("missing RecipientInfos");
}
for (int i = 0; i < asn2.Count; i++)
{
ASN1 asn3 = asn2[i];
this._recipientInfos.Add(new PKCS7.RecipientInfo(asn3));
}
ASN1 asn4 = asn1[0][2];
if (asn4.Tag != 48)
{
throw new ArgumentException("missing EncryptedContentInfo");
}
ASN1 asn5 = asn4[0];
if (asn5.Tag != 6)
{
throw new ArgumentException("missing EncryptedContentInfo.ContentType");
}
this._content = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn5));
ASN1 asn6 = asn4[1];
if (asn6.Tag != 48)
{
throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
}
this._encryptionAlgorithm = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn6[0]));
this._encryptionAlgorithm.Content = asn6[1];
ASN1 asn7 = asn4[2];
if (asn7.Tag != 128)
{
throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
}
this._encrypted = asn7.Value;
}
// Token: 0x17000012 RID: 18
// (get) Token: 0x060000CE RID: 206 RVA: 0x00006278 File Offset: 0x00004478
public ArrayList RecipientInfos
{
get
{
return this._recipientInfos;
}
}
// Token: 0x17000013 RID: 19
// (get) Token: 0x060000CF RID: 207 RVA: 0x00006280 File Offset: 0x00004480
public ASN1 ASN1
{
get
{
return this.GetASN1();
}
}
// Token: 0x17000014 RID: 20
// (get) Token: 0x060000D0 RID: 208 RVA: 0x00006288 File Offset: 0x00004488
public PKCS7.ContentInfo ContentInfo
{
get
{
return this._content;
}
}
// Token: 0x17000015 RID: 21
// (get) Token: 0x060000D1 RID: 209 RVA: 0x00006290 File Offset: 0x00004490
public PKCS7.ContentInfo EncryptionAlgorithm
{
get
{
return this._encryptionAlgorithm;
}
}
// Token: 0x17000016 RID: 22
// (get) Token: 0x060000D2 RID: 210 RVA: 0x00006298 File Offset: 0x00004498
public byte[] EncryptedContent
{
get
{
if (this._encrypted == null)
{
return null;
}
return (byte[])this._encrypted.Clone();
}
}
// Token: 0x17000017 RID: 23
// (get) Token: 0x060000D3 RID: 211 RVA: 0x000062B8 File Offset: 0x000044B8
// (set) Token: 0x060000D4 RID: 212 RVA: 0x000062C0 File Offset: 0x000044C0
public byte Version
{
get
{
return this._version;
}
set
{
this._version = value;
}
}
// Token: 0x060000D5 RID: 213 RVA: 0x000062CC File Offset: 0x000044CC
internal ASN1 GetASN1()
{
return new ASN1(48);
}
// Token: 0x060000D6 RID: 214 RVA: 0x000062E4 File Offset: 0x000044E4
public byte[] GetBytes()
{
return this.GetASN1().GetBytes();
}
// Token: 0x04000045 RID: 69
private byte _version;
// Token: 0x04000046 RID: 70
private PKCS7.ContentInfo _content;
// Token: 0x04000047 RID: 71
private PKCS7.ContentInfo _encryptionAlgorithm;
// Token: 0x04000048 RID: 72
private ArrayList _recipientInfos;
// Token: 0x04000049 RID: 73
private byte[] _encrypted;
}
// Token: 0x02000016 RID: 22
public class RecipientInfo
{
// Token: 0x060000D7 RID: 215 RVA: 0x000062F4 File Offset: 0x000044F4
public RecipientInfo()
{
}
// Token: 0x060000D8 RID: 216 RVA: 0x000062FC File Offset: 0x000044FC
public RecipientInfo(ASN1 data)
{
if (data.Tag != 48)
{
throw new ArgumentException("Invalid RecipientInfo");
}
ASN1 asn = data[0];
if (asn.Tag != 2)
{
throw new ArgumentException("missing Version");
}
this._version = (int)asn.Value[0];
ASN1 asn2 = data[1];
if (asn2.Tag == 128 && this._version == 3)
{
this._ski = asn2.Value;
}
else
{
this._issuer = X501.ToString(asn2[0]);
this._serial = asn2[1].Value;
}
ASN1 asn3 = data[2];
this._oid = ASN1Convert.ToOid(asn3[0]);
ASN1 asn4 = data[3];
this._key = asn4.Value;
}
// Token: 0x17000018 RID: 24
// (get) Token: 0x060000D9 RID: 217 RVA: 0x000063DC File Offset: 0x000045DC
public string Oid
{
get
{
return this._oid;
}
}
// Token: 0x17000019 RID: 25
// (get) Token: 0x060000DA RID: 218 RVA: 0x000063E4 File Offset: 0x000045E4
public byte[] Key
{
get
{
if (this._key == null)
{
return null;
}
return (byte[])this._key.Clone();
}
}
// Token: 0x1700001A RID: 26
// (get) Token: 0x060000DB RID: 219 RVA: 0x00006404 File Offset: 0x00004604
public byte[] SubjectKeyIdentifier
{
get
{
if (this._ski == null)
{
return null;
}
return (byte[])this._ski.Clone();
}
}
// Token: 0x1700001B RID: 27
// (get) Token: 0x060000DC RID: 220 RVA: 0x00006424 File Offset: 0x00004624
public string Issuer
{
get
{
return this._issuer;
}
}
// Token: 0x1700001C RID: 28
// (get) Token: 0x060000DD RID: 221 RVA: 0x0000642C File Offset: 0x0000462C
public byte[] Serial
{
get
{
if (this._serial == null)
{
return null;
}
return (byte[])this._serial.Clone();
}
}
// Token: 0x1700001D RID: 29
// (get) Token: 0x060000DE RID: 222 RVA: 0x0000644C File Offset: 0x0000464C
public int Version
{
get
{
return this._version;
}
}
// Token: 0x0400004A RID: 74
private int _version;
// Token: 0x0400004B RID: 75
private string _oid;
// Token: 0x0400004C RID: 76
private byte[] _key;
// Token: 0x0400004D RID: 77
private byte[] _ski;
// Token: 0x0400004E RID: 78
private string _issuer;
// Token: 0x0400004F RID: 79
private byte[] _serial;
}
// Token: 0x02000017 RID: 23
public class SignedData
{
// Token: 0x060000DF RID: 223 RVA: 0x00006454 File Offset: 0x00004654
public SignedData()
{
this.version = 1;
this.contentInfo = new PKCS7.ContentInfo();
this.certs = new X509CertificateCollection();
this.crls = new ArrayList();
this.signerInfo = new PKCS7.SignerInfo();
this.mda = true;
this.signed = false;
}
// Token: 0x060000E0 RID: 224 RVA: 0x000064A8 File Offset: 0x000046A8
public SignedData(byte[] data)
: this(new ASN1(data))
{
}
// Token: 0x060000E1 RID: 225 RVA: 0x000064B8 File Offset: 0x000046B8
public SignedData(ASN1 asn1)
{
if (asn1[0].Tag != 48 || asn1[0].Count < 4)
{
throw new ArgumentException("Invalid SignedData");
}
if (asn1[0][0].Tag != 2)
{
throw new ArgumentException("Invalid version");
}
this.version = asn1[0][0].Value[0];
this.contentInfo = new PKCS7.ContentInfo(asn1[0][2]);
int num = 3;
this.certs = new X509CertificateCollection();
if (asn1[0][num].Tag == 160)
{
for (int i = 0; i < asn1[0][num].Count; i++)
{
this.certs.Add(new X509Certificate(asn1[0][num][i].GetBytes()));
}
num++;
}
this.crls = new ArrayList();
if (asn1[0][num].Tag == 161)
{
for (int j = 0; j < asn1[0][num].Count; j++)
{
this.crls.Add(asn1[0][num][j].GetBytes());
}
num++;
}
if (asn1[0][num].Count > 0)
{
this.signerInfo = new PKCS7.SignerInfo(asn1[0][num]);
}
else
{
this.signerInfo = new PKCS7.SignerInfo();
}
if (this.signerInfo.HashName != null)
{
this.HashName = this.OidToName(this.signerInfo.HashName);
}
this.mda = this.signerInfo.AuthenticatedAttributes.Count > 0;
}
// Token: 0x1700001E RID: 30
// (get) Token: 0x060000E2 RID: 226 RVA: 0x000066BC File Offset: 0x000048BC
public ASN1 ASN1
{
get
{
return this.GetASN1();
}
}
// Token: 0x1700001F RID: 31
// (get) Token: 0x060000E3 RID: 227 RVA: 0x000066C4 File Offset: 0x000048C4
public X509CertificateCollection Certificates
{
get
{
return this.certs;
}
}
// Token: 0x17000020 RID: 32
// (get) Token: 0x060000E4 RID: 228 RVA: 0x000066CC File Offset: 0x000048CC
public PKCS7.ContentInfo ContentInfo
{
get
{
return this.contentInfo;
}
}
// Token: 0x17000021 RID: 33
// (get) Token: 0x060000E5 RID: 229 RVA: 0x000066D4 File Offset: 0x000048D4
public ArrayList Crls
{
get
{
return this.crls;
}
}
// Token: 0x17000022 RID: 34
// (get) Token: 0x060000E6 RID: 230 RVA: 0x000066DC File Offset: 0x000048DC
// (set) Token: 0x060000E7 RID: 231 RVA: 0x000066E4 File Offset: 0x000048E4
public string HashName
{
get
{
return this.hashAlgorithm;
}
set
{
this.hashAlgorithm = value;
this.signerInfo.HashName = value;
}
}
// Token: 0x17000023 RID: 35
// (get) Token: 0x060000E8 RID: 232 RVA: 0x000066FC File Offset: 0x000048FC
public PKCS7.SignerInfo SignerInfo
{
get
{
return this.signerInfo;
}
}
// Token: 0x17000024 RID: 36
// (get) Token: 0x060000E9 RID: 233 RVA: 0x00006704 File Offset: 0x00004904
// (set) Token: 0x060000EA RID: 234 RVA: 0x0000670C File Offset: 0x0000490C
public byte Version
{
get
{
return this.version;
}
set
{
this.version = value;
}
}
// Token: 0x17000025 RID: 37
// (get) Token: 0x060000EB RID: 235 RVA: 0x00006718 File Offset: 0x00004918
// (set) Token: 0x060000EC RID: 236 RVA: 0x00006720 File Offset: 0x00004920
public bool UseAuthenticatedAttributes
{
get
{
return this.mda;
}
set
{
this.mda = value;
}
}
// Token: 0x060000ED RID: 237 RVA: 0x0000672C File Offset: 0x0000492C
public bool VerifySignature(AsymmetricAlgorithm aa)
{
if (aa == null)
{
return false;
}
RSAPKCS1SignatureDeformatter rsapkcs1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(aa);
rsapkcs1SignatureDeformatter.SetHashAlgorithm(this.hashAlgorithm);
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.hashAlgorithm);
byte[] signature = this.signerInfo.Signature;
byte[] array;
if (this.mda)
{
ASN1 asn = new ASN1(49);
foreach (object obj in this.signerInfo.AuthenticatedAttributes)
{
ASN1 asn2 = (ASN1)obj;
asn.Add(asn2);
}
array = hashAlgorithm.ComputeHash(asn.GetBytes());
}
else
{
array = hashAlgorithm.ComputeHash(this.contentInfo.Content[0].Value);
}
return array != null && signature != null && rsapkcs1SignatureDeformatter.VerifySignature(array, signature);
}
// Token: 0x060000EE RID: 238 RVA: 0x0000683C File Offset: 0x00004A3C
internal string OidToName(string oid)
{
switch (oid)
{
case "1.3.14.3.2.26":
return "SHA1";
case "1.2.840.113549.2.2":
return "MD2";
case "1.2.840.113549.2.5":
return "MD5";
case "2.16.840.1.101.3.4.1":
return "SHA256";
case "2.16.840.1.101.3.4.2":
return "SHA384";
case "2.16.840.1.101.3.4.3":
return "SHA512";
}
return oid;
}
// Token: 0x060000EF RID: 239 RVA: 0x00006910 File Offset: 0x00004B10
internal ASN1 GetASN1()
{
ASN1 asn = new ASN1(48);
byte[] array = new byte[] { this.version };
asn.Add(new ASN1(2, array));
ASN1 asn2 = asn.Add(new ASN1(49));
if (this.hashAlgorithm != null)
{
string text = CryptoConfig.MapNameToOID(this.hashAlgorithm);
asn2.Add(PKCS7.AlgorithmIdentifier(text));
}
ASN1 asn3 = this.contentInfo.ASN1;
asn.Add(asn3);
if (!this.signed && this.hashAlgorithm != null)
{
if (this.mda)
{
ASN1 asn4 = PKCS7.Attribute("1.2.840.113549.1.9.3", asn3[0]);
this.signerInfo.AuthenticatedAttributes.Add(asn4);
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.hashAlgorithm);
byte[] array2 = hashAlgorithm.ComputeHash(asn3[1][0].Value);
ASN1 asn5 = new ASN1(48);
ASN1 asn6 = PKCS7.Attribute("1.2.840.113549.1.9.4", asn5.Add(new ASN1(4, array2)));
this.signerInfo.AuthenticatedAttributes.Add(asn6);
}
else
{
RSAPKCS1SignatureFormatter rsapkcs1SignatureFormatter = new RSAPKCS1SignatureFormatter(this.signerInfo.Key);
rsapkcs1SignatureFormatter.SetHashAlgorithm(this.hashAlgorithm);
HashAlgorithm hashAlgorithm2 = HashAlgorithm.Create(this.hashAlgorithm);
byte[] array3 = hashAlgorithm2.ComputeHash(asn3[1][0].Value);
this.signerInfo.Signature = rsapkcs1SignatureFormatter.CreateSignature(array3);
}
this.signed = true;
}
if (this.certs.Count > 0)
{
ASN1 asn7 = asn.Add(new ASN1(160));
foreach (X509Certificate x509Certificate in this.certs)
{
asn7.Add(new ASN1(x509Certificate.RawData));
}
}
if (this.crls.Count > 0)
{
ASN1 asn8 = asn.Add(new ASN1(161));
foreach (object obj in this.crls)
{
byte[] array4 = (byte[])obj;
asn8.Add(new ASN1(array4));
}
}
ASN1 asn9 = asn.Add(new ASN1(49));
if (this.signerInfo.Key != null)
{
asn9.Add(this.signerInfo.ASN1);
}
return asn;
}
// Token: 0x060000F0 RID: 240 RVA: 0x00006BF4 File Offset: 0x00004DF4
public byte[] GetBytes()
{
return this.GetASN1().GetBytes();
}
// Token: 0x04000050 RID: 80
private byte version;
// Token: 0x04000051 RID: 81
private string hashAlgorithm;
// Token: 0x04000052 RID: 82
private PKCS7.ContentInfo contentInfo;
// Token: 0x04000053 RID: 83
private X509CertificateCollection certs;
// Token: 0x04000054 RID: 84
private ArrayList crls;
// Token: 0x04000055 RID: 85
private PKCS7.SignerInfo signerInfo;
// Token: 0x04000056 RID: 86
private bool mda;
// Token: 0x04000057 RID: 87
private bool signed;
}
// Token: 0x02000018 RID: 24
public class SignerInfo
{
// Token: 0x060000F1 RID: 241 RVA: 0x00006C04 File Offset: 0x00004E04
public SignerInfo()
{
this.version = 1;
this.authenticatedAttributes = new ArrayList();
this.unauthenticatedAttributes = new ArrayList();
}
// Token: 0x060000F2 RID: 242 RVA: 0x00006C2C File Offset: 0x00004E2C
public SignerInfo(byte[] data)
: this(new ASN1(data))
{
}
// Token: 0x060000F3 RID: 243 RVA: 0x00006C3C File Offset: 0x00004E3C
public SignerInfo(ASN1 asn1)
: this()
{
if (asn1[0].Tag != 48 || asn1[0].Count < 5)
{
throw new ArgumentException("Invalid SignedData");
}
if (asn1[0][0].Tag != 2)
{
throw new ArgumentException("Invalid version");
}
this.version = asn1[0][0].Value[0];
ASN1 asn2 = asn1[0][1];
if (asn2.Tag == 128 && this.version == 3)
{
this.ski = asn2.Value;
}
else
{
this.issuer = X501.ToString(asn2[0]);
this.serial = asn2[1].Value;
}
ASN1 asn3 = asn1[0][2];
this.hashAlgorithm = ASN1Convert.ToOid(asn3[0]);
int num = 3;
ASN1 asn4 = asn1[0][num];
if (asn4.Tag == 160)
{
num++;
for (int i = 0; i < asn4.Count; i++)
{
this.authenticatedAttributes.Add(asn4[i]);
}
}
num++;
ASN1 asn5 = asn1[0][num++];
if (asn5.Tag == 4)
{
this.signature = asn5.Value;
}
ASN1 asn6 = asn1[0][num];
if (asn6 != null && asn6.Tag == 161)
{
for (int j = 0; j < asn6.Count; j++)
{
this.unauthenticatedAttributes.Add(asn6[j]);
}
}
}
// Token: 0x17000026 RID: 38
// (get) Token: 0x060000F4 RID: 244 RVA: 0x00006E18 File Offset: 0x00005018
public string IssuerName
{
get
{
return this.issuer;
}
}
// Token: 0x17000027 RID: 39
// (get) Token: 0x060000F5 RID: 245 RVA: 0x00006E20 File Offset: 0x00005020
public byte[] SerialNumber
{
get
{
if (this.serial == null)
{
return null;
}
return (byte[])this.serial.Clone();
}
}
// Token: 0x17000028 RID: 40
// (get) Token: 0x060000F6 RID: 246 RVA: 0x00006E40 File Offset: 0x00005040
public byte[] SubjectKeyIdentifier
{
get
{
if (this.ski == null)
{
return null;
}
return (byte[])this.ski.Clone();
}
}
// Token: 0x17000029 RID: 41
// (get) Token: 0x060000F7 RID: 247 RVA: 0x00006E60 File Offset: 0x00005060
public ASN1 ASN1
{
get
{
return this.GetASN1();
}
}
// Token: 0x1700002A RID: 42
// (get) Token: 0x060000F8 RID: 248 RVA: 0x00006E68 File Offset: 0x00005068
public ArrayList AuthenticatedAttributes
{
get
{
return this.authenticatedAttributes;
}
}
// Token: 0x1700002B RID: 43
// (get) Token: 0x060000F9 RID: 249 RVA: 0x00006E70 File Offset: 0x00005070
// (set) Token: 0x060000FA RID: 250 RVA: 0x00006E78 File Offset: 0x00005078
public X509Certificate Certificate
{
get
{
return this.x509;
}
set
{
this.x509 = value;
}
}
// Token: 0x1700002C RID: 44
// (get) Token: 0x060000FB RID: 251 RVA: 0x00006E84 File Offset: 0x00005084
// (set) Token: 0x060000FC RID: 252 RVA: 0x00006E8C File Offset: 0x0000508C
public string HashName
{
get
{
return this.hashAlgorithm;
}
set
{
this.hashAlgorithm = value;
}
}
// Token: 0x1700002D RID: 45
// (get) Token: 0x060000FD RID: 253 RVA: 0x00006E98 File Offset: 0x00005098
// (set) Token: 0x060000FE RID: 254 RVA: 0x00006EA0 File Offset: 0x000050A0
public AsymmetricAlgorithm Key
{
get
{
return this.key;
}
set
{
this.key = value;
}
}
// Token: 0x1700002E RID: 46
// (get) Token: 0x060000FF RID: 255 RVA: 0x00006EAC File Offset: 0x000050AC
// (set) Token: 0x06000100 RID: 256 RVA: 0x00006ECC File Offset: 0x000050CC
public byte[] Signature
{
get
{
if (this.signature == null)
{
return null;
}
return (byte[])this.signature.Clone();
}
set
{
if (value != null)
{
this.signature = (byte[])value.Clone();
}
}
}
// Token: 0x1700002F RID: 47
// (get) Token: 0x06000101 RID: 257 RVA: 0x00006EE8 File Offset: 0x000050E8
public ArrayList UnauthenticatedAttributes
{
get
{
return this.unauthenticatedAttributes;
}
}
// Token: 0x17000030 RID: 48
// (get) Token: 0x06000102 RID: 258 RVA: 0x00006EF0 File Offset: 0x000050F0
// (set) Token: 0x06000103 RID: 259 RVA: 0x00006EF8 File Offset: 0x000050F8
public byte Version
{
get
{
return this.version;
}
set
{
this.version = value;
}
}
// Token: 0x06000104 RID: 260 RVA: 0x00006F04 File Offset: 0x00005104
internal ASN1 GetASN1()
{
if (this.key == null || this.hashAlgorithm == null)
{
return null;
}
byte[] array = new byte[] { this.version };
ASN1 asn = new ASN1(48);
asn.Add(new ASN1(2, array));
asn.Add(PKCS7.IssuerAndSerialNumber(this.x509));
string text = CryptoConfig.MapNameToOID(this.hashAlgorithm);
asn.Add(PKCS7.AlgorithmIdentifier(text));
ASN1 asn2 = null;
if (this.authenticatedAttributes.Count > 0)
{
asn2 = asn.Add(new ASN1(160));
this.authenticatedAttributes.Sort(new PKCS7.SortedSet());
foreach (object obj in this.authenticatedAttributes)
{
ASN1 asn3 = (ASN1)obj;
asn2.Add(asn3);
}
}
if (this.key is RSA)
{
asn.Add(PKCS7.AlgorithmIdentifier("1.2.840.113549.1.1.1"));
if (asn2 != null)
{
RSAPKCS1SignatureFormatter rsapkcs1SignatureFormatter = new RSAPKCS1SignatureFormatter(this.key);
rsapkcs1SignatureFormatter.SetHashAlgorithm(this.hashAlgorithm);
byte[] bytes = asn2.GetBytes();
bytes[0] = 49;
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.hashAlgorithm);
byte[] array2 = hashAlgorithm.ComputeHash(bytes);
this.signature = rsapkcs1SignatureFormatter.CreateSignature(array2);
}
asn.Add(new ASN1(4, this.signature));
if (this.unauthenticatedAttributes.Count > 0)
{
ASN1 asn4 = asn.Add(new ASN1(161));
this.unauthenticatedAttributes.Sort(new PKCS7.SortedSet());
foreach (object obj2 in this.unauthenticatedAttributes)
{
ASN1 asn5 = (ASN1)obj2;
asn4.Add(asn5);
}
}
return asn;
}
if (this.key is DSA)
{
throw new NotImplementedException("not yet");
}
throw new CryptographicException("Unknown assymetric algorithm");
}
// Token: 0x06000105 RID: 261 RVA: 0x0000716C File Offset: 0x0000536C
public byte[] GetBytes()
{
return this.GetASN1().GetBytes();
}
// Token: 0x04000059 RID: 89
private byte version;
// Token: 0x0400005A RID: 90
private X509Certificate x509;
// Token: 0x0400005B RID: 91
private string hashAlgorithm;
// Token: 0x0400005C RID: 92
private AsymmetricAlgorithm key;
// Token: 0x0400005D RID: 93
private ArrayList authenticatedAttributes;
// Token: 0x0400005E RID: 94
private ArrayList unauthenticatedAttributes;
// Token: 0x0400005F RID: 95
private byte[] signature;
// Token: 0x04000060 RID: 96
private string issuer;
// Token: 0x04000061 RID: 97
private byte[] serial;
// Token: 0x04000062 RID: 98
private byte[] ski;
}
// Token: 0x02000019 RID: 25
internal class SortedSet : IComparer
{
// Token: 0x06000107 RID: 263 RVA: 0x00007184 File Offset: 0x00005384
public int Compare(object x, object y)
{
if (x == null)
{
return (y != null) ? (-1) : 0;
}
if (y == null)
{
return 1;
}
ASN1 asn = x as ASN1;
ASN1 asn2 = y as ASN1;
if (asn == null || asn2 == null)
{
throw new ArgumentException(Locale.GetText("Invalid objects."));
}
byte[] bytes = asn.GetBytes();
byte[] bytes2 = asn2.GetBytes();
for (int i = 0; i < bytes.Length; i++)
{
if (i == bytes2.Length)
{
break;
}
if (bytes[i] != bytes2[i])
{
return (bytes[i] >= bytes2[i]) ? 1 : (-1);
}
}
if (bytes.Length > bytes2.Length)
{
return 1;
}
if (bytes.Length < bytes2.Length)
{
return -1;
}
return 0;
}
}
}
}
@@ -0,0 +1,220 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Ntlm
{
// Token: 0x02000076 RID: 118
public class ChallengeResponse : IDisposable
{
// Token: 0x06000437 RID: 1079 RVA: 0x0001B350 File Offset: 0x00019550
public ChallengeResponse()
{
this._disposed = false;
this._lmpwd = new byte[21];
this._ntpwd = new byte[21];
}
// Token: 0x06000438 RID: 1080 RVA: 0x0001B37C File Offset: 0x0001957C
public ChallengeResponse(string password, byte[] challenge)
: this()
{
this.Password = password;
this.Challenge = challenge;
}
// Token: 0x0600043A RID: 1082 RVA: 0x0001B3D0 File Offset: 0x000195D0
~ChallengeResponse()
{
if (!this._disposed)
{
this.Dispose();
}
}
// Token: 0x170000F5 RID: 245
// (get) Token: 0x0600043B RID: 1083 RVA: 0x0001B418 File Offset: 0x00019618
// (set) Token: 0x0600043C RID: 1084 RVA: 0x0001B41C File Offset: 0x0001961C
public string Password
{
get
{
return null;
}
set
{
if (this._disposed)
{
throw new ObjectDisposedException("too late");
}
DES des = DES.Create();
des.Mode = CipherMode.ECB;
if (value == null || value.Length < 1)
{
Buffer.BlockCopy(ChallengeResponse.nullEncMagic, 0, this._lmpwd, 0, 8);
}
else
{
des.Key = this.PasswordToKey(value, 0);
ICryptoTransform cryptoTransform = des.CreateEncryptor();
cryptoTransform.TransformBlock(ChallengeResponse.magic, 0, 8, this._lmpwd, 0);
}
if (value == null || value.Length < 8)
{
Buffer.BlockCopy(ChallengeResponse.nullEncMagic, 0, this._lmpwd, 8, 8);
}
else
{
des.Key = this.PasswordToKey(value, 7);
ICryptoTransform cryptoTransform = des.CreateEncryptor();
cryptoTransform.TransformBlock(ChallengeResponse.magic, 0, 8, this._lmpwd, 8);
}
MD4 md = MD4.Create();
byte[] array = ((value != null) ? Encoding.Unicode.GetBytes(value) : new byte[0]);
byte[] array2 = md.ComputeHash(array);
Buffer.BlockCopy(array2, 0, this._ntpwd, 0, 16);
Array.Clear(array, 0, array.Length);
Array.Clear(array2, 0, array2.Length);
des.Clear();
}
}
// Token: 0x170000F6 RID: 246
// (get) Token: 0x0600043D RID: 1085 RVA: 0x0001B550 File Offset: 0x00019750
// (set) Token: 0x0600043E RID: 1086 RVA: 0x0001B554 File Offset: 0x00019754
public byte[] Challenge
{
get
{
return null;
}
set
{
if (value == null)
{
throw new ArgumentNullException("Challenge");
}
if (this._disposed)
{
throw new ObjectDisposedException("too late");
}
this._challenge = (byte[])value.Clone();
}
}
// Token: 0x170000F7 RID: 247
// (get) Token: 0x0600043F RID: 1087 RVA: 0x0001B59C File Offset: 0x0001979C
public byte[] LM
{
get
{
if (this._disposed)
{
throw new ObjectDisposedException("too late");
}
return this.GetResponse(this._lmpwd);
}
}
// Token: 0x170000F8 RID: 248
// (get) Token: 0x06000440 RID: 1088 RVA: 0x0001B5CC File Offset: 0x000197CC
public byte[] NT
{
get
{
if (this._disposed)
{
throw new ObjectDisposedException("too late");
}
return this.GetResponse(this._ntpwd);
}
}
// Token: 0x06000441 RID: 1089 RVA: 0x0001B5FC File Offset: 0x000197FC
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
// Token: 0x06000442 RID: 1090 RVA: 0x0001B60C File Offset: 0x0001980C
private void Dispose(bool disposing)
{
if (!this._disposed)
{
Array.Clear(this._lmpwd, 0, this._lmpwd.Length);
Array.Clear(this._ntpwd, 0, this._ntpwd.Length);
if (this._challenge != null)
{
Array.Clear(this._challenge, 0, this._challenge.Length);
}
this._disposed = true;
}
}
// Token: 0x06000443 RID: 1091 RVA: 0x0001B674 File Offset: 0x00019874
private byte[] GetResponse(byte[] pwd)
{
byte[] array = new byte[24];
DES des = DES.Create();
des.Mode = CipherMode.ECB;
des.Key = this.PrepareDESKey(pwd, 0);
ICryptoTransform cryptoTransform = des.CreateEncryptor();
cryptoTransform.TransformBlock(this._challenge, 0, 8, array, 0);
des.Key = this.PrepareDESKey(pwd, 7);
cryptoTransform = des.CreateEncryptor();
cryptoTransform.TransformBlock(this._challenge, 0, 8, array, 8);
des.Key = this.PrepareDESKey(pwd, 14);
cryptoTransform = des.CreateEncryptor();
cryptoTransform.TransformBlock(this._challenge, 0, 8, array, 16);
return array;
}
// Token: 0x06000444 RID: 1092 RVA: 0x0001B70C File Offset: 0x0001990C
private byte[] PrepareDESKey(byte[] key56bits, int position)
{
return new byte[]
{
key56bits[position],
(byte)(((int)key56bits[position] << 7) | (key56bits[position + 1] >> 1)),
(byte)(((int)key56bits[position + 1] << 6) | (key56bits[position + 2] >> 2)),
(byte)(((int)key56bits[position + 2] << 5) | (key56bits[position + 3] >> 3)),
(byte)(((int)key56bits[position + 3] << 4) | (key56bits[position + 4] >> 4)),
(byte)(((int)key56bits[position + 4] << 3) | (key56bits[position + 5] >> 5)),
(byte)(((int)key56bits[position + 5] << 2) | (key56bits[position + 6] >> 6)),
(byte)(key56bits[position + 6] << 1)
};
}
// Token: 0x06000445 RID: 1093 RVA: 0x0001B7A4 File Offset: 0x000199A4
private byte[] PasswordToKey(string password, int position)
{
byte[] array = new byte[7];
int num = Math.Min(password.Length - position, 7);
Encoding.ASCII.GetBytes(password.ToUpper(CultureInfo.CurrentCulture), position, num, array, 0);
byte[] array2 = this.PrepareDESKey(array, 0);
Array.Clear(array, 0, array.Length);
return array2;
}
// Token: 0x040001F8 RID: 504
private static byte[] magic = new byte[] { 75, 71, 83, 33, 64, 35, 36, 37 };
// Token: 0x040001F9 RID: 505
private static byte[] nullEncMagic = new byte[] { 170, 211, 180, 53, 181, 20, 4, 238 };
// Token: 0x040001FA RID: 506
private bool _disposed;
// Token: 0x040001FB RID: 507
private byte[] _challenge;
// Token: 0x040001FC RID: 508
private byte[] _lmpwd;
// Token: 0x040001FD RID: 509
private byte[] _ntpwd;
}
}
@@ -0,0 +1,95 @@
using System;
namespace Mono.Security.Protocol.Ntlm
{
// Token: 0x02000077 RID: 119
public abstract class MessageBase
{
// Token: 0x06000446 RID: 1094 RVA: 0x0001B7F8 File Offset: 0x000199F8
protected MessageBase(int messageType)
{
this._type = messageType;
}
// Token: 0x170000F9 RID: 249
// (get) Token: 0x06000448 RID: 1096 RVA: 0x0001B820 File Offset: 0x00019A20
// (set) Token: 0x06000449 RID: 1097 RVA: 0x0001B828 File Offset: 0x00019A28
public NtlmFlags Flags
{
get
{
return this._flags;
}
set
{
this._flags = value;
}
}
// Token: 0x170000FA RID: 250
// (get) Token: 0x0600044A RID: 1098 RVA: 0x0001B834 File Offset: 0x00019A34
public int Type
{
get
{
return this._type;
}
}
// Token: 0x0600044B RID: 1099 RVA: 0x0001B83C File Offset: 0x00019A3C
protected byte[] PrepareMessage(int messageSize)
{
byte[] array = new byte[messageSize];
Buffer.BlockCopy(MessageBase.header, 0, array, 0, 8);
array[8] = (byte)this._type;
array[9] = (byte)(this._type >> 8);
array[10] = (byte)(this._type >> 16);
array[11] = (byte)(this._type >> 24);
return array;
}
// Token: 0x0600044C RID: 1100 RVA: 0x0001B894 File Offset: 0x00019A94
protected virtual void Decode(byte[] message)
{
if (message == null)
{
throw new ArgumentNullException("message");
}
if (message.Length < 12)
{
string text = Locale.GetText("Minimum message length is 12 bytes.");
throw new ArgumentOutOfRangeException("message", message.Length, text);
}
if (!this.CheckHeader(message))
{
string text2 = string.Format(Locale.GetText("Invalid Type{0} message."), this._type);
throw new ArgumentException(text2, "message");
}
}
// Token: 0x0600044D RID: 1101 RVA: 0x0001B910 File Offset: 0x00019B10
protected bool CheckHeader(byte[] message)
{
for (int i = 0; i < MessageBase.header.Length; i++)
{
if (message[i] != MessageBase.header[i])
{
return false;
}
}
return (ulong)BitConverterLE.ToUInt32(message, 8) == (ulong)((long)this._type);
}
// Token: 0x0600044E RID: 1102
public abstract byte[] GetBytes();
// Token: 0x040001FE RID: 510
private static byte[] header = new byte[] { 78, 84, 76, 77, 83, 83, 80, 0 };
// Token: 0x040001FF RID: 511
private int _type;
// Token: 0x04000200 RID: 512
private NtlmFlags _flags;
}
}
@@ -0,0 +1,30 @@
using System;
namespace Mono.Security.Protocol.Ntlm
{
// Token: 0x02000078 RID: 120
[Flags]
public enum NtlmFlags
{
// Token: 0x04000202 RID: 514
NegotiateUnicode = 1,
// Token: 0x04000203 RID: 515
NegotiateOem = 2,
// Token: 0x04000204 RID: 516
RequestTarget = 4,
// Token: 0x04000205 RID: 517
NegotiateNtlm = 512,
// Token: 0x04000206 RID: 518
NegotiateDomainSupplied = 4096,
// Token: 0x04000207 RID: 519
NegotiateWorkstationSupplied = 8192,
// Token: 0x04000208 RID: 520
NegotiateAlwaysSign = 32768,
// Token: 0x04000209 RID: 521
NegotiateNtlm2Key = 524288,
// Token: 0x0400020A RID: 522
Negotiate128 = 536870912,
// Token: 0x0400020B RID: 523
Negotiate56 = -2147483648
}
}
@@ -0,0 +1,104 @@
using System;
using System.Globalization;
using System.Text;
namespace Mono.Security.Protocol.Ntlm
{
// Token: 0x02000079 RID: 121
public class Type1Message : MessageBase
{
// Token: 0x0600044F RID: 1103 RVA: 0x0001B958 File Offset: 0x00019B58
public Type1Message()
: base(1)
{
this._domain = Environment.UserDomainName;
this._host = Environment.MachineName;
base.Flags = NtlmFlags.NegotiateUnicode | NtlmFlags.NegotiateOem | NtlmFlags.NegotiateNtlm | NtlmFlags.NegotiateDomainSupplied | NtlmFlags.NegotiateWorkstationSupplied | NtlmFlags.NegotiateAlwaysSign;
}
// Token: 0x06000450 RID: 1104 RVA: 0x0001B990 File Offset: 0x00019B90
public Type1Message(byte[] message)
: base(1)
{
this.Decode(message);
}
// Token: 0x170000FB RID: 251
// (get) Token: 0x06000451 RID: 1105 RVA: 0x0001B9A0 File Offset: 0x00019BA0
// (set) Token: 0x06000452 RID: 1106 RVA: 0x0001B9A8 File Offset: 0x00019BA8
public string Domain
{
get
{
return this._domain;
}
set
{
this._domain = value;
}
}
// Token: 0x170000FC RID: 252
// (get) Token: 0x06000453 RID: 1107 RVA: 0x0001B9B4 File Offset: 0x00019BB4
// (set) Token: 0x06000454 RID: 1108 RVA: 0x0001B9BC File Offset: 0x00019BBC
public string Host
{
get
{
return this._host;
}
set
{
this._host = value;
}
}
// Token: 0x06000455 RID: 1109 RVA: 0x0001B9C8 File Offset: 0x00019BC8
protected override void Decode(byte[] message)
{
base.Decode(message);
base.Flags = (NtlmFlags)BitConverterLE.ToUInt32(message, 12);
int num = (int)BitConverterLE.ToUInt16(message, 16);
int num2 = (int)BitConverterLE.ToUInt16(message, 20);
this._domain = Encoding.ASCII.GetString(message, num2, num);
int num3 = (int)BitConverterLE.ToUInt16(message, 24);
this._host = Encoding.ASCII.GetString(message, 32, num3);
}
// Token: 0x06000456 RID: 1110 RVA: 0x0001BA2C File Offset: 0x00019C2C
public override byte[] GetBytes()
{
short num = (short)this._domain.Length;
short num2 = (short)this._host.Length;
byte[] array = base.PrepareMessage((int)(32 + num + num2));
array[12] = (byte)base.Flags;
array[13] = (byte)(base.Flags >> 8);
array[14] = (byte)(base.Flags >> 16);
array[15] = (byte)(base.Flags >> 24);
short num3 = 32 + num2;
array[16] = (byte)num;
array[17] = (byte)(num >> 8);
array[18] = array[16];
array[19] = array[17];
array[20] = (byte)num3;
array[21] = (byte)(num3 >> 8);
array[24] = (byte)num2;
array[25] = (byte)(num2 >> 8);
array[26] = array[24];
array[27] = array[25];
array[28] = 32;
array[29] = 0;
byte[] bytes = Encoding.ASCII.GetBytes(this._host.ToUpper(CultureInfo.InvariantCulture));
Buffer.BlockCopy(bytes, 0, array, 32, bytes.Length);
byte[] bytes2 = Encoding.ASCII.GetBytes(this._domain.ToUpper(CultureInfo.InvariantCulture));
Buffer.BlockCopy(bytes2, 0, array, (int)num3, bytes2.Length);
return array;
}
// Token: 0x0400020C RID: 524
private string _host;
// Token: 0x0400020D RID: 525
private string _domain;
}
}
@@ -0,0 +1,86 @@
using System;
using System.Security.Cryptography;
namespace Mono.Security.Protocol.Ntlm
{
// Token: 0x0200007A RID: 122
public class Type2Message : MessageBase
{
// Token: 0x06000457 RID: 1111 RVA: 0x0001BB48 File Offset: 0x00019D48
public Type2Message()
: base(2)
{
this._nonce = new byte[8];
RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
randomNumberGenerator.GetBytes(this._nonce);
base.Flags = NtlmFlags.NegotiateUnicode | NtlmFlags.NegotiateNtlm | NtlmFlags.NegotiateAlwaysSign;
}
// Token: 0x06000458 RID: 1112 RVA: 0x0001BB88 File Offset: 0x00019D88
public Type2Message(byte[] message)
: base(2)
{
this._nonce = new byte[8];
this.Decode(message);
}
// Token: 0x06000459 RID: 1113 RVA: 0x0001BBA4 File Offset: 0x00019DA4
~Type2Message()
{
if (this._nonce != null)
{
Array.Clear(this._nonce, 0, this._nonce.Length);
}
}
// Token: 0x170000FD RID: 253
// (get) Token: 0x0600045A RID: 1114 RVA: 0x0001BBF8 File Offset: 0x00019DF8
// (set) Token: 0x0600045B RID: 1115 RVA: 0x0001BC0C File Offset: 0x00019E0C
public byte[] Nonce
{
get
{
return (byte[])this._nonce.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("Nonce");
}
if (value.Length != 8)
{
string text = Locale.GetText("Invalid Nonce Length (should be 8 bytes).");
throw new ArgumentException(text, "Nonce");
}
this._nonce = (byte[])value.Clone();
}
}
// Token: 0x0600045C RID: 1116 RVA: 0x0001BC5C File Offset: 0x00019E5C
protected override void Decode(byte[] message)
{
base.Decode(message);
base.Flags = (NtlmFlags)BitConverterLE.ToUInt32(message, 20);
Buffer.BlockCopy(message, 24, this._nonce, 0, 8);
}
// Token: 0x0600045D RID: 1117 RVA: 0x0001BC90 File Offset: 0x00019E90
public override byte[] GetBytes()
{
byte[] array = base.PrepareMessage(40);
short num = (short)array.Length;
array[16] = (byte)num;
array[17] = (byte)(num >> 8);
array[20] = (byte)base.Flags;
array[21] = (byte)(base.Flags >> 8);
array[22] = (byte)(base.Flags >> 16);
array[23] = (byte)(base.Flags >> 24);
Buffer.BlockCopy(this._nonce, 0, array, 24, this._nonce.Length);
return array;
}
// Token: 0x0400020E RID: 526
private byte[] _nonce;
}
}
@@ -0,0 +1,267 @@
using System;
using System.Globalization;
using System.Text;
namespace Mono.Security.Protocol.Ntlm
{
// Token: 0x0200007B RID: 123
public class Type3Message : MessageBase
{
// Token: 0x0600045E RID: 1118 RVA: 0x0001BD08 File Offset: 0x00019F08
public Type3Message()
: base(3)
{
this._domain = Environment.UserDomainName;
this._host = Environment.MachineName;
this._username = Environment.UserName;
base.Flags = NtlmFlags.NegotiateUnicode | NtlmFlags.NegotiateNtlm | NtlmFlags.NegotiateAlwaysSign;
}
// Token: 0x0600045F RID: 1119 RVA: 0x0001BD40 File Offset: 0x00019F40
public Type3Message(byte[] message)
: base(3)
{
this.Decode(message);
}
// Token: 0x06000460 RID: 1120 RVA: 0x0001BD50 File Offset: 0x00019F50
~Type3Message()
{
if (this._challenge != null)
{
Array.Clear(this._challenge, 0, this._challenge.Length);
}
if (this._lm != null)
{
Array.Clear(this._lm, 0, this._lm.Length);
}
if (this._nt != null)
{
Array.Clear(this._nt, 0, this._nt.Length);
}
}
// Token: 0x170000FE RID: 254
// (get) Token: 0x06000461 RID: 1121 RVA: 0x0001BDE4 File Offset: 0x00019FE4
// (set) Token: 0x06000462 RID: 1122 RVA: 0x0001BE04 File Offset: 0x0001A004
public byte[] Challenge
{
get
{
if (this._challenge == null)
{
return null;
}
return (byte[])this._challenge.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("Challenge");
}
if (value.Length != 8)
{
string text = Locale.GetText("Invalid Challenge Length (should be 8 bytes).");
throw new ArgumentException(text, "Challenge");
}
this._challenge = (byte[])value.Clone();
}
}
// Token: 0x170000FF RID: 255
// (get) Token: 0x06000463 RID: 1123 RVA: 0x0001BE54 File Offset: 0x0001A054
// (set) Token: 0x06000464 RID: 1124 RVA: 0x0001BE5C File Offset: 0x0001A05C
public string Domain
{
get
{
return this._domain;
}
set
{
this._domain = value;
}
}
// Token: 0x17000100 RID: 256
// (get) Token: 0x06000465 RID: 1125 RVA: 0x0001BE68 File Offset: 0x0001A068
// (set) Token: 0x06000466 RID: 1126 RVA: 0x0001BE70 File Offset: 0x0001A070
public string Host
{
get
{
return this._host;
}
set
{
this._host = value;
}
}
// Token: 0x17000101 RID: 257
// (get) Token: 0x06000467 RID: 1127 RVA: 0x0001BE7C File Offset: 0x0001A07C
// (set) Token: 0x06000468 RID: 1128 RVA: 0x0001BE84 File Offset: 0x0001A084
public string Password
{
get
{
return this._password;
}
set
{
this._password = value;
}
}
// Token: 0x17000102 RID: 258
// (get) Token: 0x06000469 RID: 1129 RVA: 0x0001BE90 File Offset: 0x0001A090
// (set) Token: 0x0600046A RID: 1130 RVA: 0x0001BE98 File Offset: 0x0001A098
public string Username
{
get
{
return this._username;
}
set
{
this._username = value;
}
}
// Token: 0x17000103 RID: 259
// (get) Token: 0x0600046B RID: 1131 RVA: 0x0001BEA4 File Offset: 0x0001A0A4
public byte[] LM
{
get
{
return this._lm;
}
}
// Token: 0x17000104 RID: 260
// (get) Token: 0x0600046C RID: 1132 RVA: 0x0001BEAC File Offset: 0x0001A0AC
public byte[] NT
{
get
{
return this._nt;
}
}
// Token: 0x0600046D RID: 1133 RVA: 0x0001BEB4 File Offset: 0x0001A0B4
protected override void Decode(byte[] message)
{
base.Decode(message);
if ((int)BitConverterLE.ToUInt16(message, 56) != message.Length)
{
string text = Locale.GetText("Invalid Type3 message length.");
throw new ArgumentException(text, "message");
}
this._password = null;
int num = (int)BitConverterLE.ToUInt16(message, 28);
int num2 = 64;
this._domain = Encoding.Unicode.GetString(message, num2, num);
int num3 = (int)BitConverterLE.ToUInt16(message, 44);
int num4 = (int)BitConverterLE.ToUInt16(message, 48);
this._host = Encoding.Unicode.GetString(message, num4, num3);
int num5 = (int)BitConverterLE.ToUInt16(message, 36);
int num6 = (int)BitConverterLE.ToUInt16(message, 40);
this._username = Encoding.Unicode.GetString(message, num6, num5);
this._lm = new byte[24];
int num7 = (int)BitConverterLE.ToUInt16(message, 16);
Buffer.BlockCopy(message, num7, this._lm, 0, 24);
this._nt = new byte[24];
int num8 = (int)BitConverterLE.ToUInt16(message, 24);
Buffer.BlockCopy(message, num8, this._nt, 0, 24);
if (message.Length >= 64)
{
base.Flags = (NtlmFlags)BitConverterLE.ToUInt32(message, 60);
}
}
// Token: 0x0600046E RID: 1134 RVA: 0x0001BFD0 File Offset: 0x0001A1D0
public override byte[] GetBytes()
{
byte[] bytes = Encoding.Unicode.GetBytes(this._domain.ToUpper(CultureInfo.InvariantCulture));
byte[] bytes2 = Encoding.Unicode.GetBytes(this._username);
byte[] bytes3 = Encoding.Unicode.GetBytes(this._host.ToUpper(CultureInfo.InvariantCulture));
byte[] array = base.PrepareMessage(64 + bytes.Length + bytes2.Length + bytes3.Length + 24 + 24);
short num = (short)(64 + bytes.Length + bytes2.Length + bytes3.Length);
array[12] = 24;
array[13] = 0;
array[14] = 24;
array[15] = 0;
array[16] = (byte)num;
array[17] = (byte)(num >> 8);
short num2 = num + 24;
array[20] = 24;
array[21] = 0;
array[22] = 24;
array[23] = 0;
array[24] = (byte)num2;
array[25] = (byte)(num2 >> 8);
short num3 = (short)bytes.Length;
short num4 = 64;
array[28] = (byte)num3;
array[29] = (byte)(num3 >> 8);
array[30] = array[28];
array[31] = array[29];
array[32] = (byte)num4;
array[33] = (byte)(num4 >> 8);
short num5 = (short)bytes2.Length;
short num6 = num4 + num3;
array[36] = (byte)num5;
array[37] = (byte)(num5 >> 8);
array[38] = array[36];
array[39] = array[37];
array[40] = (byte)num6;
array[41] = (byte)(num6 >> 8);
short num7 = (short)bytes3.Length;
short num8 = num6 + num5;
array[44] = (byte)num7;
array[45] = (byte)(num7 >> 8);
array[46] = array[44];
array[47] = array[45];
array[48] = (byte)num8;
array[49] = (byte)(num8 >> 8);
short num9 = (short)array.Length;
array[56] = (byte)num9;
array[57] = (byte)(num9 >> 8);
array[60] = (byte)base.Flags;
array[61] = (byte)(base.Flags >> 8);
array[62] = (byte)(base.Flags >> 16);
array[63] = (byte)(base.Flags >> 24);
Buffer.BlockCopy(bytes, 0, array, (int)num4, bytes.Length);
Buffer.BlockCopy(bytes2, 0, array, (int)num6, bytes2.Length);
Buffer.BlockCopy(bytes3, 0, array, (int)num8, bytes3.Length);
using (ChallengeResponse challengeResponse = new ChallengeResponse(this._password, this._challenge))
{
Buffer.BlockCopy(challengeResponse.LM, 0, array, (int)num, 24);
Buffer.BlockCopy(challengeResponse.NT, 0, array, (int)num2, 24);
}
return array;
}
// Token: 0x0400020F RID: 527
private byte[] _challenge;
// Token: 0x04000210 RID: 528
private string _host;
// Token: 0x04000211 RID: 529
private string _domain;
// Token: 0x04000212 RID: 530
private string _username;
// Token: 0x04000213 RID: 531
private string _password;
// Token: 0x04000214 RID: 532
private byte[] _lm;
// Token: 0x04000215 RID: 533
private byte[] _nt;
}
}
@@ -0,0 +1,134 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200007E RID: 126
internal class Alert
{
// Token: 0x0600046F RID: 1135 RVA: 0x0001C234 File Offset: 0x0001A434
public Alert(AlertDescription description)
{
this.inferAlertLevel();
this.description = description;
}
// Token: 0x06000470 RID: 1136 RVA: 0x0001C24C File Offset: 0x0001A44C
public Alert(AlertLevel level, AlertDescription description)
{
this.level = level;
this.description = description;
}
// Token: 0x17000105 RID: 261
// (get) Token: 0x06000471 RID: 1137 RVA: 0x0001C264 File Offset: 0x0001A464
public AlertLevel Level
{
get
{
return this.level;
}
}
// Token: 0x17000106 RID: 262
// (get) Token: 0x06000472 RID: 1138 RVA: 0x0001C26C File Offset: 0x0001A46C
public AlertDescription Description
{
get
{
return this.description;
}
}
// Token: 0x17000107 RID: 263
// (get) Token: 0x06000473 RID: 1139 RVA: 0x0001C274 File Offset: 0x0001A474
public string Message
{
get
{
return Alert.GetAlertMessage(this.description);
}
}
// Token: 0x17000108 RID: 264
// (get) Token: 0x06000474 RID: 1140 RVA: 0x0001C284 File Offset: 0x0001A484
public bool IsWarning
{
get
{
return this.level == AlertLevel.Warning;
}
}
// Token: 0x17000109 RID: 265
// (get) Token: 0x06000475 RID: 1141 RVA: 0x0001C29C File Offset: 0x0001A49C
public bool IsCloseNotify
{
get
{
return this.IsWarning && this.description == AlertDescription.CloseNotify;
}
}
// Token: 0x06000476 RID: 1142 RVA: 0x0001C2B8 File Offset: 0x0001A4B8
private void inferAlertLevel()
{
AlertDescription alertDescription = this.description;
switch (alertDescription)
{
case AlertDescription.HandshakeFailiure:
case AlertDescription.BadCertificate:
case AlertDescription.UnsupportedCertificate:
case AlertDescription.CertificateRevoked:
case AlertDescription.CertificateExpired:
case AlertDescription.CertificateUnknown:
case AlertDescription.IlegalParameter:
case AlertDescription.UnknownCA:
case AlertDescription.AccessDenied:
case AlertDescription.DecodeError:
case AlertDescription.DecryptError:
case AlertDescription.ExportRestriction:
break;
default:
switch (alertDescription)
{
case AlertDescription.BadRecordMAC:
case AlertDescription.DecryptionFailed:
case AlertDescription.RecordOverflow:
break;
default:
if (alertDescription != AlertDescription.ProtocolVersion && alertDescription != AlertDescription.InsuficientSecurity)
{
if (alertDescription != AlertDescription.CloseNotify)
{
if (alertDescription == AlertDescription.UnexpectedMessage || alertDescription == AlertDescription.DecompressionFailiure || alertDescription == AlertDescription.InternalError)
{
break;
}
if (alertDescription != AlertDescription.UserCancelled && alertDescription != AlertDescription.NoRenegotiation)
{
break;
}
}
this.level = AlertLevel.Warning;
return;
}
break;
}
break;
}
this.level = AlertLevel.Fatal;
}
// Token: 0x06000477 RID: 1143 RVA: 0x0001C39C File Offset: 0x0001A59C
public static string GetAlertMessage(AlertDescription description)
{
return "The authentication or decryption has failed.";
}
// Token: 0x04000232 RID: 562
private AlertLevel level;
// Token: 0x04000233 RID: 563
private AlertDescription description;
}
}
@@ -0,0 +1,58 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200007D RID: 125
[Serializable]
internal enum AlertDescription : byte
{
// Token: 0x0400021A RID: 538
CloseNotify,
// Token: 0x0400021B RID: 539
UnexpectedMessage = 10,
// Token: 0x0400021C RID: 540
BadRecordMAC = 20,
// Token: 0x0400021D RID: 541
DecryptionFailed,
// Token: 0x0400021E RID: 542
RecordOverflow,
// Token: 0x0400021F RID: 543
DecompressionFailiure = 30,
// Token: 0x04000220 RID: 544
HandshakeFailiure = 40,
// Token: 0x04000221 RID: 545
NoCertificate,
// Token: 0x04000222 RID: 546
BadCertificate,
// Token: 0x04000223 RID: 547
UnsupportedCertificate,
// Token: 0x04000224 RID: 548
CertificateRevoked,
// Token: 0x04000225 RID: 549
CertificateExpired,
// Token: 0x04000226 RID: 550
CertificateUnknown,
// Token: 0x04000227 RID: 551
IlegalParameter,
// Token: 0x04000228 RID: 552
UnknownCA,
// Token: 0x04000229 RID: 553
AccessDenied,
// Token: 0x0400022A RID: 554
DecodeError,
// Token: 0x0400022B RID: 555
DecryptError,
// Token: 0x0400022C RID: 556
ExportRestriction = 60,
// Token: 0x0400022D RID: 557
ProtocolVersion = 70,
// Token: 0x0400022E RID: 558
InsuficientSecurity,
// Token: 0x0400022F RID: 559
InternalError = 80,
// Token: 0x04000230 RID: 560
UserCancelled = 90,
// Token: 0x04000231 RID: 561
NoRenegotiation = 100
}
}
@@ -0,0 +1,14 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200007C RID: 124
[Serializable]
internal enum AlertLevel : byte
{
// Token: 0x04000217 RID: 535
Warning = 1,
// Token: 0x04000218 RID: 536
Fatal
}
}
@@ -0,0 +1,9 @@
using System;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x020000CD RID: 205
// (Invoke) Token: 0x06000719 RID: 1817
public delegate X509Certificate CertificateSelectionCallback(X509CertificateCollection clientCertificates, X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates);
}
@@ -0,0 +1,9 @@
using System;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x020000CB RID: 203
// (Invoke) Token: 0x06000711 RID: 1809
public delegate bool CertificateValidationCallback(X509Certificate certificate, int[] certificateErrors);
}
@@ -0,0 +1,9 @@
using System;
using Mono.Security.X509;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x020000CC RID: 204
// (Invoke) Token: 0x06000715 RID: 1813
public delegate ValidationResult CertificateValidationCallback2(X509CertificateCollection collection);
}
@@ -0,0 +1,24 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200007F RID: 127
[Serializable]
public enum CipherAlgorithmType
{
// Token: 0x04000235 RID: 565
Des,
// Token: 0x04000236 RID: 566
None,
// Token: 0x04000237 RID: 567
Rc2,
// Token: 0x04000238 RID: 568
Rc4,
// Token: 0x04000239 RID: 569
Rijndael,
// Token: 0x0400023A RID: 570
SkipJack,
// Token: 0x0400023B RID: 571
TripleDes
}
}
@@ -0,0 +1,566 @@
using System;
using System.Security.Cryptography;
using System.Text;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000080 RID: 128
internal abstract class CipherSuite
{
// Token: 0x06000478 RID: 1144 RVA: 0x0001C3A4 File Offset: 0x0001A5A4
public CipherSuite(short code, string name, CipherAlgorithmType cipherAlgorithmType, HashAlgorithmType hashAlgorithmType, ExchangeAlgorithmType exchangeAlgorithmType, bool exportable, bool blockMode, byte keyMaterialSize, byte expandedKeyMaterialSize, short effectiveKeyBits, byte ivSize, byte blockSize)
{
this.code = code;
this.name = name;
this.cipherAlgorithmType = cipherAlgorithmType;
this.hashAlgorithmType = hashAlgorithmType;
this.exchangeAlgorithmType = exchangeAlgorithmType;
this.isExportable = exportable;
if (blockMode)
{
this.cipherMode = CipherMode.CBC;
}
this.keyMaterialSize = keyMaterialSize;
this.expandedKeyMaterialSize = expandedKeyMaterialSize;
this.effectiveKeyBits = effectiveKeyBits;
this.ivSize = ivSize;
this.blockSize = blockSize;
this.keyBlockSize = (int)this.keyMaterialSize + this.HashSize + (int)this.ivSize << 1;
}
// Token: 0x1700010A RID: 266
// (get) Token: 0x0600047A RID: 1146 RVA: 0x0001C448 File Offset: 0x0001A648
protected ICryptoTransform EncryptionCipher
{
get
{
return this.encryptionCipher;
}
}
// Token: 0x1700010B RID: 267
// (get) Token: 0x0600047B RID: 1147 RVA: 0x0001C450 File Offset: 0x0001A650
protected ICryptoTransform DecryptionCipher
{
get
{
return this.decryptionCipher;
}
}
// Token: 0x1700010C RID: 268
// (get) Token: 0x0600047C RID: 1148 RVA: 0x0001C458 File Offset: 0x0001A658
protected KeyedHashAlgorithm ClientHMAC
{
get
{
return this.clientHMAC;
}
}
// Token: 0x1700010D RID: 269
// (get) Token: 0x0600047D RID: 1149 RVA: 0x0001C460 File Offset: 0x0001A660
protected KeyedHashAlgorithm ServerHMAC
{
get
{
return this.serverHMAC;
}
}
// Token: 0x1700010E RID: 270
// (get) Token: 0x0600047E RID: 1150 RVA: 0x0001C468 File Offset: 0x0001A668
public CipherAlgorithmType CipherAlgorithmType
{
get
{
return this.cipherAlgorithmType;
}
}
// Token: 0x1700010F RID: 271
// (get) Token: 0x0600047F RID: 1151 RVA: 0x0001C470 File Offset: 0x0001A670
public string HashAlgorithmName
{
get
{
switch (this.hashAlgorithmType)
{
case HashAlgorithmType.Md5:
return "MD5";
case HashAlgorithmType.Sha1:
return "SHA1";
}
return "None";
}
}
// Token: 0x17000110 RID: 272
// (get) Token: 0x06000480 RID: 1152 RVA: 0x0001C4AC File Offset: 0x0001A6AC
public HashAlgorithmType HashAlgorithmType
{
get
{
return this.hashAlgorithmType;
}
}
// Token: 0x17000111 RID: 273
// (get) Token: 0x06000481 RID: 1153 RVA: 0x0001C4B4 File Offset: 0x0001A6B4
public int HashSize
{
get
{
switch (this.hashAlgorithmType)
{
case HashAlgorithmType.Md5:
return 16;
case HashAlgorithmType.Sha1:
return 20;
}
return 0;
}
}
// Token: 0x17000112 RID: 274
// (get) Token: 0x06000482 RID: 1154 RVA: 0x0001C4E8 File Offset: 0x0001A6E8
public ExchangeAlgorithmType ExchangeAlgorithmType
{
get
{
return this.exchangeAlgorithmType;
}
}
// Token: 0x17000113 RID: 275
// (get) Token: 0x06000483 RID: 1155 RVA: 0x0001C4F0 File Offset: 0x0001A6F0
public CipherMode CipherMode
{
get
{
return this.cipherMode;
}
}
// Token: 0x17000114 RID: 276
// (get) Token: 0x06000484 RID: 1156 RVA: 0x0001C4F8 File Offset: 0x0001A6F8
public short Code
{
get
{
return this.code;
}
}
// Token: 0x17000115 RID: 277
// (get) Token: 0x06000485 RID: 1157 RVA: 0x0001C500 File Offset: 0x0001A700
public string Name
{
get
{
return this.name;
}
}
// Token: 0x17000116 RID: 278
// (get) Token: 0x06000486 RID: 1158 RVA: 0x0001C508 File Offset: 0x0001A708
public bool IsExportable
{
get
{
return this.isExportable;
}
}
// Token: 0x17000117 RID: 279
// (get) Token: 0x06000487 RID: 1159 RVA: 0x0001C510 File Offset: 0x0001A710
public byte KeyMaterialSize
{
get
{
return this.keyMaterialSize;
}
}
// Token: 0x17000118 RID: 280
// (get) Token: 0x06000488 RID: 1160 RVA: 0x0001C518 File Offset: 0x0001A718
public int KeyBlockSize
{
get
{
return this.keyBlockSize;
}
}
// Token: 0x17000119 RID: 281
// (get) Token: 0x06000489 RID: 1161 RVA: 0x0001C520 File Offset: 0x0001A720
public byte ExpandedKeyMaterialSize
{
get
{
return this.expandedKeyMaterialSize;
}
}
// Token: 0x1700011A RID: 282
// (get) Token: 0x0600048A RID: 1162 RVA: 0x0001C528 File Offset: 0x0001A728
public short EffectiveKeyBits
{
get
{
return this.effectiveKeyBits;
}
}
// Token: 0x1700011B RID: 283
// (get) Token: 0x0600048B RID: 1163 RVA: 0x0001C530 File Offset: 0x0001A730
public byte IvSize
{
get
{
return this.ivSize;
}
}
// Token: 0x1700011C RID: 284
// (get) Token: 0x0600048C RID: 1164 RVA: 0x0001C538 File Offset: 0x0001A738
// (set) Token: 0x0600048D RID: 1165 RVA: 0x0001C540 File Offset: 0x0001A740
public Context Context
{
get
{
return this.context;
}
set
{
this.context = value;
}
}
// Token: 0x0600048E RID: 1166 RVA: 0x0001C54C File Offset: 0x0001A74C
internal void Write(byte[] array, int offset, short value)
{
if (offset > array.Length - 2)
{
throw new ArgumentException("offset");
}
array[offset] = (byte)(value >> 8);
array[offset + 1] = (byte)value;
}
// Token: 0x0600048F RID: 1167 RVA: 0x0001C580 File Offset: 0x0001A780
internal void Write(byte[] array, int offset, ulong value)
{
if (offset > array.Length - 8)
{
throw new ArgumentException("offset");
}
array[offset] = (byte)(value >> 56);
array[offset + 1] = (byte)(value >> 48);
array[offset + 2] = (byte)(value >> 40);
array[offset + 3] = (byte)(value >> 32);
array[offset + 4] = (byte)(value >> 24);
array[offset + 5] = (byte)(value >> 16);
array[offset + 6] = (byte)(value >> 8);
array[offset + 7] = (byte)value;
}
// Token: 0x06000490 RID: 1168 RVA: 0x0001C5F0 File Offset: 0x0001A7F0
public void InitializeCipher()
{
this.createEncryptionCipher();
this.createDecryptionCipher();
}
// Token: 0x06000491 RID: 1169 RVA: 0x0001C600 File Offset: 0x0001A800
public byte[] EncryptRecord(byte[] fragment, byte[] mac)
{
int num = fragment.Length + mac.Length;
int num2 = 0;
if (this.CipherMode == CipherMode.CBC)
{
num++;
num2 = (int)this.blockSize - num % (int)this.blockSize;
if (num2 == (int)this.blockSize)
{
num2 = 0;
}
num += num2;
}
byte[] array = new byte[num];
Buffer.BlockCopy(fragment, 0, array, 0, fragment.Length);
Buffer.BlockCopy(mac, 0, array, fragment.Length, mac.Length);
if (num2 > 0)
{
int num3 = fragment.Length + mac.Length;
for (int i = num3; i < num3 + num2 + 1; i++)
{
array[i] = (byte)num2;
}
}
this.EncryptionCipher.TransformBlock(array, 0, array.Length, array, 0);
return array;
}
// Token: 0x06000492 RID: 1170 RVA: 0x0001C6B0 File Offset: 0x0001A8B0
public void DecryptRecord(byte[] fragment, out byte[] dcrFragment, out byte[] dcrMAC)
{
this.DecryptionCipher.TransformBlock(fragment, 0, fragment.Length, fragment, 0);
int num2;
if (this.CipherMode == CipherMode.CBC)
{
int num = (int)fragment[fragment.Length - 1];
num2 = fragment.Length - (num + 1) - this.HashSize;
}
else
{
num2 = fragment.Length - this.HashSize;
}
dcrFragment = new byte[num2];
dcrMAC = new byte[this.HashSize];
Buffer.BlockCopy(fragment, 0, dcrFragment, 0, dcrFragment.Length);
Buffer.BlockCopy(fragment, dcrFragment.Length, dcrMAC, 0, dcrMAC.Length);
}
// Token: 0x06000493 RID: 1171
public abstract byte[] ComputeClientRecordMAC(ContentType contentType, byte[] fragment);
// Token: 0x06000494 RID: 1172
public abstract byte[] ComputeServerRecordMAC(ContentType contentType, byte[] fragment);
// Token: 0x06000495 RID: 1173
public abstract void ComputeMasterSecret(byte[] preMasterSecret);
// Token: 0x06000496 RID: 1174
public abstract void ComputeKeys();
// Token: 0x06000497 RID: 1175 RVA: 0x0001C73C File Offset: 0x0001A93C
public byte[] CreatePremasterSecret()
{
ClientContext clientContext = (ClientContext)this.context;
byte[] secureRandomBytes = this.context.GetSecureRandomBytes(48);
secureRandomBytes[0] = (byte)(clientContext.ClientHelloProtocol >> 8);
secureRandomBytes[1] = (byte)clientContext.ClientHelloProtocol;
return secureRandomBytes;
}
// Token: 0x06000498 RID: 1176 RVA: 0x0001C77C File Offset: 0x0001A97C
public byte[] PRF(byte[] secret, string label, byte[] data, int length)
{
int num = secret.Length >> 1;
if ((secret.Length & 1) == 1)
{
num++;
}
TlsStream tlsStream = new TlsStream();
tlsStream.Write(Encoding.ASCII.GetBytes(label));
tlsStream.Write(data);
byte[] array = tlsStream.ToArray();
tlsStream.Reset();
byte[] array2 = new byte[num];
Buffer.BlockCopy(secret, 0, array2, 0, num);
byte[] array3 = new byte[num];
Buffer.BlockCopy(secret, secret.Length - num, array3, 0, num);
byte[] array4 = this.Expand("MD5", array2, array, length);
byte[] array5 = this.Expand("SHA1", array3, array, length);
byte[] array6 = new byte[length];
for (int i = 0; i < array6.Length; i++)
{
array6[i] = array4[i] ^ array5[i];
}
return array6;
}
// Token: 0x06000499 RID: 1177 RVA: 0x0001C84C File Offset: 0x0001AA4C
public byte[] Expand(string hashName, byte[] secret, byte[] seed, int length)
{
int num = ((!(hashName == "MD5")) ? 20 : 16);
int num2 = length / num;
if (length % num > 0)
{
num2++;
}
Mono.Security.Cryptography.HMAC hmac = new Mono.Security.Cryptography.HMAC(hashName, secret);
TlsStream tlsStream = new TlsStream();
byte[][] array = new byte[num2 + 1][];
array[0] = seed;
for (int i = 1; i <= num2; i++)
{
TlsStream tlsStream2 = new TlsStream();
hmac.TransformFinalBlock(array[i - 1], 0, array[i - 1].Length);
array[i] = hmac.Hash;
tlsStream2.Write(array[i]);
tlsStream2.Write(seed);
hmac.TransformFinalBlock(tlsStream2.ToArray(), 0, (int)tlsStream2.Length);
tlsStream.Write(hmac.Hash);
tlsStream2.Reset();
}
byte[] array2 = new byte[length];
Buffer.BlockCopy(tlsStream.ToArray(), 0, array2, 0, array2.Length);
tlsStream.Reset();
return array2;
}
// Token: 0x0600049A RID: 1178 RVA: 0x0001C948 File Offset: 0x0001AB48
private void createEncryptionCipher()
{
switch (this.cipherAlgorithmType)
{
case CipherAlgorithmType.Des:
this.encryptionAlgorithm = DES.Create();
break;
case CipherAlgorithmType.Rc2:
this.encryptionAlgorithm = RC2.Create();
break;
case CipherAlgorithmType.Rc4:
this.encryptionAlgorithm = new ARC4Managed();
break;
case CipherAlgorithmType.Rijndael:
this.encryptionAlgorithm = Rijndael.Create();
break;
case CipherAlgorithmType.TripleDes:
this.encryptionAlgorithm = TripleDES.Create();
break;
}
if (this.cipherMode == CipherMode.CBC)
{
this.encryptionAlgorithm.Mode = this.cipherMode;
this.encryptionAlgorithm.Padding = PaddingMode.None;
this.encryptionAlgorithm.KeySize = (int)(this.expandedKeyMaterialSize * 8);
this.encryptionAlgorithm.BlockSize = (int)(this.blockSize * 8);
}
if (this.context is ClientContext)
{
this.encryptionAlgorithm.Key = this.context.ClientWriteKey;
this.encryptionAlgorithm.IV = this.context.ClientWriteIV;
}
else
{
this.encryptionAlgorithm.Key = this.context.ServerWriteKey;
this.encryptionAlgorithm.IV = this.context.ServerWriteIV;
}
this.encryptionCipher = this.encryptionAlgorithm.CreateEncryptor();
if (this.context is ClientContext)
{
this.clientHMAC = new Mono.Security.Cryptography.HMAC(this.HashAlgorithmName, this.context.Negotiating.ClientWriteMAC);
}
else
{
this.serverHMAC = new Mono.Security.Cryptography.HMAC(this.HashAlgorithmName, this.context.Negotiating.ServerWriteMAC);
}
}
// Token: 0x0600049B RID: 1179 RVA: 0x0001CAF8 File Offset: 0x0001ACF8
private void createDecryptionCipher()
{
switch (this.cipherAlgorithmType)
{
case CipherAlgorithmType.Des:
this.decryptionAlgorithm = DES.Create();
break;
case CipherAlgorithmType.Rc2:
this.decryptionAlgorithm = RC2.Create();
break;
case CipherAlgorithmType.Rc4:
this.decryptionAlgorithm = new ARC4Managed();
break;
case CipherAlgorithmType.Rijndael:
this.decryptionAlgorithm = Rijndael.Create();
break;
case CipherAlgorithmType.TripleDes:
this.decryptionAlgorithm = TripleDES.Create();
break;
}
if (this.cipherMode == CipherMode.CBC)
{
this.decryptionAlgorithm.Mode = this.cipherMode;
this.decryptionAlgorithm.Padding = PaddingMode.None;
this.decryptionAlgorithm.KeySize = (int)(this.expandedKeyMaterialSize * 8);
this.decryptionAlgorithm.BlockSize = (int)(this.blockSize * 8);
}
if (this.context is ClientContext)
{
this.decryptionAlgorithm.Key = this.context.ServerWriteKey;
this.decryptionAlgorithm.IV = this.context.ServerWriteIV;
}
else
{
this.decryptionAlgorithm.Key = this.context.ClientWriteKey;
this.decryptionAlgorithm.IV = this.context.ClientWriteIV;
}
this.decryptionCipher = this.decryptionAlgorithm.CreateDecryptor();
if (this.context is ClientContext)
{
this.serverHMAC = new Mono.Security.Cryptography.HMAC(this.HashAlgorithmName, this.context.Negotiating.ServerWriteMAC);
}
else
{
this.clientHMAC = new Mono.Security.Cryptography.HMAC(this.HashAlgorithmName, this.context.Negotiating.ClientWriteMAC);
}
}
// Token: 0x0400023C RID: 572
public static byte[] EmptyArray = new byte[0];
// Token: 0x0400023D RID: 573
private short code;
// Token: 0x0400023E RID: 574
private string name;
// Token: 0x0400023F RID: 575
private CipherAlgorithmType cipherAlgorithmType;
// Token: 0x04000240 RID: 576
private HashAlgorithmType hashAlgorithmType;
// Token: 0x04000241 RID: 577
private ExchangeAlgorithmType exchangeAlgorithmType;
// Token: 0x04000242 RID: 578
private bool isExportable;
// Token: 0x04000243 RID: 579
private CipherMode cipherMode;
// Token: 0x04000244 RID: 580
private byte keyMaterialSize;
// Token: 0x04000245 RID: 581
private int keyBlockSize;
// Token: 0x04000246 RID: 582
private byte expandedKeyMaterialSize;
// Token: 0x04000247 RID: 583
private short effectiveKeyBits;
// Token: 0x04000248 RID: 584
private byte ivSize;
// Token: 0x04000249 RID: 585
private byte blockSize;
// Token: 0x0400024A RID: 586
private Context context;
// Token: 0x0400024B RID: 587
private SymmetricAlgorithm encryptionAlgorithm;
// Token: 0x0400024C RID: 588
private ICryptoTransform encryptionCipher;
// Token: 0x0400024D RID: 589
private SymmetricAlgorithm decryptionAlgorithm;
// Token: 0x0400024E RID: 590
private ICryptoTransform decryptionCipher;
// Token: 0x0400024F RID: 591
private KeyedHashAlgorithm clientHMAC;
// Token: 0x04000250 RID: 592
private KeyedHashAlgorithm serverHMAC;
}
}
@@ -0,0 +1,254 @@
using System;
using System.Collections;
using System.Globalization;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000081 RID: 129
internal sealed class CipherSuiteCollection : IEnumerable, ICollection, IList
{
// Token: 0x0600049C RID: 1180 RVA: 0x0001CCA8 File Offset: 0x0001AEA8
public CipherSuiteCollection(SecurityProtocolType protocol)
{
this.protocol = protocol;
this.cipherSuites = new ArrayList();
}
// Token: 0x1700011D RID: 285
object IList.this[int index]
{
get
{
return this[index];
}
set
{
this[index] = (CipherSuite)value;
}
}
// Token: 0x1700011E RID: 286
// (get) Token: 0x0600049F RID: 1183 RVA: 0x0001CCE0 File Offset: 0x0001AEE0
bool ICollection.IsSynchronized
{
get
{
return this.cipherSuites.IsSynchronized;
}
}
// Token: 0x1700011F RID: 287
// (get) Token: 0x060004A0 RID: 1184 RVA: 0x0001CCF0 File Offset: 0x0001AEF0
object ICollection.SyncRoot
{
get
{
return this.cipherSuites.SyncRoot;
}
}
// Token: 0x060004A1 RID: 1185 RVA: 0x0001CD00 File Offset: 0x0001AF00
IEnumerator IEnumerable.GetEnumerator()
{
return this.cipherSuites.GetEnumerator();
}
// Token: 0x060004A2 RID: 1186 RVA: 0x0001CD10 File Offset: 0x0001AF10
bool IList.Contains(object value)
{
return this.cipherSuites.Contains(value as CipherSuite);
}
// Token: 0x060004A3 RID: 1187 RVA: 0x0001CD24 File Offset: 0x0001AF24
int IList.IndexOf(object value)
{
return this.cipherSuites.IndexOf(value as CipherSuite);
}
// Token: 0x060004A4 RID: 1188 RVA: 0x0001CD38 File Offset: 0x0001AF38
void IList.Insert(int index, object value)
{
this.cipherSuites.Insert(index, value as CipherSuite);
}
// Token: 0x060004A5 RID: 1189 RVA: 0x0001CD4C File Offset: 0x0001AF4C
void IList.Remove(object value)
{
this.cipherSuites.Remove(value as CipherSuite);
}
// Token: 0x060004A6 RID: 1190 RVA: 0x0001CD60 File Offset: 0x0001AF60
void IList.RemoveAt(int index)
{
this.cipherSuites.RemoveAt(index);
}
// Token: 0x060004A7 RID: 1191 RVA: 0x0001CD70 File Offset: 0x0001AF70
int IList.Add(object value)
{
return this.cipherSuites.Add(value as CipherSuite);
}
// Token: 0x17000120 RID: 288
public CipherSuite this[string name]
{
get
{
return (CipherSuite)this.cipherSuites[this.IndexOf(name)];
}
set
{
this.cipherSuites[this.IndexOf(name)] = value;
}
}
// Token: 0x17000121 RID: 289
public CipherSuite this[int index]
{
get
{
return (CipherSuite)this.cipherSuites[index];
}
set
{
this.cipherSuites[index] = value;
}
}
// Token: 0x17000122 RID: 290
public CipherSuite this[short code]
{
get
{
return (CipherSuite)this.cipherSuites[this.IndexOf(code)];
}
set
{
this.cipherSuites[this.IndexOf(code)] = value;
}
}
// Token: 0x17000123 RID: 291
// (get) Token: 0x060004AE RID: 1198 RVA: 0x0001CE10 File Offset: 0x0001B010
public int Count
{
get
{
return this.cipherSuites.Count;
}
}
// Token: 0x17000124 RID: 292
// (get) Token: 0x060004AF RID: 1199 RVA: 0x0001CE20 File Offset: 0x0001B020
public bool IsFixedSize
{
get
{
return this.cipherSuites.IsFixedSize;
}
}
// Token: 0x17000125 RID: 293
// (get) Token: 0x060004B0 RID: 1200 RVA: 0x0001CE30 File Offset: 0x0001B030
public bool IsReadOnly
{
get
{
return this.cipherSuites.IsReadOnly;
}
}
// Token: 0x060004B1 RID: 1201 RVA: 0x0001CE40 File Offset: 0x0001B040
public void CopyTo(Array array, int index)
{
this.cipherSuites.CopyTo(array, index);
}
// Token: 0x060004B2 RID: 1202 RVA: 0x0001CE50 File Offset: 0x0001B050
public void Clear()
{
this.cipherSuites.Clear();
}
// Token: 0x060004B3 RID: 1203 RVA: 0x0001CE60 File Offset: 0x0001B060
public int IndexOf(string name)
{
int num = 0;
foreach (object obj in this.cipherSuites)
{
CipherSuite cipherSuite = (CipherSuite)obj;
if (this.cultureAwareCompare(cipherSuite.Name, name))
{
return num;
}
num++;
}
return -1;
}
// Token: 0x060004B4 RID: 1204 RVA: 0x0001CEF0 File Offset: 0x0001B0F0
public int IndexOf(short code)
{
int num = 0;
foreach (object obj in this.cipherSuites)
{
CipherSuite cipherSuite = (CipherSuite)obj;
if (cipherSuite.Code == code)
{
return num;
}
num++;
}
return -1;
}
// Token: 0x060004B5 RID: 1205 RVA: 0x0001CF78 File Offset: 0x0001B178
public CipherSuite Add(short code, string name, CipherAlgorithmType cipherType, HashAlgorithmType hashType, ExchangeAlgorithmType exchangeType, bool exportable, bool blockMode, byte keyMaterialSize, byte expandedKeyMaterialSize, short effectiveKeyBytes, byte ivSize, byte blockSize)
{
SecurityProtocolType securityProtocolType = this.protocol;
if (securityProtocolType != SecurityProtocolType.Default)
{
if (securityProtocolType != SecurityProtocolType.Ssl2)
{
if (securityProtocolType == SecurityProtocolType.Ssl3)
{
return this.add(new SslCipherSuite(code, name, cipherType, hashType, exchangeType, exportable, blockMode, keyMaterialSize, expandedKeyMaterialSize, effectiveKeyBytes, ivSize, blockSize));
}
if (securityProtocolType == SecurityProtocolType.Tls)
{
goto IL_32;
}
}
throw new NotSupportedException("Unsupported security protocol type.");
}
IL_32:
return this.add(new TlsCipherSuite(code, name, cipherType, hashType, exchangeType, exportable, blockMode, keyMaterialSize, expandedKeyMaterialSize, effectiveKeyBytes, ivSize, blockSize));
}
// Token: 0x060004B6 RID: 1206 RVA: 0x0001D004 File Offset: 0x0001B204
private TlsCipherSuite add(TlsCipherSuite cipherSuite)
{
this.cipherSuites.Add(cipherSuite);
return cipherSuite;
}
// Token: 0x060004B7 RID: 1207 RVA: 0x0001D014 File Offset: 0x0001B214
private SslCipherSuite add(SslCipherSuite cipherSuite)
{
this.cipherSuites.Add(cipherSuite);
return cipherSuite;
}
// Token: 0x060004B8 RID: 1208 RVA: 0x0001D024 File Offset: 0x0001B224
private bool cultureAwareCompare(string strA, string strB)
{
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth) == 0;
}
// Token: 0x04000251 RID: 593
private ArrayList cipherSuites;
// Token: 0x04000252 RID: 594
private SecurityProtocolType protocol;
}
}
@@ -0,0 +1,396 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000082 RID: 130
internal class CipherSuiteFactory
{
// Token: 0x060004BA RID: 1210 RVA: 0x0001D050 File Offset: 0x0001B250
public static CipherSuiteCollection GetSupportedCiphers(SecurityProtocolType protocol)
{
if (protocol != SecurityProtocolType.Default)
{
if (protocol != SecurityProtocolType.Ssl2)
{
if (protocol == SecurityProtocolType.Ssl3)
{
return CipherSuiteFactory.GetSsl3SupportedCiphers();
}
if (protocol == SecurityProtocolType.Tls)
{
goto IL_2D;
}
}
throw new NotSupportedException("Unsupported security protocol type");
}
IL_2D:
return CipherSuiteFactory.GetTls1SupportedCiphers();
}
// Token: 0x060004BB RID: 1211 RVA: 0x0001D0A0 File Offset: 0x0001B2A0
private static CipherSuiteCollection GetTls1SupportedCiphers()
{
return new CipherSuiteCollection(SecurityProtocolType.Tls)
{
{
53,
"TLS_RSA_WITH_AES_256_CBC_SHA",
CipherAlgorithmType.Rijndael,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
32,
32,
256,
16,
16
},
{
47,
"TLS_RSA_WITH_AES_128_CBC_SHA",
CipherAlgorithmType.Rijndael,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
16,
16,
128,
16,
16
},
{
10,
"TLS_RSA_WITH_3DES_EDE_CBC_SHA",
CipherAlgorithmType.TripleDes,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
24,
24,
168,
8,
8
},
{
5,
"TLS_RSA_WITH_RC4_128_SHA",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
false,
16,
16,
128,
0,
0
},
{
4,
"TLS_RSA_WITH_RC4_128_MD5",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
false,
false,
16,
16,
128,
0,
0
},
{
9,
"TLS_RSA_WITH_DES_CBC_SHA",
CipherAlgorithmType.Des,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
8,
8,
56,
8,
8
},
{
3,
"TLS_RSA_EXPORT_WITH_RC4_40_MD5",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
false,
5,
16,
40,
0,
0
},
{
6,
"TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5",
CipherAlgorithmType.Rc2,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
5,
16,
40,
8,
8
},
{
8,
"TLS_RSA_EXPORT_WITH_DES40_CBC_SHA",
CipherAlgorithmType.Des,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
5,
8,
40,
8,
8
},
{
96,
"TLS_RSA_EXPORT_WITH_RC4_56_MD5",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
false,
7,
16,
56,
0,
0
},
{
97,
"TLS_RSA_EXPORT_WITH_RC2_CBC_56_MD5",
CipherAlgorithmType.Rc2,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
7,
16,
56,
8,
8
},
{
98,
"TLS_RSA_EXPORT_WITH_DES_CBC_56_SHA",
CipherAlgorithmType.Des,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
8,
8,
64,
8,
8
},
{
100,
"TLS_RSA_EXPORT_WITH_RC4_56_SHA",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
true,
false,
7,
16,
56,
0,
0
}
};
}
// Token: 0x060004BC RID: 1212 RVA: 0x0001D21C File Offset: 0x0001B41C
private static CipherSuiteCollection GetSsl3SupportedCiphers()
{
return new CipherSuiteCollection(SecurityProtocolType.Ssl3)
{
{
53,
"SSL_RSA_WITH_AES_256_CBC_SHA",
CipherAlgorithmType.Rijndael,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
32,
32,
256,
16,
16
},
{
10,
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
CipherAlgorithmType.TripleDes,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
24,
24,
168,
8,
8
},
{
5,
"SSL_RSA_WITH_RC4_128_SHA",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
false,
16,
16,
128,
0,
0
},
{
4,
"SSL_RSA_WITH_RC4_128_MD5",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
false,
false,
16,
16,
128,
0,
0
},
{
9,
"SSL_RSA_WITH_DES_CBC_SHA",
CipherAlgorithmType.Des,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
false,
true,
8,
8,
56,
8,
8
},
{
3,
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
false,
5,
16,
40,
0,
0
},
{
6,
"SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5",
CipherAlgorithmType.Rc2,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
5,
16,
40,
8,
8
},
{
8,
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
CipherAlgorithmType.Des,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
5,
8,
40,
8,
8
},
{
96,
"SSL_RSA_EXPORT_WITH_RC4_56_MD5",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
false,
7,
16,
56,
0,
0
},
{
97,
"SSL_RSA_EXPORT_WITH_RC2_CBC_56_MD5",
CipherAlgorithmType.Rc2,
HashAlgorithmType.Md5,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
7,
16,
56,
8,
8
},
{
98,
"SSL_RSA_EXPORT_WITH_DES_CBC_56_SHA",
CipherAlgorithmType.Des,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
true,
true,
8,
8,
64,
8,
8
},
{
100,
"SSL_RSA_EXPORT_WITH_RC4_56_SHA",
CipherAlgorithmType.Rc4,
HashAlgorithmType.Sha1,
ExchangeAlgorithmType.RsaKeyX,
true,
false,
7,
16,
56,
0,
0
}
};
}
}
}
@@ -0,0 +1,56 @@
using System;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000083 RID: 131
internal class ClientContext : Context
{
// Token: 0x060004BD RID: 1213 RVA: 0x0001D374 File Offset: 0x0001B574
public ClientContext(SslClientStream stream, SecurityProtocolType securityProtocolType, string targetHost, X509CertificateCollection clientCertificates)
: base(securityProtocolType)
{
this.sslStream = stream;
base.ClientSettings.Certificates = clientCertificates;
base.ClientSettings.TargetHost = targetHost;
}
// Token: 0x17000126 RID: 294
// (get) Token: 0x060004BE RID: 1214 RVA: 0x0001D3A8 File Offset: 0x0001B5A8
public SslClientStream SslStream
{
get
{
return this.sslStream;
}
}
// Token: 0x17000127 RID: 295
// (get) Token: 0x060004BF RID: 1215 RVA: 0x0001D3B0 File Offset: 0x0001B5B0
// (set) Token: 0x060004C0 RID: 1216 RVA: 0x0001D3B8 File Offset: 0x0001B5B8
public short ClientHelloProtocol
{
get
{
return this.clientHelloProtocol;
}
set
{
this.clientHelloProtocol = value;
}
}
// Token: 0x060004C1 RID: 1217 RVA: 0x0001D3C4 File Offset: 0x0001B5C4
public override void Clear()
{
this.clientHelloProtocol = 0;
base.Clear();
}
// Token: 0x04000253 RID: 595
private SslClientStream sslStream;
// Token: 0x04000254 RID: 596
private short clientHelloProtocol;
}
}
@@ -0,0 +1,113 @@
using System;
using System.Globalization;
using System.IO;
using Mono.Security.Protocol.Tls.Handshake;
using Mono.Security.Protocol.Tls.Handshake.Client;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000084 RID: 132
internal class ClientRecordProtocol : RecordProtocol
{
// Token: 0x060004C2 RID: 1218 RVA: 0x0001D3D4 File Offset: 0x0001B5D4
public ClientRecordProtocol(Stream innerStream, ClientContext context)
: base(innerStream, context)
{
}
// Token: 0x060004C3 RID: 1219 RVA: 0x0001D3E0 File Offset: 0x0001B5E0
public override HandshakeMessage GetMessage(HandshakeType type)
{
return this.createClientHandshakeMessage(type);
}
// Token: 0x060004C4 RID: 1220 RVA: 0x0001D3F8 File Offset: 0x0001B5F8
protected override void ProcessHandshakeMessage(TlsStream handMsg)
{
HandshakeType handshakeType = (HandshakeType)handMsg.ReadByte();
int num = handMsg.ReadInt24();
byte[] array = null;
if (num > 0)
{
array = new byte[num];
handMsg.Read(array, 0, num);
}
HandshakeMessage handshakeMessage = this.createServerHandshakeMessage(handshakeType, array);
if (handshakeMessage != null)
{
handshakeMessage.Process();
}
base.Context.LastHandshakeMsg = handshakeType;
if (handshakeMessage != null)
{
handshakeMessage.Update();
base.Context.HandshakeMessages.WriteByte((byte)handshakeType);
base.Context.HandshakeMessages.WriteInt24(num);
if (num > 0)
{
base.Context.HandshakeMessages.Write(array, 0, array.Length);
}
}
}
// Token: 0x060004C5 RID: 1221 RVA: 0x0001D49C File Offset: 0x0001B69C
private HandshakeMessage createClientHandshakeMessage(HandshakeType type)
{
switch (type)
{
case HandshakeType.CertificateVerify:
return new TlsClientCertificateVerify(this.context);
case HandshakeType.ClientKeyExchange:
return new TlsClientKeyExchange(this.context);
default:
if (type == HandshakeType.ClientHello)
{
return new TlsClientHello(this.context);
}
if (type != HandshakeType.Certificate)
{
throw new InvalidOperationException("Unknown client handshake message type: " + type.ToString());
}
return new TlsClientCertificate(this.context);
case HandshakeType.Finished:
return new TlsClientFinished(this.context);
}
}
// Token: 0x060004C6 RID: 1222 RVA: 0x0001D538 File Offset: 0x0001B738
private HandshakeMessage createServerHandshakeMessage(HandshakeType type, byte[] buffer)
{
ClientContext clientContext = (ClientContext)this.context;
switch (type)
{
case HandshakeType.Certificate:
return new TlsServerCertificate(this.context, buffer);
case HandshakeType.ServerKeyExchange:
return new TlsServerKeyExchange(this.context, buffer);
case HandshakeType.CertificateRequest:
return new TlsServerCertificateRequest(this.context, buffer);
case HandshakeType.ServerHelloDone:
return new TlsServerHelloDone(this.context, buffer);
default:
switch (type)
{
case HandshakeType.HelloRequest:
if (clientContext.HandshakeState != HandshakeState.Started)
{
clientContext.HandshakeState = HandshakeState.None;
}
else
{
base.SendAlert(AlertLevel.Warning, AlertDescription.NoRenegotiation);
}
return null;
case HandshakeType.ServerHello:
return new TlsServerHello(this.context, buffer);
}
throw new TlsException(AlertDescription.UnexpectedMessage, string.Format(CultureInfo.CurrentUICulture, "Unknown server handshake message received ({0})", new object[] { type.ToString() }));
case HandshakeType.Finished:
return new TlsServerFinished(this.context, buffer);
}
}
}
}
@@ -0,0 +1,136 @@
using System;
using System.Collections;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000086 RID: 134
internal class ClientSessionCache
{
// Token: 0x060004D5 RID: 1237 RVA: 0x0001D874 File Offset: 0x0001BA74
public static void Add(string host, byte[] id)
{
object obj = ClientSessionCache.locker;
lock (obj)
{
string text = BitConverter.ToString(id);
ClientSessionInfo clientSessionInfo = (ClientSessionInfo)ClientSessionCache.cache[text];
if (clientSessionInfo == null)
{
ClientSessionCache.cache.Add(text, new ClientSessionInfo(host, id));
}
else if (clientSessionInfo.HostName == host)
{
clientSessionInfo.KeepAlive();
}
else
{
clientSessionInfo.Dispose();
ClientSessionCache.cache.Remove(text);
ClientSessionCache.cache.Add(text, new ClientSessionInfo(host, id));
}
}
}
// Token: 0x060004D6 RID: 1238 RVA: 0x0001D92C File Offset: 0x0001BB2C
public static byte[] FromHost(string host)
{
object obj = ClientSessionCache.locker;
byte[] array;
lock (obj)
{
foreach (object obj2 in ClientSessionCache.cache.Values)
{
ClientSessionInfo clientSessionInfo = (ClientSessionInfo)obj2;
if (clientSessionInfo.HostName == host && clientSessionInfo.Valid)
{
clientSessionInfo.KeepAlive();
return clientSessionInfo.Id;
}
}
array = null;
}
return array;
}
// Token: 0x060004D7 RID: 1239 RVA: 0x0001DA04 File Offset: 0x0001BC04
private static ClientSessionInfo FromContext(Context context, bool checkValidity)
{
if (context == null)
{
return null;
}
byte[] sessionId = context.SessionId;
if (sessionId == null || sessionId.Length == 0)
{
return null;
}
string text = BitConverter.ToString(sessionId);
ClientSessionInfo clientSessionInfo = (ClientSessionInfo)ClientSessionCache.cache[text];
if (clientSessionInfo == null)
{
return null;
}
if (context.ClientSettings.TargetHost != clientSessionInfo.HostName)
{
return null;
}
if (checkValidity && !clientSessionInfo.Valid)
{
clientSessionInfo.Dispose();
ClientSessionCache.cache.Remove(text);
return null;
}
return clientSessionInfo;
}
// Token: 0x060004D8 RID: 1240 RVA: 0x0001DA94 File Offset: 0x0001BC94
public static bool SetContextInCache(Context context)
{
object obj = ClientSessionCache.locker;
bool flag;
lock (obj)
{
ClientSessionInfo clientSessionInfo = ClientSessionCache.FromContext(context, false);
if (clientSessionInfo == null)
{
flag = false;
}
else
{
clientSessionInfo.GetContext(context);
clientSessionInfo.KeepAlive();
flag = true;
}
}
return flag;
}
// Token: 0x060004D9 RID: 1241 RVA: 0x0001DB00 File Offset: 0x0001BD00
public static bool SetContextFromCache(Context context)
{
object obj = ClientSessionCache.locker;
bool flag;
lock (obj)
{
ClientSessionInfo clientSessionInfo = ClientSessionCache.FromContext(context, true);
if (clientSessionInfo == null)
{
flag = false;
}
else
{
clientSessionInfo.SetContext(context);
clientSessionInfo.KeepAlive();
flag = true;
}
}
return flag;
}
// Token: 0x0400025C RID: 604
private static Hashtable cache = new Hashtable();
// Token: 0x0400025D RID: 605
private static object locker = new object();
}
}
@@ -0,0 +1,155 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000085 RID: 133
internal class ClientSessionInfo : IDisposable
{
// Token: 0x060004C7 RID: 1223 RVA: 0x0001D638 File Offset: 0x0001B838
public ClientSessionInfo(string hostname, byte[] id)
{
this.host = hostname;
this.sid = id;
this.KeepAlive();
}
// Token: 0x060004C8 RID: 1224 RVA: 0x0001D654 File Offset: 0x0001B854
static ClientSessionInfo()
{
string environmentVariable = Environment.GetEnvironmentVariable("MONO_TLS_SESSION_CACHE_TIMEOUT");
if (environmentVariable == null)
{
ClientSessionInfo.ValidityInterval = 180;
}
else
{
try
{
ClientSessionInfo.ValidityInterval = int.Parse(environmentVariable);
}
catch
{
ClientSessionInfo.ValidityInterval = 180;
}
}
}
// Token: 0x060004C9 RID: 1225 RVA: 0x0001D6C0 File Offset: 0x0001B8C0
~ClientSessionInfo()
{
this.Dispose(false);
}
// Token: 0x17000128 RID: 296
// (get) Token: 0x060004CA RID: 1226 RVA: 0x0001D6FC File Offset: 0x0001B8FC
public string HostName
{
get
{
return this.host;
}
}
// Token: 0x17000129 RID: 297
// (get) Token: 0x060004CB RID: 1227 RVA: 0x0001D704 File Offset: 0x0001B904
public byte[] Id
{
get
{
return this.sid;
}
}
// Token: 0x1700012A RID: 298
// (get) Token: 0x060004CC RID: 1228 RVA: 0x0001D70C File Offset: 0x0001B90C
public bool Valid
{
get
{
return this.masterSecret != null && this.validuntil > DateTime.UtcNow;
}
}
// Token: 0x060004CD RID: 1229 RVA: 0x0001D72C File Offset: 0x0001B92C
public void GetContext(Context context)
{
this.CheckDisposed();
if (context.MasterSecret != null)
{
this.masterSecret = (byte[])context.MasterSecret.Clone();
}
}
// Token: 0x060004CE RID: 1230 RVA: 0x0001D760 File Offset: 0x0001B960
public void SetContext(Context context)
{
this.CheckDisposed();
if (this.masterSecret != null)
{
context.MasterSecret = (byte[])this.masterSecret.Clone();
}
}
// Token: 0x060004CF RID: 1231 RVA: 0x0001D78C File Offset: 0x0001B98C
public void KeepAlive()
{
this.CheckDisposed();
this.validuntil = DateTime.UtcNow.AddSeconds((double)ClientSessionInfo.ValidityInterval);
}
// Token: 0x060004D0 RID: 1232 RVA: 0x0001D7B8 File Offset: 0x0001B9B8
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
// Token: 0x060004D1 RID: 1233 RVA: 0x0001D7C8 File Offset: 0x0001B9C8
private void Dispose(bool disposing)
{
if (!this.disposed)
{
this.validuntil = DateTime.MinValue;
this.host = null;
this.sid = null;
if (this.masterSecret != null)
{
Array.Clear(this.masterSecret, 0, this.masterSecret.Length);
this.masterSecret = null;
}
}
this.disposed = true;
}
// Token: 0x060004D2 RID: 1234 RVA: 0x0001D828 File Offset: 0x0001BA28
private void CheckDisposed()
{
if (this.disposed)
{
string text = Locale.GetText("Cache session information were disposed.");
throw new ObjectDisposedException(text);
}
}
// Token: 0x04000255 RID: 597
private const int DefaultValidityInterval = 180;
// Token: 0x04000256 RID: 598
private static readonly int ValidityInterval;
// Token: 0x04000257 RID: 599
private bool disposed;
// Token: 0x04000258 RID: 600
private DateTime validuntil;
// Token: 0x04000259 RID: 601
private string host;
// Token: 0x0400025A RID: 602
private byte[] sid;
// Token: 0x0400025B RID: 603
private byte[] masterSecret;
}
}
@@ -0,0 +1,18 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000087 RID: 135
[Serializable]
internal enum ContentType : byte
{
// Token: 0x0400025F RID: 607
ChangeCipherSpec = 20,
// Token: 0x04000260 RID: 608
Alert,
// Token: 0x04000261 RID: 609
Handshake,
// Token: 0x04000262 RID: 610
ApplicationData
}
}
@@ -0,0 +1,731 @@
using System;
using System.Security.Cryptography;
using Mono.Security.Protocol.Tls.Handshake;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000088 RID: 136
internal abstract class Context
{
// Token: 0x060004DA RID: 1242 RVA: 0x0001DB6C File Offset: 0x0001BD6C
public Context(SecurityProtocolType securityProtocolType)
{
this.SecurityProtocol = securityProtocolType;
this.compressionMethod = SecurityCompressionType.None;
this.serverSettings = new TlsServerSettings();
this.clientSettings = new TlsClientSettings();
this.handshakeMessages = new TlsStream();
this.sessionId = null;
this.handshakeState = HandshakeState.None;
this.random = RandomNumberGenerator.Create();
}
// Token: 0x1700012B RID: 299
// (get) Token: 0x060004DB RID: 1243 RVA: 0x0001DBC8 File Offset: 0x0001BDC8
// (set) Token: 0x060004DC RID: 1244 RVA: 0x0001DBD0 File Offset: 0x0001BDD0
public bool AbbreviatedHandshake
{
get
{
return this.abbreviatedHandshake;
}
set
{
this.abbreviatedHandshake = value;
}
}
// Token: 0x1700012C RID: 300
// (get) Token: 0x060004DD RID: 1245 RVA: 0x0001DBDC File Offset: 0x0001BDDC
// (set) Token: 0x060004DE RID: 1246 RVA: 0x0001DBE4 File Offset: 0x0001BDE4
public bool ProtocolNegotiated
{
get
{
return this.protocolNegotiated;
}
set
{
this.protocolNegotiated = value;
}
}
// Token: 0x1700012D RID: 301
// (get) Token: 0x060004DF RID: 1247 RVA: 0x0001DBF0 File Offset: 0x0001BDF0
// (set) Token: 0x060004E0 RID: 1248 RVA: 0x0001DC4C File Offset: 0x0001BE4C
public SecurityProtocolType SecurityProtocol
{
get
{
if ((this.securityProtocol & SecurityProtocolType.Tls) == SecurityProtocolType.Tls || (this.securityProtocol & SecurityProtocolType.Default) == SecurityProtocolType.Default)
{
return SecurityProtocolType.Tls;
}
if ((this.securityProtocol & SecurityProtocolType.Ssl3) == SecurityProtocolType.Ssl3)
{
return SecurityProtocolType.Ssl3;
}
throw new NotSupportedException("Unsupported security protocol type");
}
set
{
this.securityProtocol = value;
}
}
// Token: 0x1700012E RID: 302
// (get) Token: 0x060004E1 RID: 1249 RVA: 0x0001DC58 File Offset: 0x0001BE58
public SecurityProtocolType SecurityProtocolFlags
{
get
{
return this.securityProtocol;
}
}
// Token: 0x1700012F RID: 303
// (get) Token: 0x060004E2 RID: 1250 RVA: 0x0001DC60 File Offset: 0x0001BE60
public short Protocol
{
get
{
SecurityProtocolType securityProtocolType = this.SecurityProtocol;
if (securityProtocolType != SecurityProtocolType.Default)
{
if (securityProtocolType != SecurityProtocolType.Ssl2)
{
if (securityProtocolType == SecurityProtocolType.Ssl3)
{
return 768;
}
if (securityProtocolType == SecurityProtocolType.Tls)
{
return 769;
}
}
throw new NotSupportedException("Unsupported security protocol type");
}
return 769;
}
}
// Token: 0x17000130 RID: 304
// (get) Token: 0x060004E3 RID: 1251 RVA: 0x0001DCB8 File Offset: 0x0001BEB8
// (set) Token: 0x060004E4 RID: 1252 RVA: 0x0001DCC0 File Offset: 0x0001BEC0
public byte[] SessionId
{
get
{
return this.sessionId;
}
set
{
this.sessionId = value;
}
}
// Token: 0x17000131 RID: 305
// (get) Token: 0x060004E5 RID: 1253 RVA: 0x0001DCCC File Offset: 0x0001BECC
// (set) Token: 0x060004E6 RID: 1254 RVA: 0x0001DCD4 File Offset: 0x0001BED4
public SecurityCompressionType CompressionMethod
{
get
{
return this.compressionMethod;
}
set
{
this.compressionMethod = value;
}
}
// Token: 0x17000132 RID: 306
// (get) Token: 0x060004E7 RID: 1255 RVA: 0x0001DCE0 File Offset: 0x0001BEE0
public TlsServerSettings ServerSettings
{
get
{
return this.serverSettings;
}
}
// Token: 0x17000133 RID: 307
// (get) Token: 0x060004E8 RID: 1256 RVA: 0x0001DCE8 File Offset: 0x0001BEE8
public TlsClientSettings ClientSettings
{
get
{
return this.clientSettings;
}
}
// Token: 0x17000134 RID: 308
// (get) Token: 0x060004E9 RID: 1257 RVA: 0x0001DCF0 File Offset: 0x0001BEF0
// (set) Token: 0x060004EA RID: 1258 RVA: 0x0001DCF8 File Offset: 0x0001BEF8
public HandshakeType LastHandshakeMsg
{
get
{
return this.lastHandshakeMsg;
}
set
{
this.lastHandshakeMsg = value;
}
}
// Token: 0x17000135 RID: 309
// (get) Token: 0x060004EB RID: 1259 RVA: 0x0001DD04 File Offset: 0x0001BF04
// (set) Token: 0x060004EC RID: 1260 RVA: 0x0001DD0C File Offset: 0x0001BF0C
public HandshakeState HandshakeState
{
get
{
return this.handshakeState;
}
set
{
this.handshakeState = value;
}
}
// Token: 0x17000136 RID: 310
// (get) Token: 0x060004ED RID: 1261 RVA: 0x0001DD18 File Offset: 0x0001BF18
// (set) Token: 0x060004EE RID: 1262 RVA: 0x0001DD20 File Offset: 0x0001BF20
public bool ReceivedConnectionEnd
{
get
{
return this.receivedConnectionEnd;
}
set
{
this.receivedConnectionEnd = value;
}
}
// Token: 0x17000137 RID: 311
// (get) Token: 0x060004EF RID: 1263 RVA: 0x0001DD2C File Offset: 0x0001BF2C
// (set) Token: 0x060004F0 RID: 1264 RVA: 0x0001DD34 File Offset: 0x0001BF34
public bool SentConnectionEnd
{
get
{
return this.sentConnectionEnd;
}
set
{
this.sentConnectionEnd = value;
}
}
// Token: 0x17000138 RID: 312
// (get) Token: 0x060004F1 RID: 1265 RVA: 0x0001DD40 File Offset: 0x0001BF40
// (set) Token: 0x060004F2 RID: 1266 RVA: 0x0001DD48 File Offset: 0x0001BF48
public CipherSuiteCollection SupportedCiphers
{
get
{
return this.supportedCiphers;
}
set
{
this.supportedCiphers = value;
}
}
// Token: 0x17000139 RID: 313
// (get) Token: 0x060004F3 RID: 1267 RVA: 0x0001DD54 File Offset: 0x0001BF54
public TlsStream HandshakeMessages
{
get
{
return this.handshakeMessages;
}
}
// Token: 0x1700013A RID: 314
// (get) Token: 0x060004F4 RID: 1268 RVA: 0x0001DD5C File Offset: 0x0001BF5C
// (set) Token: 0x060004F5 RID: 1269 RVA: 0x0001DD64 File Offset: 0x0001BF64
public ulong WriteSequenceNumber
{
get
{
return this.writeSequenceNumber;
}
set
{
this.writeSequenceNumber = value;
}
}
// Token: 0x1700013B RID: 315
// (get) Token: 0x060004F6 RID: 1270 RVA: 0x0001DD70 File Offset: 0x0001BF70
// (set) Token: 0x060004F7 RID: 1271 RVA: 0x0001DD78 File Offset: 0x0001BF78
public ulong ReadSequenceNumber
{
get
{
return this.readSequenceNumber;
}
set
{
this.readSequenceNumber = value;
}
}
// Token: 0x1700013C RID: 316
// (get) Token: 0x060004F8 RID: 1272 RVA: 0x0001DD84 File Offset: 0x0001BF84
// (set) Token: 0x060004F9 RID: 1273 RVA: 0x0001DD8C File Offset: 0x0001BF8C
public byte[] ClientRandom
{
get
{
return this.clientRandom;
}
set
{
this.clientRandom = value;
}
}
// Token: 0x1700013D RID: 317
// (get) Token: 0x060004FA RID: 1274 RVA: 0x0001DD98 File Offset: 0x0001BF98
// (set) Token: 0x060004FB RID: 1275 RVA: 0x0001DDA0 File Offset: 0x0001BFA0
public byte[] ServerRandom
{
get
{
return this.serverRandom;
}
set
{
this.serverRandom = value;
}
}
// Token: 0x1700013E RID: 318
// (get) Token: 0x060004FC RID: 1276 RVA: 0x0001DDAC File Offset: 0x0001BFAC
// (set) Token: 0x060004FD RID: 1277 RVA: 0x0001DDB4 File Offset: 0x0001BFB4
public byte[] RandomCS
{
get
{
return this.randomCS;
}
set
{
this.randomCS = value;
}
}
// Token: 0x1700013F RID: 319
// (get) Token: 0x060004FE RID: 1278 RVA: 0x0001DDC0 File Offset: 0x0001BFC0
// (set) Token: 0x060004FF RID: 1279 RVA: 0x0001DDC8 File Offset: 0x0001BFC8
public byte[] RandomSC
{
get
{
return this.randomSC;
}
set
{
this.randomSC = value;
}
}
// Token: 0x17000140 RID: 320
// (get) Token: 0x06000500 RID: 1280 RVA: 0x0001DDD4 File Offset: 0x0001BFD4
// (set) Token: 0x06000501 RID: 1281 RVA: 0x0001DDDC File Offset: 0x0001BFDC
public byte[] MasterSecret
{
get
{
return this.masterSecret;
}
set
{
this.masterSecret = value;
}
}
// Token: 0x17000141 RID: 321
// (get) Token: 0x06000502 RID: 1282 RVA: 0x0001DDE8 File Offset: 0x0001BFE8
// (set) Token: 0x06000503 RID: 1283 RVA: 0x0001DDF0 File Offset: 0x0001BFF0
public byte[] ClientWriteKey
{
get
{
return this.clientWriteKey;
}
set
{
this.clientWriteKey = value;
}
}
// Token: 0x17000142 RID: 322
// (get) Token: 0x06000504 RID: 1284 RVA: 0x0001DDFC File Offset: 0x0001BFFC
// (set) Token: 0x06000505 RID: 1285 RVA: 0x0001DE04 File Offset: 0x0001C004
public byte[] ServerWriteKey
{
get
{
return this.serverWriteKey;
}
set
{
this.serverWriteKey = value;
}
}
// Token: 0x17000143 RID: 323
// (get) Token: 0x06000506 RID: 1286 RVA: 0x0001DE10 File Offset: 0x0001C010
// (set) Token: 0x06000507 RID: 1287 RVA: 0x0001DE18 File Offset: 0x0001C018
public byte[] ClientWriteIV
{
get
{
return this.clientWriteIV;
}
set
{
this.clientWriteIV = value;
}
}
// Token: 0x17000144 RID: 324
// (get) Token: 0x06000508 RID: 1288 RVA: 0x0001DE24 File Offset: 0x0001C024
// (set) Token: 0x06000509 RID: 1289 RVA: 0x0001DE2C File Offset: 0x0001C02C
public byte[] ServerWriteIV
{
get
{
return this.serverWriteIV;
}
set
{
this.serverWriteIV = value;
}
}
// Token: 0x17000145 RID: 325
// (get) Token: 0x0600050A RID: 1290 RVA: 0x0001DE38 File Offset: 0x0001C038
// (set) Token: 0x0600050B RID: 1291 RVA: 0x0001DE40 File Offset: 0x0001C040
public RecordProtocol RecordProtocol
{
get
{
return this.recordProtocol;
}
set
{
this.recordProtocol = value;
}
}
// Token: 0x0600050C RID: 1292 RVA: 0x0001DE4C File Offset: 0x0001C04C
public int GetUnixTime()
{
return (int)((DateTime.UtcNow.Ticks - 621355968000000000L) / 10000000L);
}
// Token: 0x0600050D RID: 1293 RVA: 0x0001DE78 File Offset: 0x0001C078
public byte[] GetSecureRandomBytes(int count)
{
byte[] array = new byte[count];
this.random.GetNonZeroBytes(array);
return array;
}
// Token: 0x0600050E RID: 1294 RVA: 0x0001DE9C File Offset: 0x0001C09C
public virtual void Clear()
{
this.compressionMethod = SecurityCompressionType.None;
this.serverSettings = new TlsServerSettings();
this.clientSettings = new TlsClientSettings();
this.handshakeMessages = new TlsStream();
this.sessionId = null;
this.handshakeState = HandshakeState.None;
this.ClearKeyInfo();
}
// Token: 0x0600050F RID: 1295 RVA: 0x0001DEE8 File Offset: 0x0001C0E8
public virtual void ClearKeyInfo()
{
if (this.masterSecret != null)
{
Array.Clear(this.masterSecret, 0, this.masterSecret.Length);
this.masterSecret = null;
}
if (this.clientRandom != null)
{
Array.Clear(this.clientRandom, 0, this.clientRandom.Length);
this.clientRandom = null;
}
if (this.serverRandom != null)
{
Array.Clear(this.serverRandom, 0, this.serverRandom.Length);
this.serverRandom = null;
}
if (this.randomCS != null)
{
Array.Clear(this.randomCS, 0, this.randomCS.Length);
this.randomCS = null;
}
if (this.randomSC != null)
{
Array.Clear(this.randomSC, 0, this.randomSC.Length);
this.randomSC = null;
}
if (this.clientWriteKey != null)
{
Array.Clear(this.clientWriteKey, 0, this.clientWriteKey.Length);
this.clientWriteKey = null;
}
if (this.clientWriteIV != null)
{
Array.Clear(this.clientWriteIV, 0, this.clientWriteIV.Length);
this.clientWriteIV = null;
}
if (this.serverWriteKey != null)
{
Array.Clear(this.serverWriteKey, 0, this.serverWriteKey.Length);
this.serverWriteKey = null;
}
if (this.serverWriteIV != null)
{
Array.Clear(this.serverWriteIV, 0, this.serverWriteIV.Length);
this.serverWriteIV = null;
}
this.handshakeMessages.Reset();
if (this.securityProtocol != SecurityProtocolType.Ssl3)
{
}
}
// Token: 0x06000510 RID: 1296 RVA: 0x0001E064 File Offset: 0x0001C264
public SecurityProtocolType DecodeProtocolCode(short code)
{
if (code == 768)
{
return SecurityProtocolType.Ssl3;
}
if (code != 769)
{
throw new NotSupportedException("Unsupported security protocol type");
}
return SecurityProtocolType.Tls;
}
// Token: 0x06000511 RID: 1297 RVA: 0x0001E0A4 File Offset: 0x0001C2A4
public void ChangeProtocol(short protocol)
{
SecurityProtocolType securityProtocolType = this.DecodeProtocolCode(protocol);
if ((securityProtocolType & this.SecurityProtocolFlags) == securityProtocolType || (this.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
{
this.SecurityProtocol = securityProtocolType;
this.SupportedCiphers.Clear();
this.SupportedCiphers = null;
this.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(securityProtocolType);
return;
}
throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
}
// Token: 0x17000146 RID: 326
// (get) Token: 0x06000512 RID: 1298 RVA: 0x0001E114 File Offset: 0x0001C314
public SecurityParameters Current
{
get
{
if (this.current == null)
{
this.current = new SecurityParameters();
}
if (this.current.Cipher != null)
{
this.current.Cipher.Context = this;
}
return this.current;
}
}
// Token: 0x17000147 RID: 327
// (get) Token: 0x06000513 RID: 1299 RVA: 0x0001E154 File Offset: 0x0001C354
public SecurityParameters Negotiating
{
get
{
if (this.negotiating == null)
{
this.negotiating = new SecurityParameters();
}
if (this.negotiating.Cipher != null)
{
this.negotiating.Cipher.Context = this;
}
return this.negotiating;
}
}
// Token: 0x17000148 RID: 328
// (get) Token: 0x06000514 RID: 1300 RVA: 0x0001E194 File Offset: 0x0001C394
public SecurityParameters Read
{
get
{
return this.read;
}
}
// Token: 0x17000149 RID: 329
// (get) Token: 0x06000515 RID: 1301 RVA: 0x0001E19C File Offset: 0x0001C39C
public SecurityParameters Write
{
get
{
return this.write;
}
}
// Token: 0x06000516 RID: 1302 RVA: 0x0001E1A4 File Offset: 0x0001C3A4
public void StartSwitchingSecurityParameters(bool client)
{
if (client)
{
this.write = this.negotiating;
this.read = this.current;
}
else
{
this.read = this.negotiating;
this.write = this.current;
}
this.current = this.negotiating;
}
// Token: 0x06000517 RID: 1303 RVA: 0x0001E1F8 File Offset: 0x0001C3F8
public void EndSwitchingSecurityParameters(bool client)
{
SecurityParameters securityParameters;
if (client)
{
securityParameters = this.read;
this.read = this.current;
}
else
{
securityParameters = this.write;
this.write = this.current;
}
if (securityParameters != null)
{
securityParameters.Clear();
}
this.negotiating = securityParameters;
}
// Token: 0x04000263 RID: 611
internal const short MAX_FRAGMENT_SIZE = 16384;
// Token: 0x04000264 RID: 612
internal const short TLS1_PROTOCOL_CODE = 769;
// Token: 0x04000265 RID: 613
internal const short SSL3_PROTOCOL_CODE = 768;
// Token: 0x04000266 RID: 614
internal const long UNIX_BASE_TICKS = 621355968000000000L;
// Token: 0x04000267 RID: 615
private SecurityProtocolType securityProtocol;
// Token: 0x04000268 RID: 616
private byte[] sessionId;
// Token: 0x04000269 RID: 617
private SecurityCompressionType compressionMethod;
// Token: 0x0400026A RID: 618
private TlsServerSettings serverSettings;
// Token: 0x0400026B RID: 619
private TlsClientSettings clientSettings;
// Token: 0x0400026C RID: 620
private SecurityParameters current;
// Token: 0x0400026D RID: 621
private SecurityParameters negotiating;
// Token: 0x0400026E RID: 622
private SecurityParameters read;
// Token: 0x0400026F RID: 623
private SecurityParameters write;
// Token: 0x04000270 RID: 624
private CipherSuiteCollection supportedCiphers;
// Token: 0x04000271 RID: 625
private HandshakeType lastHandshakeMsg;
// Token: 0x04000272 RID: 626
private HandshakeState handshakeState;
// Token: 0x04000273 RID: 627
private bool abbreviatedHandshake;
// Token: 0x04000274 RID: 628
private bool receivedConnectionEnd;
// Token: 0x04000275 RID: 629
private bool sentConnectionEnd;
// Token: 0x04000276 RID: 630
private bool protocolNegotiated;
// Token: 0x04000277 RID: 631
private ulong writeSequenceNumber;
// Token: 0x04000278 RID: 632
private ulong readSequenceNumber;
// Token: 0x04000279 RID: 633
private byte[] clientRandom;
// Token: 0x0400027A RID: 634
private byte[] serverRandom;
// Token: 0x0400027B RID: 635
private byte[] randomCS;
// Token: 0x0400027C RID: 636
private byte[] randomSC;
// Token: 0x0400027D RID: 637
private byte[] masterSecret;
// Token: 0x0400027E RID: 638
private byte[] clientWriteKey;
// Token: 0x0400027F RID: 639
private byte[] serverWriteKey;
// Token: 0x04000280 RID: 640
private byte[] clientWriteIV;
// Token: 0x04000281 RID: 641
private byte[] serverWriteIV;
// Token: 0x04000282 RID: 642
private TlsStream handshakeMessages;
// Token: 0x04000283 RID: 643
private RandomNumberGenerator random;
// Token: 0x04000284 RID: 644
private RecordProtocol recordProtocol;
}
}
@@ -0,0 +1,61 @@
using System;
using System.Diagnostics;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000089 RID: 137
internal class DebugHelper
{
// Token: 0x06000519 RID: 1305 RVA: 0x0001E254 File Offset: 0x0001C454
[Conditional("DEBUG")]
public static void Initialize()
{
if (!DebugHelper.isInitialized)
{
DebugHelper.isInitialized = true;
}
}
// Token: 0x0600051A RID: 1306 RVA: 0x0001E268 File Offset: 0x0001C468
[Conditional("DEBUG")]
public static void WriteLine(string format, params object[] args)
{
}
// Token: 0x0600051B RID: 1307 RVA: 0x0001E26C File Offset: 0x0001C46C
[Conditional("DEBUG")]
public static void WriteLine(string message)
{
}
// Token: 0x0600051C RID: 1308 RVA: 0x0001E270 File Offset: 0x0001C470
[Conditional("DEBUG")]
public static void WriteLine(string message, byte[] buffer)
{
}
// Token: 0x0600051D RID: 1309 RVA: 0x0001E274 File Offset: 0x0001C474
[Conditional("DEBUG")]
public static void WriteBuffer(byte[] buffer)
{
}
// Token: 0x0600051E RID: 1310 RVA: 0x0001E278 File Offset: 0x0001C478
[Conditional("DEBUG")]
public static void WriteBuffer(byte[] buffer, int index, int length)
{
for (int i = index; i < length; i += 16)
{
int num = ((length - i < 16) ? (length - i) : 16);
string text = string.Empty;
for (int j = 0; j < num; j++)
{
text = text + buffer[i + j].ToString("x2") + " ";
}
}
}
// Token: 0x04000285 RID: 645
private static bool isInitialized;
}
}
@@ -0,0 +1,20 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200008A RID: 138
[Serializable]
public enum ExchangeAlgorithmType
{
// Token: 0x04000287 RID: 647
DiffieHellman,
// Token: 0x04000288 RID: 648
Fortezza,
// Token: 0x04000289 RID: 649
None,
// Token: 0x0400028A RID: 650
RsaKeyX,
// Token: 0x0400028B RID: 651
RsaSign
}
}
@@ -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);
}
}
}
@@ -0,0 +1,16 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200008B RID: 139
[Serializable]
internal enum HandshakeState
{
// Token: 0x0400028D RID: 653
None,
// Token: 0x0400028E RID: 654
Started,
// Token: 0x0400028F RID: 655
Finished
}
}
@@ -0,0 +1,16 @@
using System;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200008C RID: 140
[Serializable]
public enum HashAlgorithmType
{
// Token: 0x04000291 RID: 657
Md5,
// Token: 0x04000292 RID: 658
None,
// Token: 0x04000293 RID: 659
Sha1
}
}
@@ -0,0 +1,96 @@
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200008D RID: 141
internal class HttpsClientStream : SslClientStream
{
// Token: 0x0600051F RID: 1311 RVA: 0x0001E2E4 File Offset: 0x0001C4E4
public HttpsClientStream(Stream stream, X509CertificateCollection clientCertificates, HttpWebRequest request, byte[] buffer)
: base(stream, request.Address.Host, false, (SecurityProtocolType)ServicePointManager.SecurityProtocol, clientCertificates)
{
this._request = request;
this._status = 0;
if (buffer != null)
{
base.InputBuffer.Write(buffer, 0, buffer.Length);
}
base.CheckCertRevocationStatus = ServicePointManager.CheckCertificateRevocationList;
base.ClientCertSelection += (X509CertificateCollection clientCerts, X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates) => (clientCerts != null && clientCerts.Count != 0) ? clientCerts[0] : null;
base.PrivateKeySelection += delegate(X509Certificate certificate, string targetHost)
{
X509Certificate2 x509Certificate = certificate as X509Certificate2;
return (x509Certificate != null) ? x509Certificate.PrivateKey : null;
};
}
// Token: 0x1700014A RID: 330
// (get) Token: 0x06000520 RID: 1312 RVA: 0x0001E384 File Offset: 0x0001C584
public bool TrustFailure
{
get
{
int status = this._status;
return status == -2146762487 || status == -2146762486;
}
}
// Token: 0x06000521 RID: 1313 RVA: 0x0001E3B8 File Offset: 0x0001C5B8
internal override bool RaiseServerCertificateValidation(X509Certificate certificate, int[] certificateErrors)
{
bool flag = certificateErrors.Length > 0;
this._status = ((!flag) ? 0 : certificateErrors[0]);
if (ServicePointManager.CertificatePolicy != null)
{
ServicePoint servicePoint = this._request.ServicePoint;
if (!ServicePointManager.CertificatePolicy.CheckValidationResult(servicePoint, certificate, this._request, this._status))
{
return false;
}
flag = true;
}
if (this.HaveRemoteValidation2Callback)
{
return flag;
}
RemoteCertificateValidationCallback serverCertificateValidationCallback = ServicePointManager.ServerCertificateValidationCallback;
if (serverCertificateValidationCallback != null)
{
SslPolicyErrors sslPolicyErrors = SslPolicyErrors.None;
foreach (int num in certificateErrors)
{
if (num == -2146762490)
{
sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable;
}
else if (num == -2146762481)
{
sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
}
else
{
sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors;
}
}
X509Certificate2 x509Certificate = new X509Certificate2(certificate.GetRawCertData());
X509Chain x509Chain = new X509Chain();
if (!x509Chain.Build(x509Certificate))
{
sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors;
}
return serverCertificateValidationCallback(this._request, x509Certificate, x509Chain, sslPolicyErrors);
}
return flag;
}
// Token: 0x04000294 RID: 660
private HttpWebRequest _request;
// Token: 0x04000295 RID: 661
private int _status;
}
}
@@ -0,0 +1,10 @@
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x020000CE RID: 206
// (Invoke) Token: 0x0600071D RID: 1821
public delegate AsymmetricAlgorithm PrivateKeySelectionCallback(X509Certificate certificate, string targetHost);
}
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000091 RID: 145
internal class RSASslSignatureDeformatter : AsymmetricSignatureDeformatter
{
// Token: 0x0600055C RID: 1372 RVA: 0x0001F64C File Offset: 0x0001D84C
public RSASslSignatureDeformatter()
{
}
// Token: 0x0600055D RID: 1373 RVA: 0x0001F654 File Offset: 0x0001D854
public RSASslSignatureDeformatter(AsymmetricAlgorithm key)
{
this.SetKey(key);
}
// Token: 0x0600055E RID: 1374 RVA: 0x0001F664 File Offset: 0x0001D864
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
{
if (this.key == null)
{
throw new CryptographicUnexpectedOperationException("The key is a null reference");
}
if (this.hash == null)
{
throw new CryptographicUnexpectedOperationException("The hash algorithm is a null reference.");
}
if (rgbHash == null)
{
throw new ArgumentNullException("The rgbHash parameter is a null reference.");
}
return PKCS1.Verify_v15(this.key, this.hash, rgbHash, rgbSignature);
}
// Token: 0x0600055F RID: 1375 RVA: 0x0001F6C4 File Offset: 0x0001D8C4
public override void SetHashAlgorithm(string strName)
{
if (strName != null)
{
if (RSASslSignatureDeformatter.<>f__switch$map15 == null)
{
RSASslSignatureDeformatter.<>f__switch$map15 = new Dictionary<string, int>(1) { { "MD5SHA1", 0 } };
}
int num;
if (RSASslSignatureDeformatter.<>f__switch$map15.TryGetValue(strName, out num))
{
if (num == 0)
{
this.hash = new MD5SHA1();
return;
}
}
}
this.hash = HashAlgorithm.Create(strName);
}
// Token: 0x06000560 RID: 1376 RVA: 0x0001F73C File Offset: 0x0001D93C
public override void SetKey(AsymmetricAlgorithm key)
{
if (!(key is RSA))
{
throw new ArgumentException("Specfied key is not an RSA key");
}
this.key = key as RSA;
}
// Token: 0x040002AB RID: 683
private RSA key;
// Token: 0x040002AC RID: 684
private HashAlgorithm hash;
}
}
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x02000092 RID: 146
internal class RSASslSignatureFormatter : AsymmetricSignatureFormatter
{
// Token: 0x06000561 RID: 1377 RVA: 0x0001F76C File Offset: 0x0001D96C
public RSASslSignatureFormatter()
{
}
// Token: 0x06000562 RID: 1378 RVA: 0x0001F774 File Offset: 0x0001D974
public RSASslSignatureFormatter(AsymmetricAlgorithm key)
{
this.SetKey(key);
}
// Token: 0x06000563 RID: 1379 RVA: 0x0001F784 File Offset: 0x0001D984
public override byte[] CreateSignature(byte[] rgbHash)
{
if (this.key == null)
{
throw new CryptographicUnexpectedOperationException("The key is a null reference");
}
if (this.hash == null)
{
throw new CryptographicUnexpectedOperationException("The hash algorithm is a null reference.");
}
if (rgbHash == null)
{
throw new ArgumentNullException("The rgbHash parameter is a null reference.");
}
return PKCS1.Sign_v15(this.key, this.hash, rgbHash);
}
// Token: 0x06000564 RID: 1380 RVA: 0x0001F7E0 File Offset: 0x0001D9E0
public override void SetHashAlgorithm(string strName)
{
if (strName != null)
{
if (RSASslSignatureFormatter.<>f__switch$map16 == null)
{
RSASslSignatureFormatter.<>f__switch$map16 = new Dictionary<string, int>(1) { { "MD5SHA1", 0 } };
}
int num;
if (RSASslSignatureFormatter.<>f__switch$map16.TryGetValue(strName, out num))
{
if (num == 0)
{
this.hash = new MD5SHA1();
return;
}
}
}
this.hash = HashAlgorithm.Create(strName);
}
// Token: 0x06000565 RID: 1381 RVA: 0x0001F858 File Offset: 0x0001DA58
public override void SetKey(AsymmetricAlgorithm key)
{
if (!(key is RSA))
{
throw new ArgumentException("Specfied key is not an RSA key");
}
this.key = key as RSA;
}
// Token: 0x040002AE RID: 686
private RSA key;
// Token: 0x040002AF RID: 687
private HashAlgorithm hash;
}
}
@@ -0,0 +1,963 @@
using System;
using System.IO;
using System.Threading;
using Mono.Security.Protocol.Tls.Handshake;
namespace Mono.Security.Protocol.Tls
{
// Token: 0x0200008E RID: 142
internal abstract class RecordProtocol
{
// Token: 0x06000524 RID: 1316 RVA: 0x0001E514 File Offset: 0x0001C714
public RecordProtocol(Stream innerStream, Context context)
{
this.innerStream = innerStream;
this.context = context;
this.context.RecordProtocol = this;
}
// Token: 0x1700014B RID: 331
// (get) Token: 0x06000526 RID: 1318 RVA: 0x0001E554 File Offset: 0x0001C754
// (set) Token: 0x06000527 RID: 1319 RVA: 0x0001E55C File Offset: 0x0001C75C
public Context Context
{
get
{
return this.context;
}
set
{
this.context = value;
}
}
// Token: 0x06000528 RID: 1320 RVA: 0x0001E568 File Offset: 0x0001C768
public virtual void SendRecord(HandshakeType type)
{
IAsyncResult asyncResult = this.BeginSendRecord(type, null, null);
this.EndSendRecord(asyncResult);
}
// Token: 0x06000529 RID: 1321
protected abstract void ProcessHandshakeMessage(TlsStream handMsg);
// Token: 0x0600052A RID: 1322 RVA: 0x0001E588 File Offset: 0x0001C788
protected virtual void ProcessChangeCipherSpec()
{
Context context = this.Context;
context.ReadSequenceNumber = 0UL;
if (context is ClientContext)
{
context.EndSwitchingSecurityParameters(true);
}
else
{
context.StartSwitchingSecurityParameters(false);
}
}
// Token: 0x0600052B RID: 1323 RVA: 0x0001E5C4 File Offset: 0x0001C7C4
public virtual HandshakeMessage GetMessage(HandshakeType type)
{
throw new NotSupportedException();
}
// Token: 0x0600052C RID: 1324 RVA: 0x0001E5CC File Offset: 0x0001C7CC
public IAsyncResult BeginReceiveRecord(Stream record, AsyncCallback callback, object state)
{
if (this.context.ReceivedConnectionEnd)
{
throw new TlsException(AlertDescription.InternalError, "The session is finished and it's no longer valid.");
}
RecordProtocol.record_processing.Reset();
byte[] array = new byte[1];
RecordProtocol.ReceiveRecordAsyncResult receiveRecordAsyncResult = new RecordProtocol.ReceiveRecordAsyncResult(callback, state, array, record);
record.BeginRead(receiveRecordAsyncResult.InitialBuffer, 0, receiveRecordAsyncResult.InitialBuffer.Length, new AsyncCallback(this.InternalReceiveRecordCallback), receiveRecordAsyncResult);
return receiveRecordAsyncResult;
}
// Token: 0x0600052D RID: 1325 RVA: 0x0001E638 File Offset: 0x0001C838
private void InternalReceiveRecordCallback(IAsyncResult asyncResult)
{
RecordProtocol.ReceiveRecordAsyncResult receiveRecordAsyncResult = asyncResult.AsyncState as RecordProtocol.ReceiveRecordAsyncResult;
Stream record = receiveRecordAsyncResult.Record;
try
{
if (receiveRecordAsyncResult.Record.EndRead(asyncResult) == 0)
{
receiveRecordAsyncResult.SetComplete(null);
}
else
{
int num = (int)receiveRecordAsyncResult.InitialBuffer[0];
this.context.LastHandshakeMsg = HandshakeType.ClientHello;
ContentType contentType = (ContentType)num;
byte[] array = this.ReadRecordBuffer(num, record);
if (array == null)
{
receiveRecordAsyncResult.SetComplete(null);
}
else
{
if (contentType != ContentType.Alert || array.Length != 2)
{
if (this.Context.Read != null && this.Context.Read.Cipher != null)
{
array = this.decryptRecordFragment(contentType, array);
}
}
ContentType contentType2 = contentType;
switch (contentType2)
{
case ContentType.ChangeCipherSpec:
this.ProcessChangeCipherSpec();
break;
case ContentType.Alert:
this.ProcessAlert((AlertLevel)array[0], (AlertDescription)array[1]);
if (record.CanSeek)
{
record.SetLength(0L);
}
array = null;
break;
case ContentType.Handshake:
{
TlsStream tlsStream = new TlsStream(array);
while (!tlsStream.EOF)
{
this.ProcessHandshakeMessage(tlsStream);
}
break;
}
case ContentType.ApplicationData:
break;
default:
if (contentType2 != (ContentType)128)
{
throw new TlsException(AlertDescription.UnexpectedMessage, "Unknown record received from server.");
}
this.context.HandshakeMessages.Write(array);
break;
}
receiveRecordAsyncResult.SetComplete(array);
}
}
}
catch (Exception ex)
{
receiveRecordAsyncResult.SetComplete(ex);
}
}
// Token: 0x0600052E RID: 1326 RVA: 0x0001E7E4 File Offset: 0x0001C9E4
public byte[] EndReceiveRecord(IAsyncResult asyncResult)
{
RecordProtocol.ReceiveRecordAsyncResult receiveRecordAsyncResult = asyncResult as RecordProtocol.ReceiveRecordAsyncResult;
if (receiveRecordAsyncResult == null)
{
throw new ArgumentException("Either the provided async result is null or was not created by this RecordProtocol.");
}
if (!receiveRecordAsyncResult.IsCompleted)
{
receiveRecordAsyncResult.AsyncWaitHandle.WaitOne();
}
if (receiveRecordAsyncResult.CompletedWithError)
{
throw receiveRecordAsyncResult.AsyncException;
}
byte[] resultingBuffer = receiveRecordAsyncResult.ResultingBuffer;
RecordProtocol.record_processing.Set();
return resultingBuffer;
}
// Token: 0x0600052F RID: 1327 RVA: 0x0001E848 File Offset: 0x0001CA48
public byte[] ReceiveRecord(Stream record)
{
IAsyncResult asyncResult = this.BeginReceiveRecord(record, null, null);
return this.EndReceiveRecord(asyncResult);
}
// Token: 0x06000530 RID: 1328 RVA: 0x0001E868 File Offset: 0x0001CA68
private byte[] ReadRecordBuffer(int contentType, Stream record)
{
if (contentType == 128)
{
return this.ReadClientHelloV2(record);
}
if (!Enum.IsDefined(typeof(ContentType), (ContentType)contentType))
{
throw new TlsException(AlertDescription.DecodeError);
}
return this.ReadStandardRecordBuffer(record);
}
// Token: 0x06000531 RID: 1329 RVA: 0x0001E8BC File Offset: 0x0001CABC
private byte[] ReadClientHelloV2(Stream record)
{
int num = record.ReadByte();
if (record.CanSeek && (long)(num + 1) > record.Length)
{
return null;
}
byte[] array = new byte[num];
record.Read(array, 0, num);
int num2 = (int)array[0];
if (num2 != 1)
{
throw new TlsException(AlertDescription.DecodeError);
}
int num3 = ((int)array[1] << 8) | (int)array[2];
int num4 = ((int)array[3] << 8) | (int)array[4];
int num5 = ((int)array[5] << 8) | (int)array[6];
int num6 = ((int)array[7] << 8) | (int)array[8];
int num7 = ((num6 <= 32) ? num6 : 32);
byte[] array2 = new byte[num4];
Buffer.BlockCopy(array, 9, array2, 0, num4);
byte[] array3 = new byte[num5];
Buffer.BlockCopy(array, 9 + num4, array3, 0, num5);
byte[] array4 = new byte[num6];
Buffer.BlockCopy(array, 9 + num4 + num5, array4, 0, num6);
if (num6 < 16 || num4 == 0 || num4 % 3 != 0)
{
throw new TlsException(AlertDescription.DecodeError);
}
if (array3.Length > 0)
{
this.context.SessionId = array3;
}
this.Context.ChangeProtocol((short)num3);
this.ProcessCipherSpecV2Buffer(this.Context.SecurityProtocol, array2);
this.context.ClientRandom = new byte[32];
Buffer.BlockCopy(array4, array4.Length - num7, this.context.ClientRandom, 32 - num7, num7);
this.context.LastHandshakeMsg = HandshakeType.ClientHello;
this.context.ProtocolNegotiated = true;
return array;
}
// Token: 0x06000532 RID: 1330 RVA: 0x0001EA40 File Offset: 0x0001CC40
private byte[] ReadStandardRecordBuffer(Stream record)
{
byte[] array = new byte[4];
if (record.Read(array, 0, 4) != 4)
{
throw new TlsException("buffer underrun");
}
short num = (short)(((int)array[0] << 8) | (int)array[1]);
short num2 = (short)(((int)array[2] << 8) | (int)array[3]);
if (record.CanSeek && (long)(num2 + 5) > record.Length)
{
return null;
}
int num3 = 0;
byte[] array2 = new byte[(int)num2];
while (num3 != (int)num2)
{
int num4 = record.Read(array2, num3, array2.Length - num3);
if (num4 == 0)
{
throw new TlsException(AlertDescription.CloseNotify, "Received 0 bytes from stream. It must be closed.");
}
num3 += num4;
}
if (num != this.context.Protocol && this.context.ProtocolNegotiated)
{
throw new TlsException(AlertDescription.ProtocolVersion, "Invalid protocol version on message received");
}
return array2;
}
// Token: 0x06000533 RID: 1331 RVA: 0x0001EB10 File Offset: 0x0001CD10
private void ProcessAlert(AlertLevel alertLevel, AlertDescription alertDesc)
{
if (alertLevel != AlertLevel.Warning)
{
if (alertLevel == AlertLevel.Fatal)
{
throw new TlsException(alertLevel, alertDesc);
}
}
if (alertDesc == AlertDescription.CloseNotify)
{
this.context.ReceivedConnectionEnd = true;
}
}
// Token: 0x06000534 RID: 1332 RVA: 0x0001EB60 File Offset: 0x0001CD60
public void SendAlert(AlertDescription description)
{
this.SendAlert(new Alert(description));
}
// Token: 0x06000535 RID: 1333 RVA: 0x0001EB70 File Offset: 0x0001CD70
public void SendAlert(AlertLevel level, AlertDescription description)
{
this.SendAlert(new Alert(level, description));
}
// Token: 0x06000536 RID: 1334 RVA: 0x0001EB80 File Offset: 0x0001CD80
public void SendAlert(Alert alert)
{
AlertLevel alertLevel;
AlertDescription alertDescription;
bool flag;
if (alert == null)
{
alertLevel = AlertLevel.Fatal;
alertDescription = AlertDescription.InternalError;
flag = true;
}
else
{
alertLevel = alert.Level;
alertDescription = alert.Description;
flag = alert.IsCloseNotify;
}
this.SendRecord(ContentType.Alert, new byte[]
{
(byte)alertLevel,
(byte)alertDescription
});
if (flag)
{
this.context.SentConnectionEnd = true;
}
}
// Token: 0x06000537 RID: 1335 RVA: 0x0001EBDC File Offset: 0x0001CDDC
public void SendChangeCipherSpec()
{
this.SendRecord(ContentType.ChangeCipherSpec, new byte[] { 1 });
Context context = this.context;
context.WriteSequenceNumber = 0UL;
if (context is ClientContext)
{
context.StartSwitchingSecurityParameters(true);
}
else
{
context.EndSwitchingSecurityParameters(false);
}
}
// Token: 0x06000538 RID: 1336 RVA: 0x0001EC28 File Offset: 0x0001CE28
public IAsyncResult BeginSendRecord(HandshakeType handshakeType, AsyncCallback callback, object state)
{
HandshakeMessage message = this.GetMessage(handshakeType);
message.Process();
RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = new RecordProtocol.SendRecordAsyncResult(callback, state, message);
this.BeginSendRecord(message.ContentType, message.EncodeMessage(), new AsyncCallback(this.InternalSendRecordCallback), sendRecordAsyncResult);
return sendRecordAsyncResult;
}
// Token: 0x06000539 RID: 1337 RVA: 0x0001EC70 File Offset: 0x0001CE70
private void InternalSendRecordCallback(IAsyncResult ar)
{
RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = ar.AsyncState as RecordProtocol.SendRecordAsyncResult;
try
{
this.EndSendRecord(ar);
sendRecordAsyncResult.Message.Update();
sendRecordAsyncResult.Message.Reset();
sendRecordAsyncResult.SetComplete();
}
catch (Exception ex)
{
sendRecordAsyncResult.SetComplete(ex);
}
}
// Token: 0x0600053A RID: 1338 RVA: 0x0001ECDC File Offset: 0x0001CEDC
public IAsyncResult BeginSendRecord(ContentType contentType, byte[] recordData, AsyncCallback callback, object state)
{
if (this.context.SentConnectionEnd)
{
throw new TlsException(AlertDescription.InternalError, "The session is finished and it's no longer valid.");
}
byte[] array = this.EncodeRecord(contentType, recordData);
return this.innerStream.BeginWrite(array, 0, array.Length, callback, state);
}
// Token: 0x0600053B RID: 1339 RVA: 0x0001ED24 File Offset: 0x0001CF24
public void EndSendRecord(IAsyncResult asyncResult)
{
if (asyncResult is RecordProtocol.SendRecordAsyncResult)
{
RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = asyncResult as RecordProtocol.SendRecordAsyncResult;
if (!sendRecordAsyncResult.IsCompleted)
{
sendRecordAsyncResult.AsyncWaitHandle.WaitOne();
}
if (sendRecordAsyncResult.CompletedWithError)
{
throw sendRecordAsyncResult.AsyncException;
}
}
else
{
this.innerStream.EndWrite(asyncResult);
}
}
// Token: 0x0600053C RID: 1340 RVA: 0x0001ED80 File Offset: 0x0001CF80
public void SendRecord(ContentType contentType, byte[] recordData)
{
IAsyncResult asyncResult = this.BeginSendRecord(contentType, recordData, null, null);
this.EndSendRecord(asyncResult);
}
// Token: 0x0600053D RID: 1341 RVA: 0x0001EDA0 File Offset: 0x0001CFA0
public byte[] EncodeRecord(ContentType contentType, byte[] recordData)
{
return this.EncodeRecord(contentType, recordData, 0, recordData.Length);
}
// Token: 0x0600053E RID: 1342 RVA: 0x0001EDB0 File Offset: 0x0001CFB0
public byte[] EncodeRecord(ContentType contentType, byte[] recordData, int offset, int count)
{
if (this.context.SentConnectionEnd)
{
throw new TlsException(AlertDescription.InternalError, "The session is finished and it's no longer valid.");
}
TlsStream tlsStream = new TlsStream();
short num;
for (int i = offset; i < offset + count; i += (int)num)
{
if (count + offset - i > 16384)
{
num = 16384;
}
else
{
num = (short)(count + offset - i);
}
byte[] array = new byte[(int)num];
Buffer.BlockCopy(recordData, i, array, 0, (int)num);
if (this.Context.Write != null && this.Context.Write.Cipher != null)
{
array = this.encryptRecordFragment(contentType, array);
}
tlsStream.Write((byte)contentType);
tlsStream.Write(this.context.Protocol);
tlsStream.Write((short)array.Length);
tlsStream.Write(array);
}
return tlsStream.ToArray();
}
// Token: 0x0600053F RID: 1343 RVA: 0x0001EE88 File Offset: 0x0001D088
private byte[] encryptRecordFragment(ContentType contentType, byte[] fragment)
{
byte[] array;
if (this.Context is ClientContext)
{
array = this.context.Write.Cipher.ComputeClientRecordMAC(contentType, fragment);
}
else
{
array = this.context.Write.Cipher.ComputeServerRecordMAC(contentType, fragment);
}
byte[] array2 = this.context.Write.Cipher.EncryptRecord(fragment, array);
this.context.WriteSequenceNumber += 1UL;
return array2;
}
// Token: 0x06000540 RID: 1344 RVA: 0x0001EF0C File Offset: 0x0001D10C
private byte[] decryptRecordFragment(ContentType contentType, byte[] fragment)
{
byte[] array = null;
byte[] array2 = null;
try
{
this.context.Read.Cipher.DecryptRecord(fragment, out array, out array2);
}
catch
{
if (this.context is ServerContext)
{
this.Context.RecordProtocol.SendAlert(AlertDescription.DecryptionFailed);
}
throw;
}
byte[] array3;
if (this.Context is ClientContext)
{
array3 = this.context.Read.Cipher.ComputeServerRecordMAC(contentType, array);
}
else
{
array3 = this.context.Read.Cipher.ComputeClientRecordMAC(contentType, array);
}
if (!this.Compare(array3, array2))
{
throw new TlsException(AlertDescription.BadRecordMAC, "Bad record MAC");
}
this.context.ReadSequenceNumber += 1UL;
return array;
}
// Token: 0x06000541 RID: 1345 RVA: 0x0001EFF8 File Offset: 0x0001D1F8
private bool Compare(byte[] array1, byte[] array2)
{
if (array1 == null)
{
return array2 == null;
}
if (array2 == null)
{
return false;
}
if (array1.Length != array2.Length)
{
return false;
}
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
{
return false;
}
}
return true;
}
// Token: 0x06000542 RID: 1346 RVA: 0x0001F048 File Offset: 0x0001D248
private void ProcessCipherSpecV2Buffer(SecurityProtocolType protocol, byte[] buffer)
{
TlsStream tlsStream = new TlsStream(buffer);
string text = ((protocol != SecurityProtocolType.Ssl3) ? "TLS_" : "SSL_");
while (tlsStream.Position < tlsStream.Length)
{
byte b = tlsStream.ReadByte();
if (b == 0)
{
short num = tlsStream.ReadInt16();
int num2 = this.Context.SupportedCiphers.IndexOf(num);
if (num2 != -1)
{
this.Context.Negotiating.Cipher = this.Context.SupportedCiphers[num2];
break;
}
}
else
{
byte[] array = new byte[2];
tlsStream.Read(array, 0, array.Length);
int num3 = ((int)(b & byte.MaxValue) << 16) | ((int)(array[0] & byte.MaxValue) << 8) | (int)(array[1] & byte.MaxValue);
CipherSuite cipherSuite = this.MapV2CipherCode(text, num3);
if (cipherSuite != null)
{
this.Context.Negotiating.Cipher = cipherSuite;
break;
}
}
}
if (this.Context.Negotiating == null)
{
throw new TlsException(AlertDescription.InsuficientSecurity, "Insuficient Security");
}
}
// Token: 0x06000543 RID: 1347 RVA: 0x0001F168 File Offset: 0x0001D368
private CipherSuite MapV2CipherCode(string prefix, int code)
{
CipherSuite cipherSuite;
try
{
if (code != 65664)
{
if (code != 131200)
{
if (code != 196736)
{
if (code != 262272)
{
if (code != 327808)
{
if (code != 393280)
{
if (code != 458944)
{
cipherSuite = null;
}
else
{
cipherSuite = null;
}
}
else
{
cipherSuite = null;
}
}
else
{
cipherSuite = null;
}
}
else
{
cipherSuite = this.Context.SupportedCiphers[prefix + "RSA_EXPORT_WITH_RC2_CBC_40_MD5"];
}
}
else
{
cipherSuite = this.Context.SupportedCiphers[prefix + "RSA_EXPORT_WITH_RC2_CBC_40_MD5"];
}
}
else
{
cipherSuite = this.Context.SupportedCiphers[prefix + "RSA_EXPORT_WITH_RC4_40_MD5"];
}
}
else
{
cipherSuite = this.Context.SupportedCiphers[prefix + "RSA_WITH_RC4_128_MD5"];
}
}
catch
{
cipherSuite = null;
}
return cipherSuite;
}
// Token: 0x04000298 RID: 664
private static ManualResetEvent record_processing = new ManualResetEvent(true);
// Token: 0x04000299 RID: 665
protected Stream innerStream;
// Token: 0x0400029A RID: 666
protected Context context;
// Token: 0x0200008F RID: 143
private class ReceiveRecordAsyncResult : IAsyncResult
{
// Token: 0x06000544 RID: 1348 RVA: 0x0001F298 File Offset: 0x0001D498
public ReceiveRecordAsyncResult(AsyncCallback userCallback, object userState, byte[] initialBuffer, Stream record)
{
this._userCallback = userCallback;
this._userState = userState;
this._initialBuffer = initialBuffer;
this._record = record;
}
// Token: 0x1700014C RID: 332
// (get) Token: 0x06000545 RID: 1349 RVA: 0x0001F2D4 File Offset: 0x0001D4D4
public Stream Record
{
get
{
return this._record;
}
}
// Token: 0x1700014D RID: 333
// (get) Token: 0x06000546 RID: 1350 RVA: 0x0001F2DC File Offset: 0x0001D4DC
public byte[] ResultingBuffer
{
get
{
return this._resultingBuffer;
}
}
// Token: 0x1700014E RID: 334
// (get) Token: 0x06000547 RID: 1351 RVA: 0x0001F2E4 File Offset: 0x0001D4E4
public byte[] InitialBuffer
{
get
{
return this._initialBuffer;
}
}
// Token: 0x1700014F RID: 335
// (get) Token: 0x06000548 RID: 1352 RVA: 0x0001F2EC File Offset: 0x0001D4EC
public object AsyncState
{
get
{
return this._userState;
}
}
// Token: 0x17000150 RID: 336
// (get) Token: 0x06000549 RID: 1353 RVA: 0x0001F2F4 File Offset: 0x0001D4F4
public Exception AsyncException
{
get
{
return this._asyncException;
}
}
// Token: 0x17000151 RID: 337
// (get) Token: 0x0600054A RID: 1354 RVA: 0x0001F2FC File Offset: 0x0001D4FC
public bool CompletedWithError
{
get
{
return this.IsCompleted && null != this._asyncException;
}
}
// Token: 0x17000152 RID: 338
// (get) Token: 0x0600054B RID: 1355 RVA: 0x0001F318 File Offset: 0x0001D518
public WaitHandle AsyncWaitHandle
{
get
{
object obj = this.locker;
lock (obj)
{
if (this.handle == null)
{
this.handle = new ManualResetEvent(this.completed);
}
}
return this.handle;
}
}
// Token: 0x17000153 RID: 339
// (get) Token: 0x0600054C RID: 1356 RVA: 0x0001F37C File Offset: 0x0001D57C
public bool CompletedSynchronously
{
get
{
return false;
}
}
// Token: 0x17000154 RID: 340
// (get) Token: 0x0600054D RID: 1357 RVA: 0x0001F380 File Offset: 0x0001D580
public bool IsCompleted
{
get
{
object obj = this.locker;
bool flag;
lock (obj)
{
flag = this.completed;
}
return flag;
}
}
// Token: 0x0600054E RID: 1358 RVA: 0x0001F3D0 File Offset: 0x0001D5D0
private void SetComplete(Exception ex, byte[] resultingBuffer)
{
object obj = this.locker;
lock (obj)
{
if (!this.completed)
{
this.completed = true;
this._asyncException = ex;
this._resultingBuffer = resultingBuffer;
if (this.handle != null)
{
this.handle.Set();
}
if (this._userCallback != null)
{
this._userCallback.BeginInvoke(this, null, null);
}
}
}
}
// Token: 0x0600054F RID: 1359 RVA: 0x0001F468 File Offset: 0x0001D668
public void SetComplete(Exception ex)
{
this.SetComplete(ex, null);
}
// Token: 0x06000550 RID: 1360 RVA: 0x0001F474 File Offset: 0x0001D674
public void SetComplete(byte[] resultingBuffer)
{
this.SetComplete(null, resultingBuffer);
}
// Token: 0x06000551 RID: 1361 RVA: 0x0001F480 File Offset: 0x0001D680
public void SetComplete()
{
this.SetComplete(null, null);
}
// Token: 0x0400029B RID: 667
private object locker = new object();
// Token: 0x0400029C RID: 668
private AsyncCallback _userCallback;
// Token: 0x0400029D RID: 669
private object _userState;
// Token: 0x0400029E RID: 670
private Exception _asyncException;
// Token: 0x0400029F RID: 671
private ManualResetEvent handle;
// Token: 0x040002A0 RID: 672
private byte[] _resultingBuffer;
// Token: 0x040002A1 RID: 673
private Stream _record;
// Token: 0x040002A2 RID: 674
private bool completed;
// Token: 0x040002A3 RID: 675
private byte[] _initialBuffer;
}
// Token: 0x02000090 RID: 144
private class SendRecordAsyncResult : IAsyncResult
{
// Token: 0x06000552 RID: 1362 RVA: 0x0001F48C File Offset: 0x0001D68C
public SendRecordAsyncResult(AsyncCallback userCallback, object userState, HandshakeMessage message)
{
this._userCallback = userCallback;
this._userState = userState;
this._message = message;
}
// Token: 0x17000155 RID: 341
// (get) Token: 0x06000553 RID: 1363 RVA: 0x0001F4C0 File Offset: 0x0001D6C0
public HandshakeMessage Message
{
get
{
return this._message;
}
}
// Token: 0x17000156 RID: 342
// (get) Token: 0x06000554 RID: 1364 RVA: 0x0001F4C8 File Offset: 0x0001D6C8
public object AsyncState
{
get
{
return this._userState;
}
}
// Token: 0x17000157 RID: 343
// (get) Token: 0x06000555 RID: 1365 RVA: 0x0001F4D0 File Offset: 0x0001D6D0
public Exception AsyncException
{
get
{
return this._asyncException;
}
}
// Token: 0x17000158 RID: 344
// (get) Token: 0x06000556 RID: 1366 RVA: 0x0001F4D8 File Offset: 0x0001D6D8
public bool CompletedWithError
{
get
{
return this.IsCompleted && null != this._asyncException;
}
}
// Token: 0x17000159 RID: 345
// (get) Token: 0x06000557 RID: 1367 RVA: 0x0001F4F4 File Offset: 0x0001D6F4
public WaitHandle AsyncWaitHandle
{
get
{
object obj = this.locker;
lock (obj)
{
if (this.handle == null)
{
this.handle = new ManualResetEvent(this.completed);
}
}
return this.handle;
}
}
// Token: 0x1700015A RID: 346
// (get) Token: 0x06000558 RID: 1368 RVA: 0x0001F558 File Offset: 0x0001D758
public bool CompletedSynchronously
{
get
{
return false;
}
}
// Token: 0x1700015B RID: 347
// (get) Token: 0x06000559 RID: 1369 RVA: 0x0001F55C File Offset: 0x0001D75C
public bool IsCompleted
{
get
{
object obj = this.locker;
bool flag;
lock (obj)
{
flag = this.completed;
}
return flag;
}
}
// Token: 0x0600055A RID: 1370 RVA: 0x0001F5AC File Offset: 0x0001D7AC
public void SetComplete(Exception ex)
{
object obj = this.locker;
lock (obj)
{
if (!this.completed)
{
this.completed = true;
if (this.handle != null)
{
this.handle.Set();
}
if (this._userCallback != null)
{
this._userCallback.BeginInvoke(this, null, null);
}
this._asyncException = ex;
}
}
}
// Token: 0x0600055B RID: 1371 RVA: 0x0001F640 File Offset: 0x0001D840
public void SetComplete()
{
this.SetComplete(null);
}
// Token: 0x040002A4 RID: 676
private object locker = new object();
// Token: 0x040002A5 RID: 677
private AsyncCallback _userCallback;
// Token: 0x040002A6 RID: 678
private object _userState;
// Token: 0x040002A7 RID: 679
private Exception _asyncException;
// Token: 0x040002A8 RID: 680
private ManualResetEvent handle;
// Token: 0x040002A9 RID: 681
private HandshakeMessage _message;
// Token: 0x040002AA RID: 682
private bool completed;
}
}
}

Some files were not shown because too many files have changed in this diff Show More