Beispiel #1
0
 internal IssuanceLicense(
     DateTime validFrom,
     DateTime validUntil,
     string referralInfoName,
     Uri referralInfoUri,
     ContentUser owner,
     string issuanceLicense,
     SafeRightsManagementHandle boundLicenseHandle,
     Guid contentId,
     ICollection <ContentGrant> grantCollection,
     IDictionary <int, LocalizedNameDescriptionPair> localizedNameDescriptionDictionary,
     IDictionary <string, string> applicationSpecificDataDictionary,
     int rightValidityIntervalDays,
     RevocationPoint revocationPoint)
 {
     Initialize(
         validFrom,
         validUntil,
         referralInfoName,
         referralInfoUri,
         owner,
         issuanceLicense,
         boundLicenseHandle,
         contentId,
         grantCollection,
         localizedNameDescriptionDictionary,
         applicationSpecificDataDictionary,
         rightValidityIntervalDays,
         revocationPoint);
 }
 internal IssuanceLicense(
                                 DateTime validFrom,
                                 DateTime validUntil,
                                 string referralInfoName,
                                 Uri referralInfoUri,
                                 ContentUser owner,
                                 string issuanceLicense,
                                 SafeRightsManagementHandle boundLicenseHandle,
                                 Guid contentId,
                                 ICollection<ContentGrant> grantCollection,
                                 IDictionary<int, LocalizedNameDescriptionPair> localizedNameDescriptionDictionary,
                                 IDictionary<string, string> applicationSpecificDataDictionary,
                                 int rightValidityIntervalDays,
                                 RevocationPoint revocationPoint)
 {
     Initialize(
         validFrom,
         validUntil,
         referralInfoName,
         referralInfoUri,
         owner,
         issuanceLicense,
         boundLicenseHandle,
         contentId,
         grantCollection,
         localizedNameDescriptionDictionary,
         applicationSpecificDataDictionary,
         rightValidityIntervalDays,
         revocationPoint);
 }
Beispiel #3
0
        private void SetRevocationPoint(RevocationPoint revocationPoint)
        {
            int hr = SafeNativeMethods.DRMSetRevocationPoint(
                _issuanceLicenseHandle,
                false,                 // flagDelete,
                revocationPoint.Id,
                revocationPoint.IdType,
                revocationPoint.Url.AbsoluteUri,                 // We are using Uri class as a basic validation mechanism. These URIs come from unmanaged
                // code libraries and go back as parameters into the unmanaged code libraries.
                // We use AbsoluteUri property as means of verifying that it is actually an absolute and
                // well formed Uri. If by any chance it happened to be a relative URI, an exception will
                // be thrown here. This will perform the necessary escaping.
                revocationPoint.Frequency,
                revocationPoint.Name,
                revocationPoint.PublicKey);

            Errors.ThrowOnErrorCode(hr);
        }
Beispiel #4
0
        private RevocationPoint GetRevocationPoint()
        {
            uint       idLength        = 0;
            uint       idTypeLength    = 0;
            uint       urlLength       = 0;
            uint       nameLength      = 0;
            uint       publicKeyLength = 0;
            SystemTime frequency       = new SystemTime(DateTime.Now);

            int hr = SafeNativeMethods.DRMGetRevocationPoint(
                _issuanceLicenseHandle,
                ref idLength,
                null,
                ref idTypeLength,
                null,
                ref urlLength,
                null,
                frequency,
                ref nameLength,
                null,
                ref publicKeyLength,
                null);

            if (hr == (int)RightsManagementFailureCode.RevocationInfoNotSet)
            {
                return(null);
            }

            Errors.ThrowOnErrorCode(hr);

            // allocate memory as necessary, it seems that Unmanaged libraries really do not like
            // getting a non null buffer of size 0
            StringBuilder idTemp = null;

            if (idLength > 0)
            {
                idTemp = new StringBuilder(checked ((int)idLength));
            }

            StringBuilder idTypeTemp = null;

            if (idTypeLength > 0)
            {
                idTypeTemp = new StringBuilder(checked ((int)idTypeLength));
            }

            StringBuilder urlTemp = null;

            if (urlLength > 0)
            {
                urlTemp = new StringBuilder(checked ((int)urlLength));
            }

            StringBuilder nameTemp = null;

            if (nameLength > 0)
            {
                nameTemp = new StringBuilder(checked ((int)nameLength));
            }

            StringBuilder publicKeyTemp = null;

            if (publicKeyLength > 0)
            {
                publicKeyTemp = new StringBuilder(checked ((int)publicKeyLength));
            }

            hr = SafeNativeMethods.DRMGetRevocationPoint(
                _issuanceLicenseHandle,
                ref idLength,
                idTemp,
                ref idTypeLength,
                idTypeTemp,
                ref urlLength,
                urlTemp,
                frequency,
                ref nameLength,
                nameTemp,
                ref publicKeyLength,
                publicKeyTemp);
            Errors.ThrowOnErrorCode(hr);

            RevocationPoint resultRevocationPoint = new RevocationPoint();

            resultRevocationPoint.Id        = (idTemp == null) ? null : idTemp.ToString();
            resultRevocationPoint.IdType    = (idTypeTemp == null) ? null : idTypeTemp.ToString();
            resultRevocationPoint.Url       = (urlTemp == null) ? null : new Uri(urlTemp.ToString());
            resultRevocationPoint.Name      = (nameTemp == null) ? null : nameTemp.ToString();
            resultRevocationPoint.PublicKey = (publicKeyTemp == null) ? null : publicKeyTemp.ToString();
            resultRevocationPoint.Frequency = frequency;

            return(resultRevocationPoint);
        }
Beispiel #5
0
        /// <summary>
        /// constructor that buils an issuance license from scratch
        /// </summary>
        private void Initialize(
            DateTime validFrom,
            DateTime validUntil,
            string referralInfoName,
            Uri referralInfoUri,
            ContentUser owner,
            string issuanceLicense,
            SafeRightsManagementHandle boundLicenseHandle,
            Guid contentId,
            ICollection <ContentGrant> grantCollection,
            IDictionary <int, LocalizedNameDescriptionPair> localizedNameDescriptionDictionary,
            IDictionary <string, string> applicationSpecificDataDictionary,
            int rightValidityIntervalDays,
            RevocationPoint revocationPoint)
        {
            // according to the unmanaged RM SDK spec only the following scenarios are supported:
            // 1. This can be called to create an issuance license from a template.
            //       issuanceLicense         An unsigned issuance license from
            //                                   a file or by passing an issuance license
            //                                   handle into DRMGetIssuanceLicenseTemplate
            //       boundLicenseHandle   NULL
            //
            // 2. This allows you to reuse rights information (the list follows this table).
            //       issuance license        A signed issuance license
            //       boundLicenseHandle   Handle to license bound by OWNER or VIEWRIGHTSDATA right
            //
            // 3. This creates an issuance license from scratch. It includes no users, rights, metadata, or policies.
            //       issuance license         NULL
            //       boundLicenseHandle   NULL

            Debug.Assert(!boundLicenseHandle.IsClosed); // it must be either present or not
            // closed handle is an indication of some internal error

            Invariant.Assert((boundLicenseHandle.IsInvalid) || (issuanceLicense != null));

            SystemTime validFromSysTime  = null;
            SystemTime validUntilSysTime = null;

            if ((validFrom != DateTime.MinValue) || (validUntil != DateTime.MaxValue))
            {
                // we need to use non null values if at least one of the time boundaries isn't default
                // DRM SDK will not enforce date time unless both timeFrom and timeUnti are set
                validFromSysTime  = new SystemTime((DateTime)validFrom);
                validUntilSysTime = new SystemTime((DateTime)validUntil);
            }

            string referralInfoUriStr = null;

            if (referralInfoUri != null)
            {
                referralInfoUriStr = referralInfoUri.ToString();
            }

            // input parameter must be initialized to the invalid handle
            // attempt to pass in a null throws an exception from the Safe
            // Handle Marshalling code
            SafeRightsManagementPubHandle ownerHandle;

            if (owner != null)
            {
                ownerHandle = GetHandleFromUser(owner);
            }
            else
            {
                ownerHandle = SafeRightsManagementPubHandle.InvalidHandle;
            }

            int hr;

            _issuanceLicenseHandle = null;

            hr = SafeNativeMethods.DRMCreateIssuanceLicense(
                validFromSysTime,
                validUntilSysTime,
                referralInfoName,
                referralInfoUriStr,
                ownerHandle,
                issuanceLicense,
                boundLicenseHandle,
                out _issuanceLicenseHandle);

            Errors.ThrowOnErrorCode(hr);
            Invariant.Assert((_issuanceLicenseHandle != null) &&
                             (!_issuanceLicenseHandle.IsInvalid));

            Debug.Assert(rightValidityIntervalDays >= 0); // our internal code makes the guarantee that is is not negative
            if (rightValidityIntervalDays > 0)
            {
                // If it is 0 we shouldn't override the value as it might be coming from a template
                SafeNativeMethods.DRMSetIntervalTime(_issuanceLicenseHandle, (uint)rightValidityIntervalDays);
            }

            if (grantCollection != null)
            {
                foreach (ContentGrant grant in grantCollection)
                {
                    AddGrant(grant);
                }
            }

            // Set localized name description info
            if (localizedNameDescriptionDictionary != null)
            {
                foreach (KeyValuePair <int, LocalizedNameDescriptionPair> nameDescriptionEntry in localizedNameDescriptionDictionary)
                {
                    AddNameDescription(nameDescriptionEntry.Key, nameDescriptionEntry.Value);
                }
            }

            // Set application specific data
            if (applicationSpecificDataDictionary != null)
            {
                foreach (KeyValuePair <string, string> applicationSpecificDataEntry in applicationSpecificDataDictionary)
                {
                    AddApplicationSpecificData(applicationSpecificDataEntry.Key, applicationSpecificDataEntry.Value);
                }
            }

            // set metafata as required
            if (contentId != null)
            {
                hr = SafeNativeMethods.DRMSetMetaData(
                    _issuanceLicenseHandle,
                    contentId.ToString("B"),
                    DefaultContentType,
                    null,
                    null,
                    null,
                    null);

                Errors.ThrowOnErrorCode(hr);
            }

            // set revocation point if required
            if (revocationPoint != null)
            {
                SetRevocationPoint(revocationPoint);
            }
        }
        private RevocationPoint GetRevocationPoint()
        {
            uint idLength = 0;
            uint idTypeLength = 0;
            uint urlLength = 0;
            uint nameLength = 0;
            uint publicKeyLength = 0;
            SystemTime frequency = new SystemTime(DateTime.Now);

            int hr = SafeNativeMethods.DRMGetRevocationPoint(
                                _issuanceLicenseHandle,
                                ref idLength,
                                null,
                                ref idTypeLength,
                                null,
                                ref urlLength,
                                null,
                                frequency,
                                ref nameLength,
                                null,
                                ref publicKeyLength,
                                null);
            if (hr == (int)RightsManagementFailureCode.RevocationInfoNotSet)
            {
                return null;
            }

            Errors.ThrowOnErrorCode(hr);

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

            StringBuilder idTypeTemp = null;
            if (idTypeLength > 0)
            {
                idTypeTemp = new StringBuilder(checked((int)idTypeLength));
            }

            StringBuilder urlTemp = null;
            if (urlLength > 0)
            {
                urlTemp = new StringBuilder(checked((int)urlLength));
            }

            StringBuilder nameTemp = null;
            if (nameLength > 0)
            {
                nameTemp = new StringBuilder(checked((int)nameLength));
            }

            StringBuilder publicKeyTemp = null;
            if (publicKeyLength > 0)
            {
                publicKeyTemp = new StringBuilder(checked((int)publicKeyLength));
            }

            hr = SafeNativeMethods.DRMGetRevocationPoint(
                                _issuanceLicenseHandle,
                                ref idLength,
                                idTemp,
                                ref idTypeLength,
                                idTypeTemp,
                                ref urlLength,
                                urlTemp,
                                frequency,
                                ref nameLength,
                                nameTemp,
                                ref publicKeyLength,
                                publicKeyTemp);
            Errors.ThrowOnErrorCode(hr);

            RevocationPoint resultRevocationPoint = new RevocationPoint();

            resultRevocationPoint.Id = (idTemp == null) ? null : idTemp.ToString();
            resultRevocationPoint.IdType = (idTypeTemp == null) ? null : idTypeTemp.ToString();
            resultRevocationPoint.Url = (urlTemp == null) ? null : new Uri(urlTemp.ToString());
            resultRevocationPoint.Name = (nameTemp == null) ? null : nameTemp.ToString();
            resultRevocationPoint.PublicKey = (publicKeyTemp == null) ? null : publicKeyTemp.ToString();
            resultRevocationPoint.Frequency = frequency;

            return resultRevocationPoint;
        }
        private void SetRevocationPoint(RevocationPoint revocationPoint)
        {
            int hr = SafeNativeMethods.DRMSetRevocationPoint(
                                _issuanceLicenseHandle,
                                false, // flagDelete,
                                revocationPoint.Id,
                                revocationPoint.IdType,
                                revocationPoint.Url.AbsoluteUri, // We are using Uri class as a basic validation mechanism. These URIs come from unmanaged 
                // code libraries and go back as parameters into the unmanaged code libraries. 
                // We use AbsoluteUri property as means of verifying that it is actually an absolute and 
                // well formed Uri. If by any chance it happened to be a relative URI, an exception will 
                // be thrown here. This will perform the necessary escaping.
                                revocationPoint.Frequency,
                                revocationPoint.Name,
                                revocationPoint.PublicKey);

            Errors.ThrowOnErrorCode(hr);
        }
        /// <summary>
        /// constructor that buils an issuance license from scratch
        /// </summary>
        private void Initialize(
                                        DateTime validFrom,
                                        DateTime validUntil,
                                        string referralInfoName,
                                        Uri referralInfoUri,
                                        ContentUser owner,
                                        string issuanceLicense,
                                        SafeRightsManagementHandle boundLicenseHandle,
                                        Guid contentId,
                                        ICollection<ContentGrant> grantCollection,
                                        IDictionary<int, LocalizedNameDescriptionPair> localizedNameDescriptionDictionary,
                                        IDictionary<string, string> applicationSpecificDataDictionary,
                                        int rightValidityIntervalDays,
                                        RevocationPoint revocationPoint)
        {
            // according to the unmanaged RM SDK spec only the following scenarios are supported:
            // 1. This can be called to create an issuance license from a template. 
            //       issuanceLicense         An unsigned issuance license from 
            //                                   a file or by passing an issuance license 
            //                                   handle into DRMGetIssuanceLicenseTemplate 
            //       boundLicenseHandle   NULL
            //
            // 2. This allows you to reuse rights information (the list follows this table).
            //       issuance license        A signed issuance license
            //       boundLicenseHandle   Handle to license bound by OWNER or VIEWRIGHTSDATA right
            //
            // 3. This creates an issuance license from scratch. It includes no users, rights, metadata, or policies.
            //       issuance license         NULL
            //       boundLicenseHandle   NULL

            Debug.Assert(!boundLicenseHandle.IsClosed); // it must be either present or not
            // closed handle is an indication of some internal error

            Invariant.Assert((boundLicenseHandle.IsInvalid) || (issuanceLicense != null));

            SystemTime validFromSysTime = null;
            SystemTime validUntilSysTime = null;

            if ((validFrom != DateTime.MinValue) || (validUntil != DateTime.MaxValue))
            {
                // we need to use non null values if at least one of the time boundaries isn't default
                // DRM SDK will not enforce date time unless both timeFrom and timeUnti are set 
                validFromSysTime = new SystemTime((DateTime)validFrom);
                validUntilSysTime = new SystemTime((DateTime)validUntil);
            }

            string referralInfoUriStr = null;
            if (referralInfoUri != null)
            {
                referralInfoUriStr = referralInfoUri.ToString();
            }

            // input parameter must be initialized to the invalid handle 
            // attempt to pass in a null throws an exception from the Safe 
            // Handle Marshalling code  
            SafeRightsManagementPubHandle ownerHandle;

            if (owner != null)
            {
                ownerHandle = GetHandleFromUser(owner);
            }
            else
            {
                ownerHandle = SafeRightsManagementPubHandle.InvalidHandle;
            }

            int hr;

            _issuanceLicenseHandle = null;

            hr = SafeNativeMethods.DRMCreateIssuanceLicense(
                validFromSysTime,
                validUntilSysTime,
                referralInfoName,
                referralInfoUriStr,
                ownerHandle,
                issuanceLicense,
                boundLicenseHandle,
                out _issuanceLicenseHandle);

            Errors.ThrowOnErrorCode(hr);
            Invariant.Assert((_issuanceLicenseHandle != null) &&
                                       (!_issuanceLicenseHandle.IsInvalid));

            Debug.Assert(rightValidityIntervalDays >= 0); // our internal code makes the guarantee that is is not negative
            if (rightValidityIntervalDays > 0)
            {
                // If it is 0 we shouldn't override the value as it might be coming from a template 
                SafeNativeMethods.DRMSetIntervalTime(_issuanceLicenseHandle, (uint)rightValidityIntervalDays);
            }

            if (grantCollection != null)
            {
                foreach (ContentGrant grant in grantCollection)
                {
                    AddGrant(grant);
                }
            }

            // Set localized name description info 
            if (localizedNameDescriptionDictionary != null)
            {
                foreach (KeyValuePair<int, LocalizedNameDescriptionPair> nameDescriptionEntry in localizedNameDescriptionDictionary)
                {
                    AddNameDescription(nameDescriptionEntry.Key, nameDescriptionEntry.Value);
                }
            }

            // Set application specific data 
            if (applicationSpecificDataDictionary != null)
            {
                foreach (KeyValuePair<string, string> applicationSpecificDataEntry in applicationSpecificDataDictionary)
                {
                    AddApplicationSpecificData(applicationSpecificDataEntry.Key, applicationSpecificDataEntry.Value);
                }
            }

            // set metafata as required 
            if (contentId != null)
            {
                hr = SafeNativeMethods.DRMSetMetaData(
                    _issuanceLicenseHandle,
                    contentId.ToString("B"),
                    DefaultContentType,
                    null,
                    null,
                    null,
                    null);

                Errors.ThrowOnErrorCode(hr);
            }

            // set revocation point if required 
            if (revocationPoint != null)
            {
                SetRevocationPoint(revocationPoint);
            }
        }