You receive the "IssuanceLicenseIsNotWithinValidTimeRangeException" error message while you run the Rmhstore sample program in Windows Rights Management Services Software Development Kit (837235)



The information in this article 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:
  1. Download the RMS SDK. To do so, visit the following Microsoft Web site:
  2. Save the RMS SDK in a local folder.
  3. 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.
  4. Click Next. Accept the license agreement, and then click Next.
  5. Type the following path, and then click Next:

    C: Program Files\Windows Rights Management Services SDK\

  6. Click Next to install the SDK.
  7. After the installation is completed, click Close to close the dialog box.
  8. 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

  9. In Solution Explorer, expand the Rmhstore node, and then double-click the Rmhdoc.cs file.
  10. 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);
    
  11. 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("+GetUnsignedPublishingLicense");
                    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 
                                        "Windows",                  // 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
                        "MS-GUID",                      // Content ID Type
                        Guid.NewGuid().ToString(),          // SKU ID
                        "MS-GUID",                      // SKU ID Type
                        "ProtectedMHT", 
                        (string)this["RMHDOC_SKUID"] ) ); 
    
                    // Set application-specific data such that documents are republishable.
                    Nmc.Check( DRMSetApplicationSpecificData(
                        hIssuanceLicense,
                        false,
                        "Allow_Server_Editing",
                        "true"));
    			
                    // Create unsigned publishing license.
                    byte[] bContentKey = (byte[])this["RMHDOC_CONTENTKEY"];
                    uint keyLen        = (uint)bContentKey.Length;
                    string keyType     = this["CONTENT_KEYTYPE"].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("-GetUnsignedPublishingLicense");
                }
            }
  12. In Solution Explorer, right-click the Rmhstore folder, and then click Build.
  13. Locate the Rmhstore.dll file in the following folder:

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

  14. 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

  15. On the Build menu, click Build Solution.

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.

REFERENCES

For more information about the DRMCreateIssuanceLicense function, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:4/9/2004
Keywords:kbSDK kbLicensing kbprb KB837235 kbAudDeveloper