173 lines
5.4 KiB
C#
173 lines
5.4 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Mono.Security.X509
|
|
{
|
|
// Token: 0x0200027F RID: 639
|
|
internal class OSX509Certificates
|
|
{
|
|
// Token: 0x06001773 RID: 6003
|
|
[DllImport("/System/Library/Frameworks/Security.framework/Security")]
|
|
private static extern IntPtr SecCertificateCreateWithData(IntPtr allocator, IntPtr nsdataRef);
|
|
|
|
// Token: 0x06001774 RID: 6004
|
|
[DllImport("/System/Library/Frameworks/Security.framework/Security")]
|
|
private static extern int SecTrustCreateWithCertificates(IntPtr certOrCertArray, IntPtr policies, out IntPtr sectrustref);
|
|
|
|
// Token: 0x06001775 RID: 6005
|
|
[DllImport("/System/Library/Frameworks/Security.framework/Security")]
|
|
private static extern IntPtr SecPolicyCreateSSL(int server, IntPtr cfStringHostname);
|
|
|
|
// Token: 0x06001776 RID: 6006
|
|
[DllImport("/System/Library/Frameworks/Security.framework/Security")]
|
|
private static extern int SecTrustEvaluate(IntPtr secTrustRef, out OSX509Certificates.SecTrustResult secTrustResultTime);
|
|
|
|
// Token: 0x06001777 RID: 6007
|
|
[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
|
|
private unsafe static extern IntPtr CFDataCreate(IntPtr allocator, byte* bytes, IntPtr length);
|
|
|
|
// Token: 0x06001778 RID: 6008
|
|
[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
|
|
private static extern void CFRelease(IntPtr handle);
|
|
|
|
// Token: 0x06001779 RID: 6009
|
|
[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
|
|
private static extern IntPtr CFArrayCreate(IntPtr allocator, IntPtr values, IntPtr numValues, IntPtr callbacks);
|
|
|
|
// Token: 0x0600177A RID: 6010 RVA: 0x0004E19C File Offset: 0x0004C39C
|
|
private unsafe static IntPtr MakeCFData(byte[] data)
|
|
{
|
|
int num = 0;
|
|
return OSX509Certificates.CFDataCreate(IntPtr.Zero, &data[num], (IntPtr)data.Length);
|
|
}
|
|
|
|
// Token: 0x0600177B RID: 6011 RVA: 0x0004E1C4 File Offset: 0x0004C3C4
|
|
private unsafe static IntPtr FromIntPtrs(IntPtr[] values)
|
|
{
|
|
fixed (IntPtr* ptr = (ref values != null && values.Length != 0 ? ref values[0] : ref *null))
|
|
{
|
|
return OSX509Certificates.CFArrayCreate(IntPtr.Zero, (IntPtr)((void*)ptr), (IntPtr)values.Length, IntPtr.Zero);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600177C RID: 6012 RVA: 0x0004E20C File Offset: 0x0004C40C
|
|
public static OSX509Certificates.SecTrustResult TrustEvaluateSsl(X509CertificateCollection certificates)
|
|
{
|
|
OSX509Certificates.SecTrustResult secTrustResult;
|
|
try
|
|
{
|
|
secTrustResult = OSX509Certificates._TrustEvaluateSsl(certificates);
|
|
}
|
|
catch
|
|
{
|
|
secTrustResult = OSX509Certificates.SecTrustResult.Deny;
|
|
}
|
|
return secTrustResult;
|
|
}
|
|
|
|
// Token: 0x0600177D RID: 6013 RVA: 0x0004E254 File Offset: 0x0004C454
|
|
private static OSX509Certificates.SecTrustResult _TrustEvaluateSsl(X509CertificateCollection certificates)
|
|
{
|
|
if (certificates == null)
|
|
{
|
|
throw new ArgumentNullException("certificates");
|
|
}
|
|
int count = certificates.Count;
|
|
IntPtr[] array = new IntPtr[count];
|
|
IntPtr[] array2 = new IntPtr[count];
|
|
IntPtr intPtr = IntPtr.Zero;
|
|
OSX509Certificates.SecTrustResult secTrustResult2;
|
|
try
|
|
{
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
array[i] = OSX509Certificates.MakeCFData(certificates[i].RawData);
|
|
}
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
array2[j] = OSX509Certificates.SecCertificateCreateWithData(IntPtr.Zero, array[j]);
|
|
if (array2[j] == IntPtr.Zero)
|
|
{
|
|
return OSX509Certificates.SecTrustResult.Deny;
|
|
}
|
|
}
|
|
intPtr = OSX509Certificates.FromIntPtrs(array2);
|
|
IntPtr intPtr2;
|
|
if (OSX509Certificates.SecTrustCreateWithCertificates(intPtr, OSX509Certificates.sslsecpolicy, out intPtr2) == 0)
|
|
{
|
|
OSX509Certificates.SecTrustResult secTrustResult;
|
|
int num = OSX509Certificates.SecTrustEvaluate(intPtr2, out secTrustResult);
|
|
if (num != 0)
|
|
{
|
|
secTrustResult2 = OSX509Certificates.SecTrustResult.Deny;
|
|
}
|
|
else
|
|
{
|
|
OSX509Certificates.CFRelease(intPtr2);
|
|
secTrustResult2 = secTrustResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
secTrustResult2 = OSX509Certificates.SecTrustResult.Deny;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
for (int k = 0; k < count; k++)
|
|
{
|
|
if (array[k] != IntPtr.Zero)
|
|
{
|
|
OSX509Certificates.CFRelease(array[k]);
|
|
}
|
|
}
|
|
if (intPtr != IntPtr.Zero)
|
|
{
|
|
OSX509Certificates.CFRelease(intPtr);
|
|
}
|
|
else
|
|
{
|
|
for (int l = 0; l < count; l++)
|
|
{
|
|
if (array2[l] != IntPtr.Zero)
|
|
{
|
|
OSX509Certificates.CFRelease(array2[l]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return secTrustResult2;
|
|
}
|
|
|
|
// Token: 0x040012C0 RID: 4800
|
|
public const string SecurityLibrary = "/System/Library/Frameworks/Security.framework/Security";
|
|
|
|
// Token: 0x040012C1 RID: 4801
|
|
public const string CoreFoundationLibrary = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
|
|
|
|
// Token: 0x040012C2 RID: 4802
|
|
private static IntPtr sslsecpolicy = OSX509Certificates.SecPolicyCreateSSL(0, IntPtr.Zero);
|
|
|
|
// Token: 0x02000280 RID: 640
|
|
public enum SecTrustResult
|
|
{
|
|
// Token: 0x040012C4 RID: 4804
|
|
Invalid,
|
|
// Token: 0x040012C5 RID: 4805
|
|
Proceed,
|
|
// Token: 0x040012C6 RID: 4806
|
|
Confirm,
|
|
// Token: 0x040012C7 RID: 4807
|
|
Deny,
|
|
// Token: 0x040012C8 RID: 4808
|
|
Unspecified,
|
|
// Token: 0x040012C9 RID: 4809
|
|
RecoverableTrustFailure,
|
|
// Token: 0x040012CA RID: 4810
|
|
FatalTrustFailure,
|
|
// Token: 0x040012CB RID: 4811
|
|
ResultOtherError
|
|
}
|
|
}
|
|
}
|