Commit 9432bc1d661270d2e1141c2f7bb16b74fd2629f4
1 parent
97cbcee8
Exists in
master
Melhoria no TestaCrypt e ajuste de código no CACIC_Library
git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@802 fecfc0c7-e812-0410-ae72-849f08638ee7
Showing
3 changed files
with
48 additions
and
80 deletions
Show diff stats
CACIC_Library.pas
| @@ -100,7 +100,7 @@ type | @@ -100,7 +100,7 @@ type | ||
| 100 | function isWindows9xME() : boolean; | 100 | function isWindows9xME() : boolean; |
| 101 | function getWindowsStrId() : string; | 101 | function getWindowsStrId() : string; |
| 102 | function getWinDir() : string; | 102 | function getWinDir() : string; |
| 103 | - function getHomeDrive : string; | 103 | + function getHomeDrive() : string; |
| 104 | function isWindowsAdmin() : boolean; | 104 | function isWindowsAdmin() : boolean; |
| 105 | function createSampleProcess(p_cmd: string; p_wait: boolean ) : boolean; | 105 | function createSampleProcess(p_cmd: string; p_wait: boolean ) : boolean; |
| 106 | procedure showTrayIcon(p_visible:boolean); | 106 | procedure showTrayIcon(p_visible:boolean); |
| @@ -242,7 +242,7 @@ end; | @@ -242,7 +242,7 @@ end; | ||
| 242 | {*------------------------------------------------------------------------------ | 242 | {*------------------------------------------------------------------------------ |
| 243 | Retorna a unidade de instalação do MS-Windows | 243 | Retorna a unidade de instalação do MS-Windows |
| 244 | -------------------------------------------------------------------------------} | 244 | -------------------------------------------------------------------------------} |
| 245 | -function TCACIC_Windows.getHomeDrive : string; | 245 | +function TCACIC_Windows.getHomeDrive() : string; |
| 246 | begin | 246 | begin |
| 247 | Result := MidStr(getWinDir,1,3); //x:\ | 247 | Result := MidStr(getWinDir,1,3); //x:\ |
| 248 | end; | 248 | end; |
testacrypt/main_testacrypt.dfm
| @@ -90,16 +90,17 @@ object Form1: TForm1 | @@ -90,16 +90,17 @@ object Form1: TForm1 | ||
| 90 | object Label_FraseCriptografadaEnviadaEstacao: TLabel | 90 | object Label_FraseCriptografadaEnviadaEstacao: TLabel |
| 91 | Left = 8 | 91 | Left = 8 |
| 92 | Top = 110 | 92 | Top = 110 |
| 93 | - Width = 209 | 93 | + Width = 337 |
| 94 | Height = 13 | 94 | Height = 13 |
| 95 | - Caption = 'Frase Criptografada (para envio ao servidor):' | 95 | + Caption = |
| 96 | + 'Frase Criptografada (para envio ao servidor ou testes de decript' + | ||
| 97 | + 'ografia):' | ||
| 96 | Font.Charset = DEFAULT_CHARSET | 98 | Font.Charset = DEFAULT_CHARSET |
| 97 | Font.Color = clWindowText | 99 | Font.Color = clWindowText |
| 98 | Font.Height = -11 | 100 | Font.Height = -11 |
| 99 | Font.Name = 'MS Sans Serif' | 101 | Font.Name = 'MS Sans Serif' |
| 100 | Font.Style = [] | 102 | Font.Style = [] |
| 101 | ParentFont = False | 103 | ParentFont = False |
| 102 | - Visible = False | ||
| 103 | end | 104 | end |
| 104 | object Label_IVStation: TLabel | 105 | object Label_IVStation: TLabel |
| 105 | Left = 8 | 106 | Left = 8 |
| @@ -157,10 +158,9 @@ object Form1: TForm1 | @@ -157,10 +158,9 @@ object Form1: TForm1 | ||
| 157 | Font.Style = [] | 158 | Font.Style = [] |
| 158 | MaxLength = 100 | 159 | MaxLength = 100 |
| 159 | ParentFont = False | 160 | ParentFont = False |
| 160 | - ReadOnly = True | ||
| 161 | TabOrder = 2 | 161 | TabOrder = 2 |
| 162 | - Visible = False | ||
| 163 | OnChange = Edit_FraseCriptografadaEnviadaEstacaoChange | 162 | OnChange = Edit_FraseCriptografadaEnviadaEstacaoChange |
| 163 | + OnExit = Edit_FraseCriptografadaEnviadaEstacaoExit | ||
| 164 | end | 164 | end |
| 165 | object Edit_IVStation: TEdit | 165 | object Edit_IVStation: TEdit |
| 166 | Left = 8 | 166 | Left = 8 |
testacrypt/main_testacrypt.pas
| @@ -3,7 +3,14 @@ unit main_testacrypt; | @@ -3,7 +3,14 @@ unit main_testacrypt; | ||
| 3 | interface | 3 | interface |
| 4 | 4 | ||
| 5 | uses | 5 | uses |
| 6 | - Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 6 | + Windows, |
| 7 | + Messages, | ||
| 8 | + SysUtils, | ||
| 9 | + Variants, | ||
| 10 | + Classes, | ||
| 11 | + Graphics, | ||
| 12 | + Controls, | ||
| 13 | + Forms, | ||
| 7 | XML, | 14 | XML, |
| 8 | LibXmlParser, | 15 | LibXmlParser, |
| 9 | IdHTTP, | 16 | IdHTTP, |
| @@ -11,13 +18,14 @@ uses | @@ -11,13 +18,14 @@ uses | ||
| 11 | IdComponent, | 18 | IdComponent, |
| 12 | IdTCPConnection, | 19 | IdTCPConnection, |
| 13 | IdTCPClient, | 20 | IdTCPClient, |
| 14 | - DCPcrypt2, | ||
| 15 | - DCPrijndael, | ||
| 16 | - DCPbase64, | ||
| 17 | StdCtrls, | 21 | StdCtrls, |
| 18 | WinSock, | 22 | WinSock, |
| 19 | NB30, | 23 | NB30, |
| 20 | - ComCtrls, PJVersionInfo, JvExComCtrls, JvStatusBar; | 24 | + ComCtrls, |
| 25 | + PJVersionInfo, | ||
| 26 | + JvExComCtrls, | ||
| 27 | + JvStatusBar, | ||
| 28 | + CACIC_Library; | ||
| 21 | 29 | ||
| 22 | type | 30 | type |
| 23 | TForm1 = class(TForm) | 31 | TForm1 = class(TForm) |
| @@ -51,7 +59,6 @@ type | @@ -51,7 +59,6 @@ type | ||
| 51 | StatusBar_Mensagens: TJvStatusBar; | 59 | StatusBar_Mensagens: TJvStatusBar; |
| 52 | procedure Button_EfetuaTesteClick(Sender: TObject); | 60 | procedure Button_EfetuaTesteClick(Sender: TObject); |
| 53 | function PadWithZeros(const str : string; size : integer) : string; | 61 | function PadWithZeros(const str : string; size : integer) : string; |
| 54 | - function EnCrypt(p_Data : String) : String; | ||
| 55 | procedure Button_FinalizaClick(Sender: TObject); | 62 | procedure Button_FinalizaClick(Sender: TObject); |
| 56 | procedure Edit_FraseOriginalKeyUp(Sender: TObject; var Key: Word; | 63 | procedure Edit_FraseOriginalKeyUp(Sender: TObject; var Key: Word; |
| 57 | Shift: TShiftState); | 64 | Shift: TShiftState); |
| @@ -73,6 +80,7 @@ type | @@ -73,6 +80,7 @@ type | ||
| 73 | procedure Edit_ScriptPathChange(Sender: TObject); | 80 | procedure Edit_ScriptPathChange(Sender: TObject); |
| 74 | procedure DesfazCriticas; | 81 | procedure DesfazCriticas; |
| 75 | procedure Edit_IVStationChange(Sender: TObject); | 82 | procedure Edit_IVStationChange(Sender: TObject); |
| 83 | + procedure Edit_FraseCriptografadaEnviadaEstacaoExit(Sender: TObject); | ||
| 76 | private | 84 | private |
| 77 | { Private declarations } | 85 | { Private declarations } |
| 78 | public | 86 | public |
| @@ -80,14 +88,10 @@ type | @@ -80,14 +88,10 @@ type | ||
| 80 | end; | 88 | end; |
| 81 | 89 | ||
| 82 | var Form1: TForm1; | 90 | var Form1: TForm1; |
| 83 | - v_CipherKey, | ||
| 84 | - v_IV : String; | ||
| 85 | boolProcessaPausa : boolean; | 91 | boolProcessaPausa : boolean; |
| 86 | 92 | ||
| 87 | -// Some constants that are dependant on the cipher being used | ||
| 88 | -// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) | ||
| 89 | -const KeySize = 32; // 32 bytes = 256 bits | ||
| 90 | - BlockSize = 16; // 16 bytes = 128 bits | 93 | +var |
| 94 | + g_oCacic: TCACIC; | ||
| 91 | 95 | ||
| 92 | implementation | 96 | implementation |
| 93 | 97 | ||
| @@ -95,7 +99,9 @@ implementation | @@ -95,7 +99,9 @@ implementation | ||
| 95 | procedure TForm1.CriptografaPalavra; | 99 | procedure TForm1.CriptografaPalavra; |
| 96 | Begin | 100 | Begin |
| 97 | if (trim(form1.Edit_FraseOriginal.Text)<>'') then | 101 | if (trim(form1.Edit_FraseOriginal.Text)<>'') then |
| 98 | - Form1.Edit_FraseCriptografadaEnviadaEstacao.Text := form1.EnCrypt(trim(form1.Edit_FraseOriginal.Text)); | 102 | + Form1.Edit_FraseCriptografadaEnviadaEstacao.Text := g_oCacic.enCrypt(trim(form1.Edit_FraseOriginal.Text)) |
| 103 | + else if (trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text)<>'') then | ||
| 104 | + Form1.Edit_FraseOriginal.Text := g_oCacic.deCrypt(trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text)); | ||
| 99 | End; | 105 | End; |
| 100 | 106 | ||
| 101 | procedure TForm1.Button_EfetuaTesteClick(Sender: TObject); | 107 | procedure TForm1.Button_EfetuaTesteClick(Sender: TObject); |
| @@ -109,18 +115,19 @@ var v_retorno, | @@ -109,18 +115,19 @@ var v_retorno, | ||
| 109 | intAux : integer; | 115 | intAux : integer; |
| 110 | begin | 116 | begin |
| 111 | 117 | ||
| 118 | + boolProcessaPausa := true; | ||
| 119 | +// InicializaCampos; | ||
| 120 | + CriptografaPalavra; | ||
| 121 | + | ||
| 112 | intAux := POS('255.255.255.255',Edit_ScriptPath.Text); | 122 | intAux := POS('255.255.255.255',Edit_ScriptPath.Text); |
| 113 | if (intAux > 0) then | 123 | if (intAux > 0) then |
| 114 | Begin | 124 | Begin |
| 115 | - StatusBar_Mensagens.Panels[0].Text := 'ATENÇÃO: Informe um endereço válido para o teste'; | 125 | + StatusBar_Mensagens.Panels[0].Text := 'ATENÇÃO: Caso não seja um teste local, informe um endereço válido.'; |
| 116 | StatusBar_Mensagens.Color := clYellow; | 126 | StatusBar_Mensagens.Color := clYellow; |
| 117 | Edit_ScriptPath.SetFocus; | 127 | Edit_ScriptPath.SetFocus; |
| 118 | End | 128 | End |
| 119 | else | 129 | else |
| 120 | Begin | 130 | Begin |
| 121 | - boolProcessaPausa := true; | ||
| 122 | - InicializaCampos; | ||
| 123 | - CriptografaPalavra; | ||
| 124 | 131 | ||
| 125 | Request_Config := TStringList.Create; | 132 | Request_Config := TStringList.Create; |
| 126 | Request_Config.Values['cs_operacao'] := 'TestaCrypt'; | 133 | Request_Config.Values['cs_operacao'] := 'TestaCrypt'; |
| @@ -163,7 +170,7 @@ begin | @@ -163,7 +170,7 @@ begin | ||
| 163 | Begin | 170 | Begin |
| 164 | Form1.StatusBar_Mensagens.Panels[0].Text := 'Problemas na comunicação...'; | 171 | Form1.StatusBar_Mensagens.Panels[0].Text := 'Problemas na comunicação...'; |
| 165 | Sleep(1000); | 172 | Sleep(1000); |
| 166 | - Form1.StatusBar_Mensagens.Panels[0].Text := ''; | 173 | + Form1.StatusBar_Mensagens.Panels[0].Text := ''; |
| 167 | End; | 174 | End; |
| 168 | End; | 175 | End; |
| 169 | Request_Config.Free; | 176 | Request_Config.Free; |
| @@ -228,47 +235,6 @@ begin | @@ -228,47 +235,6 @@ begin | ||
| 228 | end; | 235 | end; |
| 229 | end; | 236 | end; |
| 230 | 237 | ||
| 231 | -// Encrypt a string and return the Base64 encoded result | ||
| 232 | -function TForm1.EnCrypt(p_Data : String) : String; | ||
| 233 | -var | ||
| 234 | - l_Cipher : TDCP_rijndael; | ||
| 235 | - l_Data, l_Key, l_IV : string; | ||
| 236 | -begin | ||
| 237 | - Form1.StatusBar_Mensagens.Panels[0].Text := 'Criptografando "'+p_Data+'"'; | ||
| 238 | - | ||
| 239 | - if boolProcessaPausa then | ||
| 240 | - Begin | ||
| 241 | - boolProcessaPausa := false; | ||
| 242 | - Sleep(1000); | ||
| 243 | - End; | ||
| 244 | - Form1.StatusBar_Mensagens.Panels[0].Text := ''; | ||
| 245 | - Try | ||
| 246 | - // Pad Key, IV and Data with zeros as appropriate | ||
| 247 | - l_Key := form1.PadWithZeros(trim(form1.Edit_CipherKeyStation.Text),KeySize); | ||
| 248 | - l_IV := form1.PadWithZeros(trim(form1.Edit_IVStation.Text),BlockSize); | ||
| 249 | - l_Data := form1.PadWithZeros(p_Data,BlockSize); | ||
| 250 | - | ||
| 251 | - // Create the cipher and initialise according to the key length | ||
| 252 | - l_Cipher := TDCP_rijndael.Create(nil); | ||
| 253 | - if Length(trim(form1.Edit_CipherKeyStation.Text)) <= 16 then | ||
| 254 | - l_Cipher.Init(l_Key[1],128,@l_IV[1]) | ||
| 255 | - else if Length(trim(form1.Edit_CipherKeyStation.Text)) <= 24 then | ||
| 256 | - l_Cipher.Init(l_Key[1],192,@l_IV[1]) | ||
| 257 | - else | ||
| 258 | - l_Cipher.Init(l_Key[1],256,@l_IV[1]); | ||
| 259 | - | ||
| 260 | - // Encrypt the data | ||
| 261 | - l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data)); | ||
| 262 | - | ||
| 263 | - // Free the cipher and clear sensitive information | ||
| 264 | - l_Cipher.Free; | ||
| 265 | - FillChar(l_Key[1],Length(l_Key),0); | ||
| 266 | - | ||
| 267 | - // Return the Base64 encoded result | ||
| 268 | - Result := Base64EncodeStr(l_Data); | ||
| 269 | - Except | ||
| 270 | - End; | ||
| 271 | -end; | ||
| 272 | 238 | ||
| 273 | 239 | ||
| 274 | procedure TForm1.Button_FinalizaClick(Sender: TObject); | 240 | procedure TForm1.Button_FinalizaClick(Sender: TObject); |
| @@ -303,12 +269,12 @@ end; | @@ -303,12 +269,12 @@ end; | ||
| 303 | 269 | ||
| 304 | procedure TForm1.FormCreate(Sender: TObject); | 270 | procedure TForm1.FormCreate(Sender: TObject); |
| 305 | begin | 271 | begin |
| 306 | - //chave AES. Recomenda-se que cada empresa/órgão altere a sua chave. | ||
| 307 | - v_CipherKey := 'CacicBrasil'; | ||
| 308 | - v_IV := 'abcdefghijklmnop'; | 272 | + g_oCacic := TCACIC.Create; |
| 273 | + g_oCacic.setBoolCipher(true); | ||
| 274 | + | ||
| 275 | + form1.Edit_IVStation.Text := g_oCacic.getIV; | ||
| 276 | + form1.Edit_CipherKeyStation.Text := g_oCacic.getCipherKey; | ||
| 309 | 277 | ||
| 310 | - form1.Edit_IVStation.Text := v_IV; | ||
| 311 | - form1.Edit_CipherKeyStation.Text := v_CipherKey; | ||
| 312 | Form1.StatusBar_Mensagens.Panels[1].Text := 'v: '+getVersionInfo(ParamStr(0)); | 278 | Form1.StatusBar_Mensagens.Panels[1].Text := 'v: '+getVersionInfo(ParamStr(0)); |
| 313 | boolProcessaPausa := false; | 279 | boolProcessaPausa := false; |
| 314 | end; | 280 | end; |
| @@ -329,15 +295,7 @@ procedure TForm1.Edit_FraseCriptografadaEnviadaEstacaoChange( | @@ -329,15 +295,7 @@ procedure TForm1.Edit_FraseCriptografadaEnviadaEstacaoChange( | ||
| 329 | Sender: TObject); | 295 | Sender: TObject); |
| 330 | begin | 296 | begin |
| 331 | if trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text) = '' then | 297 | if trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text) = '' then |
| 332 | - Begin | ||
| 333 | - form1.Edit_FraseCriptografadaEnviadaEstacao.Visible := false; | ||
| 334 | - form1.Label_FraseCriptografadaEnviadaEstacao.Visible := false; | ||
| 335 | - End | ||
| 336 | - else | ||
| 337 | - Begin | ||
| 338 | - form1.Edit_FraseCriptografadaEnviadaEstacao.Visible := true; | ||
| 339 | - form1.Label_FraseCriptografadaEnviadaEstacao.Visible := true; | ||
| 340 | - End; | 298 | + form1.Button_EfetuaTeste.Enabled := true; |
| 341 | ProcessaPausa; | 299 | ProcessaPausa; |
| 342 | end; | 300 | end; |
| 343 | 301 | ||
| @@ -439,4 +397,14 @@ begin | @@ -439,4 +397,14 @@ begin | ||
| 439 | DesfazCriticas; | 397 | DesfazCriticas; |
| 440 | end; | 398 | end; |
| 441 | 399 | ||
| 400 | +procedure TForm1.Edit_FraseCriptografadaEnviadaEstacaoExit( | ||
| 401 | + Sender: TObject); | ||
| 402 | +begin | ||
| 403 | + if (form1.Edit_FraseCriptografadaEnviadaEstacao.Text <> '') then | ||
| 404 | + Begin | ||
| 405 | + form1.Button_EfetuaTeste.Enabled := true; | ||
| 406 | + End; | ||
| 407 | + | ||
| 408 | +end; | ||
| 409 | + | ||
| 442 | end. | 410 | end. |