Microsoft KB Archive/837235

= You receive the &quot;IssuanceLicenseIsNotWithinValidTimeRangeException&quot; error message while you run the Rmhstore sample program in Windows Rights Management Services Software Development Kit =

Article ID: 837235

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Windows Rights Management Services (RMS) for Windows Server 2003

-



SYMPTOMS
If you run the code for the Rmhdoc.cs file that is present in the Microsoft Windows Rights Management Services (RMS) Software Development Kit (SDK), you may receive the following error message:

IssuanceLicenseIsNotWithinValidTimeRangeException

Note You may receive this error message only for those countries that are ahead of Greenwich Mean Time (GMT). You may not experience any problem if you run the code for countries that are behind GMT.



CAUSE
The RMS SDK sample code does not convert the DateTime values that are used for VALIDITYTIME values to universal time. Therefore, the code returns the local time value.

This problem does not affect countries that are behind GMT. However, this problem may occur for those time zones that are ahead of GMT (such as the time zones for Hong Kong and Australia).



RESOLUTION
To resolve this problem, follow these steps:  Download the RMS SDK. To do so, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?FamilyId=3C918424-40E6-4CB9-BCBD-E89686F036A3&displaylang=en

 Save the RMS SDK in a local folder. To install the RMS SDK, open the folder that you saved the RMS SDK in, and then double-click the RMS_SDK_Setup.msi file. The Windows Rights Management Services SDK dialog box appears. Click Next. Accept the license agreement, and then click Next. Type the following path, and then click Next:

C: Program Files\Windows Rights Management Services SDK\

 Click Next to install the SDK. After the installation is completed, click Close to close the dialog box.</li> Locate the following folder, and then double-click the Rmhstore.sln solution file to open the file in Visual Studio .NET:

C:\Program Files\Windows Rights Management Services SDK\Samples\Source\Rmhstore

</li> In Solution Explorer, expand the Rmhstore node, and then double-click the Rmhdoc.cs file.</li>  Locate the following code: // Set the Validity time from yesterday. DateTime dtFrom = DateTime.Now - new TimeSpan(1,0,0);

// Set the To time one year from now. DateTime dtUntil = DateTime.Now + new TimeSpan(365,0,0); </li>  Replace the code that you located in the previous step with the following code: // Set the Validity time from yesterday. DateTime dtFrom = DateTime.Now.ToUniversalTime - new TimeSpan(1,0,0,0);

// Set the To time one year from now. DateTime dtUntil = DateTime.Now.ToUniversalTime + new TimeSpan(365,0,0,0); Following is the complete code for the corresponding function: private void GetUnsignedPublishingLicense(IRMSsrv rms, RmhStore rmhStore) {           Hashtable users = new Hashtable;

try {               Debug.WriteLine(&quot;+GetUnsignedPublishingLicense&quot;); DRMPUBHANDLE hIssuanceLicense = IntPtr.Zero; DRMPUBHANDLE hRight          = IntPtr.Zero; DRMPUBHANDLE hUser;

// Set the Validity time from yesterday. DateTime dtFrom = DateTime.Now.ToUniversalTime - new TimeSpan(1,0,0,0);

// Set the To time one year from now. DateTime dtUntil = DateTime.Now.ToUniversalTime + new TimeSpan(365,0,0,0);

// Marshal the From date time to the system time. SYSTEMTIME stFrom  = RmhHelper.MarshalDateTimeToSystemTime(dtFrom);

// Marshal the To date time to the system time. SYSTEMTIME stUntil = RmhHelper.MarshalDateTimeToSystemTime(dtUntil);

// Create the Issuance License. Nmc.Check(DRMCreateIssuanceLicense( ref stFrom, ref stUntil, null, null, 0,                   IntPtr.Zero, 0,                   out hIssuanceLicense));

// Get the store rights in the user right format arranged as right and user pair. StoreRights storeRights = rmhStore.StoreUserRights;

IDictionaryEnumerator userRights = (IDictionaryEnumerator)storeRights.GetEnumerator; while (userRights.MoveNext) {                   Right right = (Right)userRights.Value; // If there are no users for this right, skip to the next right. if (right == null ||                       (right.AllowedUsers.Count == 0 && right.DeniedUsers.Count == 0)) {                       continue; }

IDictionaryEnumerator rightUsers = right.AllowedUsers.GetEnumerator;

// For each rendering right, create add user. foreach (string xrmlRight in right.MappedXrMLRights) {                       // Create the RM right for the store right. Nmc.Check( DRMCreateRight( xrmlRight,                // Right Name ref stFrom,                // Validity Date From ref stUntil,               // Validity Date Until 0,                         // Extended Info IntPtr.Zero, IntPtr.Zero, out hRight));              // Handle to right

// For each user right in the store rights, create the user right and the associate right. while ( rightUsers.MoveNext ) {                           if (users[rightUsers.Key] == null) {                               hUser = new DRMPUBHANDLE;

// Create the User that corresponds to the user right. Nmc.Check( DRMCreateUser( (string)rightUsers.Value,  // User Name (string)rightUsers.Key,    // Users Sid &quot;Windows&quot;,                 // Windows identity out hUser));               // Handle to user

users.Add(rightUsers.Key, hUser);  // Save the created user }

// Add the right to the user. Nmc.Check( DRMAddRightWithUser( hIssuanceLicense,                      // Handle of issuance license hRight,                                // Handle of created right (DRMPUBHANDLE)users[rightUsers.Key] ) ); // Handle of right user }

// Free the Right handle here. Nmc.Check(DRMClosePubHandle(hRight));

// Reset the users list. rightUsers.Reset; }               }

// Set the metadata for the issuance license. Nmc.Check( DRMSetMetaData( hIssuanceLicense, Guid.NewGuid.ToString,         // Content ID                    &quot;MS-GUID&quot;,                      // Content ID Type Guid.NewGuid.ToString,         // SKU ID                    &quot;MS-GUID&quot;,                      // SKU ID Type &quot;ProtectedMHT&quot;, (string)this[&quot;RMHDOC_SKUID&quot;] ) );

// Set application-specific data such that documents are republishable. Nmc.Check( DRMSetApplicationSpecificData( hIssuanceLicense, false, &quot;Allow_Server_Editing&quot;, &quot;true&quot;)); // Create unsigned publishing license. byte[] bContentKey = (byte[])this[&quot;RMHDOC_CONTENTKEY&quot;]; uint keyLen       = (uint)bContentKey.Length; string keyType    = this[&quot;CONTENT_KEYTYPE&quot;].ToString;

// Get the licensor certificate from the server. Notice that applications can do               // fancy certificate caching of licensor certificates. string[] LicensorCertChain = rms.GetRMSLicensorCert;

// Create the client compatible chain. StringBuilder szChain     = CreateMsdrmCompatibleChain(LicensorCertChain); unsafe {                   // Pin the content key. fixed (byte* keyBuffer = bContentKey) {                       // Get the unsigned issuance license. To get the unsigned PL from the client // bits, treat the call as offline publishing, set the option as                        // DRM_SERVER_ISSUANCELICENSE, pass on the key buffer, the key length, the key type // Licensor certificate chain of the licensing server that // the document is going to be online published through. Nmc.Check(DRMGetSignedIssuanceLicense( IntPtr.Zero,                   // Set it to NULL if you do offline publishing. hIssuanceLicense,              // Specify the handle to the publishing license. DRM_SERVER_ISSUANCELICENSE,    // Specify that an unsigned issuance license is required. (IntPtr)keyBuffer,             // Content key. keyLen,                        // Content Key length. keyType,                       // Content Key type. szChain,                       // Licensor certificate chain, call creates issuedprincipal for the cert chain. new MsdrmCallback(RmOnStatus), // MSDRM callback. null,                                     // URL required for online publishing. hIssuanceLicense));            // Set the context to null. }               }            }            finally {               // Free the user handles. IDictionaryEnumerator ide = users.GetEnumerator; while (ide.MoveNext) {                   if (ide.Value != null) {                       Nmc.Check(DRMClosePubHandle((DRMPUBHANDLE)ide.Value)); }               }                Debug.WriteLine(&quot;-GetUnsignedPublishingLicense&quot;); }       } </li> In Solution Explorer, right-click the Rmhstore folder, and then click Build.</li> Locate the Rmhstore.dll file in the following folder:

C:\Program Files\Windows Rights Management Services SDK\Samples\Bin

</li> Replace the file that you located in the previous step with the new Rmhstore.dll file from the following location:

C:\Program Files\Windows Rights Management Services SDK\Samples\Source\Rmhstore\Rmhstore\Bin\Debug

</li> On the Build menu, click Build Solution.</li></ol>

<div class="moreinformation_section">

MORE INFORMATION
The DRMCreateIssuanceLicense function includes the following parameters:
 * pstTimeFrom: [in] - Starting validity time for the license
 * pstTimeUntil: [in] - Ending validity time for the license

For both these parameters, although the license validity times are entered in local time, the function converts the value to Universal Time in the license.

<div class="references_section">