Lập trỡnh ứng dụng

Một phần của tài liệu LUẬN VĂN: NGHIÊN CỨU CÁC GIẢI PHÁP ĐẢM BẢO AN NINH AN TOÀN CHO MẠNG KHÔNG DÂY potx (Trang 86 - 108)

3.2.2.1. Thiết kế và mó nguồn cửa sổ chớnh của chương trỡnh

Chương trỡnh chớnh

Cửa sổ chớnh của chương trỡnh được thiết kế như giao diện của Windows Explorer và tớch hợp với cỏc tớnh năng cơ bản của Windows. Dưới đõy là giao diện cửa sổ chớnh của chương trỡnh, được tổ chức bao gồm trờn cựng là Menu để lựa chọn cỏc chức năng chi tiết. Dưới đú là thanh cụng cụ (Toolbar) với cỏc chức năng cơ bản. Phần chớnh là hai cửa sổ xếp ngang nhau, bờn trỏi hiển thị cỏc ổ đĩa và thư mục (folder) cú trong mỏy tớnh của người sử dụng; bờn phải hiển thị cửa sổ thư mục và File cú trong ổ đĩa và thư mục được chọn từ cửa sổ bờn trỏi. Dưới cựng là thanh trạng thỏi, thể hiện cỏc thuộc tớnh của ổ đĩa, thư mục hiện hành được chọn hoặc cỏc hoạt động của chương trỡnh.

Hỡnh 3.6: Thiết kế cửa sổ chớnh của chương trỡnh

Dưới đõy là một phần mó nguồn của form này: Option Explicit

Private HidenFile As String '--- Private WinDir As String Private SysDir As String Private TempDir As String

Private SourcePath As String Private sFolder As String 'Private sFile As String Private sName As String Private sExtension As String Private sSize As String Private sType As String Private sModified As String Private sTime As String Private sCreated As String Private sAccessed As String Private sAttribute As String Private sMsDos As String Private sNone As String Private m_MyDocs As String '--- Private Start As Long Private FvFilter As Variant Private TypeNew() As FTs Private NodeIdx As Integer Private TaskFld As String Private CutCopy As Long '--- Private Enum CBoolean CFalse = 0

CTrue = 1 End Enum

Private m_cxyAutoScroll As Long '---

Private Const SM_CXDRAG = 68 Private Const SM_CYDRAG = 69 '---

Private Const SHGFI_DISPLAYNAME = &H200 Private Const TVGN_ROOT = &H0

'---

Private Const TVIS_EXPANDED = &H20 Private Const TV_FIRST = &H1100

Private Const TVM_EXPAND = (TV_FIRST + 2)

Private Const TVM_GETITEMRECT = (TV_FIRST + 4) Private Const TVM_GETNEXTITEM = (TV_FIRST + 10)

Private Const TVM_SELECTITEM = (TV_FIRST + 11) Private Const TVM_GETITEM = (TV_FIRST + 12) Private Const TVM_SETITEM = (TV_FIRST + 13) Private Const TVM_HITTEST = (TV_FIRST + 17)

Private Const TVM_CREATEDRAGIMAGE = (TV_FIRST + 18) '---

Const MyComputer$ = "MyComputer" Const Desktop$ = "Desktop"

Private Type RECT ' rct Left As Long Top As Long Right As Long Bottom As Long End Type Private m_hwndTV As Long ' TV.hWnd Private m_szDrag As Size

Private ResetNodepic(1 To 20) As ParentPic '---

Private Type Size cx As Long cy As Long End Type

Private Type ParentPic NodeId As Integer NodePic As String End Type

'--- 'For monitor comport

Private Const GENERIC_WRITE = &H40000000 Private Const GENERIC_READ = &H80000000 Private Const FILE_ATTRIBUTE_NORMAL = &H80 Private Const CREATE_NEW = 1

Private Const CREATE_ALWAYS = 2 Private Const OPEN_EXISTING = 3 Private Const OPEN_ALWAYS = 4

Private Const TRUNCATE_EXISTING = 5

Private Declare Function CreateFile Lib "kernel32" _ Alias "CreateFileA" (ByVal lpFileName As String, _

ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _ ByVal lpSecurityAttributes As Long, _

ByVal dwCreationDisposition As Long, _

ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) _ As Long

Private Declare Function CloseHandle Lib "kernel32" ( _ ByVal hObject As Long) As Long

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long '---

Private cFolderSize As Double

Private Function TreeView_GetRoot(hwnd As Long) As Long

TreeView_GetRoot = TreeView_GetNextItem(hwnd, 0, TVGN_ROOT) End Function

Private Function TreeView_GetNextItem(ByVal hwnd As Long, hitem As Long, Flag As Long) As Long

TreeView_GetNextItem = SendMessage(hwnd, TVM_GETNEXTITEM, ByVal Flag, ByVal hitem)

End Function

Private Function TreeView_GetItemRect(ByVal hwnd As Long) As Boolean prc.Left = hitem

TreeView_GetItemRect = SendMessage(hwnd, TVM_GETITEMRECT, ByVal fItemRect, prc)

End Function

Private Function NiceCase(ByVal Nam As String) As String Dim UNam As String, LNam As String

On Error GoTo ProcedureError UNam = Nam: LNam = Nam

CharUpper UNam: CharLower LNam If Nam = UNam Or Nam = LNam Then

' If Nam = UCase$(Nam) Or Nam = LCase$(Nam) Then NiceCase = StrConv(Nam, vbProperCase)

Else

NiceCase = Nam 'already mixed case so leave alone End If

ProcedureExit: Exit Function ProcedureError:

If ErrMsgBox(Me.Name & ".NiceCase") = vbRetry Then Resume Next End Function

Private Function BinarySearchTypeNew(sExt As String) As Integer Dim iLow As Integer

3.2.2.2. Thiết kế và mó nguồn của Form mó húa

Từ cửa số chớnh sau khi đó lựa chọn Mó húa, sẽ xuất hiện cửa sổ hội thoại dưới đõy. Trờn cửa sổ hiển thị danh sỏch, tổng số và dung lượng của cỏc file và thư mục sẽ được mó. Ngoài ra cũn cú cỏc lựa chọn thờm, bớt cỏc file vào danh sỏch, chọn vị trớ sẽ cất giữ file mó trờn ổ đĩa.

Hỡnh 3.7: Thiết kế Form mó húa

Ở đõy, người sử dụng cũng cú thể đặt lại cấu hỡnh cho chương trỡnh như:

- Tự động tạo file mó: Chương trỡnh sẽ tự động tạo ra file mó là tờn của thư mục hay file gắn thờm đuụi của chương trỡnh, lỳc này người sử dụng khụng cần vào tờn file mó. - Xúa file gốc sau khi mó xong: Ngay sau khi mó xong file hoặc thư mục, chương trỡnh sẽ xúa file hay thư mục gốc.

- Mó và nộn dữ liệu: Ngoài việc thư mục và file được mó, chương trỡnh cũn nộn file và thư mục nhằm giảm dung lượng lưu trữ cũng như khi gửi file đi.

- Người sử dụng cú thể lựa chọn thuật toỏn mó dữ liệu của thư mục và file.

- Đặt cấu hỡnh cho khúa phiờn: Khi chọn khúa hay mật khẩu theo phiờn, người dựng chỉ cần vào mật khẩu lỳc đầu cũn trong phiờn làm việc chương trỡnh sẽ mó mà khụng yờu cầu người sử dụng vào khúa hay mật khẩu. Tựy chọn này giỳp thao tỏc nhanh, đơn giản song về mặt bảo mật tớnh an toàn khụng cao do phải lưu khúa phiờn trong bộ nhớ. - Đặt thuộc tớnh cho Smartcard

- …

Cuối cựng, người sử dụng sẽ chọn phương thức mó:  Mó sử dụng khúa

 Mó sử dụng thẻ thụng minh - Smartcard  Mó dựng mật khẩu - password

hoặc thoỏt ra khỏi cửa sổ mó húa trở về cửa sổ chớnh mà khụng thực hiện một cụng việc nào. Dưới đõy là một phần mó nguồn của Module mó húa:

Option Explicit

Private nActiveTime As Integer

Private WithEvents CpBlf1 As clsBlowfish Private WithEvents CpGost As clsGost Private WithEvents Cp3Des As cls3DES Private WithEvents CpTwf1 As clsTwofish Private WithEvents CpSkj As clsSkipjack Private WithEvents CpSrp As clsSerpent Private WithEvents CpTea As clsTEA Private WithEvents CpRjd1 As clsRijndael Private WithEvents CpRC6 As clsRC6 '---

Private WinDir As String Private SysDir As String Private TempDir As String Private SourcePath As String Private sFolder As String 'Private sFile As String Private sName As String Private sExtension As String Private sSize As String Private sType As String Private sModified As String Private sTime As String Private sCreated As String Private sAccessed As String Private sAttribute As String Private sMsDos As String Private sNone As String Private m_MyDocs As String '--- Private Start As Long Private FvFilter As Variant

Private TypeNew() As FTs '--- Private Enum CBoolean CFalse = 0

CTrue = 1 End Enum

Private m_cxyAutoScroll As Long '---

Private Const SM_CXDRAG = 68 Private Const SM_CYDRAG = 69 '---

Private Const SHGFI_DISPLAYNAME = &H200 Private Type Size

cx As Long cy As Long End Type

Private FileCollection As Collection Private Sub cmdOK_Click()

cTypeEnc = "S" EncOrNo = True Me.EncryptAll 'reset after encrypted cCurEncFile = "" EncOrNo = True End Sub

Private Sub Command10_Click() cTypeEnc = "P"

EncOrNo = True Me.EncryptAll 'reset after encrypted cCurEncFile = "" EncOrNo = True End Sub

Private Sub Command6_Click() Unload Me

End Sub

Private Sub Command9_Click() MsgBox "OK click"

End Sub

If cFileSkin <> "" Then Skin1.LoadSkin cFileSkin Skin1.ApplySkin Me.hwnd End If

End Sub

Private Sub Command8_Click() cTypeEnc = "K"

cCancelFolder = True Me.EncryptAll

'reset after encrypted cCurEncFile = "" EncOrNo = True End Sub

Private Sub LVEncFiles_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 2 Then

Me.PopupMenu Me.MnuFile End If

End Sub

Private Sub mnuAddDir_Click()

cCurEncFile = GetBrowseFolder("Select the folder for find decrypttion key", Me) cCurFileOnly = Replace(cCurEncFile, FileNameOnly(cCurEncFile), "")

ReActiveForm End Sub

Private Sub mnuAddFile_Click() On Error Resume Next

DiaOpen.CancelError = True DiaOpen.ShowOpen

cCurEncFile = DiaOpen.Filename

cCurFileOnly = Replace(cCurEncFile, FileNameOnly(cCurEncFile), "") ReActiveForm

End Sub

Private Sub mnuDelete_Click()

If LVEncFiles.ListItems.Count = 0 Then Exit Sub

txtTotalsize.Text = Val(txtTotalsize.Text) - FileLen(LVEncFiles.SelectedItem.key) Me.txtTotalsizeNew.Caption = FormatSize(txtTotalsize.Text)

LVEncFiles.ListItems.Remove LVEncFiles.SelectedItem.Index txtTotalFile.Caption = Val(txtTotalFile.Caption) - 1

End Sub

LVEncFiles.ListItems.Clear txtTotalFile.Caption = 0 txtTotalsize.Text = 0

txtTotalsizeNew.Caption = 0 End Sub

Private Sub mnuExit_Click() Unload Me

End Sub

Private EncryptFolderName As String Private Sub cmdBrow_Click()

On Error Resume Next DiaOpen.ShowSave

txtEncFileName.Text = Mid(DiaOpen.Filename, 1, Len(DiaOpen.Filename) - 3) & "dvd"

End Sub

Private Sub cmdExtCancel_Click() SelfExtrac = False

Unload Me End Sub

Private Sub cmdExtOK_Click() Dim cFileSaveAs As String Dim cFileAdd As String Dim TempCipherAl As String Dim TempComp As Boolean

cFileAdd = Me.txtEncFileName.Text

cFileSaveAs = Mid(cFileAdd, 1, Len(cFileAdd) - 3) & "exe" TempCipherAl = CipherAlgorithm cTypeEnc = "P" TempComp = CompressOrNo CompressOrNo = False CipherAlgorithm = "TWF" Me.EncryptAll

AddToSelfExtract App.Path & "\SelfExtract.dve", cFileAdd, cFileSaveAs SelfExtrac = False Kill cFileAdd CipherAlgorithm = TempCipherAl CompressOrNo = TempComp Unload Me End Sub

ProgressBar.Value = Percent End Sub

Private Sub Cp3Des_Progress(Percent As Long) ProgressBar.Value = Percent

End Sub

Private Sub CpGost_Progress(Percent As Long) ProgressBar.Value = Percent

End Sub

Private Sub CpRC6_Progress(Percent As Long) ProgressBar.Value = Percent

End Sub

3.2.2.3. Thiết kế và mó nguồn của Form giải mó

Khi người dựng cần giải mó, chương trỡnh sẽ hỏi người dựng vào khúa (mật khẩu) tuỳ theo phương thức mó bằng mật khẩu, bằng khúa hay bằng thẻ thụng minh. Chương trỡnh sẽ tự động nhận dạng mó bằng phương phỏp nào, bằng thuật toỏn gỡ, và yờu cầu người dựng vào thụng tin thớch hợp. Vớ dụ nếu người dựng đó mó bằng mật khẩu, chương trỡnh sẽ yờu cầu nhập vào mật khẩu thớch hợp, nếu mó dựng Smart card chương trỡnh tự động tỡm khúa trờn thẻ, nếu thẻ khụng đỳng sẽ thoỏt ra. Trong trường hợp được mó bằng khúa do người dựng tạo ra, chương trỡnh sẽ hiển thị cửa sổ đọc khúa vào (cú cả tiện ớch tỡm kiếm khoỏ).

Hỡnh 3.8: Thiết kế Form giải mó

Trờn cửa sổ giải mó phớa bờn trỏi chương trỡnh hiển thị toàn bộ cấu trỳc của thư mục mó, người dựng cú thể chọn riờng từng thư mục con để giải mó hay xem cấu trỳc thư

mục. Phớa bờn phải là danh sỏch cỏc file mó bao gồm cỏc thụng tin như kớch thước, tờn file, … cú thể chọn một hay nhiều file để giải mó tựy theo yờu cầu.

Dưới đõy là một phần mó nguồn của Module giải mó: Private WithEvents CpBlf As clsBlowfish

Private WithEvents CpGost As clsGost Private WithEvents CpDes As cls3DES Private WithEvents CpTwf1 As clsTwofish Private WithEvents CpRjd1 As clsRijndael Private WithEvents CpSkj As clsSkipjack Private WithEvents CpSrp As clsSerpent Private WithEvents CpTea As clsTEA Private WithEvents CpRC6 As clsRC6 Private FilesSeleted As Collection Private FolderSeleted As Collection Private Node1 As ComctlLib.Node Private NodeIdx As Integer

Private SLCryptError As Boolean Private Sub cmdNewFolder_Click() diaNewFolder.ShowOpen

FolderToDec = diaNewFolder.Filename End Sub

Private Sub ReUpdateIcon(LVview As ComctlLib.ListView) Dim I As Integer

Dim J As Integer Dim Ext As String Dim sloop As Integer Dim sFlderPos As Integer Dim sFldrName As String Dim nChilds As Integer

For I = 1 To LVview.ListItems.Count

Ext = UCase(GetExt(LVview.ListItems(I).Text)) Select Case Ext

Case "TXT", "INI"

LVview.ListItems(I).SmallIcon = "TXT" Case "DOC"

LVview.ListItems(I).SmallIcon = "WORD" Case "OCX", "OCA", "DLL", "SYS", "DLL" LVview.ListItems(I).SmallIcon = "OCX" Case "ZIP"

Case "EXE"

LVview.ListItems(I).SmallIcon = "EXE" Case "HTM", "HTML"

LVview.ListItems(I).SmallIcon = "IE" Case "BMP", "JPG", "GIF", "ICO" LVview.ListItems(I).SmallIcon = "BMP" Case "MDB"

LVview.ListItems(I).SmallIcon = "ACES" Case "XLS"

LVview.ListItems(I).SmallIcon = "XLS"

Case "AVI", "MP3", "WAV", "WMV", "MPEG" LVview.ListItems(I).SmallIcon = "MEDIA" Case "PPT" LVview.ListItems(I).SmallIcon = "PPT" Case "HLP", "CHM" LVview.ListItems(I).SmallIcon = "HLP" Case Else LVview.ListItems(I).SmallIcon = "OTHER" End Select Next End Sub

Private Sub cboPath_Change()

If Right(cboPath.Text, 2) = "\\" Then cboPath.Text = Mid(cboPath.Text, 1, Len(cboPath.Text) - 1)

End Sub

Private Sub CpBlf_Progress(Percent As Long) Me.ProgressBar.Value = Percent

End Sub

Private Sub CpDes_Progress(Percent As Long) Me.ProgressBar.Value = Percent

End Sub

Private Sub CpGost_Progress(Percent As Long) Me.ProgressBar.Value = Percent

End Sub

Private Sub CpRC6_Progress(Percent As Long) Me.ProgressBar.Value = Percent

End Sub

Private Sub CpSkj_Progress(Percent As Long) Me.ProgressBar.Value = Percent

Private Sub CpTea_Progress(Percent As Long) Me.ProgressBar.Value = Percent

End Sub

Private Sub CpTwf1_Progress(Percent As Long) Me.ProgressBar.Value = Percent

End Sub

Private Sub Form_Activate() ReUpdateIcon Me.LvDecFile Screen.MousePointer = 0 OperateMode = 1 'frmMain.StatusBar.Panels(1).Text = cEncFileName MakeTree EncOrNo = False Dim nFileS As Integer Dim nToatlS As Long Dim I As Integer

For I = 1 To Me.LvDecFile.ListItems.Count

nTotals = nTotals + Val(LvDecFile.ListItems(I).Tag) Next

Me.StatusBar1.Panels(2).Text = "Tổng cộng: " & Me.LvDecFile.ListItems.Count & _ " Files -> " & FormatSize(nTotals)

GetFolderStr

'If LVDecFile.ListItems.Count = 0 And cCurFilename <> "" Then

' MsgBox "Sai mật khẩu, hoặc sai định dạng file", vbCritical, "SLCrypt error" ' Unload Me

'End If End Sub

Private Sub Form_Load()

ApplySin App.Path & "\Skin\winaqua.skn" 'If ValidLicense = False Then End

'For ADODB---

Set ConnectDB = New ADODB.Connection ConnectDB.CursorLocation = adUseClient

ConnectDB.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" _

& App.Path & "\SLCrypt.mdb;Jet OLEDB:Database Password=E15@SLCrypt54;" GetSMConfig

Set FilesSeleted = New Collection Set FolderSeleted = New Collection

cboPath.Text = App.Path & "\" & CurCardHolder & "\Thu muc tep ro\" DecRootFolder = FullPathDes

'Init treeview

SLCryptError = False

Dim Node2 As ComctlLib.Node

Set Node1 = tvDir.Nodes.Add(, , "RootFolder", "Root", 4) Set Node2 = tvDir.Nodes.Add(, , "All file", "All Files", 1) 'Check the command line

If Len(Command) > 0 Then ListFolderAndFiles Command cEncFileName = Command MakeTree ReUpdateIcon LvDecFile End If End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

On Error Resume Next If Y > tvDir.Top Then

If Y < tvDir.ToolTipText + tvDir.Height Then If X > tvDir.Left Then

If X < Me.LvDecFile.Left + LvDecFile.Width Then Me.MousePointer = 9

If Button = 1 Then tvDir.Width = X

LvDecFile.Left = X + 100

LvDecFile.Width = Me.Width - tvDir.Width - 400 End If End If End If End If End If End Sub

3.2.2.4. Thiết kế và mó nguồn của Form gửi thư

Chương trỡnh được thiết kế cú module gửi thư mật cho những thành viờn trong nhúm. Người sử dụng chỉ cần chọn tệp cần gửi, nhấn vào Menu hay phớm phải chuột, chọn người cần gửi, chương trỡnh sẽ tự động mó húa với khúa của người gửi và gửi đi.

Hỡnh 3.9: Chọn người nhận mail trong danh sỏch

Hỡnh 3.10: Thiết kế Form gửi thư

Dưới đõy là một phần mó nguồn của Module gửi thư: Option Explicit

Private WithEvents CpGost As clsGost Private WithEvents CpDes As clsDES Private WithEvents CpTwf1 As clsTwofish Private WithEvents CpSkj As clsSkipjack Private WithEvents CpRC6 As clsRC6 Private WithEvents CpTea As clsTEA Private WithEvents CpRjd1 As clsRijndael Private InetConn As clsInternetCon

'For send Mail

Private WithEvents poSendMail As clsSendMail Private MaskSend As Boolean

'---

Private cEncFileAtt As String

Một phần của tài liệu LUẬN VĂN: NGHIÊN CỨU CÁC GIẢI PHÁP ĐẢM BẢO AN NINH AN TOÀN CHO MẠNG KHÔNG DÂY potx (Trang 86 - 108)