[ActiveLock-Development] CVS: activelock2/src ActiveLock.cls,1.7,1.8 Globals.cls,1.8,1.9 modActiveLo
Brought to you by:
ialkan
From: Thanh H. T. <th...@us...> - 2003-07-31 07:04:56
|
Update of /cvsroot/activelock/activelock2/src In directory sc8-pr-cvs1:/tmp/cvs-serv13676 Modified Files: ActiveLock.cls Globals.cls modActiveLock.bas modMd5.bas ActiveLock2.dll Log Message: Implemented Task 82242 - Checksumming the DLL to prevent cracking. IActiveLock_Init() to check ALCrypto.dll. As for ActiveLock2.dll, since this is an operation that need to be perform from the client application's side, all we can do is add some helper routines that they can use to do this. See Test App for a demo on how they are used. Index: ActiveLock.cls =================================================================== RCS file: /cvsroot/activelock/activelock2/src/ActiveLock.cls,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ActiveLock.cls 29 Jul 2003 18:49:42 -0000 1.7 +++ ActiveLock.cls 31 Jul 2003 07:04:53 -0000 1.8 @@ -55,9 +55,9 @@ ' / MODULE TO DO LIST / ' /////////////////////////////////////////////////////////////////////// ' -' [ ] IActiveLock_Acquire: Check if license has not expired ' [ ] Implement IActiveLock_Release ' [ ] Implement IActiveLock_Transfer +' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// @@ -65,7 +65,7 @@ ' 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() ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// @@ -98,7 +98,14 @@ End Property Private Sub IActiveLock_Init(Arg1 As Variant, ParamArray OtherArgs() As Variant) - ' Do nothing. No extra initialization needed for now. + ' Checksum ALCrypto.dll + Const ALCRYPTO_MD5$ = "ac0dd6351905e6d688199146165170c4" + 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 End Sub Private Sub IActiveLock_Acquire() @@ -106,7 +113,7 @@ 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" @@ -281,7 +288,7 @@ Private Function IActiveLock_LockCode(Optional Lic As ProductLicense = Nothing) As String Dim strLock As String - + If (mLockTypes And lockMAC) = lockMAC Then strLock = strLock & modMACAddress.GetMACAddress() End If Index: Globals.cls =================================================================== RCS file: /cvsroot/activelock/activelock2/src/Globals.cls,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Globals.cls 29 Jul 2003 18:49:42 -0000 1.8 +++ Globals.cls 31 Jul 2003 07:04:53 -0000 1.9 @@ -59,10 +59,11 @@ ' / MODULE CHANGE LOG / ' /////////////////////////////////////////////////////////////////////// ' -' 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.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 ' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / @@ -94,6 +95,7 @@ alerrLicenseTampered = &H80040004 alerrLockChanged = &H80040005 alerrKeyStoreInvalid = &H80040010 + alerrFileTampered = &H80040011 End Enum '' @@ -226,3 +228,4 @@ rsa_freekey Key RSAVerify = rc End Function + Index: modActiveLock.bas =================================================================== RCS file: /cvsroot/activelock/activelock2/src/modActiveLock.bas,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- modActiveLock.bas 28 Jul 2003 06:35:30 -0000 1.5 +++ modActiveLock.bas 31 Jul 2003 07:04:53 -0000 1.6 @@ -49,6 +49,7 @@ ' /////////////////////////////////////////////////////////////////////// ' ' 07.07.03 - mcrute - Updated the header comments for this file. +' 07.30.03 - th2tran - New routines to do MD5 hashes of TypeLibs. ' ' ' /////////////////////////////////////////////////////////////////////// @@ -85,6 +86,9 @@ Public Declare Function rsa_decrypt Lib "ALCrypto" (ByVal CryptType As Long, ByVal data As String, dLen As Long, ptrKey As RSAKey) As Long Public Declare Function rsa_sign Lib "ALCrypto" (ByRef ptrKey As RSAKey, ByVal data As String, ByVal dLen As Long, ByVal sig As String, ByRef sLen As Long) As Long Public Declare Function rsa_verifysig Lib "ALCrypto" (ByRef ptrKey As RSAKey, ByVal sig As String, ByVal sLen As Long, ByVal data As String, ByVal dLen As Long) As Long + +Public Declare Function md5_hash Lib "ALCrypto" (ByVal inData As String, ByVal nDataLen As Long, ByVal outData As String) As Long + Type PhaseType exponential As Byte startpoint As Byte @@ -108,9 +112,9 @@ Private Crypto As New BlowFish -' ActiveLock Data Encryption Key +' ActiveLock Encryption Key ' !!!WARNING!!! It is highly recommended that you change this key for your version of ActiveLock before deploying your app. -Public Const ENCRYPT_KEY$ = "MGFJzuX2wGiuXAmOWguXQVeTrnDFRm0SUEPgda1feCI=" +Public Const ENCRYPT_KEY$ = "AAAAgEPRFzhQEF7S91vt2K6kOcEdDDe5BfwNiEL30/+ozTFHc7cZctB8NIlS++ZR//D3AjSMqScjh7xUF/gwvUgGCjiExjj1DF/XWFWnPOCfF8UxYAizCLZ9fdqxb1FRpI5NoW0xxUmvxGjmxKwazIW4P4XVi/+i1Bvh2qQ6ri3whcsNAAAAQQCyWGsbJKO28H2QLYH+enb7ehzwBThqfAeke/Gv1Te95yIAWme71I9aCTTlLsmtIYSk9rNrp3sh9ItD2Re67SE7AAAAQQCAookH1nws1gS2XP9cZTPaZEmFLwuxlSVsLQ5RWmd9cuxpgw5y2gIskbL4c+4oBuj0IDwKtnMrZq7UfV9I5VfVAAAAQQCEnyAuO0ahXH3KhAboop9+tCmRzZInTrDYdMy23xf3PLCLd777dL/Y2Y+zmaH1VO03m6iOog7WLiN4dCL7m+Im" ' RSA Private Key Public Const MAGICNUMBER_YES& = &HEFCDAB89 Public Const MAGICNUMBER_NO& = &H98BADCFE @@ -123,6 +127,8 @@ Private fInit As Boolean ' flag to indicate that module initialization has been done Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) +Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long + Public Sub Init() If fInit Then Exit Sub @@ -220,6 +226,32 @@ End If End Function +'' +' Reads a binary file into the sData buffer. +' Returns the number of bytes read. +' +Public Function ReadFile(ByVal sPath As String, ByRef sData As String) As Long + Dim hFile As Integer + ' obtain next free file handle + hFile = FreeFile + ' read file content + Open sPath For Binary Access Read As #hFile + On Error GoTo Hell + Debug.Print "File len: " & LOF(hFile) + ' allocate enough memory to hold the data + sData = String(LOF(hFile), 0) + ' read from file + Get hFile, , sData + Debug.Print "Bytes read: " & Len(sData) + Close #hFile + ReadFile = Len(sData) + Exit Function +Hell: + Close #hFile + Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext +End Function + + '' @@ -240,4 +272,45 @@ Debug.Print "Progress Update received " & param & ", action: " & action & ", iprogress: " & iprogress End Sub +'' +' Computes an MD5 hash of the type library containing the object. +' +Public Function MD5HashTypeLib(obj As IUnknown) As String + ' Retrieve DLL Path of self + ' Use late-binding so that the user doesn't have to add it to their project reference + Dim tliApp As Object + Set tliApp = CreateObject("TLI.TLIApplication") + Dim ti As Object ' actually TLI.TypeInfo + Set ti = tliApp.ClassInfoFromObject(obj) + Dim strDllPath As String + strDllPath = ti.Parent.ContainingFile + MD5HashTypeLib = MD5HashFile(strDllPath) +End Function + +'' +' Computes an MD5 hash of the specified file. +' +Public Function MD5HashFile(ByVal strPath As String) As String +Debug.Print "Hashing file " & strPath +Debug.Print "File Date: " & FileDateTime(strPath) + ' read and hash the content + Dim sData As String, nFileLen + nFileLen = ReadFile(strPath, sData) + Dim sHash As String: sHash = String(32, 0) + ' hash it + md5_hash sData, nFileLen, sHash + MD5HashFile = sHash +End Function + +'' +' Check if we're running inside the VB6 IDE +Private Function IsRunningInIde() As Boolean + Dim strFileName As String + Dim lngCount As Long + +10 strFileName = String(255, 0) +20 lngCount = GetModuleFileName(App.hInstance, strFileName, 255) +30 strFileName = Left(strFileName, lngCount) +40 IsRunningInIde = UCase(Right(strFileName, 7)) = "VB6.EXE" +End Function Index: modMd5.bas =================================================================== RCS file: /cvsroot/activelock/activelock2/src/modMd5.bas,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- modMd5.bas 8 Jul 2003 03:26:44 -0000 1.3 +++ modMd5.bas 31 Jul 2003 07:04:53 -0000 1.4 @@ -10,6 +10,20 @@ ' /////////////////////////////////////////////////////////////////////// ' ' +'* /////////////////////////////////////////////////////////////////////// +' / MODULE TO DO LIST / +' /////////////////////////////////////////////////////////////////////// +' +' [ ] Nothing to do :) +' +' /////////////////////////////////////////////////////////////////////// +' / MODULE CHANGE LOG / +' /////////////////////////////////////////////////////////////////////// +' +' 07.07.03 - mcrute - Updated the header comments for this file. +' 07.31.03 - th2tran - Changed Integer defs to Long to handle large data. +' +' ' /////////////////////////////////////////////////////////////////////// ' / MODULE CODE BEGINS BELOW THIS LINE / ' /////////////////////////////////////////////////////////////////////// @@ -43,46 +57,46 @@ Private Function MD5Round(strRound As String, a As Long, b As Long, c As Long, d As Long, X As Long, s As Long, ac As Long) As Long Select Case strRound - + Case Is = "FF" a = MD5LongAdd4(a, (b And c) Or (Not (b) And d), X, ac) a = MD5Rotate(a, s) a = MD5LongAdd(a, b) - + Case Is = "GG" a = MD5LongAdd4(a, (b And d) Or (c And Not (d)), X, ac) a = MD5Rotate(a, s) a = MD5LongAdd(a, b) - + Case Is = "HH" a = MD5LongAdd4(a, b Xor c Xor d, X, ac) a = MD5Rotate(a, s) a = MD5LongAdd(a, b) - + Case Is = "II" a = MD5LongAdd4(a, c Xor (b Or Not (d)), X, ac) a = MD5Rotate(a, s) a = MD5LongAdd(a, b) - + End Select - + End Function Private Function MD5Rotate(lngValue As Long, lngBits As Long) As Long - + Dim lngSign As Long Dim lngI As Long - + lngBits = (lngBits Mod 32) - + If lngBits = 0 Then MD5Rotate = lngValue: Exit Function - + For lngI = 1 To lngBits lngSign = lngValue And &HC0000000 lngValue = (lngValue And &H3FFFFFFF) * 2 lngValue = lngValue Or ((lngSign < 0) And 1) Or (CBool(lngSign And &H40000000) And &H80000000) Next - + MD5Rotate = lngValue End Function @@ -91,14 +105,14 @@ Dim sngNum As Single, lngnum As Long Dim strResult As String - + sngNum = Rnd(2147483648#) strResult = CStr(sngNum) - + strResult = Replace(strResult, "0.", "") strResult = Replace(strResult, ".", "") strResult = Replace(strResult, "E-", "") - + TRID = strResult End Function @@ -106,58 +120,58 @@ Private Function MD564Split(lngLength As Long, bytBuffer() As Byte) As String Dim lngBytesTotal As Long, lngBytesToAdd As Long - Dim intLoop As Integer, intLoop2 As Integer, lngTrace As Long - Dim intInnerLoop As Integer, intLoop3 As Integer - + Dim intLoop As Long, intLoop2 As Long, lngTrace As Long + Dim intInnerLoop As Long, intLoop3 As Long + lngBytesTotal = lngTrack Mod 64 lngBytesToAdd = 64 - lngBytesTotal lngTrack = (lngTrack + lngLength) - + If lngLength >= lngBytesToAdd Then For intLoop = 0 To lngBytesToAdd - 1 arrSplit64(lngBytesTotal + intLoop) = bytBuffer(intLoop) Next intLoop - + MD5Conversion arrSplit64 - + lngTrace = (lngLength) Mod 64 For intLoop2 = lngBytesToAdd To lngLength - intLoop - lngTrace Step 64 For intInnerLoop = 0 To 63 arrSplit64(intInnerLoop) = bytBuffer(intLoop2 + intInnerLoop) Next intInnerLoop - + MD5Conversion arrSplit64 - + Next intLoop2 - + lngBytesTotal = 0 Else - + intLoop2 = 0 - + End If - + For intLoop3 = 0 To lngLength - intLoop2 - 1 - + arrSplit64(lngBytesTotal + intLoop3) = bytBuffer(intLoop2 + intLoop3) - + Next intLoop3 - + End Function Private Function MD5StringArray(strInput As String) As Byte() - - Dim intLoop As Integer + + Dim intLoop As Long Dim bytBuffer() As Byte ReDim bytBuffer(Len(strInput)) - + For intLoop = 0 To Len(strInput) - 1 bytBuffer(intLoop) = Asc(Mid(strInput, intLoop + 1, 1)) Next intLoop - + MD5StringArray = bytBuffer - + End Function Private Sub MD5Conversion(bytBuffer() As Byte) @@ -165,14 +179,14 @@ Dim X(16) As Long, a As Long Dim b As Long, c As Long Dim d As Long - + a = arrLongConversion(1) b = arrLongConversion(2) c = arrLongConversion(3) d = arrLongConversion(4) - + MD5Decode 64, X, bytBuffer - + MD5Round "FF", a, b, c, d, X(0), S11, -680876936 MD5Round "FF", d, a, b, c, X(1), S12, -389564586 MD5Round "FF", c, d, a, b, X(2), S13, 606105819 @@ -206,7 +220,7 @@ MD5Round "GG", d, a, b, c, X(2), S22, -51403784 MD5Round "GG", c, d, a, b, X(7), S23, 1735328473 MD5Round "GG", b, c, d, a, X(12), S24, -1926607734 - + MD5Round "HH", a, b, c, d, X(5), S31, -378558 MD5Round "HH", d, a, b, c, X(8), S32, -2022574463 MD5Round "HH", c, d, a, b, X(11), S33, 1839030562 @@ -223,7 +237,7 @@ MD5Round "HH", d, a, b, c, X(12), S32, -421815835 MD5Round "HH", c, d, a, b, X(15), S33, 530742520 MD5Round "HH", b, c, d, a, X(2), S34, -995338651 - + MD5Round "II", a, b, c, d, X(0), S41, -198630844 MD5Round "II", d, a, b, c, X(7), S42, 1126891415 MD5Round "II", c, d, a, b, X(14), S43, -1416354905 @@ -240,16 +254,16 @@ MD5Round "II", d, a, b, c, X(11), S42, -1120210379 MD5Round "II", c, d, a, b, X(2), S43, 718787259 MD5Round "II", b, c, d, a, X(9), S44, -343485551 - + arrLongConversion(1) = MD5LongAdd(arrLongConversion(1), a) arrLongConversion(2) = MD5LongAdd(arrLongConversion(2), b) arrLongConversion(3) = MD5LongAdd(arrLongConversion(3), c) arrLongConversion(4) = MD5LongAdd(arrLongConversion(4), d) - + End Sub Private Function MD5LongAdd(lngVal1 As Long, lngVal2 As Long) As Long - + Dim lngHighWord As Long Dim lngLowWord As Long Dim lngOverflow As Long @@ -257,13 +271,13 @@ lngLowWord = (lngVal1 And &HFFFF&) + (lngVal2 And &HFFFF&) lngOverflow = lngLowWord \ 65536 lngHighWord = (((lngVal1 And &HFFFF0000) \ 65536) + ((lngVal2 And &HFFFF0000) \ 65536) + lngOverflow) And &HFFFF& - + MD5LongAdd = MD5LongConversion((lngHighWord * 65536#) + (lngLowWord And &HFFFF&)) End Function Private Function MD5LongAdd4(lngVal1 As Long, lngVal2 As Long, lngVal3 As Long, lngVal4 As Long) As Long - + Dim lngHighWord As Long Dim lngLowWord As Long Dim lngOverflow As Long @@ -276,54 +290,54 @@ End Function Private Sub MD5Decode(intLength As Integer, lngOutBuffer() As Long, bytInBuffer() As Byte) - + Dim intDblIndex As Integer Dim intByteIndex As Integer Dim dblSum As Double - + intDblIndex = 0 - + For intByteIndex = 0 To intLength - 1 Step 4 - + dblSum = bytInBuffer(intByteIndex) + bytInBuffer(intByteIndex + 1) * 256# + bytInBuffer(intByteIndex + 2) * 65536# + bytInBuffer(intByteIndex + 3) * 16777216# lngOutBuffer(intDblIndex) = MD5LongConversion(dblSum) intDblIndex = (intDblIndex + 1) - + Next intByteIndex End Sub Private Function MD5LongConversion(dblValue As Double) As Long - + If dblValue < 0 Or dblValue >= OFFSET_4 Then Error 6 - + If dblValue <= MAXINT_4 Then MD5LongConversion = dblValue Else MD5LongConversion = dblValue - OFFSET_4 End If - + End Function Private Sub MD5Finish() - + Dim dblBits As Double Dim arrPadding(72) As Byte Dim lngBytesBuffered As Long - + arrPadding(0) = &H80 - + dblBits = lngTrack * 8 - + lngBytesBuffered = lngTrack Mod 64 - + If lngBytesBuffered <= 56 Then MD564Split (56 - lngBytesBuffered), arrPadding Else MD564Split (120 - lngTrack), arrPadding End If - - + + arrPadding(0) = MD5LongConversion(dblBits) And &HFF& arrPadding(1) = MD5LongConversion(dblBits) \ 256 And &HFF& arrPadding(2) = MD5LongConversion(dblBits) \ 65536 And &HFF& @@ -332,45 +346,45 @@ arrPadding(5) = 0 arrPadding(6) = 0 arrPadding(7) = 0 - + MD564Split 8, arrPadding - + End Sub Private Function MD5StringChange(lngnum As Long) As String - + Dim bytA As Byte Dim bytB As Byte Dim bytC As Byte Dim bytD As Byte - + bytA = lngnum And &HFF& If bytA < 16 Then MD5StringChange = "0" & Hex(bytA) Else MD5StringChange = Hex(bytA) End If - + bytB = (lngnum And &HFF00&) \ 256 If bytB < 16 Then MD5StringChange = MD5StringChange & "0" & Hex(bytB) Else MD5StringChange = MD5StringChange & Hex(bytB) End If - + bytC = (lngnum And &HFF0000) \ 65536 If bytC < 16 Then MD5StringChange = MD5StringChange & "0" & Hex(bytC) Else MD5StringChange = MD5StringChange & Hex(bytC) End If - + If lngnum < 0 Then bytD = ((lngnum And &H7F000000) \ 16777216) Or &H80& Else bytD = (lngnum And &HFF000000) \ 16777216 End If - + If bytD < 16 Then MD5StringChange = MD5StringChange & "0" & Hex(bytD) Else @@ -392,13 +406,13 @@ ReDim arrSplit64(63) Dim bytBuffer() As Byte bytBuffer = MD5StringArray(strMessage) - + MD5Start MD564Split Len(strMessage), bytBuffer MD5Finish - + Hash = MD5Value - + End Function Private Sub MD5Start() @@ -408,6 +422,6 @@ arrLongConversion(2) = MD5LongConversion(4023233417#) arrLongConversion(3) = MD5LongConversion(2562383102#) arrLongConversion(4) = MD5LongConversion(271733878#) - + End Sub Index: ActiveLock2.dll =================================================================== RCS file: /cvsroot/activelock/activelock2/src/ActiveLock2.dll,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 Binary files /tmp/cvs3uihri and /tmp/cvsAKXfWt differ |