[ActiveLock-Development] CVS: activelock/src ActiveLock.cls,1.4,1.5 ActiveLock2.vbp,1.3,1.4 ActiveLo
Brought to you by:
ialkan
From: Thanh H. T. <th...@us...> - 2003-10-13 04:49:09
|
Update of /cvsroot/activelock/activelock/src In directory sc8-pr-cvs1:/tmp/cvs-serv27199 Modified Files: ActiveLock.cls ActiveLock2.vbp ActiveLockEventNotifier.cls Globals.cls IActiveLock.cls ProductLicense.cls Log Message: Batch commit for 2.0.3 build. - Mainly vbdox changes. - ActiveLockEventNotifier's ValidateValue() event signature changed. Binary compatibility had to be broken. Index: ActiveLock.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/ActiveLock.cls,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ActiveLock.cls 6 Oct 2003 05:09:29 -0000 1.4 +++ ActiveLock.cls 13 Oct 2003 04:49:03 -0000 1.5 @@ -80,6 +80,8 @@ ' instead of the working directory. Otherwise, users will have to put alcrypto.dll in ' each of their apps' working directory, which is OK if they only have 1 app, ' but not so OK when multiple apps are involved. +' 10.13.03 - th2tran - Fixed bug: If ValidateValue event was not handled by the client, then we ended up +' hashing an empty string. ' </pre> ' /////////////////////////////////////////////////////////////////////// @@ -185,7 +187,7 @@ ' Print out some info for debugging purposes Debug.Print "Code1: " & strPubKey Debug.Print "Lic: " & strLic -Debug.Print "Lic hash: " & MyGlobals.MD5Hash(strLic) +Debug.Print "Lic hash: " & modMD5.Hash(strLic) Debug.Print "LicKey: " & strLicKey Debug.Print "Sig: " & strSig Debug.Print "Verify: " & MyGlobals.RSAVerify(strPubKey, strLic, strSig) @@ -220,8 +222,9 @@ ValidateKey Lic Dim strEncrypted As String, strHash As String ' Validate last run date - MyNotifier.Notify "ValidateValue", Lic.LastUsed, strEncrypted - strHash = MyGlobals.MD5Hash(strEncrypted) + strEncrypted = Lic.LastUsed + MyNotifier.Notify "ValidateValue", strEncrypted + strHash = modMD5.Hash(strEncrypted) If strHash <> Lic.Hash1 Then Err.Raise ActiveLockErrCodeConstants.alerrLicenseTampered, "ActiveLock2", "License may have been tampered." End If @@ -243,8 +246,8 @@ Dim strLastUsed As String strLastUsed = Format(Now(), "YYYY/MM/DD HH:MM:SS") Lic.LastUsed = strLastUsed - MyNotifier.Notify "ValidateValue", strLastUsed, strEncrypted - Lic.Hash1 = MyGlobals.MD5Hash(strEncrypted) + MyNotifier.Notify "ValidateValue", strLastUsed + Lic.Hash1 = modMD5.Hash(strLastUsed) End Sub Private Property Get IActiveLock_ExpirationDate() As String @@ -311,12 +314,6 @@ If mKeyStore Is Nothing Then Err.Raise ActiveLockErrCodeConstants.alerrKeyStoreInvalid, "IActiveLock_Register", "Key Store Provider hasn't been initialized yet." End If -' ' obtain encrypted value for the RegisteredDate -' Lic.RegisteredDate = Format(Now(), "yyyy/mm/dd") -' Dim strEncrypted As String -' MyNotifier.Notify "ValidateValue", Lic.RegisteredDate, strEncrypted -' ' hash it -' Lic.Hash1 = modMD5.Hash(strEncrypted) ' Update last used date UpdateLastUsed Lic Index: ActiveLock2.vbp =================================================================== RCS file: /cvsroot/activelock/activelock/src/ActiveLock2.vbp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ActiveLock2.vbp 5 Oct 2003 08:44:19 -0000 1.3 +++ ActiveLock2.vbp 13 Oct 2003 04:49:03 -0000 1.4 @@ -1,6 +1,6 @@ Type=OleDll Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation -Reference=*\G{9AC9BB25-D182-447E-8398-D8A8F40DE906}#1.0#0#..\bin\alutil.dll#ActiveLockUtil +Reference=*\G{9AC9BB25-D182-447E-8398-D8A8F40DE906}#1.0#0#..\..\alutil\alutil.dll#ActiveLockUtil Class=ActiveLock; ActiveLock.cls Class=IActiveLock; IActiveLock.cls Class=Globals; Globals.cls @@ -31,7 +31,7 @@ VersionCompatible32="1" MajorVer=2 MinorVer=0 -RevisionVer=2 +RevisionVer=3 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="The ActiveLock Software Group" Index: ActiveLockEventNotifier.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/ActiveLockEventNotifier.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ActiveLockEventNotifier.cls 7 Aug 2003 17:30:59 -0000 1.1 +++ ActiveLockEventNotifier.cls 13 Oct 2003 04:49:03 -0000 1.2 @@ -44,7 +44,7 @@ '' ' This class handles ActiveLock COM event notifications to the interested observers. -' It is simply a wrapper containing pubic events. These events should +' It is simply a wrapper containing public events. These events should ' really belong in IActiveLock, but since VB doesn't support inheritance ' of events, we have to do it this way. ' @@ -65,6 +65,8 @@ ' <pre> ' 07.20.03 - th2tran - Created ' 08.03.03 - th2tran - VBDox'ed this interface. +' 10.13.03 - th2tran - ValidateValue() event signature changed from 2 parameters +' to 1 parameter, for simplicity. ' </pre> ' /////////////////////////////////////////////////////////////////////// @@ -74,19 +76,27 @@ Option Explicit '' -' ProductLicense Property Value validation event allows the client application -' to return the encrypted version of a license property value. +' (Optional) Product License Property Value validation event allows the client application +' to return the encrypted version of a license property value (such as LastRunDate). +' <p>An example, of when <code>ValidateValue</code> event would be used, +' can be observed for the <code>LastRunDate</code> property. +' For readability, this property is saved in the KeyStore in plain-text format. However, to prevent hackers from +' changing this value, an accompanying Hash Code for this value, <code>Hash1</code>, is also stored. This Hash Code +' is an MD5 hash of the (possibly) encrypted value of <code>LastRunDate</code>. The encrypted value is +' is user application specific, and is obtained from the user application via the <code>ValidateValue</code> event. ' The client will receive this event, encrypt <code>Value</code> using its own encryption algorithm, -' and store the result in <code>Result</code> to be returned to ActiveLock. +' and store the result back in <code>Value</code> to be returned to ActiveLock. +' <p>Handling of this event is OPTIONAL. If not handled, it simply means there will be no encryption for +' the stored property values. +' ' @param Value Property value. -' @param Result Encrypted value. -Public Event ValidateValue(ByVal Value As String, Result As String) +Public Event ValidateValue(ByRef Value As String) Friend Sub Notify(EventName As String, ParamArray Args()) If EventName = "ValidateValue" Then Dim Result As String - Result = Args(1) - RaiseEvent ValidateValue(CStr(Args(0)), Result) - Args(1) = Result ' assign value back to the result + Result = Args(0) + RaiseEvent ValidateValue(Result) + Args(0) = Result ' assign value back to the result End If End Sub Index: Globals.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/Globals.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Globals.cls 7 Aug 2003 17:30:59 -0000 1.1 +++ Globals.cls 13 Oct 2003 04:49:03 -0000 1.2 @@ -43,10 +43,10 @@ '* '' -' This class contains global object factory and utility methods. +' This class contains global object factory and utility methods and constants. ' It is a global class so its routines in here can be accessed directly ' from the ActiveLock2 namespace. -' For example, the <code>NewInstance()</code> routine can be access via +' For example, the <code>NewInstance()</code> function can be access via ' <code>ActiveLock2.NewInstance()</code>. ' ' @author th...@us... @@ -56,7 +56,7 @@ '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// -' @todo GetLicTypeString() - Implement this fully. +' @todo GetLicTypeString(). Currently only supports "Single". Need to implement the rest. ' ' /////////////////////////////////////////////////////////////////////// @@ -72,6 +72,8 @@ ' - CreateProductLicense() to ignore Expiration date ' for Permanent license type ' 08.03.03 - th2tran - VBDox'ed this class. +' 10.13.03 - th2tran - Corrections to ActiveLockErrCodeConstants vbdox errors. +' - Added VB descriptions for VB Object Browser's sake. ' </pre> ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / @@ -79,20 +81,21 @@ Option Explicit '' -' ActiveLock Error Codes +' ActiveLock Error Codes. +' These error codes are used for <code>Err.Number</code> whenever ActiveLock raises an error. ' ' @param alerrOK No error. Operation was successful. ' @param alerrNoLicense No license available. ' @param alerrLicenseInvalid License is invalid. ' @param alerrLicenseExpired License has expired. ' @param alerrLicenseTampered License has been tampered. -' @param alerrClockChanged System as been set back. +' @param alerrClockChanged System clock has been set back. ' @param alerrKeyStoreInvalid Key Store Provider has not been initialized yet. -' @param alerrFileTampered License file has been tampered. +' @param alerrFileTampered ActiveLock DLL file has been tampered. ' @param alerrNotInitialized ActiveLock has not been initialized yet. Public Enum ActiveLockErrCodeConstants alerrOK = 0 ' successful - alerrNoLicense = &H80040001 ' vbObjectError (&H80040000) + 1 + alerrNoLicense = &H80040001 ' vbObjectError (&H80040000) + 1 alerrLicenseInvalid = &H80040002 alerrLicenseExpired = &H80040003 alerrLicenseTampered = &H80040004 @@ -103,10 +106,12 @@ End Enum '' -' Returns a new instance of an object that implements IActiveLock interface. +' Obtains a new instance of an object that implements IActiveLock interface. ' @param Args Optional list of parameters. +' @return ActiveLock interface. ' Public Function NewInstance(Optional Args As Variant) As IActiveLock 'TODO: Add parameters as appropriate +Attribute NewInstance.VB_Description = "Returns a new instance of an object that implements IActiveLock interface." Dim NewInst As IActiveLock Set NewInst = New ActiveLock With NewInst @@ -117,8 +122,8 @@ End Function '' -' Instantiates a new ProductLicense object. -' If LicType is "Permanent", then Expiration date parameter will be ignored. +' Instantiates a new ProductLicense object from the specified parameters. +' <p>If <code>LicType</code> is <i>Permanent</i>, then <code>Expiration</code> date parameter will be ignored. ' ' @param Name Product/Software Name ' @param Code Product/Software Code @@ -131,17 +136,19 @@ ' @param RegisteredDate Date on which the product is registered ' @param Hash1 Hash-1 code ' -Public Function CreateProductLicense(name As String, _ - Code As String, _ - Ver As String, _ - LicClass As ActiveLock2.ALLockTypes, _ - LicType As ActiveLock2.ALLicType, _ - Licensee As String, _ - Expiration As String, _ - Optional LicKey As String, _ - Optional RegisteredDate As String, _ - Optional Hash1 As String _ +' @return License object. +Public Function CreateProductLicense(ByVal name As String, _ + ByVal Code As String, _ + ByVal Ver As String, _ + ByVal LicClass As ActiveLock2.ALLockTypes, _ + ByVal LicType As ActiveLock2.ALLicType, _ + ByVal Licensee As String, _ + ByVal Expiration As String, _ + Optional ByVal LicKey As String, _ + Optional ByVal RegisteredDate As String, _ + Optional ByVal Hash1 As String _ ) As ProductLicense +Attribute CreateProductLicense.VB_Description = "Creates a new ProductLicense object." Dim NewLic As New ProductLicense With NewLic .ProductName = name @@ -194,44 +201,52 @@ End Function '' -' Trim Null characters from the string. +' Removes Null characters from the string. ' @param str String to be trimmed. -' -Public Function TrimNulls(str As String) As String +' @return Trimmed string. +Public Function TrimNulls(ByVal str As String) As String +Attribute TrimNulls.VB_Description = "Trim Null characters from the string." TrimNulls = modActiveLock.TrimNulls(str) End Function '' ' Computes an MD5 hash of the specified string. ' @param str String to be hashed. +' @return Computed hash code. ' -Public Function MD5Hash(str As String) As String +Public Function MD5Hash(ByVal str As String) As String +Attribute MD5Hash.VB_Description = "Computes an MD5 hash of the specified string." MD5Hash = modMD5.Hash(str) End Function '' -' Base-64 encode the specified string. +' Encodes a string using base64 encoding. ' @param str String to be encoded +' @return Encoded string. ' -Public Function Base64Encode(str As String) As String +Public Function Base64Encode(ByVal str As String) As String +Attribute Base64Encode.VB_Description = "Performs Base-64 encoding of the specified string." Base64Encode = modBase64.Base64_Encode(str) End Function '' -' Base-64 decode the string. +' Decodes a base64-encoded string. ' @param strEncoded String to be decoded +' @return Decoded string. ' -Public Function Base64Decode(strEncoded As String) As String +Public Function Base64Decode(ByVal strEncoded As String) As String +Attribute Base64Decode.VB_Description = "Performs Base-64 decoding of the specified string." Base64Decode = modBase64.Base64_Decode(strEncoded) End Function '' -' Performs RSA signing of strData using the specified key. -' @param strPub Public key blob -' @param strPriv Private key blob +' Performs RSA signing of <code>strData</code> using the specified key. +' @param strPub RSA Public key blob +' @param strPriv RSA Private key blob ' @param strData Data to be signed -' @return Signature string. +' @return Signature string. ' -Public Function RSASign(strPub As String, strPriv As String, strdata As String) As String +Public Function RSASign(ByVal strPub As String, ByVal strPriv As String, ByVal strdata As String) As String +Attribute RSASign.VB_Description = "Performs RSA signing of strData using the specified key." Dim Key As RSAKey ' create the key from the key blobs modActiveLock.rsa_createkey strPub, Len(strPub), strPriv, Len(strPriv), Key @@ -247,12 +262,13 @@ '' ' Verifies an RSA signature. -' @param strPub Public key blob +' @param strPub Public key blob ' @param strData Data to be signed -' @param strSig Private key blob -' @return Zero if verification is successful; Non-zero otherwise. +' @param strSig Private key blob +' @return Zero if verification is successful; Non-zero otherwise. ' Public Function RSAVerify(strPub As String, strdata As String, strSig As String) As Long +Attribute RSAVerify.VB_Description = "Verifies an RSA signature." Dim Key As RSAKey Dim rc& ' create the key from the public key blob Index: IActiveLock.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/IActiveLock.cls,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IActiveLock.cls 22 Sep 2003 02:11:21 -0000 1.2 +++ IActiveLock.cls 13 Oct 2003 04:49:03 -0000 1.3 @@ -43,36 +43,44 @@ '* '' -' This is the main interface into ActiveLock. -' The user program interacts with ActiveLock via this IActiveLock interface. -' Typically, the user program would obtain an instance of this interface via the -' <code>ActiveLock2.NewInstance()</code> accessor method. From there, initialization calls are taken -' place, and then various method such as <code>Register()</code>, <code>Acquire()</code>, etc..., can be used. -' ActiveLock also sends event notifications to to the user program whenever it needs the -' user program's help to perform some action, such as parameter validation. These events -' are sent via the ActiveLockEventNotifier object, which can be obtained from IActiveLock_Notifier() -' accessor method. +' This is the main interface into ActiveLock's functionalities. +' The user application interacts with ActiveLock primarily through this IActiveLock interface. +' Typically, the application would obtain an instance of this interface via the +' <a href="Globals.NewInstance.html">ActiveLock2.NewInstance()</a> accessor method. From there, initialization calls are done, +' and then various method such as <a href="IActiveLock.Register.html">Register()</a>, <a href="IActiveLock.Acquire.html">Acquire()</a>, etc..., can be used. +' <p> +' ActiveLock also sends COM event notifications to the user application whenever it needs help to perform +' some action, such as license property validation/encryption. The user application can intercept +' these events via the ActiveLockEventNotifier object, which can be obtained from +' <a href="IActiveLock.Get.EventNotifier.html">IActiveLock.EventNotifier</a> property. +' <p> +' <b>Important Note</b><br> +' The user application is strongly advised to perform a checksum on the +' ActiveLock DLL prior to accessing and interacting with ActiveLock. Using the checksum, you can tell if +' the DLL has been tampered. Please refer to sample code below on how the checksumming can be done. +' <p> +' The sample code fragments below illustrate the typical usage flow between your application and ActiveLock. +' Please note that the code shown is only for illustration purposes and is not meant to be a complete +' compilable program. You may have to add variable declarations and function definitions around the code +' fragments before you can compile it. ' <p> -' <b>Important!</b> It is also strongly recommended that a checksum on ActiveLock2.dll be performed -' prior to accessing and interacting with ActiveLock. See sample code below on how it is done. -' <p> The sample code fragments below illustrate of how this interface is used. Please note that the code shown is -' only for illustration purposes and is not meant to be a complete compilable program. You may have to add -' variable declarations and function definitions around the code fragments before you can compile it. ' <pre> ' Form1.frm: ' ... ' Private MyActiveLock As ActiveLock2.IActiveLock ' Private WithEvents ActiveLockEventSink As ActiveLockEventNotifier -' Private Const AL_CRC& = 308603 ' ActiveLock2.dll's CRC checksum to be used for validation -'<br> -' '' This RSA private key will be used for data encryption and/or license key signing. -' Private Const PRIV_KEY$ = "AAAAgEPRFzhQEF7S91vt2K6kOcEdDDe5BfwNiEL30/+ozTFHc7cZctB8NIlS++ZR//D3AjSMqScjh7xUF/gwvUgGCjiExjj1DF/XWFWnPOCfF8UxYAizCLZ9fdqxb1FRpI5NoW0xxUmvxGjmxKwazIW4P4XVi/+i1Bvh2qQ6ri3whcsNAAAAQQCyWGsbJKO28H2QLYH+enb7ehzwBThqfAeke/Gv1Te95yIAWme71I9aCTTlLsmtIYSk9rNrp3sh9ItD2Re67SE7AAAAQQCAookH1nws1gS2XP9cZTPaZEmFLwuxlSVsLQ5RWmd9cuxpgw5y2gIskbL4c+4oBuj0IDwKtnMrZq7UfV9I5VfVAAAAQQCEnyAuO0ahXH3KhAboop9+tCmRzZInTrDYdMy23xf3PLCLd777dL/Y2Y+zmaH1VO03m6iOog7WLiN4dCL7m+Im" -' '' This RSA public key will be used as the product's software code. -' Private Const PUB_KEY$ = "AAAAB3NzaC1yc2EAAAABJQAAAIBZnXD4IKfrBH25ekwLWQMs5mJuNH7D7U99EKFIsVhKQv17GHxKWvxHv/FwWhI1Rmd8TCiqk4Wmk7H1rh6xdbIVBwDj+RSeiXs8mmQX4/XvaWZx9BIQr5wODWnQCH/tj6Y6In2Xjc2J3B7LSjD60cWDBY/u+z9cSheTHLyhb16zFw==" -'<br> -' ... +' Private Const AL_CRC& = 123+ ' ActiveLock2.dll's CRC checksum to be used for validation +' +' ' This key will be used to set <a href="IActiveLock.Let.SoftwareCode.html">IActiveLock.SoftwareCode</a> property. +' ' NOTE: This is NOT a complete key (complete key is to long to put in documentation). +' ' You will generate your own product code using ALUGEN. This is the <code>VCode</code> generated +' by ALUGEN. +' Private Const PROD_CODE$ = "AAAAB3NzaC1yc2EAAAABJQAAAIBZnXD4IKfrBH25ekwLWQMs5mJ..." +' +' .... +' ' Private Sub Form_Load() -' On Error GoTo Hell +' On Error GoTo ErrHandler ' ' Obtain an instance of AL ' Set MyActiveLock = ActiveLock2.NewInstance() ' ' Verify AL's authenticity @@ -81,91 +89,98 @@ ' ' So can't use MyActiveLock object to authenticate since it is not a public creatable object. ' ' So we'll use ActiveLock2.Globals, which is just as good because they are in the same DLL. ' Dim crc As Long -' crc = modActiveLock.CRCCheckSumTypeLib(New ActiveLock2.Globals) +' crc = CRCCheckSumTypeLib(New ActiveLock2.Globals) ' See below for CRCCheckSumTypeLib() implementation ' Debug.Print "Hash: " & crc ' If crc <> AL_CRC Then -' MsgBox "ActiveLock2.dll has been corrupted. If you were running a real application, it should terminate at this point." +' MsgBox "ActiveLock2.dll has been corrupted." +' End ' terminate ' End If -'<br> +' ' ' Initialize the keystore. We use a File keystore in this case. ' MyActiveLock.KeyStoreType = alsFile -' MyActiveLock.KeyStorePath = App.path & "\al.lic" -'<br> +' MyActiveLock.KeyStorePath = App.path & "\myapp.lic" +' ' ' Obtain the EventNotifier so that we can receive notifications from AL. ' Set ActiveLockEventSink = MyActiveLock.EventNotifier -'<br> +' ' ' Specify the name of the product that will be locked through AL. ' MyActiveLock.SoftwareName = "MyApp" -'<br> -' ' Specify our product code. This is a RSA public key, which will be used later by ActiveLock to validate license signatures -' MyActiveLock.SoftwareCode = "AAAAB3NzaC1yc2EAAAABJQAAAIBZnXD4IKfrBH25ekwLWQMs5mJuNH7D7U99EKFIsVhKQv17GHxKWvxHv/FwWhI1Rmd8TCiqk4Wmk7H1rh6xdbIVBwDj+RSeiXs8mmQX4/XvaWZx9BIQr5wODWnQCH/tj6Y6In2Xjc2J3B7LSjD60cWDBY/u+z9cSheTHLyhb16zFw==" -'<br> +' +' ' Specify our product code. This code will be used later by ActiveLock to validate license keys. +' MyActiveLock.SoftwareCode = PROD_CODE +' ' ' Specify product version ' MyActiveLock.SoftwareVersion = txtVersion -'<br> +' ' ' Specify License Type ' MyActiveLock.LicenseType = allicTimeLocked -'<br> +' ' ' Specify Lock Type ' MyActiveLock.LockType = lockHD -'<br> +' ' ' Now initialize AL ' MyActiveLock.Init -'<br> +' ' ' At this point, either AL has been initialized or an error would have already been raised -' ' if there were problems (such as the DLL has been tampered). -'<br> +' ' if there were problems (such as activelock2.dll having been tampered). +' ' ' Check registration status by calling Acquire() ' ' Note: Calling Acquire() may trigger ActiveLockEventNotifier_ValidateValue() event. -' ' So we must be prepared to handle that. +' ' So we should be prepared to handle that. ' MyActiveLock.Acquire -'<br> -' ' By now, if the product is not registered, then an error whould have been raised, +' +' ' By now, if the product is not registered, then an error would have been raised, ' ' which means if we get to here, then we're registered. -'<br> +' ' ' Just for fun, print out some registration status info ' Debug.Print "Used Days: " & MyActiveLock.UsedDays ' Debug.Print "Expiration Date: " & MyActiveLock.ExpirationDate ' Exit Sub -' Hell: +' ErrHandler: ' MsgBox Err.Number & ": " & Err.Description ' ' End program ' End ' End Sub ' ... -' ... -' ' -' ' ActiveLock raises this event typically when it needs a value to be encrypted. -' ' We can use any kind of encryption we'd like here, as long as it's deterministic. -' ' i.e. there's a one-to-one correspondence between unencrypted value and encrypted value. -' ' NOTE: BlowFish is NOT an example of deterministic encryption so you can't use it here. +' <p> +' (Optional) ActiveLock raises this event typically when it needs a value to be encrypted. +' We can use any kind of encryption we'd like here, as long as it's deterministic. +' i.e. there's a one-to-one correspondence between unencrypted value and encrypted value. +' NOTE: BlowFish is NOT an example of deterministic encryption so you can't use it here. +' You are allowed to use asymmetric algorithm since you will never be asked to decrypt a value, +' only to encrypt. +' You don't have to handle this event if you don't want to; it just means that the value WILL NOT +' be encrypted when it is saved to the keystore. +' ' Private Sub ActiveLockEventSink_ValidateValue(ByVal Value As String, Result As String) ' Result = Encrypt(Value) ' End Sub '<br> -' ' Encrypts a string. +' ' Roll our own simple-yet-weird encryption routine. +' ' Must keep in mind that our encryption algorithm must be deterministic. +' ' In other words, given the same uncrypted string, it must always yield the same encrypted string. ' Private Function Encrypt(strData As String) As String -' Dim Key As RSAKey -' ' create the key from the key blobs -' modActiveLock.rsa_createkey PUB_KEY, Len(PUB_KEY), PRIV_KEY, Len(PRIV_KEY), Key -'<br> -' ' sign the data using the created key -' Dim dLen& -' Dim strEnc As String * 255 -' strEnc = strData -' dLen = Len(strData) -' modActiveLock.rsa_encrypt 1, strEnc, dLen, Key -'<br> -' ' done with the key - throw it away -' modActiveLock.rsa_freekey Key -'<br> -' Dim strOut As String -' strOut = Left$(strEnc, dLen) -' Encrypt = strOut -' End Function +' Dim i&, n& +' dim sResult$ +' n = Len(strData) +' For i = 1 to n +' sResult = sResult & Asc(Mid$(strData, i, 1)) * 7 +' Next i +' Encrypt = sResult +' End Function +' ... +' ' Returns the CRC checksum of the activelock2.dll. +' Private Property Get ALCRC() As Long +' ' Don't just return a single value, but rather compute it using some simple arithmetic +' ' so that hackers can't easily find it with a hex editor. +' ' Of course, the values below will not make up the real checksum. For the most up-to-date +' ' checksum, please refer to the ActiveLock Release Notes. +' ALCRC = 123 + 456 +' End Property ' </pre> ' -' <p>Generating registration request code from the user application. +' <p>Generating registration code from the user application to be sent to the vendor in exchange for +' a liberation key. ' <pre> ' ' Generate Request code ' Dim strReq As String, strLock As String @@ -178,58 +193,6 @@ ' ' strReq2 now contains the request code to be sent to the vendor for activation. ' </pre> ' -' <p>Key Generator functionality - generating license key for a request code. -' <pre> -' ' First, take request code and decode it. -' Dim strReq As String -' strReq = ActiveLock2.Base64Decode(txtReqCodeIn) ' txtReqCodeIn is a textbox containing the input from the user -' ' strReq now contains the {LockCode + vbLf + User} string -' Dim strLock$, strUser$ -' -' ' Get Lock and user from request code -' Dim Index% -' Index = InStr(1, strReq, vbLf) -' If Index <= 0 Then Exit Sub -' -' strLock = Left(strReq, Index - 1) -' strUser = Mid$(strReq, Index + 1) -' strUser = TrimNulls(strUser) -' -' ' Compute expiration date for a 1-year license -' Dim strExpire$ -' strExpire = Format$(Now + 365, "YYYY/MM/DD") -' -' ' registration date -' Dim strRegDate As String -' strRegDate = Format(Now(), "yyyy/mm/dd") -' Dim strEncrypted As String -' -' ' Use the same encryption routine as ActiveLockEventSink_ValidateValue() event to encrypt the key -' ActiveLockEventSink_ValidateValue strRegDate, strEncrypted -' -' ' hash it -' strEncrypted = ActiveLock2.MD5Hash(strEncrypted) -' -' Dim Lic As ProductLicense -' Set Lic = ActiveLock2.CreateProductLicense("MyApp", PUB_KEY, -' "1.0", MyActiveLock.LockType, MyActiveLock.LicenseType, strUser, strExpire, , strRegDate, strEncrypted) -' Dim strLic As String -' ' encrypt Product license using LockCode -' strLic = MyActiveLock.LockCode(Lic) -' ' Sign it -' Dim strSig As String -' strSig = ActiveLock2.RSASign(PUB_KEY, PRIV_KEY, strLic) -' ' Create liberation key. This will be a base-64 encoded string of the whole license. -' Dim strLicKey As String -' strLicKey = ActiveLock2.Base64Encode(strSig) -' ' update Lic with license key -' Lic.LicenseKey = strLicKey -' ' Serialize it into a formatted string -' Dim strLibKey As String -' Lic.Save strLibKey -' Debug.Print "This is your liberation key: " & strLibKey -' </pre> -' ' <p>Key Registration functionality - register using a liberation key. ' <pre> ' On Error GoTo ErrHandler @@ -248,7 +211,7 @@ ' </pre> ' ' @author th...@us... -' @version 2.0.0 +' @version 2.0 ' @date 20030616 ' '* /////////////////////////////////////////////////////////////////////// @@ -264,7 +227,9 @@ ' 07.20.03 - th2tran - Added EventNotifier used for firing COM events. ' 08.03.03 - th2tran - VBDox'ed this interface. ' 09.21.03 - th2tran - Changed Register(Lic As ProductLicense) subroutine to Register(ByVal LibKey As String) -' +' 10.11.03 - th2tran - Major updates to VBDOX comments... +' - Removed VBDox regarding key generation, now taken care by ALUGEN. +' - Added VB doc Attributes for showing in VB Object Browser ' </pre> ' /////////////////////////////////////////////////////////////////////// @@ -274,9 +239,9 @@ Option Explicit '' -' License Types. Values are mutually exclusive. i.e. they cannot be OR'd together. +' License Types. Values are mutually exclusive. i.e. they cannot be OR'ed together. ' -' @param allicNone Not licensed +' @param allicNone No license enforcement ' @param allicPeriodic License expires after X number of days ' @param allicPermanent License will never expire ' @param allicTimeLocked License expires on a particular date @@ -325,6 +290,7 @@ alsFile = 1 End Enum +'* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Interface Properties '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' @@ -334,6 +300,7 @@ ' @param LicType License Type ' Public Property Let LicenseType(LicType As ALLicType) +Attribute LicenseType.VB_Description = "License Type being used in this instance." End Property @@ -349,12 +316,13 @@ ' @param LockTypes Lock Types. ' Public Property Let LockType(LockTypes As ALLockTypes) +Attribute LockType.VB_Description = "Lock type for this instance of ActiveLock." End Property '' ' Returns the Lock Type being used in this instance. -' +' @return Value corresponding to the lock type(s) being used. Public Property Get LockType() As ALLockTypes End Property @@ -364,6 +332,7 @@ ' @param sName Software Name ' Public Property Let SoftwareName(sName As String) +Attribute SoftwareName.VB_Description = "Name of the product being locked." End Property @@ -378,6 +347,7 @@ ' Specifies the software code (product code) ' @param sCode Software Code. Public Property Let SoftwareCode(sCode As String) +Attribute SoftwareCode.VB_Description = "software code (product code). This is Code1 generated by ALUGEN." End Property @@ -386,6 +356,7 @@ ' @param sVer Version string e.g. "1.0" ' Public Property Let SoftwareVersion(sVer As String) +Attribute SoftwareVersion.VB_Description = "Version of the product being locked." End Property @@ -401,15 +372,19 @@ ' @param KeyStore Key Store Type. ' Public Property Let KeyStoreType(KeyStore As LicStoreType) +Attribute KeyStoreType.VB_Description = "Specifies the key store (e.g. registry or file)." End Property '' ' Specifies the key store path. ' @param Path The path to be used for the specified KeyStoreType. -' e.g. If <code>alsFile</code> is used for <code>KeyStoreType</code>, then Path specifies the path to the license file. -' If <code>alsRegistry</code> is used for <code>KeyStoreType</code>, the Path specifies the Registry hive where license information is stored. -Public Property Let KeyStorePath(path As String) +' e.g. If <a href="IActiveLock.LicStoreType.html">alsFile</a> is used for <a href="IActiveLock.Let.KeyStoreType.html">KeyStoreType</a>, +' then <code>Path</code> specifies the path to the license file. +' If <a href="IActiveLock.LicStoreType.html">alsRegistry</a> is used for <a href="IActiveLock.Let.KeyStoreType.htm">KeyStoreType</a>, +' the Path specifies the Registry hive where license information is stored. +Public Property Let KeyStorePath(sPath As String) +Attribute KeyStorePath.VB_Description = "Specifies the path where the license store resides." End Property @@ -423,43 +398,49 @@ ' Optionally, if a product license is specified, then a lock string specific to that license is returned. ' @param Lic Product License for which to compute the lock code. Public Function LockCode(Optional Lic As ProductLicense = Nothing) As String +Attribute LockCode.VB_Description = "Computes a lock code corresponding to the specified Lock Types, License Class, etc... Optionally, if a product license is specified, then a lock string specific to that license is returned." End Function '' -' Registers the following product license. +' Registers the product using the specified liberation key. ' @param LibKey Liberation Key. Public Sub Register(ByVal LibKey As String) +Attribute Register.VB_Description = "Registers the product using the specified liberation key." End Sub '' ' Transfers the current license to another computer. -' Returns the liberation key tailored for the other request code. ' @param RequestCode Request Code generated from the other computer. -' +' @return The liberation key tailored for the request code generated from the other machine. Public Function Transfer(RequestCode As String) As String +Attribute Transfer.VB_Description = "Transfers the current license to another computer." End Function '' -' Performs special initialization before we start operating. Some of the routines, including <code>Acquire()</code> -' and <code>Register()</code> requires Init() to be called first. +' Initializes ActiveLock before use. Some of the routines, including <a href="IActiveLock.Acquire.html">Acquire()</a> +' and <a href="IActiveLock.Register.html">Register()</a> requires <code>Init()</code> to be called first. ' This routine accepts varying number of parameters. +' Note: If you're accessing IActiveLock via <a href="Globals.NewInstance.html">ActiveLock2.NewInstance()</a>, +' then Init() would already been called for you, so you don't need to call it again. ' ' @param Arg1 First parameter to be passed to this routine. ' @param OtherArgs The remaining array of arguments to be passed into this routine. Public Sub Init(Arg1 As Variant, ParamArray OtherArgs() As Variant) +Attribute Init.VB_Description = "Initializes ActiveLock. This routine must be called before anything else." End Sub '' ' Acquires a valid license token. -' If no valid license can be found, an appropriate error will be thrown, specifying the cause. +' If no valid license can be found, an appropriate error will be raised, specifying the cause. ' Public Sub Acquire() +Attribute Acquire.VB_Description = "Attempts to acquire a valid license token." End Sub @@ -467,15 +448,18 @@ ' Release the acquired token. ' Public Sub Release() +Attribute Release.VB_Description = "Release the acquired license token. This call is only required when concurrent license is being used." End Sub '' ' Retrieves the event notifier. ' Client applications uses this Notifier to handle event notifications sent by ActiveLock, -' including license validation events. +' including license property validation and encryption events. ' @see ActiveLockEventNotifier for more information. +' @return An object that can be used as a COM event source. i.e. can be used in <code>WithEvents</code> statements in VB. Public Property Get EventNotifier() As ActiveLockEventNotifier +Attribute EventNotifier.VB_Description = "Returns the Event Notifier object used by ActiveLock to broadcast COM events." End Property @@ -483,19 +467,24 @@ ' Returns the number of days this product has been used since its registration. ' Public Property Get UsedDays() As Long +Attribute UsedDays.VB_Description = "Returns the number of days this product has been used since its registration." End Property '' -' Returns the date on which the product was registered. +' Retrieves registration date. +' @return Date on which the product is registered. ' Public Property Get RegisteredDate() As String +Attribute RegisteredDate.VB_Description = "Returns the date on which the product was registered." End Property '' -' Returns the expiration date string. +' Retrieves the expiration date. +' @return Date on which the license will expire. ' Public Property Get ExpirationDate() As String +Attribute ExpirationDate.VB_Description = "Returns the expiration date of the current license." End Property Index: ProductLicense.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/ProductLicense.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ProductLicense.cls 7 Aug 2003 17:30:59 -0000 1.1 +++ ProductLicense.cls 13 Oct 2003 04:49:03 -0000 1.2 @@ -61,9 +61,10 @@ ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' <pre> -' 06.16.03 - th2tran - created +' 06.16.03 - th2tran - Created ' 07.07.03 - mecrute - Updated the header comments for this file. ' 08.03.03 - th2tran - VBDox'ed this class. +' 10.12.03 - th2tran - Added VB doc Attributes for showing in VB Object Browser ' </pre> @@ -108,8 +109,10 @@ '' ' Returns the product name. +' @return Product Name ' Public Property Get ProductName() As String +Attribute ProductName.VB_Description = "Returns the product name." ProductName = mstrProductName End Property @@ -122,8 +125,10 @@ '' ' Returns the product version string. +' @return Product Version ' Public Property Get ProductVer() As String +Attribute ProductVer.VB_Description = "Returns the product version string." ProductVer = mstrProductVer End Property @@ -135,11 +140,13 @@ ' @param Key Product Key ' Public Property Let ProductKey(Key As String) +Attribute ProductKey.VB_Description = "Product Key." mstrProductKey = Key End Property '' ' Returns the product key. +' @return Product Key (aka SoftwareCode) ' Public Property Get ProductKey() As String ProductKey = mstrProductKey @@ -154,8 +161,10 @@ '' ' Returns the license type. +' @return License Type ' Public Property Get LicenseType() As String +Attribute LicenseType.VB_Description = "License Type string." LicenseType = mstrType End Property @@ -168,8 +177,10 @@ '' ' Returns the license class string. +' @return License Class ' Public Property Get LicenseClass() As String +Attribute LicenseClass.VB_Description = "License class." LicenseClass = mstrLicenseClass End Property @@ -182,8 +193,10 @@ '' ' Returns the person or organization registered to this license. +' @return Registered User ' Public Property Get Licensee() As String +Attribute Licensee.VB_Description = "Person or organization registered to this license." Licensee = mstrLicensee End Property @@ -195,11 +208,13 @@ ' @param Key New license key to be updated. ' Public Property Let LicenseKey(Key As String) +Attribute LicenseKey.VB_Description = "License key." mstrLicenseKey = Key End Property '' ' Returns the license key. +' @return License key ' Public Property Get LicenseKey() As String LicenseKey = mstrLicenseKey @@ -214,16 +229,20 @@ End Property '' -' Returns the expiration date string. +' Returns the expiration date string in YYYY/MM/DD format. +' @return Expiration date ' Public Property Get Expiration() As String +Attribute Expiration.VB_Description = "expiration date string in YYYY/MM/DD format." Expiration = mstrExpiration End Property '' -' Returns the date on which the product was registered. +' Returns the date in YYYY/MM/DD format on which the product was registered. +' @return Registered date ' Public Property Get RegisteredDate() As String +Attribute RegisteredDate.VB_Description = "Date, in YYYY/MM/DD string format, on which the product was registered." RegisteredDate = mstrRegisteredDate End Property @@ -235,9 +254,11 @@ End Property '' -' Returns the last date and time the product was run. +' Returns the date and time, in YYYY/MM/DD HH:MM:SS format, when the product was last run. +' @return DateTime string ' Public Property Get LastUsed() As String +Attribute LastUsed.VB_Description = "The date and time, in YYYY/MM/DD HH:MM:SS format, when the product was last run." LastUsed = mstrLastUsed End Property @@ -251,8 +272,10 @@ '' ' Returns Hash-1 code. Hash-1 code is the encryption hash of the <code>LastUsed</code> property. +' @return Hash Code ' Public Property Get Hash1() As String +Attribute Hash1.VB_Description = "Returns Hash-1 code. Hash-1 code is the encryption hash of the LastUsed property." Hash1 = mstrHash1 End Property @@ -267,8 +290,10 @@ '' ' Returns a line-feed delimited string encoding of this object's properties ' Note: LicenseKey is not included in this string. +' @return License String ' Public Function ToString() As String +Attribute ToString.VB_Description = "Returns a line-feed delimited string encoding of this object's properties." ToString = ProductName & vbCrLf & _ ProductVer & vbCrLf & _ ProductKey & vbCrLf & _ @@ -280,10 +305,11 @@ End Function '' -' Loads the license from a formatted string. +' Loads the license from a formatted string created from <a href="ProductLicense.Save.html">Save()</a>. ' @param strLic Formatted license string, delimited by CrLf characters. ' Public Sub Load(strLic As String) +Attribute Load.VB_Description = "Loads the license from a formatted string created by Save() method." ' First, base64-decode it strLic = modBase64.Base64_Decode(strLic) Dim arrParts() As String @@ -304,6 +330,7 @@ ' @param strOut [out] Formatted license string will be saved into this parameter when the routine returns. ' Public Sub Save(strOut As String) +Attribute Save.VB_Description = "Saves the license into a formatted string." strOut = ToString() & vbCrLf & LicenseKey 'add License Key at the end strOut = modBase64.Base64_Encode(strOut) End Sub |