Beispiel #1
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();
        }
Beispiel #2
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;
        }
        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;
        }