[ActiveLock-Development] CVS: activelock/src ActiveLock.cls,1.5,1.6 FileKeyStore.cls,1.1,1.2 Globals
Brought to you by:
ialkan
From: Thanh H. T. <th...@us...> - 2003-11-03 06:30:46
|
Update of /cvsroot/activelock/activelock/src In directory sc8-pr-cvs1:/tmp/cvs-serv28911 Modified Files: ActiveLock.cls FileKeyStore.cls Globals.cls IActiveLock.cls ProductLicense.cls Log Message: Batch commit. See Change Log within individual files for details. Index: ActiveLock.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/ActiveLock.cls,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ActiveLock.cls 13 Oct 2003 04:49:03 -0000 1.5 +++ ActiveLock.cls 3 Nov 2003 06:30:42 -0000 1.6 @@ -98,7 +98,6 @@ Private mSoftwareVer As String Private mSoftwareCode As String Private mLockTypes As ALLockTypes -Private mLicType As ALLicType Private mKeyStore As IKeyStoreProvider Private mKeyStorePath As String Private MyNotifier As New ActiveLockEventNotifier @@ -163,6 +162,18 @@ IActiveLock_RegisteredDate = Lic.RegisteredDate End Property +Private Property Get IActiveLock_RegisteredUser() As String + Dim Lic As ProductLicense + Set Lic = mKeyStore.Retrieve(mSoftwareName) + If Lic Is Nothing Then + Err.Raise ActiveLockErrCodeConstants.alerrNoLicense, "IActiveLock_RegisteredUser", "No license." + End If + ' Validate the License. + ValidateLic Lic + IActiveLock_RegisteredUser = Lic.Licensee +End Property + + '' ' Validate the License Key using RSA signature verification. ' License key contains the RSA signature of IActiveLock_LockCode. @@ -261,7 +272,6 @@ IActiveLock_ExpirationDate = Lic.Expiration End Property - Private Sub IActiveLock_Release() ' TODO: Implement Me! End Sub @@ -286,13 +296,6 @@ End If End Property -Private Property Let IActiveLock_LicenseType(RHS As ALLicType) - mLicType = RHS -End Property -Private Property Get IActiveLock_LicenseType() As ALLicType - IActiveLock_LicenseType = mLicType -End Property - Private Property Let IActiveLock_LockType(RHS As ALLockTypes) mLockTypes = RHS End Property @@ -332,6 +335,22 @@ End Property Private Property Get IActiveLock_SoftwareName() As String IActiveLock_SoftwareName = mSoftwareName +End Property + +Private Property Get IActiveLock_InstallationCode(Optional ByVal User As String = "") As String + ' Generate Request code to Lock + Dim strReq As String, strLock As String + strLock = IActiveLock_LockCode() + ' combine with user name + If User = "" Then + strReq = strLock + Else + strReq = strLock & vbLf & User + End If + ' base-64 encode the request + Dim strReq2 As String + strReq2 = modBase64.Base64_Encode(strReq) + IActiveLock_InstallationCode = strReq2 End Property Private Function IActiveLock_LockCode(Optional Lic As ProductLicense = Nothing) As String Index: FileKeyStore.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/FileKeyStore.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FileKeyStore.cls 7 Aug 2003 17:30:59 -0000 1.1 +++ FileKeyStore.cls 3 Nov 2003 06:30:42 -0000 1.2 @@ -61,6 +61,7 @@ ' /////////////////////////////////////////////////////////////////////// ' ' 07.07.03 - mcrute - Updated the header comments for this file. +' 11.02.03 - th2tran - Handle loading and saving of new MaxCount property ' ' ' /////////////////////////////////////////////////////////////////////// @@ -81,6 +82,7 @@ Private Const KEY_PRODNAME$ = "ProductName" Private Const KEY_PRODVER$ = "ProductVersion" Private Const KEY_LICENSEE$ = "Licensee" +Private Const KEY_MAXCOUNT$ = "MaxCount" ' Maximum number of users Private Const KEY_LICTYPE$ = "LicenseType" Private Const KEY_LICCLASS$ = "LicenseClass" Private Const KEY_LICKEY$ = "LicenseKey" @@ -107,28 +109,39 @@ mIniFile.Values(KEY_LICTYPE) = .LicenseType mIniFile.Values(KEY_LICCLASS) = .LicenseClass mIniFile.Values(KEY_LICENSEE) = .Licensee + mIniFile.Values(KEY_MAXCOUNT) = CStr(.MaxCount) mIniFile.Values(KEY_LICKEY) = .LicenseKey mIniFile.Values(KEY_REGISTERED_DATE) = .RegisteredDate mIniFile.Values(KEY_LASTRUN_DATE) = .LastUsed mIniFile.Values(KEY_LASTRUN_DATE_HASH) = .Hash1 mIniFile.Values(KEY_EXP) = .Expiration + + End With - + End Sub '' ' Retrieves the registered license for the specified product. ' Private Function IKeyStoreProvider_Retrieve(ProductName As String) As ProductLicense - Dim Lic As New ProductLicense + Set IKeyStoreProvider_Retrieve = Nothing + ' Read license properties from INI file section ' TODO: Perhaps we need to lock the file first.? mIniFile.Section = ProductName + + ' No license found + If mIniFile.GetValue(KEY_LICKEY) = "" Then Exit Function + + Dim Lic As New ProductLicense + On Error GoTo InvalidValue With Lic .ProductName = ProductName .ProductVer = mIniFile.GetValue(KEY_PRODVER) .ProductKey = mIniFile.GetValue(KEY_PRODKEY) .Licensee = mIniFile.GetValue(KEY_LICENSEE) + .MaxCount = CLng(mIniFile.Values(KEY_MAXCOUNT)) .LicenseType = mIniFile.GetValue(KEY_LICTYPE) .LicenseClass = mIniFile.GetValue(KEY_LICCLASS) .LicenseKey = mIniFile.GetValue(KEY_LICKEY) @@ -138,6 +151,9 @@ .Hash1 = mIniFile.Values(KEY_LASTRUN_DATE_HASH) End With Set IKeyStoreProvider_Retrieve = Lic + Exit Function +InvalidValue: + Err.Raise alerrKeyStoreInvalid, "ActiveLock2.FileKeyStoreProvider", "A license property contains an invalid value." End Function Index: Globals.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/Globals.cls,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Globals.cls 13 Oct 2003 04:49:03 -0000 1.2 +++ Globals.cls 3 Nov 2003 06:30:42 -0000 1.3 @@ -137,27 +137,27 @@ ' @param Hash1 Hash-1 code ' ' @return License object. -Public Function CreateProductLicense(ByVal name As String, _ - ByVal Code As String, _ +Public Function CreateProductLicense(ByVal Name As String, _ ByVal Ver As String, _ - ByVal LicClass As ActiveLock2.ALLockTypes, _ + ByVal Code As String, _ + ByVal Flags As ActiveLock2.LicFlags, _ 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 _ + Optional ByVal Hash1 As String, _ + Optional ByVal MaxUsers As Integer = 1 _ ) As ProductLicense -Attribute CreateProductLicense.VB_Description = "Creates a new ProductLicense object." Dim NewLic As New ProductLicense With NewLic - .ProductName = name + .ProductName = Name .ProductKey = Code .ProductVer = Ver - .LicenseClass = GetClassString(LicClass) - .LicenseType = GetLicTypeString(LicType) + .LicenseClass = GetClassString(Flags) + .LicenseType = LicType .Licensee = Licensee - + .MaxCount = MaxUsers ' ignore exipration date if license type is "permanent" If LicType <> allicPermanent Then .Expiration = Expiration @@ -175,18 +175,14 @@ Set CreateProductLicense = NewLic End Function -Private Function GetClassString(LockType As ActiveLock2.ALLockTypes) As String +Private Function GetClassString(Flags As ActiveLock2.LicFlags) As String 'TODO: Decide the class numbers. ' lockMAC should probably be last, ' like it is in the enum. (IActivelock.cls) - If LockType = lockMAC Then - GetClassString = "Class1" - ElseIf LockType = lockWindows Then - GetClassString = "Class2" - ElseIf LockType = lockComp Then - GetClassString = "Class3" - ElseIf LockType = lockHD Then - GetClassString = "Class4" + If Flags = alfMulti Then + GetClassString = "MultiUser" + Else ' default + GetClassString = "Single" End If End Function @@ -197,7 +193,15 @@ ' Private Function GetLicTypeString(LicType As ALLicType) As String 'TODO: Implement this properly. - GetLicTypeString = "Single" + If LicType = allicPeriodic Then + GetLicTypeString = "Periodic" + ElseIf LicType = allicPermanent Then + GetLicTypeString = "Permanent" + ElseIf LicType = allicTimeLocked Then + GetLicTypeString = "Timed Expiry" + Else ' default + GetLicTypeString = "None" + End If End Function '' Index: IActiveLock.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/IActiveLock.cls,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- IActiveLock.cls 13 Oct 2003 04:49:03 -0000 1.3 +++ IActiveLock.cls 3 Nov 2003 06:30:42 -0000 1.4 @@ -81,8 +81,11 @@ ' ' Private Sub Form_Load() ' On Error GoTo ErrHandler -' ' Obtain an instance of AL +' ' Obtain an instance of AL. NewInstance() also calls IActiveLock.Init() ' Set MyActiveLock = ActiveLock2.NewInstance() +' ' At this point, either AL has been initialized or an error would have already been raised +' ' if there were problems (such as activelock2.dll having been tampered). +' ' ' Verify AL's authenticity ' ' modActiveLock.CRCCheckSumTypeLib() requires a public-creatable object to be passed in so that it can ' ' determine the Type Library DLL on which to perform the checksum. @@ -112,18 +115,9 @@ ' ' Specify product version ' MyActiveLock.SoftwareVersion = txtVersion ' -' ' Specify License Type -' MyActiveLock.LicenseType = allicTimeLocked -' ' ' Specify Lock Type ' MyActiveLock.LockType = lockHD ' -' ' Now initialize AL -' MyActiveLock.Init -' -' ' At this point, either AL has been initialized or an error would have already been raised -' ' 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 should be prepared to handle that. @@ -133,6 +127,7 @@ ' ' which means if we get to here, then we're registered. ' ' ' Just for fun, print out some registration status info +' Debug.Print "Registered User: " & MyActiveLock.RegisteredUser ' Debug.Print "Used Days: " & MyActiveLock.UsedDays ' Debug.Print "Expiration Date: " & MyActiveLock.ExpirationDate ' Exit Sub @@ -182,28 +177,20 @@ ' <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 -' strLock = MyActiveLock.LockCode() -' ' Combine with user name -' strReq = strLock & vbLf & txtUser -' ' base-64 encode the request -' Dim strReq2 As String -' strReq2 = ActiveLock2.Base64Encode(strReq) -' ' strReq2 now contains the request code to be sent to the vendor for activation. +' ' Generate Installation code +' Dim strInstCode As String +' strInstCode = MyActiveLock.InstallCode(txtUser) +' ' strInstCode now contains the request code to be sent to the vendor for activation. ' </pre> ' ' <p>Key Registration functionality - register using a liberation key. ' <pre> ' On Error GoTo ErrHandler ' ' Register this key -' Dim Lic As New ActiveLock2.ProductLicense ' ' txtLibKey contains the liberation key entered by the user. ' ' This key could have be sent via an email to the user or a program that automatically ' ' requests the key from a registration website. -' ' Load up the license txtLibKey. ' txtLibKey is a textbox containing the input from the user. -' Lic.Load txtLibKey -' MyActiveLock.Register Lic +' MyActiveLock.Register txtLibKey ' MsgBox "Registration successful!" ' Exit Sub 'ErrHandler: @@ -230,6 +217,9 @@ ' 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 +' 11.02.03 - th2tran - LicFlags Enum and its corresponding property don't belong here. Moved its definition to ProductLicense. +' - Added InstallationCode and RegisteredUser properties +' - Updated VBDox with new/simpler registration instructions. ' </pre> ' /////////////////////////////////////////////////////////////////////// @@ -239,20 +229,6 @@ Option Explicit '' -' License Types. Values are mutually exclusive. i.e. they cannot be OR'ed together. -' -' @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 -Public Enum ALLicType - allicNone = 0 - allicPeriodic = 1 - allicPermanent = 2 - allicTimeLocked = 3 -End Enum - -'' ' License Lock Types. Values can be combined (OR'ed) together. ' ' @param lockNone No locking - not recommended @@ -271,16 +247,6 @@ End Enum '' -' License Flags. Values can be combined (OR'ed) together. -' -' @param alfSingle Single-user license -' @param alfMulti Multi-user license -Public Enum LicFlags - alfSingle = 0 - alfMulti = 1 -End Enum - -'' ' License Store Type specifies where to store license keys ' ' @param alsRegistry ' Store in Windows Registry @@ -296,22 +262,6 @@ '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' -' Specifies the license type for this instance of ActiveLock. -' @param LicType License Type -' -Public Property Let LicenseType(LicType As ALLicType) -Attribute LicenseType.VB_Description = "License Type being used in this instance." - -End Property - -'' -' Returns the License Type being used in this instance. -' -Public Property Get LicenseType() As ALLicType - -End Property - -'' ' Specifies the lock type for this instance of ActiveLock. ' @param LockTypes Lock Types. ' @@ -362,6 +312,7 @@ '' ' Returns the Software Version being used in this instance. +' @return Software Version ' Public Property Get SoftwareVersion() As String @@ -388,6 +339,15 @@ End Property +'' +' Returns the installation-specific code needed to obtain the liberation key. +' @param User (Optional) Tailor the installation code specific to this user. +' @return Installation Code +' +Public Property Get InstallationCode(Optional ByVal User As String = "") As String + +End Property + '* '*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '* Interface Methods @@ -413,9 +373,9 @@ '' ' Transfers the current license to another computer. -' @param RequestCode Request Code generated from the other computer. +' @param InstallCode Installation 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 +Public Function Transfer(InstallCode As String) As String Attribute Transfer.VB_Description = "Transfers the current license to another computer." End Function @@ -477,6 +437,15 @@ ' Public Property Get RegisteredDate() As String Attribute RegisteredDate.VB_Description = "Returns the date on which the product was registered." + +End Property + +'' +' Returns the registered user. +' @return User name +' +Public Property Get RegisteredUser() As String +Attribute RegisteredUser.VB_Description = "Returns the registered user." End Property Index: ProductLicense.cls =================================================================== RCS file: /cvsroot/activelock/activelock/src/ProductLicense.cls,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ProductLicense.cls 13 Oct 2003 08:41:56 -0000 1.3 +++ ProductLicense.cls 3 Nov 2003 06:30:42 -0000 1.4 @@ -67,7 +67,9 @@ ' 10.12.03 - th2tran - Added VB doc Attributes for showing in VB Object Browser ' - Load() now drops CRLF chars from the liberation key. ' This allows users to format the key into nice 64-byte -' for better readability. +' 11.02.03 - th2tran - New license properties: License Type, MaxCount +' - Removed CLASS_n constants +' - Moved LicFlags definition from IActiveLock into here ' </pre> @@ -79,6 +81,7 @@ Private mstrType As String Private mstrLicensee As String Private mstrLicenseClass As String +Private mLicType As ALLicType Private mstrProductKey As String Private mstrProductName As String Private mstrProductVer As String @@ -86,28 +89,57 @@ Private mstrExpiration As String Private mstrRegisteredDate As String Private mstrLastUsed As String - Private mstrHash1 As String ' hash of mstrRegisteredDate +Private mnMaxCount As Long ' max number of concurrent users '' -' CPU License Class - I don't yet know how this could be done! +' License Flags. Values can be combined (OR'ed) together. ' -Public Property Get CLASS_1() As String - CLASS_1 = "Class1" +' @param alfSingle Single-user license +' @param alfMulti Multi-user license +Public Enum LicFlags + alfSingle = 0 + alfMulti = 1 +End Enum + +'' +' License Types. Values are mutually exclusive. i.e. they cannot be OR'ed together. +' +' @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 +Public Enum ALLicType + allicNone = 0 + allicPeriodic = 1 + allicPermanent = 2 + allicTimeLocked = 3 +End Enum + + + +'' +' Specifies the license type for this instance of ActiveLock. +' @param LicType License Type +' +Public Property Let LicenseType(LicType As ALLicType) +Attribute LicenseType.VB_Description = "License Type" + mLicType = LicType End Property '' -' Site License Class - lock to hard-drive(nic?) +' Returns the License Type being used in this instance. ' -Public Property Get CLASS_2() As String - CLASS_2 = "Class2" +Public Property Get LicenseType() As ALLicType +Attribute LicenseType.VB_Description = "License Type" + LicenseType = mLicType End Property '' ' [INTERNAL] Specifies product name. ' -Friend Property Let ProductName(ByVal Name As String) - mstrProductName = Name +Friend Property Let ProductName(ByVal name As String) + mstrProductName = name End Property '' @@ -156,22 +188,6 @@ End Property '' -' [INTERNAL] Specifies license type. -' -Friend Property Let LicenseType(ByVal LicType As String) - mstrType = LicType -End Property - -'' -' Returns the license type. -' @return License Type -' -Public Property Get LicenseType() As String -Attribute LicenseType.VB_Description = "License Type string." - LicenseType = mstrType -End Property - -'' ' [INTERNAL] Specifies the license class string. ' Friend Property Let LicenseClass(ByVal LicClass As String) @@ -189,9 +205,11 @@ '' ' [INTERNAL] Specifies the licensed user. +' <p>!!! WARNING !!! Make sure you know what you're doing when you call this method; otherwise, you run +' the risk of invalidating your existing license. ' -Friend Property Let Licensee(ByVal Name As String) - mstrLicensee = Name +Public Property Let Licensee(ByVal name As String) + mstrLicensee = name End Property '' @@ -236,7 +254,7 @@ ' @return Expiration date ' Public Property Get Expiration() As String -Attribute Expiration.VB_Description = "expiration date string in YYYY/MM/DD format." +Attribute Expiration.VB_Description = "Expiration date string in YYYY/MM/DD format." Expiration = mstrExpiration End Property @@ -256,6 +274,14 @@ mstrRegisteredDate = strDate End Property +Public Property Get MaxCount() As Long + MaxCount = mnMaxCount +End Property + +Friend Property Let MaxCount(nCount As Long) + mnMaxCount = nCount +End Property + '' ' Returns the date and time, in YYYY/MM/DD HH:MM:SS format, when the product was last run. ' @return DateTime string @@ -304,7 +330,8 @@ LicenseType & vbCrLf & _ Licensee & vbCrLf & _ RegisteredDate & vbCrLf & _ - Expiration + Expiration & vbCrLf & _ + MaxCount End Function '' @@ -324,11 +351,12 @@ ProductVer = arrParts(1) ProductKey = arrParts(2) LicenseClass = arrParts(3) - LicenseType = arrParts(4) + LicenseType = CLng(arrParts(4)) Licensee = arrParts(5) RegisteredDate = arrParts(6) Expiration = arrParts(7) - LicenseKey = arrParts(8) + MaxCount = CLng(arrParts(8)) + LicenseKey = arrParts(9) End Sub '' |