aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Networking/NativeMethods.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.ServerApplication/Networking/NativeMethods.cs')
-rw-r--r--MediaBrowser.ServerApplication/Networking/NativeMethods.cs156
1 files changed, 155 insertions, 1 deletions
diff --git a/MediaBrowser.ServerApplication/Networking/NativeMethods.cs b/MediaBrowser.ServerApplication/Networking/NativeMethods.cs
index 20f7ac23d..037b1f75b 100644
--- a/MediaBrowser.ServerApplication/Networking/NativeMethods.cs
+++ b/MediaBrowser.ServerApplication/Networking/NativeMethods.cs
@@ -47,9 +47,108 @@ namespace MediaBrowser.ServerApplication.Networking
/// <returns>System.Int32.</returns>
[DllImport("Netapi32", SetLastError = true),
SuppressUnmanagedCodeSecurity]
-
public static extern int NetApiBufferFree(
IntPtr pBuf);
+
+ [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool FileTimeToSystemTime(
+ [In] ref long fileTime,
+ out SystemTime systemTime);
+
+ [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CryptAcquireContextW(
+ out IntPtr providerContext,
+ [MarshalAs(UnmanagedType.LPWStr)] string container,
+ [MarshalAs(UnmanagedType.LPWStr)] string provider,
+ int providerType,
+ int flags);
+
+ [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CryptReleaseContext(
+ IntPtr providerContext,
+ int flags);
+
+ [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CryptGenKey(
+ IntPtr providerContext,
+ int algorithmId,
+ int flags,
+ out IntPtr cryptKeyHandle);
+
+ [DllImport("AdvApi32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CryptDestroyKey(
+ IntPtr cryptKeyHandle);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CertStrToNameW(
+ int certificateEncodingType,
+ IntPtr x500,
+ int strType,
+ IntPtr reserved,
+ [MarshalAs(UnmanagedType.LPArray)] [Out] byte[] encoded,
+ ref int encodedLength,
+ out IntPtr errorString);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ public static extern IntPtr CertCreateSelfSignCertificate(
+ IntPtr providerHandle,
+ [In] ref CryptoApiBlob subjectIssuerBlob,
+ int flags,
+ [In] ref CryptKeyProviderInformation keyProviderInformation,
+ [In] ref CryptAlgorithmIdentifier algorithmIdentifier,
+ [In] ref SystemTime startTime,
+ [In] ref SystemTime endTime,
+ IntPtr extensions);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CertFreeCertificateContext(
+ IntPtr certificateContext);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ public static extern IntPtr CertOpenStore(
+ [MarshalAs(UnmanagedType.LPStr)] string storeProvider,
+ int messageAndCertificateEncodingType,
+ IntPtr cryptProvHandle,
+ int flags,
+ IntPtr parameters);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CertCloseStore(
+ IntPtr certificateStoreHandle,
+ int flags);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CertAddCertificateContextToStore(
+ IntPtr certificateStoreHandle,
+ IntPtr certificateContext,
+ int addDisposition,
+ out IntPtr storeContextPtr);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool CertSetCertificateContextProperty(
+ IntPtr certificateContext,
+ int propertyId,
+ int flags,
+ [In] ref CryptKeyProviderInformation data);
+
+ [DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool PFXExportCertStoreEx(
+ IntPtr certificateStoreHandle,
+ ref CryptoApiBlob pfxBlob,
+ IntPtr password,
+ IntPtr reserved,
+ int flags);
}
//create a _SERVER_INFO_100 STRUCTURE
@@ -69,4 +168,59 @@ namespace MediaBrowser.ServerApplication.Networking
[MarshalAs(UnmanagedType.LPWStr)]
internal string sv100_name;
}
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SystemTime
+ {
+ public short Year;
+ public short Month;
+ public short DayOfWeek;
+ public short Day;
+ public short Hour;
+ public short Minute;
+ public short Second;
+ public short Milliseconds;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct CryptObjIdBlob
+ {
+ public uint cbData;
+ public IntPtr pbData;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct CryptAlgorithmIdentifier
+ {
+ [MarshalAs(UnmanagedType.LPStr)]
+ public String pszObjId;
+ public CryptObjIdBlob Parameters;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct CryptoApiBlob
+ {
+ public int DataLength;
+ public IntPtr Data;
+
+ public CryptoApiBlob(int dataLength, IntPtr data)
+ {
+ this.DataLength = dataLength;
+ this.Data = data;
+ }
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct CryptKeyProviderInformation
+ {
+ [MarshalAs(UnmanagedType.LPWStr)]
+ public string ContainerName;
+ [MarshalAs(UnmanagedType.LPWStr)]
+ public string ProviderName;
+ public int ProviderType;
+ public int Flags;
+ public int ProviderParameterCount;
+ public IntPtr ProviderParameters; // PCRYPT_KEY_PROV_PARAM
+ public int KeySpec;
+ }
}