Ejemplo n.º 1
0
 internal static int DRMGetIssuanceLicenseTemplate(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     ref uint issuanceLicenseTemplateLength,
     StringBuilder issuanceLicenseTemplate)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMGetIssuanceLicenseTemplate(
                issuanceLicenseHandle,
                ref issuanceLicenseTemplateLength,
                issuanceLicenseTemplate));
 }
 internal static int DRMGetOwnerLicense(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     ref uint ownerLicenseLength,
     StringBuilder ownerLicense)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMGetOwnerLicense(
                issuanceLicenseHandle,
                ref ownerLicenseLength,
                ownerLicense));
 }
Ejemplo n.º 3
0
 internal static int DRMAddRightWithUser(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     SafeRightsManagementPubHandle rightHandle,
     SafeRightsManagementPubHandle userHandle)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMAddRightWithUser(
                issuanceLicenseHandle,
                rightHandle,
                userHandle));
 }
Ejemplo n.º 4
0
 internal static int DRMSetApplicationSpecificData(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     bool flagDelete,
     string name,
     string value)
 {
     return(UnsafeNativeMethods.DRMSetApplicationSpecificData(
                issuanceLicenseHandle,
                flagDelete,
                name,
                value));
 }
Ejemplo n.º 5
0
 internal static extern int DRMGetRevocationPoint(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint idLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder id,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint idTypeLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder idType,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint urlLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder url,
     [MarshalAs(UnmanagedType.LPStruct)] SystemTime frequency,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint nameLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder name,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint publicKeyLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder publicKey);
Ejemplo n.º 6
0
 internal static int DRMSetNameAndDescription(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     bool flagDelete,
     uint localeId,
     string name,
     string description)
 {
     return(UnsafeNativeMethods.DRMSetNameAndDescription(
                issuanceLicenseHandle,
                flagDelete,
                localeId,
                name,
                description));
 }
Ejemplo n.º 7
0
 internal static int DRMGetRightInfo(
     SafeRightsManagementPubHandle rightHandle,
     ref uint rightNameLength,
     StringBuilder rightName,
     SystemTime timeFrom,
     SystemTime timeUntil)
 {
     return(UnsafeNativeMethods.DRMGetRightInfo(
                rightHandle,
                ref rightNameLength,
                rightName,
                timeFrom,
                timeUntil));
 }
Ejemplo n.º 8
0
 internal static int DRMGetApplicationSpecificData(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     uint index,
     ref uint nameLength,
     StringBuilder name,
     ref uint valueLength,
     StringBuilder value)
 {
     return(UnsafeNativeMethods.DRMGetApplicationSpecificData(
                issuanceLicenseHandle,
                index,
                ref nameLength,
                name,
                ref valueLength,
                value));
 }
Ejemplo n.º 9
0
        private void AddGrant(ContentGrant grant)
        {
            Invariant.Assert(grant != null);
            Invariant.Assert(grant.User != null);

            SafeRightsManagementPubHandle right = GetRightHandle(grant);

            SafeRightsManagementPubHandle user = GetHandleFromUser(grant.User);

            int hr = SafeNativeMethods.DRMAddRightWithUser(
                _issuanceLicenseHandle,
                right,
                user);

            Errors.ThrowOnErrorCode(hr);
        }
Ejemplo n.º 10
0
 internal static int DRMGetNameAndDescription(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     uint uIndex,
     out uint localeId,
     ref uint nameLength,
     StringBuilder name,
     ref uint descriptionLength,
     StringBuilder description)
 {
     return(UnsafeNativeMethods.DRMGetNameAndDescription(
                issuanceLicenseHandle,
                uIndex,
                out localeId,
                ref nameLength,
                name,
                ref descriptionLength,
                description));
 }
Ejemplo n.º 11
0
 internal static int DRMSetMetaData(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     string contentId,
     string contentIdType,
     string SkuId,
     string SkuIdType,
     string contentType,
     string contentName)
 {
     return(UnsafeNativeMethods.DRMSetMetaData(
                issuanceLicenseHandle,
                contentId,
                contentIdType,
                SkuId,
                SkuIdType,
                contentType,
                contentName));
 }
Ejemplo n.º 12
0
 internal static int DRMGetUserInfo(
     SafeRightsManagementPubHandle userHandle,
     ref uint userNameLength,
     StringBuilder userName,
     ref uint userIdLength,
     StringBuilder userId,
     ref uint userIdTypeLength,
     StringBuilder userIdType)
 {
     return(UnsafeNativeMethods.DRMGetUserInfo(
                userHandle,
                ref userNameLength,
                userName,
                ref userIdLength,
                userId,
                ref userIdTypeLength,
                userIdType));
 }
Ejemplo n.º 13
0
 internal static int DRMGetUserInfo(
     SafeRightsManagementPubHandle userHandle,
     ref uint userNameLength,
     StringBuilder userName,
     ref uint userIdLength,
     StringBuilder userId,
     ref uint userIdTypeLength,
     StringBuilder userIdType)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMGetUserInfo(
                userHandle,
                ref userNameLength,
                userName,
                ref userIdLength,
                userId,
                ref userIdTypeLength,
                userIdType));
 }
Ejemplo n.º 14
0
 internal static int DRMSetMetaData(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     string contentId,
     string contentIdType,
     string SkuId,
     string SkuIdType,
     string contentType,
     string contentName)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return(UnsafeNativeMethods.DRMSetMetaData(
                issuanceLicenseHandle,
                contentId,
                contentIdType,
                SkuId,
                SkuIdType,
                contentType,
                contentName));
 }
Ejemplo n.º 15
0
 internal static int DRMSetRevocationPoint(
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     bool flagDelete,
     string id,
     string idType,
     string url,
     SystemTime frequency,
     string name,
     string publicKey)
 {
     return(UnsafeNativeMethods.DRMSetRevocationPoint(
                issuanceLicenseHandle,
                flagDelete,
                id,
                idType,
                url,
                frequency,
                name,
                publicKey));
 }
Ejemplo n.º 16
0
        internal static int DRMGetUsers(
            SafeRightsManagementPubHandle issuanceLicenseHandle,
            uint index,
            out SafeRightsManagementPubHandle userHandle)
        {
            int res = UnsafeNativeMethods.DRMGetUsers(
                issuanceLicenseHandle,
                index,
                out userHandle);

            // 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 ((userHandle != null) && userHandle.IsInvalid)
            {
                userHandle.Dispose();
                userHandle = null;
            }
            return(res);
        }
Ejemplo n.º 17
0
        internal static int DRMCreateUser(
            string userName,
            string userId,
            string userIdType,
            out SafeRightsManagementPubHandle userHandle)
        {
            SecurityHelper.DemandRightsManagementPermission();
            int res = UnsafeNativeMethods.DRMCreateUser(
                userName,
                userId,
                userIdType,
                out userHandle);

            // 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 ((userHandle != null) && userHandle.IsInvalid)
            {
                userHandle.Dispose();
                userHandle = null;
            }
            return(res);
        }
Ejemplo n.º 18
0
 internal static int DRMGetSignedIssuanceLicense(
     SafeRightsManagementEnvironmentHandle environmentHandle,
     SafeRightsManagementPubHandle issuanceLicenseHandle,
     uint flags,
     byte[] symmetricKey,
     uint symmetricKeyByteCount,
     string symmetricKeyType,
     string clientLicensorCertificate,
     CallbackDelegate pfnCallback,
     string Url,
     uint context)
 {
     return(UnsafeNativeMethods.DRMGetSignedIssuanceLicense(
                environmentHandle,
                issuanceLicenseHandle,
                flags,
                symmetricKey,
                symmetricKeyByteCount,
                symmetricKeyType,
                clientLicensorCertificate,
                pfnCallback,
                Url,
                context));
 }
Ejemplo n.º 19
0
        private ContentUser GetIssuanceLicenseUser(int index, out SafeRightsManagementPubHandle userHandle)
        {
            Invariant.Assert(index >= 0);

            int hr = SafeNativeMethods.DRMGetUsers(
                _issuanceLicenseHandle, (uint)index, out userHandle);

            // there is a special code indication end of the enumeration
            if (hr == (int)RightsManagementFailureCode.NoMoreData)
            {
                userHandle = null;
                return(null);
            }

            // check for errors
            Errors.ThrowOnErrorCode(hr);
            Debug.Assert((userHandle != null) && (!userHandle.IsInvalid));

            // preserve handle so we can destruct it later
            _pubHandlesList.Add(userHandle);

            // now we can build a ContentUser
            return(GetUserFromHandle(userHandle));
        }
Ejemplo n.º 20
0
 internal static extern int DRMAddRightWithUser(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In] SafeRightsManagementPubHandle rightHandle,
     [In] SafeRightsManagementPubHandle userHandle);
Ejemplo n.º 21
0
 internal static extern int DRMGetOwnerLicense(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint ownerLicenseLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder ownerLicense);
Ejemplo n.º 22
0
 internal static int DRMSetNameAndDescription(
                             SafeRightsManagementPubHandle issuanceLicenseHandle,
                             bool flagDelete,
                             uint localeId, 
                             string name,
                             string description) 
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMSetNameAndDescription( 
                          issuanceLicenseHandle,
                          flagDelete,
                          localeId,
                          name, 
                          description);
 } 
Ejemplo n.º 23
0
 internal static extern int DRMGetUserRights(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In] SafeRightsManagementPubHandle userHandle,
     [In, MarshalAs(UnmanagedType.U4)] uint index,
     [Out] out SafeRightsManagementPubHandle rightHandle);
Ejemplo n.º 24
0
        internal static int DRMCreateUser(
                                 string userName,
                                 string userId,
                                 string userIdType, 
                                 out SafeRightsManagementPubHandle userHandle)
        { 
            SecurityHelper.DemandRightsManagementPermission(); 
            int res = UnsafeNativeMethods.DRMCreateUser(
                                userName, 
                                userId,
                                userIdType,
                                out userHandle);
 
            // 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 ((userHandle != null) && userHandle.IsInvalid)
            { 
                userHandle.Dispose();
                userHandle = null;
            }
            return res; 
        }
Ejemplo n.º 25
0
        internal void UpdateUnsignedPublishLicense(UnsignedPublishLicense unsignedPublishLicense)
        {
            Invariant.Assert(unsignedPublishLicense != null);

            DateTime timeFrom;
            DateTime timeUntil;
            DistributionPointInfo distributionPointInfo = DistributionPointInfo.ReferralInfo;
            string      distributionPointName;
            string      distributionPointUri;
            ContentUser owner;
            bool        officialFlag;

            GetIssuanceLicenseInfo(out timeFrom,
                                   out timeUntil,
                                   distributionPointInfo,
                                   out distributionPointName,
                                   out distributionPointUri,
                                   out owner,
                                   out officialFlag);

            unsignedPublishLicense.ReferralInfoName = distributionPointName;

            if (distributionPointUri != null)
            {
                unsignedPublishLicense.ReferralInfoUri = new Uri(distributionPointUri);
            }
            else
            {
                unsignedPublishLicense.ReferralInfoUri = null;
            }

            unsignedPublishLicense.Owner = owner;

            // Let's get the validity Iterval information (days) and save it in the license
            uint validityDays = 0;
            int  hr           = SafeNativeMethods.DRMGetIntervalTime(_issuanceLicenseHandle, ref validityDays);

            Errors.ThrowOnErrorCode(hr);
            checked { unsignedPublishLicense.RightValidityIntervalDays = (int)validityDays; }

            // let's get the rights information
            int userIndex = 0;

            while (true) // in this loop we are enumerating users mentioned in the license
            {
                SafeRightsManagementPubHandle userHandle = null;

                // extract the user based on the index
                ContentUser user = GetIssuanceLicenseUser(userIndex, out userHandle);

                if ((user == null) || (userHandle == null))
                {
                    break;
                }

                int rightIndex = 0;
                while (true) // now we can enumerate rights granted to the given user
                {
                    SafeRightsManagementPubHandle rightHandle = null;
                    DateTime validFrom;
                    DateTime validUntil;

                    // extract the right based on the index and the user
                    Nullable <ContentRight> right = GetIssuanceLicenseUserRight
                                                        (userHandle, rightIndex, out rightHandle, out validFrom, out validUntil);

                    // 0 right handle is an indication of the end of the list
                    if (rightHandle == null)
                    {
                        break;
                    }

                    // right == null is an indication of a right that we didn't recognize
                    // we should still continue the enumeration
                    if (right != null)
                    {
                        // Add the grant for the User Right pair here
                        unsignedPublishLicense.Grants.Add(
                            new ContentGrant(user, right.Value, validFrom, validUntil));
                    }

                    rightIndex++;
                }
                userIndex++;
            }

            // let's get the localized name description pairs
            int nameIndex = 0;

            while (true) // in this loop we are enumerating nameDescription pairs mentioned in the license
            {
                int localeId;

                // extract the user based on the index
                LocalizedNameDescriptionPair nameDescription = GetLocalizedNameDescriptionPair(nameIndex,
                                                                                               out localeId);
                if (nameDescription == null)
                {
                    break;
                }

                // Add the name description info to the license
                unsignedPublishLicense.LocalizedNameDescriptionDictionary.Add(localeId, nameDescription);
                nameIndex++;
            }

            // let's get the application specific data
            int appDataIndex = 0;

            while (true) // in this loop we are enumerating nameDescription pairs mentioned in the license
            {
                // extract the user based on the index

                Nullable <KeyValuePair <string, string> > appSpecificDataEntry = GetApplicationSpecificData(appDataIndex);

                if (appSpecificDataEntry == null)
                {
                    break;
                }

                // Add the name description info to the license
                unsignedPublishLicense.ApplicationSpecificDataDictionary.Add(appSpecificDataEntry.Value.Key, appSpecificDataEntry.Value.Value);
                appDataIndex++;
            }

            // Get the revocation Point information, it is optional and can be null
            unsignedPublishLicense.RevocationPoint = GetRevocationPoint();
        }
Ejemplo n.º 26
0
 internal static int DRMSetIntervalTime(
                         SafeRightsManagementPubHandle issuanceLicenseHandle, 
                         uint days)
 { 
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMSetIntervalTime(
                         issuanceLicenseHandle, 
                         days);
 }
Ejemplo n.º 27
0
        internal static string GetOwnerLicense(SafeRightsManagementPubHandle issuanceLicenseHandle)
        {
            Invariant.Assert(!issuanceLicenseHandle.IsInvalid);

            uint ownerLicenseLength = 0;
            StringBuilder ownerLicense = null;

            int hr = SafeNativeMethods.DRMGetOwnerLicense(
                issuanceLicenseHandle, ref ownerLicenseLength, null);
            Errors.ThrowOnErrorCode(hr);

            checked
            {
                ownerLicense = new StringBuilder((int)ownerLicenseLength);
            }

            hr = SafeNativeMethods.DRMGetOwnerLicense(
                issuanceLicenseHandle, ref ownerLicenseLength, ownerLicense);
            Errors.ThrowOnErrorCode(hr);

            return ownerLicense.ToString();
        }
Ejemplo n.º 28
0
 internal static int DRMGetApplicationSpecificData( 
                         SafeRightsManagementPubHandle issuanceLicenseHandle, 
                         uint index,
                         ref uint nameLength, 
                         StringBuilder name,
                         ref uint valueLength,
                         StringBuilder value)
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMGetApplicationSpecificData( 
                         issuanceLicenseHandle, 
                         index,
                         ref nameLength, 
                         name,
                         ref valueLength,
                         value);
 } 
Ejemplo n.º 29
0
 internal static int DRMSetApplicationSpecificData( 
                         SafeRightsManagementPubHandle issuanceLicenseHandle, 
                         bool flagDelete,
                         string name, 
                         string value)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMSetApplicationSpecificData( 
                         issuanceLicenseHandle,
                         flagDelete, 
                         name, 
                         value);
 } 
Ejemplo n.º 30
0
 internal static int DRMGetOwnerLicense(
                          SafeRightsManagementPubHandle issuanceLicenseHandle,
                          ref uint ownerLicenseLength,
                          StringBuilder ownerLicense) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMGetOwnerLicense( 
                         issuanceLicenseHandle,
                         ref ownerLicenseLength, 
                         ownerLicense);
 }
Ejemplo n.º 31
0
 internal static int DRMGetSignedIssuanceLicense(
                          SafeRightsManagementEnvironmentHandle environmentHandle,
                          SafeRightsManagementPubHandle issuanceLicenseHandle, 
                          uint flags,
                          byte[] symmetricKey, 
                          uint symmetricKeyByteCount, 
                          string symmetricKeyType,
                          string clientLicensorCertificate, 
                          CallbackDelegate pfnCallback,
                          string Url,
                          uint context)
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMGetSignedIssuanceLicense( 
                         environmentHandle, 
                         issuanceLicenseHandle,
                         flags, 
                         symmetricKey,
                         symmetricKeyByteCount,
                         symmetricKeyType,
                         clientLicensorCertificate, 
                         pfnCallback,
                         Url, 
                         context); 
 }
Ejemplo n.º 32
0
 internal static int DRMGetNameAndDescription( 
                             SafeRightsManagementPubHandle issuanceLicenseHandle,
                             uint uIndex,
                             out uint localeId,
                             ref uint nameLength, 
                             StringBuilder name,
                             ref uint descriptionLength, 
                             StringBuilder description) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMGetNameAndDescription(
                             issuanceLicenseHandle,
                             uIndex,
                             out localeId, 
                             ref nameLength,
                             name, 
                             ref descriptionLength, 
                             description);
 } 
Ejemplo n.º 33
0
 internal static extern int DRMSetIntervalTime(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In, MarshalAs(UnmanagedType.U4)] uint days);
Ejemplo n.º 34
0
 internal static int DRMCreateRight(
                          string rightName, 
                          SystemTime timeFrom,
                          SystemTime timeUntil,
                          uint countExtendedInfo,
                          string[] extendedInfoNames, 
                          string[] extendedInfoValues,
                          out SafeRightsManagementPubHandle rightHandle) 
 { 
     SecurityHelper.DemandRightsManagementPermission();
     int res = UnsafeNativeMethods.DRMCreateRight( 
                         rightName,
                         timeFrom,
                         timeUntil,
                         countExtendedInfo, 
                         extendedInfoNames,
                         extendedInfoValues, 
                         out rightHandle); 
     // 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 ((rightHandle != null) && rightHandle.IsInvalid)
     {
         rightHandle.Dispose(); 
         rightHandle = null;
     } 
     return res; 
 }
Ejemplo n.º 35
0
 internal static int DRMAddRightWithUser( 
                          SafeRightsManagementPubHandle issuanceLicenseHandle,
                          SafeRightsManagementPubHandle rightHandle, 
                          SafeRightsManagementPubHandle userHandle)
 {
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMAddRightWithUser( 
                         issuanceLicenseHandle,
                         rightHandle, 
                         userHandle); 
 }
Ejemplo n.º 36
0
 internal static int DRMSetRevocationPoint(
                         SafeRightsManagementPubHandle issuanceLicenseHandle, 
                         bool flagDelete,
                         string id,
                         string idType,
                         string url, 
                         SystemTime frequency,
                         string name, 
                         string publicKey) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMSetRevocationPoint(
                         issuanceLicenseHandle,
                         flagDelete,
                         id, 
                         idType,
                         url, 
                         frequency, 
                         name,
                         publicKey); 
 }
Ejemplo n.º 37
0
 internal static int DRMSetMetaData(
                          SafeRightsManagementPubHandle issuanceLicenseHandle,
                          string contentId,
                          string contentIdType, 
                          string SkuId,
                          string SkuIdType, 
                          string contentType, 
                          string contentName)
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMSetMetaData(
                         issuanceLicenseHandle,
                         contentId, 
                         contentIdType,
                         SkuId, 
                         SkuIdType, 
                         contentType,
                         contentName); 
 }
Ejemplo n.º 38
0
        static private ContentUser GetUserFromHandle(SafeRightsManagementPubHandle userHandle)
        {
            uint          userNameLength   = 0;
            StringBuilder userName         = null;
            uint          userIdLength     = 0;
            StringBuilder userId           = null;
            uint          userIdTypeLength = 0;
            StringBuilder userIdType       = null;

            int hr = SafeNativeMethods.DRMGetUserInfo(userHandle,
                                                      ref userNameLength,
                                                      null,
                                                      ref userIdLength,
                                                      null,
                                                      ref userIdTypeLength,
                                                      null);

            Errors.ThrowOnErrorCode(hr);

            if (userNameLength > 0)
            {   // only allocate memory if we got a non-zero size back
                userName = new StringBuilder(checked ((int)userNameLength));
            }

            if (userIdLength > 0)
            {   // only allocate memory if we got a non-zero size back
                userId = new StringBuilder(checked ((int)userIdLength));
            }

            if (userIdTypeLength > 0)
            {   // only allocate memory if we got a non-zero size back
                userIdType = new StringBuilder(checked ((int)userIdTypeLength));
            }

            hr = SafeNativeMethods.DRMGetUserInfo(userHandle,
                                                  ref userNameLength,
                                                  userName,
                                                  ref userIdLength,
                                                  userId,
                                                  ref userIdTypeLength,
                                                  userIdType);
            Errors.ThrowOnErrorCode(hr);

            // Convert String Builder values to string values
            string userNameStr = null;

            if (userName != null)
            {
                userNameStr = userName.ToString();
            }

            string userIdTypeStr = null;

            if (userIdType != null)
            {
                userIdTypeStr = userIdType.ToString().ToUpperInvariant();
            }

            string userIdStr = null;

            if (userId != null)
            {
                userIdStr = userId.ToString().ToUpperInvariant();
            }

            // based on the UserTypeId build appropriate instance of User class
            if (String.CompareOrdinal(userIdTypeStr, AuthenticationType.Windows.ToString().ToUpperInvariant()) == 0)
            {
                return(new ContentUser(userNameStr, AuthenticationType.Windows));
            }
            else if (String.CompareOrdinal(userIdTypeStr, AuthenticationType.Passport.ToString().ToUpperInvariant()) == 0)
            {
                return(new ContentUser(userNameStr, AuthenticationType.Passport));
            }
            else if (String.CompareOrdinal(userIdTypeStr, AuthenticationType.Internal.ToString().ToUpperInvariant()) == 0)
            {
                // internal anyone user
                if (ContentUser.CompareToAnyone(userIdStr))
                {
                    return(ContentUser.AnyoneUser);
                }
                else if (ContentUser.CompareToOwner(userIdStr))
                {
                    return(ContentUser.OwnerUser);
                }
            }
            else if (String.CompareOrdinal(userIdTypeStr, UnspecifiedAuthenticationType.ToUpperInvariant()) == 0)
            {
                return(new ContentUser(userNameStr, AuthenticationType.WindowsPassport));
            }

            throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);
        }
Ejemplo n.º 39
0
        internal static int DRMCreateIssuanceLicense(
                                 SystemTime timeFrom, 
                                 SystemTime timeUntil, 
                                 string referralInfoName,
                                 string referralInfoUrl, 
                                 SafeRightsManagementPubHandle ownerUserHandle,
                                 string issuanceLicense,
                                 SafeRightsManagementHandle boundLicenseHandle,
                                 out SafeRightsManagementPubHandle issuanceLicenseHandle) 
        {
            SecurityHelper.DemandRightsManagementPermission(); 
            int res = UnsafeNativeMethods.DRMCreateIssuanceLicense( 
                                timeFrom,
                                timeUntil, 
                                referralInfoName,
                                referralInfoUrl,
                                ownerUserHandle,
                                issuanceLicense, 
                                boundLicenseHandle,
                                out issuanceLicenseHandle); 
 
            // 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 ((issuanceLicenseHandle != null) && issuanceLicenseHandle.IsInvalid)
            {
                issuanceLicenseHandle.Dispose(); 
                issuanceLicenseHandle = null;
            } 
            return res; 
        }
Ejemplo n.º 40
0
        private void GetIssuanceLicenseInfo(
            out DateTime timeFrom,
            out DateTime timeUntil,
            DistributionPointInfo distributionPointInfo,
            out string distributionPointName,
            out string distributionPointUri,
            out ContentUser owner,
            out bool officialFlag)
        {
            uint distributionPointNameLength = 0;
            uint distributionPointUriLength  = 0;
            bool officialFlagTemp            = false;
            SafeRightsManagementPubHandle ownerHandleTemp = null;

            int hr = SafeNativeMethods.DRMGetIssuanceLicenseInfo(
                _issuanceLicenseHandle,
                null,
                null,
                (uint)distributionPointInfo,
                ref distributionPointNameLength,
                null,
                ref distributionPointUriLength,
                null,
                out ownerHandleTemp,
                out officialFlagTemp);

            Errors.ThrowOnErrorCode(hr);

            if (ownerHandleTemp != null)
            {
                // As a result of calling DRMGetIssuanceLicenseInfo twice,
                // we are getting 2 handles. We are going to dispose the first one
                // and preserve the second one.
                ownerHandleTemp.Dispose();
                ownerHandleTemp = null;
            }

            StringBuilder distributionPointNameTemp = null;

            // allocate memory as necessary, it seems that Unmanaged libraries really do not like
            // getting a non null buffer of size 0
            if (distributionPointNameLength > 0)
            {
                distributionPointNameTemp = new StringBuilder(checked ((int)distributionPointNameLength));
            }

            StringBuilder distributionPointUriTemp = null;

            // allocate memory as necessary, it seems that Unmanaged libraries really do not like
            // getting a non null buffer of size 0
            if (distributionPointUriLength > 0)
            {
                distributionPointUriTemp = new StringBuilder(checked ((int)distributionPointUriLength));
            }

            SystemTime timeFromTemp  = new SystemTime(DateTime.Now);
            SystemTime timeUntilTemp = new SystemTime(DateTime.Now);

            hr = SafeNativeMethods.DRMGetIssuanceLicenseInfo(
                _issuanceLicenseHandle,
                timeFromTemp,
                timeUntilTemp,
                (uint)distributionPointInfo,
                ref distributionPointNameLength,
                distributionPointNameTemp,
                ref distributionPointUriLength,
                distributionPointUriTemp,
                out ownerHandleTemp,
                out officialFlagTemp);
            Errors.ThrowOnErrorCode(hr);

            timeFrom  = timeFromTemp.GetDateTime(DateTime.MinValue);
            timeUntil = timeUntilTemp.GetDateTime(DateTime.MaxValue);

            // only if we got some data back we shall try to process it
            if (distributionPointNameTemp != null)
            {
                distributionPointName = distributionPointNameTemp.ToString();
            }
            else
            {
                distributionPointName = null;
            }

            // only if we got some data back we shall try to process it
            if (distributionPointUriTemp != null)
            {
                distributionPointUri = distributionPointUriTemp.ToString();
            }
            else
            {
                distributionPointUri = null;
            }

            // if we have owner let's convert it to a user and preserve
            // handler for further destruction
            owner = null;
            if (ownerHandleTemp != null)
            {
                _pubHandlesList.Add(ownerHandleTemp);

                if (!ownerHandleTemp.IsInvalid)
                {
                    owner = GetUserFromHandle(ownerHandleTemp);
                }
            }

            officialFlag = officialFlagTemp;
        }
Ejemplo n.º 41
0
 internal static int DRMGetRightInfo(
                          SafeRightsManagementPubHandle rightHandle,
                          ref uint rightNameLength,
                          StringBuilder rightName, 
                          SystemTime timeFrom,
                          SystemTime timeUntil) 
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMGetRightInfo( 
                         rightHandle,
                         ref rightNameLength,
                         rightName,
                         timeFrom, 
                         timeUntil);
 } 
Ejemplo n.º 42
0
 internal static int DRMGetIssuanceLicenseInfo(
                          SafeRightsManagementPubHandle issuanceLicenseHandle, 
                          SystemTime timeFrom,
                          SystemTime timeUntil, 
                          uint flags, 
                          ref uint distributionPointNameLength,
                          StringBuilder DistributionPointName, 
                          ref uint distributionPointUriLength,
                          StringBuilder DistributionPointUri,
                          out SafeRightsManagementPubHandle ownerHandle,
                          out bool officialFlag) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     int res = UnsafeNativeMethods.DRMGetIssuanceLicenseInfo( 
                         issuanceLicenseHandle,
                         timeFrom, 
                         timeUntil,
                         flags,
                         ref distributionPointNameLength,
                         DistributionPointName, 
                         ref distributionPointUriLength,
                         DistributionPointUri, 
                         out ownerHandle, 
                         out officialFlag);
     // 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 ((ownerHandle != null) && ownerHandle.IsInvalid)
     { 
         ownerHandle.Dispose();
         ownerHandle = null; 
     } 
     return res;
 } 
Ejemplo n.º 43
0
 internal static int DRMGetUserInfo(
                          SafeRightsManagementPubHandle userHandle, 
                          ref uint userNameLength,
                          StringBuilder userName,
                          ref uint userIdLength,
                          StringBuilder userId, 
                          ref uint userIdTypeLength,
                          StringBuilder userIdType) 
 { 
     SecurityHelper.DemandRightsManagementPermission();
     return UnsafeNativeMethods.DRMGetUserInfo( 
                         userHandle,
                         ref userNameLength,
                         userName,
                         ref userIdLength, 
                         userId,
                         ref userIdTypeLength, 
                         userIdType); 
 }
Ejemplo n.º 44
0
        internal static int DRMGetUserRights(
                                 SafeRightsManagementPubHandle issuanceLicenseHandle,
                                 SafeRightsManagementPubHandle userHandle, 
                                 uint index,
                                 out SafeRightsManagementPubHandle rightHandle) 
        { 
            SecurityHelper.DemandRightsManagementPermission();
            int res = UnsafeNativeMethods.DRMGetUserRights( 
                                issuanceLicenseHandle,
                                userHandle,
                                index,
                                out rightHandle); 

            // 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 ((rightHandle != null) && rightHandle.IsInvalid) 
            {
                rightHandle.Dispose();
                rightHandle = null;
            } 
            return res;
        } 
Ejemplo n.º 45
0
 internal static extern int DRMCreateUser(
     [In, MarshalAs(UnmanagedType.LPWStr)] string userName,
     [In, MarshalAs(UnmanagedType.LPWStr)] string userId,
     [In, MarshalAs(UnmanagedType.LPWStr)] string userIdType,
     [Out] out SafeRightsManagementPubHandle userHandle);
Ejemplo n.º 46
0
        static private Nullable<ContentRight> GetRightFromHandle(SafeRightsManagementPubHandle rightHandle,
                                                        out DateTime validFrom,
                                                        out DateTime validUntil)
        {
            uint rightNameLength = 0;
            StringBuilder rightName;

            int hr = SafeNativeMethods.DRMGetRightInfo(rightHandle,
                                                                                ref rightNameLength,
                                                                                null,
                                                                                null,
                                                                                null);
            Errors.ThrowOnErrorCode(hr);

            rightName = new StringBuilder(checked((int)rightNameLength));
            SystemTime validFromSysTime = new SystemTime(DateTime.Now);
            SystemTime validUntilSysTime = new SystemTime(DateTime.Now);

            hr = SafeNativeMethods.DRMGetRightInfo(rightHandle,
                                                                                ref rightNameLength,
                                                                                rightName,
                                                                                validFromSysTime,
                                                                                validUntilSysTime);
            Errors.ThrowOnErrorCode(hr);

            validFrom = validFromSysTime.GetDateTime(DateTime.MinValue);
            validUntil = validUntilSysTime.GetDateTime(DateTime.MaxValue);

            return ClientSession.GetRightFromString(rightName.ToString());
        }
Ejemplo n.º 47
0
 internal static extern int DRMGetRightInfo(
     [In] SafeRightsManagementPubHandle rightHandle,
     [In, Out, MarshalAs(UnmanagedType.U4)] ref uint rightNameLength,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder rightName,
     [MarshalAs(UnmanagedType.LPStruct)] SystemTime timeFrom,
     [MarshalAs(UnmanagedType.LPStruct)] SystemTime timeUntil);
Ejemplo n.º 48
0
        static private ContentUser GetUserFromHandle(SafeRightsManagementPubHandle userHandle)
        {
            uint userNameLength = 0;
            StringBuilder userName = null;
            uint userIdLength = 0;
            StringBuilder userId = null;
            uint userIdTypeLength = 0;
            StringBuilder userIdType = null;

            int hr = SafeNativeMethods.DRMGetUserInfo(userHandle,
                                                                                ref userNameLength,
                                                                                null,
                                                                                ref userIdLength,
                                                                                null,
                                                                                ref userIdTypeLength,
                                                                                null);
            Errors.ThrowOnErrorCode(hr);

            if (userNameLength > 0)
            {   // only allocate memory if we got a non-zero size back
                userName = new StringBuilder(checked((int)userNameLength));
            }

            if (userIdLength > 0)
            {   // only allocate memory if we got a non-zero size back
                userId = new StringBuilder(checked((int)userIdLength));
            }

            if (userIdTypeLength > 0)
            {   // only allocate memory if we got a non-zero size back
                userIdType = new StringBuilder(checked((int)userIdTypeLength));
            }

            hr = SafeNativeMethods.DRMGetUserInfo(userHandle,
                                                                                ref userNameLength,
                                                                                userName,
                                                                                ref userIdLength,
                                                                                userId,
                                                                                ref userIdTypeLength,
                                                                                userIdType);
            Errors.ThrowOnErrorCode(hr);

            // Convert String Builder values to string values 
            string userNameStr = null;
            if (userName != null)
            {
                userNameStr = userName.ToString();
            }

            string userIdTypeStr = null;
            if (userIdType != null)
            {
                userIdTypeStr = userIdType.ToString().ToUpperInvariant();
            }

            string userIdStr = null;
            if (userId != null)
            {
                userIdStr = userId.ToString().ToUpperInvariant();
            }

            // based on the UserTypeId build appropriate instance of User class 
            if (String.CompareOrdinal(userIdTypeStr, AuthenticationType.Windows.ToString().ToUpperInvariant()) == 0)
            {
                return new ContentUser(userNameStr, AuthenticationType.Windows);
            }
            else if (String.CompareOrdinal(userIdTypeStr, AuthenticationType.Passport.ToString().ToUpperInvariant()) == 0)
            {
                return new ContentUser(userNameStr, AuthenticationType.Passport);
            }
            else if (String.CompareOrdinal(userIdTypeStr, AuthenticationType.Internal.ToString().ToUpperInvariant()) == 0)
            {
                // internal anyone user 
                if (ContentUser.CompareToAnyone(userIdStr))
                {
                    return ContentUser.AnyoneUser;
                }
                else if (ContentUser.CompareToOwner(userIdStr))
                {
                    return ContentUser.OwnerUser;
                }
            }
            else if (String.CompareOrdinal(userIdTypeStr, UnspecifiedAuthenticationType.ToUpperInvariant()) == 0)
            {
                return new ContentUser(userNameStr, AuthenticationType.WindowsPassport);
            }

            throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);
        }
Ejemplo n.º 49
0
 internal static extern int DRMSetNameAndDescription(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In, MarshalAs(UnmanagedType.Bool)] bool flagDelete,
     [In, MarshalAs(UnmanagedType.U4)] uint localeId,
     [In, MarshalAs(UnmanagedType.LPWStr)] string name,
     [In, MarshalAs(UnmanagedType.LPWStr)] string description);
Ejemplo n.º 50
0
        private ContentUser GetIssuanceLicenseUser(int index, out SafeRightsManagementPubHandle userHandle)
        {
            Invariant.Assert(index >= 0);

            int hr = SafeNativeMethods.DRMGetUsers(
                _issuanceLicenseHandle, (uint)index, out userHandle);

            // there is a special code indication end of the enumeration 
            if (hr == (int)RightsManagementFailureCode.NoMoreData)
            {
                userHandle = null;
                return null;
            }

            // check for errors
            Errors.ThrowOnErrorCode(hr);
            Debug.Assert((userHandle != null) && (!userHandle.IsInvalid));

            // preserve handle so we can destruct it later 
            _pubHandlesList.Add(userHandle);

            // now we can build a ContentUser
            return GetUserFromHandle(userHandle);
        }
Ejemplo n.º 51
0
 internal static extern int DRMSetApplicationSpecificData(
     [In] SafeRightsManagementPubHandle issuanceLicenseHandle,
     [In, MarshalAs(UnmanagedType.Bool)] bool flagDelete,
     [In, MarshalAs(UnmanagedType.LPWStr)] string name,
     [In, MarshalAs(UnmanagedType.LPWStr)] string value);
Ejemplo n.º 52
0
        private Nullable<ContentRight> GetIssuanceLicenseUserRight
                                                    (SafeRightsManagementPubHandle userHandle,
                                                    int index,
                                                    out SafeRightsManagementPubHandle rightHandle,
                                                    out DateTime validFrom,
                                                    out DateTime validUntil)
        {
            Invariant.Assert(index >= 0);

            int hr = SafeNativeMethods.DRMGetUserRights(_issuanceLicenseHandle, userHandle, (uint)index, out rightHandle);

            // there is a special code indicating end of the enumeration 
            if (hr == (int)RightsManagementFailureCode.NoMoreData)
            {
                rightHandle = null;
                validFrom = DateTime.MinValue;
                validUntil = DateTime.MaxValue;

                return null;       // intentionally we return an invalid value, to make use client 
                // properly verify right handle 
            }

            // check for errors
            Errors.ThrowOnErrorCode(hr);
            Debug.Assert((rightHandle != null) && (!rightHandle.IsInvalid));

            // preserve handle so we can destruct it later 
            _pubHandlesList.Add(rightHandle);

            // now we can build a User
            return GetRightFromHandle(rightHandle, out validFrom, out validUntil);
        }
Ejemplo n.º 53
0
 internal static int DRMGetRevocationPoint( 
                         SafeRightsManagementPubHandle issuanceLicenseHandle,
                         ref uint idLength, 
                         StringBuilder id, 
                         ref uint idTypeLength,
                         StringBuilder idType, 
                         ref uint urlLength,
                         StringBuilder url,
                         SystemTime frequency,
                         ref uint nameLength, 
                         StringBuilder name,
                         ref uint publicKeyLength, 
                         StringBuilder publicKey) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMGetRevocationPoint(
                         issuanceLicenseHandle,
                         ref idLength,
                         id, 
                         ref idTypeLength,
                         idType, 
                         ref urlLength, 
                         url,
                         frequency, 
                         ref nameLength,
                         name,
                         ref publicKeyLength,
                         publicKey); 
 }
Ejemplo n.º 54
0
 internal static int DRMGetIssuanceLicenseTemplate(
                          SafeRightsManagementPubHandle issuanceLicenseHandle,
                          ref uint issuanceLicenseTemplateLength,
                          StringBuilder issuanceLicenseTemplate) 
 {
     SecurityHelper.DemandRightsManagementPermission(); 
     return UnsafeNativeMethods.DRMGetIssuanceLicenseTemplate( 
                         issuanceLicenseHandle,
                         ref issuanceLicenseTemplateLength, 
                         issuanceLicenseTemplate);
 }