WMRMLicenseRevocationChallenge.GetCustomData

banner art

Previous Next

WMRMLicenseRevocationChallenge.GetCustomData

The GetCustomData method retrieves custom data from the license revocation challenge.

Syntax

  String = WMRMLicenseRevocationChallenge
  .GetCustomData

Parameters

This method takes no parameters.

Return Values

If the method succeeds, it returns a base64-encoded String containing the custom data. If it fails, it returns a number in the error object.

Remarks

The custom data string must be decoded before it can be parsed. See the B64Decode function at the end of the following example code.

The client application might include additional information about the consumer, or include custom metadata that appears in licenses. For example, the client application might specify a user ID.

Example Code

'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' Declare variables.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
Dim LRChallengeObj       ' WMRMLicenseRevocationChallenge object
Dim LRResponseObj        ' WMRMLicenseRevocationResponse object

Dim LRChallString        ' License revocation challenge string
Dim ClientMachineID      ' Value that identifies the client computer
Dim CustomDataArray      ' Array to hold the custom data
Dim CustomDataItem       ' Counter
Dim UIDValue             ' User ID value
Dim KIDValue             ' Key ID value
Dim ChallTransID         ' Transaction ID in the challenge
Dim ClientPubkey         ' Public key of the client computer
Dim CustomDataString     ' Custom data included by the client plug-in
Dim KeyID                ' Key ID identifying the licenses to revoke
Dim LRPubkey             ' Public key for license revocation
Dim LRPrivkey            ' Private key for license revocation
Dim LRResponseString     ' License revocation response string

'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' Set variables.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
LRChallString = "<Replace this with a challenge string>"
LRPubkey = "<Replace this with the license revocation public key>"
LRPrivkey = "<Replace this with the license revocation private key>"


'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' Set the license revocation challenge into the WMRMLicenseRevocationChallenge object.
' Retrieve the client computer ID, public key, transaction ID, and custom data.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
Set LRChallengeObj = Server.CreateObject("WMRMObjs.WMRMLicenseRevocationChallenge")
Call LRChallengeObj.Initialize(LRChallString)
ClientMachineID = LRChallengeObj.GetMachineId
ChallTransID = LRChallengeObj.GetTransactionId
ClientPubkey = LRChallengeObj.GetMachinePublicKey

' B64Decode is a custom function (see below) to decode the base64-encoded string.
CustomDataString = B64Decode(LRChallengeObj.GetCustomData())

'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' Create the license revocation response. 
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
Set LRResponseObj = Server.CreateObject("WMRMObjs.WMRMLicenseRevocationResponse")

'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' Process your custom data and follow your business logic 
' to determine which licenses to delete. 
' In this sample, assume the custom data specified a user ID
' (UID) of 123 and a key ID (KID) of 456; the custom data string
' would be "UID=123;KID=456;"
' So, in this sample, if a user ID is present, set it into
' the CustomData property. 
' If a key ID is present, set it into the KeyId property. 
' If both values are specified, only licenses with both
' values will be revoked.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
CustomDataArray = Split(CustomDataString, ";")
For Each CustomDataItem in CustomDataArray
    If InStr(CustomDataItem, "UID=") > 0 then      ' Specify a user ID
        UIDValue = right(CustomDataItem, Len(CustomDataItem)-Len("UID:"))
        LRResponseObj.CustomData = UIDValue
    Elseif InStr(CustomDataItem, "KID=") > 0 then  ' Specify a key ID
        KIDValue = right(CustomDataItem, Len(CustomDataItem) - Len("KID:"))
        LRResponseObj.KeyId = KIDValue 
    End If
Next

'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' Specify the license revocation public key and the transaction ID.
' Generate the license revocation response.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
LRResponseObj.RevocationPublicKey = LRPubkey
LRResponseObj.TransactionId = ChallTransID    
LRResponseString = LRResponseObj.GenerateSignedResponse(LRPrivkey, ClientPubkey)

The following code shows an example of how to create a custom function to decode a base64-encoded string.

'"""""""""""""""""""""""""""""""""""""""""""""""""""""
' B64Decode function
'"""""""""""""""""""""""""""""""""""""""""""""""""""""
Const B64Standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Public Function B64Decode(szData)
    For i = 1 To Len(szData) Step 4
        nValue = 0
        For j = 0 To 3
            c = mid(szData, i+j, 1)
            If c = "=" then
                nValue = nValue \ 4
            Else
                index = InStr(B64Standard, c)-1
                nValue = nValue*64 + index
            End If
        Next
        szDecoded = ""
        While nValue > 0
            cc = Chr(CByte(nValue And 255))
            szDecoded = cc & szDecoded
            nValue = nValue \ 256
        Wend
        B64Decode = B64Decode & szDecoded
    Next
End Function

Requirements

Version: Windows Media Rights Manager 10 SDK or later

Reference: wmrmobjs 1.0 Type Library

Library: wmrmobjs.dll

Platform: Windows Server 2003

See Also

Previous Next

© 2007 Microsoft Corporation. All rights reserved.