internal static int DRMInitEnvironment( uint eSecurityProviderType, uint eSpecification, string securityProvider, string manifestCredentials, string machineCredentials, out SafeRightsManagementEnvironmentHandle environmentHandle, out SafeRightsManagementHandle defaultLibrary) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMInitEnvironment( eSecurityProviderType, eSpecification, securityProvider, manifestCredentials, machineCredentials, out environmentHandle, out defaultLibrary); // 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 ((environmentHandle != null) && environmentHandle.IsInvalid) { environmentHandle.Dispose(); environmentHandle = null; } if ((defaultLibrary != null) && defaultLibrary.IsInvalid) { defaultLibrary.Dispose(); defaultLibrary = null; } return(res); }
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 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 DRMCreateBoundLicense( SafeRightsManagementEnvironmentHandle environmentHandle, BoundLicenseParams boundLicenseParams, string licenseChain, out SafeRightsManagementHandle boundLicenseHandle, out uint errorLogHandle) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMCreateBoundLicense( environmentHandle, boundLicenseParams, licenseChain, out boundLicenseHandle, out errorLogHandle); // 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 ((boundLicenseHandle != null) && boundLicenseHandle.IsInvalid) { boundLicenseHandle.Dispose(); boundLicenseHandle = null; } return(res); }
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); }
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);
internal static int DRMCreateEnablingBitsEncryptor( SafeRightsManagementHandle boundLicenseHandle, string right, uint auxLibrary, string auxPlugin, out SafeRightsManagementHandle encryptorHandle) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMCreateEnablingBitsEncryptor( boundLicenseHandle, right, auxLibrary, auxPlugin, out encryptorHandle); // 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 ((encryptorHandle != null) && encryptorHandle.IsInvalid) { encryptorHandle.Dispose(); encryptorHandle = null; } return(res); }
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 static extern int DRMEncrypt( [In] SafeRightsManagementHandle cryptoProvHandle, [In, MarshalAs(UnmanagedType.U4)] uint position, [In, MarshalAs(UnmanagedType.U4)] uint inputByteCount, byte[] inputBuffer, [In, Out, MarshalAs(UnmanagedType.U4)] ref uint outputByteCount, byte[] outputBuffer);
internal static extern int DRMGetBoundLicenseAttribute( [In] SafeRightsManagementHandle queryRootHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string attributeType, [In, MarshalAs(UnmanagedType.U4)] uint index, [Out, MarshalAs(UnmanagedType.U4)] out uint encodingType, [In, Out, MarshalAs(UnmanagedType.U4)] ref uint bufferSize, byte[] buffer);
internal static extern int DRMInitEnvironment( [In, MarshalAs(UnmanagedType.U4)] uint eSecurityProviderType, [In, MarshalAs(UnmanagedType.U4)] uint eSpecification, [In, MarshalAs(UnmanagedType.LPWStr)] string securityProvider, [In, MarshalAs(UnmanagedType.LPWStr)] string manifestCredentials, [In, MarshalAs(UnmanagedType.LPWStr)] string machineCredentials, [Out] out SafeRightsManagementEnvironmentHandle environmentHandle, [Out] out SafeRightsManagementHandle defaultLibrary);
internal static extern int DRMCreateIssuanceLicense( [In, MarshalAs(UnmanagedType.LPStruct)] SystemTime timeFrom, [In, MarshalAs(UnmanagedType.LPStruct)] SystemTime timeUntil, [In, MarshalAs(UnmanagedType.LPWStr)] string referralInfoName, [In, MarshalAs(UnmanagedType.LPWStr)] string referralInfoUrl, [In] SafeRightsManagementPubHandle ownerUserHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string issuanceLicense, [In] SafeRightsManagementHandle boundLicenseHandle, [Out] out SafeRightsManagementPubHandle issuanceLicenseHandle);
internal static int DRMGetInfo( SafeRightsManagementHandle handle, string attributeType, out uint encodingType, ref uint outputByteCount, byte[] outputBuffer) { return(UnsafeNativeMethods.DRMGetInfo( handle, attributeType, out encodingType, ref outputByteCount, outputBuffer)); }
internal static int DRMEncrypt( SafeRightsManagementHandle cryptoProvHandle, uint position, uint inputByteCount, byte[] inputBuffer, ref uint outputByteCount, byte[] outputBuffer) { return(UnsafeNativeMethods.DRMEncrypt( cryptoProvHandle, position, inputByteCount, inputBuffer, ref outputByteCount, outputBuffer)); }
internal static int DRMGetBoundLicenseAttribute( SafeRightsManagementHandle queryRootHandle, string attributeType, uint index, out uint encodingType, ref uint bufferSize, byte[] buffer) { return(UnsafeNativeMethods.DRMGetBoundLicenseAttribute( queryRootHandle, attributeType, index, out encodingType, ref bufferSize, buffer)); }
internal static int DRMDecrypt( SafeRightsManagementHandle cryptoProvHandle, uint position, uint inputByteCount, byte[] inputBuffer, ref uint outputByteCount, byte[] outputBuffer) { SecurityHelper.DemandRightsManagementPermission(); return(UnsafeNativeMethods.DRMDecrypt( cryptoProvHandle, position, inputByteCount, inputBuffer, ref outputByteCount, outputBuffer)); }
internal static int DRMGetBoundLicenseObject( SafeRightsManagementHandle queryRootHandle, string subObjectType, uint index, out SafeRightsManagementHandle subQueryHandle) { int res = UnsafeNativeMethods.DRMGetBoundLicenseObject( queryRootHandle, subObjectType, index, out subQueryHandle); // 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 ((subQueryHandle != null) && subQueryHandle.IsInvalid) { subQueryHandle.Dispose(); subQueryHandle = null; } return(res); }
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 extern int DRMCreateBoundLicense( [In] SafeRightsManagementEnvironmentHandle environmentHandle, [In, MarshalAs(UnmanagedType.LPStruct)] BoundLicenseParams boundLicenseParams, [In, MarshalAs(UnmanagedType.LPWStr)] string licenseChain, [Out] out SafeRightsManagementHandle boundLicenseHandle, [Out, MarshalAs(UnmanagedType.U4)] out uint errorLogHandle);
internal static extern int DRMGetBoundLicenseObject( [In] SafeRightsManagementHandle queryRootHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string subObjectType, [In, MarshalAs(UnmanagedType.U4)] uint index, [Out] out SafeRightsManagementHandle subQueryHandle);
internal static int DRMGetBoundLicenseObject( SafeRightsManagementHandle queryRootHandle, string subObjectType, uint index, out SafeRightsManagementHandle subQueryHandle) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMGetBoundLicenseObject( queryRootHandle, subObjectType, index, out subQueryHandle); // 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 ((subQueryHandle != null) && subQueryHandle.IsInvalid) { subQueryHandle.Dispose(); subQueryHandle = null; } return res; }
// This method has only one caller GetGrantsFromBoundUseLicense(), which is // in the #if DEBUG static private string GetBoundLicenseStringAttribute( SafeRightsManagementHandle queryHandle, string attributeType, uint attributeIndex) { uint attributeSize = 0; byte[] dataBuffer = null; uint encodingType; int hr = SafeNativeMethods.DRMGetBoundLicenseAttribute( queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, null); Errors.ThrowOnErrorCode(hr); if (encodingType != (uint)LicenseAttributeEncoding.String) { throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense); } // this is the size of the null terminator so essentially this is an empty string if (attributeSize < 2) return null; checked { dataBuffer = new byte[(int)attributeSize]; } hr = SafeNativeMethods.DRMGetBoundLicenseAttribute( queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, dataBuffer); Errors.ThrowOnErrorCode(hr); // we need to truncate the last 2 bytes that have unicode 0 termination return Encoding.Unicode.GetString(dataBuffer, 0, dataBuffer.Length - 2); }
internal static int DRMGetBoundLicenseAttribute( SafeRightsManagementHandle queryRootHandle, string attributeType, uint index, out uint encodingType, ref uint bufferSize, byte[] buffer) { SecurityHelper.DemandRightsManagementPermission(); return UnsafeNativeMethods.DRMGetBoundLicenseAttribute( queryRootHandle, attributeType, index, out encodingType, ref bufferSize, buffer); }
internal static int DRMCreateBoundLicense( SafeRightsManagementEnvironmentHandle environmentHandle, BoundLicenseParams boundLicenseParams, string licenseChain, out SafeRightsManagementHandle boundLicenseHandle, out uint errorLogHandle) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMCreateBoundLicense( environmentHandle, boundLicenseParams, licenseChain, out boundLicenseHandle, out errorLogHandle); // 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 ((boundLicenseHandle != null) && boundLicenseHandle.IsInvalid) { boundLicenseHandle.Dispose(); boundLicenseHandle = null; } return res; }
internal static extern int DRMGetInfo( [In] SafeRightsManagementHandle handle, [In, MarshalAs(UnmanagedType.LPWStr)] string attributeType, [Out, MarshalAs(UnmanagedType.U4)] out uint encodingType, [In, Out, MarshalAs(UnmanagedType.U4)] ref uint outputByteCount, byte[] outputBuffer);
internal static int DRMEncrypt( SafeRightsManagementHandle cryptoProvHandle, uint position, uint inputByteCount, byte[] inputBuffer, ref uint outputByteCount, byte[] outputBuffer) { SecurityHelper.DemandRightsManagementPermission(); return UnsafeNativeMethods.DRMEncrypt( cryptoProvHandle, position, inputByteCount, inputBuffer, ref outputByteCount, outputBuffer); }
internal static int DRMCreateEnablingBitsEncryptor( SafeRightsManagementHandle boundLicenseHandle, string right, uint auxLibrary, string auxPlugin, out SafeRightsManagementHandle encryptorHandle) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMCreateEnablingBitsEncryptor( boundLicenseHandle, right, auxLibrary, auxPlugin, out encryptorHandle); // 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 ((encryptorHandle != null) && encryptorHandle.IsInvalid) { encryptorHandle.Dispose(); encryptorHandle = null; } return res; }
internal static int DRMGetInfo( SafeRightsManagementHandle handle, string attributeType, out uint encodingType, ref uint outputByteCount, byte[] outputBuffer) { SecurityHelper.DemandRightsManagementPermission(); return UnsafeNativeMethods.DRMGetInfo( handle, attributeType, out encodingType, ref outputByteCount, outputBuffer); }
/// <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); } }
/// <summary> /// This constructor accepts Signed XrML Publish License as a parameter. /// It decrypts and parses parses the XrRML document and initializes class based on that. /// </summary> internal UnsignedPublishLicense(SafeRightsManagementHandle boundLicenseHandle, string publishLicenseTemplate) :this () { Invariant.Assert(!boundLicenseHandle.IsInvalid); Invariant.Assert(publishLicenseTemplate != null); using(IssuanceLicense issuanceLicense = new IssuanceLicense( DateTime.MinValue, // validFrom, - default DateTime.MaxValue, // validUntil, - default null, // referralInfoName, null, // referralInfoUrl, null, // owner, publishLicenseTemplate, boundLicenseHandle, // boundLicenseHandle, _contentId, // contentId, null, // grantCollection null, // Localized Name Description pairs collection null, // Application Specific Data Dictionary 0, // validity interval days null)) // revocation point info { // update our instance data based on the parsed information issuanceLicense.UpdateUnsignedPublishLicense(this); } }
internal static extern int DRMCreateEnablingBitsEncryptor( [In] SafeRightsManagementHandle boundLicenseHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string right, [In, MarshalAs(UnmanagedType.U4)] uint auxLibrary, [In, MarshalAs(UnmanagedType.LPWStr)] string auxPlugin, [Out] out SafeRightsManagementHandle encryptorHandle);
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; }
internal static int DRMInitEnvironment( uint eSecurityProviderType, uint eSpecification, string securityProvider, string manifestCredentials, string machineCredentials, out SafeRightsManagementEnvironmentHandle environmentHandle, out SafeRightsManagementHandle defaultLibrary) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMInitEnvironment( eSecurityProviderType, eSpecification, securityProvider, manifestCredentials, machineCredentials, out environmentHandle, out defaultLibrary); // 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 ((environmentHandle != null) && environmentHandle.IsInvalid) { environmentHandle.Dispose(); environmentHandle = null; } if ((defaultLibrary != null) && defaultLibrary.IsInvalid) { defaultLibrary.Dispose(); defaultLibrary = null; } return res; }
/// <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); } }
// We currently don’t use these two methods, but they may be useful in the future. // So we keep them in the debug build only, and changed them from internal methods // to private methods to remove them from asmmeta files. #if DEBUG private static List<ContentGrant> GetGrantsFromBoundUseLicense( SafeRightsManagementHandle boundUseLicenseHandle, ContentUser user) { Invariant.Assert(!boundUseLicenseHandle.IsInvalid); List<ContentGrant> resultList = new List<ContentGrant>(10); // Go through each ContentRight within group item for (uint rightIndex = 0; ; rightIndex++) { // extract object information from each Work Item SafeRightsManagementHandle rightQueryHandle = null; int hr = SafeNativeMethods.DRMGetBoundLicenseObject( boundUseLicenseHandle, NativeConstants.QUERY_RIGHT, rightIndex, out rightQueryHandle); if ((hr == (int)RightsManagementFailureCode.NoMoreData) || (hr == (int)RightsManagementFailureCode.QueryReportsNoResults)) { // we got to the end of the RIGHT's list break; } Errors.ThrowOnErrorCode(hr); Debug.Assert((rightQueryHandle != null) && (!rightQueryHandle.IsInvalid)); using (rightQueryHandle) { // We got to the "right" object, now we can ask for the name string rightName = GetBoundLicenseStringAttribute(rightQueryHandle, NativeConstants.QUERY_NAME, 0); // if it is one of the erights that we "understand" we can proceed to query the time interval Nullable<ContentRight> right = GetRightFromString(rightName); if (right != null) { DateTime timeFrom = DateTime.MinValue; DateTime timeUntil = DateTime.MaxValue; SafeRightsManagementHandle rangeTimeQueryHandle = null; hr = SafeNativeMethods.DRMGetBoundLicenseObject( rightQueryHandle, NativeConstants.QUERY_RANGETIMECONDITION, 0, out rangeTimeQueryHandle); if ((hr != (int)RightsManagementFailureCode.NoMoreData) && (hr != (int)RightsManagementFailureCode.QueryReportsNoResults)) { Errors.ThrowOnErrorCode(hr); Debug.Assert((rangeTimeQueryHandle != null) && (!rangeTimeQueryHandle.IsInvalid)); using (rangeTimeQueryHandle) { timeFrom = GetBoundLicenseDateTimeAttribute( rangeTimeQueryHandle, NativeConstants.QUERY_FROMTIME, 0, DateTime.MinValue); timeUntil = GetBoundLicenseDateTimeAttribute( rangeTimeQueryHandle, NativeConstants.QUERY_UNTILTIME, 0, DateTime.MaxValue); } } resultList.Add(new ContentGrant(user, right.Value, timeFrom, timeUntil)); } } } return resultList; }
// This method has only one caller GetGrantsFromBoundUseLicense(), which is // in the #if DEBUG static private DateTime GetBoundLicenseDateTimeAttribute( SafeRightsManagementHandle queryHandle, string attributeType, uint attributeIndex, DateTime defaultValue) { uint attributeSize = SystemTime.Size; byte[] dataBuffer = new byte[attributeSize]; uint encodingType; int hr = SafeNativeMethods.DRMGetBoundLicenseAttribute( queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, dataBuffer); if (encodingType != (uint)LicenseAttributeEncoding.Time) { throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense); } if ((hr == (int)RightsManagementFailureCode.NoMoreData) || (hr == (int)RightsManagementFailureCode.QueryReportsNoResults)) { return defaultValue; } Errors.ThrowOnErrorCode(hr); Debug.Assert(attributeSize == SystemTime.Size); // if isn't true it is an indication of a problem in the underlying libraries SystemTime sysTime = new SystemTime(dataBuffer); return sysTime.GetDateTime(defaultValue); }