scripts
This commit is contained in:
@@ -0,0 +1,389 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000DA RID: 218
|
||||
internal class ASN1
|
||||
{
|
||||
// Token: 0x06000ADA RID: 2778 RVA: 0x0002FF08 File Offset: 0x0002E108
|
||||
public ASN1()
|
||||
: this(0, null)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000ADB RID: 2779 RVA: 0x0002FF14 File Offset: 0x0002E114
|
||||
public ASN1(byte tag)
|
||||
: this(tag, null)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000ADC RID: 2780 RVA: 0x0002FF20 File Offset: 0x0002E120
|
||||
public ASN1(byte tag, byte[] data)
|
||||
{
|
||||
this.m_nTag = tag;
|
||||
this.m_aValue = data;
|
||||
}
|
||||
|
||||
// Token: 0x06000ADD RID: 2781 RVA: 0x0002FF38 File Offset: 0x0002E138
|
||||
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: 0x1700016E RID: 366
|
||||
// (get) Token: 0x06000ADE RID: 2782 RVA: 0x0002FFEC File Offset: 0x0002E1EC
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.elist == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this.elist.Count;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700016F RID: 367
|
||||
// (get) Token: 0x06000ADF RID: 2783 RVA: 0x00030008 File Offset: 0x0002E208
|
||||
public byte Tag
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_nTag;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000170 RID: 368
|
||||
// (get) Token: 0x06000AE0 RID: 2784 RVA: 0x00030010 File Offset: 0x0002E210
|
||||
public int Length
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.m_aValue != null)
|
||||
{
|
||||
return this.m_aValue.Length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000171 RID: 369
|
||||
// (get) Token: 0x06000AE1 RID: 2785 RVA: 0x00030028 File Offset: 0x0002E228
|
||||
// (set) Token: 0x06000AE2 RID: 2786 RVA: 0x00030058 File Offset: 0x0002E258
|
||||
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: 0x06000AE3 RID: 2787 RVA: 0x00030074 File Offset: 0x0002E274
|
||||
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: 0x06000AE4 RID: 2788 RVA: 0x000300B4 File Offset: 0x0002E2B4
|
||||
public bool Equals(byte[] asn1)
|
||||
{
|
||||
return this.CompareArray(this.GetBytes(), asn1);
|
||||
}
|
||||
|
||||
// Token: 0x06000AE5 RID: 2789 RVA: 0x000300C4 File Offset: 0x0002E2C4
|
||||
public bool CompareValue(byte[] value)
|
||||
{
|
||||
return this.CompareArray(this.m_aValue, value);
|
||||
}
|
||||
|
||||
// Token: 0x06000AE6 RID: 2790 RVA: 0x000300D4 File Offset: 0x0002E2D4
|
||||
public ASN1 Add(ASN1 asn1)
|
||||
{
|
||||
if (asn1 != null)
|
||||
{
|
||||
if (this.elist == null)
|
||||
{
|
||||
this.elist = new ArrayList();
|
||||
}
|
||||
this.elist.Add(asn1);
|
||||
}
|
||||
return asn1;
|
||||
}
|
||||
|
||||
// Token: 0x06000AE7 RID: 2791 RVA: 0x0003010C File Offset: 0x0002E30C
|
||||
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: 0x06000AE8 RID: 2792 RVA: 0x0003037C File Offset: 0x0002E57C
|
||||
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: 0x06000AE9 RID: 2793 RVA: 0x000303E4 File Offset: 0x0002E5E4
|
||||
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: 0x17000172 RID: 370
|
||||
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: 0x06000AEB RID: 2795 RVA: 0x000304E8 File Offset: 0x0002E6E8
|
||||
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: 0x06000AEC RID: 2796 RVA: 0x00030574 File Offset: 0x0002E774
|
||||
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: 0x06000AED RID: 2797 RVA: 0x0003063C File Offset: 0x0002E83C
|
||||
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: 0x040002D4 RID: 724
|
||||
private byte m_nTag;
|
||||
|
||||
// Token: 0x040002D5 RID: 725
|
||||
private byte[] m_aValue;
|
||||
|
||||
// Token: 0x040002D6 RID: 726
|
||||
private ArrayList elist;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000DB RID: 219
|
||||
internal static class ASN1Convert
|
||||
{
|
||||
// Token: 0x06000AEE RID: 2798 RVA: 0x000306A4 File Offset: 0x0002E8A4
|
||||
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: 0x06000AEF RID: 2799 RVA: 0x0003072C File Offset: 0x0002E92C
|
||||
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: 0x06000AF0 RID: 2800 RVA: 0x000307C0 File Offset: 0x0002E9C0
|
||||
public static ASN1 FromOid(string oid)
|
||||
{
|
||||
if (oid == null)
|
||||
{
|
||||
throw new ArgumentNullException("oid");
|
||||
}
|
||||
return new ASN1(CryptoConfig.EncodeOID(oid));
|
||||
}
|
||||
|
||||
// Token: 0x06000AF1 RID: 2801 RVA: 0x000307E0 File Offset: 0x0002E9E0
|
||||
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: 0x06000AF2 RID: 2802 RVA: 0x00030830 File Offset: 0x0002EA30
|
||||
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: 0x06000AF3 RID: 2803 RVA: 0x00030890 File Offset: 0x0002EA90
|
||||
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: 0x06000AF4 RID: 2804 RVA: 0x00030978 File Offset: 0x0002EB78
|
||||
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,278 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Authenticode
|
||||
{
|
||||
// Token: 0x0200009F RID: 159
|
||||
internal class AuthenticodeBase
|
||||
{
|
||||
// Token: 0x060008B2 RID: 2226 RVA: 0x00020E80 File Offset: 0x0001F080
|
||||
public AuthenticodeBase()
|
||||
{
|
||||
this.fileblock = new byte[4096];
|
||||
}
|
||||
|
||||
// Token: 0x170000E7 RID: 231
|
||||
// (get) Token: 0x060008B3 RID: 2227 RVA: 0x00020E98 File Offset: 0x0001F098
|
||||
internal int PEOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.blockNo < 1)
|
||||
{
|
||||
this.ReadFirstBlock();
|
||||
}
|
||||
return this.peOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000E8 RID: 232
|
||||
// (get) Token: 0x060008B4 RID: 2228 RVA: 0x00020EB4 File Offset: 0x0001F0B4
|
||||
internal int CoffSymbolTableOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.blockNo < 1)
|
||||
{
|
||||
this.ReadFirstBlock();
|
||||
}
|
||||
return this.coffSymbolTableOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000E9 RID: 233
|
||||
// (get) Token: 0x060008B5 RID: 2229 RVA: 0x00020ED0 File Offset: 0x0001F0D0
|
||||
internal int SecurityOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.blockNo < 1)
|
||||
{
|
||||
this.ReadFirstBlock();
|
||||
}
|
||||
return this.dirSecurityOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008B6 RID: 2230 RVA: 0x00020EEC File Offset: 0x0001F0EC
|
||||
internal void Open(string filename)
|
||||
{
|
||||
if (this.fs != null)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
this.fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
}
|
||||
|
||||
// Token: 0x060008B7 RID: 2231 RVA: 0x00020F1C File Offset: 0x0001F11C
|
||||
internal void Close()
|
||||
{
|
||||
if (this.fs != null)
|
||||
{
|
||||
this.fs.Close();
|
||||
this.fs = null;
|
||||
this.blockNo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008B8 RID: 2232 RVA: 0x00020F50 File Offset: 0x0001F150
|
||||
internal bool ReadFirstBlock()
|
||||
{
|
||||
if (this.fs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.fs.Position = 0L;
|
||||
this.blockLength = this.fs.Read(this.fileblock, 0, this.fileblock.Length);
|
||||
this.blockNo = 1;
|
||||
if (this.blockLength < 64)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (BitConverterLE.ToUInt16(this.fileblock, 0) != 23117)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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 false;
|
||||
}
|
||||
if (BitConverterLE.ToUInt32(this.fileblock, this.peOffset) != 17744U)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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 true;
|
||||
}
|
||||
|
||||
// Token: 0x060008B9 RID: 2233 RVA: 0x0002109C File Offset: 0x0001F29C
|
||||
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: 0x060008BA RID: 2234 RVA: 0x00021100 File Offset: 0x0001F300
|
||||
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: 0x060008BB RID: 2235 RVA: 0x000213C4 File Offset: 0x0001F5C4
|
||||
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: 0x040001C2 RID: 450
|
||||
public const string spcIndirectDataContext = "1.3.6.1.4.1.311.2.1.4";
|
||||
|
||||
// Token: 0x040001C3 RID: 451
|
||||
private byte[] fileblock;
|
||||
|
||||
// Token: 0x040001C4 RID: 452
|
||||
private FileStream fs;
|
||||
|
||||
// Token: 0x040001C5 RID: 453
|
||||
private int blockNo;
|
||||
|
||||
// Token: 0x040001C6 RID: 454
|
||||
private int blockLength;
|
||||
|
||||
// Token: 0x040001C7 RID: 455
|
||||
private int peOffset;
|
||||
|
||||
// Token: 0x040001C8 RID: 456
|
||||
private int dirSecurityOffset;
|
||||
|
||||
// Token: 0x040001C9 RID: 457
|
||||
private int dirSecuritySize;
|
||||
|
||||
// Token: 0x040001CA RID: 458
|
||||
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: 0x020000A0 RID: 160
|
||||
internal class AuthenticodeDeformatter : AuthenticodeBase
|
||||
{
|
||||
// Token: 0x060008BC RID: 2236 RVA: 0x00021424 File Offset: 0x0001F624
|
||||
public AuthenticodeDeformatter()
|
||||
{
|
||||
this.reason = -1;
|
||||
this.signerChain = new X509Chain();
|
||||
this.timestampChain = new X509Chain();
|
||||
}
|
||||
|
||||
// Token: 0x060008BD RID: 2237 RVA: 0x0002144C File Offset: 0x0001F64C
|
||||
public AuthenticodeDeformatter(string fileName)
|
||||
: this()
|
||||
{
|
||||
this.FileName = fileName;
|
||||
}
|
||||
|
||||
// Token: 0x170000EA RID: 234
|
||||
// (get) Token: 0x060008BE RID: 2238 RVA: 0x0002145C File Offset: 0x0001F65C
|
||||
// (set) Token: 0x060008BF RID: 2239 RVA: 0x00021464 File Offset: 0x0001F664
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.filename;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Reset();
|
||||
try
|
||||
{
|
||||
this.CheckSignature(value);
|
||||
}
|
||||
catch (SecurityException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.reason = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000EB RID: 235
|
||||
// (get) Token: 0x060008C0 RID: 2240 RVA: 0x000214D0 File Offset: 0x0001F6D0
|
||||
public byte[] Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.signedHash == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.signedHash.Value.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000EC RID: 236
|
||||
// (get) Token: 0x060008C1 RID: 2241 RVA: 0x00021500 File Offset: 0x0001F700
|
||||
public int Reason
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.reason == -1)
|
||||
{
|
||||
this.IsTrusted();
|
||||
}
|
||||
return this.reason;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008C2 RID: 2242 RVA: 0x0002151C File Offset: 0x0001F71C
|
||||
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: 0x170000ED RID: 237
|
||||
// (get) Token: 0x060008C3 RID: 2243 RVA: 0x00021600 File Offset: 0x0001F800
|
||||
public byte[] Signature
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.entry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.entry.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000EE RID: 238
|
||||
// (get) Token: 0x060008C4 RID: 2244 RVA: 0x00021620 File Offset: 0x0001F820
|
||||
public DateTime Timestamp
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000EF RID: 239
|
||||
// (get) Token: 0x060008C5 RID: 2245 RVA: 0x00021628 File Offset: 0x0001F828
|
||||
public X509CertificateCollection Certificates
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.coll;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F0 RID: 240
|
||||
// (get) Token: 0x060008C6 RID: 2246 RVA: 0x00021630 File Offset: 0x0001F830
|
||||
public X509Certificate SigningCertificate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.signingCertificate;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008C7 RID: 2247 RVA: 0x00021638 File Offset: 0x0001F838
|
||||
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: 0x060008C8 RID: 2248 RVA: 0x000217D8 File Offset: 0x0001F9D8
|
||||
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: 0x060008C9 RID: 2249 RVA: 0x0002183C File Offset: 0x0001FA3C
|
||||
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$map6 == null)
|
||||
{
|
||||
AuthenticodeDeformatter.<>f__switch$map6 = new Dictionary<string, int>(1) { { "1.2.840.113549.1.9.6", 0 } };
|
||||
}
|
||||
int num;
|
||||
if (AuthenticodeDeformatter.<>f__switch$map6.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: 0x060008CA RID: 2250 RVA: 0x00021C0C File Offset: 0x0001FE0C
|
||||
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: 0x060008CB RID: 2251 RVA: 0x00021F18 File Offset: 0x00020118
|
||||
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: 0x040001CB RID: 459
|
||||
private string filename;
|
||||
|
||||
// Token: 0x040001CC RID: 460
|
||||
private byte[] hash;
|
||||
|
||||
// Token: 0x040001CD RID: 461
|
||||
private X509CertificateCollection coll;
|
||||
|
||||
// Token: 0x040001CE RID: 462
|
||||
private ASN1 signedHash;
|
||||
|
||||
// Token: 0x040001CF RID: 463
|
||||
private DateTime timestamp;
|
||||
|
||||
// Token: 0x040001D0 RID: 464
|
||||
private X509Certificate signingCertificate;
|
||||
|
||||
// Token: 0x040001D1 RID: 465
|
||||
private int reason;
|
||||
|
||||
// Token: 0x040001D2 RID: 466
|
||||
private bool trustedRoot;
|
||||
|
||||
// Token: 0x040001D3 RID: 467
|
||||
private bool trustedTimestampRoot;
|
||||
|
||||
// Token: 0x040001D4 RID: 468
|
||||
private byte[] entry;
|
||||
|
||||
// Token: 0x040001D5 RID: 469
|
||||
private X509Chain signerChain;
|
||||
|
||||
// Token: 0x040001D6 RID: 470
|
||||
private X509Chain timestampChain;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Authenticode
|
||||
{
|
||||
// Token: 0x0200009E RID: 158
|
||||
internal enum Authority
|
||||
{
|
||||
// Token: 0x040001BF RID: 447
|
||||
Individual,
|
||||
// Token: 0x040001C0 RID: 448
|
||||
Commercial,
|
||||
// Token: 0x040001C1 RID: 449
|
||||
Maximum
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000DC RID: 220
|
||||
internal sealed class BitConverterLE
|
||||
{
|
||||
// Token: 0x06000AF5 RID: 2805 RVA: 0x00030B00 File Offset: 0x0002ED00
|
||||
private BitConverterLE()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000AF6 RID: 2806 RVA: 0x00030B08 File Offset: 0x0002ED08
|
||||
private unsafe static byte[] GetUShortBytes(byte* bytes)
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
return new byte[]
|
||||
{
|
||||
*bytes,
|
||||
bytes[1]
|
||||
};
|
||||
}
|
||||
return new byte[]
|
||||
{
|
||||
bytes[1],
|
||||
*bytes
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x06000AF7 RID: 2807 RVA: 0x00030B3C File Offset: 0x0002ED3C
|
||||
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: 0x06000AF8 RID: 2808 RVA: 0x00030B94 File Offset: 0x0002ED94
|
||||
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: 0x06000AF9 RID: 2809 RVA: 0x00030C24 File Offset: 0x0002EE24
|
||||
internal static byte[] GetBytes(bool value)
|
||||
{
|
||||
return new byte[] { (!value) ? 0 : 1 };
|
||||
}
|
||||
|
||||
// Token: 0x06000AFA RID: 2810 RVA: 0x00030C3C File Offset: 0x0002EE3C
|
||||
internal unsafe static byte[] GetBytes(char value)
|
||||
{
|
||||
return BitConverterLE.GetUShortBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000AFB RID: 2811 RVA: 0x00030C48 File Offset: 0x0002EE48
|
||||
internal unsafe static byte[] GetBytes(short value)
|
||||
{
|
||||
return BitConverterLE.GetUShortBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000AFC RID: 2812 RVA: 0x00030C54 File Offset: 0x0002EE54
|
||||
internal unsafe static byte[] GetBytes(int value)
|
||||
{
|
||||
return BitConverterLE.GetUIntBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000AFD RID: 2813 RVA: 0x00030C60 File Offset: 0x0002EE60
|
||||
internal unsafe static byte[] GetBytes(long value)
|
||||
{
|
||||
return BitConverterLE.GetULongBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000AFE RID: 2814 RVA: 0x00030C6C File Offset: 0x0002EE6C
|
||||
internal unsafe static byte[] GetBytes(ushort value)
|
||||
{
|
||||
return BitConverterLE.GetUShortBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000AFF RID: 2815 RVA: 0x00030C78 File Offset: 0x0002EE78
|
||||
internal unsafe static byte[] GetBytes(uint value)
|
||||
{
|
||||
return BitConverterLE.GetUIntBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000B00 RID: 2816 RVA: 0x00030C84 File Offset: 0x0002EE84
|
||||
internal unsafe static byte[] GetBytes(ulong value)
|
||||
{
|
||||
return BitConverterLE.GetULongBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000B01 RID: 2817 RVA: 0x00030C90 File Offset: 0x0002EE90
|
||||
internal unsafe static byte[] GetBytes(float value)
|
||||
{
|
||||
return BitConverterLE.GetUIntBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000B02 RID: 2818 RVA: 0x00030C9C File Offset: 0x0002EE9C
|
||||
internal unsafe static byte[] GetBytes(double value)
|
||||
{
|
||||
return BitConverterLE.GetULongBytes((byte*)(&value));
|
||||
}
|
||||
|
||||
// Token: 0x06000B03 RID: 2819 RVA: 0x00030CA8 File Offset: 0x0002EEA8
|
||||
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: 0x06000B04 RID: 2820 RVA: 0x00030CD8 File Offset: 0x0002EED8
|
||||
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: 0x06000B05 RID: 2821 RVA: 0x00030D34 File Offset: 0x0002EF34
|
||||
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: 0x06000B06 RID: 2822 RVA: 0x00030D88 File Offset: 0x0002EF88
|
||||
internal static bool ToBoolean(byte[] value, int startIndex)
|
||||
{
|
||||
return value[startIndex] != 0;
|
||||
}
|
||||
|
||||
// Token: 0x06000B07 RID: 2823 RVA: 0x00030D94 File Offset: 0x0002EF94
|
||||
internal unsafe static char ToChar(byte[] value, int startIndex)
|
||||
{
|
||||
char c;
|
||||
BitConverterLE.UShortFromBytes((byte*)(&c), value, startIndex);
|
||||
return c;
|
||||
}
|
||||
|
||||
// Token: 0x06000B08 RID: 2824 RVA: 0x00030DAC File Offset: 0x0002EFAC
|
||||
internal unsafe static short ToInt16(byte[] value, int startIndex)
|
||||
{
|
||||
short num;
|
||||
BitConverterLE.UShortFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B09 RID: 2825 RVA: 0x00030DC4 File Offset: 0x0002EFC4
|
||||
internal unsafe static int ToInt32(byte[] value, int startIndex)
|
||||
{
|
||||
int num;
|
||||
BitConverterLE.UIntFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B0A RID: 2826 RVA: 0x00030DDC File Offset: 0x0002EFDC
|
||||
internal unsafe static long ToInt64(byte[] value, int startIndex)
|
||||
{
|
||||
long num;
|
||||
BitConverterLE.ULongFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B0B RID: 2827 RVA: 0x00030DF4 File Offset: 0x0002EFF4
|
||||
internal unsafe static ushort ToUInt16(byte[] value, int startIndex)
|
||||
{
|
||||
ushort num;
|
||||
BitConverterLE.UShortFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B0C RID: 2828 RVA: 0x00030E0C File Offset: 0x0002F00C
|
||||
internal unsafe static uint ToUInt32(byte[] value, int startIndex)
|
||||
{
|
||||
uint num;
|
||||
BitConverterLE.UIntFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B0D RID: 2829 RVA: 0x00030E24 File Offset: 0x0002F024
|
||||
internal unsafe static ulong ToUInt64(byte[] value, int startIndex)
|
||||
{
|
||||
ulong num;
|
||||
BitConverterLE.ULongFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B0E RID: 2830 RVA: 0x00030E3C File Offset: 0x0002F03C
|
||||
internal unsafe static float ToSingle(byte[] value, int startIndex)
|
||||
{
|
||||
float num;
|
||||
BitConverterLE.UIntFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x06000B0F RID: 2831 RVA: 0x00030E54 File Offset: 0x0002F054
|
||||
internal unsafe static double ToDouble(byte[] value, int startIndex)
|
||||
{
|
||||
double num;
|
||||
BitConverterLE.ULongFromBytes((byte*)(&num), value, startIndex);
|
||||
return num;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A3 RID: 163
|
||||
internal class BlockProcessor
|
||||
{
|
||||
// Token: 0x060008EB RID: 2283 RVA: 0x00023098 File Offset: 0x00021298
|
||||
public BlockProcessor(ICryptoTransform transform)
|
||||
: this(transform, transform.InputBlockSize)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060008EC RID: 2284 RVA: 0x000230A8 File Offset: 0x000212A8
|
||||
public BlockProcessor(ICryptoTransform transform, int blockSize)
|
||||
{
|
||||
this.transform = transform;
|
||||
this.blockSize = blockSize;
|
||||
this.block = new byte[blockSize];
|
||||
}
|
||||
|
||||
// Token: 0x060008ED RID: 2285 RVA: 0x000230D8 File Offset: 0x000212D8
|
||||
~BlockProcessor()
|
||||
{
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
}
|
||||
|
||||
// Token: 0x060008EE RID: 2286 RVA: 0x00023120 File Offset: 0x00021320
|
||||
public void Initialize()
|
||||
{
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
this.blockCount = 0;
|
||||
}
|
||||
|
||||
// Token: 0x060008EF RID: 2287 RVA: 0x0002313C File Offset: 0x0002133C
|
||||
public void Core(byte[] rgb)
|
||||
{
|
||||
this.Core(rgb, 0, rgb.Length);
|
||||
}
|
||||
|
||||
// Token: 0x060008F0 RID: 2288 RVA: 0x0002314C File Offset: 0x0002134C
|
||||
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: 0x060008F1 RID: 2289 RVA: 0x00023230 File Offset: 0x00021430
|
||||
public byte[] Final()
|
||||
{
|
||||
return this.transform.TransformFinalBlock(this.block, 0, this.blockCount);
|
||||
}
|
||||
|
||||
// Token: 0x040001DB RID: 475
|
||||
private ICryptoTransform transform;
|
||||
|
||||
// Token: 0x040001DC RID: 476
|
||||
private byte[] block;
|
||||
|
||||
// Token: 0x040001DD RID: 477
|
||||
private int blockSize;
|
||||
|
||||
// Token: 0x040001DE RID: 478
|
||||
private int blockCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,642 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A1 RID: 161
|
||||
internal sealed class CryptoConvert
|
||||
{
|
||||
// Token: 0x060008CC RID: 2252 RVA: 0x00021F80 File Offset: 0x00020180
|
||||
private CryptoConvert()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060008CD RID: 2253 RVA: 0x00021F88 File Offset: 0x00020188
|
||||
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: 0x060008CE RID: 2254 RVA: 0x00021FA8 File Offset: 0x000201A8
|
||||
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: 0x060008CF RID: 2255 RVA: 0x00021FC8 File Offset: 0x000201C8
|
||||
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: 0x060008D0 RID: 2256 RVA: 0x00022010 File Offset: 0x00020210
|
||||
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: 0x060008D1 RID: 2257 RVA: 0x00022054 File Offset: 0x00020254
|
||||
public static RSA FromCapiPrivateKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPrivateKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008D2 RID: 2258 RVA: 0x00022060 File Offset: 0x00020260
|
||||
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 = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
// Token: 0x060008D3 RID: 2259 RVA: 0x000222C4 File Offset: 0x000204C4
|
||||
public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPrivateKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008D4 RID: 2260 RVA: 0x000222D0 File Offset: 0x000204D0
|
||||
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 = DSA.Create();
|
||||
dsa.ImportParameters(dsaparameters);
|
||||
return dsa;
|
||||
}
|
||||
|
||||
// Token: 0x060008D5 RID: 2261 RVA: 0x000224A8 File Offset: 0x000206A8
|
||||
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: 0x060008D6 RID: 2262 RVA: 0x00022690 File Offset: 0x00020890
|
||||
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: 0x060008D7 RID: 2263 RVA: 0x000227DC File Offset: 0x000209DC
|
||||
public static RSA FromCapiPublicKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008D8 RID: 2264 RVA: 0x000227E8 File Offset: 0x000209E8
|
||||
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 = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
rsa2 = rsa;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob.", ex);
|
||||
}
|
||||
return rsa2;
|
||||
}
|
||||
|
||||
// Token: 0x060008D9 RID: 2265 RVA: 0x00022930 File Offset: 0x00020B30
|
||||
public static DSA FromCapiPublicKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008DA RID: 2266 RVA: 0x0002293C File Offset: 0x00020B3C
|
||||
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: 0x060008DB RID: 2267 RVA: 0x00022B18 File Offset: 0x00020D18
|
||||
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: 0x060008DC RID: 2268 RVA: 0x00022BF0 File Offset: 0x00020DF0
|
||||
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: 0x060008DD RID: 2269 RVA: 0x00022D38 File Offset: 0x00020F38
|
||||
public static RSA FromCapiKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008DE RID: 2270 RVA: 0x00022D44 File Offset: 0x00020F44
|
||||
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: 0x060008DF RID: 2271 RVA: 0x00022DCC File Offset: 0x00020FCC
|
||||
public static DSA FromCapiKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008E0 RID: 2272 RVA: 0x00022DD8 File Offset: 0x00020FD8
|
||||
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: 0x060008E1 RID: 2273 RVA: 0x00022E3C File Offset: 0x0002103C
|
||||
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: 0x060008E2 RID: 2274 RVA: 0x00022E8C File Offset: 0x0002108C
|
||||
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: 0x060008E3 RID: 2275 RVA: 0x00022EC0 File Offset: 0x000210C0
|
||||
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: 0x060008E4 RID: 2276 RVA: 0x00022EF4 File Offset: 0x000210F4
|
||||
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: 0x060008E5 RID: 2277 RVA: 0x00022F4C File Offset: 0x0002114C
|
||||
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: 0x060008E6 RID: 2278 RVA: 0x00022FAC File Offset: 0x000211AC
|
||||
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,509 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Math;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A4 RID: 164
|
||||
internal class DSAManaged : DSA
|
||||
{
|
||||
// Token: 0x060008F2 RID: 2290 RVA: 0x0002324C File Offset: 0x0002144C
|
||||
public DSAManaged()
|
||||
: this(1024)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060008F3 RID: 2291 RVA: 0x0002325C File Offset: 0x0002145C
|
||||
public DSAManaged(int dwKeySize)
|
||||
{
|
||||
this.KeySizeValue = dwKeySize;
|
||||
this.LegalKeySizesValue = new KeySizes[1];
|
||||
this.LegalKeySizesValue[0] = new KeySizes(512, 1024, 64);
|
||||
}
|
||||
|
||||
// Token: 0x14000001 RID: 1
|
||||
// (add) Token: 0x060008F4 RID: 2292 RVA: 0x0002329C File Offset: 0x0002149C
|
||||
// (remove) Token: 0x060008F5 RID: 2293 RVA: 0x000232B8 File Offset: 0x000214B8
|
||||
public event DSAManaged.KeyGeneratedEventHandler KeyGenerated;
|
||||
|
||||
// Token: 0x060008F6 RID: 2294 RVA: 0x000232D4 File Offset: 0x000214D4
|
||||
~DSAManaged()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x060008F7 RID: 2295 RVA: 0x00023310 File Offset: 0x00021510
|
||||
private void Generate()
|
||||
{
|
||||
this.GenerateParams(base.KeySize);
|
||||
this.GenerateKeyPair();
|
||||
this.keypairGenerated = true;
|
||||
if (this.KeyGenerated != null)
|
||||
{
|
||||
this.KeyGenerated(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008F8 RID: 2296 RVA: 0x00023350 File Offset: 0x00021550
|
||||
private void GenerateKeyPair()
|
||||
{
|
||||
this.x = BigInteger.GenerateRandom(160);
|
||||
while (this.x == 0U || this.x >= this.q)
|
||||
{
|
||||
this.x.Randomize();
|
||||
}
|
||||
this.y = this.g.ModPow(this.x, this.p);
|
||||
}
|
||||
|
||||
// Token: 0x060008F9 RID: 2297 RVA: 0x000233C4 File Offset: 0x000215C4
|
||||
private void add(byte[] a, byte[] b, int value)
|
||||
{
|
||||
uint num = (uint)((int)(b[b.Length - 1] & byte.MaxValue) + value);
|
||||
a[b.Length - 1] = (byte)num;
|
||||
num >>= 8;
|
||||
for (int i = b.Length - 2; i >= 0; i--)
|
||||
{
|
||||
num += (uint)(b[i] & byte.MaxValue);
|
||||
a[i] = (byte)num;
|
||||
num >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008FA RID: 2298 RVA: 0x0002341C File Offset: 0x0002161C
|
||||
private void GenerateParams(int keyLength)
|
||||
{
|
||||
byte[] array = new byte[20];
|
||||
byte[] array2 = new byte[20];
|
||||
byte[] array3 = new byte[20];
|
||||
byte[] array4 = new byte[20];
|
||||
SHA1 sha = SHA1.Create();
|
||||
int num = (keyLength - 1) / 160;
|
||||
byte[] array5 = new byte[keyLength / 8];
|
||||
bool flag = false;
|
||||
while (!flag)
|
||||
{
|
||||
do
|
||||
{
|
||||
this.Random.GetBytes(array);
|
||||
array2 = sha.ComputeHash(array);
|
||||
Array.Copy(array, 0, array3, 0, array.Length);
|
||||
this.add(array3, array, 1);
|
||||
array3 = sha.ComputeHash(array3);
|
||||
for (int num2 = 0; num2 != array4.Length; num2++)
|
||||
{
|
||||
array4[num2] = array2[num2] ^ array3[num2];
|
||||
}
|
||||
byte[] array6 = array4;
|
||||
int num3 = 0;
|
||||
array6[num3] |= 128;
|
||||
byte[] array7 = array4;
|
||||
int num4 = 19;
|
||||
array7[num4] |= 1;
|
||||
this.q = new BigInteger(array4);
|
||||
}
|
||||
while (!this.q.IsProbablePrime());
|
||||
this.counter = 0;
|
||||
int num5 = 2;
|
||||
while (this.counter < 4096)
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
this.add(array2, array, num5 + i);
|
||||
array2 = sha.ComputeHash(array2);
|
||||
Array.Copy(array2, 0, array5, array5.Length - (i + 1) * array2.Length, array2.Length);
|
||||
}
|
||||
this.add(array2, array, num5 + num);
|
||||
array2 = sha.ComputeHash(array2);
|
||||
Array.Copy(array2, array2.Length - (array5.Length - num * array2.Length), array5, 0, array5.Length - num * array2.Length);
|
||||
byte[] array8 = array5;
|
||||
int num6 = 0;
|
||||
array8[num6] |= 128;
|
||||
BigInteger bigInteger = new BigInteger(array5);
|
||||
BigInteger bigInteger2 = bigInteger % (this.q * 2);
|
||||
this.p = bigInteger - (bigInteger2 - 1);
|
||||
if (this.p.TestBit((uint)(keyLength - 1)) && this.p.IsProbablePrime())
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
this.counter++;
|
||||
num5 += num + 1;
|
||||
}
|
||||
}
|
||||
BigInteger bigInteger3 = (this.p - 1) / this.q;
|
||||
for (;;)
|
||||
{
|
||||
BigInteger bigInteger4 = BigInteger.GenerateRandom(keyLength);
|
||||
if (!(bigInteger4 <= 1) && !(bigInteger4 >= this.p - 1))
|
||||
{
|
||||
this.g = bigInteger4.ModPow(bigInteger3, this.p);
|
||||
if (!(this.g <= 1))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.seed = new BigInteger(array);
|
||||
this.j = (this.p - 1) / this.q;
|
||||
}
|
||||
|
||||
// Token: 0x170000F2 RID: 242
|
||||
// (get) Token: 0x060008FB RID: 2299 RVA: 0x000236FC File Offset: 0x000218FC
|
||||
private RandomNumberGenerator Random
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.rng == null)
|
||||
{
|
||||
this.rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
return this.rng;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F3 RID: 243
|
||||
// (get) Token: 0x060008FC RID: 2300 RVA: 0x0002371C File Offset: 0x0002191C
|
||||
public override int KeySize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.keypairGenerated)
|
||||
{
|
||||
return this.p.BitCount();
|
||||
}
|
||||
return base.KeySize;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F4 RID: 244
|
||||
// (get) Token: 0x060008FD RID: 2301 RVA: 0x0002373C File Offset: 0x0002193C
|
||||
public override string KeyExchangeAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F5 RID: 245
|
||||
// (get) Token: 0x060008FE RID: 2302 RVA: 0x00023740 File Offset: 0x00021940
|
||||
public bool PublicOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keypairGenerated && this.x == null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F6 RID: 246
|
||||
// (get) Token: 0x060008FF RID: 2303 RVA: 0x0002375C File Offset: 0x0002195C
|
||||
public override string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000900 RID: 2304 RVA: 0x00023764 File Offset: 0x00021964
|
||||
private byte[] NormalizeArray(byte[] array)
|
||||
{
|
||||
int num = array.Length % 4;
|
||||
if (num > 0)
|
||||
{
|
||||
byte[] array2 = new byte[array.Length + 4 - num];
|
||||
Array.Copy(array, 0, array2, 4 - num, array.Length);
|
||||
return array2;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000901 RID: 2305 RVA: 0x0002379C File Offset: 0x0002199C
|
||||
public override DSAParameters ExportParameters(bool includePrivateParameters)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.Generate();
|
||||
}
|
||||
if (includePrivateParameters && this.x == null)
|
||||
{
|
||||
throw new CryptographicException("no private key to export");
|
||||
}
|
||||
DSAParameters dsaparameters = default(DSAParameters);
|
||||
dsaparameters.P = this.NormalizeArray(this.p.GetBytes());
|
||||
dsaparameters.Q = this.NormalizeArray(this.q.GetBytes());
|
||||
dsaparameters.G = this.NormalizeArray(this.g.GetBytes());
|
||||
dsaparameters.Y = this.NormalizeArray(this.y.GetBytes());
|
||||
if (!this.j_missing)
|
||||
{
|
||||
dsaparameters.J = this.NormalizeArray(this.j.GetBytes());
|
||||
}
|
||||
if (this.seed != 0U)
|
||||
{
|
||||
dsaparameters.Seed = this.NormalizeArray(this.seed.GetBytes());
|
||||
dsaparameters.Counter = this.counter;
|
||||
}
|
||||
if (includePrivateParameters)
|
||||
{
|
||||
byte[] bytes = this.x.GetBytes();
|
||||
if (bytes.Length == 20)
|
||||
{
|
||||
dsaparameters.X = this.NormalizeArray(bytes);
|
||||
}
|
||||
}
|
||||
return dsaparameters;
|
||||
}
|
||||
|
||||
// Token: 0x06000902 RID: 2306 RVA: 0x000238E4 File Offset: 0x00021AE4
|
||||
public override void ImportParameters(DSAParameters parameters)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (parameters.P == null || parameters.Q == null || parameters.G == null)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing mandatory DSA parameters (P, Q or G)."));
|
||||
}
|
||||
if (parameters.X == null && parameters.Y == null)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing both public (Y) and private (X) keys."));
|
||||
}
|
||||
this.p = new BigInteger(parameters.P);
|
||||
this.q = new BigInteger(parameters.Q);
|
||||
this.g = new BigInteger(parameters.G);
|
||||
if (parameters.X != null)
|
||||
{
|
||||
this.x = new BigInteger(parameters.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.x = null;
|
||||
}
|
||||
if (parameters.Y != null)
|
||||
{
|
||||
this.y = new BigInteger(parameters.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.y = this.g.ModPow(this.x, this.p);
|
||||
}
|
||||
if (parameters.J != null)
|
||||
{
|
||||
this.j = new BigInteger(parameters.J);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.j = (this.p - 1) / this.q;
|
||||
this.j_missing = true;
|
||||
}
|
||||
if (parameters.Seed != null)
|
||||
{
|
||||
this.seed = new BigInteger(parameters.Seed);
|
||||
this.counter = parameters.Counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.seed = 0;
|
||||
}
|
||||
this.keypairGenerated = true;
|
||||
}
|
||||
|
||||
// Token: 0x06000903 RID: 2307 RVA: 0x00023A98 File Offset: 0x00021C98
|
||||
public override byte[] CreateSignature(byte[] rgbHash)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (rgbHash == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbHash");
|
||||
}
|
||||
if (rgbHash.Length != 20)
|
||||
{
|
||||
throw new CryptographicException("invalid hash length");
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.Generate();
|
||||
}
|
||||
if (this.x == null)
|
||||
{
|
||||
throw new CryptographicException("no private key available for signature");
|
||||
}
|
||||
BigInteger bigInteger = new BigInteger(rgbHash);
|
||||
BigInteger bigInteger2 = BigInteger.GenerateRandom(160);
|
||||
while (bigInteger2 >= this.q)
|
||||
{
|
||||
bigInteger2.Randomize();
|
||||
}
|
||||
BigInteger bigInteger3 = this.g.ModPow(bigInteger2, this.p) % this.q;
|
||||
BigInteger bigInteger4 = bigInteger2.ModInverse(this.q) * (bigInteger + this.x * bigInteger3) % this.q;
|
||||
byte[] array = new byte[40];
|
||||
byte[] bytes = bigInteger3.GetBytes();
|
||||
byte[] bytes2 = bigInteger4.GetBytes();
|
||||
int num = 20 - bytes.Length;
|
||||
Array.Copy(bytes, 0, array, num, bytes.Length);
|
||||
num = 40 - bytes2.Length;
|
||||
Array.Copy(bytes2, 0, array, num, bytes2.Length);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000904 RID: 2308 RVA: 0x00023BDC File Offset: 0x00021DDC
|
||||
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (rgbHash == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbHash");
|
||||
}
|
||||
if (rgbSignature == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbSignature");
|
||||
}
|
||||
if (rgbHash.Length != 20)
|
||||
{
|
||||
throw new CryptographicException("invalid hash length");
|
||||
}
|
||||
if (rgbSignature.Length != 40)
|
||||
{
|
||||
throw new CryptographicException("invalid signature length");
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
BigInteger bigInteger = new BigInteger(rgbHash);
|
||||
byte[] array = new byte[20];
|
||||
Array.Copy(rgbSignature, 0, array, 0, 20);
|
||||
BigInteger bigInteger2 = new BigInteger(array);
|
||||
Array.Copy(rgbSignature, 20, array, 0, 20);
|
||||
BigInteger bigInteger3 = new BigInteger(array);
|
||||
if (bigInteger2 < 0 || this.q <= bigInteger2)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else if (bigInteger3 < 0 || this.q <= bigInteger3)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
BigInteger bigInteger4 = bigInteger3.ModInverse(this.q);
|
||||
BigInteger bigInteger5 = bigInteger * bigInteger4 % this.q;
|
||||
BigInteger bigInteger6 = bigInteger2 * bigInteger4 % this.q;
|
||||
bigInteger5 = this.g.ModPow(bigInteger5, this.p);
|
||||
bigInteger6 = this.y.ModPow(bigInteger6, this.p);
|
||||
BigInteger bigInteger7 = bigInteger5 * bigInteger6 % this.p % this.q;
|
||||
flag = bigInteger7 == bigInteger2;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new CryptographicException("couldn't compute signature verification");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000905 RID: 2309 RVA: 0x00023DAC File Offset: 0x00021FAC
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.m_disposed)
|
||||
{
|
||||
if (this.x != null)
|
||||
{
|
||||
this.x.Clear();
|
||||
this.x = null;
|
||||
}
|
||||
if (disposing)
|
||||
{
|
||||
if (this.p != null)
|
||||
{
|
||||
this.p.Clear();
|
||||
this.p = null;
|
||||
}
|
||||
if (this.q != null)
|
||||
{
|
||||
this.q.Clear();
|
||||
this.q = null;
|
||||
}
|
||||
if (this.g != null)
|
||||
{
|
||||
this.g.Clear();
|
||||
this.g = null;
|
||||
}
|
||||
if (this.j != null)
|
||||
{
|
||||
this.j.Clear();
|
||||
this.j = null;
|
||||
}
|
||||
if (this.seed != null)
|
||||
{
|
||||
this.seed.Clear();
|
||||
this.seed = null;
|
||||
}
|
||||
if (this.y != null)
|
||||
{
|
||||
this.y.Clear();
|
||||
this.y = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.m_disposed = true;
|
||||
}
|
||||
|
||||
// Token: 0x040001DF RID: 479
|
||||
private const int defaultKeySize = 1024;
|
||||
|
||||
// Token: 0x040001E0 RID: 480
|
||||
private bool keypairGenerated;
|
||||
|
||||
// Token: 0x040001E1 RID: 481
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x040001E2 RID: 482
|
||||
private BigInteger p;
|
||||
|
||||
// Token: 0x040001E3 RID: 483
|
||||
private BigInteger q;
|
||||
|
||||
// Token: 0x040001E4 RID: 484
|
||||
private BigInteger g;
|
||||
|
||||
// Token: 0x040001E5 RID: 485
|
||||
private BigInteger x;
|
||||
|
||||
// Token: 0x040001E6 RID: 486
|
||||
private BigInteger y;
|
||||
|
||||
// Token: 0x040001E7 RID: 487
|
||||
private BigInteger j;
|
||||
|
||||
// Token: 0x040001E8 RID: 488
|
||||
private BigInteger seed;
|
||||
|
||||
// Token: 0x040001E9 RID: 489
|
||||
private int counter;
|
||||
|
||||
// Token: 0x040001EA RID: 490
|
||||
private bool j_missing;
|
||||
|
||||
// Token: 0x040001EB RID: 491
|
||||
private RandomNumberGenerator rng;
|
||||
|
||||
// Token: 0x020006C4 RID: 1732
|
||||
// (Invoke) Token: 0x06004198 RID: 16792
|
||||
public delegate void KeyGeneratedEventHandler(object sender, EventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A5 RID: 165
|
||||
internal class HMACAlgorithm
|
||||
{
|
||||
// Token: 0x06000906 RID: 2310 RVA: 0x00023EC8 File Offset: 0x000220C8
|
||||
public HMACAlgorithm(string algoName)
|
||||
{
|
||||
this.CreateHash(algoName);
|
||||
}
|
||||
|
||||
// Token: 0x06000907 RID: 2311 RVA: 0x00023ED8 File Offset: 0x000220D8
|
||||
~HMACAlgorithm()
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
// Token: 0x06000908 RID: 2312 RVA: 0x00023F14 File Offset: 0x00022114
|
||||
private void CreateHash(string algoName)
|
||||
{
|
||||
this.algo = HashAlgorithm.Create(algoName);
|
||||
this.hashName = algoName;
|
||||
this.block = new BlockProcessor(this.algo, 8);
|
||||
}
|
||||
|
||||
// Token: 0x06000909 RID: 2313 RVA: 0x00023F3C File Offset: 0x0002213C
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.key != null)
|
||||
{
|
||||
Array.Clear(this.key, 0, this.key.Length);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F7 RID: 247
|
||||
// (get) Token: 0x0600090A RID: 2314 RVA: 0x00023F60 File Offset: 0x00022160
|
||||
public HashAlgorithm Algo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.algo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F8 RID: 248
|
||||
// (get) Token: 0x0600090B RID: 2315 RVA: 0x00023F68 File Offset: 0x00022168
|
||||
// (set) Token: 0x0600090C RID: 2316 RVA: 0x00023F70 File Offset: 0x00022170
|
||||
public string HashName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.hashName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.CreateHash(value);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F9 RID: 249
|
||||
// (get) Token: 0x0600090D RID: 2317 RVA: 0x00023F7C File Offset: 0x0002217C
|
||||
// (set) Token: 0x0600090E RID: 2318 RVA: 0x00023F84 File Offset: 0x00022184
|
||||
public byte[] Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.Length > 64)
|
||||
{
|
||||
this.key = this.algo.ComputeHash(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.key = (byte[])value.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600090F RID: 2319 RVA: 0x00023FCC File Offset: 0x000221CC
|
||||
public void Initialize()
|
||||
{
|
||||
this.hash = null;
|
||||
this.block.Initialize();
|
||||
byte[] array = this.KeySetup(this.key, 54);
|
||||
this.algo.Initialize();
|
||||
this.block.Core(array);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
}
|
||||
|
||||
// Token: 0x06000910 RID: 2320 RVA: 0x0002401C File Offset: 0x0002221C
|
||||
private byte[] KeySetup(byte[] key, byte padding)
|
||||
{
|
||||
byte[] array = new byte[64];
|
||||
for (int i = 0; i < key.Length; i++)
|
||||
{
|
||||
array[i] = key[i] ^ padding;
|
||||
}
|
||||
for (int j = key.Length; j < 64; j++)
|
||||
{
|
||||
array[j] = padding;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000911 RID: 2321 RVA: 0x00024068 File Offset: 0x00022268
|
||||
public void Core(byte[] rgb, int ib, int cb)
|
||||
{
|
||||
this.block.Core(rgb, ib, cb);
|
||||
}
|
||||
|
||||
// Token: 0x06000912 RID: 2322 RVA: 0x00024078 File Offset: 0x00022278
|
||||
public byte[] Final()
|
||||
{
|
||||
this.block.Final();
|
||||
byte[] array = this.algo.Hash;
|
||||
byte[] array2 = this.KeySetup(this.key, 92);
|
||||
this.algo.Initialize();
|
||||
this.algo.TransformBlock(array2, 0, array2.Length, array2, 0);
|
||||
this.algo.TransformFinalBlock(array, 0, array.Length);
|
||||
this.hash = this.algo.Hash;
|
||||
this.algo.Clear();
|
||||
Array.Clear(array2, 0, array2.Length);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
// Token: 0x040001ED RID: 493
|
||||
private byte[] key;
|
||||
|
||||
// Token: 0x040001EE RID: 494
|
||||
private byte[] hash;
|
||||
|
||||
// Token: 0x040001EF RID: 495
|
||||
private HashAlgorithm algo;
|
||||
|
||||
// Token: 0x040001F0 RID: 496
|
||||
private string hashName;
|
||||
|
||||
// Token: 0x040001F1 RID: 497
|
||||
private BlockProcessor block;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A2 RID: 162
|
||||
internal sealed class KeyBuilder
|
||||
{
|
||||
// Token: 0x060008E7 RID: 2279 RVA: 0x00023034 File Offset: 0x00021234
|
||||
private KeyBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x170000F1 RID: 241
|
||||
// (get) Token: 0x060008E8 RID: 2280 RVA: 0x0002303C File Offset: 0x0002123C
|
||||
private static RandomNumberGenerator Rng
|
||||
{
|
||||
get
|
||||
{
|
||||
if (KeyBuilder.rng == null)
|
||||
{
|
||||
KeyBuilder.rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
return KeyBuilder.rng;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008E9 RID: 2281 RVA: 0x00023058 File Offset: 0x00021258
|
||||
public static byte[] Key(int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
KeyBuilder.Rng.GetBytes(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060008EA RID: 2282 RVA: 0x00023078 File Offset: 0x00021278
|
||||
public static byte[] IV(int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
KeyBuilder.Rng.GetBytes(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x040001DA RID: 474
|
||||
private static RandomNumberGenerator rng;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Xml;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A6 RID: 166
|
||||
internal class KeyPairPersistence
|
||||
{
|
||||
// Token: 0x06000913 RID: 2323 RVA: 0x00024114 File Offset: 0x00022314
|
||||
public KeyPairPersistence(CspParameters parameters)
|
||||
: this(parameters, null)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000914 RID: 2324 RVA: 0x00024120 File Offset: 0x00022320
|
||||
public KeyPairPersistence(CspParameters parameters, string keyPair)
|
||||
{
|
||||
if (parameters == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameters");
|
||||
}
|
||||
this._params = this.Copy(parameters);
|
||||
this._keyvalue = keyPair;
|
||||
}
|
||||
|
||||
// Token: 0x170000FA RID: 250
|
||||
// (get) Token: 0x06000916 RID: 2326 RVA: 0x00024168 File Offset: 0x00022368
|
||||
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: 0x170000FB RID: 251
|
||||
// (get) Token: 0x06000917 RID: 2327 RVA: 0x0002420C File Offset: 0x0002240C
|
||||
// (set) Token: 0x06000918 RID: 2328 RVA: 0x00024214 File Offset: 0x00022414
|
||||
public string KeyValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._keyvalue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.CanChange)
|
||||
{
|
||||
this._keyvalue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000FC RID: 252
|
||||
// (get) Token: 0x06000919 RID: 2329 RVA: 0x00024228 File Offset: 0x00022428
|
||||
public CspParameters Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Copy(this._params);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600091A RID: 2330 RVA: 0x00024238 File Offset: 0x00022438
|
||||
public bool Load()
|
||||
{
|
||||
if (Environment.SocketSecurityEnabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag = File.Exists(this.Filename);
|
||||
if (flag)
|
||||
{
|
||||
using (StreamReader streamReader = File.OpenText(this.Filename))
|
||||
{
|
||||
this.FromXml(streamReader.ReadToEnd());
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x0600091B RID: 2331 RVA: 0x000242AC File Offset: 0x000224AC
|
||||
public void Save()
|
||||
{
|
||||
if (Environment.SocketSecurityEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
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: 0x0600091C RID: 2332 RVA: 0x00024348 File Offset: 0x00022548
|
||||
public void Remove()
|
||||
{
|
||||
if (Environment.SocketSecurityEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
File.Delete(this.Filename);
|
||||
}
|
||||
|
||||
// Token: 0x170000FD RID: 253
|
||||
// (get) Token: 0x0600091D RID: 2333 RVA: 0x00024360 File Offset: 0x00022560
|
||||
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: 0x170000FE RID: 254
|
||||
// (get) Token: 0x0600091E RID: 2334 RVA: 0x00024484 File Offset: 0x00022684
|
||||
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: 0x0600091F RID: 2335
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _CanSecure(string root);
|
||||
|
||||
// Token: 0x06000920 RID: 2336
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _ProtectUser(string path);
|
||||
|
||||
// Token: 0x06000921 RID: 2337
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _ProtectMachine(string path);
|
||||
|
||||
// Token: 0x06000922 RID: 2338
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _IsUserProtected(string path);
|
||||
|
||||
// Token: 0x06000923 RID: 2339
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _IsMachineProtected(string path);
|
||||
|
||||
// Token: 0x06000924 RID: 2340 RVA: 0x000245A8 File Offset: 0x000227A8
|
||||
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: 0x06000925 RID: 2341 RVA: 0x000245E8 File Offset: 0x000227E8
|
||||
private static bool ProtectUser(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectUser(path);
|
||||
}
|
||||
|
||||
// Token: 0x06000926 RID: 2342 RVA: 0x00024600 File Offset: 0x00022800
|
||||
private static bool ProtectMachine(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectMachine(path);
|
||||
}
|
||||
|
||||
// Token: 0x06000927 RID: 2343 RVA: 0x00024618 File Offset: 0x00022818
|
||||
private static bool IsUserProtected(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsUserProtected(path);
|
||||
}
|
||||
|
||||
// Token: 0x06000928 RID: 2344 RVA: 0x00024630 File Offset: 0x00022830
|
||||
private static bool IsMachineProtected(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsMachineProtected(path);
|
||||
}
|
||||
|
||||
// Token: 0x170000FF RID: 255
|
||||
// (get) Token: 0x06000929 RID: 2345 RVA: 0x00024648 File Offset: 0x00022848
|
||||
private bool CanChange
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._keyvalue == null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000100 RID: 256
|
||||
// (get) Token: 0x0600092A RID: 2346 RVA: 0x00024654 File Offset: 0x00022854
|
||||
private bool UseDefaultKeyContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._params.Flags & CspProviderFlags.UseDefaultKeyContainer) == CspProviderFlags.UseDefaultKeyContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000101 RID: 257
|
||||
// (get) Token: 0x0600092B RID: 2347 RVA: 0x00024668 File Offset: 0x00022868
|
||||
private bool UseMachineKeyStore
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._params.Flags & CspProviderFlags.UseMachineKeyStore) == CspProviderFlags.UseMachineKeyStore;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000102 RID: 258
|
||||
// (get) Token: 0x0600092C RID: 2348 RVA: 0x0002467C File Offset: 0x0002287C
|
||||
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: 0x0600092D RID: 2349 RVA: 0x0002472C File Offset: 0x0002292C
|
||||
private CspParameters Copy(CspParameters p)
|
||||
{
|
||||
return new CspParameters(p.ProviderType, p.ProviderName, p.KeyContainerName)
|
||||
{
|
||||
KeyNumber = p.KeyNumber,
|
||||
Flags = p.Flags
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x0600092E RID: 2350 RVA: 0x0002476C File Offset: 0x0002296C
|
||||
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: 0x0600092F RID: 2351 RVA: 0x000247D8 File Offset: 0x000229D8
|
||||
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: 0x040001F2 RID: 498
|
||||
private static bool _userPathExists = false;
|
||||
|
||||
// Token: 0x040001F3 RID: 499
|
||||
private static string _userPath;
|
||||
|
||||
// Token: 0x040001F4 RID: 500
|
||||
private static bool _machinePathExists = false;
|
||||
|
||||
// Token: 0x040001F5 RID: 501
|
||||
private static string _machinePath;
|
||||
|
||||
// Token: 0x040001F6 RID: 502
|
||||
private CspParameters _params;
|
||||
|
||||
// Token: 0x040001F7 RID: 503
|
||||
private string _keyvalue;
|
||||
|
||||
// Token: 0x040001F8 RID: 504
|
||||
private string _filename;
|
||||
|
||||
// Token: 0x040001F9 RID: 505
|
||||
private string _container;
|
||||
|
||||
// Token: 0x040001FA RID: 506
|
||||
private static object lockobj = new object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A7 RID: 167
|
||||
internal class MACAlgorithm
|
||||
{
|
||||
// Token: 0x06000930 RID: 2352 RVA: 0x000248BC File Offset: 0x00022ABC
|
||||
public MACAlgorithm(SymmetricAlgorithm algorithm)
|
||||
{
|
||||
this.algo = algorithm;
|
||||
this.algo.Mode = CipherMode.CBC;
|
||||
this.blockSize = this.algo.BlockSize >> 3;
|
||||
this.algo.IV = new byte[this.blockSize];
|
||||
this.block = new byte[this.blockSize];
|
||||
}
|
||||
|
||||
// Token: 0x06000931 RID: 2353 RVA: 0x0002491C File Offset: 0x00022B1C
|
||||
public void Initialize(byte[] key)
|
||||
{
|
||||
this.algo.Key = key;
|
||||
if (this.enc == null)
|
||||
{
|
||||
this.enc = this.algo.CreateEncryptor();
|
||||
}
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
this.blockCount = 0;
|
||||
}
|
||||
|
||||
// Token: 0x06000932 RID: 2354 RVA: 0x0002496C File Offset: 0x00022B6C
|
||||
public void Core(byte[] rgb, int ib, int cb)
|
||||
{
|
||||
int num = Math.Min(this.blockSize - this.blockCount, cb);
|
||||
Array.Copy(rgb, ib, this.block, this.blockCount, num);
|
||||
this.blockCount += num;
|
||||
if (this.blockCount == this.blockSize)
|
||||
{
|
||||
this.enc.TransformBlock(this.block, 0, this.blockSize, this.block, 0);
|
||||
int num2 = (cb - num) / this.blockSize;
|
||||
for (int i = 0; i < num2; i++)
|
||||
{
|
||||
this.enc.TransformBlock(rgb, num, this.blockSize, this.block, 0);
|
||||
num += this.blockSize;
|
||||
}
|
||||
this.blockCount = cb - num;
|
||||
if (this.blockCount > 0)
|
||||
{
|
||||
Array.Copy(rgb, num, this.block, 0, this.blockCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000933 RID: 2355 RVA: 0x00024A4C File Offset: 0x00022C4C
|
||||
public byte[] Final()
|
||||
{
|
||||
byte[] array;
|
||||
if (this.blockCount > 0 || (this.algo.Padding != PaddingMode.Zeros && this.algo.Padding != PaddingMode.None))
|
||||
{
|
||||
array = this.enc.TransformFinalBlock(this.block, 0, this.blockCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
array = (byte[])this.block.Clone();
|
||||
}
|
||||
if (!this.enc.CanReuseTransform)
|
||||
{
|
||||
this.enc.Dispose();
|
||||
this.enc = null;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x040001FB RID: 507
|
||||
private SymmetricAlgorithm algo;
|
||||
|
||||
// Token: 0x040001FC RID: 508
|
||||
private ICryptoTransform enc;
|
||||
|
||||
// Token: 0x040001FD RID: 509
|
||||
private byte[] block;
|
||||
|
||||
// Token: 0x040001FE RID: 510
|
||||
private int blockSize;
|
||||
|
||||
// Token: 0x040001FF RID: 511
|
||||
private int blockCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A8 RID: 168
|
||||
internal sealed class PKCS1
|
||||
{
|
||||
// Token: 0x06000934 RID: 2356 RVA: 0x00024ADC File Offset: 0x00022CDC
|
||||
private PKCS1()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000936 RID: 2358 RVA: 0x00024B50 File Offset: 0x00022D50
|
||||
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: 0x06000937 RID: 2359 RVA: 0x00024B90 File Offset: 0x00022D90
|
||||
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: 0x06000938 RID: 2360 RVA: 0x00024BC8 File Offset: 0x00022DC8
|
||||
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: 0x06000939 RID: 2361 RVA: 0x00024C20 File Offset: 0x00022E20
|
||||
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: 0x0600093A RID: 2362 RVA: 0x00024C48 File Offset: 0x00022E48
|
||||
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: 0x0600093B RID: 2363 RVA: 0x00024C70 File Offset: 0x00022E70
|
||||
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: 0x0600093C RID: 2364 RVA: 0x00024CC0 File Offset: 0x00022EC0
|
||||
public static byte[] RSAEP(RSA rsa, byte[] m)
|
||||
{
|
||||
return rsa.EncryptValue(m);
|
||||
}
|
||||
|
||||
// Token: 0x0600093D RID: 2365 RVA: 0x00024CCC File Offset: 0x00022ECC
|
||||
public static byte[] RSADP(RSA rsa, byte[] c)
|
||||
{
|
||||
return rsa.DecryptValue(c);
|
||||
}
|
||||
|
||||
// Token: 0x0600093E RID: 2366 RVA: 0x00024CD8 File Offset: 0x00022ED8
|
||||
public static byte[] RSASP1(RSA rsa, byte[] m)
|
||||
{
|
||||
return rsa.DecryptValue(m);
|
||||
}
|
||||
|
||||
// Token: 0x0600093F RID: 2367 RVA: 0x00024CE4 File Offset: 0x00022EE4
|
||||
public static byte[] RSAVP1(RSA rsa, byte[] s)
|
||||
{
|
||||
return rsa.EncryptValue(s);
|
||||
}
|
||||
|
||||
// Token: 0x06000940 RID: 2368 RVA: 0x00024CF0 File Offset: 0x00022EF0
|
||||
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: 0x06000941 RID: 2369 RVA: 0x00024E08 File Offset: 0x00023008
|
||||
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: 0x06000942 RID: 2370 RVA: 0x00024F54 File Offset: 0x00023154
|
||||
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: 0x06000943 RID: 2371 RVA: 0x00024FE0 File Offset: 0x000231E0
|
||||
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: 0x06000944 RID: 2372 RVA: 0x00025090 File Offset: 0x00023290
|
||||
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: 0x06000945 RID: 2373 RVA: 0x000250CC File Offset: 0x000232CC
|
||||
public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature)
|
||||
{
|
||||
return PKCS1.Verify_v15(rsa, hash, hashValue, signature, false);
|
||||
}
|
||||
|
||||
// Token: 0x06000946 RID: 2374 RVA: 0x000250D8 File Offset: 0x000232D8
|
||||
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: 0x06000947 RID: 2375 RVA: 0x0002519C File Offset: 0x0002339C
|
||||
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: 0x06000948 RID: 2376 RVA: 0x000252A8 File Offset: 0x000234A8
|
||||
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: 0x04000200 RID: 512
|
||||
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: 0x04000201 RID: 513
|
||||
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: 0x04000202 RID: 514
|
||||
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: 0x04000203 RID: 515
|
||||
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: 0x020000A9 RID: 169
|
||||
internal sealed class PKCS8
|
||||
{
|
||||
// Token: 0x06000949 RID: 2377 RVA: 0x00025360 File Offset: 0x00023560
|
||||
private PKCS8()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600094A RID: 2378 RVA: 0x00025368 File Offset: 0x00023568
|
||||
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: 0x020000AA RID: 170
|
||||
public enum KeyInfo
|
||||
{
|
||||
// Token: 0x04000205 RID: 517
|
||||
PrivateKey,
|
||||
// Token: 0x04000206 RID: 518
|
||||
EncryptedPrivateKey,
|
||||
// Token: 0x04000207 RID: 519
|
||||
Unknown
|
||||
}
|
||||
|
||||
// Token: 0x020000AB RID: 171
|
||||
public class PrivateKeyInfo
|
||||
{
|
||||
// Token: 0x0600094B RID: 2379 RVA: 0x0002540C File Offset: 0x0002360C
|
||||
public PrivateKeyInfo()
|
||||
{
|
||||
this._version = 0;
|
||||
this._list = new ArrayList();
|
||||
}
|
||||
|
||||
// Token: 0x0600094C RID: 2380 RVA: 0x00025428 File Offset: 0x00023628
|
||||
public PrivateKeyInfo(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x17000103 RID: 259
|
||||
// (get) Token: 0x0600094D RID: 2381 RVA: 0x00025438 File Offset: 0x00023638
|
||||
// (set) Token: 0x0600094E RID: 2382 RVA: 0x00025440 File Offset: 0x00023640
|
||||
public string Algorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._algorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._algorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000104 RID: 260
|
||||
// (get) Token: 0x0600094F RID: 2383 RVA: 0x0002544C File Offset: 0x0002364C
|
||||
public ArrayList Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._list;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000105 RID: 261
|
||||
// (get) Token: 0x06000950 RID: 2384 RVA: 0x00025454 File Offset: 0x00023654
|
||||
// (set) Token: 0x06000951 RID: 2385 RVA: 0x00025474 File Offset: 0x00023674
|
||||
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: 0x17000106 RID: 262
|
||||
// (get) Token: 0x06000952 RID: 2386 RVA: 0x000254A4 File Offset: 0x000236A4
|
||||
// (set) Token: 0x06000953 RID: 2387 RVA: 0x000254AC File Offset: 0x000236AC
|
||||
public int Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("negative version");
|
||||
}
|
||||
this._version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000954 RID: 2388 RVA: 0x000254C8 File Offset: 0x000236C8
|
||||
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: 0x06000955 RID: 2389 RVA: 0x000255C8 File Offset: 0x000237C8
|
||||
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: 0x06000956 RID: 2390 RVA: 0x000256D0 File Offset: 0x000238D0
|
||||
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: 0x06000957 RID: 2391 RVA: 0x00025704 File Offset: 0x00023904
|
||||
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: 0x06000958 RID: 2392 RVA: 0x00025744 File Offset: 0x00023944
|
||||
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: 0x06000959 RID: 2393 RVA: 0x000258E4 File Offset: 0x00023AE4
|
||||
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: 0x0600095A RID: 2394 RVA: 0x000259B4 File Offset: 0x00023BB4
|
||||
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: 0x0600095B RID: 2395 RVA: 0x00025A04 File Offset: 0x00023C04
|
||||
public static byte[] Encode(DSA dsa)
|
||||
{
|
||||
return ASN1Convert.FromUnsignedBigInteger(dsa.ExportParameters(true).X).GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x0600095C RID: 2396 RVA: 0x00025A2C File Offset: 0x00023C2C
|
||||
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: 0x04000208 RID: 520
|
||||
private int _version;
|
||||
|
||||
// Token: 0x04000209 RID: 521
|
||||
private string _algorithm;
|
||||
|
||||
// Token: 0x0400020A RID: 522
|
||||
private byte[] _key;
|
||||
|
||||
// Token: 0x0400020B RID: 523
|
||||
private ArrayList _list;
|
||||
}
|
||||
|
||||
// Token: 0x020000AC RID: 172
|
||||
public class EncryptedPrivateKeyInfo
|
||||
{
|
||||
// Token: 0x0600095D RID: 2397 RVA: 0x00025A78 File Offset: 0x00023C78
|
||||
public EncryptedPrivateKeyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600095E RID: 2398 RVA: 0x00025A80 File Offset: 0x00023C80
|
||||
public EncryptedPrivateKeyInfo(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x17000107 RID: 263
|
||||
// (get) Token: 0x0600095F RID: 2399 RVA: 0x00025A90 File Offset: 0x00023C90
|
||||
// (set) Token: 0x06000960 RID: 2400 RVA: 0x00025A98 File Offset: 0x00023C98
|
||||
public string Algorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._algorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._algorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000108 RID: 264
|
||||
// (get) Token: 0x06000961 RID: 2401 RVA: 0x00025AA4 File Offset: 0x00023CA4
|
||||
// (set) Token: 0x06000962 RID: 2402 RVA: 0x00025AC8 File Offset: 0x00023CC8
|
||||
public byte[] EncryptedData
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._data != null) ? ((byte[])this._data.Clone()) : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._data = ((value != null) ? ((byte[])value.Clone()) : null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000109 RID: 265
|
||||
// (get) Token: 0x06000963 RID: 2403 RVA: 0x00025AE8 File Offset: 0x00023CE8
|
||||
// (set) Token: 0x06000964 RID: 2404 RVA: 0x00025B30 File Offset: 0x00023D30
|
||||
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: 0x1700010A RID: 266
|
||||
// (get) Token: 0x06000965 RID: 2405 RVA: 0x00025B44 File Offset: 0x00023D44
|
||||
// (set) Token: 0x06000966 RID: 2406 RVA: 0x00025B4C File Offset: 0x00023D4C
|
||||
public int IterationCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._iterations;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("IterationCount", "Negative");
|
||||
}
|
||||
this._iterations = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000967 RID: 2407 RVA: 0x00025B6C File Offset: 0x00023D6C
|
||||
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: 0x06000968 RID: 2408 RVA: 0x00025C9C File Offset: 0x00023E9C
|
||||
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: 0x0400020C RID: 524
|
||||
private string _algorithm;
|
||||
|
||||
// Token: 0x0400020D RID: 525
|
||||
private byte[] _salt;
|
||||
|
||||
// Token: 0x0400020E RID: 526
|
||||
private int _iterations;
|
||||
|
||||
// Token: 0x0400020F RID: 527
|
||||
private byte[] _data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Math;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000AD RID: 173
|
||||
internal class RSAManaged : RSA
|
||||
{
|
||||
// Token: 0x06000969 RID: 2409 RVA: 0x00025D5C File Offset: 0x00023F5C
|
||||
public RSAManaged()
|
||||
: this(1024)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600096A RID: 2410 RVA: 0x00025D6C File Offset: 0x00023F6C
|
||||
public RSAManaged(int keySize)
|
||||
{
|
||||
this.LegalKeySizesValue = new KeySizes[1];
|
||||
this.LegalKeySizesValue[0] = new KeySizes(384, 16384, 8);
|
||||
base.KeySize = keySize;
|
||||
}
|
||||
|
||||
// Token: 0x14000002 RID: 2
|
||||
// (add) Token: 0x0600096B RID: 2411 RVA: 0x00025DB4 File Offset: 0x00023FB4
|
||||
// (remove) Token: 0x0600096C RID: 2412 RVA: 0x00025DD0 File Offset: 0x00023FD0
|
||||
public event RSAManaged.KeyGeneratedEventHandler KeyGenerated;
|
||||
|
||||
// Token: 0x0600096D RID: 2413 RVA: 0x00025DEC File Offset: 0x00023FEC
|
||||
~RSAManaged()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x0600096E RID: 2414 RVA: 0x00025E28 File Offset: 0x00024028
|
||||
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: 0x1700010B RID: 267
|
||||
// (get) Token: 0x0600096F RID: 2415 RVA: 0x00025FCC File Offset: 0x000241CC
|
||||
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: 0x1700010C RID: 268
|
||||
// (get) Token: 0x06000970 RID: 2416 RVA: 0x00026008 File Offset: 0x00024208
|
||||
public override string KeyExchangeAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "RSA-PKCS1-KeyEx";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010D RID: 269
|
||||
// (get) Token: 0x06000971 RID: 2417 RVA: 0x00026010 File Offset: 0x00024210
|
||||
public bool PublicOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keypairGenerated && (this.d == null || this.n == null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010E RID: 270
|
||||
// (get) Token: 0x06000972 RID: 2418 RVA: 0x0002604C File Offset: 0x0002424C
|
||||
public override string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000973 RID: 2419 RVA: 0x00026054 File Offset: 0x00024254
|
||||
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: 0x06000974 RID: 2420 RVA: 0x00026210 File Offset: 0x00024410
|
||||
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: 0x06000975 RID: 2421 RVA: 0x0002627C File Offset: 0x0002447C
|
||||
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: 0x06000976 RID: 2422 RVA: 0x0002642C File Offset: 0x0002462C
|
||||
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: 0x06000977 RID: 2423 RVA: 0x000266B4 File Offset: 0x000248B4
|
||||
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: 0x06000978 RID: 2424 RVA: 0x000267F4 File Offset: 0x000249F4
|
||||
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: 0x1700010F RID: 271
|
||||
// (get) Token: 0x06000979 RID: 2425 RVA: 0x00026ABC File Offset: 0x00024CBC
|
||||
// (set) Token: 0x0600097A RID: 2426 RVA: 0x00026AC4 File Offset: 0x00024CC4
|
||||
public bool UseKeyBlinding
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keyBlinding;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.keyBlinding = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000110 RID: 272
|
||||
// (get) Token: 0x0600097B RID: 2427 RVA: 0x00026AD0 File Offset: 0x00024CD0
|
||||
public bool IsCrtPossible
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.keypairGenerated || this.isCRTpossible;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600097C RID: 2428 RVA: 0x00026AE8 File Offset: 0x00024CE8
|
||||
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: 0x04000210 RID: 528
|
||||
private const int defaultKeySize = 1024;
|
||||
|
||||
// Token: 0x04000211 RID: 529
|
||||
private bool isCRTpossible;
|
||||
|
||||
// Token: 0x04000212 RID: 530
|
||||
private bool keyBlinding = true;
|
||||
|
||||
// Token: 0x04000213 RID: 531
|
||||
private bool keypairGenerated;
|
||||
|
||||
// Token: 0x04000214 RID: 532
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x04000215 RID: 533
|
||||
private BigInteger d;
|
||||
|
||||
// Token: 0x04000216 RID: 534
|
||||
private BigInteger p;
|
||||
|
||||
// Token: 0x04000217 RID: 535
|
||||
private BigInteger q;
|
||||
|
||||
// Token: 0x04000218 RID: 536
|
||||
private BigInteger dp;
|
||||
|
||||
// Token: 0x04000219 RID: 537
|
||||
private BigInteger dq;
|
||||
|
||||
// Token: 0x0400021A RID: 538
|
||||
private BigInteger qInv;
|
||||
|
||||
// Token: 0x0400021B RID: 539
|
||||
private BigInteger n;
|
||||
|
||||
// Token: 0x0400021C RID: 540
|
||||
private BigInteger e;
|
||||
|
||||
// Token: 0x020006C5 RID: 1733
|
||||
// (Invoke) Token: 0x0600419C RID: 16796
|
||||
public delegate void KeyGeneratedEventHandler(object sender, EventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,556 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000AE RID: 174
|
||||
internal abstract class SymmetricTransform : IDisposable, ICryptoTransform
|
||||
{
|
||||
// Token: 0x0600097D RID: 2429 RVA: 0x00026B2C File Offset: 0x00024D2C
|
||||
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: 0x0600097E RID: 2430 RVA: 0x00026C58 File Offset: 0x00024E58
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Token: 0x0600097F RID: 2431 RVA: 0x00026C68 File Offset: 0x00024E68
|
||||
~SymmetricTransform()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x06000980 RID: 2432 RVA: 0x00026CA4 File Offset: 0x00024EA4
|
||||
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: 0x17000111 RID: 273
|
||||
// (get) Token: 0x06000981 RID: 2433 RVA: 0x00026CFC File Offset: 0x00024EFC
|
||||
public virtual bool CanTransformMultipleBlocks
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000112 RID: 274
|
||||
// (get) Token: 0x06000982 RID: 2434 RVA: 0x00026D00 File Offset: 0x00024F00
|
||||
public virtual bool CanReuseTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000113 RID: 275
|
||||
// (get) Token: 0x06000983 RID: 2435 RVA: 0x00026D04 File Offset: 0x00024F04
|
||||
public virtual int InputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.BlockSizeByte;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000114 RID: 276
|
||||
// (get) Token: 0x06000984 RID: 2436 RVA: 0x00026D0C File Offset: 0x00024F0C
|
||||
public virtual int OutputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.BlockSizeByte;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000985 RID: 2437 RVA: 0x00026D14 File Offset: 0x00024F14
|
||||
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: 0x06000986 RID: 2438
|
||||
protected abstract void ECB(byte[] input, byte[] output);
|
||||
|
||||
// Token: 0x06000987 RID: 2439 RVA: 0x00026DB4 File Offset: 0x00024FB4
|
||||
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: 0x06000988 RID: 2440 RVA: 0x00026E80 File Offset: 0x00025080
|
||||
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: 0x06000989 RID: 2441 RVA: 0x00026FE0 File Offset: 0x000251E0
|
||||
protected virtual void OFB(byte[] input, byte[] output)
|
||||
{
|
||||
throw new CryptographicException("OFB isn't supported by the framework");
|
||||
}
|
||||
|
||||
// Token: 0x0600098A RID: 2442 RVA: 0x00026FEC File Offset: 0x000251EC
|
||||
protected virtual void CTS(byte[] input, byte[] output)
|
||||
{
|
||||
throw new CryptographicException("CTS isn't supported by the framework");
|
||||
}
|
||||
|
||||
// Token: 0x0600098B RID: 2443 RVA: 0x00026FF8 File Offset: 0x000251F8
|
||||
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: 0x0600098C RID: 2444 RVA: 0x00027064 File Offset: 0x00025264
|
||||
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: 0x17000115 RID: 277
|
||||
// (get) Token: 0x0600098D RID: 2445 RVA: 0x0002718C File Offset: 0x0002538C
|
||||
private bool KeepLastBlock
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.encrypt && this.algo.Padding != PaddingMode.None && this.algo.Padding != PaddingMode.Zeros;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600098E RID: 2446 RVA: 0x000271CC File Offset: 0x000253CC
|
||||
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: 0x0600098F RID: 2447 RVA: 0x00027300 File Offset: 0x00025500
|
||||
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: 0x06000990 RID: 2448 RVA: 0x00027340 File Offset: 0x00025540
|
||||
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: 0x06000991 RID: 2449 RVA: 0x000273B0 File Offset: 0x000255B0
|
||||
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: 0x06000992 RID: 2450 RVA: 0x000275BC File Offset: 0x000257BC
|
||||
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: 0x06000993 RID: 2451 RVA: 0x000277F8 File Offset: 0x000259F8
|
||||
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: 0x0400021E RID: 542
|
||||
protected SymmetricAlgorithm algo;
|
||||
|
||||
// Token: 0x0400021F RID: 543
|
||||
protected bool encrypt;
|
||||
|
||||
// Token: 0x04000220 RID: 544
|
||||
private int BlockSizeByte;
|
||||
|
||||
// Token: 0x04000221 RID: 545
|
||||
private byte[] temp;
|
||||
|
||||
// Token: 0x04000222 RID: 546
|
||||
private byte[] temp2;
|
||||
|
||||
// Token: 0x04000223 RID: 547
|
||||
private byte[] workBuff;
|
||||
|
||||
// Token: 0x04000224 RID: 548
|
||||
private byte[] workout;
|
||||
|
||||
// Token: 0x04000225 RID: 549
|
||||
private int FeedBackByte;
|
||||
|
||||
// Token: 0x04000226 RID: 550
|
||||
private int FeedBackIter;
|
||||
|
||||
// Token: 0x04000227 RID: 551
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x04000228 RID: 552
|
||||
private bool lastBlock;
|
||||
|
||||
// Token: 0x04000229 RID: 553
|
||||
private RandomNumberGenerator _rng;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,1267 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Security.X509;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000DD RID: 221
|
||||
internal sealed class PKCS7
|
||||
{
|
||||
// Token: 0x06000B10 RID: 2832 RVA: 0x00030E6C File Offset: 0x0002F06C
|
||||
private PKCS7()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B11 RID: 2833 RVA: 0x00030E74 File Offset: 0x0002F074
|
||||
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: 0x06000B12 RID: 2834 RVA: 0x00030EB0 File Offset: 0x0002F0B0
|
||||
public static ASN1 AlgorithmIdentifier(string oid)
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid(oid));
|
||||
asn.Add(new ASN1(5));
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x06000B13 RID: 2835 RVA: 0x00030EE0 File Offset: 0x0002F0E0
|
||||
public static ASN1 AlgorithmIdentifier(string oid, ASN1 parameters)
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid(oid));
|
||||
asn.Add(parameters);
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x06000B14 RID: 2836 RVA: 0x00030F0C File Offset: 0x0002F10C
|
||||
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: 0x020000DE RID: 222
|
||||
public class Oid
|
||||
{
|
||||
// Token: 0x040002D7 RID: 727
|
||||
public const string rsaEncryption = "1.2.840.113549.1.1.1";
|
||||
|
||||
// Token: 0x040002D8 RID: 728
|
||||
public const string data = "1.2.840.113549.1.7.1";
|
||||
|
||||
// Token: 0x040002D9 RID: 729
|
||||
public const string signedData = "1.2.840.113549.1.7.2";
|
||||
|
||||
// Token: 0x040002DA RID: 730
|
||||
public const string envelopedData = "1.2.840.113549.1.7.3";
|
||||
|
||||
// Token: 0x040002DB RID: 731
|
||||
public const string signedAndEnvelopedData = "1.2.840.113549.1.7.4";
|
||||
|
||||
// Token: 0x040002DC RID: 732
|
||||
public const string digestedData = "1.2.840.113549.1.7.5";
|
||||
|
||||
// Token: 0x040002DD RID: 733
|
||||
public const string encryptedData = "1.2.840.113549.1.7.6";
|
||||
|
||||
// Token: 0x040002DE RID: 734
|
||||
public const string contentType = "1.2.840.113549.1.9.3";
|
||||
|
||||
// Token: 0x040002DF RID: 735
|
||||
public const string messageDigest = "1.2.840.113549.1.9.4";
|
||||
|
||||
// Token: 0x040002E0 RID: 736
|
||||
public const string signingTime = "1.2.840.113549.1.9.5";
|
||||
|
||||
// Token: 0x040002E1 RID: 737
|
||||
public const string countersignature = "1.2.840.113549.1.9.6";
|
||||
}
|
||||
|
||||
// Token: 0x020000DF RID: 223
|
||||
public class ContentInfo
|
||||
{
|
||||
// Token: 0x06000B16 RID: 2838 RVA: 0x00030FB4 File Offset: 0x0002F1B4
|
||||
public ContentInfo()
|
||||
{
|
||||
this.content = new ASN1(160);
|
||||
}
|
||||
|
||||
// Token: 0x06000B17 RID: 2839 RVA: 0x00030FCC File Offset: 0x0002F1CC
|
||||
public ContentInfo(string oid)
|
||||
: this()
|
||||
{
|
||||
this.contentType = oid;
|
||||
}
|
||||
|
||||
// Token: 0x06000B18 RID: 2840 RVA: 0x00030FDC File Offset: 0x0002F1DC
|
||||
public ContentInfo(byte[] data)
|
||||
: this(new ASN1(data))
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B19 RID: 2841 RVA: 0x00030FEC File Offset: 0x0002F1EC
|
||||
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: 0x17000173 RID: 371
|
||||
// (get) Token: 0x06000B1A RID: 2842 RVA: 0x00031098 File Offset: 0x0002F298
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetASN1();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000174 RID: 372
|
||||
// (get) Token: 0x06000B1B RID: 2843 RVA: 0x000310A0 File Offset: 0x0002F2A0
|
||||
// (set) Token: 0x06000B1C RID: 2844 RVA: 0x000310A8 File Offset: 0x0002F2A8
|
||||
public ASN1 Content
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.content = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000175 RID: 373
|
||||
// (get) Token: 0x06000B1D RID: 2845 RVA: 0x000310B4 File Offset: 0x0002F2B4
|
||||
// (set) Token: 0x06000B1E RID: 2846 RVA: 0x000310BC File Offset: 0x0002F2BC
|
||||
public string ContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contentType;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.contentType = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B1F RID: 2847 RVA: 0x000310C8 File Offset: 0x0002F2C8
|
||||
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: 0x06000B20 RID: 2848 RVA: 0x0003111C File Offset: 0x0002F31C
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.GetASN1().GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x040002E2 RID: 738
|
||||
private string contentType;
|
||||
|
||||
// Token: 0x040002E3 RID: 739
|
||||
private ASN1 content;
|
||||
}
|
||||
|
||||
// Token: 0x020000E0 RID: 224
|
||||
public class EncryptedData
|
||||
{
|
||||
// Token: 0x06000B21 RID: 2849 RVA: 0x0003112C File Offset: 0x0002F32C
|
||||
public EncryptedData()
|
||||
{
|
||||
this._version = 0;
|
||||
}
|
||||
|
||||
// Token: 0x06000B22 RID: 2850 RVA: 0x0003113C File Offset: 0x0002F33C
|
||||
public EncryptedData(byte[] data)
|
||||
: this(new ASN1(data))
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B23 RID: 2851 RVA: 0x0003114C File Offset: 0x0002F34C
|
||||
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: 0x17000176 RID: 374
|
||||
// (get) Token: 0x06000B24 RID: 2852 RVA: 0x0003127C File Offset: 0x0002F47C
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetASN1();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000177 RID: 375
|
||||
// (get) Token: 0x06000B25 RID: 2853 RVA: 0x00031284 File Offset: 0x0002F484
|
||||
public PKCS7.ContentInfo ContentInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._content;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000178 RID: 376
|
||||
// (get) Token: 0x06000B26 RID: 2854 RVA: 0x0003128C File Offset: 0x0002F48C
|
||||
public PKCS7.ContentInfo EncryptionAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._encryptionAlgorithm;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000179 RID: 377
|
||||
// (get) Token: 0x06000B27 RID: 2855 RVA: 0x00031294 File Offset: 0x0002F494
|
||||
public byte[] EncryptedContent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._encrypted == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this._encrypted.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700017A RID: 378
|
||||
// (get) Token: 0x06000B28 RID: 2856 RVA: 0x000312B4 File Offset: 0x0002F4B4
|
||||
// (set) Token: 0x06000B29 RID: 2857 RVA: 0x000312BC File Offset: 0x0002F4BC
|
||||
public byte Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B2A RID: 2858 RVA: 0x000312C8 File Offset: 0x0002F4C8
|
||||
internal ASN1 GetASN1()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000B2B RID: 2859 RVA: 0x000312CC File Offset: 0x0002F4CC
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.GetASN1().GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x040002E4 RID: 740
|
||||
private byte _version;
|
||||
|
||||
// Token: 0x040002E5 RID: 741
|
||||
private PKCS7.ContentInfo _content;
|
||||
|
||||
// Token: 0x040002E6 RID: 742
|
||||
private PKCS7.ContentInfo _encryptionAlgorithm;
|
||||
|
||||
// Token: 0x040002E7 RID: 743
|
||||
private byte[] _encrypted;
|
||||
}
|
||||
|
||||
// Token: 0x020000E1 RID: 225
|
||||
public class EnvelopedData
|
||||
{
|
||||
// Token: 0x06000B2C RID: 2860 RVA: 0x000312DC File Offset: 0x0002F4DC
|
||||
public EnvelopedData()
|
||||
{
|
||||
this._version = 0;
|
||||
this._content = new PKCS7.ContentInfo();
|
||||
this._encryptionAlgorithm = new PKCS7.ContentInfo();
|
||||
this._recipientInfos = new ArrayList();
|
||||
}
|
||||
|
||||
// Token: 0x06000B2D RID: 2861 RVA: 0x00031318 File Offset: 0x0002F518
|
||||
public EnvelopedData(byte[] data)
|
||||
: this(new ASN1(data))
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B2E RID: 2862 RVA: 0x00031328 File Offset: 0x0002F528
|
||||
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: 0x1700017B RID: 379
|
||||
// (get) Token: 0x06000B2F RID: 2863 RVA: 0x000314D8 File Offset: 0x0002F6D8
|
||||
public ArrayList RecipientInfos
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._recipientInfos;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700017C RID: 380
|
||||
// (get) Token: 0x06000B30 RID: 2864 RVA: 0x000314E0 File Offset: 0x0002F6E0
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetASN1();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700017D RID: 381
|
||||
// (get) Token: 0x06000B31 RID: 2865 RVA: 0x000314E8 File Offset: 0x0002F6E8
|
||||
public PKCS7.ContentInfo ContentInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._content;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700017E RID: 382
|
||||
// (get) Token: 0x06000B32 RID: 2866 RVA: 0x000314F0 File Offset: 0x0002F6F0
|
||||
public PKCS7.ContentInfo EncryptionAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._encryptionAlgorithm;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700017F RID: 383
|
||||
// (get) Token: 0x06000B33 RID: 2867 RVA: 0x000314F8 File Offset: 0x0002F6F8
|
||||
public byte[] EncryptedContent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._encrypted == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this._encrypted.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000180 RID: 384
|
||||
// (get) Token: 0x06000B34 RID: 2868 RVA: 0x00031518 File Offset: 0x0002F718
|
||||
// (set) Token: 0x06000B35 RID: 2869 RVA: 0x00031520 File Offset: 0x0002F720
|
||||
public byte Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B36 RID: 2870 RVA: 0x0003152C File Offset: 0x0002F72C
|
||||
internal ASN1 GetASN1()
|
||||
{
|
||||
return new ASN1(48);
|
||||
}
|
||||
|
||||
// Token: 0x06000B37 RID: 2871 RVA: 0x00031544 File Offset: 0x0002F744
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.GetASN1().GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x040002E8 RID: 744
|
||||
private byte _version;
|
||||
|
||||
// Token: 0x040002E9 RID: 745
|
||||
private PKCS7.ContentInfo _content;
|
||||
|
||||
// Token: 0x040002EA RID: 746
|
||||
private PKCS7.ContentInfo _encryptionAlgorithm;
|
||||
|
||||
// Token: 0x040002EB RID: 747
|
||||
private ArrayList _recipientInfos;
|
||||
|
||||
// Token: 0x040002EC RID: 748
|
||||
private byte[] _encrypted;
|
||||
}
|
||||
|
||||
// Token: 0x020000E2 RID: 226
|
||||
public class RecipientInfo
|
||||
{
|
||||
// Token: 0x06000B38 RID: 2872 RVA: 0x00031554 File Offset: 0x0002F754
|
||||
public RecipientInfo()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B39 RID: 2873 RVA: 0x0003155C File Offset: 0x0002F75C
|
||||
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: 0x17000181 RID: 385
|
||||
// (get) Token: 0x06000B3A RID: 2874 RVA: 0x0003163C File Offset: 0x0002F83C
|
||||
public string Oid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._oid;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000182 RID: 386
|
||||
// (get) Token: 0x06000B3B RID: 2875 RVA: 0x00031644 File Offset: 0x0002F844
|
||||
public byte[] Key
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._key == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this._key.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000183 RID: 387
|
||||
// (get) Token: 0x06000B3C RID: 2876 RVA: 0x00031664 File Offset: 0x0002F864
|
||||
public byte[] SubjectKeyIdentifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._ski == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this._ski.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000184 RID: 388
|
||||
// (get) Token: 0x06000B3D RID: 2877 RVA: 0x00031684 File Offset: 0x0002F884
|
||||
public string Issuer
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._issuer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000185 RID: 389
|
||||
// (get) Token: 0x06000B3E RID: 2878 RVA: 0x0003168C File Offset: 0x0002F88C
|
||||
public byte[] Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._serial == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this._serial.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000186 RID: 390
|
||||
// (get) Token: 0x06000B3F RID: 2879 RVA: 0x000316AC File Offset: 0x0002F8AC
|
||||
public int Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040002ED RID: 749
|
||||
private int _version;
|
||||
|
||||
// Token: 0x040002EE RID: 750
|
||||
private string _oid;
|
||||
|
||||
// Token: 0x040002EF RID: 751
|
||||
private byte[] _key;
|
||||
|
||||
// Token: 0x040002F0 RID: 752
|
||||
private byte[] _ski;
|
||||
|
||||
// Token: 0x040002F1 RID: 753
|
||||
private string _issuer;
|
||||
|
||||
// Token: 0x040002F2 RID: 754
|
||||
private byte[] _serial;
|
||||
}
|
||||
|
||||
// Token: 0x020000E3 RID: 227
|
||||
public class SignedData
|
||||
{
|
||||
// Token: 0x06000B40 RID: 2880 RVA: 0x000316B4 File Offset: 0x0002F8B4
|
||||
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: 0x06000B41 RID: 2881 RVA: 0x00031708 File Offset: 0x0002F908
|
||||
public SignedData(byte[] data)
|
||||
: this(new ASN1(data))
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B42 RID: 2882 RVA: 0x00031718 File Offset: 0x0002F918
|
||||
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: 0x17000187 RID: 391
|
||||
// (get) Token: 0x06000B43 RID: 2883 RVA: 0x0003191C File Offset: 0x0002FB1C
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetASN1();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000188 RID: 392
|
||||
// (get) Token: 0x06000B44 RID: 2884 RVA: 0x00031924 File Offset: 0x0002FB24
|
||||
public X509CertificateCollection Certificates
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.certs;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000189 RID: 393
|
||||
// (get) Token: 0x06000B45 RID: 2885 RVA: 0x0003192C File Offset: 0x0002FB2C
|
||||
public PKCS7.ContentInfo ContentInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contentInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700018A RID: 394
|
||||
// (get) Token: 0x06000B46 RID: 2886 RVA: 0x00031934 File Offset: 0x0002FB34
|
||||
public ArrayList Crls
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.crls;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700018B RID: 395
|
||||
// (get) Token: 0x06000B47 RID: 2887 RVA: 0x0003193C File Offset: 0x0002FB3C
|
||||
// (set) Token: 0x06000B48 RID: 2888 RVA: 0x00031944 File Offset: 0x0002FB44
|
||||
public string HashName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.hashAlgorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.hashAlgorithm = value;
|
||||
this.signerInfo.HashName = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700018C RID: 396
|
||||
// (get) Token: 0x06000B49 RID: 2889 RVA: 0x0003195C File Offset: 0x0002FB5C
|
||||
public PKCS7.SignerInfo SignerInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.signerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700018D RID: 397
|
||||
// (get) Token: 0x06000B4A RID: 2890 RVA: 0x00031964 File Offset: 0x0002FB64
|
||||
// (set) Token: 0x06000B4B RID: 2891 RVA: 0x0003196C File Offset: 0x0002FB6C
|
||||
public byte Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.version;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700018E RID: 398
|
||||
// (get) Token: 0x06000B4C RID: 2892 RVA: 0x00031978 File Offset: 0x0002FB78
|
||||
// (set) Token: 0x06000B4D RID: 2893 RVA: 0x00031980 File Offset: 0x0002FB80
|
||||
public bool UseAuthenticatedAttributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mda;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.mda = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B4E RID: 2894 RVA: 0x0003198C File Offset: 0x0002FB8C
|
||||
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: 0x06000B4F RID: 2895 RVA: 0x00031A9C File Offset: 0x0002FC9C
|
||||
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: 0x06000B50 RID: 2896 RVA: 0x00031B70 File Offset: 0x0002FD70
|
||||
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: 0x06000B51 RID: 2897 RVA: 0x00031E54 File Offset: 0x00030054
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.GetASN1().GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x040002F3 RID: 755
|
||||
private byte version;
|
||||
|
||||
// Token: 0x040002F4 RID: 756
|
||||
private string hashAlgorithm;
|
||||
|
||||
// Token: 0x040002F5 RID: 757
|
||||
private PKCS7.ContentInfo contentInfo;
|
||||
|
||||
// Token: 0x040002F6 RID: 758
|
||||
private X509CertificateCollection certs;
|
||||
|
||||
// Token: 0x040002F7 RID: 759
|
||||
private ArrayList crls;
|
||||
|
||||
// Token: 0x040002F8 RID: 760
|
||||
private PKCS7.SignerInfo signerInfo;
|
||||
|
||||
// Token: 0x040002F9 RID: 761
|
||||
private bool mda;
|
||||
|
||||
// Token: 0x040002FA RID: 762
|
||||
private bool signed;
|
||||
}
|
||||
|
||||
// Token: 0x020000E4 RID: 228
|
||||
public class SignerInfo
|
||||
{
|
||||
// Token: 0x06000B52 RID: 2898 RVA: 0x00031E64 File Offset: 0x00030064
|
||||
public SignerInfo()
|
||||
{
|
||||
this.version = 1;
|
||||
this.authenticatedAttributes = new ArrayList();
|
||||
this.unauthenticatedAttributes = new ArrayList();
|
||||
}
|
||||
|
||||
// Token: 0x06000B53 RID: 2899 RVA: 0x00031E8C File Offset: 0x0003008C
|
||||
public SignerInfo(byte[] data)
|
||||
: this(new ASN1(data))
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B54 RID: 2900 RVA: 0x00031E9C File Offset: 0x0003009C
|
||||
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: 0x1700018F RID: 399
|
||||
// (get) Token: 0x06000B55 RID: 2901 RVA: 0x00032078 File Offset: 0x00030278
|
||||
public string IssuerName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.issuer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000190 RID: 400
|
||||
// (get) Token: 0x06000B56 RID: 2902 RVA: 0x00032080 File Offset: 0x00030280
|
||||
public byte[] SerialNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.serial == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.serial.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000191 RID: 401
|
||||
// (get) Token: 0x06000B57 RID: 2903 RVA: 0x000320A0 File Offset: 0x000302A0
|
||||
public byte[] SubjectKeyIdentifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ski == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.ski.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000192 RID: 402
|
||||
// (get) Token: 0x06000B58 RID: 2904 RVA: 0x000320C0 File Offset: 0x000302C0
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetASN1();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000193 RID: 403
|
||||
// (get) Token: 0x06000B59 RID: 2905 RVA: 0x000320C8 File Offset: 0x000302C8
|
||||
public ArrayList AuthenticatedAttributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.authenticatedAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000194 RID: 404
|
||||
// (get) Token: 0x06000B5A RID: 2906 RVA: 0x000320D0 File Offset: 0x000302D0
|
||||
// (set) Token: 0x06000B5B RID: 2907 RVA: 0x000320D8 File Offset: 0x000302D8
|
||||
public X509Certificate Certificate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.x509;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.x509 = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000195 RID: 405
|
||||
// (get) Token: 0x06000B5C RID: 2908 RVA: 0x000320E4 File Offset: 0x000302E4
|
||||
// (set) Token: 0x06000B5D RID: 2909 RVA: 0x000320EC File Offset: 0x000302EC
|
||||
public string HashName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.hashAlgorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.hashAlgorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000196 RID: 406
|
||||
// (get) Token: 0x06000B5E RID: 2910 RVA: 0x000320F8 File Offset: 0x000302F8
|
||||
// (set) Token: 0x06000B5F RID: 2911 RVA: 0x00032100 File Offset: 0x00030300
|
||||
public AsymmetricAlgorithm Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.key = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000197 RID: 407
|
||||
// (get) Token: 0x06000B60 RID: 2912 RVA: 0x0003210C File Offset: 0x0003030C
|
||||
// (set) Token: 0x06000B61 RID: 2913 RVA: 0x0003212C File Offset: 0x0003032C
|
||||
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: 0x17000198 RID: 408
|
||||
// (get) Token: 0x06000B62 RID: 2914 RVA: 0x00032148 File Offset: 0x00030348
|
||||
public ArrayList UnauthenticatedAttributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.unauthenticatedAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000199 RID: 409
|
||||
// (get) Token: 0x06000B63 RID: 2915 RVA: 0x00032150 File Offset: 0x00030350
|
||||
// (set) Token: 0x06000B64 RID: 2916 RVA: 0x00032158 File Offset: 0x00030358
|
||||
public byte Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.version;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B65 RID: 2917 RVA: 0x00032164 File Offset: 0x00030364
|
||||
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));
|
||||
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));
|
||||
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: 0x06000B66 RID: 2918 RVA: 0x000323AC File Offset: 0x000305AC
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.GetASN1().GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x040002FC RID: 764
|
||||
private byte version;
|
||||
|
||||
// Token: 0x040002FD RID: 765
|
||||
private X509Certificate x509;
|
||||
|
||||
// Token: 0x040002FE RID: 766
|
||||
private string hashAlgorithm;
|
||||
|
||||
// Token: 0x040002FF RID: 767
|
||||
private AsymmetricAlgorithm key;
|
||||
|
||||
// Token: 0x04000300 RID: 768
|
||||
private ArrayList authenticatedAttributes;
|
||||
|
||||
// Token: 0x04000301 RID: 769
|
||||
private ArrayList unauthenticatedAttributes;
|
||||
|
||||
// Token: 0x04000302 RID: 770
|
||||
private byte[] signature;
|
||||
|
||||
// Token: 0x04000303 RID: 771
|
||||
private string issuer;
|
||||
|
||||
// Token: 0x04000304 RID: 772
|
||||
private byte[] serial;
|
||||
|
||||
// Token: 0x04000305 RID: 773
|
||||
private byte[] ski;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,665 @@
|
||||
using System;
|
||||
using System.Configuration.Assemblies;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000E5 RID: 229
|
||||
internal sealed class StrongName
|
||||
{
|
||||
// Token: 0x06000B67 RID: 2919 RVA: 0x000323BC File Offset: 0x000305BC
|
||||
public StrongName()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B68 RID: 2920 RVA: 0x000323C4 File Offset: 0x000305C4
|
||||
public StrongName(int keySize)
|
||||
{
|
||||
this.rsa = new RSAManaged(keySize);
|
||||
}
|
||||
|
||||
// Token: 0x06000B69 RID: 2921 RVA: 0x000323D8 File Offset: 0x000305D8
|
||||
public StrongName(byte[] data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
throw new ArgumentNullException("data");
|
||||
}
|
||||
if (data.Length == 16)
|
||||
{
|
||||
int i = 0;
|
||||
int num = 0;
|
||||
while (i < data.Length)
|
||||
{
|
||||
num += (int)data[i++];
|
||||
}
|
||||
if (num == 4)
|
||||
{
|
||||
this.publicKey = (byte[])data.Clone();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.RSA = CryptoConvert.FromCapiKeyBlob(data);
|
||||
if (this.rsa == null)
|
||||
{
|
||||
throw new ArgumentException("data isn't a correctly encoded RSA public key");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B6A RID: 2922 RVA: 0x00032464 File Offset: 0x00030664
|
||||
public StrongName(RSA rsa)
|
||||
{
|
||||
if (rsa == null)
|
||||
{
|
||||
throw new ArgumentNullException("rsa");
|
||||
}
|
||||
this.RSA = rsa;
|
||||
}
|
||||
|
||||
// Token: 0x06000B6C RID: 2924 RVA: 0x00032498 File Offset: 0x00030698
|
||||
private void InvalidateCache()
|
||||
{
|
||||
this.publicKey = null;
|
||||
this.keyToken = null;
|
||||
}
|
||||
|
||||
// Token: 0x1700019A RID: 410
|
||||
// (get) Token: 0x06000B6D RID: 2925 RVA: 0x000324A8 File Offset: 0x000306A8
|
||||
public bool CanSign
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.rsa == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.RSA is RSACryptoServiceProvider)
|
||||
{
|
||||
return !(this.rsa as RSACryptoServiceProvider).PublicOnly;
|
||||
}
|
||||
if (this.RSA is RSAManaged)
|
||||
{
|
||||
return !(this.rsa as RSAManaged).PublicOnly;
|
||||
}
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
RSAParameters rsaparameters = this.rsa.ExportParameters(true);
|
||||
flag = rsaparameters.D != null && rsaparameters.P != null && rsaparameters.Q != null;
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700019B RID: 411
|
||||
// (get) Token: 0x06000B6E RID: 2926 RVA: 0x00032574 File Offset: 0x00030774
|
||||
// (set) Token: 0x06000B6F RID: 2927 RVA: 0x00032594 File Offset: 0x00030794
|
||||
public RSA RSA
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.rsa == null)
|
||||
{
|
||||
this.rsa = RSA.Create();
|
||||
}
|
||||
return this.rsa;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.rsa = value;
|
||||
this.InvalidateCache();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700019C RID: 412
|
||||
// (get) Token: 0x06000B70 RID: 2928 RVA: 0x000325A4 File Offset: 0x000307A4
|
||||
public byte[] PublicKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.publicKey == null)
|
||||
{
|
||||
byte[] array = CryptoConvert.ToCapiKeyBlob(this.rsa, false);
|
||||
this.publicKey = new byte[32 + (this.rsa.KeySize >> 3)];
|
||||
this.publicKey[0] = array[4];
|
||||
this.publicKey[1] = array[5];
|
||||
this.publicKey[2] = array[6];
|
||||
this.publicKey[3] = array[7];
|
||||
this.publicKey[4] = 4;
|
||||
this.publicKey[5] = 128;
|
||||
this.publicKey[6] = 0;
|
||||
this.publicKey[7] = 0;
|
||||
byte[] bytes = BitConverterLE.GetBytes(this.publicKey.Length - 12);
|
||||
this.publicKey[8] = bytes[0];
|
||||
this.publicKey[9] = bytes[1];
|
||||
this.publicKey[10] = bytes[2];
|
||||
this.publicKey[11] = bytes[3];
|
||||
this.publicKey[12] = 6;
|
||||
Buffer.BlockCopy(array, 1, this.publicKey, 13, this.publicKey.Length - 13);
|
||||
this.publicKey[23] = 49;
|
||||
}
|
||||
return (byte[])this.publicKey.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700019D RID: 413
|
||||
// (get) Token: 0x06000B71 RID: 2929 RVA: 0x000326B8 File Offset: 0x000308B8
|
||||
public byte[] PublicKeyToken
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.keyToken == null)
|
||||
{
|
||||
byte[] array = this.PublicKey;
|
||||
if (array == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.TokenAlgorithm);
|
||||
byte[] array2 = hashAlgorithm.ComputeHash(array);
|
||||
this.keyToken = new byte[8];
|
||||
Buffer.BlockCopy(array2, array2.Length - 8, this.keyToken, 0, 8);
|
||||
Array.Reverse(this.keyToken, 0, 8);
|
||||
}
|
||||
return (byte[])this.keyToken.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700019E RID: 414
|
||||
// (get) Token: 0x06000B72 RID: 2930 RVA: 0x00032730 File Offset: 0x00030930
|
||||
// (set) Token: 0x06000B73 RID: 2931 RVA: 0x00032750 File Offset: 0x00030950
|
||||
public string TokenAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.tokenAlgorithm == null)
|
||||
{
|
||||
this.tokenAlgorithm = "SHA1";
|
||||
}
|
||||
return this.tokenAlgorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
string text = value.ToUpper(CultureInfo.InvariantCulture);
|
||||
if (text == "SHA1" || text == "MD5")
|
||||
{
|
||||
this.tokenAlgorithm = value;
|
||||
this.InvalidateCache();
|
||||
return;
|
||||
}
|
||||
throw new ArgumentException("Unsupported hash algorithm for token");
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B74 RID: 2932 RVA: 0x000327A8 File Offset: 0x000309A8
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return CryptoConvert.ToCapiPrivateKeyBlob(this.RSA);
|
||||
}
|
||||
|
||||
// Token: 0x06000B75 RID: 2933 RVA: 0x000327B8 File Offset: 0x000309B8
|
||||
private uint RVAtoPosition(uint r, int sections, byte[] headers)
|
||||
{
|
||||
for (int i = 0; i < sections; i++)
|
||||
{
|
||||
uint num = BitConverterLE.ToUInt32(headers, i * 40 + 20);
|
||||
uint num2 = BitConverterLE.ToUInt32(headers, i * 40 + 12);
|
||||
int num3 = (int)BitConverterLE.ToUInt32(headers, i * 40 + 8);
|
||||
if (num2 <= r && (ulong)r < (ulong)num2 + (ulong)((long)num3))
|
||||
{
|
||||
return num + r - num2;
|
||||
}
|
||||
}
|
||||
return 0U;
|
||||
}
|
||||
|
||||
// Token: 0x06000B76 RID: 2934 RVA: 0x0003281C File Offset: 0x00030A1C
|
||||
internal StrongName.StrongNameSignature StrongHash(Stream stream, StrongName.StrongNameOptions options)
|
||||
{
|
||||
StrongName.StrongNameSignature strongNameSignature = new StrongName.StrongNameSignature();
|
||||
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.TokenAlgorithm);
|
||||
CryptoStream cryptoStream = new CryptoStream(Stream.Null, hashAlgorithm, CryptoStreamMode.Write);
|
||||
byte[] array = new byte[128];
|
||||
stream.Read(array, 0, 128);
|
||||
if (BitConverterLE.ToUInt16(array, 0) != 23117)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
uint num = BitConverterLE.ToUInt32(array, 60);
|
||||
cryptoStream.Write(array, 0, 128);
|
||||
if (num != 128U)
|
||||
{
|
||||
byte[] array2 = new byte[num - 128U];
|
||||
stream.Read(array2, 0, array2.Length);
|
||||
cryptoStream.Write(array2, 0, array2.Length);
|
||||
}
|
||||
byte[] array3 = new byte[248];
|
||||
stream.Read(array3, 0, 248);
|
||||
if (BitConverterLE.ToUInt32(array3, 0) != 17744U)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (BitConverterLE.ToUInt16(array3, 4) != 332)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] array4 = new byte[8];
|
||||
Buffer.BlockCopy(array4, 0, array3, 88, 4);
|
||||
Buffer.BlockCopy(array4, 0, array3, 152, 8);
|
||||
cryptoStream.Write(array3, 0, 248);
|
||||
ushort num2 = BitConverterLE.ToUInt16(array3, 6);
|
||||
int num3 = (int)(num2 * 40);
|
||||
byte[] array5 = new byte[num3];
|
||||
stream.Read(array5, 0, num3);
|
||||
cryptoStream.Write(array5, 0, num3);
|
||||
uint num4 = BitConverterLE.ToUInt32(array3, 232);
|
||||
uint num5 = this.RVAtoPosition(num4, (int)num2, array5);
|
||||
int num6 = (int)BitConverterLE.ToUInt32(array3, 236);
|
||||
byte[] array6 = new byte[num6];
|
||||
stream.Position = (long)((ulong)num5);
|
||||
stream.Read(array6, 0, num6);
|
||||
uint num7 = BitConverterLE.ToUInt32(array6, 32);
|
||||
strongNameSignature.SignaturePosition = this.RVAtoPosition(num7, (int)num2, array5);
|
||||
strongNameSignature.SignatureLength = BitConverterLE.ToUInt32(array6, 36);
|
||||
uint num8 = BitConverterLE.ToUInt32(array6, 8);
|
||||
strongNameSignature.MetadataPosition = this.RVAtoPosition(num8, (int)num2, array5);
|
||||
strongNameSignature.MetadataLength = BitConverterLE.ToUInt32(array6, 12);
|
||||
if (options == StrongName.StrongNameOptions.Metadata)
|
||||
{
|
||||
cryptoStream.Close();
|
||||
hashAlgorithm.Initialize();
|
||||
byte[] array7 = new byte[strongNameSignature.MetadataLength];
|
||||
stream.Position = (long)((ulong)strongNameSignature.MetadataPosition);
|
||||
stream.Read(array7, 0, array7.Length);
|
||||
strongNameSignature.Hash = hashAlgorithm.ComputeHash(array7);
|
||||
return strongNameSignature;
|
||||
}
|
||||
for (int i = 0; i < (int)num2; i++)
|
||||
{
|
||||
uint num9 = BitConverterLE.ToUInt32(array5, i * 40 + 20);
|
||||
int num10 = (int)BitConverterLE.ToUInt32(array5, i * 40 + 16);
|
||||
byte[] array8 = new byte[num10];
|
||||
stream.Position = (long)((ulong)num9);
|
||||
stream.Read(array8, 0, num10);
|
||||
if (num9 <= strongNameSignature.SignaturePosition && (ulong)strongNameSignature.SignaturePosition < (ulong)num9 + (ulong)((long)num10))
|
||||
{
|
||||
int num11 = (int)(strongNameSignature.SignaturePosition - num9);
|
||||
if (num11 > 0)
|
||||
{
|
||||
cryptoStream.Write(array8, 0, num11);
|
||||
}
|
||||
strongNameSignature.Signature = new byte[strongNameSignature.SignatureLength];
|
||||
Buffer.BlockCopy(array8, num11, strongNameSignature.Signature, 0, (int)strongNameSignature.SignatureLength);
|
||||
Array.Reverse(strongNameSignature.Signature);
|
||||
int num12 = (int)((long)num11 + (long)((ulong)strongNameSignature.SignatureLength));
|
||||
int num13 = num10 - num12;
|
||||
if (num13 > 0)
|
||||
{
|
||||
cryptoStream.Write(array8, num12, num13);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cryptoStream.Write(array8, 0, num10);
|
||||
}
|
||||
}
|
||||
cryptoStream.Close();
|
||||
strongNameSignature.Hash = hashAlgorithm.Hash;
|
||||
return strongNameSignature;
|
||||
}
|
||||
|
||||
// Token: 0x06000B77 RID: 2935 RVA: 0x00032B68 File Offset: 0x00030D68
|
||||
public byte[] Hash(string fileName)
|
||||
{
|
||||
FileStream fileStream = File.OpenRead(fileName);
|
||||
StrongName.StrongNameSignature strongNameSignature = this.StrongHash(fileStream, StrongName.StrongNameOptions.Metadata);
|
||||
fileStream.Close();
|
||||
return strongNameSignature.Hash;
|
||||
}
|
||||
|
||||
// Token: 0x06000B78 RID: 2936 RVA: 0x00032B94 File Offset: 0x00030D94
|
||||
public bool Sign(string fileName)
|
||||
{
|
||||
bool flag = false;
|
||||
StrongName.StrongNameSignature strongNameSignature;
|
||||
using (FileStream fileStream = File.OpenRead(fileName))
|
||||
{
|
||||
strongNameSignature = this.StrongHash(fileStream, StrongName.StrongNameOptions.Signature);
|
||||
fileStream.Close();
|
||||
}
|
||||
if (strongNameSignature.Hash == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
byte[] array = null;
|
||||
try
|
||||
{
|
||||
RSAPKCS1SignatureFormatter rsapkcs1SignatureFormatter = new RSAPKCS1SignatureFormatter(this.rsa);
|
||||
rsapkcs1SignatureFormatter.SetHashAlgorithm(this.TokenAlgorithm);
|
||||
array = rsapkcs1SignatureFormatter.CreateSignature(strongNameSignature.Hash);
|
||||
Array.Reverse(array);
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (FileStream fileStream2 = File.OpenWrite(fileName))
|
||||
{
|
||||
fileStream2.Position = (long)((ulong)strongNameSignature.SignaturePosition);
|
||||
fileStream2.Write(array, 0, array.Length);
|
||||
fileStream2.Close();
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000B79 RID: 2937 RVA: 0x00032CAC File Offset: 0x00030EAC
|
||||
public bool Verify(string fileName)
|
||||
{
|
||||
bool flag = false;
|
||||
using (FileStream fileStream = File.OpenRead(fileName))
|
||||
{
|
||||
flag = this.Verify(fileStream);
|
||||
fileStream.Close();
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000B7A RID: 2938 RVA: 0x00032D00 File Offset: 0x00030F00
|
||||
public bool Verify(Stream stream)
|
||||
{
|
||||
StrongName.StrongNameSignature strongNameSignature = this.StrongHash(stream, StrongName.StrongNameOptions.Signature);
|
||||
if (strongNameSignature.Hash == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
AssemblyHashAlgorithm assemblyHashAlgorithm = AssemblyHashAlgorithm.SHA1;
|
||||
if (this.tokenAlgorithm == "MD5")
|
||||
{
|
||||
assemblyHashAlgorithm = AssemblyHashAlgorithm.MD5;
|
||||
}
|
||||
flag = StrongName.Verify(this.rsa, assemblyHashAlgorithm, strongNameSignature.Hash, strongNameSignature.Signature);
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000B7B RID: 2939 RVA: 0x00032D94 File Offset: 0x00030F94
|
||||
public static bool IsAssemblyStrongnamed(string assemblyName)
|
||||
{
|
||||
if (!StrongName.initialized)
|
||||
{
|
||||
object obj = StrongName.lockObject;
|
||||
lock (obj)
|
||||
{
|
||||
if (!StrongName.initialized)
|
||||
{
|
||||
StrongName.initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
AssemblyName assemblyName2 = AssemblyName.GetAssemblyName(assemblyName);
|
||||
if (assemblyName2 == null)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] mappedPublicKey = StrongNameManager.GetMappedPublicKey(assemblyName2.GetPublicKeyToken());
|
||||
if (mappedPublicKey == null || mappedPublicKey.Length < 12)
|
||||
{
|
||||
mappedPublicKey = assemblyName2.GetPublicKey();
|
||||
if (mappedPublicKey == null || mappedPublicKey.Length < 12)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!StrongNameManager.MustVerify(assemblyName2))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RSA rsa = CryptoConvert.FromCapiPublicKeyBlob(mappedPublicKey, 12);
|
||||
StrongName strongName = new StrongName(rsa);
|
||||
bool flag2 = strongName.Verify(assemblyName);
|
||||
flag = flag2;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000B7C RID: 2940 RVA: 0x00032EA4 File Offset: 0x000310A4
|
||||
public static bool VerifySignature(byte[] publicKey, int algorithm, byte[] hash, byte[] signature)
|
||||
{
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
RSA rsa = CryptoConvert.FromCapiPublicKeyBlob(publicKey);
|
||||
flag = StrongName.Verify(rsa, (AssemblyHashAlgorithm)algorithm, hash, signature);
|
||||
}
|
||||
catch
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000B7D RID: 2941 RVA: 0x00032EF8 File Offset: 0x000310F8
|
||||
private static bool Verify(RSA rsa, AssemblyHashAlgorithm algorithm, byte[] hash, byte[] signature)
|
||||
{
|
||||
RSAPKCS1SignatureDeformatter rsapkcs1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
|
||||
if (algorithm != AssemblyHashAlgorithm.MD5)
|
||||
{
|
||||
if (algorithm != AssemblyHashAlgorithm.SHA1 && algorithm != AssemblyHashAlgorithm.None)
|
||||
{
|
||||
}
|
||||
rsapkcs1SignatureDeformatter.SetHashAlgorithm("SHA1");
|
||||
}
|
||||
else
|
||||
{
|
||||
rsapkcs1SignatureDeformatter.SetHashAlgorithm("MD5");
|
||||
}
|
||||
return rsapkcs1SignatureDeformatter.VerifySignature(hash, signature);
|
||||
}
|
||||
|
||||
// Token: 0x04000306 RID: 774
|
||||
private RSA rsa;
|
||||
|
||||
// Token: 0x04000307 RID: 775
|
||||
private byte[] publicKey;
|
||||
|
||||
// Token: 0x04000308 RID: 776
|
||||
private byte[] keyToken;
|
||||
|
||||
// Token: 0x04000309 RID: 777
|
||||
private string tokenAlgorithm;
|
||||
|
||||
// Token: 0x0400030A RID: 778
|
||||
private static object lockObject = new object();
|
||||
|
||||
// Token: 0x0400030B RID: 779
|
||||
private static bool initialized = false;
|
||||
|
||||
// Token: 0x020000E6 RID: 230
|
||||
internal class StrongNameSignature
|
||||
{
|
||||
// Token: 0x1700019F RID: 415
|
||||
// (get) Token: 0x06000B7F RID: 2943 RVA: 0x00032F60 File Offset: 0x00031160
|
||||
// (set) Token: 0x06000B80 RID: 2944 RVA: 0x00032F68 File Offset: 0x00031168
|
||||
public byte[] Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.hash;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.hash = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A0 RID: 416
|
||||
// (get) Token: 0x06000B81 RID: 2945 RVA: 0x00032F74 File Offset: 0x00031174
|
||||
// (set) Token: 0x06000B82 RID: 2946 RVA: 0x00032F7C File Offset: 0x0003117C
|
||||
public byte[] Signature
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.signature;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.signature = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A1 RID: 417
|
||||
// (get) Token: 0x06000B83 RID: 2947 RVA: 0x00032F88 File Offset: 0x00031188
|
||||
// (set) Token: 0x06000B84 RID: 2948 RVA: 0x00032F90 File Offset: 0x00031190
|
||||
public uint MetadataPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.metadataPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.metadataPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A2 RID: 418
|
||||
// (get) Token: 0x06000B85 RID: 2949 RVA: 0x00032F9C File Offset: 0x0003119C
|
||||
// (set) Token: 0x06000B86 RID: 2950 RVA: 0x00032FA4 File Offset: 0x000311A4
|
||||
public uint MetadataLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.metadataLength;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.metadataLength = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A3 RID: 419
|
||||
// (get) Token: 0x06000B87 RID: 2951 RVA: 0x00032FB0 File Offset: 0x000311B0
|
||||
// (set) Token: 0x06000B88 RID: 2952 RVA: 0x00032FB8 File Offset: 0x000311B8
|
||||
public uint SignaturePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.signaturePosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.signaturePosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A4 RID: 420
|
||||
// (get) Token: 0x06000B89 RID: 2953 RVA: 0x00032FC4 File Offset: 0x000311C4
|
||||
// (set) Token: 0x06000B8A RID: 2954 RVA: 0x00032FCC File Offset: 0x000311CC
|
||||
public uint SignatureLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.signatureLength;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.signatureLength = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A5 RID: 421
|
||||
// (get) Token: 0x06000B8B RID: 2955 RVA: 0x00032FD8 File Offset: 0x000311D8
|
||||
// (set) Token: 0x06000B8C RID: 2956 RVA: 0x00032FE0 File Offset: 0x000311E0
|
||||
public byte CliFlag
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cliFlag;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.cliFlag = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A6 RID: 422
|
||||
// (get) Token: 0x06000B8D RID: 2957 RVA: 0x00032FEC File Offset: 0x000311EC
|
||||
// (set) Token: 0x06000B8E RID: 2958 RVA: 0x00032FF4 File Offset: 0x000311F4
|
||||
public uint CliFlagPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cliFlagPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.cliFlagPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0400030C RID: 780
|
||||
private byte[] hash;
|
||||
|
||||
// Token: 0x0400030D RID: 781
|
||||
private byte[] signature;
|
||||
|
||||
// Token: 0x0400030E RID: 782
|
||||
private uint signaturePosition;
|
||||
|
||||
// Token: 0x0400030F RID: 783
|
||||
private uint signatureLength;
|
||||
|
||||
// Token: 0x04000310 RID: 784
|
||||
private uint metadataPosition;
|
||||
|
||||
// Token: 0x04000311 RID: 785
|
||||
private uint metadataLength;
|
||||
|
||||
// Token: 0x04000312 RID: 786
|
||||
private byte cliFlag;
|
||||
|
||||
// Token: 0x04000313 RID: 787
|
||||
private uint cliFlagPosition;
|
||||
}
|
||||
|
||||
// Token: 0x020000E7 RID: 231
|
||||
internal enum StrongNameOptions
|
||||
{
|
||||
// Token: 0x04000315 RID: 789
|
||||
Metadata,
|
||||
// Token: 0x04000316 RID: 790
|
||||
Signature
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using Mono.Security.Cryptography;
|
||||
using Mono.Xml;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000E8 RID: 232
|
||||
internal class StrongNameManager
|
||||
{
|
||||
// Token: 0x06000B91 RID: 2961 RVA: 0x0003300C File Offset: 0x0003120C
|
||||
public static void LoadConfig(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
SecurityParser securityParser = new SecurityParser();
|
||||
using (StreamReader streamReader = new StreamReader(filename))
|
||||
{
|
||||
string text = streamReader.ReadToEnd();
|
||||
securityParser.LoadXml(text);
|
||||
}
|
||||
SecurityElement securityElement = securityParser.ToXml();
|
||||
if (securityElement != null && securityElement.Tag == "configuration")
|
||||
{
|
||||
SecurityElement securityElement2 = securityElement.SearchForChildByTag("strongNames");
|
||||
if (securityElement2 != null && securityElement2.Children.Count > 0)
|
||||
{
|
||||
SecurityElement securityElement3 = securityElement2.SearchForChildByTag("pubTokenMapping");
|
||||
if (securityElement3 != null && securityElement3.Children.Count > 0)
|
||||
{
|
||||
StrongNameManager.LoadMapping(securityElement3);
|
||||
}
|
||||
SecurityElement securityElement4 = securityElement2.SearchForChildByTag("verificationSettings");
|
||||
if (securityElement4 != null && securityElement4.Children.Count > 0)
|
||||
{
|
||||
StrongNameManager.LoadVerificationSettings(securityElement4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B92 RID: 2962 RVA: 0x00033114 File Offset: 0x00031314
|
||||
private static void LoadMapping(SecurityElement mapping)
|
||||
{
|
||||
if (StrongNameManager.mappings == null)
|
||||
{
|
||||
StrongNameManager.mappings = new Hashtable();
|
||||
}
|
||||
object syncRoot = StrongNameManager.mappings.SyncRoot;
|
||||
lock (syncRoot)
|
||||
{
|
||||
foreach (object obj in mapping.Children)
|
||||
{
|
||||
SecurityElement securityElement = (SecurityElement)obj;
|
||||
if (!(securityElement.Tag != "map"))
|
||||
{
|
||||
string text = securityElement.Attribute("Token");
|
||||
if (text != null && text.Length == 16)
|
||||
{
|
||||
text = text.ToUpper(CultureInfo.InvariantCulture);
|
||||
string text2 = securityElement.Attribute("PublicKey");
|
||||
if (text2 != null)
|
||||
{
|
||||
if (StrongNameManager.mappings[text] == null)
|
||||
{
|
||||
StrongNameManager.mappings.Add(text, text2);
|
||||
}
|
||||
else
|
||||
{
|
||||
StrongNameManager.mappings[text] = text2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B93 RID: 2963 RVA: 0x0003325C File Offset: 0x0003145C
|
||||
private static void LoadVerificationSettings(SecurityElement settings)
|
||||
{
|
||||
if (StrongNameManager.tokens == null)
|
||||
{
|
||||
StrongNameManager.tokens = new Hashtable();
|
||||
}
|
||||
object syncRoot = StrongNameManager.tokens.SyncRoot;
|
||||
lock (syncRoot)
|
||||
{
|
||||
foreach (object obj in settings.Children)
|
||||
{
|
||||
SecurityElement securityElement = (SecurityElement)obj;
|
||||
if (!(securityElement.Tag != "skip"))
|
||||
{
|
||||
string text = securityElement.Attribute("Token");
|
||||
if (text != null)
|
||||
{
|
||||
text = text.ToUpper(CultureInfo.InvariantCulture);
|
||||
string text2 = securityElement.Attribute("Assembly");
|
||||
if (text2 == null)
|
||||
{
|
||||
text2 = "*";
|
||||
}
|
||||
string text3 = securityElement.Attribute("Users");
|
||||
if (text3 == null)
|
||||
{
|
||||
text3 = "*";
|
||||
}
|
||||
StrongNameManager.Element element = (StrongNameManager.Element)StrongNameManager.tokens[text];
|
||||
if (element == null)
|
||||
{
|
||||
element = new StrongNameManager.Element(text2, text3);
|
||||
StrongNameManager.tokens.Add(text, element);
|
||||
}
|
||||
else if ((string)element.assemblies[text2] == null)
|
||||
{
|
||||
element.assemblies.Add(text2, text3);
|
||||
}
|
||||
else if (text3 == "*")
|
||||
{
|
||||
element.assemblies[text2] = "*";
|
||||
}
|
||||
else
|
||||
{
|
||||
string text4 = (string)element.assemblies[text2];
|
||||
string text5 = text4 + "," + text3;
|
||||
element.assemblies[text2] = text5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000B94 RID: 2964 RVA: 0x00033448 File Offset: 0x00031648
|
||||
public static byte[] GetMappedPublicKey(byte[] token)
|
||||
{
|
||||
if (StrongNameManager.mappings == null || token == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string text = CryptoConvert.ToHex(token);
|
||||
string text2 = (string)StrongNameManager.mappings[text];
|
||||
if (text2 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CryptoConvert.FromHex(text2);
|
||||
}
|
||||
|
||||
// Token: 0x06000B95 RID: 2965 RVA: 0x00033490 File Offset: 0x00031690
|
||||
public static bool MustVerify(AssemblyName an)
|
||||
{
|
||||
if (an == null || StrongNameManager.tokens == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
string text = CryptoConvert.ToHex(an.GetPublicKeyToken());
|
||||
StrongNameManager.Element element = (StrongNameManager.Element)StrongNameManager.tokens[text];
|
||||
if (element != null)
|
||||
{
|
||||
string text2 = element.GetUsers(an.Name);
|
||||
if (text2 == null)
|
||||
{
|
||||
text2 = element.GetUsers("*");
|
||||
}
|
||||
if (text2 != null)
|
||||
{
|
||||
return !(text2 == "*") && text2.IndexOf(Environment.UserName) < 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000B96 RID: 2966 RVA: 0x0003351C File Offset: 0x0003171C
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("Public Key Token\tAssemblies\t\tUsers");
|
||||
stringBuilder.Append(Environment.NewLine);
|
||||
foreach (object obj in StrongNameManager.tokens)
|
||||
{
|
||||
DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
|
||||
stringBuilder.Append((string)dictionaryEntry.Key);
|
||||
StrongNameManager.Element element = (StrongNameManager.Element)dictionaryEntry.Value;
|
||||
bool flag = true;
|
||||
foreach (object obj2 in element.assemblies)
|
||||
{
|
||||
DictionaryEntry dictionaryEntry2 = (DictionaryEntry)obj2;
|
||||
if (flag)
|
||||
{
|
||||
stringBuilder.Append("\t");
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append("\t\t\t");
|
||||
}
|
||||
stringBuilder.Append((string)dictionaryEntry2.Key);
|
||||
stringBuilder.Append("\t");
|
||||
string text = (string)dictionaryEntry2.Value;
|
||||
if (text == "*")
|
||||
{
|
||||
text = "All users";
|
||||
}
|
||||
stringBuilder.Append(text);
|
||||
stringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x04000317 RID: 791
|
||||
private static Hashtable mappings;
|
||||
|
||||
// Token: 0x04000318 RID: 792
|
||||
private static Hashtable tokens;
|
||||
|
||||
// Token: 0x020000E9 RID: 233
|
||||
private class Element
|
||||
{
|
||||
// Token: 0x06000B97 RID: 2967 RVA: 0x000336B0 File Offset: 0x000318B0
|
||||
public Element()
|
||||
{
|
||||
this.assemblies = new Hashtable();
|
||||
}
|
||||
|
||||
// Token: 0x06000B98 RID: 2968 RVA: 0x000336C4 File Offset: 0x000318C4
|
||||
public Element(string assembly, string users)
|
||||
: this()
|
||||
{
|
||||
this.assemblies.Add(assembly, users);
|
||||
}
|
||||
|
||||
// Token: 0x06000B99 RID: 2969 RVA: 0x000336DC File Offset: 0x000318DC
|
||||
public string GetUsers(string assembly)
|
||||
{
|
||||
return (string)this.assemblies[assembly];
|
||||
}
|
||||
|
||||
// Token: 0x04000319 RID: 793
|
||||
internal Hashtable assemblies;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,1423 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000EB RID: 235
|
||||
internal class Uri
|
||||
{
|
||||
// Token: 0x06000B9A RID: 2970 RVA: 0x000336F0 File Offset: 0x000318F0
|
||||
public Uri(string uriString)
|
||||
: this(uriString, false)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B9B RID: 2971 RVA: 0x000336FC File Offset: 0x000318FC
|
||||
public Uri(string uriString, bool dontEscape)
|
||||
{
|
||||
this.scheme = string.Empty;
|
||||
this.host = string.Empty;
|
||||
this.port = -1;
|
||||
this.path = string.Empty;
|
||||
this.query = string.Empty;
|
||||
this.fragment = string.Empty;
|
||||
this.userinfo = string.Empty;
|
||||
this.reduce = true;
|
||||
base..ctor();
|
||||
this.userEscaped = dontEscape;
|
||||
this.source = uriString;
|
||||
this.Parse();
|
||||
}
|
||||
|
||||
// Token: 0x06000B9C RID: 2972 RVA: 0x00033774 File Offset: 0x00031974
|
||||
public Uri(string uriString, bool dontEscape, bool reduce)
|
||||
{
|
||||
this.scheme = string.Empty;
|
||||
this.host = string.Empty;
|
||||
this.port = -1;
|
||||
this.path = string.Empty;
|
||||
this.query = string.Empty;
|
||||
this.fragment = string.Empty;
|
||||
this.userinfo = string.Empty;
|
||||
this.reduce = true;
|
||||
base..ctor();
|
||||
this.userEscaped = dontEscape;
|
||||
this.source = uriString;
|
||||
this.reduce = reduce;
|
||||
this.Parse();
|
||||
}
|
||||
|
||||
// Token: 0x06000B9D RID: 2973 RVA: 0x000337F4 File Offset: 0x000319F4
|
||||
public Uri(Uri baseUri, string relativeUri)
|
||||
: this(baseUri, relativeUri, false)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000B9E RID: 2974 RVA: 0x00033800 File Offset: 0x00031A00
|
||||
public Uri(Uri baseUri, string relativeUri, bool dontEscape)
|
||||
{
|
||||
this.scheme = string.Empty;
|
||||
this.host = string.Empty;
|
||||
this.port = -1;
|
||||
this.path = string.Empty;
|
||||
this.query = string.Empty;
|
||||
this.fragment = string.Empty;
|
||||
this.userinfo = string.Empty;
|
||||
this.reduce = true;
|
||||
base..ctor();
|
||||
if (baseUri == null)
|
||||
{
|
||||
throw new NullReferenceException("baseUri");
|
||||
}
|
||||
this.userEscaped = dontEscape;
|
||||
if (relativeUri == null)
|
||||
{
|
||||
throw new NullReferenceException("relativeUri");
|
||||
}
|
||||
if (relativeUri.StartsWith("\\\\"))
|
||||
{
|
||||
this.source = relativeUri;
|
||||
this.Parse();
|
||||
return;
|
||||
}
|
||||
int num = relativeUri.IndexOf(':');
|
||||
if (num != -1)
|
||||
{
|
||||
int num2 = relativeUri.IndexOfAny(new char[] { '/', '\\', '?' });
|
||||
if (num2 > num || num2 < 0)
|
||||
{
|
||||
this.source = relativeUri;
|
||||
this.Parse();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.scheme = baseUri.scheme;
|
||||
this.host = baseUri.host;
|
||||
this.port = baseUri.port;
|
||||
this.userinfo = baseUri.userinfo;
|
||||
this.isUnc = baseUri.isUnc;
|
||||
this.isUnixFilePath = baseUri.isUnixFilePath;
|
||||
this.isOpaquePart = baseUri.isOpaquePart;
|
||||
if (relativeUri == string.Empty)
|
||||
{
|
||||
this.path = baseUri.path;
|
||||
this.query = baseUri.query;
|
||||
this.fragment = baseUri.fragment;
|
||||
return;
|
||||
}
|
||||
num = relativeUri.IndexOf('#');
|
||||
if (num != -1)
|
||||
{
|
||||
this.fragment = relativeUri.Substring(num);
|
||||
relativeUri = relativeUri.Substring(0, num);
|
||||
}
|
||||
num = relativeUri.IndexOf('?');
|
||||
if (num != -1)
|
||||
{
|
||||
this.query = relativeUri.Substring(num);
|
||||
if (!this.userEscaped)
|
||||
{
|
||||
this.query = Uri.EscapeString(this.query);
|
||||
}
|
||||
relativeUri = relativeUri.Substring(0, num);
|
||||
}
|
||||
if (relativeUri.Length > 0 && relativeUri[0] == '/')
|
||||
{
|
||||
if (relativeUri.Length > 1 && relativeUri[1] == '/')
|
||||
{
|
||||
this.source = this.scheme + ':' + relativeUri;
|
||||
this.Parse();
|
||||
return;
|
||||
}
|
||||
this.path = relativeUri;
|
||||
if (!this.userEscaped)
|
||||
{
|
||||
this.path = Uri.EscapeString(this.path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.path = baseUri.path;
|
||||
if (relativeUri.Length > 0 || this.query.Length > 0)
|
||||
{
|
||||
num = this.path.LastIndexOf('/');
|
||||
if (num >= 0)
|
||||
{
|
||||
this.path = this.path.Substring(0, num + 1);
|
||||
}
|
||||
}
|
||||
if (relativeUri.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.path += relativeUri;
|
||||
int num3 = 0;
|
||||
for (;;)
|
||||
{
|
||||
num = this.path.IndexOf("./", num3);
|
||||
if (num == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (num == 0)
|
||||
{
|
||||
this.path = this.path.Remove(0, 2);
|
||||
}
|
||||
else if (this.path[num - 1] != '.')
|
||||
{
|
||||
this.path = this.path.Remove(num, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
num3 = num + 1;
|
||||
}
|
||||
}
|
||||
if (this.path.Length > 1 && this.path[this.path.Length - 1] == '.' && this.path[this.path.Length - 2] == '/')
|
||||
{
|
||||
this.path = this.path.Remove(this.path.Length - 1, 1);
|
||||
}
|
||||
num3 = 0;
|
||||
for (;;)
|
||||
{
|
||||
num = this.path.IndexOf("/../", num3);
|
||||
if (num == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (num == 0)
|
||||
{
|
||||
num3 = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
int num4 = this.path.LastIndexOf('/', num - 1);
|
||||
if (num4 == -1)
|
||||
{
|
||||
num3 = num + 1;
|
||||
}
|
||||
else if (this.path.Substring(num4 + 1, num - num4 - 1) != "..")
|
||||
{
|
||||
this.path = this.path.Remove(num4 + 1, num - num4 + 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
num3 = num + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.path.Length > 3 && this.path.EndsWith("/.."))
|
||||
{
|
||||
num = this.path.LastIndexOf('/', this.path.Length - 4);
|
||||
if (num != -1 && this.path.Substring(num + 1, this.path.Length - num - 4) != "..")
|
||||
{
|
||||
this.path = this.path.Remove(num + 1, this.path.Length - num - 1);
|
||||
}
|
||||
}
|
||||
if (!this.userEscaped)
|
||||
{
|
||||
this.path = Uri.EscapeString(this.path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A7 RID: 423
|
||||
// (get) Token: 0x06000BA0 RID: 2976 RVA: 0x00033E64 File Offset: 0x00032064
|
||||
public string AbsolutePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A8 RID: 424
|
||||
// (get) Token: 0x06000BA1 RID: 2977 RVA: 0x00033E6C File Offset: 0x0003206C
|
||||
public string AbsoluteUri
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.cachedAbsoluteUri == null)
|
||||
{
|
||||
this.cachedAbsoluteUri = this.GetLeftPart(UriPartial.Path) + this.query + this.fragment;
|
||||
}
|
||||
return this.cachedAbsoluteUri;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001A9 RID: 425
|
||||
// (get) Token: 0x06000BA2 RID: 2978 RVA: 0x00033EA0 File Offset: 0x000320A0
|
||||
public string Authority
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Uri.GetDefaultPort(this.scheme) != this.port) ? (this.host + ":" + this.port) : this.host;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001AA RID: 426
|
||||
// (get) Token: 0x06000BA3 RID: 2979 RVA: 0x00033EEC File Offset: 0x000320EC
|
||||
public string Fragment
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.fragment;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001AB RID: 427
|
||||
// (get) Token: 0x06000BA4 RID: 2980 RVA: 0x00033EF4 File Offset: 0x000320F4
|
||||
public string Host
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.host;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001AC RID: 428
|
||||
// (get) Token: 0x06000BA5 RID: 2981 RVA: 0x00033EFC File Offset: 0x000320FC
|
||||
public bool IsDefaultPort
|
||||
{
|
||||
get
|
||||
{
|
||||
return Uri.GetDefaultPort(this.scheme) == this.port;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001AD RID: 429
|
||||
// (get) Token: 0x06000BA6 RID: 2982 RVA: 0x00033F14 File Offset: 0x00032114
|
||||
public bool IsFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.scheme == Uri.UriSchemeFile;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001AE RID: 430
|
||||
// (get) Token: 0x06000BA7 RID: 2983 RVA: 0x00033F28 File Offset: 0x00032128
|
||||
public bool IsLoopback
|
||||
{
|
||||
get
|
||||
{
|
||||
return !(this.host == string.Empty) && (this.host == "loopback" || this.host == "localhost");
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001AF RID: 431
|
||||
// (get) Token: 0x06000BA8 RID: 2984 RVA: 0x00033F7C File Offset: 0x0003217C
|
||||
public bool IsUnc
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.isUnc;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B0 RID: 432
|
||||
// (get) Token: 0x06000BA9 RID: 2985 RVA: 0x00033F84 File Offset: 0x00032184
|
||||
public string LocalPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.cachedLocalPath != null)
|
||||
{
|
||||
return this.cachedLocalPath;
|
||||
}
|
||||
if (!this.IsFile)
|
||||
{
|
||||
return this.AbsolutePath;
|
||||
}
|
||||
bool flag = this.path.Length > 3 && this.path[1] == ':' && (this.path[2] == '\\' || this.path[2] == '/');
|
||||
if (!this.IsUnc)
|
||||
{
|
||||
string text = this.Unescape(this.path);
|
||||
if (Path.DirectorySeparatorChar == '\\' || flag)
|
||||
{
|
||||
this.cachedLocalPath = text.Replace('/', '\\');
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cachedLocalPath = text;
|
||||
}
|
||||
}
|
||||
else if (this.path.Length > 1 && this.path[1] == ':')
|
||||
{
|
||||
this.cachedLocalPath = this.Unescape(this.path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));
|
||||
}
|
||||
else if (Path.DirectorySeparatorChar == '\\')
|
||||
{
|
||||
this.cachedLocalPath = "\\\\" + this.Unescape(this.host + this.path.Replace('/', '\\'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cachedLocalPath = this.Unescape(this.path);
|
||||
}
|
||||
if (this.cachedLocalPath == string.Empty)
|
||||
{
|
||||
this.cachedLocalPath = Path.DirectorySeparatorChar.ToString();
|
||||
}
|
||||
return this.cachedLocalPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B1 RID: 433
|
||||
// (get) Token: 0x06000BAA RID: 2986 RVA: 0x0003411C File Offset: 0x0003231C
|
||||
public string PathAndQuery
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.path + this.query;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B2 RID: 434
|
||||
// (get) Token: 0x06000BAB RID: 2987 RVA: 0x00034130 File Offset: 0x00032330
|
||||
public int Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.port;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B3 RID: 435
|
||||
// (get) Token: 0x06000BAC RID: 2988 RVA: 0x00034138 File Offset: 0x00032338
|
||||
public string Query
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.query;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B4 RID: 436
|
||||
// (get) Token: 0x06000BAD RID: 2989 RVA: 0x00034140 File Offset: 0x00032340
|
||||
public string Scheme
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.scheme;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B5 RID: 437
|
||||
// (get) Token: 0x06000BAE RID: 2990 RVA: 0x00034148 File Offset: 0x00032348
|
||||
public string[] Segments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.segments != null)
|
||||
{
|
||||
return this.segments;
|
||||
}
|
||||
if (this.path.Length == 0)
|
||||
{
|
||||
this.segments = new string[0];
|
||||
return this.segments;
|
||||
}
|
||||
string[] array = this.path.Split(new char[] { '/' });
|
||||
this.segments = array;
|
||||
bool flag = this.path.EndsWith("/");
|
||||
if (array.Length > 0 && flag)
|
||||
{
|
||||
string[] array2 = new string[array.Length - 1];
|
||||
Array.Copy(array, 0, array2, 0, array.Length - 1);
|
||||
array = array2;
|
||||
}
|
||||
int i = 0;
|
||||
if (this.IsFile && this.path.Length > 1 && this.path[1] == ':')
|
||||
{
|
||||
string[] array3 = new string[array.Length + 1];
|
||||
Array.Copy(array, 1, array3, 2, array.Length - 1);
|
||||
array = array3;
|
||||
array[0] = this.path.Substring(0, 2);
|
||||
array[1] = string.Empty;
|
||||
i++;
|
||||
}
|
||||
int num = array.Length;
|
||||
while (i < num)
|
||||
{
|
||||
if (i != num - 1 || flag)
|
||||
{
|
||||
string[] array4 = array;
|
||||
int num2 = i;
|
||||
array4[num2] += '/';
|
||||
}
|
||||
i++;
|
||||
}
|
||||
this.segments = array;
|
||||
return this.segments;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B6 RID: 438
|
||||
// (get) Token: 0x06000BAF RID: 2991 RVA: 0x00034298 File Offset: 0x00032498
|
||||
public bool UserEscaped
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.userEscaped;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170001B7 RID: 439
|
||||
// (get) Token: 0x06000BB0 RID: 2992 RVA: 0x000342A0 File Offset: 0x000324A0
|
||||
public string UserInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.userinfo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000BB1 RID: 2993 RVA: 0x000342A8 File Offset: 0x000324A8
|
||||
internal static bool IsIPv4Address(string name)
|
||||
{
|
||||
string[] array = name.Split(new char[] { '.' });
|
||||
if (array.Length != 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
int num = int.Parse(array[i], CultureInfo.InvariantCulture);
|
||||
if (num < 0 || num > 255)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000BB2 RID: 2994 RVA: 0x0003433C File Offset: 0x0003253C
|
||||
internal static bool IsDomainAddress(string name)
|
||||
{
|
||||
int length = name.Length;
|
||||
if (name[length - 1] == '.')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int num = 0;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
char c = name[i];
|
||||
if (num == 0)
|
||||
{
|
||||
if (!char.IsLetterOrDigit(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (c == '.')
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
else if (!char.IsLetterOrDigit(c) && c != '-' && c != '_')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (++num == 64)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000BB3 RID: 2995 RVA: 0x000343D4 File Offset: 0x000325D4
|
||||
public static bool CheckSchemeName(string schemeName)
|
||||
{
|
||||
if (schemeName == null || schemeName.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!char.IsLetter(schemeName[0]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int length = schemeName.Length;
|
||||
for (int i = 1; i < length; i++)
|
||||
{
|
||||
char c = schemeName[i];
|
||||
if (!char.IsLetterOrDigit(c) && c != '.' && c != '+' && c != '-')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000BB4 RID: 2996 RVA: 0x00034450 File Offset: 0x00032650
|
||||
public override bool Equals(object comparant)
|
||||
{
|
||||
if (comparant == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Uri uri = comparant as Uri;
|
||||
if (uri == null)
|
||||
{
|
||||
string text = comparant as string;
|
||||
if (text == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uri = new Uri(text);
|
||||
}
|
||||
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
|
||||
return this.scheme.ToLower(invariantCulture) == uri.scheme.ToLower(invariantCulture) && this.userinfo.ToLower(invariantCulture) == uri.userinfo.ToLower(invariantCulture) && this.host.ToLower(invariantCulture) == uri.host.ToLower(invariantCulture) && this.port == uri.port && this.path == uri.path && this.query.ToLower(invariantCulture) == uri.query.ToLower(invariantCulture);
|
||||
}
|
||||
|
||||
// Token: 0x06000BB5 RID: 2997 RVA: 0x0003453C File Offset: 0x0003273C
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (this.cachedHashCode == 0)
|
||||
{
|
||||
this.cachedHashCode = this.scheme.GetHashCode() + this.userinfo.GetHashCode() + this.host.GetHashCode() + this.port + this.path.GetHashCode() + this.query.GetHashCode();
|
||||
}
|
||||
return this.cachedHashCode;
|
||||
}
|
||||
|
||||
// Token: 0x06000BB6 RID: 2998 RVA: 0x000345A4 File Offset: 0x000327A4
|
||||
public string GetLeftPart(UriPartial part)
|
||||
{
|
||||
switch (part)
|
||||
{
|
||||
case UriPartial.Scheme:
|
||||
return this.scheme + this.GetOpaqueWiseSchemeDelimiter();
|
||||
case UriPartial.Authority:
|
||||
{
|
||||
if (this.host == string.Empty || this.scheme == Uri.UriSchemeMailto || this.scheme == Uri.UriSchemeNews)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(this.scheme);
|
||||
stringBuilder.Append(this.GetOpaqueWiseSchemeDelimiter());
|
||||
if (this.path.Length > 1 && this.path[1] == ':' && Uri.UriSchemeFile == this.scheme)
|
||||
{
|
||||
stringBuilder.Append('/');
|
||||
}
|
||||
if (this.userinfo.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(this.userinfo).Append('@');
|
||||
}
|
||||
stringBuilder.Append(this.host);
|
||||
int num = Uri.GetDefaultPort(this.scheme);
|
||||
if (this.port != -1 && this.port != num)
|
||||
{
|
||||
stringBuilder.Append(':').Append(this.port);
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
case UriPartial.Path:
|
||||
{
|
||||
StringBuilder stringBuilder2 = new StringBuilder();
|
||||
stringBuilder2.Append(this.scheme);
|
||||
stringBuilder2.Append(this.GetOpaqueWiseSchemeDelimiter());
|
||||
if (this.path.Length > 1 && this.path[1] == ':' && Uri.UriSchemeFile == this.scheme)
|
||||
{
|
||||
stringBuilder2.Append('/');
|
||||
}
|
||||
if (this.userinfo.Length > 0)
|
||||
{
|
||||
stringBuilder2.Append(this.userinfo).Append('@');
|
||||
}
|
||||
stringBuilder2.Append(this.host);
|
||||
int num = Uri.GetDefaultPort(this.scheme);
|
||||
if (this.port != -1 && this.port != num)
|
||||
{
|
||||
stringBuilder2.Append(':').Append(this.port);
|
||||
}
|
||||
stringBuilder2.Append(this.path);
|
||||
return stringBuilder2.ToString();
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000BB7 RID: 2999 RVA: 0x000347D8 File Offset: 0x000329D8
|
||||
public static int FromHex(char digit)
|
||||
{
|
||||
if ('0' <= digit && digit <= '9')
|
||||
{
|
||||
return (int)(digit - '0');
|
||||
}
|
||||
if ('a' <= digit && digit <= 'f')
|
||||
{
|
||||
return (int)(digit - 'a' + '\n');
|
||||
}
|
||||
if ('A' <= digit && digit <= 'F')
|
||||
{
|
||||
return (int)(digit - 'A' + '\n');
|
||||
}
|
||||
throw new ArgumentException("digit");
|
||||
}
|
||||
|
||||
// Token: 0x06000BB8 RID: 3000 RVA: 0x00034834 File Offset: 0x00032A34
|
||||
public static string HexEscape(char character)
|
||||
{
|
||||
if (character > 'ÿ')
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("character");
|
||||
}
|
||||
return "%" + Uri.hexUpperChars[(int)((character & 'ð') >> 4)] + Uri.hexUpperChars[(int)(character & '\u000f')];
|
||||
}
|
||||
|
||||
// Token: 0x06000BB9 RID: 3001 RVA: 0x0003488C File Offset: 0x00032A8C
|
||||
public static char HexUnescape(string pattern, ref int index)
|
||||
{
|
||||
if (pattern == null)
|
||||
{
|
||||
throw new ArgumentException("pattern");
|
||||
}
|
||||
if (index < 0 || index >= pattern.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (index + 3 <= pattern.Length && pattern[index] == '%' && Uri.IsHexDigit(pattern[index + 1]) && Uri.IsHexDigit(pattern[index + 2]))
|
||||
{
|
||||
index++;
|
||||
int num3 = Uri.FromHex(pattern[index++]);
|
||||
int num4 = Uri.FromHex(pattern[index++]);
|
||||
int num5 = (num3 << 4) + num4;
|
||||
if (num == 0)
|
||||
{
|
||||
if (num5 < 192)
|
||||
{
|
||||
return (char)num5;
|
||||
}
|
||||
if (num5 < 224)
|
||||
{
|
||||
num2 = num5 - 192;
|
||||
num = 2;
|
||||
}
|
||||
else if (num5 < 240)
|
||||
{
|
||||
num2 = num5 - 224;
|
||||
num = 3;
|
||||
}
|
||||
else if (num5 < 248)
|
||||
{
|
||||
num2 = num5 - 240;
|
||||
num = 4;
|
||||
}
|
||||
else if (num5 < 251)
|
||||
{
|
||||
num2 = num5 - 248;
|
||||
num = 5;
|
||||
}
|
||||
else if (num5 < 254)
|
||||
{
|
||||
num2 = num5 - 252;
|
||||
num = 6;
|
||||
}
|
||||
num2 <<= (num - 1) * 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
num2 += num5 - 128 << (num - 1) * 6;
|
||||
}
|
||||
num--;
|
||||
if (num <= 0)
|
||||
{
|
||||
IL_1A2:
|
||||
return (char)num2;
|
||||
}
|
||||
}
|
||||
if (num == 0)
|
||||
{
|
||||
return pattern[index++];
|
||||
}
|
||||
goto IL_1A2;
|
||||
}
|
||||
|
||||
// Token: 0x06000BBA RID: 3002 RVA: 0x00034A40 File Offset: 0x00032C40
|
||||
public static bool IsHexDigit(char digit)
|
||||
{
|
||||
return ('0' <= digit && digit <= '9') || ('a' <= digit && digit <= 'f') || ('A' <= digit && digit <= 'F');
|
||||
}
|
||||
|
||||
// Token: 0x06000BBB RID: 3003 RVA: 0x00034A84 File Offset: 0x00032C84
|
||||
public static bool IsHexEncoding(string pattern, int index)
|
||||
{
|
||||
return index + 3 <= pattern.Length && (pattern[index++] == '%' && Uri.IsHexDigit(pattern[index++])) && Uri.IsHexDigit(pattern[index]);
|
||||
}
|
||||
|
||||
// Token: 0x06000BBC RID: 3004 RVA: 0x00034ADC File Offset: 0x00032CDC
|
||||
public string MakeRelative(Uri toUri)
|
||||
{
|
||||
if (this.Scheme != toUri.Scheme || this.Authority != toUri.Authority)
|
||||
{
|
||||
return toUri.ToString();
|
||||
}
|
||||
if (this.path == toUri.path)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
string[] array = this.Segments;
|
||||
string[] array2 = toUri.Segments;
|
||||
int i = 0;
|
||||
int num = Math.Min(array.Length, array2.Length);
|
||||
while (i < num)
|
||||
{
|
||||
if (array[i] != array2[i])
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
string text = string.Empty;
|
||||
for (int j = i + 1; j < array.Length; j++)
|
||||
{
|
||||
text += "../";
|
||||
}
|
||||
for (int k = i; k < array2.Length; k++)
|
||||
{
|
||||
text += array2[k];
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// Token: 0x06000BBD RID: 3005 RVA: 0x00034BD0 File Offset: 0x00032DD0
|
||||
public override string ToString()
|
||||
{
|
||||
if (this.cachedToString != null)
|
||||
{
|
||||
return this.cachedToString;
|
||||
}
|
||||
string text = ((!this.query.StartsWith("?")) ? this.Unescape(this.query) : ('?' + this.Unescape(this.query.Substring(1))));
|
||||
this.cachedToString = this.Unescape(this.GetLeftPart(UriPartial.Path), true) + text + this.fragment;
|
||||
return this.cachedToString;
|
||||
}
|
||||
|
||||
// Token: 0x06000BBE RID: 3006 RVA: 0x00034C5C File Offset: 0x00032E5C
|
||||
protected void Escape()
|
||||
{
|
||||
this.path = Uri.EscapeString(this.path);
|
||||
}
|
||||
|
||||
// Token: 0x06000BBF RID: 3007 RVA: 0x00034C70 File Offset: 0x00032E70
|
||||
protected static string EscapeString(string str)
|
||||
{
|
||||
return Uri.EscapeString(str, false, true, true);
|
||||
}
|
||||
|
||||
// Token: 0x06000BC0 RID: 3008 RVA: 0x00034C7C File Offset: 0x00032E7C
|
||||
internal static string EscapeString(string str, bool escapeReserved, bool escapeHex, bool escapeBrackets)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int length = str.Length;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (Uri.IsHexEncoding(str, i))
|
||||
{
|
||||
stringBuilder.Append(str.Substring(i, 3));
|
||||
i += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(new char[] { str[i] });
|
||||
int num = bytes.Length;
|
||||
for (int j = 0; j < num; j++)
|
||||
{
|
||||
char c = (char)bytes[j];
|
||||
if (c <= ' ' || c >= '\u007f' || "<>%\"{}|\\^`".IndexOf(c) != -1 || (escapeHex && c == '#') || (escapeBrackets && (c == '[' || c == ']')) || (escapeReserved && ";/?:@&=+$,".IndexOf(c) != -1))
|
||||
{
|
||||
stringBuilder.Append(Uri.HexEscape(c));
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x06000BC1 RID: 3009 RVA: 0x00034D9C File Offset: 0x00032F9C
|
||||
protected void Parse()
|
||||
{
|
||||
this.Parse(this.source);
|
||||
if (this.userEscaped)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.host = Uri.EscapeString(this.host, false, true, false);
|
||||
this.path = Uri.EscapeString(this.path);
|
||||
}
|
||||
|
||||
// Token: 0x06000BC2 RID: 3010 RVA: 0x00034DE8 File Offset: 0x00032FE8
|
||||
protected string Unescape(string str)
|
||||
{
|
||||
return this.Unescape(str, false);
|
||||
}
|
||||
|
||||
// Token: 0x06000BC3 RID: 3011 RVA: 0x00034DF4 File Offset: 0x00032FF4
|
||||
internal string Unescape(string str, bool excludeSharp)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int length = str.Length;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
char c = str[i];
|
||||
if (c == '%')
|
||||
{
|
||||
char c2 = Uri.HexUnescape(str, ref i);
|
||||
if (excludeSharp && c2 == '#')
|
||||
{
|
||||
stringBuilder.Append("%23");
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(c2);
|
||||
}
|
||||
i--;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(c);
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x06000BC4 RID: 3012 RVA: 0x00034E88 File Offset: 0x00033088
|
||||
private void ParseAsWindowsUNC(string uriString)
|
||||
{
|
||||
this.scheme = Uri.UriSchemeFile;
|
||||
this.port = -1;
|
||||
this.fragment = string.Empty;
|
||||
this.query = string.Empty;
|
||||
this.isUnc = true;
|
||||
uriString = uriString.TrimStart(new char[] { '\\' });
|
||||
int num = uriString.IndexOf('\\');
|
||||
if (num > 0)
|
||||
{
|
||||
this.path = uriString.Substring(num);
|
||||
this.host = uriString.Substring(0, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.host = uriString;
|
||||
this.path = string.Empty;
|
||||
}
|
||||
this.path = this.path.Replace("\\", "/");
|
||||
}
|
||||
|
||||
// Token: 0x06000BC5 RID: 3013 RVA: 0x00034F34 File Offset: 0x00033134
|
||||
private void ParseAsWindowsAbsoluteFilePath(string uriString)
|
||||
{
|
||||
if (uriString.Length > 2 && uriString[2] != '\\' && uriString[2] != '/')
|
||||
{
|
||||
throw new FormatException("Relative file path is not allowed.");
|
||||
}
|
||||
this.scheme = Uri.UriSchemeFile;
|
||||
this.host = string.Empty;
|
||||
this.port = -1;
|
||||
this.path = uriString.Replace("\\", "/");
|
||||
this.fragment = string.Empty;
|
||||
this.query = string.Empty;
|
||||
}
|
||||
|
||||
// Token: 0x06000BC6 RID: 3014 RVA: 0x00034FC0 File Offset: 0x000331C0
|
||||
private void ParseAsUnixAbsoluteFilePath(string uriString)
|
||||
{
|
||||
this.isUnixFilePath = true;
|
||||
this.scheme = Uri.UriSchemeFile;
|
||||
this.port = -1;
|
||||
this.fragment = string.Empty;
|
||||
this.query = string.Empty;
|
||||
this.host = string.Empty;
|
||||
this.path = null;
|
||||
if (uriString.StartsWith("//"))
|
||||
{
|
||||
uriString = uriString.TrimStart(new char[] { '/' });
|
||||
this.path = '/' + uriString;
|
||||
}
|
||||
if (this.path == null)
|
||||
{
|
||||
this.path = uriString;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000BC7 RID: 3015 RVA: 0x00035058 File Offset: 0x00033258
|
||||
private void Parse(string uriString)
|
||||
{
|
||||
if (uriString == null)
|
||||
{
|
||||
throw new ArgumentNullException("uriString");
|
||||
}
|
||||
int length = uriString.Length;
|
||||
if (length <= 1)
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
int num = uriString.IndexOf(':');
|
||||
if (num < 0)
|
||||
{
|
||||
if (uriString[0] == '/')
|
||||
{
|
||||
this.ParseAsUnixAbsoluteFilePath(uriString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!uriString.StartsWith("\\\\"))
|
||||
{
|
||||
throw new FormatException("URI scheme was not recognized, nor input string is not recognized as an absolute file path.");
|
||||
}
|
||||
this.ParseAsWindowsUNC(uriString);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (num == 1)
|
||||
{
|
||||
if (!char.IsLetter(uriString[0]))
|
||||
{
|
||||
throw new FormatException("URI scheme must start with alphabet character.");
|
||||
}
|
||||
this.ParseAsWindowsAbsoluteFilePath(uriString);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scheme = uriString.Substring(0, num).ToLower(CultureInfo.InvariantCulture);
|
||||
if (!char.IsLetter(this.scheme[0]))
|
||||
{
|
||||
throw new FormatException("URI scheme must start with alphabet character.");
|
||||
}
|
||||
for (int i = 1; i < this.scheme.Length; i++)
|
||||
{
|
||||
if (!char.IsLetterOrDigit(this.scheme, i))
|
||||
{
|
||||
switch (this.scheme[i])
|
||||
{
|
||||
case '+':
|
||||
case '-':
|
||||
case '.':
|
||||
goto IL_132;
|
||||
}
|
||||
throw new FormatException("URI scheme must consist of one of alphabet, digits, '+', '-' or '.' character.");
|
||||
}
|
||||
IL_132:;
|
||||
}
|
||||
uriString = uriString.Substring(num + 1);
|
||||
num = uriString.IndexOf('#');
|
||||
if (!this.IsUnc && num != -1)
|
||||
{
|
||||
this.fragment = uriString.Substring(num);
|
||||
uriString = uriString.Substring(0, num);
|
||||
}
|
||||
num = uriString.IndexOf('?');
|
||||
if (num != -1)
|
||||
{
|
||||
this.query = uriString.Substring(num);
|
||||
uriString = uriString.Substring(0, num);
|
||||
if (!this.userEscaped)
|
||||
{
|
||||
this.query = Uri.EscapeString(this.query);
|
||||
}
|
||||
}
|
||||
bool flag = this.scheme == Uri.UriSchemeFile && uriString.StartsWith("///");
|
||||
if (uriString.StartsWith("//"))
|
||||
{
|
||||
if (uriString.StartsWith("////"))
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
uriString = uriString.TrimStart(new char[] { '/' });
|
||||
if (uriString.Length > 1 && uriString[1] == ':')
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
else if (!Uri.IsPredefinedScheme(this.scheme))
|
||||
{
|
||||
this.path = uriString;
|
||||
this.isOpaquePart = true;
|
||||
return;
|
||||
}
|
||||
num = uriString.IndexOfAny(new char[] { '/' });
|
||||
if (flag)
|
||||
{
|
||||
num = -1;
|
||||
}
|
||||
if (num == -1)
|
||||
{
|
||||
if (this.scheme != Uri.UriSchemeMailto && this.scheme != Uri.UriSchemeNews && this.scheme != Uri.UriSchemeFile)
|
||||
{
|
||||
this.path = "/";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.path = uriString.Substring(num);
|
||||
uriString = uriString.Substring(0, num);
|
||||
}
|
||||
num = uriString.IndexOf("@");
|
||||
if (num != -1)
|
||||
{
|
||||
this.userinfo = uriString.Substring(0, num);
|
||||
uriString = uriString.Remove(0, num + 1);
|
||||
}
|
||||
this.port = -1;
|
||||
num = uriString.LastIndexOf(":");
|
||||
if (flag)
|
||||
{
|
||||
num = -1;
|
||||
}
|
||||
if (num != -1 && num != uriString.Length - 1)
|
||||
{
|
||||
string text = uriString.Remove(0, num + 1);
|
||||
if (text.Length > 1 && text[text.Length - 1] != ']')
|
||||
{
|
||||
try
|
||||
{
|
||||
this.port = (int)uint.Parse(text, CultureInfo.InvariantCulture);
|
||||
uriString = uriString.Substring(0, num);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new FormatException("Invalid URI: invalid port number");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.port == -1)
|
||||
{
|
||||
this.port = Uri.GetDefaultPort(this.scheme);
|
||||
}
|
||||
this.host = uriString;
|
||||
if (flag)
|
||||
{
|
||||
this.path = '/' + uriString;
|
||||
this.host = string.Empty;
|
||||
}
|
||||
else if (this.host.Length == 2 && this.host[1] == ':')
|
||||
{
|
||||
this.path = this.host + this.path;
|
||||
this.host = string.Empty;
|
||||
}
|
||||
else if (this.isUnixFilePath)
|
||||
{
|
||||
uriString = "//" + uriString;
|
||||
this.host = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.host.Length == 0)
|
||||
{
|
||||
throw new FormatException("Invalid URI: The hostname could not be parsed");
|
||||
}
|
||||
if (this.scheme == Uri.UriSchemeFile)
|
||||
{
|
||||
this.isUnc = true;
|
||||
}
|
||||
}
|
||||
if (this.scheme != Uri.UriSchemeMailto && this.scheme != Uri.UriSchemeNews && this.scheme != Uri.UriSchemeFile && this.reduce)
|
||||
{
|
||||
this.path = Uri.Reduce(this.path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000BC8 RID: 3016 RVA: 0x0003557C File Offset: 0x0003377C
|
||||
private static string Reduce(string path)
|
||||
{
|
||||
path = path.Replace('\\', '/');
|
||||
string[] array = path.Split(new char[] { '/' });
|
||||
ArrayList arrayList = new ArrayList();
|
||||
int num = array.Length;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
string text = array[i];
|
||||
if (text.Length != 0 && !(text == "."))
|
||||
{
|
||||
if (text == "..")
|
||||
{
|
||||
if (arrayList.Count == 0)
|
||||
{
|
||||
if (i != 1)
|
||||
{
|
||||
throw new Exception("Invalid path.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
arrayList.RemoveAt(arrayList.Count - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
arrayList.Add(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arrayList.Count == 0)
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
arrayList.Insert(0, string.Empty);
|
||||
string text2 = string.Join("/", (string[])arrayList.ToArray(typeof(string)));
|
||||
if (path.EndsWith("/"))
|
||||
{
|
||||
text2 += '/';
|
||||
}
|
||||
return text2;
|
||||
}
|
||||
|
||||
// Token: 0x06000BC9 RID: 3017 RVA: 0x0003569C File Offset: 0x0003389C
|
||||
internal static string GetSchemeDelimiter(string scheme)
|
||||
{
|
||||
for (int i = 0; i < Uri.schemes.Length; i++)
|
||||
{
|
||||
if (Uri.schemes[i].scheme == scheme)
|
||||
{
|
||||
return Uri.schemes[i].delimiter;
|
||||
}
|
||||
}
|
||||
return Uri.SchemeDelimiter;
|
||||
}
|
||||
|
||||
// Token: 0x06000BCA RID: 3018 RVA: 0x000356F4 File Offset: 0x000338F4
|
||||
internal static int GetDefaultPort(string scheme)
|
||||
{
|
||||
for (int i = 0; i < Uri.schemes.Length; i++)
|
||||
{
|
||||
if (Uri.schemes[i].scheme == scheme)
|
||||
{
|
||||
return Uri.schemes[i].defaultPort;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000BCB RID: 3019 RVA: 0x00035748 File Offset: 0x00033948
|
||||
private string GetOpaqueWiseSchemeDelimiter()
|
||||
{
|
||||
if (this.isOpaquePart)
|
||||
{
|
||||
return ":";
|
||||
}
|
||||
return Uri.GetSchemeDelimiter(this.scheme);
|
||||
}
|
||||
|
||||
// Token: 0x06000BCC RID: 3020 RVA: 0x00035768 File Offset: 0x00033968
|
||||
protected bool IsBadFileSystemCharacter(char ch)
|
||||
{
|
||||
if (ch < ' ' || (ch < '@' && ch > '9'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
switch (ch)
|
||||
{
|
||||
case '*':
|
||||
case ',':
|
||||
case '/':
|
||||
break;
|
||||
default:
|
||||
switch (ch)
|
||||
{
|
||||
case '\\':
|
||||
case '^':
|
||||
break;
|
||||
default:
|
||||
if (ch != '\0' && ch != '"' && ch != '&' && ch != '|')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000BCD RID: 3021 RVA: 0x000357F0 File Offset: 0x000339F0
|
||||
protected static bool IsExcludedCharacter(char ch)
|
||||
{
|
||||
return ch <= ' ' || ch >= '\u007f' || (ch == '"' || ch == '#' || ch == '%' || ch == '<' || ch == '>' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}');
|
||||
}
|
||||
|
||||
// Token: 0x06000BCE RID: 3022 RVA: 0x0003587C File Offset: 0x00033A7C
|
||||
private static bool IsPredefinedScheme(string scheme)
|
||||
{
|
||||
if (scheme != null)
|
||||
{
|
||||
if (Uri.<>f__switch$map17 == null)
|
||||
{
|
||||
Uri.<>f__switch$map17 = new Dictionary<string, int>(8)
|
||||
{
|
||||
{ "http", 0 },
|
||||
{ "https", 0 },
|
||||
{ "file", 0 },
|
||||
{ "ftp", 0 },
|
||||
{ "nntp", 0 },
|
||||
{ "gopher", 0 },
|
||||
{ "mailto", 0 },
|
||||
{ "news", 0 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (Uri.<>f__switch$map17.TryGetValue(scheme, out num))
|
||||
{
|
||||
if (num == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Token: 0x06000BCF RID: 3023 RVA: 0x00035928 File Offset: 0x00033B28
|
||||
protected bool IsReservedCharacter(char ch)
|
||||
{
|
||||
return ch == '$' || ch == '&' || ch == '+' || ch == ',' || ch == '/' || ch == ':' || ch == ';' || ch == '=' || ch == '@';
|
||||
}
|
||||
|
||||
// Token: 0x0400031E RID: 798
|
||||
private bool isUnixFilePath;
|
||||
|
||||
// Token: 0x0400031F RID: 799
|
||||
private string source;
|
||||
|
||||
// Token: 0x04000320 RID: 800
|
||||
private string scheme;
|
||||
|
||||
// Token: 0x04000321 RID: 801
|
||||
private string host;
|
||||
|
||||
// Token: 0x04000322 RID: 802
|
||||
private int port;
|
||||
|
||||
// Token: 0x04000323 RID: 803
|
||||
private string path;
|
||||
|
||||
// Token: 0x04000324 RID: 804
|
||||
private string query;
|
||||
|
||||
// Token: 0x04000325 RID: 805
|
||||
private string fragment;
|
||||
|
||||
// Token: 0x04000326 RID: 806
|
||||
private string userinfo;
|
||||
|
||||
// Token: 0x04000327 RID: 807
|
||||
private bool isUnc;
|
||||
|
||||
// Token: 0x04000328 RID: 808
|
||||
private bool isOpaquePart;
|
||||
|
||||
// Token: 0x04000329 RID: 809
|
||||
private string[] segments;
|
||||
|
||||
// Token: 0x0400032A RID: 810
|
||||
private bool userEscaped;
|
||||
|
||||
// Token: 0x0400032B RID: 811
|
||||
private string cachedAbsoluteUri;
|
||||
|
||||
// Token: 0x0400032C RID: 812
|
||||
private string cachedToString;
|
||||
|
||||
// Token: 0x0400032D RID: 813
|
||||
private string cachedLocalPath;
|
||||
|
||||
// Token: 0x0400032E RID: 814
|
||||
private int cachedHashCode;
|
||||
|
||||
// Token: 0x0400032F RID: 815
|
||||
private bool reduce;
|
||||
|
||||
// Token: 0x04000330 RID: 816
|
||||
private static readonly string hexUpperChars = "0123456789ABCDEF";
|
||||
|
||||
// Token: 0x04000331 RID: 817
|
||||
public static readonly string SchemeDelimiter = "://";
|
||||
|
||||
// Token: 0x04000332 RID: 818
|
||||
public static readonly string UriSchemeFile = "file";
|
||||
|
||||
// Token: 0x04000333 RID: 819
|
||||
public static readonly string UriSchemeFtp = "ftp";
|
||||
|
||||
// Token: 0x04000334 RID: 820
|
||||
public static readonly string UriSchemeGopher = "gopher";
|
||||
|
||||
// Token: 0x04000335 RID: 821
|
||||
public static readonly string UriSchemeHttp = "http";
|
||||
|
||||
// Token: 0x04000336 RID: 822
|
||||
public static readonly string UriSchemeHttps = "https";
|
||||
|
||||
// Token: 0x04000337 RID: 823
|
||||
public static readonly string UriSchemeMailto = "mailto";
|
||||
|
||||
// Token: 0x04000338 RID: 824
|
||||
public static readonly string UriSchemeNews = "news";
|
||||
|
||||
// Token: 0x04000339 RID: 825
|
||||
public static readonly string UriSchemeNntp = "nntp";
|
||||
|
||||
// Token: 0x0400033A RID: 826
|
||||
private static Uri.UriScheme[] schemes = new Uri.UriScheme[]
|
||||
{
|
||||
new Uri.UriScheme(Uri.UriSchemeHttp, Uri.SchemeDelimiter, 80),
|
||||
new Uri.UriScheme(Uri.UriSchemeHttps, Uri.SchemeDelimiter, 443),
|
||||
new Uri.UriScheme(Uri.UriSchemeFtp, Uri.SchemeDelimiter, 21),
|
||||
new Uri.UriScheme(Uri.UriSchemeFile, Uri.SchemeDelimiter, -1),
|
||||
new Uri.UriScheme(Uri.UriSchemeMailto, ":", 25),
|
||||
new Uri.UriScheme(Uri.UriSchemeNews, ":", -1),
|
||||
new Uri.UriScheme(Uri.UriSchemeNntp, Uri.SchemeDelimiter, 119),
|
||||
new Uri.UriScheme(Uri.UriSchemeGopher, Uri.SchemeDelimiter, 70)
|
||||
};
|
||||
|
||||
// Token: 0x020000EC RID: 236
|
||||
private struct UriScheme
|
||||
{
|
||||
// Token: 0x06000BD0 RID: 3024 RVA: 0x00035980 File Offset: 0x00033B80
|
||||
public UriScheme(string s, string d, int p)
|
||||
{
|
||||
this.scheme = s;
|
||||
this.delimiter = d;
|
||||
this.defaultPort = p;
|
||||
}
|
||||
|
||||
// Token: 0x0400033C RID: 828
|
||||
public string scheme;
|
||||
|
||||
// Token: 0x0400033D RID: 829
|
||||
public string delimiter;
|
||||
|
||||
// Token: 0x0400033E RID: 830
|
||||
public int defaultPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security
|
||||
{
|
||||
// Token: 0x020000EA RID: 234
|
||||
internal enum UriPartial
|
||||
{
|
||||
// Token: 0x0400031B RID: 795
|
||||
Scheme,
|
||||
// Token: 0x0400031C RID: 796
|
||||
Authority,
|
||||
// Token: 0x0400031D RID: 797
|
||||
Path
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.X509.Extensions
|
||||
{
|
||||
// Token: 0x020000AF RID: 175
|
||||
internal class BasicConstraintsExtension : X509Extension
|
||||
{
|
||||
// Token: 0x06000994 RID: 2452 RVA: 0x00027844 File Offset: 0x00025A44
|
||||
public BasicConstraintsExtension()
|
||||
{
|
||||
this.extnOid = "2.5.29.19";
|
||||
this.pathLenConstraint = -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000995 RID: 2453 RVA: 0x00027860 File Offset: 0x00025A60
|
||||
public BasicConstraintsExtension(ASN1 asn1)
|
||||
: base(asn1)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000996 RID: 2454 RVA: 0x0002786C File Offset: 0x00025A6C
|
||||
public BasicConstraintsExtension(X509Extension extension)
|
||||
: base(extension)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000997 RID: 2455 RVA: 0x00027878 File Offset: 0x00025A78
|
||||
protected override void Decode()
|
||||
{
|
||||
this.cA = false;
|
||||
this.pathLenConstraint = -1;
|
||||
ASN1 asn = new ASN1(this.extnValue.Value);
|
||||
if (asn.Tag != 48)
|
||||
{
|
||||
throw new ArgumentException("Invalid BasicConstraints extension");
|
||||
}
|
||||
int num = 0;
|
||||
ASN1 asn2 = asn[num++];
|
||||
if (asn2 != null && asn2.Tag == 1)
|
||||
{
|
||||
this.cA = asn2.Value[0] == byte.MaxValue;
|
||||
asn2 = asn[num++];
|
||||
}
|
||||
if (asn2 != null && asn2.Tag == 2)
|
||||
{
|
||||
this.pathLenConstraint = ASN1Convert.ToInt32(asn2);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000998 RID: 2456 RVA: 0x0002791C File Offset: 0x00025B1C
|
||||
protected override void Encode()
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
if (this.cA)
|
||||
{
|
||||
asn.Add(new ASN1(1, new byte[] { byte.MaxValue }));
|
||||
}
|
||||
if (this.cA && this.pathLenConstraint >= 0)
|
||||
{
|
||||
asn.Add(ASN1Convert.FromInt32(this.pathLenConstraint));
|
||||
}
|
||||
this.extnValue = new ASN1(4);
|
||||
this.extnValue.Add(asn);
|
||||
}
|
||||
|
||||
// Token: 0x17000116 RID: 278
|
||||
// (get) Token: 0x06000999 RID: 2457 RVA: 0x0002799C File Offset: 0x00025B9C
|
||||
// (set) Token: 0x0600099A RID: 2458 RVA: 0x000279A4 File Offset: 0x00025BA4
|
||||
public bool CertificateAuthority
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cA;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.cA = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000117 RID: 279
|
||||
// (get) Token: 0x0600099B RID: 2459 RVA: 0x000279B0 File Offset: 0x00025BB0
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Basic Constraints";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000118 RID: 280
|
||||
// (get) Token: 0x0600099C RID: 2460 RVA: 0x000279B8 File Offset: 0x00025BB8
|
||||
// (set) Token: 0x0600099D RID: 2461 RVA: 0x000279C0 File Offset: 0x00025BC0
|
||||
public int PathLenConstraint
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.pathLenConstraint;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < -1)
|
||||
{
|
||||
string text = Locale.GetText("PathLenConstraint must be positive or -1 for none ({0}).", new object[] { value });
|
||||
throw new ArgumentOutOfRangeException(text);
|
||||
}
|
||||
this.pathLenConstraint = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600099E RID: 2462 RVA: 0x000279FC File Offset: 0x00025BFC
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("Subject Type=");
|
||||
stringBuilder.Append((!this.cA) ? "End Entity" : "CA");
|
||||
stringBuilder.Append(Environment.NewLine);
|
||||
stringBuilder.Append("Path Length Constraint=");
|
||||
if (this.pathLenConstraint == -1)
|
||||
{
|
||||
stringBuilder.Append("None");
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(this.pathLenConstraint.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
stringBuilder.Append(Environment.NewLine);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x0400022A RID: 554
|
||||
public const int NoPathLengthConstraint = -1;
|
||||
|
||||
// Token: 0x0400022B RID: 555
|
||||
private bool cA;
|
||||
|
||||
// Token: 0x0400022C RID: 556
|
||||
private int pathLenConstraint;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.X509.Extensions
|
||||
{
|
||||
// Token: 0x020000B1 RID: 177
|
||||
internal class KeyUsageExtension : X509Extension
|
||||
{
|
||||
// Token: 0x0600099F RID: 2463 RVA: 0x00027A9C File Offset: 0x00025C9C
|
||||
public KeyUsageExtension(ASN1 asn1)
|
||||
: base(asn1)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060009A0 RID: 2464 RVA: 0x00027AA8 File Offset: 0x00025CA8
|
||||
public KeyUsageExtension(X509Extension extension)
|
||||
: base(extension)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060009A1 RID: 2465 RVA: 0x00027AB4 File Offset: 0x00025CB4
|
||||
public KeyUsageExtension()
|
||||
{
|
||||
this.extnOid = "2.5.29.15";
|
||||
}
|
||||
|
||||
// Token: 0x060009A2 RID: 2466 RVA: 0x00027AC8 File Offset: 0x00025CC8
|
||||
protected override void Decode()
|
||||
{
|
||||
ASN1 asn = new ASN1(this.extnValue.Value);
|
||||
if (asn.Tag != 3)
|
||||
{
|
||||
throw new ArgumentException("Invalid KeyUsage extension");
|
||||
}
|
||||
int i = 1;
|
||||
while (i < asn.Value.Length)
|
||||
{
|
||||
this.kubits = (this.kubits << 8) + (int)asn.Value[i++];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009A3 RID: 2467 RVA: 0x00027B30 File Offset: 0x00025D30
|
||||
protected override void Encode()
|
||||
{
|
||||
this.extnValue = new ASN1(4);
|
||||
ushort num = (ushort)this.kubits;
|
||||
if (num > 0)
|
||||
{
|
||||
byte b;
|
||||
for (b = 15; b > 0; b -= 1)
|
||||
{
|
||||
if ((num & 32768) == 32768)
|
||||
{
|
||||
break;
|
||||
}
|
||||
num = (ushort)(num << 1);
|
||||
}
|
||||
if (this.kubits > 255)
|
||||
{
|
||||
b -= 8;
|
||||
this.extnValue.Add(new ASN1(3, new byte[]
|
||||
{
|
||||
b,
|
||||
(byte)this.kubits,
|
||||
(byte)(this.kubits >> 8)
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extnValue.Add(new ASN1(3, new byte[]
|
||||
{
|
||||
b,
|
||||
(byte)this.kubits
|
||||
}));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ASN1 extnValue = this.extnValue;
|
||||
byte b2 = 3;
|
||||
byte[] array = new byte[2];
|
||||
array[0] = 7;
|
||||
extnValue.Add(new ASN1(b2, array));
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000119 RID: 281
|
||||
// (get) Token: 0x060009A4 RID: 2468 RVA: 0x00027C20 File Offset: 0x00025E20
|
||||
// (set) Token: 0x060009A5 RID: 2469 RVA: 0x00027C28 File Offset: 0x00025E28
|
||||
public KeyUsages KeyUsage
|
||||
{
|
||||
get
|
||||
{
|
||||
return (KeyUsages)this.kubits;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.kubits = Convert.ToInt32(value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700011A RID: 282
|
||||
// (get) Token: 0x060009A6 RID: 2470 RVA: 0x00027C40 File Offset: 0x00025E40
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Key Usage";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009A7 RID: 2471 RVA: 0x00027C48 File Offset: 0x00025E48
|
||||
public bool Support(KeyUsages usage)
|
||||
{
|
||||
int num = Convert.ToInt32(usage, CultureInfo.InvariantCulture);
|
||||
return (num & this.kubits) == num;
|
||||
}
|
||||
|
||||
// Token: 0x060009A8 RID: 2472 RVA: 0x00027C74 File Offset: 0x00025E74
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (this.Support(KeyUsages.digitalSignature))
|
||||
{
|
||||
stringBuilder.Append("Digital Signature");
|
||||
}
|
||||
if (this.Support(KeyUsages.nonRepudiation))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Non-Repudiation");
|
||||
}
|
||||
if (this.Support(KeyUsages.keyEncipherment))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Key Encipherment");
|
||||
}
|
||||
if (this.Support(KeyUsages.dataEncipherment))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Data Encipherment");
|
||||
}
|
||||
if (this.Support(KeyUsages.keyAgreement))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Key Agreement");
|
||||
}
|
||||
if (this.Support(KeyUsages.keyCertSign))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Certificate Signing");
|
||||
}
|
||||
if (this.Support(KeyUsages.cRLSign))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("CRL Signing");
|
||||
}
|
||||
if (this.Support(KeyUsages.encipherOnly))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Encipher Only ");
|
||||
}
|
||||
if (this.Support(KeyUsages.decipherOnly))
|
||||
{
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(" , ");
|
||||
}
|
||||
stringBuilder.Append("Decipher Only");
|
||||
}
|
||||
stringBuilder.Append("(");
|
||||
stringBuilder.Append(this.kubits.ToString("X2", CultureInfo.InvariantCulture));
|
||||
stringBuilder.Append(")");
|
||||
stringBuilder.Append(Environment.NewLine);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x04000238 RID: 568
|
||||
private int kubits;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.X509.Extensions
|
||||
{
|
||||
// Token: 0x020000B0 RID: 176
|
||||
[Flags]
|
||||
internal enum KeyUsages
|
||||
{
|
||||
// Token: 0x0400022E RID: 558
|
||||
digitalSignature = 128,
|
||||
// Token: 0x0400022F RID: 559
|
||||
nonRepudiation = 64,
|
||||
// Token: 0x04000230 RID: 560
|
||||
keyEncipherment = 32,
|
||||
// Token: 0x04000231 RID: 561
|
||||
dataEncipherment = 16,
|
||||
// Token: 0x04000232 RID: 562
|
||||
keyAgreement = 8,
|
||||
// Token: 0x04000233 RID: 563
|
||||
keyCertSign = 4,
|
||||
// Token: 0x04000234 RID: 564
|
||||
cRLSign = 2,
|
||||
// Token: 0x04000235 RID: 565
|
||||
encipherOnly = 1,
|
||||
// Token: 0x04000236 RID: 566
|
||||
decipherOnly = 2048,
|
||||
// Token: 0x04000237 RID: 567
|
||||
none = 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.X509.Extensions
|
||||
{
|
||||
// Token: 0x020000B2 RID: 178
|
||||
internal class SubjectKeyIdentifierExtension : X509Extension
|
||||
{
|
||||
// Token: 0x060009A9 RID: 2473 RVA: 0x00027E70 File Offset: 0x00026070
|
||||
public SubjectKeyIdentifierExtension()
|
||||
{
|
||||
this.extnOid = "2.5.29.14";
|
||||
}
|
||||
|
||||
// Token: 0x060009AA RID: 2474 RVA: 0x00027E84 File Offset: 0x00026084
|
||||
public SubjectKeyIdentifierExtension(ASN1 asn1)
|
||||
: base(asn1)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060009AB RID: 2475 RVA: 0x00027E90 File Offset: 0x00026090
|
||||
public SubjectKeyIdentifierExtension(X509Extension extension)
|
||||
: base(extension)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060009AC RID: 2476 RVA: 0x00027E9C File Offset: 0x0002609C
|
||||
protected override void Decode()
|
||||
{
|
||||
ASN1 asn = new ASN1(this.extnValue.Value);
|
||||
if (asn.Tag != 4)
|
||||
{
|
||||
throw new ArgumentException("Invalid SubjectKeyIdentifier extension");
|
||||
}
|
||||
this.ski = asn.Value;
|
||||
}
|
||||
|
||||
// Token: 0x1700011B RID: 283
|
||||
// (get) Token: 0x060009AD RID: 2477 RVA: 0x00027EE0 File Offset: 0x000260E0
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Subject Key Identifier";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700011C RID: 284
|
||||
// (get) Token: 0x060009AE RID: 2478 RVA: 0x00027EE8 File Offset: 0x000260E8
|
||||
public byte[] Identifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ski == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.ski.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009AF RID: 2479 RVA: 0x00027F08 File Offset: 0x00026108
|
||||
public override string ToString()
|
||||
{
|
||||
if (this.ski == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < this.ski.Length; i++)
|
||||
{
|
||||
stringBuilder.Append(this.ski[i].ToString("X2", CultureInfo.InvariantCulture));
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
stringBuilder.Append(" ");
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x04000239 RID: 569
|
||||
private byte[] ski;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2347 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000B6 RID: 182
|
||||
internal class PKCS12 : ICloneable
|
||||
{
|
||||
// Token: 0x060009B5 RID: 2485 RVA: 0x00027FB8 File Offset: 0x000261B8
|
||||
public PKCS12()
|
||||
{
|
||||
this._iterations = PKCS12.recommendedIterationCount;
|
||||
this._keyBags = new ArrayList();
|
||||
this._secretBags = new ArrayList();
|
||||
this._certs = new X509CertificateCollection();
|
||||
this._keyBagsChanged = false;
|
||||
this._secretBagsChanged = false;
|
||||
this._certsChanged = false;
|
||||
this._safeBags = new ArrayList();
|
||||
}
|
||||
|
||||
// Token: 0x060009B6 RID: 2486 RVA: 0x00028018 File Offset: 0x00026218
|
||||
public PKCS12(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Password = null;
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x060009B7 RID: 2487 RVA: 0x00028030 File Offset: 0x00026230
|
||||
public PKCS12(byte[] data, string password)
|
||||
: this()
|
||||
{
|
||||
this.Password = password;
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x060009B8 RID: 2488 RVA: 0x00028048 File Offset: 0x00026248
|
||||
public PKCS12(byte[] data, byte[] password)
|
||||
: this()
|
||||
{
|
||||
this._password = password;
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x060009BA RID: 2490 RVA: 0x00028078 File Offset: 0x00026278
|
||||
private void Decode(byte[] data)
|
||||
{
|
||||
ASN1 asn = new ASN1(data);
|
||||
if (asn.Tag != 48)
|
||||
{
|
||||
throw new ArgumentException("invalid data");
|
||||
}
|
||||
ASN1 asn2 = asn[0];
|
||||
if (asn2.Tag != 2)
|
||||
{
|
||||
throw new ArgumentException("invalid PFX version");
|
||||
}
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn[1]);
|
||||
if (contentInfo.ContentType != "1.2.840.113549.1.7.1")
|
||||
{
|
||||
throw new ArgumentException("invalid authenticated safe");
|
||||
}
|
||||
if (asn.Count > 2)
|
||||
{
|
||||
ASN1 asn3 = asn[2];
|
||||
if (asn3.Tag != 48)
|
||||
{
|
||||
throw new ArgumentException("invalid MAC");
|
||||
}
|
||||
ASN1 asn4 = asn3[0];
|
||||
if (asn4.Tag != 48)
|
||||
{
|
||||
throw new ArgumentException("invalid MAC");
|
||||
}
|
||||
ASN1 asn5 = asn4[0];
|
||||
string text = ASN1Convert.ToOid(asn5[0]);
|
||||
if (text != "1.3.14.3.2.26")
|
||||
{
|
||||
throw new ArgumentException("unsupported HMAC");
|
||||
}
|
||||
byte[] value = asn4[1].Value;
|
||||
ASN1 asn6 = asn3[1];
|
||||
if (asn6.Tag != 4)
|
||||
{
|
||||
throw new ArgumentException("missing MAC salt");
|
||||
}
|
||||
this._iterations = 1;
|
||||
if (asn3.Count > 2)
|
||||
{
|
||||
ASN1 asn7 = asn3[2];
|
||||
if (asn7.Tag != 2)
|
||||
{
|
||||
throw new ArgumentException("invalid MAC iteration");
|
||||
}
|
||||
this._iterations = ASN1Convert.ToInt32(asn7);
|
||||
}
|
||||
byte[] value2 = contentInfo.Content[0].Value;
|
||||
byte[] array = this.MAC(this._password, asn6.Value, this._iterations, value2);
|
||||
if (!this.Compare(value, array))
|
||||
{
|
||||
throw new CryptographicException("Invalid MAC - file may have been tampered!");
|
||||
}
|
||||
}
|
||||
ASN1 asn8 = new ASN1(contentInfo.Content[0].Value);
|
||||
int i = 0;
|
||||
while (i < asn8.Count)
|
||||
{
|
||||
PKCS7.ContentInfo contentInfo2 = new PKCS7.ContentInfo(asn8[i]);
|
||||
string contentType = contentInfo2.ContentType;
|
||||
if (contentType != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$map8 == null)
|
||||
{
|
||||
PKCS12.<>f__switch$map8 = new Dictionary<string, int>(3)
|
||||
{
|
||||
{ "1.2.840.113549.1.7.1", 0 },
|
||||
{ "1.2.840.113549.1.7.6", 1 },
|
||||
{ "1.2.840.113549.1.7.3", 2 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (PKCS12.<>f__switch$map8.TryGetValue(contentType, out num))
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
ASN1 asn9 = new ASN1(contentInfo2.Content[0].Value);
|
||||
for (int j = 0; j < asn9.Count; j++)
|
||||
{
|
||||
ASN1 asn10 = asn9[j];
|
||||
this.ReadSafeBag(asn10);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
PKCS7.EncryptedData encryptedData = new PKCS7.EncryptedData(contentInfo2.Content[0]);
|
||||
ASN1 asn11 = new ASN1(this.Decrypt(encryptedData));
|
||||
for (int k = 0; k < asn11.Count; k++)
|
||||
{
|
||||
ASN1 asn12 = asn11[k];
|
||||
this.ReadSafeBag(asn12);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
throw new NotImplementedException("public key encrypted");
|
||||
default:
|
||||
goto IL_303;
|
||||
}
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
IL_303:
|
||||
throw new ArgumentException("unknown authenticatedSafe");
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009BB RID: 2491 RVA: 0x000283A8 File Offset: 0x000265A8
|
||||
~PKCS12()
|
||||
{
|
||||
if (this._password != null)
|
||||
{
|
||||
Array.Clear(this._password, 0, this._password.Length);
|
||||
}
|
||||
this._password = null;
|
||||
}
|
||||
|
||||
// Token: 0x1700011F RID: 287
|
||||
// (set) Token: 0x060009BC RID: 2492 RVA: 0x00028404 File Offset: 0x00026604
|
||||
public string Password
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (value.Length > 0)
|
||||
{
|
||||
int num = value.Length;
|
||||
int num2 = 0;
|
||||
if (num < PKCS12.MaximumPasswordLength)
|
||||
{
|
||||
if (value[num - 1] != '\0')
|
||||
{
|
||||
num2 = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num = PKCS12.MaximumPasswordLength;
|
||||
}
|
||||
this._password = new byte[num + num2 << 1];
|
||||
Encoding.BigEndianUnicode.GetBytes(value, 0, num, this._password, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._password = new byte[2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._password = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000120 RID: 288
|
||||
// (get) Token: 0x060009BD RID: 2493 RVA: 0x00028494 File Offset: 0x00026694
|
||||
// (set) Token: 0x060009BE RID: 2494 RVA: 0x0002849C File Offset: 0x0002669C
|
||||
public int IterationCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._iterations;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._iterations = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000121 RID: 289
|
||||
// (get) Token: 0x060009BF RID: 2495 RVA: 0x000284A8 File Offset: 0x000266A8
|
||||
public ArrayList Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._keyBagsChanged)
|
||||
{
|
||||
this._keyBags.Clear();
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(asn2.Value);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b == 48)
|
||||
{
|
||||
this._keyBags.Add(PKCS8.PrivateKeyInfo.DecodeRSA(privateKey));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DSAParameters dsaparameters = default(DSAParameters);
|
||||
this._keyBags.Add(PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, dsaparameters));
|
||||
}
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
}
|
||||
else if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
ASN1 asn3 = safeBag.ASN1;
|
||||
ASN1 asn4 = asn3[1];
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(asn4.Value);
|
||||
byte[] array = this.Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo2 = new PKCS8.PrivateKeyInfo(array);
|
||||
byte[] privateKey2 = privateKeyInfo2.PrivateKey;
|
||||
byte b = privateKey2[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b == 48)
|
||||
{
|
||||
this._keyBags.Add(PKCS8.PrivateKeyInfo.DecodeRSA(privateKey2));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DSAParameters dsaparameters2 = default(DSAParameters);
|
||||
this._keyBags.Add(PKCS8.PrivateKeyInfo.DecodeDSA(privateKey2, dsaparameters2));
|
||||
}
|
||||
Array.Clear(privateKey2, 0, privateKey2.Length);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
}
|
||||
}
|
||||
this._keyBagsChanged = false;
|
||||
}
|
||||
return ArrayList.ReadOnly(this._keyBags);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000122 RID: 290
|
||||
// (get) Token: 0x060009C0 RID: 2496 RVA: 0x000286C0 File Offset: 0x000268C0
|
||||
public ArrayList Secrets
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._secretBagsChanged)
|
||||
{
|
||||
this._secretBags.Clear();
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.5"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
byte[] value = asn2.Value;
|
||||
this._secretBags.Add(value);
|
||||
}
|
||||
}
|
||||
this._secretBagsChanged = false;
|
||||
}
|
||||
return ArrayList.ReadOnly(this._secretBags);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000123 RID: 291
|
||||
// (get) Token: 0x060009C1 RID: 2497 RVA: 0x00028790 File Offset: 0x00026990
|
||||
public X509CertificateCollection Certificates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._certsChanged)
|
||||
{
|
||||
this._certs.Clear();
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn2.Value);
|
||||
this._certs.Add(new X509Certificate(contentInfo.Content[0].Value));
|
||||
}
|
||||
}
|
||||
this._certsChanged = false;
|
||||
}
|
||||
return this._certs;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000124 RID: 292
|
||||
// (get) Token: 0x060009C2 RID: 2498 RVA: 0x00028874 File Offset: 0x00026A74
|
||||
internal RandomNumberGenerator RNG
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._rng == null)
|
||||
{
|
||||
this._rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
return this._rng;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009C3 RID: 2499 RVA: 0x00028894 File Offset: 0x00026A94
|
||||
private bool Compare(byte[] expected, byte[] actual)
|
||||
{
|
||||
bool flag = false;
|
||||
if (expected.Length == actual.Length)
|
||||
{
|
||||
for (int i = 0; i < expected.Length; i++)
|
||||
{
|
||||
if (expected[i] != actual[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x060009C4 RID: 2500 RVA: 0x000288D4 File Offset: 0x00026AD4
|
||||
private SymmetricAlgorithm GetSymmetricAlgorithm(string algorithmOid, byte[] salt, int iterationCount)
|
||||
{
|
||||
string text = null;
|
||||
int num = 8;
|
||||
int num2 = 8;
|
||||
PKCS12.DeriveBytes deriveBytes = new PKCS12.DeriveBytes();
|
||||
deriveBytes.Password = this._password;
|
||||
deriveBytes.Salt = salt;
|
||||
deriveBytes.IterationCount = iterationCount;
|
||||
if (algorithmOid != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$map9 == null)
|
||||
{
|
||||
PKCS12.<>f__switch$map9 = new Dictionary<string, int>(12)
|
||||
{
|
||||
{ "1.2.840.113549.1.5.1", 0 },
|
||||
{ "1.2.840.113549.1.5.3", 1 },
|
||||
{ "1.2.840.113549.1.5.4", 2 },
|
||||
{ "1.2.840.113549.1.5.6", 3 },
|
||||
{ "1.2.840.113549.1.5.10", 4 },
|
||||
{ "1.2.840.113549.1.5.11", 5 },
|
||||
{ "1.2.840.113549.1.12.1.1", 6 },
|
||||
{ "1.2.840.113549.1.12.1.2", 7 },
|
||||
{ "1.2.840.113549.1.12.1.3", 8 },
|
||||
{ "1.2.840.113549.1.12.1.4", 9 },
|
||||
{ "1.2.840.113549.1.12.1.5", 10 },
|
||||
{ "1.2.840.113549.1.12.1.6", 11 }
|
||||
};
|
||||
}
|
||||
int num3;
|
||||
if (PKCS12.<>f__switch$map9.TryGetValue(algorithmOid, out num3))
|
||||
{
|
||||
switch (num3)
|
||||
{
|
||||
case 0:
|
||||
deriveBytes.HashName = "MD2";
|
||||
text = "DES";
|
||||
break;
|
||||
case 1:
|
||||
deriveBytes.HashName = "MD5";
|
||||
text = "DES";
|
||||
break;
|
||||
case 2:
|
||||
deriveBytes.HashName = "MD2";
|
||||
text = "RC2";
|
||||
num = 4;
|
||||
break;
|
||||
case 3:
|
||||
deriveBytes.HashName = "MD5";
|
||||
text = "RC2";
|
||||
num = 4;
|
||||
break;
|
||||
case 4:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "DES";
|
||||
break;
|
||||
case 5:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "RC2";
|
||||
num = 4;
|
||||
break;
|
||||
case 6:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "RC4";
|
||||
num = 16;
|
||||
num2 = 0;
|
||||
break;
|
||||
case 7:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "RC4";
|
||||
num = 5;
|
||||
num2 = 0;
|
||||
break;
|
||||
case 8:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "TripleDES";
|
||||
num = 24;
|
||||
break;
|
||||
case 9:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "TripleDES";
|
||||
num = 16;
|
||||
break;
|
||||
case 10:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "RC2";
|
||||
num = 16;
|
||||
break;
|
||||
case 11:
|
||||
deriveBytes.HashName = "SHA1";
|
||||
text = "RC2";
|
||||
num = 5;
|
||||
break;
|
||||
default:
|
||||
goto IL_25A;
|
||||
}
|
||||
SymmetricAlgorithm symmetricAlgorithm = SymmetricAlgorithm.Create(text);
|
||||
symmetricAlgorithm.Key = deriveBytes.DeriveKey(num);
|
||||
if (num2 > 0)
|
||||
{
|
||||
symmetricAlgorithm.IV = deriveBytes.DeriveIV(num2);
|
||||
symmetricAlgorithm.Mode = CipherMode.CBC;
|
||||
}
|
||||
return symmetricAlgorithm;
|
||||
}
|
||||
}
|
||||
IL_25A:
|
||||
throw new NotSupportedException("unknown oid " + text);
|
||||
}
|
||||
|
||||
// Token: 0x060009C5 RID: 2501 RVA: 0x00028B84 File Offset: 0x00026D84
|
||||
public byte[] Decrypt(string algorithmOid, byte[] salt, int iterationCount, byte[] encryptedData)
|
||||
{
|
||||
SymmetricAlgorithm symmetricAlgorithm = null;
|
||||
byte[] array = null;
|
||||
try
|
||||
{
|
||||
symmetricAlgorithm = this.GetSymmetricAlgorithm(algorithmOid, salt, iterationCount);
|
||||
ICryptoTransform cryptoTransform = symmetricAlgorithm.CreateDecryptor();
|
||||
array = cryptoTransform.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (symmetricAlgorithm != null)
|
||||
{
|
||||
symmetricAlgorithm.Clear();
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060009C6 RID: 2502 RVA: 0x00028BE4 File Offset: 0x00026DE4
|
||||
public byte[] Decrypt(PKCS7.EncryptedData ed)
|
||||
{
|
||||
return this.Decrypt(ed.EncryptionAlgorithm.ContentType, ed.EncryptionAlgorithm.Content[0].Value, ASN1Convert.ToInt32(ed.EncryptionAlgorithm.Content[1]), ed.EncryptedContent);
|
||||
}
|
||||
|
||||
// Token: 0x060009C7 RID: 2503 RVA: 0x00028C34 File Offset: 0x00026E34
|
||||
public byte[] Encrypt(string algorithmOid, byte[] salt, int iterationCount, byte[] data)
|
||||
{
|
||||
byte[] array = null;
|
||||
using (SymmetricAlgorithm symmetricAlgorithm = this.GetSymmetricAlgorithm(algorithmOid, salt, iterationCount))
|
||||
{
|
||||
ICryptoTransform cryptoTransform = symmetricAlgorithm.CreateEncryptor();
|
||||
array = cryptoTransform.TransformFinalBlock(data, 0, data.Length);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060009C8 RID: 2504 RVA: 0x00028C94 File Offset: 0x00026E94
|
||||
private DSAParameters GetExistingParameters(out bool found)
|
||||
{
|
||||
foreach (X509Certificate x509Certificate in this.Certificates)
|
||||
{
|
||||
if (x509Certificate.KeyAlgorithmParameters != null)
|
||||
{
|
||||
DSA dsa = x509Certificate.DSA;
|
||||
if (dsa != null)
|
||||
{
|
||||
found = true;
|
||||
return dsa.ExportParameters(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
found = false;
|
||||
return default(DSAParameters);
|
||||
}
|
||||
|
||||
// Token: 0x060009C9 RID: 2505 RVA: 0x00028D34 File Offset: 0x00026F34
|
||||
private void AddPrivateKey(PKCS8.PrivateKeyInfo pki)
|
||||
{
|
||||
byte[] privateKey = pki.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b != 48)
|
||||
{
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
throw new CryptographicException("Unknown private key format");
|
||||
}
|
||||
this._keyBags.Add(PKCS8.PrivateKeyInfo.DecodeRSA(privateKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag;
|
||||
DSAParameters existingParameters = this.GetExistingParameters(out flag);
|
||||
if (flag)
|
||||
{
|
||||
this._keyBags.Add(PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, existingParameters));
|
||||
}
|
||||
}
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
}
|
||||
|
||||
// Token: 0x060009CA RID: 2506 RVA: 0x00028DC0 File Offset: 0x00026FC0
|
||||
private void ReadSafeBag(ASN1 safeBag)
|
||||
{
|
||||
if (safeBag.Tag != 48)
|
||||
{
|
||||
throw new ArgumentException("invalid safeBag");
|
||||
}
|
||||
ASN1 asn = safeBag[0];
|
||||
if (asn.Tag != 6)
|
||||
{
|
||||
throw new ArgumentException("invalid safeBag id");
|
||||
}
|
||||
ASN1 asn2 = safeBag[1];
|
||||
string text = ASN1Convert.ToOid(asn);
|
||||
string text2 = text;
|
||||
if (text2 != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$mapA == null)
|
||||
{
|
||||
PKCS12.<>f__switch$mapA = new Dictionary<string, int>(6)
|
||||
{
|
||||
{ "1.2.840.113549.1.12.10.1.1", 0 },
|
||||
{ "1.2.840.113549.1.12.10.1.2", 1 },
|
||||
{ "1.2.840.113549.1.12.10.1.3", 2 },
|
||||
{ "1.2.840.113549.1.12.10.1.4", 3 },
|
||||
{ "1.2.840.113549.1.12.10.1.5", 4 },
|
||||
{ "1.2.840.113549.1.12.10.1.6", 5 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (PKCS12.<>f__switch$mapA.TryGetValue(text2, out num))
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
case 0:
|
||||
this.AddPrivateKey(new PKCS8.PrivateKeyInfo(asn2.Value));
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(asn2.Value);
|
||||
byte[] array = this.Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
|
||||
this.AddPrivateKey(new PKCS8.PrivateKeyInfo(array));
|
||||
Array.Clear(array, 0, array.Length);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn2.Value);
|
||||
if (contentInfo.ContentType != "1.2.840.113549.1.9.22.1")
|
||||
{
|
||||
throw new NotSupportedException("unsupport certificate type");
|
||||
}
|
||||
X509Certificate x509Certificate = new X509Certificate(contentInfo.Content[0].Value);
|
||||
this._certs.Add(x509Certificate);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
byte[] value = asn2.Value;
|
||||
this._secretBags.Add(value);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
break;
|
||||
default:
|
||||
goto IL_1CD;
|
||||
}
|
||||
if (safeBag.Count > 2)
|
||||
{
|
||||
ASN1 asn3 = safeBag[2];
|
||||
if (asn3.Tag != 49)
|
||||
{
|
||||
throw new ArgumentException("invalid safeBag attributes id");
|
||||
}
|
||||
for (int i = 0; i < asn3.Count; i++)
|
||||
{
|
||||
ASN1 asn4 = asn3[i];
|
||||
if (asn4.Tag != 48)
|
||||
{
|
||||
throw new ArgumentException("invalid PKCS12 attributes id");
|
||||
}
|
||||
ASN1 asn5 = asn4[0];
|
||||
if (asn5.Tag != 6)
|
||||
{
|
||||
throw new ArgumentException("invalid attribute id");
|
||||
}
|
||||
string text3 = ASN1Convert.ToOid(asn5);
|
||||
ASN1 asn6 = asn4[1];
|
||||
int j = 0;
|
||||
while (j < asn6.Count)
|
||||
{
|
||||
ASN1 asn7 = asn6[j];
|
||||
text2 = text3;
|
||||
if (text2 != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$mapB == null)
|
||||
{
|
||||
PKCS12.<>f__switch$mapB = new Dictionary<string, int>(2)
|
||||
{
|
||||
{ "1.2.840.113549.1.9.20", 0 },
|
||||
{ "1.2.840.113549.1.9.21", 1 }
|
||||
};
|
||||
}
|
||||
if (PKCS12.<>f__switch$mapB.TryGetValue(text2, out num))
|
||||
{
|
||||
if (num != 0)
|
||||
{
|
||||
if (num == 1)
|
||||
{
|
||||
if (asn7.Tag != 4)
|
||||
{
|
||||
throw new ArgumentException("invalid attribute value id");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (asn7.Tag != 30)
|
||||
{
|
||||
throw new ArgumentException("invalid attribute value id");
|
||||
}
|
||||
}
|
||||
}
|
||||
IL_31F:
|
||||
j++;
|
||||
continue;
|
||||
goto IL_31F;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._safeBags.Add(new SafeBag(text, safeBag));
|
||||
return;
|
||||
}
|
||||
}
|
||||
IL_1CD:
|
||||
throw new ArgumentException("unknown safeBag oid");
|
||||
}
|
||||
|
||||
// Token: 0x060009CB RID: 2507 RVA: 0x00029128 File Offset: 0x00027328
|
||||
private ASN1 Pkcs8ShroudedKeyBagSafeBag(AsymmetricAlgorithm aa, IDictionary attributes)
|
||||
{
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo();
|
||||
if (aa is RSA)
|
||||
{
|
||||
privateKeyInfo.Algorithm = "1.2.840.113549.1.1.1";
|
||||
privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((RSA)aa);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(aa is DSA))
|
||||
{
|
||||
throw new CryptographicException("Unknown asymmetric algorithm {0}", aa.ToString());
|
||||
}
|
||||
privateKeyInfo.Algorithm = null;
|
||||
privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((DSA)aa);
|
||||
}
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo();
|
||||
encryptedPrivateKeyInfo.Algorithm = "1.2.840.113549.1.12.1.3";
|
||||
encryptedPrivateKeyInfo.IterationCount = this._iterations;
|
||||
encryptedPrivateKeyInfo.EncryptedData = this.Encrypt("1.2.840.113549.1.12.1.3", encryptedPrivateKeyInfo.Salt, this._iterations, privateKeyInfo.GetBytes());
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.2"));
|
||||
ASN1 asn2 = new ASN1(160);
|
||||
asn2.Add(new ASN1(encryptedPrivateKeyInfo.GetBytes()));
|
||||
asn.Add(asn2);
|
||||
if (attributes != null)
|
||||
{
|
||||
ASN1 asn3 = new ASN1(49);
|
||||
IDictionaryEnumerator enumerator = attributes.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
string text = (string)enumerator.Key;
|
||||
string text2 = text;
|
||||
if (text2 != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$mapC == null)
|
||||
{
|
||||
PKCS12.<>f__switch$mapC = new Dictionary<string, int>(2)
|
||||
{
|
||||
{ "1.2.840.113549.1.9.20", 0 },
|
||||
{ "1.2.840.113549.1.9.21", 1 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (PKCS12.<>f__switch$mapC.TryGetValue(text2, out num))
|
||||
{
|
||||
if (num != 0)
|
||||
{
|
||||
if (num == 1)
|
||||
{
|
||||
ArrayList arrayList = (ArrayList)enumerator.Value;
|
||||
if (arrayList.Count > 0)
|
||||
{
|
||||
ASN1 asn4 = new ASN1(48);
|
||||
asn4.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
|
||||
ASN1 asn5 = new ASN1(49);
|
||||
foreach (object obj in arrayList)
|
||||
{
|
||||
byte[] array = (byte[])obj;
|
||||
asn5.Add(new ASN1(4)
|
||||
{
|
||||
Value = array
|
||||
});
|
||||
}
|
||||
asn4.Add(asn5);
|
||||
asn3.Add(asn4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList arrayList2 = (ArrayList)enumerator.Value;
|
||||
if (arrayList2.Count > 0)
|
||||
{
|
||||
ASN1 asn6 = new ASN1(48);
|
||||
asn6.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
|
||||
ASN1 asn7 = new ASN1(49);
|
||||
foreach (object obj2 in arrayList2)
|
||||
{
|
||||
byte[] array2 = (byte[])obj2;
|
||||
asn7.Add(new ASN1(30)
|
||||
{
|
||||
Value = array2
|
||||
});
|
||||
}
|
||||
asn6.Add(asn7);
|
||||
asn3.Add(asn6);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (asn3.Count > 0)
|
||||
{
|
||||
asn.Add(asn3);
|
||||
}
|
||||
}
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x060009CC RID: 2508 RVA: 0x00029478 File Offset: 0x00027678
|
||||
private ASN1 KeyBagSafeBag(AsymmetricAlgorithm aa, IDictionary attributes)
|
||||
{
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo();
|
||||
if (aa is RSA)
|
||||
{
|
||||
privateKeyInfo.Algorithm = "1.2.840.113549.1.1.1";
|
||||
privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((RSA)aa);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(aa is DSA))
|
||||
{
|
||||
throw new CryptographicException("Unknown asymmetric algorithm {0}", aa.ToString());
|
||||
}
|
||||
privateKeyInfo.Algorithm = null;
|
||||
privateKeyInfo.PrivateKey = PKCS8.PrivateKeyInfo.Encode((DSA)aa);
|
||||
}
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.1"));
|
||||
ASN1 asn2 = new ASN1(160);
|
||||
asn2.Add(new ASN1(privateKeyInfo.GetBytes()));
|
||||
asn.Add(asn2);
|
||||
if (attributes != null)
|
||||
{
|
||||
ASN1 asn3 = new ASN1(49);
|
||||
IDictionaryEnumerator enumerator = attributes.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
string text = (string)enumerator.Key;
|
||||
string text2 = text;
|
||||
if (text2 != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$mapD == null)
|
||||
{
|
||||
PKCS12.<>f__switch$mapD = new Dictionary<string, int>(2)
|
||||
{
|
||||
{ "1.2.840.113549.1.9.20", 0 },
|
||||
{ "1.2.840.113549.1.9.21", 1 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (PKCS12.<>f__switch$mapD.TryGetValue(text2, out num))
|
||||
{
|
||||
if (num != 0)
|
||||
{
|
||||
if (num == 1)
|
||||
{
|
||||
ArrayList arrayList = (ArrayList)enumerator.Value;
|
||||
if (arrayList.Count > 0)
|
||||
{
|
||||
ASN1 asn4 = new ASN1(48);
|
||||
asn4.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
|
||||
ASN1 asn5 = new ASN1(49);
|
||||
foreach (object obj in arrayList)
|
||||
{
|
||||
byte[] array = (byte[])obj;
|
||||
asn5.Add(new ASN1(4)
|
||||
{
|
||||
Value = array
|
||||
});
|
||||
}
|
||||
asn4.Add(asn5);
|
||||
asn3.Add(asn4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList arrayList2 = (ArrayList)enumerator.Value;
|
||||
if (arrayList2.Count > 0)
|
||||
{
|
||||
ASN1 asn6 = new ASN1(48);
|
||||
asn6.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
|
||||
ASN1 asn7 = new ASN1(49);
|
||||
foreach (object obj2 in arrayList2)
|
||||
{
|
||||
byte[] array2 = (byte[])obj2;
|
||||
asn7.Add(new ASN1(30)
|
||||
{
|
||||
Value = array2
|
||||
});
|
||||
}
|
||||
asn6.Add(asn7);
|
||||
asn3.Add(asn6);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (asn3.Count > 0)
|
||||
{
|
||||
asn.Add(asn3);
|
||||
}
|
||||
}
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x060009CD RID: 2509 RVA: 0x00029784 File Offset: 0x00027984
|
||||
private ASN1 SecretBagSafeBag(byte[] secret, IDictionary attributes)
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.5"));
|
||||
ASN1 asn2 = new ASN1(128, secret);
|
||||
asn.Add(asn2);
|
||||
if (attributes != null)
|
||||
{
|
||||
ASN1 asn3 = new ASN1(49);
|
||||
IDictionaryEnumerator enumerator = attributes.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
string text = (string)enumerator.Key;
|
||||
string text2 = text;
|
||||
if (text2 != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$mapE == null)
|
||||
{
|
||||
PKCS12.<>f__switch$mapE = new Dictionary<string, int>(2)
|
||||
{
|
||||
{ "1.2.840.113549.1.9.20", 0 },
|
||||
{ "1.2.840.113549.1.9.21", 1 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (PKCS12.<>f__switch$mapE.TryGetValue(text2, out num))
|
||||
{
|
||||
if (num != 0)
|
||||
{
|
||||
if (num == 1)
|
||||
{
|
||||
ArrayList arrayList = (ArrayList)enumerator.Value;
|
||||
if (arrayList.Count > 0)
|
||||
{
|
||||
ASN1 asn4 = new ASN1(48);
|
||||
asn4.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
|
||||
ASN1 asn5 = new ASN1(49);
|
||||
foreach (object obj in arrayList)
|
||||
{
|
||||
byte[] array = (byte[])obj;
|
||||
asn5.Add(new ASN1(4)
|
||||
{
|
||||
Value = array
|
||||
});
|
||||
}
|
||||
asn4.Add(asn5);
|
||||
asn3.Add(asn4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList arrayList2 = (ArrayList)enumerator.Value;
|
||||
if (arrayList2.Count > 0)
|
||||
{
|
||||
ASN1 asn6 = new ASN1(48);
|
||||
asn6.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
|
||||
ASN1 asn7 = new ASN1(49);
|
||||
foreach (object obj2 in arrayList2)
|
||||
{
|
||||
byte[] array2 = (byte[])obj2;
|
||||
asn7.Add(new ASN1(30)
|
||||
{
|
||||
Value = array2
|
||||
});
|
||||
}
|
||||
asn6.Add(asn7);
|
||||
asn3.Add(asn6);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (asn3.Count > 0)
|
||||
{
|
||||
asn.Add(asn3);
|
||||
}
|
||||
}
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x060009CE RID: 2510 RVA: 0x00029A0C File Offset: 0x00027C0C
|
||||
private ASN1 CertificateSafeBag(X509Certificate x509, IDictionary attributes)
|
||||
{
|
||||
ASN1 asn = new ASN1(4, x509.RawData);
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo();
|
||||
contentInfo.ContentType = "1.2.840.113549.1.9.22.1";
|
||||
contentInfo.Content.Add(asn);
|
||||
ASN1 asn2 = new ASN1(160);
|
||||
asn2.Add(contentInfo.ASN1);
|
||||
ASN1 asn3 = new ASN1(48);
|
||||
asn3.Add(ASN1Convert.FromOid("1.2.840.113549.1.12.10.1.3"));
|
||||
asn3.Add(asn2);
|
||||
if (attributes != null)
|
||||
{
|
||||
ASN1 asn4 = new ASN1(49);
|
||||
IDictionaryEnumerator enumerator = attributes.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
string text = (string)enumerator.Key;
|
||||
string text2 = text;
|
||||
if (text2 != null)
|
||||
{
|
||||
if (PKCS12.<>f__switch$mapF == null)
|
||||
{
|
||||
PKCS12.<>f__switch$mapF = new Dictionary<string, int>(2)
|
||||
{
|
||||
{ "1.2.840.113549.1.9.20", 0 },
|
||||
{ "1.2.840.113549.1.9.21", 1 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (PKCS12.<>f__switch$mapF.TryGetValue(text2, out num))
|
||||
{
|
||||
if (num != 0)
|
||||
{
|
||||
if (num == 1)
|
||||
{
|
||||
ArrayList arrayList = (ArrayList)enumerator.Value;
|
||||
if (arrayList.Count > 0)
|
||||
{
|
||||
ASN1 asn5 = new ASN1(48);
|
||||
asn5.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.21"));
|
||||
ASN1 asn6 = new ASN1(49);
|
||||
foreach (object obj in arrayList)
|
||||
{
|
||||
byte[] array = (byte[])obj;
|
||||
asn6.Add(new ASN1(4)
|
||||
{
|
||||
Value = array
|
||||
});
|
||||
}
|
||||
asn5.Add(asn6);
|
||||
asn4.Add(asn5);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList arrayList2 = (ArrayList)enumerator.Value;
|
||||
if (arrayList2.Count > 0)
|
||||
{
|
||||
ASN1 asn7 = new ASN1(48);
|
||||
asn7.Add(ASN1Convert.FromOid("1.2.840.113549.1.9.20"));
|
||||
ASN1 asn8 = new ASN1(49);
|
||||
foreach (object obj2 in arrayList2)
|
||||
{
|
||||
byte[] array2 = (byte[])obj2;
|
||||
asn8.Add(new ASN1(30)
|
||||
{
|
||||
Value = array2
|
||||
});
|
||||
}
|
||||
asn7.Add(asn8);
|
||||
asn4.Add(asn7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (asn4.Count > 0)
|
||||
{
|
||||
asn3.Add(asn4);
|
||||
}
|
||||
}
|
||||
return asn3;
|
||||
}
|
||||
|
||||
// Token: 0x060009CF RID: 2511 RVA: 0x00029CD8 File Offset: 0x00027ED8
|
||||
private byte[] MAC(byte[] password, byte[] salt, int iterations, byte[] data)
|
||||
{
|
||||
PKCS12.DeriveBytes deriveBytes = new PKCS12.DeriveBytes();
|
||||
deriveBytes.HashName = "SHA1";
|
||||
deriveBytes.Password = password;
|
||||
deriveBytes.Salt = salt;
|
||||
deriveBytes.IterationCount = iterations;
|
||||
HMACSHA1 hmacsha = (HMACSHA1)HMAC.Create();
|
||||
hmacsha.Key = deriveBytes.DeriveMAC(20);
|
||||
return hmacsha.ComputeHash(data, 0, data.Length);
|
||||
}
|
||||
|
||||
// Token: 0x060009D0 RID: 2512 RVA: 0x00029D34 File Offset: 0x00027F34
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
ASN1 asn2 = safeBag.ASN1;
|
||||
ASN1 asn3 = asn2[1];
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn3.Value);
|
||||
arrayList.Add(new X509Certificate(contentInfo.Content[0].Value));
|
||||
}
|
||||
}
|
||||
ArrayList arrayList2 = new ArrayList();
|
||||
ArrayList arrayList3 = new ArrayList();
|
||||
foreach (X509Certificate x509Certificate in this.Certificates)
|
||||
{
|
||||
bool flag = false;
|
||||
foreach (object obj2 in arrayList)
|
||||
{
|
||||
X509Certificate x509Certificate2 = (X509Certificate)obj2;
|
||||
if (this.Compare(x509Certificate.RawData, x509Certificate2.RawData))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
arrayList2.Add(x509Certificate);
|
||||
}
|
||||
}
|
||||
foreach (object obj3 in arrayList)
|
||||
{
|
||||
X509Certificate x509Certificate3 = (X509Certificate)obj3;
|
||||
bool flag2 = false;
|
||||
foreach (X509Certificate x509Certificate4 in this.Certificates)
|
||||
{
|
||||
if (this.Compare(x509Certificate3.RawData, x509Certificate4.RawData))
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
if (!flag2)
|
||||
{
|
||||
arrayList3.Add(x509Certificate3);
|
||||
}
|
||||
}
|
||||
foreach (object obj4 in arrayList3)
|
||||
{
|
||||
X509Certificate x509Certificate5 = (X509Certificate)obj4;
|
||||
this.RemoveCertificate(x509Certificate5);
|
||||
}
|
||||
foreach (object obj5 in arrayList2)
|
||||
{
|
||||
X509Certificate x509Certificate6 = (X509Certificate)obj5;
|
||||
this.AddCertificate(x509Certificate6);
|
||||
}
|
||||
if (this._safeBags.Count > 0)
|
||||
{
|
||||
ASN1 asn4 = new ASN1(48);
|
||||
foreach (object obj6 in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag2 = (SafeBag)obj6;
|
||||
if (safeBag2.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
asn4.Add(safeBag2.ASN1);
|
||||
}
|
||||
}
|
||||
if (asn4.Count > 0)
|
||||
{
|
||||
PKCS7.ContentInfo contentInfo2 = this.EncryptedContentInfo(asn4, "1.2.840.113549.1.12.1.3");
|
||||
asn.Add(contentInfo2.ASN1);
|
||||
}
|
||||
}
|
||||
if (this._safeBags.Count > 0)
|
||||
{
|
||||
ASN1 asn5 = new ASN1(48);
|
||||
foreach (object obj7 in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag3 = (SafeBag)obj7;
|
||||
if (safeBag3.BagOID.Equals("1.2.840.113549.1.12.10.1.1") || safeBag3.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
asn5.Add(safeBag3.ASN1);
|
||||
}
|
||||
}
|
||||
if (asn5.Count > 0)
|
||||
{
|
||||
ASN1 asn6 = new ASN1(160);
|
||||
asn6.Add(new ASN1(4, asn5.GetBytes()));
|
||||
asn.Add(new PKCS7.ContentInfo("1.2.840.113549.1.7.1")
|
||||
{
|
||||
Content = asn6
|
||||
}.ASN1);
|
||||
}
|
||||
}
|
||||
if (this._safeBags.Count > 0)
|
||||
{
|
||||
ASN1 asn7 = new ASN1(48);
|
||||
foreach (object obj8 in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag4 = (SafeBag)obj8;
|
||||
if (safeBag4.BagOID.Equals("1.2.840.113549.1.12.10.1.5"))
|
||||
{
|
||||
asn7.Add(safeBag4.ASN1);
|
||||
}
|
||||
}
|
||||
if (asn7.Count > 0)
|
||||
{
|
||||
PKCS7.ContentInfo contentInfo3 = this.EncryptedContentInfo(asn7, "1.2.840.113549.1.12.1.3");
|
||||
asn.Add(contentInfo3.ASN1);
|
||||
}
|
||||
}
|
||||
ASN1 asn8 = new ASN1(4, asn.GetBytes());
|
||||
ASN1 asn9 = new ASN1(160);
|
||||
asn9.Add(asn8);
|
||||
PKCS7.ContentInfo contentInfo4 = new PKCS7.ContentInfo("1.2.840.113549.1.7.1");
|
||||
contentInfo4.Content = asn9;
|
||||
ASN1 asn10 = new ASN1(48);
|
||||
if (this._password != null)
|
||||
{
|
||||
byte[] array = new byte[20];
|
||||
this.RNG.GetBytes(array);
|
||||
byte[] array2 = this.MAC(this._password, array, this._iterations, contentInfo4.Content[0].Value);
|
||||
ASN1 asn11 = new ASN1(48);
|
||||
asn11.Add(ASN1Convert.FromOid("1.3.14.3.2.26"));
|
||||
asn11.Add(new ASN1(5));
|
||||
ASN1 asn12 = new ASN1(48);
|
||||
asn12.Add(asn11);
|
||||
asn12.Add(new ASN1(4, array2));
|
||||
asn10.Add(asn12);
|
||||
asn10.Add(new ASN1(4, array));
|
||||
asn10.Add(ASN1Convert.FromInt32(this._iterations));
|
||||
}
|
||||
ASN1 asn13 = new ASN1(2, new byte[] { 3 });
|
||||
ASN1 asn14 = new ASN1(48);
|
||||
asn14.Add(asn13);
|
||||
asn14.Add(contentInfo4.ASN1);
|
||||
if (asn10.Count > 0)
|
||||
{
|
||||
asn14.Add(asn10);
|
||||
}
|
||||
return asn14.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x060009D1 RID: 2513 RVA: 0x0002A488 File Offset: 0x00028688
|
||||
private PKCS7.ContentInfo EncryptedContentInfo(ASN1 safeBags, string algorithmOid)
|
||||
{
|
||||
byte[] array = new byte[8];
|
||||
this.RNG.GetBytes(array);
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(new ASN1(4, array));
|
||||
asn.Add(ASN1Convert.FromInt32(this._iterations));
|
||||
ASN1 asn2 = new ASN1(48);
|
||||
asn2.Add(ASN1Convert.FromOid(algorithmOid));
|
||||
asn2.Add(asn);
|
||||
byte[] array2 = this.Encrypt(algorithmOid, array, this._iterations, safeBags.GetBytes());
|
||||
ASN1 asn3 = new ASN1(128, array2);
|
||||
ASN1 asn4 = new ASN1(48);
|
||||
asn4.Add(ASN1Convert.FromOid("1.2.840.113549.1.7.1"));
|
||||
asn4.Add(asn2);
|
||||
asn4.Add(asn3);
|
||||
ASN1 asn5 = new ASN1(2, new byte[1]);
|
||||
ASN1 asn6 = new ASN1(48);
|
||||
asn6.Add(asn5);
|
||||
asn6.Add(asn4);
|
||||
ASN1 asn7 = new ASN1(160);
|
||||
asn7.Add(asn6);
|
||||
return new PKCS7.ContentInfo("1.2.840.113549.1.7.6")
|
||||
{
|
||||
Content = asn7
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x060009D2 RID: 2514 RVA: 0x0002A598 File Offset: 0x00028798
|
||||
public void AddCertificate(X509Certificate cert)
|
||||
{
|
||||
this.AddCertificate(cert, null);
|
||||
}
|
||||
|
||||
// Token: 0x060009D3 RID: 2515 RVA: 0x0002A5A4 File Offset: 0x000287A4
|
||||
public void AddCertificate(X509Certificate cert, IDictionary attributes)
|
||||
{
|
||||
bool flag = false;
|
||||
int num = 0;
|
||||
while (!flag && num < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn2.Value);
|
||||
X509Certificate x509Certificate = new X509Certificate(contentInfo.Content[0].Value);
|
||||
if (this.Compare(cert.RawData, x509Certificate.RawData))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
this._safeBags.Add(new SafeBag("1.2.840.113549.1.12.10.1.3", this.CertificateSafeBag(cert, attributes)));
|
||||
this._certsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009D4 RID: 2516 RVA: 0x0002A678 File Offset: 0x00028878
|
||||
public void RemoveCertificate(X509Certificate cert)
|
||||
{
|
||||
this.RemoveCertificate(cert, null);
|
||||
}
|
||||
|
||||
// Token: 0x060009D5 RID: 2517 RVA: 0x0002A684 File Offset: 0x00028884
|
||||
public void RemoveCertificate(X509Certificate cert, IDictionary attrs)
|
||||
{
|
||||
int num = -1;
|
||||
int num2 = 0;
|
||||
while (num == -1 && num2 < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num2];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn2.Value);
|
||||
X509Certificate x509Certificate = new X509Certificate(contentInfo.Content[0].Value);
|
||||
if (this.Compare(cert.RawData, x509Certificate.RawData))
|
||||
{
|
||||
if (attrs != null)
|
||||
{
|
||||
if (asn.Count == 3)
|
||||
{
|
||||
ASN1 asn3 = asn[2];
|
||||
int num3 = 0;
|
||||
for (int i = 0; i < asn3.Count; i++)
|
||||
{
|
||||
ASN1 asn4 = asn3[i];
|
||||
ASN1 asn5 = asn4[0];
|
||||
string text = ASN1Convert.ToOid(asn5);
|
||||
ArrayList arrayList = (ArrayList)attrs[text];
|
||||
if (arrayList != null)
|
||||
{
|
||||
ASN1 asn6 = asn4[1];
|
||||
if (arrayList.Count == asn6.Count)
|
||||
{
|
||||
int num4 = 0;
|
||||
for (int j = 0; j < asn6.Count; j++)
|
||||
{
|
||||
ASN1 asn7 = asn6[j];
|
||||
byte[] array = (byte[])arrayList[j];
|
||||
if (this.Compare(array, asn7.Value))
|
||||
{
|
||||
num4++;
|
||||
}
|
||||
}
|
||||
if (num4 == asn6.Count)
|
||||
{
|
||||
num3++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num3 == asn3.Count)
|
||||
{
|
||||
num = num2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num = num2;
|
||||
}
|
||||
}
|
||||
}
|
||||
num2++;
|
||||
}
|
||||
if (num != -1)
|
||||
{
|
||||
this._safeBags.RemoveAt(num);
|
||||
this._certsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009D6 RID: 2518 RVA: 0x0002A850 File Offset: 0x00028A50
|
||||
private bool CompareAsymmetricAlgorithm(AsymmetricAlgorithm a1, AsymmetricAlgorithm a2)
|
||||
{
|
||||
return a1.KeySize == a2.KeySize && a1.ToXmlString(false) == a2.ToXmlString(false);
|
||||
}
|
||||
|
||||
// Token: 0x060009D7 RID: 2519 RVA: 0x0002A884 File Offset: 0x00028A84
|
||||
public void AddPkcs8ShroudedKeyBag(AsymmetricAlgorithm aa)
|
||||
{
|
||||
this.AddPkcs8ShroudedKeyBag(aa, null);
|
||||
}
|
||||
|
||||
// Token: 0x060009D8 RID: 2520 RVA: 0x0002A890 File Offset: 0x00028A90
|
||||
public void AddPkcs8ShroudedKeyBag(AsymmetricAlgorithm aa, IDictionary attributes)
|
||||
{
|
||||
bool flag = false;
|
||||
int num = 0;
|
||||
while (!flag && num < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1[1];
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(asn.Value);
|
||||
byte[] array = this.Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(array);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
AsymmetricAlgorithm asymmetricAlgorithm;
|
||||
if (b != 2)
|
||||
{
|
||||
if (b != 48)
|
||||
{
|
||||
Array.Clear(array, 0, array.Length);
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
throw new CryptographicException("Unknown private key format");
|
||||
}
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(array, 0, array.Length);
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
if (this.CompareAsymmetricAlgorithm(aa, asymmetricAlgorithm))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
this._safeBags.Add(new SafeBag("1.2.840.113549.1.12.10.1.2", this.Pkcs8ShroudedKeyBagSafeBag(aa, attributes)));
|
||||
this._keyBagsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009D9 RID: 2521 RVA: 0x0002A9F4 File Offset: 0x00028BF4
|
||||
public void RemovePkcs8ShroudedKeyBag(AsymmetricAlgorithm aa)
|
||||
{
|
||||
int num = -1;
|
||||
int num2 = 0;
|
||||
while (num == -1 && num2 < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num2];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1[1];
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(asn.Value);
|
||||
byte[] array = this.Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(array);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
AsymmetricAlgorithm asymmetricAlgorithm;
|
||||
if (b != 2)
|
||||
{
|
||||
if (b != 48)
|
||||
{
|
||||
Array.Clear(array, 0, array.Length);
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
throw new CryptographicException("Unknown private key format");
|
||||
}
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(array, 0, array.Length);
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
if (this.CompareAsymmetricAlgorithm(aa, asymmetricAlgorithm))
|
||||
{
|
||||
num = num2;
|
||||
}
|
||||
}
|
||||
num2++;
|
||||
}
|
||||
if (num != -1)
|
||||
{
|
||||
this._safeBags.RemoveAt(num);
|
||||
this._keyBagsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009DA RID: 2522 RVA: 0x0002AB48 File Offset: 0x00028D48
|
||||
public void AddKeyBag(AsymmetricAlgorithm aa)
|
||||
{
|
||||
this.AddKeyBag(aa, null);
|
||||
}
|
||||
|
||||
// Token: 0x060009DB RID: 2523 RVA: 0x0002AB54 File Offset: 0x00028D54
|
||||
public void AddKeyBag(AsymmetricAlgorithm aa, IDictionary attributes)
|
||||
{
|
||||
bool flag = false;
|
||||
int num = 0;
|
||||
while (!flag && num < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1[1];
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(asn.Value);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
AsymmetricAlgorithm asymmetricAlgorithm;
|
||||
if (b != 2)
|
||||
{
|
||||
if (b != 48)
|
||||
{
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
throw new CryptographicException("Unknown private key format");
|
||||
}
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
if (this.CompareAsymmetricAlgorithm(aa, asymmetricAlgorithm))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
this._safeBags.Add(new SafeBag("1.2.840.113549.1.12.10.1.1", this.KeyBagSafeBag(aa, attributes)));
|
||||
this._keyBagsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009DC RID: 2524 RVA: 0x0002AC74 File Offset: 0x00028E74
|
||||
public void RemoveKeyBag(AsymmetricAlgorithm aa)
|
||||
{
|
||||
int num = -1;
|
||||
int num2 = 0;
|
||||
while (num == -1 && num2 < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num2];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1[1];
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(asn.Value);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
AsymmetricAlgorithm asymmetricAlgorithm;
|
||||
if (b != 2)
|
||||
{
|
||||
if (b != 48)
|
||||
{
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
throw new CryptographicException("Unknown private key format");
|
||||
}
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
if (this.CompareAsymmetricAlgorithm(aa, asymmetricAlgorithm))
|
||||
{
|
||||
num = num2;
|
||||
}
|
||||
}
|
||||
num2++;
|
||||
}
|
||||
if (num != -1)
|
||||
{
|
||||
this._safeBags.RemoveAt(num);
|
||||
this._keyBagsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009DD RID: 2525 RVA: 0x0002AD84 File Offset: 0x00028F84
|
||||
public void AddSecretBag(byte[] secret)
|
||||
{
|
||||
this.AddSecretBag(secret, null);
|
||||
}
|
||||
|
||||
// Token: 0x060009DE RID: 2526 RVA: 0x0002AD90 File Offset: 0x00028F90
|
||||
public void AddSecretBag(byte[] secret, IDictionary attributes)
|
||||
{
|
||||
bool flag = false;
|
||||
int num = 0;
|
||||
while (!flag && num < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.5"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1[1];
|
||||
byte[] value = asn.Value;
|
||||
if (this.Compare(secret, value))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
this._safeBags.Add(new SafeBag("1.2.840.113549.1.12.10.1.5", this.SecretBagSafeBag(secret, attributes)));
|
||||
this._secretBagsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009DF RID: 2527 RVA: 0x0002AE38 File Offset: 0x00029038
|
||||
public void RemoveSecretBag(byte[] secret)
|
||||
{
|
||||
int num = -1;
|
||||
int num2 = 0;
|
||||
while (num == -1 && num2 < this._safeBags.Count)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)this._safeBags[num2];
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.5"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1[1];
|
||||
byte[] value = asn.Value;
|
||||
if (this.Compare(secret, value))
|
||||
{
|
||||
num = num2;
|
||||
}
|
||||
}
|
||||
num2++;
|
||||
}
|
||||
if (num != -1)
|
||||
{
|
||||
this._safeBags.RemoveAt(num);
|
||||
this._secretBagsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009E0 RID: 2528 RVA: 0x0002AED0 File Offset: 0x000290D0
|
||||
public AsymmetricAlgorithm GetAsymmetricAlgorithm(IDictionary attrs)
|
||||
{
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1") || safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
if (asn.Count == 3)
|
||||
{
|
||||
ASN1 asn2 = asn[2];
|
||||
int num = 0;
|
||||
for (int i = 0; i < asn2.Count; i++)
|
||||
{
|
||||
ASN1 asn3 = asn2[i];
|
||||
ASN1 asn4 = asn3[0];
|
||||
string text = ASN1Convert.ToOid(asn4);
|
||||
ArrayList arrayList = (ArrayList)attrs[text];
|
||||
if (arrayList != null)
|
||||
{
|
||||
ASN1 asn5 = asn3[1];
|
||||
if (arrayList.Count == asn5.Count)
|
||||
{
|
||||
int num2 = 0;
|
||||
for (int j = 0; j < asn5.Count; j++)
|
||||
{
|
||||
ASN1 asn6 = asn5[j];
|
||||
byte[] array = (byte[])arrayList[j];
|
||||
if (this.Compare(array, asn6.Value))
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
if (num2 == asn5.Count)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num == asn2.Count)
|
||||
{
|
||||
ASN1 asn7 = asn[1];
|
||||
AsymmetricAlgorithm asymmetricAlgorithm = null;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1"))
|
||||
{
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(asn7.Value);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b == 48)
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
}
|
||||
else if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(asn7.Value);
|
||||
byte[] array2 = this.Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo2 = new PKCS8.PrivateKeyInfo(array2);
|
||||
byte[] privateKey2 = privateKeyInfo2.PrivateKey;
|
||||
byte b = privateKey2[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b == 48)
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey2, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(privateKey2, 0, privateKey2.Length);
|
||||
Array.Clear(array2, 0, array2.Length);
|
||||
}
|
||||
return asymmetricAlgorithm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060009E1 RID: 2529 RVA: 0x0002B1B8 File Offset: 0x000293B8
|
||||
public byte[] GetSecret(IDictionary attrs)
|
||||
{
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.5"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
if (asn.Count == 3)
|
||||
{
|
||||
ASN1 asn2 = asn[2];
|
||||
int num = 0;
|
||||
for (int i = 0; i < asn2.Count; i++)
|
||||
{
|
||||
ASN1 asn3 = asn2[i];
|
||||
ASN1 asn4 = asn3[0];
|
||||
string text = ASN1Convert.ToOid(asn4);
|
||||
ArrayList arrayList = (ArrayList)attrs[text];
|
||||
if (arrayList != null)
|
||||
{
|
||||
ASN1 asn5 = asn3[1];
|
||||
if (arrayList.Count == asn5.Count)
|
||||
{
|
||||
int num2 = 0;
|
||||
for (int j = 0; j < asn5.Count; j++)
|
||||
{
|
||||
ASN1 asn6 = asn5[j];
|
||||
byte[] array = (byte[])arrayList[j];
|
||||
if (this.Compare(array, asn6.Value))
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
if (num2 == asn5.Count)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num == asn2.Count)
|
||||
{
|
||||
ASN1 asn7 = asn[1];
|
||||
return asn7.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060009E2 RID: 2530 RVA: 0x0002B354 File Offset: 0x00029554
|
||||
public X509Certificate GetCertificate(IDictionary attrs)
|
||||
{
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
if (asn.Count == 3)
|
||||
{
|
||||
ASN1 asn2 = asn[2];
|
||||
int num = 0;
|
||||
for (int i = 0; i < asn2.Count; i++)
|
||||
{
|
||||
ASN1 asn3 = asn2[i];
|
||||
ASN1 asn4 = asn3[0];
|
||||
string text = ASN1Convert.ToOid(asn4);
|
||||
ArrayList arrayList = (ArrayList)attrs[text];
|
||||
if (arrayList != null)
|
||||
{
|
||||
ASN1 asn5 = asn3[1];
|
||||
if (arrayList.Count == asn5.Count)
|
||||
{
|
||||
int num2 = 0;
|
||||
for (int j = 0; j < asn5.Count; j++)
|
||||
{
|
||||
ASN1 asn6 = asn5[j];
|
||||
byte[] array = (byte[])arrayList[j];
|
||||
if (this.Compare(array, asn6.Value))
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
if (num2 == asn5.Count)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num == asn2.Count)
|
||||
{
|
||||
ASN1 asn7 = asn[1];
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn7.Value);
|
||||
return new X509Certificate(contentInfo.Content[0].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060009E3 RID: 2531 RVA: 0x0002B50C File Offset: 0x0002970C
|
||||
public IDictionary GetAttributes(AsymmetricAlgorithm aa)
|
||||
{
|
||||
IDictionary dictionary = new Hashtable();
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1") || safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
AsymmetricAlgorithm asymmetricAlgorithm = null;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.1"))
|
||||
{
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo = new PKCS8.PrivateKeyInfo(asn2.Value);
|
||||
byte[] privateKey = privateKeyInfo.PrivateKey;
|
||||
byte b = privateKey[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b == 48)
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(privateKey, 0, privateKey.Length);
|
||||
}
|
||||
else if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.2"))
|
||||
{
|
||||
PKCS8.EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new PKCS8.EncryptedPrivateKeyInfo(asn2.Value);
|
||||
byte[] array = this.Decrypt(encryptedPrivateKeyInfo.Algorithm, encryptedPrivateKeyInfo.Salt, encryptedPrivateKeyInfo.IterationCount, encryptedPrivateKeyInfo.EncryptedData);
|
||||
PKCS8.PrivateKeyInfo privateKeyInfo2 = new PKCS8.PrivateKeyInfo(array);
|
||||
byte[] privateKey2 = privateKeyInfo2.PrivateKey;
|
||||
byte b = privateKey2[0];
|
||||
if (b != 2)
|
||||
{
|
||||
if (b == 48)
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeRSA(privateKey2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
asymmetricAlgorithm = PKCS8.PrivateKeyInfo.DecodeDSA(privateKey2, default(DSAParameters));
|
||||
}
|
||||
Array.Clear(privateKey2, 0, privateKey2.Length);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
}
|
||||
if (asymmetricAlgorithm != null && this.CompareAsymmetricAlgorithm(asymmetricAlgorithm, aa) && asn.Count == 3)
|
||||
{
|
||||
ASN1 asn3 = asn[2];
|
||||
for (int i = 0; i < asn3.Count; i++)
|
||||
{
|
||||
ASN1 asn4 = asn3[i];
|
||||
ASN1 asn5 = asn4[0];
|
||||
string text = ASN1Convert.ToOid(asn5);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
ASN1 asn6 = asn4[1];
|
||||
for (int j = 0; j < asn6.Count; j++)
|
||||
{
|
||||
ASN1 asn7 = asn6[j];
|
||||
arrayList.Add(asn7.Value);
|
||||
}
|
||||
dictionary.Add(text, arrayList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
// Token: 0x060009E4 RID: 2532 RVA: 0x0002B7AC File Offset: 0x000299AC
|
||||
public IDictionary GetAttributes(X509Certificate cert)
|
||||
{
|
||||
IDictionary dictionary = new Hashtable();
|
||||
foreach (object obj in this._safeBags)
|
||||
{
|
||||
SafeBag safeBag = (SafeBag)obj;
|
||||
if (safeBag.BagOID.Equals("1.2.840.113549.1.12.10.1.3"))
|
||||
{
|
||||
ASN1 asn = safeBag.ASN1;
|
||||
ASN1 asn2 = asn[1];
|
||||
PKCS7.ContentInfo contentInfo = new PKCS7.ContentInfo(asn2.Value);
|
||||
X509Certificate x509Certificate = new X509Certificate(contentInfo.Content[0].Value);
|
||||
if (this.Compare(cert.RawData, x509Certificate.RawData) && asn.Count == 3)
|
||||
{
|
||||
ASN1 asn3 = asn[2];
|
||||
for (int i = 0; i < asn3.Count; i++)
|
||||
{
|
||||
ASN1 asn4 = asn3[i];
|
||||
ASN1 asn5 = asn4[0];
|
||||
string text = ASN1Convert.ToOid(asn5);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
ASN1 asn6 = asn4[1];
|
||||
for (int j = 0; j < asn6.Count; j++)
|
||||
{
|
||||
ASN1 asn7 = asn6[j];
|
||||
arrayList.Add(asn7.Value);
|
||||
}
|
||||
dictionary.Add(text, arrayList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
// Token: 0x060009E5 RID: 2533 RVA: 0x0002B924 File Offset: 0x00029B24
|
||||
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: 0x060009E6 RID: 2534 RVA: 0x0002B98C File Offset: 0x00029B8C
|
||||
public object Clone()
|
||||
{
|
||||
PKCS12 pkcs;
|
||||
if (this._password != null)
|
||||
{
|
||||
pkcs = new PKCS12(this.GetBytes(), Encoding.BigEndianUnicode.GetString(this._password));
|
||||
}
|
||||
else
|
||||
{
|
||||
pkcs = new PKCS12(this.GetBytes());
|
||||
}
|
||||
pkcs.IterationCount = this.IterationCount;
|
||||
return pkcs;
|
||||
}
|
||||
|
||||
// Token: 0x17000125 RID: 293
|
||||
// (get) Token: 0x060009E7 RID: 2535 RVA: 0x0002B9E0 File Offset: 0x00029BE0
|
||||
// (set) Token: 0x060009E8 RID: 2536 RVA: 0x0002B9E8 File Offset: 0x00029BE8
|
||||
public static int MaximumPasswordLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return PKCS12.password_max_length;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 32)
|
||||
{
|
||||
string text = Locale.GetText("Maximum password length cannot be less than {0}.", new object[] { 32 });
|
||||
throw new ArgumentOutOfRangeException(text);
|
||||
}
|
||||
PKCS12.password_max_length = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009E9 RID: 2537 RVA: 0x0002BA28 File Offset: 0x00029C28
|
||||
private static byte[] LoadFile(string filename)
|
||||
{
|
||||
byte[] array = null;
|
||||
using (FileStream fileStream = File.OpenRead(filename))
|
||||
{
|
||||
array = new byte[fileStream.Length];
|
||||
fileStream.Read(array, 0, array.Length);
|
||||
fileStream.Close();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060009EA RID: 2538 RVA: 0x0002BA8C File Offset: 0x00029C8C
|
||||
public static PKCS12 LoadFromFile(string filename)
|
||||
{
|
||||
if (filename == null)
|
||||
{
|
||||
throw new ArgumentNullException("filename");
|
||||
}
|
||||
return new PKCS12(PKCS12.LoadFile(filename));
|
||||
}
|
||||
|
||||
// Token: 0x060009EB RID: 2539 RVA: 0x0002BAAC File Offset: 0x00029CAC
|
||||
public static PKCS12 LoadFromFile(string filename, string password)
|
||||
{
|
||||
if (filename == null)
|
||||
{
|
||||
throw new ArgumentNullException("filename");
|
||||
}
|
||||
return new PKCS12(PKCS12.LoadFile(filename), password);
|
||||
}
|
||||
|
||||
// Token: 0x04000244 RID: 580
|
||||
public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1";
|
||||
|
||||
// Token: 0x04000245 RID: 581
|
||||
public const string pbeWithSHAAnd40BitRC4 = "1.2.840.113549.1.12.1.2";
|
||||
|
||||
// Token: 0x04000246 RID: 582
|
||||
public const string pbeWithSHAAnd3KeyTripleDESCBC = "1.2.840.113549.1.12.1.3";
|
||||
|
||||
// Token: 0x04000247 RID: 583
|
||||
public const string pbeWithSHAAnd2KeyTripleDESCBC = "1.2.840.113549.1.12.1.4";
|
||||
|
||||
// Token: 0x04000248 RID: 584
|
||||
public const string pbeWithSHAAnd128BitRC2CBC = "1.2.840.113549.1.12.1.5";
|
||||
|
||||
// Token: 0x04000249 RID: 585
|
||||
public const string pbeWithSHAAnd40BitRC2CBC = "1.2.840.113549.1.12.1.6";
|
||||
|
||||
// Token: 0x0400024A RID: 586
|
||||
public const string keyBag = "1.2.840.113549.1.12.10.1.1";
|
||||
|
||||
// Token: 0x0400024B RID: 587
|
||||
public const string pkcs8ShroudedKeyBag = "1.2.840.113549.1.12.10.1.2";
|
||||
|
||||
// Token: 0x0400024C RID: 588
|
||||
public const string certBag = "1.2.840.113549.1.12.10.1.3";
|
||||
|
||||
// Token: 0x0400024D RID: 589
|
||||
public const string crlBag = "1.2.840.113549.1.12.10.1.4";
|
||||
|
||||
// Token: 0x0400024E RID: 590
|
||||
public const string secretBag = "1.2.840.113549.1.12.10.1.5";
|
||||
|
||||
// Token: 0x0400024F RID: 591
|
||||
public const string safeContentsBag = "1.2.840.113549.1.12.10.1.6";
|
||||
|
||||
// Token: 0x04000250 RID: 592
|
||||
public const string x509Certificate = "1.2.840.113549.1.9.22.1";
|
||||
|
||||
// Token: 0x04000251 RID: 593
|
||||
public const string sdsiCertificate = "1.2.840.113549.1.9.22.2";
|
||||
|
||||
// Token: 0x04000252 RID: 594
|
||||
public const string x509Crl = "1.2.840.113549.1.9.23.1";
|
||||
|
||||
// Token: 0x04000253 RID: 595
|
||||
public const int CryptoApiPasswordLimit = 32;
|
||||
|
||||
// Token: 0x04000254 RID: 596
|
||||
private static int recommendedIterationCount = 2000;
|
||||
|
||||
// Token: 0x04000255 RID: 597
|
||||
private byte[] _password;
|
||||
|
||||
// Token: 0x04000256 RID: 598
|
||||
private ArrayList _keyBags;
|
||||
|
||||
// Token: 0x04000257 RID: 599
|
||||
private ArrayList _secretBags;
|
||||
|
||||
// Token: 0x04000258 RID: 600
|
||||
private X509CertificateCollection _certs;
|
||||
|
||||
// Token: 0x04000259 RID: 601
|
||||
private bool _keyBagsChanged;
|
||||
|
||||
// Token: 0x0400025A RID: 602
|
||||
private bool _secretBagsChanged;
|
||||
|
||||
// Token: 0x0400025B RID: 603
|
||||
private bool _certsChanged;
|
||||
|
||||
// Token: 0x0400025C RID: 604
|
||||
private int _iterations;
|
||||
|
||||
// Token: 0x0400025D RID: 605
|
||||
private ArrayList _safeBags;
|
||||
|
||||
// Token: 0x0400025E RID: 606
|
||||
private RandomNumberGenerator _rng;
|
||||
|
||||
// Token: 0x0400025F RID: 607
|
||||
private static int password_max_length = int.MaxValue;
|
||||
|
||||
// Token: 0x020000B7 RID: 183
|
||||
public class DeriveBytes
|
||||
{
|
||||
// Token: 0x17000126 RID: 294
|
||||
// (get) Token: 0x060009EE RID: 2542 RVA: 0x0002BB28 File Offset: 0x00029D28
|
||||
// (set) Token: 0x060009EF RID: 2543 RVA: 0x0002BB30 File Offset: 0x00029D30
|
||||
public string HashName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._hashName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._hashName = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000127 RID: 295
|
||||
// (get) Token: 0x060009F0 RID: 2544 RVA: 0x0002BB3C File Offset: 0x00029D3C
|
||||
// (set) Token: 0x060009F1 RID: 2545 RVA: 0x0002BB44 File Offset: 0x00029D44
|
||||
public int IterationCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._iterations;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._iterations = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000128 RID: 296
|
||||
// (get) Token: 0x060009F2 RID: 2546 RVA: 0x0002BB50 File Offset: 0x00029D50
|
||||
// (set) Token: 0x060009F3 RID: 2547 RVA: 0x0002BB64 File Offset: 0x00029D64
|
||||
public byte[] Password
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte[])this._password.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
this._password = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._password = (byte[])value.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000129 RID: 297
|
||||
// (get) Token: 0x060009F4 RID: 2548 RVA: 0x0002BB9C File Offset: 0x00029D9C
|
||||
// (set) Token: 0x060009F5 RID: 2549 RVA: 0x0002BBB0 File Offset: 0x00029DB0
|
||||
public byte[] Salt
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte[])this._salt.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
this._salt = (byte[])value.Clone();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._salt = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009F6 RID: 2550 RVA: 0x0002BBD8 File Offset: 0x00029DD8
|
||||
private void Adjust(byte[] a, int aOff, byte[] b)
|
||||
{
|
||||
int num = (int)((b[b.Length - 1] & byte.MaxValue) + (a[aOff + b.Length - 1] & byte.MaxValue) + 1);
|
||||
a[aOff + b.Length - 1] = (byte)num;
|
||||
num >>= 8;
|
||||
for (int i = b.Length - 2; i >= 0; i--)
|
||||
{
|
||||
num += (int)((b[i] & byte.MaxValue) + (a[aOff + i] & byte.MaxValue));
|
||||
a[aOff + i] = (byte)num;
|
||||
num >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060009F7 RID: 2551 RVA: 0x0002BC50 File Offset: 0x00029E50
|
||||
private byte[] Derive(byte[] diversifier, int n)
|
||||
{
|
||||
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this._hashName);
|
||||
int num = hashAlgorithm.HashSize >> 3;
|
||||
int num2 = 64;
|
||||
byte[] array = new byte[n];
|
||||
byte[] array2;
|
||||
if (this._salt != null && this._salt.Length != 0)
|
||||
{
|
||||
array2 = new byte[num2 * ((this._salt.Length + num2 - 1) / num2)];
|
||||
for (int num3 = 0; num3 != array2.Length; num3++)
|
||||
{
|
||||
array2[num3] = this._salt[num3 % this._salt.Length];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
array2 = new byte[0];
|
||||
}
|
||||
byte[] array3;
|
||||
if (this._password != null && this._password.Length != 0)
|
||||
{
|
||||
array3 = new byte[num2 * ((this._password.Length + num2 - 1) / num2)];
|
||||
for (int num4 = 0; num4 != array3.Length; num4++)
|
||||
{
|
||||
array3[num4] = this._password[num4 % this._password.Length];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
array3 = new byte[0];
|
||||
}
|
||||
byte[] array4 = new byte[array2.Length + array3.Length];
|
||||
Buffer.BlockCopy(array2, 0, array4, 0, array2.Length);
|
||||
Buffer.BlockCopy(array3, 0, array4, array2.Length, array3.Length);
|
||||
byte[] array5 = new byte[num2];
|
||||
int num5 = (n + num - 1) / num;
|
||||
for (int i = 1; i <= num5; i++)
|
||||
{
|
||||
hashAlgorithm.TransformBlock(diversifier, 0, diversifier.Length, diversifier, 0);
|
||||
hashAlgorithm.TransformFinalBlock(array4, 0, array4.Length);
|
||||
byte[] array6 = hashAlgorithm.Hash;
|
||||
hashAlgorithm.Initialize();
|
||||
for (int num6 = 1; num6 != this._iterations; num6++)
|
||||
{
|
||||
array6 = hashAlgorithm.ComputeHash(array6, 0, array6.Length);
|
||||
}
|
||||
for (int num7 = 0; num7 != array5.Length; num7++)
|
||||
{
|
||||
array5[num7] = array6[num7 % array6.Length];
|
||||
}
|
||||
for (int num8 = 0; num8 != array4.Length / num2; num8++)
|
||||
{
|
||||
this.Adjust(array4, num8 * num2, array5);
|
||||
}
|
||||
if (i == num5)
|
||||
{
|
||||
Buffer.BlockCopy(array6, 0, array, (i - 1) * num, array.Length - (i - 1) * num);
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy(array6, 0, array, (i - 1) * num, array6.Length);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060009F8 RID: 2552 RVA: 0x0002BE90 File Offset: 0x0002A090
|
||||
public byte[] DeriveKey(int size)
|
||||
{
|
||||
return this.Derive(PKCS12.DeriveBytes.keyDiversifier, size);
|
||||
}
|
||||
|
||||
// Token: 0x060009F9 RID: 2553 RVA: 0x0002BEA0 File Offset: 0x0002A0A0
|
||||
public byte[] DeriveIV(int size)
|
||||
{
|
||||
return this.Derive(PKCS12.DeriveBytes.ivDiversifier, size);
|
||||
}
|
||||
|
||||
// Token: 0x060009FA RID: 2554 RVA: 0x0002BEB0 File Offset: 0x0002A0B0
|
||||
public byte[] DeriveMAC(int size)
|
||||
{
|
||||
return this.Derive(PKCS12.DeriveBytes.macDiversifier, size);
|
||||
}
|
||||
|
||||
// Token: 0x04000268 RID: 616
|
||||
private static byte[] keyDiversifier = new byte[]
|
||||
{
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1
|
||||
};
|
||||
|
||||
// Token: 0x04000269 RID: 617
|
||||
private static byte[] ivDiversifier = new byte[]
|
||||
{
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2
|
||||
};
|
||||
|
||||
// Token: 0x0400026A RID: 618
|
||||
private static byte[] macDiversifier = new byte[]
|
||||
{
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3
|
||||
};
|
||||
|
||||
// Token: 0x0400026B RID: 619
|
||||
private string _hashName;
|
||||
|
||||
// Token: 0x0400026C RID: 620
|
||||
private int _iterations;
|
||||
|
||||
// Token: 0x0400026D RID: 621
|
||||
private byte[] _password;
|
||||
|
||||
// Token: 0x0400026E RID: 622
|
||||
private byte[] _salt;
|
||||
|
||||
// Token: 0x020000B8 RID: 184
|
||||
public enum Purpose
|
||||
{
|
||||
// Token: 0x04000270 RID: 624
|
||||
Key,
|
||||
// Token: 0x04000271 RID: 625
|
||||
IV,
|
||||
// Token: 0x04000272 RID: 626
|
||||
MAC
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000B3 RID: 179
|
||||
internal class PKCS5
|
||||
{
|
||||
// Token: 0x0400023A RID: 570
|
||||
public const string pbeWithMD2AndDESCBC = "1.2.840.113549.1.5.1";
|
||||
|
||||
// Token: 0x0400023B RID: 571
|
||||
public const string pbeWithMD5AndDESCBC = "1.2.840.113549.1.5.3";
|
||||
|
||||
// Token: 0x0400023C RID: 572
|
||||
public const string pbeWithMD2AndRC2CBC = "1.2.840.113549.1.5.4";
|
||||
|
||||
// Token: 0x0400023D RID: 573
|
||||
public const string pbeWithMD5AndRC2CBC = "1.2.840.113549.1.5.6";
|
||||
|
||||
// Token: 0x0400023E RID: 574
|
||||
public const string pbeWithSHA1AndDESCBC = "1.2.840.113549.1.5.10";
|
||||
|
||||
// Token: 0x0400023F RID: 575
|
||||
public const string pbeWithSHA1AndRC2CBC = "1.2.840.113549.1.5.11";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000B4 RID: 180
|
||||
internal class PKCS9
|
||||
{
|
||||
// Token: 0x04000240 RID: 576
|
||||
public const string friendlyName = "1.2.840.113549.1.9.20";
|
||||
|
||||
// Token: 0x04000241 RID: 577
|
||||
public const string localKeyId = "1.2.840.113549.1.9.21";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000B5 RID: 181
|
||||
internal class SafeBag
|
||||
{
|
||||
// Token: 0x060009B2 RID: 2482 RVA: 0x00027F90 File Offset: 0x00026190
|
||||
public SafeBag(string bagOID, ASN1 asn1)
|
||||
{
|
||||
this._bagOID = bagOID;
|
||||
this._asn1 = asn1;
|
||||
}
|
||||
|
||||
// Token: 0x1700011D RID: 285
|
||||
// (get) Token: 0x060009B3 RID: 2483 RVA: 0x00027FA8 File Offset: 0x000261A8
|
||||
public string BagOID
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._bagOID;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700011E RID: 286
|
||||
// (get) Token: 0x060009B4 RID: 2484 RVA: 0x00027FB0 File Offset: 0x000261B0
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._asn1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x04000242 RID: 578
|
||||
private string _bagOID;
|
||||
|
||||
// Token: 0x04000243 RID: 579
|
||||
private ASN1 _asn1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,457 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Mono.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000B9 RID: 185
|
||||
internal sealed class X501
|
||||
{
|
||||
// Token: 0x060009FB RID: 2555 RVA: 0x0002BEC0 File Offset: 0x0002A0C0
|
||||
private X501()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060009FD RID: 2557 RVA: 0x0002C044 File Offset: 0x0002A244
|
||||
public static string ToString(ASN1 seq)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < seq.Count; i++)
|
||||
{
|
||||
ASN1 asn = seq[i];
|
||||
X501.AppendEntry(stringBuilder, asn, true);
|
||||
if (i < seq.Count - 1)
|
||||
{
|
||||
stringBuilder.Append(", ");
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x060009FE RID: 2558 RVA: 0x0002C0A0 File Offset: 0x0002A2A0
|
||||
public static string ToString(ASN1 seq, bool reversed, string separator, bool quotes)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (reversed)
|
||||
{
|
||||
for (int i = seq.Count - 1; i >= 0; i--)
|
||||
{
|
||||
ASN1 asn = seq[i];
|
||||
X501.AppendEntry(stringBuilder, asn, quotes);
|
||||
if (i > 0)
|
||||
{
|
||||
stringBuilder.Append(separator);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < seq.Count; j++)
|
||||
{
|
||||
ASN1 asn2 = seq[j];
|
||||
X501.AppendEntry(stringBuilder, asn2, quotes);
|
||||
if (j < seq.Count - 1)
|
||||
{
|
||||
stringBuilder.Append(separator);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x060009FF RID: 2559 RVA: 0x0002C13C File Offset: 0x0002A33C
|
||||
private static void AppendEntry(StringBuilder sb, ASN1 entry, bool quotes)
|
||||
{
|
||||
for (int i = 0; i < entry.Count; i++)
|
||||
{
|
||||
ASN1 asn = entry[i];
|
||||
ASN1 asn2 = asn[1];
|
||||
if (asn2 != null)
|
||||
{
|
||||
ASN1 asn3 = asn[0];
|
||||
if (asn3 != null)
|
||||
{
|
||||
if (asn3.CompareValue(X501.countryName))
|
||||
{
|
||||
sb.Append("C=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.organizationName))
|
||||
{
|
||||
sb.Append("O=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.organizationalUnitName))
|
||||
{
|
||||
sb.Append("OU=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.commonName))
|
||||
{
|
||||
sb.Append("CN=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.localityName))
|
||||
{
|
||||
sb.Append("L=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.stateOrProvinceName))
|
||||
{
|
||||
sb.Append("S=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.streetAddress))
|
||||
{
|
||||
sb.Append("STREET=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.domainComponent))
|
||||
{
|
||||
sb.Append("DC=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.userid))
|
||||
{
|
||||
sb.Append("UID=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.email))
|
||||
{
|
||||
sb.Append("E=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.dnQualifier))
|
||||
{
|
||||
sb.Append("dnQualifier=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.title))
|
||||
{
|
||||
sb.Append("T=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.surname))
|
||||
{
|
||||
sb.Append("SN=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.givenName))
|
||||
{
|
||||
sb.Append("G=");
|
||||
}
|
||||
else if (asn3.CompareValue(X501.initial))
|
||||
{
|
||||
sb.Append("I=");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("OID.");
|
||||
sb.Append(ASN1Convert.ToOid(asn3));
|
||||
sb.Append("=");
|
||||
}
|
||||
string text;
|
||||
if (asn2.Tag == 30)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int j = 1; j < asn2.Value.Length; j += 2)
|
||||
{
|
||||
stringBuilder.Append((char)asn2.Value[j]);
|
||||
}
|
||||
text = stringBuilder.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (asn2.Tag == 20)
|
||||
{
|
||||
text = Encoding.UTF7.GetString(asn2.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
text = Encoding.UTF8.GetString(asn2.Value);
|
||||
}
|
||||
char[] array = new char[] { ',', '+', '"', '\\', '<', '>', ';' };
|
||||
if (quotes && (text.IndexOfAny(array, 0, text.Length) > 0 || text.StartsWith(" ") || text.EndsWith(" ")))
|
||||
{
|
||||
text = "\"" + text + "\"";
|
||||
}
|
||||
}
|
||||
sb.Append(text);
|
||||
if (i < entry.Count - 1)
|
||||
{
|
||||
sb.Append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A00 RID: 2560 RVA: 0x0002C4B4 File Offset: 0x0002A6B4
|
||||
private static X520.AttributeTypeAndValue GetAttributeFromOid(string attributeType)
|
||||
{
|
||||
string text = attributeType.ToUpper(CultureInfo.InvariantCulture).Trim();
|
||||
string text2 = text;
|
||||
switch (text2)
|
||||
{
|
||||
case "C":
|
||||
return new X520.CountryName();
|
||||
case "O":
|
||||
return new X520.OrganizationName();
|
||||
case "OU":
|
||||
return new X520.OrganizationalUnitName();
|
||||
case "CN":
|
||||
return new X520.CommonName();
|
||||
case "L":
|
||||
return new X520.LocalityName();
|
||||
case "S":
|
||||
case "ST":
|
||||
return new X520.StateOrProvinceName();
|
||||
case "E":
|
||||
return new X520.EmailAddress();
|
||||
case "DC":
|
||||
return new X520.DomainComponent();
|
||||
case "UID":
|
||||
return new X520.UserId();
|
||||
case "DNQUALIFIER":
|
||||
return new X520.DnQualifier();
|
||||
case "T":
|
||||
return new X520.Title();
|
||||
case "SN":
|
||||
return new X520.Surname();
|
||||
case "G":
|
||||
return new X520.GivenName();
|
||||
case "I":
|
||||
return new X520.Initial();
|
||||
}
|
||||
if (text.StartsWith("OID."))
|
||||
{
|
||||
return new X520.Oid(text.Substring(4));
|
||||
}
|
||||
if (X501.IsOid(text))
|
||||
{
|
||||
return new X520.Oid(text);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A01 RID: 2561 RVA: 0x0002C684 File Offset: 0x0002A884
|
||||
private static bool IsOid(string oid)
|
||||
{
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
ASN1 asn = ASN1Convert.FromOid(oid);
|
||||
flag = asn.Tag == 6;
|
||||
}
|
||||
catch
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000A02 RID: 2562 RVA: 0x0002C6D8 File Offset: 0x0002A8D8
|
||||
private static X520.AttributeTypeAndValue ReadAttribute(string value, ref int pos)
|
||||
{
|
||||
while (value[pos] == ' ' && pos < value.Length)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
int num = value.IndexOf('=', pos);
|
||||
if (num == -1)
|
||||
{
|
||||
string text = Locale.GetText("No attribute found.");
|
||||
throw new FormatException(text);
|
||||
}
|
||||
string text2 = value.Substring(pos, num - pos);
|
||||
X520.AttributeTypeAndValue attributeFromOid = X501.GetAttributeFromOid(text2);
|
||||
if (attributeFromOid == null)
|
||||
{
|
||||
string text3 = Locale.GetText("Unknown attribute '{0}'.");
|
||||
throw new FormatException(string.Format(text3, text2));
|
||||
}
|
||||
pos = num + 1;
|
||||
return attributeFromOid;
|
||||
}
|
||||
|
||||
// Token: 0x06000A03 RID: 2563 RVA: 0x0002C76C File Offset: 0x0002A96C
|
||||
private static bool IsHex(char c)
|
||||
{
|
||||
if (char.IsDigit(c))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
char c2 = char.ToUpper(c, CultureInfo.InvariantCulture);
|
||||
return c2 >= 'A' && c2 <= 'F';
|
||||
}
|
||||
|
||||
// Token: 0x06000A04 RID: 2564 RVA: 0x0002C7A8 File Offset: 0x0002A9A8
|
||||
private static string ReadHex(string value, ref int pos)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(value[pos++]);
|
||||
stringBuilder.Append(value[pos]);
|
||||
if (pos < value.Length - 4 && value[pos + 1] == '\\' && X501.IsHex(value[pos + 2]))
|
||||
{
|
||||
pos += 2;
|
||||
stringBuilder.Append(value[pos++]);
|
||||
stringBuilder.Append(value[pos]);
|
||||
}
|
||||
byte[] array = CryptoConvert.FromHex(stringBuilder.ToString());
|
||||
return Encoding.UTF8.GetString(array);
|
||||
}
|
||||
|
||||
// Token: 0x06000A05 RID: 2565 RVA: 0x0002C858 File Offset: 0x0002AA58
|
||||
private static int ReadEscaped(StringBuilder sb, string value, int pos)
|
||||
{
|
||||
char c = value[pos];
|
||||
switch (c)
|
||||
{
|
||||
case ';':
|
||||
case '<':
|
||||
case '=':
|
||||
case '>':
|
||||
break;
|
||||
default:
|
||||
if (c != '"' && c != '#' && c != '+' && c != ',' && c != '\\')
|
||||
{
|
||||
if (pos >= value.Length - 2)
|
||||
{
|
||||
string text = Locale.GetText("Malformed escaped value '{0}'.");
|
||||
throw new FormatException(string.Format(text, value.Substring(pos)));
|
||||
}
|
||||
sb.Append(X501.ReadHex(value, ref pos));
|
||||
return pos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
sb.Append(value[pos]);
|
||||
return pos;
|
||||
}
|
||||
|
||||
// Token: 0x06000A06 RID: 2566 RVA: 0x0002C900 File Offset: 0x0002AB00
|
||||
private static int ReadQuoted(StringBuilder sb, string value, int pos)
|
||||
{
|
||||
int num = pos;
|
||||
while (pos <= value.Length)
|
||||
{
|
||||
char c = value[pos];
|
||||
if (c == '"')
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
if (c == '\\')
|
||||
{
|
||||
return X501.ReadEscaped(sb, value, pos);
|
||||
}
|
||||
sb.Append(value[pos]);
|
||||
pos++;
|
||||
}
|
||||
string text = Locale.GetText("Malformed quoted value '{0}'.");
|
||||
throw new FormatException(string.Format(text, value.Substring(num)));
|
||||
}
|
||||
|
||||
// Token: 0x06000A07 RID: 2567 RVA: 0x0002C980 File Offset: 0x0002AB80
|
||||
private static string ReadValue(string value, ref int pos)
|
||||
{
|
||||
int num = pos;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while (pos < value.Length)
|
||||
{
|
||||
char c = value[pos];
|
||||
switch (c)
|
||||
{
|
||||
case ';':
|
||||
case '<':
|
||||
case '=':
|
||||
case '>':
|
||||
{
|
||||
string text = Locale.GetText("Malformed value '{0}' contains '{1}' outside quotes.");
|
||||
throw new FormatException(string.Format(text, value.Substring(num), value[pos]));
|
||||
}
|
||||
default:
|
||||
if (c != '"')
|
||||
{
|
||||
if (c == '#' || c == '+')
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (c == ',')
|
||||
{
|
||||
pos++;
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
if (c != '\\')
|
||||
{
|
||||
stringBuilder.Append(value[pos]);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = X501.ReadEscaped(stringBuilder, value, ++pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = X501.ReadQuoted(stringBuilder, value, ++pos);
|
||||
}
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x06000A08 RID: 2568 RVA: 0x0002CA88 File Offset: 0x0002AC88
|
||||
public static ASN1 FromString(string rdn)
|
||||
{
|
||||
if (rdn == null)
|
||||
{
|
||||
throw new ArgumentNullException("rdn");
|
||||
}
|
||||
int i = 0;
|
||||
ASN1 asn = new ASN1(48);
|
||||
while (i < rdn.Length)
|
||||
{
|
||||
X520.AttributeTypeAndValue attributeTypeAndValue = X501.ReadAttribute(rdn, ref i);
|
||||
attributeTypeAndValue.Value = X501.ReadValue(rdn, ref i);
|
||||
ASN1 asn2 = new ASN1(49);
|
||||
asn2.Add(attributeTypeAndValue.GetASN1());
|
||||
asn.Add(asn2);
|
||||
}
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x04000273 RID: 627
|
||||
private static byte[] countryName = new byte[] { 85, 4, 6 };
|
||||
|
||||
// Token: 0x04000274 RID: 628
|
||||
private static byte[] organizationName = new byte[] { 85, 4, 10 };
|
||||
|
||||
// Token: 0x04000275 RID: 629
|
||||
private static byte[] organizationalUnitName = new byte[] { 85, 4, 11 };
|
||||
|
||||
// Token: 0x04000276 RID: 630
|
||||
private static byte[] commonName = new byte[] { 85, 4, 3 };
|
||||
|
||||
// Token: 0x04000277 RID: 631
|
||||
private static byte[] localityName = new byte[] { 85, 4, 7 };
|
||||
|
||||
// Token: 0x04000278 RID: 632
|
||||
private static byte[] stateOrProvinceName = new byte[] { 85, 4, 8 };
|
||||
|
||||
// Token: 0x04000279 RID: 633
|
||||
private static byte[] streetAddress = new byte[] { 85, 4, 9 };
|
||||
|
||||
// Token: 0x0400027A RID: 634
|
||||
private static byte[] domainComponent = new byte[] { 9, 146, 38, 137, 147, 242, 44, 100, 1, 25 };
|
||||
|
||||
// Token: 0x0400027B RID: 635
|
||||
private static byte[] userid = new byte[] { 9, 146, 38, 137, 147, 242, 44, 100, 1, 1 };
|
||||
|
||||
// Token: 0x0400027C RID: 636
|
||||
private static byte[] email = new byte[] { 42, 134, 72, 134, 247, 13, 1, 9, 1 };
|
||||
|
||||
// Token: 0x0400027D RID: 637
|
||||
private static byte[] dnQualifier = new byte[] { 85, 4, 46 };
|
||||
|
||||
// Token: 0x0400027E RID: 638
|
||||
private static byte[] title = new byte[] { 85, 4, 12 };
|
||||
|
||||
// Token: 0x0400027F RID: 639
|
||||
private static byte[] surname = new byte[] { 85, 4, 4 };
|
||||
|
||||
// Token: 0x04000280 RID: 640
|
||||
private static byte[] givenName = new byte[] { 85, 4, 42 };
|
||||
|
||||
// Token: 0x04000281 RID: 641
|
||||
private static byte[] initial = new byte[] { 85, 4, 43 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,713 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000BC RID: 188
|
||||
internal class X509Certificate : ISerializable
|
||||
{
|
||||
// Token: 0x06000A29 RID: 2601 RVA: 0x0002D4B8 File Offset: 0x0002B6B8
|
||||
public X509Certificate(byte[] data)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
if (data.Length > 0 && data[0] != 48)
|
||||
{
|
||||
try
|
||||
{
|
||||
data = X509Certificate.PEM("CERTIFICATE", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException(X509Certificate.encoding_error, ex);
|
||||
}
|
||||
}
|
||||
this.Parse(data);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A2A RID: 2602 RVA: 0x0002D52C File Offset: 0x0002B72C
|
||||
protected X509Certificate(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
this.Parse((byte[])info.GetValue("raw", typeof(byte[])));
|
||||
}
|
||||
|
||||
// Token: 0x06000A2C RID: 2604 RVA: 0x0002D574 File Offset: 0x0002B774
|
||||
private void Parse(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.decoder = new ASN1(data);
|
||||
if (this.decoder.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException(X509Certificate.encoding_error);
|
||||
}
|
||||
if (this.decoder[0].Tag != 48)
|
||||
{
|
||||
throw new CryptographicException(X509Certificate.encoding_error);
|
||||
}
|
||||
ASN1 asn = this.decoder[0];
|
||||
int num = 0;
|
||||
ASN1 asn2 = this.decoder[0][num];
|
||||
this.version = 1;
|
||||
if (asn2.Tag == 160 && asn2.Count > 0)
|
||||
{
|
||||
this.version += (int)asn2[0].Value[0];
|
||||
num++;
|
||||
}
|
||||
ASN1 asn3 = this.decoder[0][num++];
|
||||
if (asn3.Tag != 2)
|
||||
{
|
||||
throw new CryptographicException(X509Certificate.encoding_error);
|
||||
}
|
||||
this.serialnumber = asn3.Value;
|
||||
Array.Reverse(this.serialnumber, 0, this.serialnumber.Length);
|
||||
num++;
|
||||
this.issuer = asn.Element(num++, 48);
|
||||
this.m_issuername = X501.ToString(this.issuer);
|
||||
ASN1 asn4 = asn.Element(num++, 48);
|
||||
ASN1 asn5 = asn4[0];
|
||||
this.m_from = ASN1Convert.ToDateTime(asn5);
|
||||
ASN1 asn6 = asn4[1];
|
||||
this.m_until = ASN1Convert.ToDateTime(asn6);
|
||||
this.subject = asn.Element(num++, 48);
|
||||
this.m_subject = X501.ToString(this.subject);
|
||||
ASN1 asn7 = asn.Element(num++, 48);
|
||||
ASN1 asn8 = asn7.Element(0, 48);
|
||||
ASN1 asn9 = asn8.Element(0, 6);
|
||||
this.m_keyalgo = ASN1Convert.ToOid(asn9);
|
||||
ASN1 asn10 = asn8[1];
|
||||
this.m_keyalgoparams = ((asn8.Count <= 1) ? null : asn10.GetBytes());
|
||||
ASN1 asn11 = asn7.Element(1, 3);
|
||||
int num2 = asn11.Length - 1;
|
||||
this.m_publickey = new byte[num2];
|
||||
Buffer.BlockCopy(asn11.Value, 1, this.m_publickey, 0, num2);
|
||||
byte[] value = this.decoder[2].Value;
|
||||
this.signature = new byte[value.Length - 1];
|
||||
Buffer.BlockCopy(value, 1, this.signature, 0, this.signature.Length);
|
||||
asn8 = this.decoder[1];
|
||||
asn9 = asn8.Element(0, 6);
|
||||
this.m_signaturealgo = ASN1Convert.ToOid(asn9);
|
||||
asn10 = asn8[1];
|
||||
if (asn10 != null)
|
||||
{
|
||||
this.m_signaturealgoparams = asn10.GetBytes();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_signaturealgoparams = null;
|
||||
}
|
||||
ASN1 asn12 = asn.Element(num, 129);
|
||||
if (asn12 != null)
|
||||
{
|
||||
num++;
|
||||
this.issuerUniqueID = asn12.Value;
|
||||
}
|
||||
ASN1 asn13 = asn.Element(num, 130);
|
||||
if (asn13 != null)
|
||||
{
|
||||
num++;
|
||||
this.subjectUniqueID = asn13.Value;
|
||||
}
|
||||
ASN1 asn14 = asn.Element(num, 163);
|
||||
if (asn14 != null && asn14.Count == 1)
|
||||
{
|
||||
this.extensions = new X509ExtensionCollection(asn14[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extensions = new X509ExtensionCollection(null);
|
||||
}
|
||||
this.m_encodedcert = (byte[])data.Clone();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException(X509Certificate.encoding_error, ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A2D RID: 2605 RVA: 0x0002D904 File Offset: 0x0002BB04
|
||||
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;
|
||||
}
|
||||
|
||||
// Token: 0x1700013A RID: 314
|
||||
// (get) Token: 0x06000A2E RID: 2606 RVA: 0x0002D934 File Offset: 0x0002BB34
|
||||
// (set) Token: 0x06000A2F RID: 2607 RVA: 0x0002DA78 File Offset: 0x0002BC78
|
||||
public DSA DSA
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.m_keyalgoparams == null)
|
||||
{
|
||||
throw new CryptographicException("Missing key algorithm parameters.");
|
||||
}
|
||||
if (this._dsa == null)
|
||||
{
|
||||
DSAParameters dsaparameters = default(DSAParameters);
|
||||
ASN1 asn = new ASN1(this.m_publickey);
|
||||
if (asn == null || asn.Tag != 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
dsaparameters.Y = this.GetUnsignedBigInteger(asn.Value);
|
||||
ASN1 asn2 = new ASN1(this.m_keyalgoparams);
|
||||
if (asn2 == null || asn2.Tag != 48 || asn2.Count < 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (asn2[0].Tag != 2 || asn2[1].Tag != 2 || asn2[2].Tag != 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
dsaparameters.P = this.GetUnsignedBigInteger(asn2[0].Value);
|
||||
dsaparameters.Q = this.GetUnsignedBigInteger(asn2[1].Value);
|
||||
dsaparameters.G = this.GetUnsignedBigInteger(asn2[2].Value);
|
||||
this._dsa = new DSACryptoServiceProvider(dsaparameters.Y.Length << 3);
|
||||
this._dsa.ImportParameters(dsaparameters);
|
||||
}
|
||||
return this._dsa;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._dsa = value;
|
||||
if (value != null)
|
||||
{
|
||||
this._rsa = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700013B RID: 315
|
||||
// (get) Token: 0x06000A30 RID: 2608 RVA: 0x0002DA90 File Offset: 0x0002BC90
|
||||
public X509ExtensionCollection Extensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.extensions;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700013C RID: 316
|
||||
// (get) Token: 0x06000A31 RID: 2609 RVA: 0x0002DA98 File Offset: 0x0002BC98
|
||||
public byte[] Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.certhash == null)
|
||||
{
|
||||
string signaturealgo = this.m_signaturealgo;
|
||||
if (signaturealgo != null)
|
||||
{
|
||||
if (X509Certificate.<>f__switch$map13 == null)
|
||||
{
|
||||
X509Certificate.<>f__switch$map13 = new Dictionary<string, int>(5)
|
||||
{
|
||||
{ "1.2.840.113549.1.1.2", 0 },
|
||||
{ "1.2.840.113549.1.1.4", 1 },
|
||||
{ "1.2.840.113549.1.1.5", 2 },
|
||||
{ "1.3.14.3.2.29", 2 },
|
||||
{ "1.2.840.10040.4.3", 2 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (X509Certificate.<>f__switch$map13.TryGetValue(signaturealgo, out num))
|
||||
{
|
||||
HashAlgorithm hashAlgorithm;
|
||||
switch (num)
|
||||
{
|
||||
case 0:
|
||||
hashAlgorithm = HashAlgorithm.Create("MD2");
|
||||
break;
|
||||
case 1:
|
||||
hashAlgorithm = MD5.Create();
|
||||
break;
|
||||
case 2:
|
||||
hashAlgorithm = SHA1.Create();
|
||||
break;
|
||||
default:
|
||||
goto IL_BD;
|
||||
}
|
||||
if (this.decoder == null || this.decoder.Count < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] bytes = this.decoder[0].GetBytes();
|
||||
this.certhash = hashAlgorithm.ComputeHash(bytes, 0, bytes.Length);
|
||||
goto IL_100;
|
||||
}
|
||||
}
|
||||
IL_BD:
|
||||
return null;
|
||||
}
|
||||
IL_100:
|
||||
return (byte[])this.certhash.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700013D RID: 317
|
||||
// (get) Token: 0x06000A32 RID: 2610 RVA: 0x0002DBB8 File Offset: 0x0002BDB8
|
||||
public virtual string IssuerName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_issuername;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700013E RID: 318
|
||||
// (get) Token: 0x06000A33 RID: 2611 RVA: 0x0002DBC0 File Offset: 0x0002BDC0
|
||||
public virtual string KeyAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_keyalgo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700013F RID: 319
|
||||
// (get) Token: 0x06000A34 RID: 2612 RVA: 0x0002DBC8 File Offset: 0x0002BDC8
|
||||
// (set) Token: 0x06000A35 RID: 2613 RVA: 0x0002DBE8 File Offset: 0x0002BDE8
|
||||
public virtual byte[] KeyAlgorithmParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.m_keyalgoparams == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.m_keyalgoparams.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
this.m_keyalgoparams = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000140 RID: 320
|
||||
// (get) Token: 0x06000A36 RID: 2614 RVA: 0x0002DBF4 File Offset: 0x0002BDF4
|
||||
public virtual byte[] PublicKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.m_publickey == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.m_publickey.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000141 RID: 321
|
||||
// (get) Token: 0x06000A37 RID: 2615 RVA: 0x0002DC14 File Offset: 0x0002BE14
|
||||
// (set) Token: 0x06000A38 RID: 2616 RVA: 0x0002DCC0 File Offset: 0x0002BEC0
|
||||
public virtual RSA RSA
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._rsa == null)
|
||||
{
|
||||
RSAParameters rsaparameters = default(RSAParameters);
|
||||
ASN1 asn = new ASN1(this.m_publickey);
|
||||
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;
|
||||
int num = rsaparameters.Modulus.Length << 3;
|
||||
this._rsa = new RSACryptoServiceProvider(num);
|
||||
this._rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
return this._rsa;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
this._dsa = null;
|
||||
}
|
||||
this._rsa = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000142 RID: 322
|
||||
// (get) Token: 0x06000A39 RID: 2617 RVA: 0x0002DCD8 File Offset: 0x0002BED8
|
||||
public virtual byte[] RawData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.m_encodedcert == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.m_encodedcert.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000143 RID: 323
|
||||
// (get) Token: 0x06000A3A RID: 2618 RVA: 0x0002DCF8 File Offset: 0x0002BEF8
|
||||
public virtual byte[] SerialNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.serialnumber == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.serialnumber.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000144 RID: 324
|
||||
// (get) Token: 0x06000A3B RID: 2619 RVA: 0x0002DD18 File Offset: 0x0002BF18
|
||||
public virtual byte[] Signature
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.signature == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string signaturealgo = this.m_signaturealgo;
|
||||
if (signaturealgo != null)
|
||||
{
|
||||
if (X509Certificate.<>f__switch$map14 == null)
|
||||
{
|
||||
X509Certificate.<>f__switch$map14 = new Dictionary<string, int>(5)
|
||||
{
|
||||
{ "1.2.840.113549.1.1.2", 0 },
|
||||
{ "1.2.840.113549.1.1.4", 0 },
|
||||
{ "1.2.840.113549.1.1.5", 0 },
|
||||
{ "1.3.14.3.2.29", 0 },
|
||||
{ "1.2.840.10040.4.3", 1 }
|
||||
};
|
||||
}
|
||||
int num;
|
||||
if (X509Certificate.<>f__switch$map14.TryGetValue(signaturealgo, out num))
|
||||
{
|
||||
if (num == 0)
|
||||
{
|
||||
return (byte[])this.signature.Clone();
|
||||
}
|
||||
if (num == 1)
|
||||
{
|
||||
ASN1 asn = new ASN1(this.signature);
|
||||
if (asn == null || asn.Count != 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] value = asn[0].Value;
|
||||
byte[] value2 = asn[1].Value;
|
||||
byte[] array = new byte[40];
|
||||
int num2 = Math.Max(0, value.Length - 20);
|
||||
int num3 = Math.Max(0, 20 - value.Length);
|
||||
Buffer.BlockCopy(value, num2, array, num3, value.Length - num2);
|
||||
int num4 = Math.Max(0, value2.Length - 20);
|
||||
int num5 = Math.Max(20, 40 - value2.Length);
|
||||
Buffer.BlockCopy(value2, num4, array, num5, value2.Length - num4);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new CryptographicException("Unsupported hash algorithm: " + this.m_signaturealgo);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000145 RID: 325
|
||||
// (get) Token: 0x06000A3C RID: 2620 RVA: 0x0002DE88 File Offset: 0x0002C088
|
||||
public virtual string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_signaturealgo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000146 RID: 326
|
||||
// (get) Token: 0x06000A3D RID: 2621 RVA: 0x0002DE90 File Offset: 0x0002C090
|
||||
public virtual byte[] SignatureAlgorithmParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.m_signaturealgoparams == null)
|
||||
{
|
||||
return this.m_signaturealgoparams;
|
||||
}
|
||||
return (byte[])this.m_signaturealgoparams.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000147 RID: 327
|
||||
// (get) Token: 0x06000A3E RID: 2622 RVA: 0x0002DEC0 File Offset: 0x0002C0C0
|
||||
public virtual string SubjectName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_subject;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000148 RID: 328
|
||||
// (get) Token: 0x06000A3F RID: 2623 RVA: 0x0002DEC8 File Offset: 0x0002C0C8
|
||||
public virtual DateTime ValidFrom
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_from;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000149 RID: 329
|
||||
// (get) Token: 0x06000A40 RID: 2624 RVA: 0x0002DED0 File Offset: 0x0002C0D0
|
||||
public virtual DateTime ValidUntil
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_until;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700014A RID: 330
|
||||
// (get) Token: 0x06000A41 RID: 2625 RVA: 0x0002DED8 File Offset: 0x0002C0D8
|
||||
public int Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.version;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700014B RID: 331
|
||||
// (get) Token: 0x06000A42 RID: 2626 RVA: 0x0002DEE0 File Offset: 0x0002C0E0
|
||||
public bool IsCurrent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.WasCurrent(DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A43 RID: 2627 RVA: 0x0002DEF0 File Offset: 0x0002C0F0
|
||||
public bool WasCurrent(DateTime instant)
|
||||
{
|
||||
return instant > this.ValidFrom && instant <= this.ValidUntil;
|
||||
}
|
||||
|
||||
// Token: 0x1700014C RID: 332
|
||||
// (get) Token: 0x06000A44 RID: 2628 RVA: 0x0002DF20 File Offset: 0x0002C120
|
||||
public byte[] IssuerUniqueIdentifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.issuerUniqueID == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.issuerUniqueID.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700014D RID: 333
|
||||
// (get) Token: 0x06000A45 RID: 2629 RVA: 0x0002DF40 File Offset: 0x0002C140
|
||||
public byte[] SubjectUniqueIdentifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.subjectUniqueID == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.subjectUniqueID.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A46 RID: 2630 RVA: 0x0002DF60 File Offset: 0x0002C160
|
||||
internal bool VerifySignature(DSA dsa)
|
||||
{
|
||||
DSASignatureDeformatter dsasignatureDeformatter = new DSASignatureDeformatter(dsa);
|
||||
dsasignatureDeformatter.SetHashAlgorithm("SHA1");
|
||||
return dsasignatureDeformatter.VerifySignature(this.Hash, this.Signature);
|
||||
}
|
||||
|
||||
// Token: 0x06000A47 RID: 2631 RVA: 0x0002DF94 File Offset: 0x0002C194
|
||||
internal string GetHashNameFromOID(string oid)
|
||||
{
|
||||
switch (oid)
|
||||
{
|
||||
case "1.2.840.113549.1.1.2":
|
||||
return "MD2";
|
||||
case "1.2.840.113549.1.1.4":
|
||||
return "MD5";
|
||||
case "1.2.840.113549.1.1.5":
|
||||
case "1.3.14.3.2.29":
|
||||
return "SHA1";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A48 RID: 2632 RVA: 0x0002E02C File Offset: 0x0002C22C
|
||||
internal bool VerifySignature(RSA rsa)
|
||||
{
|
||||
RSAPKCS1SignatureDeformatter rsapkcs1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
|
||||
string hashNameFromOID = this.GetHashNameFromOID(this.m_signaturealgo);
|
||||
if (hashNameFromOID == null)
|
||||
{
|
||||
throw new CryptographicException("Unsupported hash algorithm: " + this.m_signaturealgo);
|
||||
}
|
||||
rsapkcs1SignatureDeformatter.SetHashAlgorithm(hashNameFromOID);
|
||||
return rsapkcs1SignatureDeformatter.VerifySignature(this.Hash, this.Signature);
|
||||
}
|
||||
|
||||
// Token: 0x06000A49 RID: 2633 RVA: 0x0002E084 File Offset: 0x0002C284
|
||||
public bool VerifySignature(AsymmetricAlgorithm aa)
|
||||
{
|
||||
if (aa == null)
|
||||
{
|
||||
throw new ArgumentNullException("aa");
|
||||
}
|
||||
if (aa is RSA)
|
||||
{
|
||||
return this.VerifySignature(aa as RSA);
|
||||
}
|
||||
if (aa is DSA)
|
||||
{
|
||||
return this.VerifySignature(aa as DSA);
|
||||
}
|
||||
throw new NotSupportedException("Unknown Asymmetric Algorithm " + aa.ToString());
|
||||
}
|
||||
|
||||
// Token: 0x06000A4A RID: 2634 RVA: 0x0002E0E8 File Offset: 0x0002C2E8
|
||||
public bool CheckSignature(byte[] hash, string hashAlgorithm, byte[] signature)
|
||||
{
|
||||
RSACryptoServiceProvider rsacryptoServiceProvider = (RSACryptoServiceProvider)this.RSA;
|
||||
return rsacryptoServiceProvider.VerifyHash(hash, hashAlgorithm, signature);
|
||||
}
|
||||
|
||||
// Token: 0x1700014E RID: 334
|
||||
// (get) Token: 0x06000A4B RID: 2635 RVA: 0x0002E10C File Offset: 0x0002C30C
|
||||
public bool IsSelfSigned
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_issuername == this.m_subject && this.VerifySignature(this.RSA);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A4C RID: 2636 RVA: 0x0002E140 File Offset: 0x0002C340
|
||||
public ASN1 GetIssuerName()
|
||||
{
|
||||
return this.issuer;
|
||||
}
|
||||
|
||||
// Token: 0x06000A4D RID: 2637 RVA: 0x0002E148 File Offset: 0x0002C348
|
||||
public ASN1 GetSubjectName()
|
||||
{
|
||||
return this.subject;
|
||||
}
|
||||
|
||||
// Token: 0x06000A4E RID: 2638 RVA: 0x0002E150 File Offset: 0x0002C350
|
||||
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("raw", this.m_encodedcert);
|
||||
}
|
||||
|
||||
// Token: 0x06000A4F RID: 2639 RVA: 0x0002E164 File Offset: 0x0002C364
|
||||
private static byte[] PEM(string type, byte[] data)
|
||||
{
|
||||
string @string = Encoding.ASCII.GetString(data);
|
||||
string text = string.Format("-----BEGIN {0}-----", type);
|
||||
string text2 = string.Format("-----END {0}-----", type);
|
||||
int num = @string.IndexOf(text) + text.Length;
|
||||
int num2 = @string.IndexOf(text2, num);
|
||||
string text3 = @string.Substring(num, num2 - num);
|
||||
return Convert.FromBase64String(text3);
|
||||
}
|
||||
|
||||
// Token: 0x04000292 RID: 658
|
||||
private ASN1 decoder;
|
||||
|
||||
// Token: 0x04000293 RID: 659
|
||||
private byte[] m_encodedcert;
|
||||
|
||||
// Token: 0x04000294 RID: 660
|
||||
private DateTime m_from;
|
||||
|
||||
// Token: 0x04000295 RID: 661
|
||||
private DateTime m_until;
|
||||
|
||||
// Token: 0x04000296 RID: 662
|
||||
private ASN1 issuer;
|
||||
|
||||
// Token: 0x04000297 RID: 663
|
||||
private string m_issuername;
|
||||
|
||||
// Token: 0x04000298 RID: 664
|
||||
private string m_keyalgo;
|
||||
|
||||
// Token: 0x04000299 RID: 665
|
||||
private byte[] m_keyalgoparams;
|
||||
|
||||
// Token: 0x0400029A RID: 666
|
||||
private ASN1 subject;
|
||||
|
||||
// Token: 0x0400029B RID: 667
|
||||
private string m_subject;
|
||||
|
||||
// Token: 0x0400029C RID: 668
|
||||
private byte[] m_publickey;
|
||||
|
||||
// Token: 0x0400029D RID: 669
|
||||
private byte[] signature;
|
||||
|
||||
// Token: 0x0400029E RID: 670
|
||||
private string m_signaturealgo;
|
||||
|
||||
// Token: 0x0400029F RID: 671
|
||||
private byte[] m_signaturealgoparams;
|
||||
|
||||
// Token: 0x040002A0 RID: 672
|
||||
private byte[] certhash;
|
||||
|
||||
// Token: 0x040002A1 RID: 673
|
||||
private RSA _rsa;
|
||||
|
||||
// Token: 0x040002A2 RID: 674
|
||||
private DSA _dsa;
|
||||
|
||||
// Token: 0x040002A3 RID: 675
|
||||
private int version;
|
||||
|
||||
// Token: 0x040002A4 RID: 676
|
||||
private byte[] serialnumber;
|
||||
|
||||
// Token: 0x040002A5 RID: 677
|
||||
private byte[] issuerUniqueID;
|
||||
|
||||
// Token: 0x040002A6 RID: 678
|
||||
private byte[] subjectUniqueID;
|
||||
|
||||
// Token: 0x040002A7 RID: 679
|
||||
private X509ExtensionCollection extensions;
|
||||
|
||||
// Token: 0x040002A8 RID: 680
|
||||
private static string encoding_error = Locale.GetText("Input data cannot be coded as a valid certificate.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000BD RID: 189
|
||||
[Serializable]
|
||||
internal class X509CertificateCollection : CollectionBase, IEnumerable
|
||||
{
|
||||
// Token: 0x06000A50 RID: 2640 RVA: 0x0002E1C4 File Offset: 0x0002C3C4
|
||||
public X509CertificateCollection()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000A51 RID: 2641 RVA: 0x0002E1CC File Offset: 0x0002C3CC
|
||||
public X509CertificateCollection(X509Certificate[] value)
|
||||
{
|
||||
this.AddRange(value);
|
||||
}
|
||||
|
||||
// Token: 0x06000A52 RID: 2642 RVA: 0x0002E1DC File Offset: 0x0002C3DC
|
||||
public X509CertificateCollection(X509CertificateCollection value)
|
||||
{
|
||||
this.AddRange(value);
|
||||
}
|
||||
|
||||
// Token: 0x06000A53 RID: 2643 RVA: 0x0002E1EC File Offset: 0x0002C3EC
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return base.InnerList.GetEnumerator();
|
||||
}
|
||||
|
||||
// Token: 0x1700014F RID: 335
|
||||
public X509Certificate this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (X509Certificate)base.InnerList[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
base.InnerList[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A56 RID: 2646 RVA: 0x0002E220 File Offset: 0x0002C420
|
||||
public int Add(X509Certificate value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
return base.InnerList.Add(value);
|
||||
}
|
||||
|
||||
// Token: 0x06000A57 RID: 2647 RVA: 0x0002E240 File Offset: 0x0002C440
|
||||
public void AddRange(X509Certificate[] value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
{
|
||||
base.InnerList.Add(value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A58 RID: 2648 RVA: 0x0002E284 File Offset: 0x0002C484
|
||||
public void AddRange(X509CertificateCollection value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
for (int i = 0; i < value.InnerList.Count; i++)
|
||||
{
|
||||
base.InnerList.Add(value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A59 RID: 2649 RVA: 0x0002E2D4 File Offset: 0x0002C4D4
|
||||
public bool Contains(X509Certificate value)
|
||||
{
|
||||
return this.IndexOf(value) != -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000A5A RID: 2650 RVA: 0x0002E2E4 File Offset: 0x0002C4E4
|
||||
public void CopyTo(X509Certificate[] array, int index)
|
||||
{
|
||||
base.InnerList.CopyTo(array, index);
|
||||
}
|
||||
|
||||
// Token: 0x06000A5B RID: 2651 RVA: 0x0002E2F4 File Offset: 0x0002C4F4
|
||||
public new X509CertificateCollection.X509CertificateEnumerator GetEnumerator()
|
||||
{
|
||||
return new X509CertificateCollection.X509CertificateEnumerator(this);
|
||||
}
|
||||
|
||||
// Token: 0x06000A5C RID: 2652 RVA: 0x0002E2FC File Offset: 0x0002C4FC
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.InnerList.GetHashCode();
|
||||
}
|
||||
|
||||
// Token: 0x06000A5D RID: 2653 RVA: 0x0002E30C File Offset: 0x0002C50C
|
||||
public int IndexOf(X509Certificate value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
byte[] hash = value.Hash;
|
||||
for (int i = 0; i < base.InnerList.Count; i++)
|
||||
{
|
||||
X509Certificate x509Certificate = (X509Certificate)base.InnerList[i];
|
||||
if (this.Compare(x509Certificate.Hash, hash))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000A5E RID: 2654 RVA: 0x0002E374 File Offset: 0x0002C574
|
||||
public void Insert(int index, X509Certificate value)
|
||||
{
|
||||
base.InnerList.Insert(index, value);
|
||||
}
|
||||
|
||||
// Token: 0x06000A5F RID: 2655 RVA: 0x0002E384 File Offset: 0x0002C584
|
||||
public void Remove(X509Certificate value)
|
||||
{
|
||||
base.InnerList.Remove(value);
|
||||
}
|
||||
|
||||
// Token: 0x06000A60 RID: 2656 RVA: 0x0002E394 File Offset: 0x0002C594
|
||||
private bool Compare(byte[] array1, byte[] array2)
|
||||
{
|
||||
if (array1 == null && array2 == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (array1 == null || 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: 0x020000BE RID: 190
|
||||
public class X509CertificateEnumerator : IEnumerator
|
||||
{
|
||||
// Token: 0x06000A61 RID: 2657 RVA: 0x0002E3EC File Offset: 0x0002C5EC
|
||||
public X509CertificateEnumerator(X509CertificateCollection mappings)
|
||||
{
|
||||
this.enumerator = ((IEnumerable)mappings).GetEnumerator();
|
||||
}
|
||||
|
||||
// Token: 0x17000150 RID: 336
|
||||
// (get) Token: 0x06000A62 RID: 2658 RVA: 0x0002E400 File Offset: 0x0002C600
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A63 RID: 2659 RVA: 0x0002E410 File Offset: 0x0002C610
|
||||
bool IEnumerator.MoveNext()
|
||||
{
|
||||
return this.enumerator.MoveNext();
|
||||
}
|
||||
|
||||
// Token: 0x06000A64 RID: 2660 RVA: 0x0002E420 File Offset: 0x0002C620
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
this.enumerator.Reset();
|
||||
}
|
||||
|
||||
// Token: 0x17000151 RID: 337
|
||||
// (get) Token: 0x06000A65 RID: 2661 RVA: 0x0002E430 File Offset: 0x0002C630
|
||||
public X509Certificate Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return (X509Certificate)this.enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A66 RID: 2662 RVA: 0x0002E444 File Offset: 0x0002C644
|
||||
public bool MoveNext()
|
||||
{
|
||||
return this.enumerator.MoveNext();
|
||||
}
|
||||
|
||||
// Token: 0x06000A67 RID: 2663 RVA: 0x0002E454 File Offset: 0x0002C654
|
||||
public void Reset()
|
||||
{
|
||||
this.enumerator.Reset();
|
||||
}
|
||||
|
||||
// Token: 0x040002AC RID: 684
|
||||
private IEnumerator enumerator;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using Mono.Security.X509.Extensions;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000BF RID: 191
|
||||
internal class X509Chain
|
||||
{
|
||||
// Token: 0x06000A68 RID: 2664 RVA: 0x0002E464 File Offset: 0x0002C664
|
||||
public X509Chain()
|
||||
{
|
||||
this.certs = new X509CertificateCollection();
|
||||
}
|
||||
|
||||
// Token: 0x06000A69 RID: 2665 RVA: 0x0002E478 File Offset: 0x0002C678
|
||||
public X509Chain(X509CertificateCollection chain)
|
||||
: this()
|
||||
{
|
||||
this._chain = new X509CertificateCollection();
|
||||
this._chain.AddRange(chain);
|
||||
}
|
||||
|
||||
// Token: 0x17000152 RID: 338
|
||||
// (get) Token: 0x06000A6A RID: 2666 RVA: 0x0002E498 File Offset: 0x0002C698
|
||||
public X509CertificateCollection Chain
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._chain;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000153 RID: 339
|
||||
// (get) Token: 0x06000A6B RID: 2667 RVA: 0x0002E4A0 File Offset: 0x0002C6A0
|
||||
public X509Certificate Root
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._root;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000154 RID: 340
|
||||
// (get) Token: 0x06000A6C RID: 2668 RVA: 0x0002E4A8 File Offset: 0x0002C6A8
|
||||
public X509ChainStatusFlags Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._status;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000155 RID: 341
|
||||
// (get) Token: 0x06000A6D RID: 2669 RVA: 0x0002E4B0 File Offset: 0x0002C6B0
|
||||
// (set) Token: 0x06000A6E RID: 2670 RVA: 0x0002E4E8 File Offset: 0x0002C6E8
|
||||
public X509CertificateCollection TrustAnchors
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.roots == null)
|
||||
{
|
||||
this.roots = new X509CertificateCollection();
|
||||
this.roots.AddRange(X509StoreManager.TrustedRootCertificates);
|
||||
return this.roots;
|
||||
}
|
||||
return this.roots;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.roots = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A6F RID: 2671 RVA: 0x0002E4F4 File Offset: 0x0002C6F4
|
||||
public void LoadCertificate(X509Certificate x509)
|
||||
{
|
||||
this.certs.Add(x509);
|
||||
}
|
||||
|
||||
// Token: 0x06000A70 RID: 2672 RVA: 0x0002E504 File Offset: 0x0002C704
|
||||
public void LoadCertificates(X509CertificateCollection collection)
|
||||
{
|
||||
this.certs.AddRange(collection);
|
||||
}
|
||||
|
||||
// Token: 0x06000A71 RID: 2673 RVA: 0x0002E514 File Offset: 0x0002C714
|
||||
public X509Certificate FindByIssuerName(string issuerName)
|
||||
{
|
||||
foreach (X509Certificate x509Certificate in this.certs)
|
||||
{
|
||||
if (x509Certificate.IssuerName == issuerName)
|
||||
{
|
||||
return x509Certificate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A72 RID: 2674 RVA: 0x0002E594 File Offset: 0x0002C794
|
||||
public bool Build(X509Certificate leaf)
|
||||
{
|
||||
this._status = X509ChainStatusFlags.NoError;
|
||||
if (this._chain == null)
|
||||
{
|
||||
this._chain = new X509CertificateCollection();
|
||||
X509Certificate x509Certificate = leaf;
|
||||
X509Certificate x509Certificate2 = x509Certificate;
|
||||
while (x509Certificate != null && !x509Certificate.IsSelfSigned)
|
||||
{
|
||||
x509Certificate2 = x509Certificate;
|
||||
this._chain.Add(x509Certificate);
|
||||
x509Certificate = this.FindCertificateParent(x509Certificate);
|
||||
}
|
||||
this._root = this.FindCertificateRoot(x509Certificate2);
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = this._chain.Count;
|
||||
if (count > 0)
|
||||
{
|
||||
if (this.IsParent(leaf, this._chain[0]))
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < count; i++)
|
||||
{
|
||||
if (!this.IsParent(this._chain[i - 1], this._chain[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == count)
|
||||
{
|
||||
this._root = this.FindCertificateRoot(this._chain[count - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._root = this.FindCertificateRoot(leaf);
|
||||
}
|
||||
}
|
||||
if (this._chain != null && this._status == X509ChainStatusFlags.NoError)
|
||||
{
|
||||
foreach (X509Certificate x509Certificate3 in this._chain)
|
||||
{
|
||||
if (!this.IsValid(x509Certificate3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!this.IsValid(leaf))
|
||||
{
|
||||
if (this._status == X509ChainStatusFlags.NotTimeNested)
|
||||
{
|
||||
this._status = X509ChainStatusFlags.NotTimeValid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (this._root != null && !this.IsValid(this._root))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
IL_1A6:
|
||||
return this._status == X509ChainStatusFlags.NoError;
|
||||
}
|
||||
|
||||
// Token: 0x06000A73 RID: 2675 RVA: 0x0002E770 File Offset: 0x0002C970
|
||||
public void Reset()
|
||||
{
|
||||
this._status = X509ChainStatusFlags.NoError;
|
||||
this.roots = null;
|
||||
this.certs.Clear();
|
||||
if (this._chain != null)
|
||||
{
|
||||
this._chain.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A74 RID: 2676 RVA: 0x0002E7A4 File Offset: 0x0002C9A4
|
||||
private bool IsValid(X509Certificate cert)
|
||||
{
|
||||
if (!cert.IsCurrent)
|
||||
{
|
||||
this._status = X509ChainStatusFlags.NotTimeNested;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000A75 RID: 2677 RVA: 0x0002E7BC File Offset: 0x0002C9BC
|
||||
private X509Certificate FindCertificateParent(X509Certificate child)
|
||||
{
|
||||
foreach (X509Certificate x509Certificate in this.certs)
|
||||
{
|
||||
if (this.IsParent(child, x509Certificate))
|
||||
{
|
||||
return x509Certificate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A76 RID: 2678 RVA: 0x0002E838 File Offset: 0x0002CA38
|
||||
private X509Certificate FindCertificateRoot(X509Certificate potentialRoot)
|
||||
{
|
||||
if (potentialRoot == null)
|
||||
{
|
||||
this._status = X509ChainStatusFlags.PartialChain;
|
||||
return null;
|
||||
}
|
||||
if (this.IsTrusted(potentialRoot))
|
||||
{
|
||||
return potentialRoot;
|
||||
}
|
||||
foreach (X509Certificate x509Certificate in this.TrustAnchors)
|
||||
{
|
||||
if (this.IsParent(potentialRoot, x509Certificate))
|
||||
{
|
||||
return x509Certificate;
|
||||
}
|
||||
}
|
||||
if (potentialRoot.IsSelfSigned)
|
||||
{
|
||||
this._status = X509ChainStatusFlags.UntrustedRoot;
|
||||
return potentialRoot;
|
||||
}
|
||||
this._status = X509ChainStatusFlags.PartialChain;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A77 RID: 2679 RVA: 0x0002E8F4 File Offset: 0x0002CAF4
|
||||
private bool IsTrusted(X509Certificate potentialTrusted)
|
||||
{
|
||||
return this.TrustAnchors.Contains(potentialTrusted);
|
||||
}
|
||||
|
||||
// Token: 0x06000A78 RID: 2680 RVA: 0x0002E904 File Offset: 0x0002CB04
|
||||
private bool IsParent(X509Certificate child, X509Certificate parent)
|
||||
{
|
||||
if (child.IssuerName != parent.SubjectName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (parent.Version > 2 && !this.IsTrusted(parent))
|
||||
{
|
||||
X509Extension x509Extension = parent.Extensions["2.5.29.19"];
|
||||
if (x509Extension != null)
|
||||
{
|
||||
BasicConstraintsExtension basicConstraintsExtension = new BasicConstraintsExtension(x509Extension);
|
||||
if (!basicConstraintsExtension.CertificateAuthority)
|
||||
{
|
||||
this._status = X509ChainStatusFlags.InvalidBasicConstraints;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._status = X509ChainStatusFlags.InvalidBasicConstraints;
|
||||
}
|
||||
}
|
||||
if (!child.VerifySignature(parent.RSA))
|
||||
{
|
||||
this._status = X509ChainStatusFlags.NotSignatureValid;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x040002AD RID: 685
|
||||
private X509CertificateCollection roots;
|
||||
|
||||
// Token: 0x040002AE RID: 686
|
||||
private X509CertificateCollection certs;
|
||||
|
||||
// Token: 0x040002AF RID: 687
|
||||
private X509Certificate _root;
|
||||
|
||||
// Token: 0x040002B0 RID: 688
|
||||
private X509CertificateCollection _chain;
|
||||
|
||||
// Token: 0x040002B1 RID: 689
|
||||
private X509ChainStatusFlags _status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C0 RID: 192
|
||||
[Flags]
|
||||
[Serializable]
|
||||
internal enum X509ChainStatusFlags
|
||||
{
|
||||
// Token: 0x040002B3 RID: 691
|
||||
InvalidBasicConstraints = 1024,
|
||||
// Token: 0x040002B4 RID: 692
|
||||
NoError = 0,
|
||||
// Token: 0x040002B5 RID: 693
|
||||
NotSignatureValid = 8,
|
||||
// Token: 0x040002B6 RID: 694
|
||||
NotTimeNested = 2,
|
||||
// Token: 0x040002B7 RID: 695
|
||||
NotTimeValid = 1,
|
||||
// Token: 0x040002B8 RID: 696
|
||||
PartialChain = 65536,
|
||||
// Token: 0x040002B9 RID: 697
|
||||
UntrustedRoot = 32
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Security.X509.Extensions;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000BA RID: 186
|
||||
internal class X509Crl
|
||||
{
|
||||
// Token: 0x06000A09 RID: 2569 RVA: 0x0002CAF8 File Offset: 0x0002ACF8
|
||||
public X509Crl(byte[] crl)
|
||||
{
|
||||
if (crl == null)
|
||||
{
|
||||
throw new ArgumentNullException("crl");
|
||||
}
|
||||
this.encoded = (byte[])crl.Clone();
|
||||
this.Parse(this.encoded);
|
||||
}
|
||||
|
||||
// Token: 0x06000A0A RID: 2570 RVA: 0x0002CB3C File Offset: 0x0002AD3C
|
||||
private void Parse(byte[] crl)
|
||||
{
|
||||
string text = "Input data cannot be coded as a valid CRL.";
|
||||
try
|
||||
{
|
||||
ASN1 asn = new ASN1(this.encoded);
|
||||
if (asn.Tag != 48 || asn.Count != 3)
|
||||
{
|
||||
throw new CryptographicException(text);
|
||||
}
|
||||
ASN1 asn2 = asn[0];
|
||||
if (asn2.Tag != 48 || asn2.Count < 3)
|
||||
{
|
||||
throw new CryptographicException(text);
|
||||
}
|
||||
int num = 0;
|
||||
if (asn2[num].Tag == 2)
|
||||
{
|
||||
this.version = asn2[num++].Value[0] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.version = 1;
|
||||
}
|
||||
this.signatureOID = ASN1Convert.ToOid(asn2[num++][0]);
|
||||
this.issuer = X501.ToString(asn2[num++]);
|
||||
this.thisUpdate = ASN1Convert.ToDateTime(asn2[num++]);
|
||||
ASN1 asn3 = asn2[num++];
|
||||
if (asn3.Tag == 23 || asn3.Tag == 24)
|
||||
{
|
||||
this.nextUpdate = ASN1Convert.ToDateTime(asn3);
|
||||
asn3 = asn2[num++];
|
||||
}
|
||||
this.entries = new ArrayList();
|
||||
if (asn3 != null && asn3.Tag == 48)
|
||||
{
|
||||
ASN1 asn4 = asn3;
|
||||
for (int i = 0; i < asn4.Count; i++)
|
||||
{
|
||||
this.entries.Add(new X509Crl.X509CrlEntry(asn4[i]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num--;
|
||||
}
|
||||
ASN1 asn5 = asn2[num];
|
||||
if (asn5 != null && asn5.Tag == 160 && asn5.Count == 1)
|
||||
{
|
||||
this.extensions = new X509ExtensionCollection(asn5[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extensions = new X509ExtensionCollection(null);
|
||||
}
|
||||
string text2 = ASN1Convert.ToOid(asn[1][0]);
|
||||
if (this.signatureOID != text2)
|
||||
{
|
||||
throw new CryptographicException(text + " [Non-matching signature algorithms in CRL]");
|
||||
}
|
||||
byte[] value = asn[2].Value;
|
||||
this.signature = new byte[value.Length - 1];
|
||||
Buffer.BlockCopy(value, 1, this.signature, 0, this.signature.Length);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new CryptographicException(text);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700012A RID: 298
|
||||
// (get) Token: 0x06000A0B RID: 2571 RVA: 0x0002CDBC File Offset: 0x0002AFBC
|
||||
public ArrayList Entries
|
||||
{
|
||||
get
|
||||
{
|
||||
return ArrayList.ReadOnly(this.entries);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700012B RID: 299
|
||||
public X509Crl.X509CrlEntry this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (X509Crl.X509CrlEntry)this.entries[index];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700012C RID: 300
|
||||
public X509Crl.X509CrlEntry this[byte[] serialNumber]
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetCrlEntry(serialNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700012D RID: 301
|
||||
// (get) Token: 0x06000A0E RID: 2574 RVA: 0x0002CDEC File Offset: 0x0002AFEC
|
||||
public X509ExtensionCollection Extensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.extensions;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700012E RID: 302
|
||||
// (get) Token: 0x06000A0F RID: 2575 RVA: 0x0002CDF4 File Offset: 0x0002AFF4
|
||||
public byte[] Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.hash_value == null)
|
||||
{
|
||||
ASN1 asn = new ASN1(this.encoded);
|
||||
byte[] bytes = asn[0].GetBytes();
|
||||
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(this.GetHashName());
|
||||
this.hash_value = hashAlgorithm.ComputeHash(bytes);
|
||||
}
|
||||
return this.hash_value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700012F RID: 303
|
||||
// (get) Token: 0x06000A10 RID: 2576 RVA: 0x0002CE44 File Offset: 0x0002B044
|
||||
public string IssuerName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.issuer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000130 RID: 304
|
||||
// (get) Token: 0x06000A11 RID: 2577 RVA: 0x0002CE4C File Offset: 0x0002B04C
|
||||
public DateTime NextUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.nextUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000131 RID: 305
|
||||
// (get) Token: 0x06000A12 RID: 2578 RVA: 0x0002CE54 File Offset: 0x0002B054
|
||||
public DateTime ThisUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.thisUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000132 RID: 306
|
||||
// (get) Token: 0x06000A13 RID: 2579 RVA: 0x0002CE5C File Offset: 0x0002B05C
|
||||
public string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.signatureOID;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000133 RID: 307
|
||||
// (get) Token: 0x06000A14 RID: 2580 RVA: 0x0002CE64 File Offset: 0x0002B064
|
||||
public byte[] Signature
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.signature == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this.signature.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000134 RID: 308
|
||||
// (get) Token: 0x06000A15 RID: 2581 RVA: 0x0002CE84 File Offset: 0x0002B084
|
||||
public byte[] RawData
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte[])this.encoded.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000135 RID: 309
|
||||
// (get) Token: 0x06000A16 RID: 2582 RVA: 0x0002CE98 File Offset: 0x0002B098
|
||||
public byte Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.version;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000136 RID: 310
|
||||
// (get) Token: 0x06000A17 RID: 2583 RVA: 0x0002CEA0 File Offset: 0x0002B0A0
|
||||
public bool IsCurrent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.WasCurrent(DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A18 RID: 2584 RVA: 0x0002CEB0 File Offset: 0x0002B0B0
|
||||
public bool WasCurrent(DateTime instant)
|
||||
{
|
||||
if (this.nextUpdate == DateTime.MinValue)
|
||||
{
|
||||
return instant >= this.thisUpdate;
|
||||
}
|
||||
return instant >= this.thisUpdate && instant <= this.nextUpdate;
|
||||
}
|
||||
|
||||
// Token: 0x06000A19 RID: 2585 RVA: 0x0002CF00 File Offset: 0x0002B100
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return (byte[])this.encoded.Clone();
|
||||
}
|
||||
|
||||
// Token: 0x06000A1A RID: 2586 RVA: 0x0002CF14 File Offset: 0x0002B114
|
||||
private bool Compare(byte[] array1, byte[] array2)
|
||||
{
|
||||
if (array1 == null && array2 == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (array1 == null || 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: 0x06000A1B RID: 2587 RVA: 0x0002CF6C File Offset: 0x0002B16C
|
||||
public X509Crl.X509CrlEntry GetCrlEntry(X509Certificate x509)
|
||||
{
|
||||
if (x509 == null)
|
||||
{
|
||||
throw new ArgumentNullException("x509");
|
||||
}
|
||||
return this.GetCrlEntry(x509.SerialNumber);
|
||||
}
|
||||
|
||||
// Token: 0x06000A1C RID: 2588 RVA: 0x0002CF8C File Offset: 0x0002B18C
|
||||
public X509Crl.X509CrlEntry GetCrlEntry(byte[] serialNumber)
|
||||
{
|
||||
if (serialNumber == null)
|
||||
{
|
||||
throw new ArgumentNullException("serialNumber");
|
||||
}
|
||||
for (int i = 0; i < this.entries.Count; i++)
|
||||
{
|
||||
X509Crl.X509CrlEntry x509CrlEntry = (X509Crl.X509CrlEntry)this.entries[i];
|
||||
if (this.Compare(serialNumber, x509CrlEntry.SerialNumber))
|
||||
{
|
||||
return x509CrlEntry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A1D RID: 2589 RVA: 0x0002CFF0 File Offset: 0x0002B1F0
|
||||
public bool VerifySignature(X509Certificate x509)
|
||||
{
|
||||
if (x509 == null)
|
||||
{
|
||||
throw new ArgumentNullException("x509");
|
||||
}
|
||||
if (x509.Version >= 3)
|
||||
{
|
||||
X509Extension x509Extension = x509.Extensions["2.5.29.15"];
|
||||
if (x509Extension != null)
|
||||
{
|
||||
KeyUsageExtension keyUsageExtension = new KeyUsageExtension(x509Extension);
|
||||
if (!keyUsageExtension.Support(KeyUsages.cRLSign))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
x509Extension = x509.Extensions["2.5.29.19"];
|
||||
if (x509Extension != null)
|
||||
{
|
||||
BasicConstraintsExtension basicConstraintsExtension = new BasicConstraintsExtension(x509Extension);
|
||||
if (!basicConstraintsExtension.CertificateAuthority)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.issuer != x509.SubjectName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text = this.signatureOID;
|
||||
if (text != null)
|
||||
{
|
||||
if (X509Crl.<>f__switch$map11 == null)
|
||||
{
|
||||
X509Crl.<>f__switch$map11 = new Dictionary<string, int>(1) { { "1.2.840.10040.4.3", 0 } };
|
||||
}
|
||||
int num;
|
||||
if (X509Crl.<>f__switch$map11.TryGetValue(text, out num))
|
||||
{
|
||||
if (num == 0)
|
||||
{
|
||||
return this.VerifySignature(x509.DSA);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.VerifySignature(x509.RSA);
|
||||
}
|
||||
|
||||
// Token: 0x06000A1E RID: 2590 RVA: 0x0002D0F4 File Offset: 0x0002B2F4
|
||||
private string GetHashName()
|
||||
{
|
||||
string text = this.signatureOID;
|
||||
switch (text)
|
||||
{
|
||||
case "1.2.840.113549.1.1.2":
|
||||
return "MD2";
|
||||
case "1.2.840.113549.1.1.4":
|
||||
return "MD5";
|
||||
case "1.2.840.10040.4.3":
|
||||
case "1.2.840.113549.1.1.5":
|
||||
return "SHA1";
|
||||
}
|
||||
throw new CryptographicException("Unsupported hash algorithm: " + this.signatureOID);
|
||||
}
|
||||
|
||||
// Token: 0x06000A1F RID: 2591 RVA: 0x0002D1A8 File Offset: 0x0002B3A8
|
||||
internal bool VerifySignature(DSA dsa)
|
||||
{
|
||||
if (this.signatureOID != "1.2.840.10040.4.3")
|
||||
{
|
||||
throw new CryptographicException("Unsupported hash algorithm: " + this.signatureOID);
|
||||
}
|
||||
DSASignatureDeformatter dsasignatureDeformatter = new DSASignatureDeformatter(dsa);
|
||||
dsasignatureDeformatter.SetHashAlgorithm("SHA1");
|
||||
ASN1 asn = new ASN1(this.signature);
|
||||
if (asn == null || asn.Count != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
byte[] value = asn[0].Value;
|
||||
byte[] value2 = asn[1].Value;
|
||||
byte[] array = new byte[40];
|
||||
int num = Math.Max(0, value.Length - 20);
|
||||
int num2 = Math.Max(0, 20 - value.Length);
|
||||
Buffer.BlockCopy(value, num, array, num2, value.Length - num);
|
||||
int num3 = Math.Max(0, value2.Length - 20);
|
||||
int num4 = Math.Max(20, 40 - value2.Length);
|
||||
Buffer.BlockCopy(value2, num3, array, num4, value2.Length - num3);
|
||||
return dsasignatureDeformatter.VerifySignature(this.Hash, array);
|
||||
}
|
||||
|
||||
// Token: 0x06000A20 RID: 2592 RVA: 0x0002D2A0 File Offset: 0x0002B4A0
|
||||
internal bool VerifySignature(RSA rsa)
|
||||
{
|
||||
RSAPKCS1SignatureDeformatter rsapkcs1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
|
||||
rsapkcs1SignatureDeformatter.SetHashAlgorithm(this.GetHashName());
|
||||
return rsapkcs1SignatureDeformatter.VerifySignature(this.Hash, this.signature);
|
||||
}
|
||||
|
||||
// Token: 0x06000A21 RID: 2593 RVA: 0x0002D2D4 File Offset: 0x0002B4D4
|
||||
public bool VerifySignature(AsymmetricAlgorithm aa)
|
||||
{
|
||||
if (aa == null)
|
||||
{
|
||||
throw new ArgumentNullException("aa");
|
||||
}
|
||||
if (aa is RSA)
|
||||
{
|
||||
return this.VerifySignature(aa as RSA);
|
||||
}
|
||||
if (aa is DSA)
|
||||
{
|
||||
return this.VerifySignature(aa as DSA);
|
||||
}
|
||||
throw new NotSupportedException("Unknown Asymmetric Algorithm " + aa.ToString());
|
||||
}
|
||||
|
||||
// Token: 0x06000A22 RID: 2594 RVA: 0x0002D338 File Offset: 0x0002B538
|
||||
public static X509Crl CreateFromFile(string 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 X509Crl(array);
|
||||
}
|
||||
|
||||
// Token: 0x04000283 RID: 643
|
||||
private string issuer;
|
||||
|
||||
// Token: 0x04000284 RID: 644
|
||||
private byte version;
|
||||
|
||||
// Token: 0x04000285 RID: 645
|
||||
private DateTime thisUpdate;
|
||||
|
||||
// Token: 0x04000286 RID: 646
|
||||
private DateTime nextUpdate;
|
||||
|
||||
// Token: 0x04000287 RID: 647
|
||||
private ArrayList entries;
|
||||
|
||||
// Token: 0x04000288 RID: 648
|
||||
private string signatureOID;
|
||||
|
||||
// Token: 0x04000289 RID: 649
|
||||
private byte[] signature;
|
||||
|
||||
// Token: 0x0400028A RID: 650
|
||||
private X509ExtensionCollection extensions;
|
||||
|
||||
// Token: 0x0400028B RID: 651
|
||||
private byte[] encoded;
|
||||
|
||||
// Token: 0x0400028C RID: 652
|
||||
private byte[] hash_value;
|
||||
|
||||
// Token: 0x020000BB RID: 187
|
||||
public class X509CrlEntry
|
||||
{
|
||||
// Token: 0x06000A23 RID: 2595 RVA: 0x0002D3A4 File Offset: 0x0002B5A4
|
||||
internal X509CrlEntry(byte[] serialNumber, DateTime revocationDate, X509ExtensionCollection extensions)
|
||||
{
|
||||
this.sn = serialNumber;
|
||||
this.revocationDate = revocationDate;
|
||||
if (extensions == null)
|
||||
{
|
||||
this.extensions = new X509ExtensionCollection();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extensions = extensions;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A24 RID: 2596 RVA: 0x0002D3D8 File Offset: 0x0002B5D8
|
||||
internal X509CrlEntry(ASN1 entry)
|
||||
{
|
||||
this.sn = entry[0].Value;
|
||||
Array.Reverse(this.sn);
|
||||
this.revocationDate = ASN1Convert.ToDateTime(entry[1]);
|
||||
this.extensions = new X509ExtensionCollection(entry[2]);
|
||||
}
|
||||
|
||||
// Token: 0x17000137 RID: 311
|
||||
// (get) Token: 0x06000A25 RID: 2597 RVA: 0x0002D42C File Offset: 0x0002B62C
|
||||
public byte[] SerialNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte[])this.sn.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000138 RID: 312
|
||||
// (get) Token: 0x06000A26 RID: 2598 RVA: 0x0002D440 File Offset: 0x0002B640
|
||||
public DateTime RevocationDate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.revocationDate;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000139 RID: 313
|
||||
// (get) Token: 0x06000A27 RID: 2599 RVA: 0x0002D448 File Offset: 0x0002B648
|
||||
public X509ExtensionCollection Extensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.extensions;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A28 RID: 2600 RVA: 0x0002D450 File Offset: 0x0002B650
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(new ASN1(2, this.sn));
|
||||
asn.Add(ASN1Convert.FromDateTime(this.revocationDate));
|
||||
if (this.extensions.Count > 0)
|
||||
{
|
||||
asn.Add(new ASN1(this.extensions.GetBytes()));
|
||||
}
|
||||
return asn.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x0400028F RID: 655
|
||||
private byte[] sn;
|
||||
|
||||
// Token: 0x04000290 RID: 656
|
||||
private DateTime revocationDate;
|
||||
|
||||
// Token: 0x04000291 RID: 657
|
||||
private X509ExtensionCollection extensions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C1 RID: 193
|
||||
internal class X509Extension
|
||||
{
|
||||
// Token: 0x06000A79 RID: 2681 RVA: 0x0002E9A0 File Offset: 0x0002CBA0
|
||||
protected X509Extension()
|
||||
{
|
||||
this.extnCritical = false;
|
||||
}
|
||||
|
||||
// Token: 0x06000A7A RID: 2682 RVA: 0x0002E9B0 File Offset: 0x0002CBB0
|
||||
public X509Extension(ASN1 asn1)
|
||||
{
|
||||
if (asn1.Tag != 48 || asn1.Count < 2)
|
||||
{
|
||||
throw new ArgumentException(Locale.GetText("Invalid X.509 extension."));
|
||||
}
|
||||
if (asn1[0].Tag != 6)
|
||||
{
|
||||
throw new ArgumentException(Locale.GetText("Invalid X.509 extension."));
|
||||
}
|
||||
this.extnOid = ASN1Convert.ToOid(asn1[0]);
|
||||
this.extnCritical = asn1[1].Tag == 1 && asn1[1].Value[0] == byte.MaxValue;
|
||||
this.extnValue = asn1[asn1.Count - 1];
|
||||
if (this.extnValue.Tag == 4 && this.extnValue.Length > 0 && this.extnValue.Count == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
ASN1 asn2 = new ASN1(this.extnValue.Value);
|
||||
this.extnValue.Value = null;
|
||||
this.extnValue.Add(asn2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
this.Decode();
|
||||
}
|
||||
|
||||
// Token: 0x06000A7B RID: 2683 RVA: 0x0002EAF0 File Offset: 0x0002CCF0
|
||||
public X509Extension(X509Extension extension)
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
throw new ArgumentNullException("extension");
|
||||
}
|
||||
if (extension.Value == null || extension.Value.Tag != 4 || extension.Value.Count != 1)
|
||||
{
|
||||
throw new ArgumentException(Locale.GetText("Invalid X.509 extension."));
|
||||
}
|
||||
this.extnOid = extension.Oid;
|
||||
this.extnCritical = extension.Critical;
|
||||
this.extnValue = extension.Value;
|
||||
this.Decode();
|
||||
}
|
||||
|
||||
// Token: 0x06000A7C RID: 2684 RVA: 0x0002EB7C File Offset: 0x0002CD7C
|
||||
protected virtual void Decode()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000A7D RID: 2685 RVA: 0x0002EB80 File Offset: 0x0002CD80
|
||||
protected virtual void Encode()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x17000156 RID: 342
|
||||
// (get) Token: 0x06000A7E RID: 2686 RVA: 0x0002EB84 File Offset: 0x0002CD84
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid(this.extnOid));
|
||||
if (this.extnCritical)
|
||||
{
|
||||
asn.Add(new ASN1(1, new byte[] { byte.MaxValue }));
|
||||
}
|
||||
this.Encode();
|
||||
asn.Add(this.extnValue);
|
||||
return asn;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000157 RID: 343
|
||||
// (get) Token: 0x06000A7F RID: 2687 RVA: 0x0002EBE8 File Offset: 0x0002CDE8
|
||||
public string Oid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.extnOid;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000158 RID: 344
|
||||
// (get) Token: 0x06000A80 RID: 2688 RVA: 0x0002EBF0 File Offset: 0x0002CDF0
|
||||
// (set) Token: 0x06000A81 RID: 2689 RVA: 0x0002EBF8 File Offset: 0x0002CDF8
|
||||
public bool Critical
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.extnCritical;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.extnCritical = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000159 RID: 345
|
||||
// (get) Token: 0x06000A82 RID: 2690 RVA: 0x0002EC04 File Offset: 0x0002CE04
|
||||
public virtual string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.extnOid;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700015A RID: 346
|
||||
// (get) Token: 0x06000A83 RID: 2691 RVA: 0x0002EC0C File Offset: 0x0002CE0C
|
||||
public ASN1 Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.extnValue == null)
|
||||
{
|
||||
this.Encode();
|
||||
}
|
||||
return this.extnValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A84 RID: 2692 RVA: 0x0002EC28 File Offset: 0x0002CE28
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
X509Extension x509Extension = obj as X509Extension;
|
||||
if (x509Extension == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.extnCritical != x509Extension.extnCritical)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.extnOid != x509Extension.extnOid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.extnValue.Length != x509Extension.extnValue.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.extnValue.Length; i++)
|
||||
{
|
||||
if (this.extnValue[i] != x509Extension.extnValue[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000A85 RID: 2693 RVA: 0x0002ECD0 File Offset: 0x0002CED0
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.ASN1.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x06000A86 RID: 2694 RVA: 0x0002ECE0 File Offset: 0x0002CEE0
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.extnOid.GetHashCode();
|
||||
}
|
||||
|
||||
// Token: 0x06000A87 RID: 2695 RVA: 0x0002ECF0 File Offset: 0x0002CEF0
|
||||
private void WriteLine(StringBuilder sb, int n, int pos)
|
||||
{
|
||||
byte[] value = this.extnValue.Value;
|
||||
int num = pos;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (i < n)
|
||||
{
|
||||
sb.Append(value[num++].ToString("X2", CultureInfo.InvariantCulture));
|
||||
sb.Append(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(" ");
|
||||
}
|
||||
}
|
||||
sb.Append(" ");
|
||||
num = pos;
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
byte b = value[num++];
|
||||
if (b < 32)
|
||||
{
|
||||
sb.Append(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(Convert.ToChar(b));
|
||||
}
|
||||
}
|
||||
sb.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
// Token: 0x06000A88 RID: 2696 RVA: 0x0002EDC0 File Offset: 0x0002CFC0
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int num = this.extnValue.Length >> 3;
|
||||
int num2 = this.extnValue.Length - (num << 3);
|
||||
int num3 = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
this.WriteLine(stringBuilder, 8, num3);
|
||||
num3 += 8;
|
||||
}
|
||||
this.WriteLine(stringBuilder, num2, num3);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x040002BA RID: 698
|
||||
protected string extnOid;
|
||||
|
||||
// Token: 0x040002BB RID: 699
|
||||
protected bool extnCritical;
|
||||
|
||||
// Token: 0x040002BC RID: 700
|
||||
protected ASN1 extnValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C2 RID: 194
|
||||
internal sealed class X509ExtensionCollection : CollectionBase, IEnumerable
|
||||
{
|
||||
// Token: 0x06000A89 RID: 2697 RVA: 0x0002EE28 File Offset: 0x0002D028
|
||||
public X509ExtensionCollection()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000A8A RID: 2698 RVA: 0x0002EE30 File Offset: 0x0002D030
|
||||
public X509ExtensionCollection(ASN1 asn1)
|
||||
: this()
|
||||
{
|
||||
this.readOnly = true;
|
||||
if (asn1 == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (asn1.Tag != 48)
|
||||
{
|
||||
throw new Exception("Invalid extensions format");
|
||||
}
|
||||
for (int i = 0; i < asn1.Count; i++)
|
||||
{
|
||||
X509Extension x509Extension = new X509Extension(asn1[i]);
|
||||
base.InnerList.Add(x509Extension);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A8B RID: 2699 RVA: 0x0002EE9C File Offset: 0x0002D09C
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return base.InnerList.GetEnumerator();
|
||||
}
|
||||
|
||||
// Token: 0x06000A8C RID: 2700 RVA: 0x0002EEAC File Offset: 0x0002D0AC
|
||||
public int Add(X509Extension extension)
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
throw new ArgumentNullException("extension");
|
||||
}
|
||||
if (this.readOnly)
|
||||
{
|
||||
throw new NotSupportedException("Extensions are read only");
|
||||
}
|
||||
return base.InnerList.Add(extension);
|
||||
}
|
||||
|
||||
// Token: 0x06000A8D RID: 2701 RVA: 0x0002EEE4 File Offset: 0x0002D0E4
|
||||
public void AddRange(X509Extension[] extension)
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
throw new ArgumentNullException("extension");
|
||||
}
|
||||
if (this.readOnly)
|
||||
{
|
||||
throw new NotSupportedException("Extensions are read only");
|
||||
}
|
||||
for (int i = 0; i < extension.Length; i++)
|
||||
{
|
||||
base.InnerList.Add(extension[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A8E RID: 2702 RVA: 0x0002EF3C File Offset: 0x0002D13C
|
||||
public void AddRange(X509ExtensionCollection collection)
|
||||
{
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException("collection");
|
||||
}
|
||||
if (this.readOnly)
|
||||
{
|
||||
throw new NotSupportedException("Extensions are read only");
|
||||
}
|
||||
for (int i = 0; i < collection.InnerList.Count; i++)
|
||||
{
|
||||
base.InnerList.Add(collection[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A8F RID: 2703 RVA: 0x0002EFA0 File Offset: 0x0002D1A0
|
||||
public bool Contains(X509Extension extension)
|
||||
{
|
||||
return this.IndexOf(extension) != -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000A90 RID: 2704 RVA: 0x0002EFB0 File Offset: 0x0002D1B0
|
||||
public bool Contains(string oid)
|
||||
{
|
||||
return this.IndexOf(oid) != -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000A91 RID: 2705 RVA: 0x0002EFC0 File Offset: 0x0002D1C0
|
||||
public void CopyTo(X509Extension[] extensions, int index)
|
||||
{
|
||||
if (extensions == null)
|
||||
{
|
||||
throw new ArgumentNullException("extensions");
|
||||
}
|
||||
base.InnerList.CopyTo(extensions, index);
|
||||
}
|
||||
|
||||
// Token: 0x06000A92 RID: 2706 RVA: 0x0002EFE0 File Offset: 0x0002D1E0
|
||||
public int IndexOf(X509Extension extension)
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
throw new ArgumentNullException("extension");
|
||||
}
|
||||
for (int i = 0; i < base.InnerList.Count; i++)
|
||||
{
|
||||
X509Extension x509Extension = (X509Extension)base.InnerList[i];
|
||||
if (x509Extension.Equals(extension))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000A93 RID: 2707 RVA: 0x0002F03C File Offset: 0x0002D23C
|
||||
public int IndexOf(string oid)
|
||||
{
|
||||
if (oid == null)
|
||||
{
|
||||
throw new ArgumentNullException("oid");
|
||||
}
|
||||
for (int i = 0; i < base.InnerList.Count; i++)
|
||||
{
|
||||
X509Extension x509Extension = (X509Extension)base.InnerList[i];
|
||||
if (x509Extension.Oid == oid)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Token: 0x06000A94 RID: 2708 RVA: 0x0002F09C File Offset: 0x0002D29C
|
||||
public void Insert(int index, X509Extension extension)
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
throw new ArgumentNullException("extension");
|
||||
}
|
||||
base.InnerList.Insert(index, extension);
|
||||
}
|
||||
|
||||
// Token: 0x06000A95 RID: 2709 RVA: 0x0002F0BC File Offset: 0x0002D2BC
|
||||
public void Remove(X509Extension extension)
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
throw new ArgumentNullException("extension");
|
||||
}
|
||||
base.InnerList.Remove(extension);
|
||||
}
|
||||
|
||||
// Token: 0x06000A96 RID: 2710 RVA: 0x0002F0DC File Offset: 0x0002D2DC
|
||||
public void Remove(string oid)
|
||||
{
|
||||
if (oid == null)
|
||||
{
|
||||
throw new ArgumentNullException("oid");
|
||||
}
|
||||
int num = this.IndexOf(oid);
|
||||
if (num != -1)
|
||||
{
|
||||
base.InnerList.RemoveAt(num);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700015B RID: 347
|
||||
public X509Extension this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (X509Extension)base.InnerList[index];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700015C RID: 348
|
||||
public X509Extension this[string oid]
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = this.IndexOf(oid);
|
||||
if (num == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (X509Extension)base.InnerList[num];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A99 RID: 2713 RVA: 0x0002F15C File Offset: 0x0002D35C
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
if (base.InnerList.Count < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ASN1 asn = new ASN1(48);
|
||||
for (int i = 0; i < base.InnerList.Count; i++)
|
||||
{
|
||||
X509Extension x509Extension = (X509Extension)base.InnerList[i];
|
||||
asn.Add(x509Extension.ASN1);
|
||||
}
|
||||
return asn.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x040002BD RID: 701
|
||||
private bool readOnly;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Mono.Security.X509.Extensions;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C3 RID: 195
|
||||
internal class X509Store
|
||||
{
|
||||
// Token: 0x06000A9A RID: 2714 RVA: 0x0002F1C8 File Offset: 0x0002D3C8
|
||||
internal X509Store(string path, bool crl)
|
||||
{
|
||||
this._storePath = path;
|
||||
this._crl = crl;
|
||||
}
|
||||
|
||||
// Token: 0x1700015D RID: 349
|
||||
// (get) Token: 0x06000A9B RID: 2715 RVA: 0x0002F1E0 File Offset: 0x0002D3E0
|
||||
public X509CertificateCollection Certificates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._certificates == null)
|
||||
{
|
||||
this._certificates = this.BuildCertificatesCollection(this._storePath);
|
||||
}
|
||||
return this._certificates;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700015E RID: 350
|
||||
// (get) Token: 0x06000A9C RID: 2716 RVA: 0x0002F208 File Offset: 0x0002D408
|
||||
public ArrayList Crls
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!this._crl)
|
||||
{
|
||||
this._crls = new ArrayList();
|
||||
}
|
||||
if (this._crls == null)
|
||||
{
|
||||
this._crls = this.BuildCrlsCollection(this._storePath);
|
||||
}
|
||||
return this._crls;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700015F RID: 351
|
||||
// (get) Token: 0x06000A9D RID: 2717 RVA: 0x0002F244 File Offset: 0x0002D444
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._name == null)
|
||||
{
|
||||
int num = this._storePath.LastIndexOf(Path.DirectorySeparatorChar);
|
||||
this._name = this._storePath.Substring(num + 1);
|
||||
}
|
||||
return this._name;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000A9E RID: 2718 RVA: 0x0002F288 File Offset: 0x0002D488
|
||||
public void Clear()
|
||||
{
|
||||
if (this._certificates != null)
|
||||
{
|
||||
this._certificates.Clear();
|
||||
}
|
||||
this._certificates = null;
|
||||
if (this._crls != null)
|
||||
{
|
||||
this._crls.Clear();
|
||||
}
|
||||
this._crls = null;
|
||||
}
|
||||
|
||||
// Token: 0x06000A9F RID: 2719 RVA: 0x0002F2D0 File Offset: 0x0002D4D0
|
||||
public void Import(X509Certificate certificate)
|
||||
{
|
||||
this.CheckStore(this._storePath, true);
|
||||
string text = Path.Combine(this._storePath, this.GetUniqueName(certificate));
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
using (FileStream fileStream = File.Create(text))
|
||||
{
|
||||
byte[] rawData = certificate.RawData;
|
||||
fileStream.Write(rawData, 0, rawData.Length);
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000AA0 RID: 2720 RVA: 0x0002F358 File Offset: 0x0002D558
|
||||
public void Import(X509Crl crl)
|
||||
{
|
||||
this.CheckStore(this._storePath, true);
|
||||
string text = Path.Combine(this._storePath, this.GetUniqueName(crl));
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
using (FileStream fileStream = File.Create(text))
|
||||
{
|
||||
byte[] rawData = crl.RawData;
|
||||
fileStream.Write(rawData, 0, rawData.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000AA1 RID: 2721 RVA: 0x0002F3D8 File Offset: 0x0002D5D8
|
||||
public void Remove(X509Certificate certificate)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, this.GetUniqueName(certificate));
|
||||
if (File.Exists(text))
|
||||
{
|
||||
File.Delete(text);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000AA2 RID: 2722 RVA: 0x0002F40C File Offset: 0x0002D60C
|
||||
public void Remove(X509Crl crl)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, this.GetUniqueName(crl));
|
||||
if (File.Exists(text))
|
||||
{
|
||||
File.Delete(text);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000AA3 RID: 2723 RVA: 0x0002F440 File Offset: 0x0002D640
|
||||
private string GetUniqueName(X509Certificate certificate)
|
||||
{
|
||||
byte[] array = this.GetUniqueName(certificate.Extensions);
|
||||
string text;
|
||||
if (array == null)
|
||||
{
|
||||
text = "tbp";
|
||||
array = certificate.Hash;
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "ski";
|
||||
}
|
||||
return this.GetUniqueName(text, array, ".cer");
|
||||
}
|
||||
|
||||
// Token: 0x06000AA4 RID: 2724 RVA: 0x0002F488 File Offset: 0x0002D688
|
||||
private string GetUniqueName(X509Crl crl)
|
||||
{
|
||||
byte[] array = this.GetUniqueName(crl.Extensions);
|
||||
string text;
|
||||
if (array == null)
|
||||
{
|
||||
text = "tbp";
|
||||
array = crl.Hash;
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "ski";
|
||||
}
|
||||
return this.GetUniqueName(text, array, ".crl");
|
||||
}
|
||||
|
||||
// Token: 0x06000AA5 RID: 2725 RVA: 0x0002F4D0 File Offset: 0x0002D6D0
|
||||
private byte[] GetUniqueName(X509ExtensionCollection extensions)
|
||||
{
|
||||
X509Extension x509Extension = extensions["2.5.29.14"];
|
||||
if (x509Extension == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SubjectKeyIdentifierExtension subjectKeyIdentifierExtension = new SubjectKeyIdentifierExtension(x509Extension);
|
||||
return subjectKeyIdentifierExtension.Identifier;
|
||||
}
|
||||
|
||||
// Token: 0x06000AA6 RID: 2726 RVA: 0x0002F500 File Offset: 0x0002D700
|
||||
private string GetUniqueName(string method, byte[] name, string fileExtension)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder(method);
|
||||
stringBuilder.Append("-");
|
||||
foreach (byte b in name)
|
||||
{
|
||||
stringBuilder.Append(b.ToString("X2", CultureInfo.InvariantCulture));
|
||||
}
|
||||
stringBuilder.Append(fileExtension);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x06000AA7 RID: 2727 RVA: 0x0002F560 File Offset: 0x0002D760
|
||||
private byte[] Load(string filename)
|
||||
{
|
||||
byte[] array = null;
|
||||
using (FileStream fileStream = File.OpenRead(filename))
|
||||
{
|
||||
array = new byte[fileStream.Length];
|
||||
fileStream.Read(array, 0, array.Length);
|
||||
fileStream.Close();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000AA8 RID: 2728 RVA: 0x0002F5C4 File Offset: 0x0002D7C4
|
||||
private X509Certificate LoadCertificate(string filename)
|
||||
{
|
||||
byte[] array = this.Load(filename);
|
||||
return new X509Certificate(array);
|
||||
}
|
||||
|
||||
// Token: 0x06000AA9 RID: 2729 RVA: 0x0002F5E4 File Offset: 0x0002D7E4
|
||||
private X509Crl LoadCrl(string filename)
|
||||
{
|
||||
byte[] array = this.Load(filename);
|
||||
return new X509Crl(array);
|
||||
}
|
||||
|
||||
// Token: 0x06000AAA RID: 2730 RVA: 0x0002F604 File Offset: 0x0002D804
|
||||
private bool CheckStore(string path, bool throwException)
|
||||
{
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
flag = Directory.Exists(path);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000AAB RID: 2731 RVA: 0x0002F670 File Offset: 0x0002D870
|
||||
private X509CertificateCollection BuildCertificatesCollection(string storeName)
|
||||
{
|
||||
X509CertificateCollection x509CertificateCollection = new X509CertificateCollection();
|
||||
string text = Path.Combine(this._storePath, storeName);
|
||||
if (!this.CheckStore(text, false))
|
||||
{
|
||||
return x509CertificateCollection;
|
||||
}
|
||||
string[] files = Directory.GetFiles(text, "*.cer");
|
||||
if (files != null && files.Length > 0)
|
||||
{
|
||||
foreach (string text2 in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
X509Certificate x509Certificate = this.LoadCertificate(text2);
|
||||
x509CertificateCollection.Add(x509Certificate);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
return x509CertificateCollection;
|
||||
}
|
||||
|
||||
// Token: 0x06000AAC RID: 2732 RVA: 0x0002F718 File Offset: 0x0002D918
|
||||
private ArrayList BuildCrlsCollection(string storeName)
|
||||
{
|
||||
ArrayList arrayList = new ArrayList();
|
||||
string text = Path.Combine(this._storePath, storeName);
|
||||
if (!this.CheckStore(text, false))
|
||||
{
|
||||
return arrayList;
|
||||
}
|
||||
string[] files = Directory.GetFiles(text, "*.crl");
|
||||
if (files != null && files.Length > 0)
|
||||
{
|
||||
foreach (string text2 in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
X509Crl x509Crl = this.LoadCrl(text2);
|
||||
arrayList.Add(x509Crl);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
// Token: 0x040002BE RID: 702
|
||||
private string _storePath;
|
||||
|
||||
// Token: 0x040002BF RID: 703
|
||||
private X509CertificateCollection _certificates;
|
||||
|
||||
// Token: 0x040002C0 RID: 704
|
||||
private ArrayList _crls;
|
||||
|
||||
// Token: 0x040002C1 RID: 705
|
||||
private bool _crl;
|
||||
|
||||
// Token: 0x040002C2 RID: 706
|
||||
private string _name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C4 RID: 196
|
||||
internal sealed class X509StoreManager
|
||||
{
|
||||
// Token: 0x06000AAD RID: 2733 RVA: 0x0002F7C0 File Offset: 0x0002D9C0
|
||||
private X509StoreManager()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x17000160 RID: 352
|
||||
// (get) Token: 0x06000AAE RID: 2734 RVA: 0x0002F7C8 File Offset: 0x0002D9C8
|
||||
public static X509Stores CurrentUser
|
||||
{
|
||||
get
|
||||
{
|
||||
if (X509StoreManager._userStore == null)
|
||||
{
|
||||
string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".mono");
|
||||
text = Path.Combine(text, "certs");
|
||||
X509StoreManager._userStore = new X509Stores(text);
|
||||
}
|
||||
return X509StoreManager._userStore;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000161 RID: 353
|
||||
// (get) Token: 0x06000AAF RID: 2735 RVA: 0x0002F810 File Offset: 0x0002DA10
|
||||
public static X509Stores LocalMachine
|
||||
{
|
||||
get
|
||||
{
|
||||
if (X509StoreManager._machineStore == null)
|
||||
{
|
||||
string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), ".mono");
|
||||
text = Path.Combine(text, "certs");
|
||||
X509StoreManager._machineStore = new X509Stores(text);
|
||||
}
|
||||
return X509StoreManager._machineStore;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000162 RID: 354
|
||||
// (get) Token: 0x06000AB0 RID: 2736 RVA: 0x0002F858 File Offset: 0x0002DA58
|
||||
public static X509CertificateCollection IntermediateCACertificates
|
||||
{
|
||||
get
|
||||
{
|
||||
X509CertificateCollection x509CertificateCollection = new X509CertificateCollection();
|
||||
x509CertificateCollection.AddRange(X509StoreManager.CurrentUser.IntermediateCA.Certificates);
|
||||
x509CertificateCollection.AddRange(X509StoreManager.LocalMachine.IntermediateCA.Certificates);
|
||||
return x509CertificateCollection;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000163 RID: 355
|
||||
// (get) Token: 0x06000AB1 RID: 2737 RVA: 0x0002F898 File Offset: 0x0002DA98
|
||||
public static ArrayList IntermediateCACrls
|
||||
{
|
||||
get
|
||||
{
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.AddRange(X509StoreManager.CurrentUser.IntermediateCA.Crls);
|
||||
arrayList.AddRange(X509StoreManager.LocalMachine.IntermediateCA.Crls);
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000164 RID: 356
|
||||
// (get) Token: 0x06000AB2 RID: 2738 RVA: 0x0002F8D8 File Offset: 0x0002DAD8
|
||||
public static X509CertificateCollection TrustedRootCertificates
|
||||
{
|
||||
get
|
||||
{
|
||||
X509CertificateCollection x509CertificateCollection = new X509CertificateCollection();
|
||||
x509CertificateCollection.AddRange(X509StoreManager.CurrentUser.TrustedRoot.Certificates);
|
||||
x509CertificateCollection.AddRange(X509StoreManager.LocalMachine.TrustedRoot.Certificates);
|
||||
return x509CertificateCollection;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000165 RID: 357
|
||||
// (get) Token: 0x06000AB3 RID: 2739 RVA: 0x0002F918 File Offset: 0x0002DB18
|
||||
public static ArrayList TrustedRootCACrls
|
||||
{
|
||||
get
|
||||
{
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.AddRange(X509StoreManager.CurrentUser.TrustedRoot.Crls);
|
||||
arrayList.AddRange(X509StoreManager.LocalMachine.TrustedRoot.Crls);
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000166 RID: 358
|
||||
// (get) Token: 0x06000AB4 RID: 2740 RVA: 0x0002F958 File Offset: 0x0002DB58
|
||||
public static X509CertificateCollection UntrustedCertificates
|
||||
{
|
||||
get
|
||||
{
|
||||
X509CertificateCollection x509CertificateCollection = new X509CertificateCollection();
|
||||
x509CertificateCollection.AddRange(X509StoreManager.CurrentUser.Untrusted.Certificates);
|
||||
x509CertificateCollection.AddRange(X509StoreManager.LocalMachine.Untrusted.Certificates);
|
||||
return x509CertificateCollection;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040002C3 RID: 707
|
||||
private static X509Stores _userStore;
|
||||
|
||||
// Token: 0x040002C4 RID: 708
|
||||
private static X509Stores _machineStore;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C5 RID: 197
|
||||
internal class X509Stores
|
||||
{
|
||||
// Token: 0x06000AB5 RID: 2741 RVA: 0x0002F998 File Offset: 0x0002DB98
|
||||
internal X509Stores(string path)
|
||||
{
|
||||
this._storePath = path;
|
||||
}
|
||||
|
||||
// Token: 0x17000167 RID: 359
|
||||
// (get) Token: 0x06000AB6 RID: 2742 RVA: 0x0002F9A8 File Offset: 0x0002DBA8
|
||||
public X509Store Personal
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._personal == null)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, "My");
|
||||
this._personal = new X509Store(text, false);
|
||||
}
|
||||
return this._personal;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000168 RID: 360
|
||||
// (get) Token: 0x06000AB7 RID: 2743 RVA: 0x0002F9E4 File Offset: 0x0002DBE4
|
||||
public X509Store OtherPeople
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._other == null)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, "AddressBook");
|
||||
this._other = new X509Store(text, false);
|
||||
}
|
||||
return this._other;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000169 RID: 361
|
||||
// (get) Token: 0x06000AB8 RID: 2744 RVA: 0x0002FA20 File Offset: 0x0002DC20
|
||||
public X509Store IntermediateCA
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._intermediate == null)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, "CA");
|
||||
this._intermediate = new X509Store(text, true);
|
||||
}
|
||||
return this._intermediate;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700016A RID: 362
|
||||
// (get) Token: 0x06000AB9 RID: 2745 RVA: 0x0002FA5C File Offset: 0x0002DC5C
|
||||
public X509Store TrustedRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._trusted == null)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, "Trust");
|
||||
this._trusted = new X509Store(text, true);
|
||||
}
|
||||
return this._trusted;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700016B RID: 363
|
||||
// (get) Token: 0x06000ABA RID: 2746 RVA: 0x0002FA98 File Offset: 0x0002DC98
|
||||
public X509Store Untrusted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._untrusted == null)
|
||||
{
|
||||
string text = Path.Combine(this._storePath, "Disallowed");
|
||||
this._untrusted = new X509Store(text, false);
|
||||
}
|
||||
return this._untrusted;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000ABB RID: 2747 RVA: 0x0002FAD4 File Offset: 0x0002DCD4
|
||||
public void Clear()
|
||||
{
|
||||
if (this._personal != null)
|
||||
{
|
||||
this._personal.Clear();
|
||||
}
|
||||
this._personal = null;
|
||||
if (this._other != null)
|
||||
{
|
||||
this._other.Clear();
|
||||
}
|
||||
this._other = null;
|
||||
if (this._intermediate != null)
|
||||
{
|
||||
this._intermediate.Clear();
|
||||
}
|
||||
this._intermediate = null;
|
||||
if (this._trusted != null)
|
||||
{
|
||||
this._trusted.Clear();
|
||||
}
|
||||
this._trusted = null;
|
||||
if (this._untrusted != null)
|
||||
{
|
||||
this._untrusted.Clear();
|
||||
}
|
||||
this._untrusted = null;
|
||||
}
|
||||
|
||||
// Token: 0x06000ABC RID: 2748 RVA: 0x0002FB74 File Offset: 0x0002DD74
|
||||
public X509Store Open(string storeName, bool create)
|
||||
{
|
||||
if (storeName == null)
|
||||
{
|
||||
throw new ArgumentNullException("storeName");
|
||||
}
|
||||
string text = Path.Combine(this._storePath, storeName);
|
||||
if (!create && !Directory.Exists(text))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new X509Store(text, true);
|
||||
}
|
||||
|
||||
// Token: 0x040002C5 RID: 709
|
||||
private string _storePath;
|
||||
|
||||
// Token: 0x040002C6 RID: 710
|
||||
private X509Store _personal;
|
||||
|
||||
// Token: 0x040002C7 RID: 711
|
||||
private X509Store _other;
|
||||
|
||||
// Token: 0x040002C8 RID: 712
|
||||
private X509Store _intermediate;
|
||||
|
||||
// Token: 0x040002C9 RID: 713
|
||||
private X509Store _trusted;
|
||||
|
||||
// Token: 0x040002CA RID: 714
|
||||
private X509Store _untrusted;
|
||||
|
||||
// Token: 0x020000C6 RID: 198
|
||||
public class Names
|
||||
{
|
||||
// Token: 0x040002CB RID: 715
|
||||
public const string Personal = "My";
|
||||
|
||||
// Token: 0x040002CC RID: 716
|
||||
public const string OtherPeople = "AddressBook";
|
||||
|
||||
// Token: 0x040002CD RID: 717
|
||||
public const string IntermediateCA = "CA";
|
||||
|
||||
// Token: 0x040002CE RID: 718
|
||||
public const string TrustedRoot = "Trust";
|
||||
|
||||
// Token: 0x040002CF RID: 719
|
||||
public const string Untrusted = "Disallowed";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.X509
|
||||
{
|
||||
// Token: 0x020000C7 RID: 199
|
||||
internal class X520
|
||||
{
|
||||
// Token: 0x020000C8 RID: 200
|
||||
public abstract class AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ABF RID: 2751 RVA: 0x0002FBCC File Offset: 0x0002DDCC
|
||||
protected AttributeTypeAndValue(string oid, int upperBound)
|
||||
{
|
||||
this.oid = oid;
|
||||
this.upperBound = upperBound;
|
||||
this.encoding = byte.MaxValue;
|
||||
}
|
||||
|
||||
// Token: 0x06000AC0 RID: 2752 RVA: 0x0002FBF0 File Offset: 0x0002DDF0
|
||||
protected AttributeTypeAndValue(string oid, int upperBound, byte encoding)
|
||||
{
|
||||
this.oid = oid;
|
||||
this.upperBound = upperBound;
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
// Token: 0x1700016C RID: 364
|
||||
// (get) Token: 0x06000AC1 RID: 2753 RVA: 0x0002FC10 File Offset: 0x0002DE10
|
||||
// (set) Token: 0x06000AC2 RID: 2754 RVA: 0x0002FC18 File Offset: 0x0002DE18
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.attrValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.attrValue != null && this.attrValue.Length > this.upperBound)
|
||||
{
|
||||
string text = Locale.GetText("Value length bigger than upperbound ({0}).");
|
||||
throw new FormatException(string.Format(text, this.upperBound));
|
||||
}
|
||||
this.attrValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700016D RID: 365
|
||||
// (get) Token: 0x06000AC3 RID: 2755 RVA: 0x0002FC70 File Offset: 0x0002DE70
|
||||
public ASN1 ASN1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetASN1();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000AC4 RID: 2756 RVA: 0x0002FC78 File Offset: 0x0002DE78
|
||||
internal ASN1 GetASN1(byte encoding)
|
||||
{
|
||||
byte b = encoding;
|
||||
if (b == 255)
|
||||
{
|
||||
b = this.SelectBestEncoding();
|
||||
}
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid(this.oid));
|
||||
byte b2 = b;
|
||||
switch (b2)
|
||||
{
|
||||
case 19:
|
||||
asn.Add(new ASN1(19, Encoding.ASCII.GetBytes(this.attrValue)));
|
||||
break;
|
||||
default:
|
||||
if (b2 == 30)
|
||||
{
|
||||
asn.Add(new ASN1(30, Encoding.BigEndianUnicode.GetBytes(this.attrValue)));
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
asn.Add(new ASN1(22, Encoding.ASCII.GetBytes(this.attrValue)));
|
||||
break;
|
||||
}
|
||||
return asn;
|
||||
}
|
||||
|
||||
// Token: 0x06000AC5 RID: 2757 RVA: 0x0002FD48 File Offset: 0x0002DF48
|
||||
internal ASN1 GetASN1()
|
||||
{
|
||||
return this.GetASN1(this.encoding);
|
||||
}
|
||||
|
||||
// Token: 0x06000AC6 RID: 2758 RVA: 0x0002FD58 File Offset: 0x0002DF58
|
||||
public byte[] GetBytes(byte encoding)
|
||||
{
|
||||
return this.GetASN1(encoding).GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x06000AC7 RID: 2759 RVA: 0x0002FD68 File Offset: 0x0002DF68
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return this.GetASN1().GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x06000AC8 RID: 2760 RVA: 0x0002FD78 File Offset: 0x0002DF78
|
||||
private byte SelectBestEncoding()
|
||||
{
|
||||
foreach (char c in this.attrValue)
|
||||
{
|
||||
char c2 = c;
|
||||
if (c2 == '@' || c2 == '_')
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
if (c > '\u007f')
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
}
|
||||
return 19;
|
||||
}
|
||||
|
||||
// Token: 0x040002D0 RID: 720
|
||||
private string oid;
|
||||
|
||||
// Token: 0x040002D1 RID: 721
|
||||
private string attrValue;
|
||||
|
||||
// Token: 0x040002D2 RID: 722
|
||||
private int upperBound;
|
||||
|
||||
// Token: 0x040002D3 RID: 723
|
||||
private byte encoding;
|
||||
}
|
||||
|
||||
// Token: 0x020000C9 RID: 201
|
||||
public class Name : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AC9 RID: 2761 RVA: 0x0002FDD8 File Offset: 0x0002DFD8
|
||||
public Name()
|
||||
: base("2.5.4.41", 32768)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000CA RID: 202
|
||||
public class CommonName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ACA RID: 2762 RVA: 0x0002FDEC File Offset: 0x0002DFEC
|
||||
public CommonName()
|
||||
: base("2.5.4.3", 64)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000CB RID: 203
|
||||
public class SerialNumber : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ACB RID: 2763 RVA: 0x0002FDFC File Offset: 0x0002DFFC
|
||||
public SerialNumber()
|
||||
: base("2.5.4.5", 64, 19)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000CC RID: 204
|
||||
public class LocalityName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ACC RID: 2764 RVA: 0x0002FE10 File Offset: 0x0002E010
|
||||
public LocalityName()
|
||||
: base("2.5.4.7", 128)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000CD RID: 205
|
||||
public class StateOrProvinceName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ACD RID: 2765 RVA: 0x0002FE24 File Offset: 0x0002E024
|
||||
public StateOrProvinceName()
|
||||
: base("2.5.4.8", 128)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000CE RID: 206
|
||||
public class OrganizationName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ACE RID: 2766 RVA: 0x0002FE38 File Offset: 0x0002E038
|
||||
public OrganizationName()
|
||||
: base("2.5.4.10", 64)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000CF RID: 207
|
||||
public class OrganizationalUnitName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000ACF RID: 2767 RVA: 0x0002FE48 File Offset: 0x0002E048
|
||||
public OrganizationalUnitName()
|
||||
: base("2.5.4.11", 64)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D0 RID: 208
|
||||
public class EmailAddress : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD0 RID: 2768 RVA: 0x0002FE58 File Offset: 0x0002E058
|
||||
public EmailAddress()
|
||||
: base("1.2.840.113549.1.9.1", 128, 22)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D1 RID: 209
|
||||
public class DomainComponent : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD1 RID: 2769 RVA: 0x0002FE6C File Offset: 0x0002E06C
|
||||
public DomainComponent()
|
||||
: base("0.9.2342.19200300.100.1.25", int.MaxValue, 22)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D2 RID: 210
|
||||
public class UserId : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD2 RID: 2770 RVA: 0x0002FE80 File Offset: 0x0002E080
|
||||
public UserId()
|
||||
: base("0.9.2342.19200300.100.1.1", 256)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D3 RID: 211
|
||||
public class Oid : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD3 RID: 2771 RVA: 0x0002FE94 File Offset: 0x0002E094
|
||||
public Oid(string oid)
|
||||
: base(oid, int.MaxValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D4 RID: 212
|
||||
public class Title : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD4 RID: 2772 RVA: 0x0002FEA4 File Offset: 0x0002E0A4
|
||||
public Title()
|
||||
: base("2.5.4.12", 64)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D5 RID: 213
|
||||
public class CountryName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD5 RID: 2773 RVA: 0x0002FEB4 File Offset: 0x0002E0B4
|
||||
public CountryName()
|
||||
: base("2.5.4.6", 2, 19)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D6 RID: 214
|
||||
public class DnQualifier : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD6 RID: 2774 RVA: 0x0002FEC4 File Offset: 0x0002E0C4
|
||||
public DnQualifier()
|
||||
: base("2.5.4.46", 2, 19)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D7 RID: 215
|
||||
public class Surname : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD7 RID: 2775 RVA: 0x0002FED4 File Offset: 0x0002E0D4
|
||||
public Surname()
|
||||
: base("2.5.4.4", 32768)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D8 RID: 216
|
||||
public class GivenName : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD8 RID: 2776 RVA: 0x0002FEE8 File Offset: 0x0002E0E8
|
||||
public GivenName()
|
||||
: base("2.5.4.42", 16)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x020000D9 RID: 217
|
||||
public class Initial : X520.AttributeTypeAndValue
|
||||
{
|
||||
// Token: 0x06000AD9 RID: 2777 RVA: 0x0002FEF8 File Offset: 0x0002E0F8
|
||||
public Initial()
|
||||
: base("2.5.4.43", 5)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user