예제 #1
0
        internal static int DRMCreateLicenseStorageSession(
            SafeRightsManagementEnvironmentHandle hEnv,
            SafeRightsManagementHandle hDefLib,
            SafeRightsManagementSessionHandle hClientSession,
            uint uFlags,
            string IssuanceLicense,
            out SafeRightsManagementSessionHandle phLicenseStorageSession)
        {
            SecurityHelper.DemandRightsManagementPermission();
            int res = UnsafeNativeMethods.DRMCreateLicenseStorageSession(
                hEnv,
                hDefLib,
                hClientSession,
                uFlags,
                IssuanceLicense,
                out phLicenseStorageSession);

            // on some platforms in the failure cases the out parameter is being created with the value 0
            // in order to simplify error handling and Disposing of those handles we will just close them as
            // soon as we detect such case
            if ((phLicenseStorageSession != null) && phLicenseStorageSession.IsInvalid)
            {
                phLicenseStorageSession.Dispose();
                phLicenseStorageSession = null;
            }
            return(res);
        }
예제 #2
0
 internal static extern int DRMCreateLicenseStorageSession(
     [In] SafeRightsManagementEnvironmentHandle envHandle,
     [In] SafeRightsManagementHandle hDefLib,
     [In] SafeRightsManagementSessionHandle hClientSession,
     [In, MarshalAs(UnmanagedType.U4)] uint uFlags,
     [In, MarshalAs(UnmanagedType.LPWStr)] string IssuanceLicense,
     [Out] out SafeRightsManagementSessionHandle phLicenseStorageSession);
예제 #3
0
        internal static int DRMCreateClientSession(
            CallbackDelegate pfnCallback,
            uint uCallbackVersion,
            string GroupIDProviderType,
            string GroupID,
            out SafeRightsManagementSessionHandle phSession)
        {
            SecurityHelper.DemandRightsManagementPermission();
            int res = UnsafeNativeMethods.DRMCreateClientSession(
                pfnCallback,
                uCallbackVersion,
                GroupIDProviderType,
                GroupID,
                out phSession);

            // on some platforms in the failure cases the out parameter is being created with the value 0
            // in order to simplify error handling and Disposing of those handles we will just close them as
            // soon as we detect such case
            if ((phSession != null) && phSession.IsInvalid)
            {
                phSession.Dispose();
                phSession = null;
            }
            return(res);
        }
예제 #4
0
 internal static extern int DRMActivate(
     [In] SafeRightsManagementSessionHandle hSession,
     [In, MarshalAs(UnmanagedType.U4)] uint uFlags,
     [In, MarshalAs(UnmanagedType.U4)] uint uLangID,
     [In, MarshalAs(UnmanagedType.LPStruct)] ActivationServerInfo activationServerInfo,
     IntPtr context,                      // this is a void* in the unmanaged SDK so IntPtr is the right (platform dependent declaration)
     IntPtr parentWindowHandle);          // this a HWND in the unmanaged SDK so IntPtr is the right (platform dependent declaration)
예제 #5
0
 internal static extern int DRMEnumerateLicense(
     [In] SafeRightsManagementSessionHandle hSession,
     [In, MarshalAs(UnmanagedType.U4)] uint uFlags,
     [In, MarshalAs(UnmanagedType.U4)] uint uIndex,
     [In, Out, MarshalAs(UnmanagedType.Bool)] ref bool pfSharedFlag,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint puCertDataLen,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder wszCertificateData);
        internal static int DRMCreateClientSession(
                                CallbackDelegate pfnCallback,
                                 uint uCallbackVersion, 
                                 string GroupIDProviderType,
                                 string GroupID, 
                                 out SafeRightsManagementSessionHandle phSession) 
        {
            SecurityHelper.DemandRightsManagementPermission(); 
            int res = UnsafeNativeMethods.DRMCreateClientSession(
                                pfnCallback,
                                uCallbackVersion,
                                GroupIDProviderType, 
                                GroupID,
                                out phSession); 
 
            // on some platforms in the failure cases the out parameter is being created with the value 0
            // in order to simplify error handling and Disposing of those handles we will just close them as 
            // soon as we detect such case
            if ((phSession != null) && phSession.IsInvalid)
            {
                phSession.Dispose(); 
                phSession = null;
            } 
            return res; 
        }
예제 #7
0
 internal static extern int DRMGetServiceLocation(
     [In] SafeRightsManagementSessionHandle clientSessionHandle,
     [In, MarshalAs(UnmanagedType.U4)] uint serviceType,
     [In, MarshalAs(UnmanagedType.U4)] uint serviceLocation,
     [In, MarshalAs(UnmanagedType.LPWStr)] string issuanceLicense,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint serviceUrlLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder serviceUrl);
예제 #8
0
 internal static int DRMDeleteLicense(
     SafeRightsManagementSessionHandle hSession,
     string wszLicenseId)
 {
     return(UnsafeNativeMethods.DRMDeleteLicense(
                hSession,
                wszLicenseId));
 }
예제 #9
0
 internal static extern int DRMAcquireLicense(
     [In] SafeRightsManagementSessionHandle hSession,
     [In, MarshalAs(UnmanagedType.U4)] uint uFlags,
     [In, MarshalAs(UnmanagedType.LPWStr)] string GroupIdentityCredential,
     [In, MarshalAs(UnmanagedType.LPWStr)] string RequestedRights,
     [In, MarshalAs(UnmanagedType.LPWStr)] string CustomData,
     [In, MarshalAs(UnmanagedType.LPWStr)] string url,
     IntPtr context);                     // this is a void* in the unmanaged SDK so IntPtr is the right (platform dependent declaration)
예제 #10
0
 internal static int DRMDeleteLicense(
     SafeRightsManagementSessionHandle hSession,
     string wszLicenseId)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMDeleteLicense(
                hSession,
                wszLicenseId));
 }
예제 #11
0
 internal static int DRMIsActivated(
     SafeRightsManagementSessionHandle hSession,
     uint uFlags,
     ActivationServerInfo activationServerInfo)
 {
     return(UnsafeNativeMethods.DRMIsActivated(
                hSession,
                uFlags,
                activationServerInfo));
 }
예제 #12
0
 internal static int DRMIsActivated(
     SafeRightsManagementSessionHandle hSession,
     uint uFlags,
     ActivationServerInfo activationServerInfo)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMIsActivated(
                hSession,
                uFlags,
                activationServerInfo));
 }
예제 #13
0
 internal static int DRMEnumerateLicense(
     SafeRightsManagementSessionHandle hSession,
     uint uFlags,
     uint uIndex,
     ref bool pfSharedFlag,
     ref uint puCertDataLen,
     StringBuilder wszCertificateData)
 {
     return(UnsafeNativeMethods.DRMEnumerateLicense(
                hSession,
                uFlags,
                uIndex,
                ref pfSharedFlag,
                ref puCertDataLen,
                wszCertificateData));
 }
예제 #14
0
 internal static int DRMGetServiceLocation(
     SafeRightsManagementSessionHandle clientSessionHandle,
     uint serviceType,
     uint serviceLocation,
     string issuanceLicense,
     ref uint serviceUrlLength,
     StringBuilder serviceUrl)
 {
     return(UnsafeNativeMethods.DRMGetServiceLocation(
                clientSessionHandle,
                serviceType,
                serviceLocation,
                issuanceLicense,
                ref serviceUrlLength,
                serviceUrl));
 }
예제 #15
0
 internal static int DRMActivate(
     SafeRightsManagementSessionHandle hSession,
     uint uFlags,
     uint uLangID,
     ActivationServerInfo activationServerInfo,
     IntPtr context,
     IntPtr parentWindowHandle)
 {
     return(UnsafeNativeMethods.DRMActivate(
                hSession,
                uFlags,
                uLangID,
                activationServerInfo,
                context,
                parentWindowHandle));
 }
예제 #16
0
 internal static int DRMAcquireLicense(
     SafeRightsManagementSessionHandle hSession,
     uint uFlags,
     string GroupIdentityCredential,
     string RequestedRights,
     string CustomData,
     string url,
     IntPtr context)
 {
     return(UnsafeNativeMethods.DRMAcquireLicense(
                hSession,
                uFlags,
                GroupIdentityCredential,
                RequestedRights,
                CustomData,
                url,
                context));
 }
 internal static int DRMDeleteLicense( 
                          SafeRightsManagementSessionHandle hSession,
                          string wszLicenseId)
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMDeleteLicense(
                         hSession, 
                         wszLicenseId); 
 }
 internal static int DRMIsActivated( 
                          SafeRightsManagementSessionHandle hSession,
                          uint uFlags, 
                          ActivationServerInfo activationServerInfo) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMIsActivated(
                         hSession,
                         uFlags,
                         activationServerInfo); 
 }
예제 #19
0
 internal static extern int DRMIsActivated(
     [In] SafeRightsManagementSessionHandle hSession,
     [In, MarshalAs(UnmanagedType.U4)] uint uFlags,
     [In, MarshalAs(UnmanagedType.LPStruct)] ActivationServerInfo activationServerInfo);
 internal static int DRMActivate( 
                         SafeRightsManagementSessionHandle hSession,
                         uint uFlags, 
                         uint uLangID,
                         ActivationServerInfo activationServerInfo,
                         IntPtr context,
                         IntPtr parentWindowHandle) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMActivate( 
                         hSession,
                         uFlags, 
                         uLangID,
                         activationServerInfo,
                         context,
                         parentWindowHandle); 
 }
        internal static int DRMCreateLicenseStorageSession( 
                                SafeRightsManagementEnvironmentHandle hEnv,
                                SafeRightsManagementHandle hDefLib, 
                                SafeRightsManagementSessionHandle hClientSession,
                                uint uFlags,
                                string IssuanceLicense,
                                out SafeRightsManagementSessionHandle phLicenseStorageSession) 
        {
            SecurityHelper.DemandRightsManagementPermission(); 
            int res = UnsafeNativeMethods.DRMCreateLicenseStorageSession( 
                                hEnv,
                                hDefLib, 
                                hClientSession,
                                uFlags,
                                IssuanceLicense,
                                out phLicenseStorageSession); 

            // on some platforms in the failure cases the out parameter is being created with the value 0 
            // in order to simplify error handling and Disposing of those handles we will just close them as 
            // soon as we detect such case
            if ((phLicenseStorageSession != null) && phLicenseStorageSession.IsInvalid) 
            {
                phLicenseStorageSession.Dispose();
                phLicenseStorageSession = null;
            } 
            return res;
        } 
 internal static int DRMAcquireLicense(
                          SafeRightsManagementSessionHandle hSession, 
                          uint uFlags,
                          string GroupIdentityCredential,
                          string RequestedRights,
                          string CustomData, 
                          string url,
                         IntPtr context) 
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMAcquireLicense( 
                         hSession,
                         uFlags,
                         GroupIdentityCredential,
                         RequestedRights, 
                         CustomData,
                         url, 
                         context); 
 }
예제 #23
0
        internal static string GetLicenseOnSession(SafeRightsManagementSessionHandle sessionHandle, EnumerateLicenseFlags enumerateLicenseFlags, int index)
        {
            Invariant.Assert(index >= 0);

            if ((enumerateLicenseFlags != EnumerateLicenseFlags.Machine) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.GroupIdentity) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.GroupIdentityName) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.GroupIdentityLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.SpecifiedGroupIdentity) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.Eul) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.EulLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.ClientLicensor) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.ClientLicensorLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.SpecifiedClientLicensor) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.RevocationList) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.RevocationListLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.Expired))
            {
                throw new ArgumentOutOfRangeException("enumerateLicenseFlags");
            }

            int hr = 0;
            bool sharedFlag = false;
            uint dataLen = 0;
            StringBuilder license = null;

            hr = SafeNativeMethods.DRMEnumerateLicense(
                sessionHandle, (uint)enumerateLicenseFlags, (uint)index, ref sharedFlag, ref dataLen, null);

            if (hr == (int)RightsManagementFailureCode.NoMoreData)
                return null;

            Errors.ThrowOnErrorCode(hr);

            if (dataLen > System.Int32.MaxValue)
                return null;

            //returned size accounts for null termination; we do not need to add 1 
            checked
            {
                license = new StringBuilder((int)dataLen);
            }

            hr = SafeNativeMethods.DRMEnumerateLicense(
                sessionHandle, (uint)enumerateLicenseFlags, (uint)index, ref sharedFlag, ref dataLen, license);

            Errors.ThrowOnErrorCode(hr);

            return license.ToString();
        }
예제 #24
0
 internal static extern int DRMDeleteLicense(
     [In] SafeRightsManagementSessionHandle hSession,
     [In, MarshalAs(UnmanagedType.LPWStr)] string wszLicenseId);
 internal static int DRMEnumerateLicense(
                          SafeRightsManagementSessionHandle hSession,
                          uint uFlags,
                          uint uIndex, 
                          ref bool pfSharedFlag,
                          ref uint puCertDataLen, 
                          StringBuilder wszCertificateData) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMEnumerateLicense(
                         hSession,
                         uFlags,
                         uIndex, 
                         ref pfSharedFlag,
                         ref puCertDataLen, 
                         wszCertificateData); 
 }
 internal static int DRMGetServiceLocation(
                          SafeRightsManagementSessionHandle clientSessionHandle,
                          uint serviceType,
                          uint serviceLocation, 
                          string issuanceLicense,
                          ref uint serviceUrlLength, 
                          StringBuilder serviceUrl) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMGetServiceLocation(
                         clientSessionHandle,
                         serviceType,
                         serviceLocation, 
                         issuanceLicense,
                         ref serviceUrlLength, 
                         serviceUrl); 
 }
예제 #27
0
 internal static extern int DRMCreateClientSession(
     [In, MarshalAs(UnmanagedType.FunctionPtr)] CallbackDelegate pfnCallback,
     [In, MarshalAs(UnmanagedType.U4)] uint uCallbackVersion,
     [In, MarshalAs(UnmanagedType.LPWStr)] string GroupIDProviderType,
     [In, MarshalAs(UnmanagedType.LPWStr)] string GroupID,
     [Out] out SafeRightsManagementSessionHandle phSession);
예제 #28
0
        private static ArrayList EnumerateAllValuesOnSession(SafeRightsManagementSessionHandle sessionHandle, EnumerateLicenseFlags enumerateLicenseFlags)
        {
            ArrayList result = new ArrayList(5);
            int index = 0;

            while (true)
            {
                string currentRes = GetLicenseOnSession(sessionHandle, enumerateLicenseFlags, index);

                if (currentRes == null)
                {
                    break;
                }
                result.Add(currentRes);
                index++;
            }
            return result;
        }