[ActiveLock-Development] CVS: alugen/lib ALUGENLib.vbp,1.1,1.2 Generator.cls,1.1,1.2 IALUGenerator.c
Brought to you by:
ialkan
From: Thanh H. T. <th...@us...> - 2003-09-22 02:46:29
|
Update of /cvsroot/activelock/alugen/lib In directory sc8-pr-cvs1:/tmp/cvs-serv8615 Modified Files: ALUGENLib.vbp Generator.cls IALUGenerator.cls ProductInfo.cls alugen.dll Log Message: ALUGENLib is now able to generate a valid license key. Limited testing has been done; will do more when I have more free time. Index: ALUGENLib.vbp =================================================================== RCS file: /cvsroot/activelock/alugen/lib/ALUGENLib.vbp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ALUGENLib.vbp 24 Aug 2003 18:06:36 -0000 1.1 +++ ALUGENLib.vbp 22 Sep 2003 02:46:02 -0000 1.2 @@ -20,7 +20,7 @@ VersionCompatible32="1" MajorVer=2 MinorVer=0 -RevisionVer=1 +RevisionVer=2 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="The ActiveLock Software Group" Index: Generator.cls =================================================================== RCS file: /cvsroot/activelock/alugen/lib/Generator.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Generator.cls 24 Aug 2003 18:06:36 -0000 1.1 +++ Generator.cls 22 Sep 2003 02:46:02 -0000 1.2 @@ -46,7 +46,7 @@ ' This is a concrete implementation of the IALUGenerator interface. ' ' @author th...@us... -' @version 2.0.0 +' @version 2.0.2 ' @date 20030815 ' '* /////////////////////////////////////////////////////////////////////// @@ -61,7 +61,10 @@ ' /////////////////////////////////////////////////////////////////////// ' @history ' <pre> -' 08.15.03 - th2tran - Created +' 08.15.03 - th2tran - Created +' 09.21.03 - th2tran - Implemented IALUGenerator_RetrieveProduct() +' - Finished implementing IALUGenerator_GenKey() +' - Dumped ActiveLockEventNotifier. Don't neeed it here. ' ' </pre> @@ -69,18 +72,11 @@ ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// Option Explicit +Option Base 0 Implements IALUGenerator Private MyActiveLock As ActiveLock2.IActiveLock Private MyIniFile As New ActiveLockUtil.INIFile -Private WithEvents ActiveLockEventSink As ActiveLockEventNotifier -Attribute ActiveLockEventSink.VB_VarHelpID = -1 - -Private Sub ActiveLockEventSink_ValidateValue(ByVal Value As String, Result As String) - '@todo Encrypt Value using the private key of the product specified in MyActiveLock's IActiveLock_SoftwareName and IActiveLock_SoftwareVersion - ' By now, MyActiveLock is currently set with a current ProductName and ProductVer - ' We need to retrieve the private key for it from MyIniFile and use that key to encrypt -End Sub '' ' Returns IActiveLock interface @@ -93,13 +89,20 @@ Private Sub Class_Initialize() ' Initialize AL Set MyActiveLock = ActiveLock2.NewInstance() - ' Obtain the EventNotifier so that we can receive notifications from AL. - Set ActiveLockEventSink = MyActiveLock.EventNotifier End Sub -Private Function IALUGenerator_RetrieveProducts() As ProductInfo() - '@todo Retrieve all product information from INI. Return as an array. -End Function +'' +' Loads Product Info from the specified INI section. +' +Private Sub LoadProdInfo(Section As String, ProdInfo As ProductInfo) + With MyIniFile + .Section = Section + ProdInfo.Name = .Values("Name") + ProdInfo.Version = .Values("Version") + ProdInfo.Code1 = .Values("Code1") + ProdInfo.Code2 = .Values("Code2") + End With +End Sub ''' ' IALUGenerator Interface implementations @@ -108,12 +111,28 @@ With MyIniFile ' Section name has to contain ProdName and ProdVer in order to be unique .Section = ProdInfo.Name & " " & ProdInfo.Version + .Values("Name") = ProdInfo.Name .Values("Version") = ProdInfo.Version .Values("Code1") = ProdInfo.Code1 '@todo Encrypt code1 and code2, possibly using something as simple as modCrypto.bas .Values("Code2") = ProdInfo.Code2 End With End Sub +Private Function IALUGenerator_RetrieveProducts() As ProductInfo() + ' Retrieve all product information from INI. Return as an array. + Dim arrProdInfos() As ProductInfo + Dim Count%: Count = 0 + Dim iniCount% + Dim arrSections() As String + iniCount = MyIniFile.EnumSections(arrSections) + For Count = 0 To iniCount - 1 + ReDim Preserve arrProdInfos(Count) + Set arrProdInfos(Count) = New ProductInfo + LoadProdInfo arrSections(Count), arrProdInfos(Count) + Next + IALUGenerator_RetrieveProducts = arrProdInfos +End Function + Private Function IALUGenerator_RetrieveProduct(ByVal Name As String, ByVal Ver As String) As ProductInfo '@todo Error Handling - Need to return Nothing if store file doesn't contain the product Dim ProdInfo As New ProductInfo @@ -136,7 +155,7 @@ MyIniFile.File = RHS End Property -Private Function IALUGenerator_GenKey(ByVal Name As String, ByVal Ver As String, ByVal ReqCode As String, LicType As Long, ExpireDate As String) As String +Private Function IALUGenerator_GenKey(ActiveLock As ActiveLock2.IActiveLock, ByVal ReqCode As String, ExpireDate As String) As String ' Take request code and decrypt it. Dim strReq As String strReq = ActiveLock2.Base64Decode(ReqCode) @@ -148,31 +167,49 @@ Dim strRegDate As String strRegDate = Format(Now(), "yyyy/mm/dd") Dim strEncrypted As String - ActiveLockEventSink_ValidateValue strRegDate, strEncrypted + ' @todo Rethink this bit about encrypting the dates. + ' We need to keep in mind that the app does not have access to the private key, so and any decryption that requires private key + ' would not be possible. + ' Perhaps instead of encrypting, we could do MD5 hash of (regdate+lockcode)? + 'ActiveLockEventSink_ValidateValue strRegDate, strEncrypted ' hash it - strEncrypted = ActiveLock2.MD5Hash(strEncrypted) + 'strEncrypted = ActiveLock2.MD5Hash(strEncrypted) + strEncrypted = strRegDate ' get software codes Dim ProdInfo As ProductInfo - Set ProdInfo = IALUGenerator_RetrieveProduct(Name, Ver) + Set ProdInfo = IALUGenerator_RetrieveProduct(ActiveLock.SoftwareName, ActiveLock.SoftwareVersion) '@todo Check for "ProdInfo Is Nothing" and handle appropriately Dim Lic As ProductLicense - Set Lic = ActiveLock2.CreateProductLicense(Name, ProdInfo.Code1, _ - Ver, MyActiveLock.LockType, MyActiveLock.LicenseType, strUser, ExpireDate, , strRegDate, strEncrypted) + With ActiveLock + Set Lic = ActiveLock2.CreateProductLicense(ProdInfo.Name, ProdInfo.Code1, _ + ProdInfo.Version, .LockType, .LicenseType, strUser, ExpireDate, , strRegDate, strEncrypted) + End With Dim strLic As String ' encrypt Product license using the MAC - strLic = MyActiveLock.LockCode(Lic) + strLic = MyActiveLock.LockCode(Lic) & vbLf & strLock +Debug.Print "strLic: " & vbCrLf & strLic ' sign it Dim strSig As String strSig = ActiveLock2.RSASign(ProdInfo.Code1, ProdInfo.Code2, 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 +' Print some info for debugging purposes +Debug.Print "Code1: " & ProdInfo.Code1 +Debug.Print "Lic: " & strLic +Debug.Print "Lic hash: " & ActiveLock2.MD5Hash(strLic) +Debug.Print "LicKey: " & strLicKey +Debug.Print "Sig: " & strSig +Debug.Print "Verify: " & ActiveLock2.RSAVerify(ProdInfo.Code1, strLic, ActiveLock2.Base64Decode(strLicKey)) +Debug.Print "====================================================" + + ' Serialize it into a formatted string Dim strLibKey As String Lic.Save strLibKey IALUGenerator_GenKey = strLibKey Index: IALUGenerator.cls =================================================================== RCS file: /cvsroot/activelock/alugen/lib/IALUGenerator.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IALUGenerator.cls 24 Aug 2003 18:06:36 -0000 1.1 +++ IALUGenerator.cls 22 Sep 2003 02:46:02 -0000 1.2 @@ -46,7 +46,7 @@ ' Interface for the ActiveLock Universal Generator (ALUGEN) ' ' @author th...@us... -' @version 2.0.0 +' @version 2.0.2 ' @date 20030815 ' '* /////////////////////////////////////////////////////////////////////// @@ -63,6 +63,10 @@ ' @history ' <pre> ' 08.15.03 - th2tran - Created +' 09.21.03 - th2tran - Changed GenKey() interface signature from +' GenKey(ByVal Name As String, ByVal Ver As String, ByVal ReqCode As String, LicType As Long, ExpireDate As String) +' to +' GenKey(objActiveLock As IActiveLock, ByVal ReqCode As String, ExpireDate As String) ' ' </pre> @@ -116,12 +120,10 @@ '' ' Generates liberation key for the specified product. ' -' @param Name Product Name -' @param Ver Product Version -' @param ReqCode Key Request Code -' @param LicType License Type -' @param ExpDate Expiration Date +' @param objActiveLock ActiveLock object. Needed for software name, version, code, etc... +' @param ReqCode Key Request Code +' @param ExpireDate Expiration Date ' -Public Function GenKey(ByVal Name As String, ByVal Ver As String, ByVal ReqCode As String, LicType As Long, ExpireDate As String) As String +Public Function GenKey(objActiveLock As IActiveLock, ByVal ReqCode As String, ExpireDate As String) As String End Function Index: ProductInfo.cls =================================================================== RCS file: /cvsroot/activelock/alugen/lib/ProductInfo.cls,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ProductInfo.cls 24 Aug 2003 18:06:36 -0000 1.1 +++ ProductInfo.cls 22 Sep 2003 02:46:02 -0000 1.2 @@ -46,7 +46,7 @@ ' This class encapsulates information about a product maintained by ALUGEN. ' ' @author th...@us... -' @version 2.0.0 +' @version 2.0.2 ' @date 20030815 ' '* /////////////////////////////////////////////////////////////////////// @@ -62,6 +62,8 @@ ' @history ' <pre> ' 08.15.03 - th2tran - Created +' 09.21.03 - th2tran - Fixed bug: Name() property wasn't implemented. +' Originally, the methods were there but had no code. ' ' </pre> @@ -79,10 +81,10 @@ ' Product Name ' Public Property Get Name() As String - + Name = mstrName End Property Friend Property Let Name(ByVal sName As String) - + mstrName = sName End Property '' Index: alugen.dll =================================================================== RCS file: /cvsroot/activelock/alugen/lib/alugen.dll,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 Binary files /tmp/cvsOVsCkV and /tmp/cvsM33SxI differ |