internal static extern int DRMGetUnboundLicenseAttribute( [In] SafeRightsManagementQueryHandle 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 int DRMGetUnboundLicenseObjectCount( SafeRightsManagementQueryHandle queryRootHandle, string subObjectType, out uint objectCount) { return(UnsafeNativeMethods.DRMGetUnboundLicenseObjectCount( queryRootHandle, subObjectType, out objectCount)); }
internal static int DRMGetUnboundLicenseObjectCount( SafeRightsManagementQueryHandle queryRootHandle, string subObjectType, out uint objectCount) { SecurityHelper.DemandRightsManagementPermission(); return(UnsafeNativeMethods.DRMGetUnboundLicenseObjectCount( queryRootHandle, subObjectType, out objectCount)); }
internal static int DRMGetUnboundLicenseAttribute( SafeRightsManagementQueryHandle queryRootHandle, string attributeType, uint index, out uint encodingType, ref uint bufferSize, byte[] buffer) { return(UnsafeNativeMethods.DRMGetUnboundLicenseAttribute( queryRootHandle, attributeType, index, out encodingType, ref bufferSize, buffer)); }
internal static int DRMParseUnboundLicense( string certificate, out SafeRightsManagementQueryHandle queryRootHandle) { int res = UnsafeNativeMethods.DRMParseUnboundLicense( certificate, out queryRootHandle); // 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 ((queryRootHandle != null) && queryRootHandle.IsInvalid) { queryRootHandle.Dispose(); queryRootHandle = null; } return(res); }
internal static int DRMGetUnboundLicenseObject( SafeRightsManagementQueryHandle queryRootHandle, string subObjectType, uint index, out SafeRightsManagementQueryHandle subQueryHandle) { int res = UnsafeNativeMethods.DRMGetUnboundLicenseObject( 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 extern int DRMGetUnboundLicenseObject( [In] SafeRightsManagementQueryHandle queryRootHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string subObjectType, [In, MarshalAs(UnmanagedType.U4)] uint index, [Out] out SafeRightsManagementQueryHandle subQueryHandle);
internal static extern int DRMParseUnboundLicense( [In, MarshalAs(UnmanagedType.LPWStr)] string certificate, [Out] out SafeRightsManagementQueryHandle queryRootHandle);
private static RightNameExpirationInfoPair GetRightInfoFromRightGroupQueryHandle (SafeRightsManagementQueryHandle rightGroupQueryHandle, uint rightIndex) { SafeRightsManagementQueryHandle rightQueryHandle = null; int hr = SafeNativeMethods.DRMGetUnboundLicenseObject( rightGroupQueryHandle, 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 return null; } 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 = GetUnboundLicenseStringAttribute( rightQueryHandle, NativeConstants.QUERY_NAME, 0); DateTime timeFrom = DateTime.MinValue; DateTime timeUntil = DateTime.MaxValue; SafeRightsManagementQueryHandle conditionListHandle = null; // we should also get the expiration infornmation out hr = SafeNativeMethods.DRMGetUnboundLicenseObject( rightQueryHandle, NativeConstants.QUERY_CONDITIONLIST, 0, out conditionListHandle); if (hr >= 0) { Debug.Assert((conditionListHandle != null) && (!conditionListHandle.IsInvalid)); using (conditionListHandle) { SafeRightsManagementQueryHandle rangeTimeQueryHandle = null; hr = SafeNativeMethods.DRMGetUnboundLicenseObject( conditionListHandle, 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 = GetUnboundLicenseDateTimeAttribute( rangeTimeQueryHandle, NativeConstants.QUERY_FROMTIME, 0, DateTime.MinValue); timeUntil = GetUnboundLicenseDateTimeAttribute( rangeTimeQueryHandle, NativeConstants.QUERY_UNTILTIME, 0, DateTime.MaxValue); } } } } return new RightNameExpirationInfoPair(rightName, timeFrom, timeUntil); } }
static private DateTime GetUnboundLicenseDateTimeAttribute( SafeRightsManagementQueryHandle queryHandle, string attributeType, uint attributeIndex, DateTime defaultValue) { uint attributeSize = SystemTime.Size; byte[] dataBuffer = new byte[attributeSize]; uint encodingType; int hr = SafeNativeMethods.DRMGetUnboundLicenseAttribute( 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); }
private static string GetUnboundLicenseStringAttribute( SafeRightsManagementQueryHandle queryHandle, string attributeType, uint attributeIndex) { uint attributeSize = 0; byte[] dataBuffer = null; uint encodingType; // get the attribute information (memory size to be allocated) int hr = SafeNativeMethods.DRMGetUnboundLicenseAttribute( queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, null); if (hr == (int)RightsManagementFailureCode.QueryReportsNoResults) { return null; } Errors.ThrowOnErrorCode(hr); // 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.DRMGetUnboundLicenseAttribute( 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 DRMGetUnboundLicenseAttribute( SafeRightsManagementQueryHandle queryRootHandle, string attributeType, uint index, out uint encodingType, ref uint bufferSize, byte[] buffer) { SecurityHelper.DemandRightsManagementPermission(); return UnsafeNativeMethods.DRMGetUnboundLicenseAttribute( queryRootHandle, attributeType, index, out encodingType, ref bufferSize, buffer); }
internal static int DRMGetUnboundLicenseObject( SafeRightsManagementQueryHandle queryRootHandle, string subObjectType, uint index, out SafeRightsManagementQueryHandle subQueryHandle) { SecurityHelper.DemandRightsManagementPermission(); int res = UnsafeNativeMethods.DRMGetUnboundLicenseObject( 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 DRMGetUnboundLicenseObjectCount( SafeRightsManagementQueryHandle queryRootHandle, string subObjectType, out uint objectCount) { SecurityHelper.DemandRightsManagementPermission(); return UnsafeNativeMethods.DRMGetUnboundLicenseObjectCount( queryRootHandle, subObjectType, out objectCount); }