[ActiveLock-Development] CVS: activelock/tutorials/vb BasicTutorial.html,NONE,1.1
Brought to you by:
ialkan
From: Thanh H. T. <th...@us...> - 2003-11-26 05:57:04
|
Update of /cvsroot/activelock/activelock/tutorials/vb In directory sc8-pr-cvs1:/tmp/cvs-serv24465 Added Files: BasicTutorial.html Log Message: VB Tutorial for ActiveLock 2 --- NEW FILE: BasicTutorial.html --- <!-- TODO's: ------- - make sure it's printer-friendly - Add a Terminology section at the end --> <html><head> <title>ActiveLock 2: A Basic Tutorial</title> <style>.dtcheading1 { FONT-WEIGHT: bold; FONT-SIZE: 14pt; MARGIN-BOTTOM: 0px } .dtcheading2 { MARGIN-TOP: 0px; FONT-WEIGHT: bold; FONT-SIZE: 12pt } .dtcMajorheading1 { FONT-WEIGHT: bold; FONT-SIZE: 12pt; MARGIN-BOTTOM: 0px } .dtcMajorheading2 { MARGIN-TOP: 0px; FONT-WEIGHT: bold; FONT-SIZE: 12pt; MARGIN-BOTTOM: 0px } .dtcMajorheading3 { FONT-WEIGHT: bold; FONT-SIZE: 12pt } .dtcsubheading { FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px } .dtcsubheadingindent { MARGIN-TOP: 0px; FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 60px; TEXT-ALIGN: left } .dtcbody { MARGIN-TOP: 0px; FONT-SIZE: 10pt } .dtcbulleted { FONT-SIZE: 12pt } .dtcnumbered { FONT-SIZE: 12pt } .dtcbodycr { MARGIN-TOP: 0px; FONT-SIZE: 14px } </style> </head> <body bgcolor="#ffffff"> <center> <h1>ActiveLock 2: A Basic Tutorial</h1> <h3>by<br> <a href="mailto:th...@us...">Thanh Hai Tran</a><br> November 05, 2003 </h3> </center> <hr> <p> <h2>Contents</h2> <ul> <li><a href=#disclaimer>Disclaimer</a> <li><a href=#introduction>Introduction</a> <li><a href=#prerequisites>Prerequisites</a> <li><a href=#step1>Step 1: Generating a Product Key for your application</a> <li><a href=#step2>Step 2: Adding ActiveLock 2 Object Reference to your VB Project</a> <li><a href=#step3>Step 3: Instantiating and Initializing ActiveLock</a> <li><a href=#step4>Step 4: Checking for a Valid License</a> <li><a href=#step5>Step 5: License Registration</a> <li><a href=#step6>Step 6: Let's Get A Little More Advanced</a> <li><a href=#resources>Resources</a> </ul> <a name="disclaimer"><h2>Disclaimer</h2></a> <blockquote> <pre> USE OF ACTIVELOCK 2 TUTORIALS IS ENTIRELY AT YOUR OWN RISK! THE INFORMATION IN THESE TUTORIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ARISING FROM THE COURSE OF DEALING BETWEEN THE PARTIES AND USAGE OF TRADE. THE ENTIRE RISK AS TO THE RESULTS AND PERFORMANCE OF THE INSTRUCTIONS AND INFORMATION IS ASSUMED BY THE USER. THE AUTHOR OF THESE TUTORIALS WILL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, INDIRECT, OR SIMILAR DAMAGES DUE TO LOSS OF INFORMATION OR DATA, LOSS OF PROFITS, BUSINESS INTERRUPTION, INJURY, OR ANY OTHER DAMAGES, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. </pre> </blockquote> <a name="introduction"><h2>Introduction</h2></a> <blockquote> So you've installed the latest and greatest ActiveLock 2 release, and now you're wondering how the heck you're going use this thing, right? Well, read on, my friend. This tutorial was written just for you. We will walk through a step-by-step process of putting ActiveLock 2 to work in your VB application. </blockquote> <a name="prerequisites"><h2>Prerequisites</h2></a> <blockquote> <p>This tutorial was created using ActiveLock 2.0.4. Therefore, please ensure that you have the same version (or later) installed on your system before you proceed any further. For the latest ActiveLock 2 release, check <a href="http://sourceforge.net/projects/activelock/">here</a>. </blockquote> <a name="step1"><h2>Step 1: Generating a Product Key for your application</h2></a> <blockquote> <ol> <li>Start the generator application, alugen.exe. <li>Enter your application name in the <b>Name</b> text box. e.g. MyApp <li>Enter your application version in the <b>Version</b> text box. e.g. 1.0 <li>Click the <b>Generate</b> button to generate the Product Keys. <li>When the Product VCode and GCode generation process is complete, click <b>Add To Product List</b> button to add/save the product into the product database, to be used later for license key generation. <li>Make note of the generated VCode. You will use this code later within your application. <img src="images/alugen.jpg"><br> Note that because of its length, the complete code may not be fully visible in the text box. You'll need to double-click on the text box and do a Ctrl-C operation if you want to copy the entire code. </ol> </blockquote> <a name="step2"><h2>Step 2: Adding ActiveLock 2 Object Reference to your VB Project</h2></a> <blockquote> <ol> <li>Using ALUGEN to generate a Product Key for your application <li>Open your .vbp project in VB, and then select <b>References</b> from the <b>Project</b> menu. <li>Scroll down on the list until you see <b>ActiveLock Object Library 2.0</b>, then select by clicking on the empty checkbox beside it. <img src="images/addref.jpg"> </ol> </blockquote> <a name="step3"><h2>Step 3: Instantiating and Initializing ActiveLock</h2></a> <blockquote> <ol> <li>Somewhere within your app, declare an object reference to ActiveLock2.IActiveLock. <blockquote> <pre> 1 Private ActiveLock As ActiveLock2.IActiveLock </pre> </blockquote> <li>Also declare a reference to ActiveLock2.ActiveLockEventNotifier so that you can receive COM events sent by ActiveLock 2. <blockquote> <pre> 2 Private WithEvents ActiveLockEventSink As ActiveLockEventNotifier </pre> </blockquote> <li>Decide on a place within your application where initialization usually takes places, within main form's Form_Load() for example, and add these ActiveLock initialization code: <blockquote> <code> <pre> 3 ' Obtain an instance of ActiveLock object 4 Set ActiveLock = ActiveLock2.NewInstance() 5 6 ' Specify where the license file is 7 ActiveLock.KeyStoreType = alsFile 8 ActiveLock.KeyStorePath = App.path & "\myapp.lic" 9 10 ' Obtain the EventNotifier so that we can receive notifications from AL. 11 Set ActiveLockEventSink = ActiveLock.EventNotifier 12 13 ' Specify the name of the product that will be locked through AL. 14 ActiveLock.SoftwareName = "MyApp" 15 16 ' Specify your product code. 17 ' This code will be used later by ActiveLock to validate license keys. 18 ActiveLock.SoftwareCode = "AAAAB3NzaC1yc2EAAAABJQAAAIB9JNUb5AAI7xnlCRB2muU0PO/Q5jY/...." 19 20 ' Specify product version 21 ActiveLock.SoftwareVersion = "1.0" 22 23 ' Specify Lock Type as Lock-to-HardDrive. ' The System drive (where Windows is installed) will be used as part of the lock key. 24 ActiveLock.LockType = lockHD </pre> </code> </blockquote> <li>In line 8 above, we specified the path to the license file. We will now create an empty license file for ActiveLock to use. Simply start up NotePad or your favourite Text Editor, leave the file content blank, and save it under your application directory by the name of <b>myapp.lic</b>. </ol> </blockquote> <a name="step4"><h2>Step 4: Checking for a Valid License</h2></a> <blockquote> <p>OK. So now you've got ActiveLock successfully initialized. At some point in your application's lifetime, it will need to check for a valid license. This is accomplished by calling IActiveLock's <code>Acquire()</code> method. <code> <pre> 25 ' Attempt to acquire a valid license token 26 On Error GoTo ErrHandler 27 ActiveLock.Acquire ' Acquire will raise an error if no valid license exists. 28 Exit Sub ' Exit Form_Load() 29 ErrHandler: 30 MsgBox "ActiveLock Error: " & Err.Description 31 End Sub </pre> </code> When <code>ActiveLock.Acquire()</code> returns no error, it means you currently have a valid license. At that point you can continue to verify some other properties of the license such as <code>RegisteredDate</code>, <code>RegisteredUser</code>, <code>UsedDays</code>, <code>ExpirationDate</code>, etc... For further information on these properties, refer to the IActiveLock interface in the API Documentation. <p>OK. Based on what you've done so far, if you now try to run your application, you should get this error message: <p><img src="images/nolic.jpg"> </blockquote> <a name="step5"><h2>Step 5: License Registration</h2></a> <blockquote> <p>Your application must provide a facility for your users to request license keys. It needs to tell your users what their installation code is. This is an ActiveLock-computed code that is unique for that user's machine alone. To keep it simple for this tutorial, I will simply use a TextBox on the TutorialApp Form to display the installation code. Let's also add a text box for specifying the registered user. This way, the registered user will now be part of the Installation Code, which means that the liberation will not specific to the machine, but it's also specific to a particular user. The code that re-computes the installation code might look like this: <pre> 32 ' Re-compute Installation Code when "Registered User" changes 33 Private Sub txtUser_Change() 34 txtInstCode = ActiveLock.InstallCode(txtUser) 35 End Sub </pre> <p>Your users will then be instructed to contact you with this Installation Code in exchange for a liberation key to unlock the application. This contact can be done via either a telephone call or an email message. You can also add the capability to do instant activation by having your application connect directly to your web server, accessing an ASP on that server, which will use <b>ALUGENLib</b> installed there to generate the liberation key, and then return the key immediately for registration. But this is a topic for another tutorial :-). For the purpose of this tutorial, I will assume that your customer either calls or emails you the Installation Code. <p>So with the Installation Code in hand, you: <ol> <li>Open up ALUGEN <li>Go to the <b>License Key Generator</b> tab <li>Select <b>MyApp</b> from the Product drop-down list <li>Select a <b>License Type</b>. e.g. Periodic for a license that will expire after x days <li>Set the Expiration date if applicable <li>Paste the InstallationCode into its text box <li>Click the <b>Generate</b> button </ol> <p>Congratulations! You've generated your first ActiveLock 2 liberation key. <br> <img src="images/keygen.jpg"> <p>Now back in your application, you'll need to provide a way for the user to input the liberation key for activation. Again for simplicity's sake, I'll fall back to my favourite TextBox and Command Button combination: <ol> <li>Add a label to the form and give the caption <b>Liberation Key:</b> <li>Add a multi-line Text Box and name it <b>txtLibKey</b> <li>Add a command button and name it <b>cmdReg</b> <li>Add the following code snippet to the cndReg Click event handler: <pre> ' Register the liberation key 36 Private Sub cmdReg_Click() 37 ' Be prepared to handle registration error (e.g. invalid license) 38 On Error GoTo ErrHandler 39 ActiveLock.Register txtLibKey 40 ' No error. This means success! 41 MsgBox "License was successfully registered!" 42 Exit Sub 43 ErrHandler: 44 MsgBox Err.Description 45 End Sub </pre> </ol> <img src="images/keyreg.jpg"> </blockquote> <a name="step6"><h2>Step 6: Let's Get A Little More Advanced</h2></a> <blockquote> <p>So far we've done the very basic steps required to get ActiveLock 2 up and running within your app. This will prevent the very novice of hackers from breaking your protection. But a mediocre hacker will attempt to break it by cracking the ActiveLock 2 dlls, and since ActiveLock is open-source, this can be quite easily done. Therefore, you'll need to employ a few extra stragedies :) <h3>Handling ActiveLockEventNotifier_ValidateValue() Events to Do Some Customized Encryption</h3> <p>If you look inside the license file, you'll see this (note that the long keys have been partially chopped for better formatting within this document): <table CELLPADDING="0" CELLSPACING="0" border="1"> <tr> <td> <pre> [MyApp] ProductKey=AAAAB3NzaC1yc2EAAAABJQAAAIB9JNUb5AAI7xnlCRB2muU0PO/Q5jY/hVz1y..... ProductVersion=1.0 LicenseType=3 LicenseClass=Single Licensee=John Q Public LicenseKey=AAAAB3NzaC1yc2EAAACAQpQF1xrjJcxyKJO8oO7fb2XgDMFwpHmYMSHKje/4t..... RegisteredDate=2003/11/02 LastUsed=2003/11/02 23:07:46 Hash1=7c929f2389d5bf5f026ed4bb85b17add Expiration=2003/12/02 MaxCount=1</pre> </td> </tr> </table> You may have noticed the <code>Hash1</code> license property. The value for this property is an MD5 hash value of the <code>LastUsed</code> property. <code>LastUsed</code> property is used to detect when the user has set their system clock backward in order to continue using the app after its license has expired. To defeat this detection, all the hacker has to do blank the <code>LastUsed</code> property, computes his own MD5 hash for an empty string, enters it into the <code>Hash1</code> property, then he can continue using your application with no problem. To prevent this type of hack, ActiveLock 2 makes use of the <code>ActiveLockEventNotifier_ValidateValue()</code> event. This event allows you to encrypt the <code>LastUsed</code> value using your own encryption technique that only you know, then it will take your encrypted value, and computes an MD5 hash for it, then saves it as the <code>hash1</code> value. <p>Here's an example of a simple encryption implementation: <pre> '' ' Simple encryption of a string: simply multiply every character's ASCII code by 11. ' 46 Private Function Enc(strData As String) As String 47 Dim i&, n& 48 Dim sResult$ 49 n = Len(strData) 50 Dim l As Long 51 For i = 1 To n 52 l = Asc(Mid$(strData, i, 1)) * 11 53 If sResult = "" Then 54 sResult = Hex(l) 55 Else 56 sResult = sResult & "." & Hex(l) 57 End If 58 Next i 59 Enc = sResult 60 End Function </pre> <p>Then, you handle <code>ActiveLockEventNotifier_ValidateValue()</code> event like this: <pre> 61 Private Sub ActiveLockEventSink_ValidateValue(ByRef Value As String) 62 Value = Encrypt(Value) 63 End Sub </pre> <h3>Authenticating ActiveLock 2 DLL To Detect Cracking</h3> <p>There's a saying that security people usually like to say: "a chain is only as strong as its weakest link". Because ActiveLock is open-source, and hence its implementation completely exposed to the public, there is no way for it to employ any "good" anti-cracking technique. In this sense, it can be your weakest link. Your application, on the other hand, is closed-source and therefore a little more difficult to crack. <p>Hackers can either crack the ActiveLock 2 DLL or use the source to build an imposter DLL that pretends to be the real ActiveLock and does anything the hacker wants it to, such as fooling your application into thinking that there is a valid license in the system when in fact there isn't. Therefore, your application must authenticate the ActiveLock 2 DLL before use, and one way to do it is to use the built-in CRC checksum facility that's provided by Windows. Here's the general process of how to use CRC checksum to authenticate the DLL. <ol> <li>First, you compute the CRC checksum activelock2.dll and store it within your source code, possibly encrypted, as a private constant value. <li>Somewhere within your application, typically in the initialization code and before initializing ActiveLock, compute the current CRC checksum of activelock2.dll and compare it against the saved checksum. If they don't match, then the DLL has been cracked. </ol> You can find working code of how this is done by looking in the source code for the example application, ALTestApp, which is included in the ActiveLock 2 distribution. </blockquote> <a name="resources"><h2>Resources</h2></a> <blockquote> For the source code of the little VB app I created for this tutorial, click <a href="Tutorial1_SourceCode.zip">here</a>. <p>Your closest source of information is the API Documentation that's included in the distribution. I strongly recommend that you at least read the section on <code>IActiveLock</code> interface to learn about ways you can interact with ActiveLock. <p>If you get stuck, here are a few other places you can go for help: <dl> <dt><a href="http://lists.sourceforge.net/mailman/listinfo/activelock-users">ActiveLock Users Mailing List</a> <dd>This is the fastest way to get help if you're having trouble with using ActiveLock. <dt><a href="http://activelock.sourceforge.net/boards/">ActiveLock Message Board</a> <dd>You can also post questions and discussions here. This way any newcomers who have not joined our mailing list can also benefit from your discussions. </dl> </blockquote> <hr> <small> ActiveLock<sup><font size=-2>TM</font></sup> is a trademark of Nelson Ferraz <br> Copyright 1998-2002 Nelson Ferraz <br> Copyright 2003 The ActiveLock Software Group (ASG) <br> All material is the property of the contributing authors. <br> </pre> </small> </body></html> |