[ActiveLock-Development] CVS: activelock/src .cvsignore,NONE,1.1 ActiveLock.cls,NONE,1.1 ActiveLock2
Brought to you by:
ialkan
Update of /cvsroot/activelock/activelock/src In directory sc8-pr-cvs1:/tmp/cvs-serv28087/src Added Files: .cvsignore ActiveLock.cls ActiveLock2.vbp ActiveLockEventNotifier.cls BlowFish.cls FileKeyStore.cls Globals.cls IActiveLock.cls IKeyStoreProvider.cls INIFile.cls ProductKeyGenerator.cls ProductLicense.cls RegistryKeyStore.cls modActiveLock.bas modBase64.bas modComputerName.bas modHDSerial.bas modMACAddress.bas modMd5.bas modRegistryAPIs.bas modSha1.bas modWinApi.bas modWindowsSerial.bas Log Message: Inital Checkin After Restructure --- NEW FILE: .cvsignore --- *.vbw *.lib *.exp --- NEW FILE: ActiveLock.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "ActiveLock" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False '* ActiveLock '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions are '* met: '* '* [o] Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* '* [o] Redistributions in binary form must reproduce the above '* copyright notice, this list of conditions and the following '* disclaimer in the documentation and/or other materials provided '* with the distribution. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR '* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT '* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, '* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT '* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, '* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY '* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT '* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE '* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '* '' ' This is an implementation of IActiveLock. It is not public-creatable, and so must only ' be accessed via ActiveLock.NewInstance() method. ' ' @author th...@us... ' @version 2.0.0 ' @date 20030616 ' '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' ' @todo Implement IActiveLock_Release. Not sure what if anything needs to be ' done here. ' @todo Implement IActiveLock_Transfer. This is the functionality to transfer ' a license from one machine to another. '* /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' @history ' <pre> ' 07.07.03 - mcrute - Updated the header comments for this file. ' 07.28.03 - th2tran - Using RSA signature for license key. ' 07.28.03 - wizzardme2000 - Implemented lockComp, lockHD, and lockWindows ' 07.31.03 - th2tran - Perform checksum on ALCrypto.dll on Init() ' - ValidateKey() to bypass checking expiry if there's no expiration date. ' </pre> ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit '' ' Implements the IActiveLock interface. ' Implements IActiveLock Private mSoftwareName As String 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 Private MyGlobals As New Globals ' Registry hive used to store Active Lock settings. Private Const AL_REGISTRY_HIVE$ = "Software\ActiveLock Software Group\ActiveLock2" ' Transients Private mfInit As Boolean ' flag to indicate that ActiveLock has been initialized ''' ' IActiveLock Interface implementations '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Property Get IActiveLock_EventNotifier() As ActiveLockEventNotifier Set IActiveLock_EventNotifier = MyNotifier End Property Private Sub IActiveLock_Init(Arg1 As Variant, ParamArray OtherArgs() As Variant) ' Checksum ALCrypto.dll Const ALCRYPTO_MD5$ = "e30f9189d9feb4eb222386c7c294f45e" Dim strdata As String, strMD5 As String Call modActiveLock.ReadFile(App.path & "\ALCrypto.Dll", strdata) strMD5 = modMD5.Hash(strdata) ' use our own MD5 hashing routine instead of ALCrypto's md5_hash() function. If strMD5 <> ALCRYPTO_MD5 Then Err.Raise ActiveLockErrCodeConstants.alerrFileTampered, "IActiveLock_Acquire", "ALCrypto.dll has been tampered." End If mfInit = True End Sub Private Sub IActiveLock_Acquire() If mKeyStore Is Nothing Then Err.Raise ActiveLockErrCodeConstants.alerrKeyStoreInvalid, "IActiveLock_Acquire", "Key Store Provider hasn't been initialized yet." End If Dim Lic As ProductLicense Set Lic = mKeyStore.Retrieve(mSoftwareName) If Lic Is Nothing Then Err.Raise ActiveLockErrCodeConstants.alerrNoLicense, "IActiveLock_Acquire", "No valid license" End If ' Validate license ValidateLic Lic End Sub Private Property Get IActiveLock_RegisteredDate() As String Dim Lic As ProductLicense Set Lic = mKeyStore.Retrieve(mSoftwareName) If Lic Is Nothing Then Err.Raise ActiveLockErrCodeConstants.alerrNoLicense, "IActiveLock_RegisteredDate", "No license." End If ' Validate the License. ValidateLic Lic IActiveLock_RegisteredDate = Lic.RegisteredDate End Property '' ' Validate the License Key using RSA signature verification. ' License key contains the RSA signature of IActiveLock_LockCode. Private Sub ValidateKey(Lic As ProductLicense) ' make sure software code is set If mSoftwareCode = "" Then Err.Raise ActiveLockErrCodeConstants.alerrNotInitialized, "ActiveLock2", "Software Code has not been set." End If Dim Key As RSAKey Dim strPubKey As String strPubKey = mSoftwareCode Dim strSig As String Dim strLic As String strLic = IActiveLock_LockCode(Lic) ' decode the license key strSig = MyGlobals.Base64Decode(Lic.LicenseKey) ' validate the key Dim rc& rc = MyGlobals.RSAVerify(strPubKey, strLic, strSig) If rc <> 0 Then Err.Raise ActiveLockErrCodeConstants.alerrLicenseInvalid, "ActiveLock2", "License invalid." End If ' Check if license has not expired ' but don't do it if there's no expiration date If Lic.Expiration = "" Then Exit Sub Dim dtExp As Date dtExp = CDate(Lic.Expiration) If Now > dtExp Then Err.Raise ActiveLockErrCodeConstants.alerrLicenseExpired, "ActiveLock2", "License expired" End If End Sub '' ' Validate the entire license (including lastused, etc...) ' Private Sub ValidateLic(Lic As ProductLicense) ' make sure we're initialized. If Not mfInit Then Err.Raise ActiveLockErrCodeConstants.alerrNotInitialized, "ActiveLock2", "ActiveLock has not been initialized." End If ' validate license key first ValidateKey Lic Dim strEncrypted As String, strHash As String ' Validate last run date MyNotifier.Notify "ValidateValue", Lic.LastUsed, strEncrypted strHash = MyGlobals.MD5Hash(strEncrypted) If strHash <> Lic.Hash1 Then Err.Raise ActiveLockErrCodeConstants.alerrLicenseTampered, "ActiveLock2", "License may have been tampered." End If ' try to detect the user setting their system clock back If Now < CDate(Lic.LastUsed) Then ' TODO: Need to account for Daylight Savings Time Err.Raise ActiveLockErrCodeConstants.alerrClockChanged, "ActiveLock2", "License invalid. You have set your system clock backward!" End If UpdateLastUsed Lic mKeyStore.Store Lic End Sub '' ' Updates LastUsed property with current date stamp. ' Private Sub UpdateLastUsed(Lic As ProductLicense) ' Update license store with LastRunDate Dim strEncrypted As String 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) End Sub Private Property Get IActiveLock_ExpirationDate() As String Dim Lic As ProductLicense Set Lic = mKeyStore.Retrieve(mSoftwareName) If Lic Is Nothing Then Err.Raise ActiveLockErrCodeConstants.alerrNoLicense, "IActiveLock_ExpirationDate", "No license." End If ' Validate the License. ValidateLic Lic IActiveLock_ExpirationDate = Lic.Expiration End Property Private Sub IActiveLock_Release() ' TODO: Implement Me! End Sub Private Property Let IActiveLock_KeyStorePath(RHS As String) If Not mKeyStore Is Nothing Then mKeyStore.KeyStorePath = RHS End If mKeyStorePath = RHS End Property Private Property Let IActiveLock_KeyStoreType(RHS As LicStoreType) ' Instantiate Key Store Provider If RHS = alsFile Then Set mKeyStore = New FileKeyStoreProvider Else Set mKeyStore = New RegistryKeyStoreProvider End If ' Set Key Store Path in KeyStoreProvider If mKeyStorePath <> "" Then mKeyStore.KeyStorePath = mKeyStorePath 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 Private Property Get IActiveLock_LockType() As ALLockTypes IActiveLock_LockType = mLockTypes End Property Private Sub IActiveLock_Register(Lic As ProductLicense) ' Validate that the license key. ' - registered user ' - expiry date Dim varResult As Variant ValidateKey Lic ' License was validated successfuly. Store it. 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 mKeyStore.Store Lic End Sub Private Function RandomNumber() As String ' Generates a random number On Error Resume Next Randomize RandomNumber = CStr(CLng(Rnd(1) * 2147483647)) End Function Private Property Let IActiveLock_SoftwareName(RHS As String) mSoftwareName = RHS End Property Private Property Get IActiveLock_SoftwareName() As String IActiveLock_SoftwareName = mSoftwareName End Property Private Function IActiveLock_LockCode(Optional Lic As ProductLicense = Nothing) As String Dim strLock As String If (mLockTypes And lockMAC) = lockMAC Then strLock = strLock & vbLf & modMACAddress.GetMACAddress() End If If mLockTypes And lockComp Then strLock = strLock & vbLf & modComputerName.GetComputerName() End If If mLockTypes And lockHD Then strLock = strLock & vbLf & modHDSerial.GetHDSerial() End If If mLockTypes And lockWindows Then strLock = strLock & vbLf & modWindowsSerial.GetWindowsSerial() End If If Left(strLock, 1) = vbLf Then strLock = Mid(strLock, 2) If Lic Is Nothing Then IActiveLock_LockCode = strLock Else IActiveLock_LockCode = Lic.ToString() & vbCrLf & strLock End If End Function Private Property Let IActiveLock_SoftwareVersion(RHS As String) mSoftwareVer = RHS End Property Private Property Get IActiveLock_SoftwareVersion() As String IActiveLock_SoftwareVersion = mSoftwareVer End Property Private Property Let IActiveLock_SoftwareCode(RHS As String) ' SoftwareCode is an RSA public key. This code will be used to verify license keys later on. mSoftwareCode = RHS End Property Private Function IActiveLock_Transfer(OtherSoftwareCode As String) As String ' TODO: Implement me! End Function Private Property Get IActiveLock_UsedDays() As Long Dim Lic As ProductLicense Set Lic = mKeyStore.Retrieve(mSoftwareName) ' validate the license ValidateLic Lic IActiveLock_UsedDays = CLng(DateDiff("d", Lic.RegisteredDate, Now)) End Property --- NEW FILE: ActiveLock2.vbp --- Type=OleDll Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation Class=ActiveLock; ActiveLock.cls Class=IActiveLock; IActiveLock.cls Class=Globals; Globals.cls Class=IKeyStoreProvider; IKeyStoreProvider.cls Class=RegistryKeyStoreProvider; RegistryKeyStore.cls Class=ProductLicense; ProductLicense.cls Class=FileKeyStoreProvider; FileKeyStore.cls Module=modMACAddress; modMACAddress.bas Module=modMD5; modMd5.bas Module=modSHA1; modSha1.bas Module=modRegistryAPIs; modRegistryAPIs.bas Class=INIFile; INIFile.cls Module=modWinApi; modWinApi.bas Class=ActiveLockEventNotifier; ActiveLockEventNotifier.cls Module=modActiveLock; modActiveLock.bas Module=modBase64; modBase64.bas Module=modHDSerial; modHDSerial.bas Module=modWindowsSerial; modWindowsSerial.bas Module=modComputerName; modComputerName.bas Startup="(None)" HelpFile="" Title="ActiveLock2" ExeName32="ActiveLock2.dll" Command32="" Name="ActiveLock2" HelpContextID="0" CompatibleMode="2" CompatibleEXE32="ActiveLock2.dll" VersionCompatible32="1" MajorVer=2 MinorVer=0 RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="The ActiveLock Software Group" VersionLegalCopyright="Copyright © 2003" VersionProductName="ActiveLock" CompilationType=0 OptimizationType=0 FavorPentiumPro(tm)=0 CodeViewDebugInfo=0 NoAliasing=0 BoundsCheck=0 OverflowCheck=0 FlPointCheck=0 FDIVCheck=0 UnroundedFP=0 StartMode=1 Unattended=0 Retained=0 ThreadPerObject=0 MaxNumberOfThreads=1 ThreadingModel=1 DebugStartupOption=0 [MS Transaction Server] AutoRefresh=1 --- NEW FILE: ActiveLockEventNotifier.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "ActiveLockEventNotifier" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '* ActiveLock '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions are '* met: '* '* [o] Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* '* [o] Redistributions in binary form must reproduce the above '* copyright notice, this list of conditions and the following '* disclaimer in the documentation and/or other materials provided '* with the distribution. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR '* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT '* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, '* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT '* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, '* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY '* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT '* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE '* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '* '' ' This class handles ActiveLock COM event notifications to the interested observers. ' It is simply a wrapper containing pubic events. These events should ' really belong in IActiveLock, but since VB doesn't support inheritance ' of events, we have to do it this way. ' ' @author th...@us... ' @version 2.0.0 ' @date 20030720 ' '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' [ ] TODO Item 1 ' [ ] TODO Item 2 ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' @history ' <pre> ' 07.20.03 - th2tran - Created ' 08.03.03 - th2tran - VBDox'ed this interface. ' </pre> ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit '' ' ProductLicense Property Value validation event allows the client application ' to return the encrypted version of a license property value. ' 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. ' @param Value Property value. ' @param Result Encrypted value. Public Event ValidateValue(ByVal Value As String, Result 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 End If End Sub --- NEW FILE: BlowFish.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "BlowFish" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '* ActiveLock '* Copyright 2000 Fredrik Qvarfort '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* [...1462 lines suppressed...] m_sBox(3, 254) = &HC208E69F m_sBox(0, 255) = &HB74E6132 m_sBox(1, 255) = &HCE77E25B m_sBox(2, 255) = &H578FDFE3 m_sBox(3, 255) = &H3AC372E6 End Sub Public Function FileExist(Filename As String) As Boolean On Error GoTo NotExist Call FileLen(Filename) FileExist = True Exit Function NotExist: End Function --- NEW FILE: FileKeyStore.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "FileKeyStoreProvider" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False '* ActiveLock '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions are '* met: '* '* [o] Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* '* [o] Redistributions in binary form must reproduce the above '* copyright notice, this list of conditions and the following '* disclaimer in the documentation and/or other materials provided '* with the distribution. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR '* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT '* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, '* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT '* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, '* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY '* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT '* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE '* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '* '' ' This IKeyStoreProvider implementation is used to maintain the license keys on a file system. ' ' @author th...@us... ' @version 2.0.0 ' @date 20030616 ' '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' ' [ ] IKeyStoreProvider_Store() - need to handle file locking for concurrent licensing. ' ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' ' 07.07.03 - mcrute - Updated the header comments for this file. ' ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit '' ' Implements IKeyStoreProvider interface. Implements IKeyStoreProvider Private mstrPath As String Private mIniFile As New INIFile ' License File Key names Private Const KEY_PRODKEY$ = "ProductKey" Private Const KEY_PRODNAME$ = "ProductName" Private Const KEY_PRODVER$ = "ProductVersion" Private Const KEY_LICENSEE$ = "Licensee" Private Const KEY_LICTYPE$ = "LicenseType" Private Const KEY_LICCLASS$ = "LicenseClass" Private Const KEY_LICKEY$ = "LicenseKey" Private Const KEY_EXP$ = "Expiration" Private Const KEY_REGISTERED_DATE$ = "RegisteredDate" Private Const KEY_LASTRUN_DATE$ = "LastUsed" ' date and time stamp Private Const KEY_LASTRUN_DATE_HASH$ = "Hash1" ' Hash of LastRunDate Private Property Let IKeyStoreProvider_KeyStorePath(RHS As String) If Not FileExists(RHS) Then Err.Raise alerrKeyStoreInvalid, , "License file '" & RHS & "' not found." End If mstrPath = RHS mIniFile.File = mstrPath End Property Private Sub IKeyStoreProvider_Store(Lic As ProductLicense) ' Write license properties to INI file section ' TODO: Perhaps we need to lock the file first.? mIniFile.Section = Lic.ProductName With Lic mIniFile.Values(KEY_PRODKEY) = .ProductKey mIniFile.Values(KEY_PRODVER) = .ProductVer mIniFile.Values(KEY_LICTYPE) = .LicenseType mIniFile.Values(KEY_LICCLASS) = .LicenseClass mIniFile.Values(KEY_LICENSEE) = .Licensee 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 ' Read license properties from INI file section ' TODO: Perhaps we need to lock the file first.? mIniFile.Section = ProductName With Lic .ProductName = ProductName .ProductVer = mIniFile.GetValue(KEY_PRODVER) .ProductKey = mIniFile.GetValue(KEY_PRODKEY) .Licensee = mIniFile.GetValue(KEY_LICENSEE) .LicenseType = mIniFile.GetValue(KEY_LICTYPE) .LicenseClass = mIniFile.GetValue(KEY_LICCLASS) .LicenseKey = mIniFile.GetValue(KEY_LICKEY) .Expiration = mIniFile.GetValue(KEY_EXP) .RegisteredDate = mIniFile.Values(KEY_REGISTERED_DATE) .LastUsed = mIniFile.Values(KEY_LASTRUN_DATE) .Hash1 = mIniFile.Values(KEY_LASTRUN_DATE_HASH) End With Set IKeyStoreProvider_Retrieve = Lic End Function '' ' Determines if a file exists. ' Private Function FileExists(FilePath As String) As Boolean If Len(FilePath) > 0 Then FileExists = (Len(Dir$(FilePath)) > 0) End If End Function --- NEW FILE: Globals.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "Globals" Attribute VB_GlobalNameSpace = True Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '* ActiveLock '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions are '* met: '* '* [o] Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* '* [o] Redistributions in binary form must reproduce the above '* copyright notice, this list of conditions and the following '* disclaimer in the documentation and/or other materials provided '* with the distribution. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR '* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT '* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, '* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT '* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, '* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY '* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT '* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE '* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '* '' ' This class contains global object factory and utility methods. ' 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 ' <code>ActiveLock2.NewInstance()</code>. ' ' @author th...@us... ' @version 2.0.0 ' @date 20030616 ' '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' @todo GetLicTypeString() - Implement this fully. ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' @history ' <pre> ' 07.07.03 - mcrute - Updated the header comments for this file. ' 07.21.03 - th2tran - Added ActiveLockErrCodeConstants to contain ' a list of error code constants raised by ActiveLock. ' 07.28.03 - wizzardme2000 - Implemented lockComp, lockHD, and lockWindows ' 07.31.03 - th2tran - Added alerrFileTampered ' - CreateProductLicense() to ignore Expiration date ' for Permanent license type ' 08.03.03 - th2tran - VBDox'ed this class. ' </pre> ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit '' ' ActiveLock Error Codes ' ' @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 alerrKeyStoreInvalid Key Store Provider has not been initialized yet. ' @param alerrFileTampered License file has been tampered. ' @param alerrNotInitialized ActiveLock has not been initialized yet. Public Enum ActiveLockErrCodeConstants alerrOK = 0 ' successful alerrNoLicense = &H80040001 ' vbObjectError (&H80040000) + 1 alerrLicenseInvalid = &H80040002 alerrLicenseExpired = &H80040003 alerrLicenseTampered = &H80040004 alerrClockChanged = &H80040005 alerrKeyStoreInvalid = &H80040010 alerrFileTampered = &H80040011 alerrNotInitialized = &H80040012 End Enum '' ' Returns a new instance of an object that implements IActiveLock interface. ' @param Args Optional list of parameters. ' Public Function NewInstance(Optional Args As Variant) As IActiveLock 'TODO: Add parameters as appropriate Dim NewInst As IActiveLock Set NewInst = New ActiveLock With NewInst ' Initialize properties ..... .Init Args End With Set NewInstance = NewInst End Function '' ' Instantiates a new ProductLicense object. ' If LicType is "Permanent", then Expiration date parameter will be ignored. ' ' @param Name Product/Software Name ' @param Code Product/Software Code ' @param Ver Product version ' @param Licclass License class ' @param LicType License type ' @param Licensee Registered party for which the license has been issued ' @param Expiration Expiration date ' @param LicKey License key ' @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 _ ) As ProductLicense Dim NewLic As New ProductLicense With NewLic .ProductName = name .ProductKey = Code .ProductVer = Ver .LicenseClass = GetClassString(LicClass) .LicenseType = GetLicTypeString(LicType) .Licensee = Licensee ' ignore exipration date if license type is "permanent" If LicType <> allicPermanent Then .Expiration = Expiration End If If Not IsMissing(LicKey) Then .LicenseKey = LicKey End If If Not IsMissing(RegisteredDate) Then .RegisteredDate = RegisteredDate End If If Not IsMissing(Hash1) Then .Hash1 = Hash1 End If End With Set CreateProductLicense = NewLic End Function Private Function GetClassString(LockType As ActiveLock2.ALLockTypes) 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" End If End Function '' ' Returns a string version of LicType ' ' @param LicType License Type ' Private Function GetLicTypeString(LicType As ALLicType) As String 'TODO: Implement this properly. GetLicTypeString = "Single" End Function '' ' Trim Null characters from the string. ' @param str String to be trimmed. ' Public Function TrimNulls(str As String) As String TrimNulls = modActiveLock.TrimNulls(str) End Function '' ' Computes an MD5 hash of the specified string. ' @param str String to be hashed. ' Public Function MD5Hash(str As String) As String MD5Hash = modMD5.Hash(str) End Function '' ' Base-64 encode the specified string. ' @param str String to be encoded ' Public Function Base64Encode(str As String) As String Base64Encode = modBase64.Base64_Encode(str) End Function '' ' Base-64 decode the string. ' @param strEncoded String to be decoded ' Public Function Base64Decode(strEncoded As String) As 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 ' @param strData Data to be signed ' @return Signature string. ' Public Function RSASign(strPub As String, strPriv As String, strdata As String) As String Dim Key As RSAKey ' create the key from the key blobs modActiveLock.rsa_createkey strPub, Len(strPub), strPriv, Len(strPriv), Key ' sign the data using the created key Dim sLen& rsa_sign Key, strdata, Len(strdata), vbNullString, sLen Dim strSig As String: strSig = String(sLen, 0) modActiveLock.rsa_sign Key, strdata, Len(strdata), strSig, sLen ' throw away the key modActiveLock.rsa_freekey Key RSASign = strSig End Function '' ' Verifies an RSA signature. ' @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. ' Public Function RSAVerify(strPub As String, strdata As String, strSig As String) As Long Dim Key As RSAKey Dim rc& ' create the key from the public key blob rsa_createkey strPub, Len(strPub), vbNullString, 0, Key ' validate the key rc = rsa_verifysig(Key, strSig, Len(strSig), strdata, Len(strdata)) ' de-allocate memory used by the key rsa_freekey Key RSAVerify = rc End Function --- NEW FILE: IActiveLock.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "IActiveLock" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '* ActiveLock '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions are '* met: '* '* [o] Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* '* [o] Redistributions in binary form must reproduce the above '* copyright notice, this list of conditions and the following '* disclaimer in the documentation and/or other materials provided '* with the distribution. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR '* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT '* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, '* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT '* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, '* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY '* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT '* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE '* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '* '' ' 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. ' <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 Sub Form_Load() ' On Error GoTo Hell ' ' Obtain an instance of AL ' Set MyActiveLock = ActiveLock2.NewInstance() ' ' 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. ' ' 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) ' 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." ' End If '<br> ' ' Initialize the keystore. We use a File keystore in this case. ' MyActiveLock.KeyStoreType = alsFile ' MyActiveLock.KeyStorePath = App.path & "\al.lic" '<br> ' ' 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 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> ' ' Check registration status by calling Acquire() ' ' Note: Calling Acquire() may trigger ActiveLockEventNotifier_ValidateValue() event. ' ' So we must be prepared to handle that. ' MyActiveLock.Acquire '<br> ' ' By now, if the product is not registered, then an error whould 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: ' 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. ' Private Sub ActiveLockEventSink_ValidateValue(ByVal Value As String, Result As String) ' Result = Encrypt(Value) ' End Sub '<br> ' ' Encrypts a 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 ' </pre> ' ' <p>Generating registration request code from the user application. ' <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. ' </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 ' ' 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 ' MsgBox "Registration successful!" ' Exit Sub 'ErrHandler: ' MsgBox Err.Number & ": " & Err.Description ' </pre> ' ' @author th...@us... ' @version 2.0.0 ' @date 20030616 ' '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' @history ' <pre> ' 07.07.03 - mcrute - Updated the header comments for this file. ' 07.20.03 - th2tran - Added EventNotifier used for firing COM events. ' 08.03.03 - th2tran - VBDox'ed this interface. ' ' </pre> ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit '' ' License Types. Values are mutually exclusive. i.e. they cannot be OR'd together. ' ' @param allicNone Not licensed ' @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 ' @param lockWindows Lock to windows serial number ' @param lockComp Lock to computer name ' @param lockHD Lock to hard drive serial ' @param lockMAC Lock to network NIC address Public Enum ALLockTypes lockNone = 0 lockWindows = 1 lockComp = 2 lockHD = 4 lockMAC = 8 ' lockCustom = 16 ' lock to a custom string ' lockRandom = 32 ' lock to a random number 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 ' @param alsFile ' Store in a license file Public Enum LicStoreType alsRegistry = 0 alsFile = 1 End Enum '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Interface Properties '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' ' Specifies the license type for this instance of ActiveLock. ' @param LicType License Type ' Public Property Let LicenseType(LicType As ALLicType) 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. ' Public Property Let LockType(LockTypes As ALLockTypes) End Property '' ' Returns the Lock Type being used in this instance. ' Public Property Get LockType() As ALLockTypes End Property '' ' Specifies the name of the product being locked. ' @param sName Software Name ' Public Property Let SoftwareName(sName As String) End Property '' ' Returns the Software Name being used in this instance. ' Public Property Get SoftwareName() As String End Property '' ' Specifies the software code (product code) ' @param sCode Software Code. Public Property Let SoftwareCode(sCode As String) End Property '' ' Specifies the version of the product being locked. ' @param sVer Version string e.g. "1.0" ' Public Property Let SoftwareVersion(sVer As String) End Property '' ' Returns the Software Version being used in this instance. ' Public Property Get SoftwareVersion() As String End Property '' ' Specifies the key store type. ' @param KeyStore Key Store Type. ' Public Property Let KeyStoreType(KeyStore As LicStoreType) 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) End Property '* '*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '* Interface Methods '*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' ' 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. ' @param Lic Product License for which to compute the lock code. Public Function LockCode(Optional Lic As ProductLicense = Nothing) As String End Function '' ' Registers the following product license. ' @param Lic Product License with which to register. Public Sub Register(Lic As ProductLicense) 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. ' Public Function Transfer(RequestCode As String) As String 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. ' This routine accepts varying number of parameters. ' ' @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) End Sub '' ' Acquires a valid license token. ' If no valid license can be found, an appropriate error will be thrown, specifying the cause. ' Public Sub Acquire() End Sub '' ' Release the acquired token. ' Public Sub Release() End Sub '' ' Retrieves the event notifier. ' Client applications uses this Notifier to handle event notifications sent by ActiveLock, ' including license validation events. ' @see ActiveLockEventNotifier for more information. Public Property Get EventNotifier() As ActiveLockEventNotifier End Property '' ' Returns the number of days this product has been used since its registration. ' Public Property Get UsedDays() As Long End Property '' ' Returns the date on which the product was registered. ' Public Property Get RegisteredDate() As String End Property '' ' Returns the expiration date string. ' Public Property Get ExpirationDate() As String End Property --- NEW FILE: IKeyStoreProvider.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "IKeyStoreProvider" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False '* ActiveLock '* Copyright 1998-2002 Nelson Ferraz '* Copyright 2003 The ActiveLock Software Group (ASG) '* All material is the property of the contributing authors. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions are '* met: '* '* [o] Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* '* [o] Redistributions in binary form must reproduce the above '* copyright notice, this list of conditions and the following '* disclaimer in the documentation and/or other materials provided '* with the distribution. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR '* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT '* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, '* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT '* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, '* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY '* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT '* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE '* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '* '' ' This is the interface for a class that facilitates storing and ' retrieving of product license keys. ' ' @author th...@us... ' @version 2.0.0 ' @date 20030616 ' '* /////////////////////////////////////////////////////////////////////// ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' ' [ ] TO-DO Item 1 ' ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' @history ' <pre> ' 07.07.03 - mcrute - Updated the header comments for this file. ' 08.03.03 - th2tran - VBDox'ed this class. ' </pre> ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit '' ' Specifies the path under which the keys are stored. ' Example: path to a license file, or path to the Windows Registry hive. ' @param Path Key store path. ' Public Property Let KeyStorePath(path As String) End Property '' ' Retrieves license info for the specified product name. ' @param ProductName Product name. ' @return ProductLicense object matching the specified product name. ' If no license found, then <code>Nothing</code> is returned. ' Public Function Retrieve(ProductName As String) As ProductLicense End Function '' ' Stores a license. ' @param Lic License to be stored. ' Public Sub Store(Lic As ProductLicense) End Sub --- NEW FILE: INIFile.cls --- VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "INIFile" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes" Attribute VB_Ext_KEY = "Top_Level" ,"Yes" ' /////////////////////////////////////////////////////////////////////// ' / Filename: INIFile.cls / ' / Version: 1.0.0.1 / ' / Purpose: Stores and retrives product keys / ' / Klaus H. Probst [kp...@vb...] / ' / / ' / Date Created: ???? ??, ???? - KHP / ' / Date Last Modified: July 07, 2003 - MEC / ' / / ' / This software is released under the license detailed below and is / ' / subject to said license. Neither this header nor the licese below / ' / may be removed from this module. / ' /////////////////////////////////////////////////////////////////////// ' ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE DESCRIPTION / ' /////////////////////////////////////////////////////////////////////// ' ' An "object-oriented" approach to using Windows INI files, with some ' useful additions. ' ' ' /////////////////////////////////////////////////////////////////////// ' / SOFTWARE LICENSE / ' /////////////////////////////////////////////////////////////////////// ' ' If you intend to distribute the file(s) that make up this sample to ' any WWW site, online service, electronic bulletin board system (BBS), ' CD or any other electronic or physical media, you must notify me in ' advance to obtain my express permission. ' ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit DefLng A-Z 'Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "Get... [truncated message content] |