Changeset ce57b1b in nscp
- Timestamp:
- 02/11/08 23:15:02 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 7a156f4
- Parents:
- 1a35b3f
- Files:
-
- 13 edited
-
AutoBuild.h (modified) (1 diff)
-
NSC.dist (modified) (3 diffs)
-
NSClient++-2005.sln (modified) (4 diffs)
-
NSClient++.cpp (modified) (1 diff)
-
changelog (modified) (1 diff)
-
include/Socket.h (modified) (1 diff)
-
include/utils.cpp (modified) (1 diff)
-
include/utils.h (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (4 diffs)
-
modules/NSCAAgent/NSCAAgent-2005.vcproj (modified) (16 diffs)
-
modules/NSCAAgent/NSCAThread.cpp (modified) (3 diffs)
-
modules/NSCAAgent/NSCAThread.h (modified) (1 diff)
-
modules/NSCAAgent/nsca_enrypt.hpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
rc1d545e rce57b1b 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,0, 486 #define PRODUCTVER 0,3,0, 487 #define STRFILEVER _T("0.3.0. 48")8 #define STRPRODUCTVER _T("0.3.0. 48")9 #define STRPRODUCTDATE _T("2008-02- 08")5 #define FILEVER 0,3,0,50 6 #define PRODUCTVER 0,3,0,50 7 #define STRFILEVER _T("0.3.0.50") 8 #define STRPRODUCTVER _T("0.3.0.50") 9 #define STRPRODUCTDATE _T("2008-02-11") 10 10 #endif // AUTOBUILD_H -
NSC.dist
r1a35b3f rce57b1b 130 130 131 131 [External Alias] 132 alias_cpu=checkCPU warn=80 crit=90 time=5m time=1m time=30s133 alias_disk=CheckDriveSize MinWarn=10% MinCrit=5% CheckAll FilterType=FIXED134 alias_service=checkServiceState CheckAll135 alias_mem=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=physical132 ;alias_cpu=checkCPU warn=80 crit=90 time=5m time=1m time=30s 133 ;alias_disk=CheckDriveSize MinWarn=10% MinCrit=5% CheckAll FilterType=FIXED 134 ;alias_service=checkServiceState CheckAll 135 ;alias_mem=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=physical 136 136 137 137 … … 232 232 ; 0 = None (Do NOT use this option) 233 233 ; 1 = Simple XOR (No security, just obfuscation, but very fast) 234 ; (no MCRYPT yet, but soon...) 235 ;encryption_method=1 234 ; 2 = DES 235 ; 3 = 3DES (Triple DES) 236 ; 4 = CAST-128 237 ; 6 = xTEA 238 ; 8 = BLOWFISH 239 ; 9 = TWOFISH 240 ; 11 = RC2 241 ; 14 = RIJNDAEL-128 (AES) 242 ; 20 = SERPENT 243 ;encryption_method=14 236 244 ; 237 245 ;# ENCRYPTION PASSWORD … … 258 266 ; 259 267 [NSCA Commands] 260 my_cpu_check=checkCPU warn=80 crit=90 time=20m time=10s time=4261 my_mem_check=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=page262 my_svc_check=checkServiceState CheckAll exclude=wampmysqld exclude=MpfService268 ;my_cpu_check=checkCPU warn=80 crit=90 time=20m time=10s time=4 269 ;my_mem_check=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=page 270 ;my_svc_check=checkServiceState CheckAll exclude=wampmysqld exclude=MpfService -
NSClient++-2005.sln
rc1d545e rce57b1b 3 3 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NSClient++", "NSClient++-2005.vcproj", "{2286162D-7571-4735-BAC8-4A8D33A4F42D}" 4 4 ProjectSection(ProjectDependencies) = postProject 5 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} = {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} 6 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} = {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} 7 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} = {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} 8 {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8} 9 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} 10 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} 11 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} = {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} 12 {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B} 13 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} 5 14 {BBFF8362-C626-4838-B0A2-F695D638AD24} = {BBFF8362-C626-4838-B0A2-F695D638AD24} 6 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}7 {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B}8 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} = {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}9 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}10 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}11 {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8}12 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} = {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}13 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} = {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}14 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} = {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}15 15 EndProjectSection 16 16 EndProject … … 38 38 EndProject 39 39 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NSCAAgent", "modules\NSCAAgent\NSCAAgent-2005.vcproj", "{6F55C9BF-57F6-4A15-A058-C83A52F539EE}" 40 ProjectSection(ProjectDependencies) = postProject 41 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A} = {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A} 42 EndProjectSection 40 43 EndProject 41 44 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LUAScript", "modules\LUAScript\LUAScript-2005.vcproj", "{26B84883-BE52-40E6-9BEE-55AD056D5751}" … … 47 50 EndProject 48 51 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckExternalScripts", "modules\CheckExternalScripts\CheckExternalScripts-2005.vcproj", "{0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}" 52 EndProject 53 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypt++", "..\Crypt++\Crypt++.vcproj", "{630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}" 49 54 EndProject 50 55 Global … … 680 685 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Release|x64.ActiveCfg = Release|x64 681 686 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Release|x64.Build.0 = Release|x64 687 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|Any CPU.ActiveCfg = Debug|Win32 688 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|Itanium.ActiveCfg = Debug|Win32 689 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 690 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 691 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|Win32.ActiveCfg = Debug|Win32 692 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|Win32.Build.0 = Debug|Win32 693 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug|x64.ActiveCfg = Debug|Win32 694 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|Any CPU.ActiveCfg = Debug|Win32 695 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|Itanium.ActiveCfg = Debug|Win32 696 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|Mixed Platforms.ActiveCfg = Debug|Win32 697 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|Mixed Platforms.Build.0 = Debug|Win32 698 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|Win32.ActiveCfg = Debug|Win32 699 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|Win32.Build.0 = Debug|Win32 700 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Debug-MemCheck|x64.ActiveCfg = Debug|Win32 701 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|Any CPU.ActiveCfg = Debug|Win32 702 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|Itanium.ActiveCfg = Debug|Win32 703 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|Mixed Platforms.ActiveCfg = Debug|Win32 704 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|Mixed Platforms.Build.0 = Debug|Win32 705 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|Win32.ActiveCfg = Debug|Win32 706 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|Win32.Build.0 = Debug|Win32 707 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Distribution|x64.ActiveCfg = Debug|Win32 708 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|Any CPU.ActiveCfg = Release|Win32 709 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|Itanium.ActiveCfg = Release|Win32 710 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|Mixed Platforms.ActiveCfg = Release|Win32 711 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|Mixed Platforms.Build.0 = Release|Win32 712 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|Win32.ActiveCfg = Nightly|Win32 713 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|Win32.Build.0 = Nightly|Win32 714 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Nightly|x64.ActiveCfg = Release|Win32 715 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Any CPU.ActiveCfg = Release|Win32 716 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Itanium.ActiveCfg = Release|Win32 717 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 718 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Mixed Platforms.Build.0 = Release|Win32 719 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Win32.ActiveCfg = Release|Win32 720 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Win32.Build.0 = Release|Win32 721 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|x64.ActiveCfg = Release|Win32 682 722 EndGlobalSection 683 723 GlobalSection(SolutionProperties) = preSolution -
NSClient++.cpp
rc1d545e rce57b1b 28 28 ////////////////////////////////////////////////////////////////////////// 29 29 // Startup code 30 30 31 31 32 /** -
changelog
rc1d545e rce57b1b 5 5 * Add module for relaying events 6 6 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 7 8 2008-02-11 MickeM 9 + Added encryption support for NSCA module (about half of the algorithms are avalible, 10 if someone wants to use one not available let me know, and I will try to add it) 7 11 8 12 2008-02-09 MickeM -
include/Socket.h
r035c51f rce57b1b 56 56 } 57 57 DataBuffer(const char* buffer, unsigned int length) { 58 buffer_ = new char[length+2]; 59 memcpy(buffer_, buffer, length+1); 60 length_ = length; 61 } 62 DataBuffer(const unsigned char* buffer, unsigned int length) { 58 63 buffer_ = new char[length+2]; 59 64 memcpy(buffer_, buffer, length+1); -
include/utils.cpp
rdc65e35 rce57b1b 57 57 } 58 58 59 unsigned long calculate_crc32(const unsigned char *buffer, int buffer_size){ 60 if (!hascrc32) 61 generate_crc32_table(); 62 register unsigned long crc; 63 int this_char; 64 int current_index; 59 65 66 crc=0xFFFFFFFF; 67 68 for(current_index=0;current_index<buffer_size;current_index++){ 69 this_char=(int)buffer[current_index]; 70 crc=((crc>>8) & 0x00FFFFFF) ^ crc32_table[(crc ^ this_char) & 0xFF]; 71 } 72 73 return (crc ^ 0xFFFFFFFF); 74 } 75 76 -
include/utils.h
r99e4d8f rce57b1b 26 26 void generate_crc32_table(void); 27 27 unsigned long calculate_crc32(const char *buffer, int buffer_size); 28 unsigned long calculate_crc32(const unsigned char *buffer, int buffer_size); 28 29 29 30 -
modules/CheckExternalScripts/CheckExternalScripts.cpp
rc1d545e rce57b1b 124 124 125 125 for (;cit2!=arr.end();cit2++,i++) { 126 if ( NSCModuleHelper::getSettingsInt(EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_ALLOW_NASTY_META, EXTSCRIPT_SETTINGS_ALLOW_NASTY_META_DEFAULT) == 0) {126 if (isAlias || NSCModuleHelper::getSettingsInt(EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_ALLOW_NASTY_META, EXTSCRIPT_SETTINGS_ALLOW_NASTY_META_DEFAULT) == 0) { 127 127 if ((*cit2).find_first_of(NASTY_METACHARS) != std::wstring::npos) { 128 128 NSC_LOG_ERROR(_T("Request string contained illegal metachars!")); … … 136 136 return NSCModuleHelper::InjectSplitAndCommand(cd.command, cd.arguments, ' ', message, perf, true); 137 137 } else { 138 return executeNRPECommand( args, message, perf);138 return executeNRPECommand(cd.command + _T(" ") + args, message, perf); 139 139 /* 140 140 } else if (cd.type == script_dir) { … … 168 168 sec.lpSecurityDescriptor = NULL; 169 169 170 // CreateProcess doesn't work with a const command 171 TCHAR *cmd = new TCHAR[command.length()+1]; 172 if (cmd == NULL) { 173 NSC_LOG_ERROR(_T("Failed to allocate memory for command buffer (") + command + _T(").")); 174 return NSCAPI::returnUNKNOWN; 175 } 176 wcsncpy_s(cmd, command.length()+1, command.c_str(), command.length()); 177 cmd[command.length()] = 0; 178 std::wstring root = NSCModuleHelper::getBasePath(); 179 170 180 // Create Pipes 171 CreatePipe(&hChildInR, &hChildInW, &sec, 0); 172 CreatePipe(&hChildOutR, &hChildOutW, &sec, 0); 181 if (!CreatePipe(&hChildInR, &hChildInW, &sec, 0)) { 182 NSC_LOG_ERROR(_T("Failed to create pipe for (") + command + _T(") return code: ") + error::lookup::last_error()); 183 return NSCAPI::returnUNKNOWN; 184 } 185 if (!CreatePipe(&hChildOutR, &hChildOutW, &sec, 0)) { 186 NSC_LOG_ERROR(_T("Failed to create pipe for (") + command + _T(") return code: ") + error::lookup::last_error()); 187 return NSCAPI::returnUNKNOWN; 188 } 173 189 174 190 // Set up members of STARTUPINFO structure. … … 181 197 si.hStdError = hChildOutW; 182 198 si.wShowWindow = SW_HIDE; 183 184 185 // CreateProcess doesn't work with a const command186 TCHAR *cmd = new TCHAR[command.length()+1];187 wcsncpy_s(cmd, command.length()+1, command.c_str(), command.length());188 cmd[command.length()] = 0;189 std::wstring root = NSCModuleHelper::getBasePath();190 199 191 200 // Create the child process. -
modules/NSCAAgent/NSCAAgent-2005.vcproj
r035c51f rce57b1b 69 69 <Tool 70 70 Name="VCLinkerTool" 71 AdditionalDependencies="ws2_32.lib "71 AdditionalDependencies="ws2_32.lib Crypt++.lib" 72 72 OutputFile="../../Debug/modules/$(ProjectName).dll" 73 73 LinkIncremental="2" 74 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 74 75 ModuleDefinitionFile="NSCAAgent.def" 75 76 GenerateDebugInformation="true" 76 77 ProgramDatabaseFile="$(OutDir)/NSCAAgent.pdb" 77 78 SubSystem="2" 78 ImportLibrary="$(OutDir)/N SCAAgent.lib"79 ImportLibrary="$(OutDir)/NRPEListener.lib" 79 80 TargetMachine="1" 80 81 /> … … 152 153 <Tool 153 154 Name="VCLinkerTool" 154 AdditionalDependencies="ws2_32.lib "155 AdditionalDependencies="ws2_32.lib Crypt++.lib" 155 156 OutputFile="$(OutDir)\$(ProjectName).dll" 156 157 LinkIncremental="2" 158 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 157 159 ModuleDefinitionFile="NSCAAgent.def" 158 160 GenerateDebugInformation="true" 159 161 ProgramDatabaseFile="$(OutDir)/NSCAAgent.pdb" 160 162 SubSystem="2" 161 ImportLibrary="$(OutDir)/N SCAAgent.lib"163 ImportLibrary="$(OutDir)/NRPEListener.lib" 162 164 TargetMachine="17" 163 165 /> … … 231 233 <Tool 232 234 Name="VCLinkerTool" 233 AdditionalDependencies="ws2_32.lib "235 AdditionalDependencies="ws2_32.lib Crypt++.lib" 234 236 OutputFile="$(OutDir)\$(ProjectName).dll" 235 237 LinkIncremental="1" 238 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 236 239 ModuleDefinitionFile="NSCAAgent.def" 237 240 GenerateDebugInformation="false" … … 239 242 OptimizeReferences="2" 240 243 EnableCOMDATFolding="2" 241 ImportLibrary="$( OutDir)/NSCAAgent.lib"244 ImportLibrary="$(TargetDir)$(TargetName).lib" 242 245 TargetMachine="1" 243 246 /> … … 312 315 <Tool 313 316 Name="VCLinkerTool" 314 AdditionalDependencies="ws2_32.lib "317 AdditionalDependencies="ws2_32.lib Crypt++.lib" 315 318 OutputFile="$(OutDir)\$(ProjectName).dll" 316 319 LinkIncremental="1" 320 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 317 321 ModuleDefinitionFile="NSCAAgent.def" 318 322 GenerateDebugInformation="false" … … 320 324 OptimizeReferences="2" 321 325 EnableCOMDATFolding="2" 322 ImportLibrary="$( OutDir)/NSCAAgent.lib"326 ImportLibrary="$(TargetDir)$(TargetName).lib" 323 327 TargetMachine="17" 324 328 /> … … 392 396 <Tool 393 397 Name="VCLinkerTool" 394 AdditionalDependencies="ws2_32.lib "398 AdditionalDependencies="ws2_32.lib Crypt++.lib" 395 399 OutputFile="$(OutDir)\$(ProjectName).dll" 396 400 LinkIncremental="1" 401 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 397 402 ModuleDefinitionFile="NSCAAgent.def" 398 403 GenerateDebugInformation="false" … … 400 405 OptimizeReferences="2" 401 406 EnableCOMDATFolding="2" 402 ImportLibrary="$( OutDir)/NSCAAgent.lib"407 ImportLibrary="$(TargetDir)$(TargetName).lib" 403 408 TargetMachine="1" 404 409 /> … … 473 478 <Tool 474 479 Name="VCLinkerTool" 475 AdditionalDependencies="ws2_32.lib "480 AdditionalDependencies="ws2_32.lib Crypt++.lib" 476 481 OutputFile="$(OutDir)\$(ProjectName).dll" 477 482 LinkIncremental="1" 483 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 478 484 ModuleDefinitionFile="NSCAAgent.def" 479 485 GenerateDebugInformation="false" … … 481 487 OptimizeReferences="2" 482 488 EnableCOMDATFolding="2" 483 ImportLibrary="$( OutDir)/NSCAAgent.lib"489 ImportLibrary="$(TargetDir)$(TargetName).lib" 484 490 TargetMachine="17" 485 491 /> … … 553 559 <Tool 554 560 Name="VCLinkerTool" 555 AdditionalDependencies="ws2_32.lib "561 AdditionalDependencies="ws2_32.lib Crypt++.lib" 556 562 OutputFile="$(OutDir)\$(ProjectName).dll" 557 563 LinkIncremental="1" 564 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 558 565 ModuleDefinitionFile="NSCAAgent.def" 559 566 GenerateDebugInformation="false" … … 561 568 OptimizeReferences="2" 562 569 EnableCOMDATFolding="2" 563 ImportLibrary=" $(OutDir)/NSCAAgent.lib"570 ImportLibrary="" 564 571 TargetMachine="1" 565 572 /> … … 634 641 <Tool 635 642 Name="VCLinkerTool" 636 AdditionalDependencies="ws2_32.lib "643 AdditionalDependencies="ws2_32.lib Crypt++.lib" 637 644 OutputFile="$(OutDir)\$(ProjectName).dll" 638 645 LinkIncremental="1" 646 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 639 647 ModuleDefinitionFile="NSCAAgent.def" 640 648 GenerateDebugInformation="false" … … 642 650 OptimizeReferences="2" 643 651 EnableCOMDATFolding="2" 644 ImportLibrary="$( OutDir)/NSCAAgent.lib"652 ImportLibrary="$(TargetDir)$(TargetName).lib" 645 653 TargetMachine="17" 646 654 /> … … 717 725 <Tool 718 726 Name="VCLinkerTool" 719 AdditionalDependencies="ws2_32.lib "727 AdditionalDependencies="ws2_32.lib Crypt++.lib" 720 728 OutputFile="$(OutDir)\$(ProjectName).dll" 721 729 LinkIncremental="2" 730 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 722 731 ModuleDefinitionFile="NSCAAgent.def" 723 732 GenerateDebugInformation="true" 724 733 ProgramDatabaseFile="$(OutDir)/NSCAAgent.pdb" 725 734 SubSystem="2" 726 ImportLibrary="$( OutDir)/NSCAAgent.lib"735 ImportLibrary="$(TargetDir)$(TargetName).lib" 727 736 TargetMachine="1" 728 737 /> … … 800 809 <Tool 801 810 Name="VCLinkerTool" 802 AdditionalDependencies="ws2_32.lib "811 AdditionalDependencies="ws2_32.lib Crypt++.lib" 803 812 OutputFile="$(OutDir)\$(ProjectName).dll" 804 813 LinkIncremental="2" 814 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" 805 815 ModuleDefinitionFile="NSCAAgent.def" 806 816 GenerateDebugInformation="true" 807 817 ProgramDatabaseFile="$(OutDir)/NSCAAgent.pdb" 808 818 SubSystem="2" 809 ImportLibrary="$( OutDir)/NSCAAgent.lib"819 ImportLibrary="$(TargetDir)$(TargetName).lib" 810 820 TargetMachine="17" 811 821 /> -
modules/NSCAAgent/NSCAThread.cpp
r035c51f rce57b1b 33 33 addCommand(*cit); 34 34 } 35 //std::string s = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU_BUFFER_TIME, C_SYSTEM_CPU_BUFFER_TIME_DEFAULT);36 //unsigned int i = strEx::stoui_as_time(s, checkIntervall_*100);37 35 } 38 36 … … 143 141 NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer(); 144 142 try { 145 crypt_inst.encrypt_init(password_.c_str(),encryption_method_, packet_in->iv);146 } catch (nsca_encrypt::e xception &e) {143 crypt_inst.encrypt_init(password_.c_str(),encryption_method_,reinterpret_cast<unsigned char*>(packet_in->iv)); 144 } catch (nsca_encrypt::encryption_exception &e) { 147 145 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header: ") + e.getMessage()); 148 146 return; … … 154 152 try { 155 153 for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) { 156 //NSC_DEBUG_MSG_STD(_T("Sending : ") + (*cit).toString());157 154 socket.send((*cit).getBuffer(crypt_inst)); 158 155 } 159 } catch (nsca_encrypt::e xception &e) {156 } catch (nsca_encrypt::encryption_exception &e) { 160 157 NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet: ") + e.getMessage()); 161 158 return; -
modules/NSCAAgent/NSCAThread.h
r035c51f rce57b1b 159 159 std::string h = strEx::wstring_to_string(host); 160 160 161 NSCAPacket::data_packet data; 162 data.packet_version=static_cast<NSCAPacket::int16_t>(htons(NSCA_PACKET_VERSION_3)); 163 data.timestamp=static_cast<NSCAPacket::u_int32_t>(htonl(time)); 164 data.return_code = code; 165 data.crc32_value=static_cast<NSCAPacket::u_int32_t>(0L); 166 167 strncpy_s(data.host_name, NSCA_MAX_HOSTNAME_LENGTH, h.c_str(), h.length()); 168 strncpy_s(data.svc_description, NSCA_MAX_DESCRIPTION_LENGTH, s.c_str(), s.length()); 169 strncpy_s(data.plugin_output, NSCA_MAX_PLUGINOUTPUT_LENGTH, r.c_str(), r.length()); 170 171 unsigned int calculated_crc32=calculate_crc32(reinterpret_cast<char*>(&data),sizeof(data)); 172 data.crc32_value=static_cast<NSCAPacket::u_int32_t>(htonl(calculated_crc32)); 173 char * buffer = reinterpret_cast<char*>(&data); 174 crypt_inst.encrypt_buffer(buffer, sizeof(data)); 175 return simpleSocket::DataBuffer(buffer,sizeof(data)); 161 unsigned int buffer_len = sizeof(NSCAPacket::data_packet); 162 unsigned char* buffer = crypt_inst.get_rand_buffer(buffer_len); 163 NSCAPacket::data_packet *data = reinterpret_cast<NSCAPacket::data_packet*>(buffer); 164 data->packet_version=static_cast<NSCAPacket::int16_t>(htons(NSCA_PACKET_VERSION_3)); 165 data->timestamp=static_cast<NSCAPacket::u_int32_t>(htonl(time)); 166 data->return_code = code; 167 data->crc32_value=static_cast<NSCAPacket::u_int32_t>(0L); 168 169 strncpy_s(data->host_name, NSCA_MAX_HOSTNAME_LENGTH, h.c_str(), h.length()); 170 strncpy_s(data->svc_description, NSCA_MAX_DESCRIPTION_LENGTH, s.c_str(), s.length()); 171 strncpy_s(data->plugin_output, NSCA_MAX_PLUGINOUTPUT_LENGTH, r.c_str(), r.length()); 172 173 unsigned int calculated_crc32=calculate_crc32(buffer,buffer_len); 174 data->crc32_value=static_cast<NSCAPacket::u_int32_t>(htonl(calculated_crc32)); 175 crypt_inst.encrypt_buffer(buffer, buffer_len); 176 simpleSocket::DataBuffer ret(buffer,buffer_len); 177 crypt_inst.destroy_random_buffer(buffer); 178 return ret; 176 179 } 177 180 -
modules/NSCAAgent/nsca_enrypt.hpp
r035c51f rce57b1b 1 #define HAVE_LIBCRYPTOPP 2 3 #ifdef HAVE_LIBCRYPTOPP 4 #include <crypto++/cryptlib.h> 5 #include <crypto++/modes.h> 6 #include <crypto++/des.h> 7 #include <crypto++/aes.h> 8 #include <crypto++/cast.h> 9 #include <crypto++/tea.h> 10 #include <crypto++/3way.h> 11 #include <crypto++/blowfish.h> 12 #include <crypto++/twofish.h> 13 #include <crypto++/rc2.h> 14 #include <crypto++/arc4.h> 15 #include <crypto++/serpent.h> 16 #include <crypto++/gost.h> 17 #include <crypto++/filters.h> 18 #include <crypto++/osrng.h> 19 #endif 1 20 2 21 #define TRANSMITTED_IV_SIZE 128 /* size of IV to transmit - must be as big as largest IV needed for any crypto algorithm */ … … 7 26 #define ENCRYPT_XOR 1 /* not really encrypted, just obfuscated */ 8 27 9 #ifdef HAVE_LIB MCRYPT28 #ifdef HAVE_LIBCRYPTOPP 10 29 #define ENCRYPT_DES 2 /* DES */ 11 30 #define ENCRYPT_3DES 3 /* 3DES or Triple DES */ … … 37 56 38 57 class nsca_encrypt { 58 public: 59 class encryption_exception { 60 std::wstring msg_; 61 public: 62 encryption_exception() {} 63 encryption_exception(std::wstring msg) : msg_(msg) {} 64 std::wstring getMessage() const { return msg_; } 65 66 }; 67 class any_encryption { 68 public: 69 virtual void init(std::string password, unsigned char *transmitted_iv, int iv_size) = 0; 70 virtual void encrypt(unsigned char *buffer, int buffer_size) = 0; 71 virtual void decrypt(unsigned char *buffer, int buffer_size) = 0; 72 }; 73 template <class TMethod> 74 class cryptopp_encryption : public any_encryption { 75 private: 76 typedef CryptoPP::CFB_Mode_ExternalCipher::Encryption TEncryption; 77 typedef typename TMethod::Encryption TCipher; 78 TEncryption crypto_; 79 TCipher cipher_; 80 int keysize_; 81 public: 82 cryptopp_encryption() : keysize_(TMethod::DEFAULT_KEYLENGTH) {} 83 cryptopp_encryption(int keysize) : keysize_(keysize) {} 84 int get_keySize() { 85 return keysize_; 86 } 87 int get_blockSize() { 88 return TMethod::BLOCKSIZE; 89 } 90 91 void init(std::string password, unsigned char *transmitted_iv, int iv_size) { 92 /* generate an encryption/description key using the password */ 93 int keysize=get_keySize(); 94 std::cout << "keysize: " << keysize << std::endl; 95 96 unsigned char *key = new unsigned char[keysize+1]; 97 if (key == NULL){ 98 throw encryption_exception(_T("Could not allocate memory for encryption/decryption key")); 99 } 100 ZeroMemory(key,keysize*sizeof(unsigned char)); 101 strncpy(reinterpret_cast<char*>(key),password.c_str(),min(keysize,password.length())); 102 103 104 /* determine size of IV buffer for this algorithm */ 105 int blocksize = get_blockSize(); 106 if(blocksize>iv_size){ 107 throw encryption_exception(_T("IV size for crypto algorithm exceeds limits")); 108 } 109 110 /* allocate memory for IV buffer */ 111 unsigned char *iv = new unsigned char[blocksize+1]; 112 if (iv == NULL){ 113 throw encryption_exception(_T("Could not allocate memory for IV buffer")); 114 } 115 116 /* fill IV buffer with first bytes of IV that is going to be used to crypt (determined by server) */ 117 memcpy(iv, transmitted_iv, sizeof(unsigned char)*blocksize); 118 119 try { 120 cipher_.SetKey(key, keysize); 121 crypto_.SetCipherWithIV(cipher_, iv, 1); 122 } catch (...) { 123 throw encryption_exception(_T("Unknown exception when trying to setup crypto")); 124 } 125 delete [] iv; 126 delete [] key; 127 } 128 void encrypt(unsigned char *buffer, int buffer_size) { 129 /* encrypt each byte of buffer, one byte at a time (CFB mode) */ 130 try { 131 for(int x=0;x<buffer_size;x++) 132 crypto_.ProcessData(&buffer[x], &buffer[x], 1); 133 } catch (...) { 134 throw encryption_exception(_T("Unknown exception when trying to setup crypto")); 135 } 136 } 137 void decrypt(unsigned char *buffer, int buffer_size) { 138 throw encryption_exception(_T("Decryption not supported")); 139 } 140 141 }; 142 class no_encryption : public any_encryption { 143 public: 144 static int get_keySize() { 145 return 0; 146 } 147 static int get_blockSize() { 148 return 1; 149 } 150 void init(std::string password, unsigned char *transmitted_iv, int iv_size) {} 151 void encrypt(unsigned char *buffer, int buffer_size) {} 152 void decrypt(unsigned char *buffer, int buffer_size) {} 153 }; 154 class xor_encryption : public any_encryption { 155 private: 156 int password_size_; 157 int iv_size_; 158 unsigned char* transmitted_iv_; 159 unsigned char* password_; 160 public: 161 xor_encryption() : transmitted_iv_(NULL), password_(NULL) {} 162 ~xor_encryption() { 163 delete [] password_; 164 delete [] transmitted_iv_; 165 } 166 static int get_keySize() { 167 return 0; 168 } 169 static int get_blockSize() { 170 return 1; 171 } 172 void init(std::string password, unsigned char *transmitted_iv, int iv_size) { 173 iv_size_ = iv_size; 174 delete [] transmitted_iv_; 175 transmitted_iv_ = new unsigned char[iv_size_+1]; 176 if (transmitted_iv_ == NULL) 177 throw encryption_exception(_T("Failed to allocate memory for iv")); 178 memcpy(transmitted_iv_, transmitted_iv, sizeof(unsigned char)*iv_size_); 179 180 password_size_ = password.length(); 181 delete [] password_; 182 password_ = new unsigned char[password_size_+1]; 183 if (password_ == NULL) 184 throw encryption_exception(_T("Failed to allocate memory for password")); 185 memcpy(password_, password.c_str(), sizeof(unsigned char)*password_size_); 186 187 } 188 void encrypt(unsigned char *buffer, int buffer_size) { 189 /* rotate over IV we received from the server... */ 190 for (int y=0,x=0;y<buffer_size;y++,x++) { 191 /* keep rotating over IV */ 192 if (x >= iv_size_) 193 x = 0; 194 buffer[y] ^= transmitted_iv_[x]; 195 } 196 197 /* rotate over password... */ 198 for(int y=0,x=0; y < buffer_size; y++,x++) { 199 /* keep rotating over password */ 200 if (x >= password_size_) 201 x = 0; 202 buffer[y] ^= password_[x]; 203 } 204 return; 205 } 206 void decrypt(unsigned char *buffer, int buffer_size) { 207 throw encryption_exception(_T("Decryption not supported")); 208 } 209 }; 210 39 211 private: 40 char transmitted_iv_[TRANSMITTED_IV_SIZE]; 41 bool isInialized_; 42 std::string password_; 43 int encryption_method_; 44 #ifdef HAVE_LIBMCRYPT 45 MCRYPT td_; 46 char *key_; 47 char *IV_; 48 char block_buffer_; 49 int blocksize_; 50 int keysize_; 51 std::string mcrypt_algorithm_; 52 std::string mcrypt_mode_; 53 #endif 212 any_encryption *core_; 54 213 public: 55 class exception { 56 std::wstring error_; 57 public: 58 exception(std::wstring error) : error_(error) {} 59 std::wstring getMessage() const { return error_; } 60 61 }; 62 63 nsca_encrypt() : isInialized_(false) 64 #ifdef HAVE_LIBMCRYPT 65 , key_(NULL), IV_(NULL) 66 #endif 67 {} 214 215 nsca_encrypt() : core_(NULL) {} 68 216 ~nsca_encrypt() { 69 #ifdef HAVE_LIBMCRYPT 70 /* mcrypt cleanup */ 71 if(encryption_method!=ENCRYPT_NONE && encryption_method!=ENCRYPT_XOR){ 72 mcrypt_generic_end(td); 73 delete [] key; 74 key=NULL; 75 delete [] IV; 76 IV=NULL; 77 } 78 #endif 217 delete core_; 79 218 } 80 219 … … 84 223 case ENCRYPT_NONE: 85 224 case ENCRYPT_XOR: 86 #ifdef HAVE_LIB MCRYPT225 #ifdef HAVE_LIBCRYPTOPP 87 226 case ENCRYPT_DES: 88 227 case ENCRYPT_3DES: 89 228 case ENCRYPT_CAST128: 90 case ENCRYPT_CAST256:91 229 case ENCRYPT_XTEA: 92 case ENCRYPT_3WAY:93 230 case ENCRYPT_BLOWFISH: 94 231 case ENCRYPT_TWOFISH: 232 case ENCRYPT_RC2: 233 case ENCRYPT_RIJNDAEL128: 234 case ENCRYPT_SERPENT: 235 case ENCRYPT_GOST: 236 #endif 237 return true; 238 239 // UNdefined 240 case ENCRYPT_3WAY: 241 case ENCRYPT_ARCFOUR: 242 case ENCRYPT_CAST256: 95 243 case ENCRYPT_LOKI97: 96 case ENCRYPT_RC2: 97 case ENCRYPT_ARCFOUR: 98 case ENCRYPT_RIJNDAEL128: 244 case ENCRYPT_WAKE: 245 case ENCRYPT_ENIGMA: 99 246 case ENCRYPT_RIJNDAEL192: 100 247 case ENCRYPT_RIJNDAEL256: 101 case ENCRYPT_WAKE:102 case ENCRYPT_SERPENT:103 case ENCRYPT_ENIGMA:104 case ENCRYPT_GOST:105 248 case ENCRYPT_SAFER64: 106 249 case ENCRYPT_SAFER128: 107 250 case ENCRYPT_SAFERPLUS: 108 #endif109 return true;110 251 default: 111 252 return false; … … 113 254 } 114 255 115 static void generate_transmitted_iv(char *transmitted_iv){ 256 257 static any_encryption* get_encryption_core(int encryption_method) { 258 switch(encryption_method) { 259 case ENCRYPT_NONE: 260 return new no_encryption(); 261 case ENCRYPT_XOR: 262 return new xor_encryption(); 263 #ifdef HAVE_LIBCRYPTOPP 264 case ENCRYPT_DES: 265 return new cryptopp_encryption<CryptoPP::DES>(); 266 case ENCRYPT_3DES: 267 return new cryptopp_encryption<CryptoPP::DES_EDE3>(); 268 case ENCRYPT_CAST128: 269 return new cryptopp_encryption<CryptoPP::CAST128>(); 270 case ENCRYPT_XTEA: 271 return new cryptopp_encryption<CryptoPP::XTEA>(); 272 case ENCRYPT_3WAY: 273 return new cryptopp_encryption<CryptoPP::ThreeWay>(); 274 case ENCRYPT_BLOWFISH: 275 return new cryptopp_encryption<CryptoPP::Blowfish>(56); 276 case ENCRYPT_TWOFISH: 277 return new cryptopp_encryption<CryptoPP::Twofish>(32); 278 case ENCRYPT_RC2: 279 return new cryptopp_encryption<CryptoPP::RC2>(128); 280 case ENCRYPT_RIJNDAEL128: 281 return new cryptopp_encryption<CryptoPP::AES>(32); 282 case ENCRYPT_SERPENT: 283 return new cryptopp_encryption<CryptoPP::Serpent>(32); 284 case ENCRYPT_GOST: 285 return new cryptopp_encryption<CryptoPP::GOST>(); 286 #endif 287 default: 288 return NULL; 289 } 290 } 291 static void generate_transmitted_iv(unsigned char *transmitted_iv){ 116 292 int x; 117 293 int seed=0; … … 121 297 /*********************************************************/ 122 298 123 /* else fall back to using the current time as the seed */299 /* else fall back to using the current time as the seed */ 124 300 seed=(int)time(NULL); 125 301 … … 132 308 } 133 309 134 135 136 310 /* initializes encryption routines */ 137 void encrypt_init(std::string password, int encryption_method, char *received_iv){ 138 #ifdef HAVE_LIBMCRYPT 139 int i; 140 int iv_size; 141 #endif 142 if (isInialized_) 143 throw exception(_T("already iniatilized!")); 144 encryption_method_ = encryption_method; 145 password_ = password; 146 isInialized_ = true; 311 void encrypt_init(std::string password, int encryption_method, unsigned char *received_iv){ 312 delete core_; 313 core_ = get_encryption_core(encryption_method); 314 if (core_ == NULL) 315 throw encryption_exception(_T("Failed to get encryption core!")); 147 316 148 317 /* server generates IV used for encryption */ 149 if(received_iv==NULL) 150 generate_transmitted_iv(transmitted_iv_); 151 152 /* client receives IV from server */ 153 else 154 memcpy(transmitted_iv_,received_iv,TRANSMITTED_IV_SIZE); 155 156 #ifdef HAVE_LIBMCRYPT 157 blocksize=1; /* block size = 1 byte w/ CFB mode */ 158 keysize=7; /* default to 56 bit key length */ 159 mcrypt_mode="cfb"; /* CFB = 8-bit cipher-feedback mode */ 160 mcrypt_algorithm="unknown"; 161 #endif 162 163 164 165 /* get the name of the mcrypt encryption algorithm to use */ 166 switch(encryption_method){ 167 /* no encryption */ 168 case ENCRYPT_NONE: 169 return; 170 /* XOR or no encryption */ 171 case ENCRYPT_XOR: 172 return; 173 #ifdef HAVE_LIBMCRYPT 174 case ENCRYPT_DES: 175 mcrypt_algorithm=MCRYPT_DES; 176 break; 177 case ENCRYPT_3DES: 178 mcrypt_algorithm=MCRYPT_3DES; 179 break; 180 case ENCRYPT_CAST128: 181 mcrypt_algorithm=MCRYPT_CAST_128; 182 break; 183 case ENCRYPT_CAST256: 184 mcrypt_algorithm=MCRYPT_CAST_256; 185 break; 186 case ENCRYPT_XTEA: 187 mcrypt_algorithm=MCRYPT_XTEA; 188 break; 189 case ENCRYPT_3WAY: 190 mcrypt_algorithm=MCRYPT_3WAY; 191 break; 192 case ENCRYPT_BLOWFISH: 193 mcrypt_algorithm=MCRYPT_BLOWFISH; 194 break; 195 case ENCRYPT_TWOFISH: 196 mcrypt_algorithm=MCRYPT_TWOFISH; 197 break; 198 case ENCRYPT_LOKI97: 199 mcrypt_algorithm=MCRYPT_LOKI97; 200 break; 201 case ENCRYPT_RC2: 202 mcrypt_algorithm=MCRYPT_RC2; 203 break; 204 case ENCRYPT_ARCFOUR: 205 mcrypt_algorithm=MCRYPT_ARCFOUR; 206 break; 207 case ENCRYPT_RIJNDAEL128: 208 mcrypt_algorithm=MCRYPT_RIJNDAEL_128; 209 break; 210 case ENCRYPT_RIJNDAEL192: 211 mcrypt_algorithm=MCRYPT_RIJNDAEL_192; 212 break; 213 case ENCRYPT_RIJNDAEL256: 214 mcrypt_algorithm=MCRYPT_RIJNDAEL_256; 215 break; 216 case ENCRYPT_WAKE: 217 mcrypt_algorithm=MCRYPT_WAKE; 218 break; 219 case ENCRYPT_SERPENT: 220 mcrypt_algorithm=MCRYPT_SERPENT; 221 break; 222 case ENCRYPT_ENIGMA: 223 mcrypt_algorithm=MCRYPT_ENIGMA; 224 break; 225 case ENCRYPT_GOST: 226 mcrypt_algorithm=MCRYPT_GOST; 227 break; 228 case ENCRYPT_SAFER64: 229 mcrypt_algorithm=MCRYPT_SAFER_SK64; 230 break; 231 case ENCRYPT_SAFER128: 232 mcrypt_algorithm=MCRYPT_SAFER_SK128; 233 break; 234 case ENCRYPT_SAFERPLUS: 235 mcrypt_algorithm=MCRYPT_SAFERPLUS; 236 break; 237 #endif 238 default: 239 throw exception(_T("Invalid encryption algorithm!")); 240 } 241 242 #ifdef HAVE_LIBMCRYPT 243 /* open encryption module */ 244 if((td=mcrypt_module_open(mcrypt_algorithm,NULL,mcrypt_mode,NULL))==MCRYPT_FAILED){ 245 throw exception(_T("Could not open mcrypt algorithm '") + mcrypt_algorithm + _T("' with mode '") + mcrypt_mode + _T("'")); 246 } 247 248 /* determine size of IV buffer for this algorithm */ 249 iv_size=mcrypt_enc_get_iv_size(td); 250 if(iv_size>TRANSMITTED_IV_SIZE){ 251 throw exception(_T("IV size for crypto algorithm exceeds limits")); 252 } 253 254 /* allocate memory for IV buffer */ 255 if((IV=new char[iv_size])==NULL){ 256 throw exception(_T("Could not allocate memory for IV buffer")); 257 } 258 259 /* fill IV buffer with first bytes of IV that is going to be used to crypt (determined by server) */ 260 for(i=0;i<iv_size;i++) 261 IV[i]=transmitted_iv[i]; 262 263 /* get maximum key size for this algorithm */ 264 keysize=mcrypt_enc_get_key_size(td); 265 266 /* generate an encryption/decription key using the password */ 267 if((key=new char[keysize])==NULL){ 268 throw exception(_T("Could not allocate memory for encryption/decryption key")); 269 return ERROR; 270 } 271 ZeroMemory(key,keysize); 272 273 if(keysize<password.length()) 274 strncpy(key,password.c_str(),keysize); 275 else 276 strncpy(key,password.c_str(),password.length()); 277 278 /* initialize encryption buffers */ 279 mcrypt_generic_init(td,key,keysize,IV); 280 #endif 318 if (received_iv==NULL) { 319 unsigned char generated_iv[TRANSMITTED_IV_SIZE]; 320 generate_transmitted_iv(generated_iv); 321 core_->init(password, generated_iv, TRANSMITTED_IV_SIZE); 322 } else /* client receives IV from server */ 323 core_->init(password, received_iv, TRANSMITTED_IV_SIZE); 281 324 } 282 325 283 326 /* encrypt a buffer */ 284 void encrypt_buffer(char *buffer,int buffer_size){ 285 int x; 286 int y; 287 int password_length; 288 289 /* no crypt instance */ 290 if (!isInialized_) 291 throw new exception(_T("Not initialized!")); 292 293 /* no encryption */ 294 if(encryption_method_==ENCRYPT_NONE) 295 return; 296 297 /* simple XOR "encryption" - not meant for any real security, just obfuscates data, but its fast... */ 298 else if(encryption_method_==ENCRYPT_XOR){ 299 300 /* rotate over IV we received from the server... */ 301 for(y=0,x=0;y<buffer_size;y++,x++){ 302 303 /* keep rotating over IV */ 304 if(x>=TRANSMITTED_IV_SIZE) 305 x=0; 306 307 buffer[y]^=transmitted_iv_[x]; 308 } 309 310 /* rotate over password... */ 311 password_length=password_.length(); 312 for(y=0,x=0;y<buffer_size;y++,x++){ 313 /* keep rotating over password */ 314 if(x>=password_length) 315 x=0; 316 buffer[y]^=password_[x]; 317 } 318 return; 319 } 320 321 #ifdef HAVE_LIBMCRYPT 322 /* use mcrypt routines */ 323 else{ 324 /* encrypt each byte of buffer, one byte at a time (CFB mode) */ 325 for(x=0;x<buffer_size;x++) 326 mcrypt_generic(td,&buffer[x],1); 327 } 328 #endif 329 return; 327 void encrypt_buffer(unsigned char *buffer,int buffer_size) { 328 if (core_ == NULL) 329 throw encryption_exception(_T("No encryption core!")); 330 core_->encrypt(buffer, buffer_size); 331 } 332 333 unsigned char* get_rand_buffer(int length) { 334 CryptoPP::AutoSeededRandomPool rng; 335 unsigned char * buffer = new unsigned char[length+1]; 336 rng.GenerateBlock(buffer, length); 337 return buffer; 338 } 339 void destroy_random_buffer(unsigned char* buffer) { 340 delete [] buffer; 330 341 } 331 342
Note: See TracChangeset
for help on using the changeset viewer.








