Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

snfNETmgr.hpp 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // snfNETmgr.hpp
  2. //
  3. // (C) Copyright 2006 - 2009 ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // SNF network node manager.
  7. // 20080312 _M Refactored exceptions to std::runtime_exception
  8. #ifndef snfNETmgr_included
  9. #define snfNETmgr_included
  10. #include <stdexcept>
  11. #include <vector>
  12. #include "networking.hpp"
  13. #include "timing.hpp"
  14. #include "threading.hpp"
  15. #include "snfCFGmgr.hpp"
  16. #include "snfLOGmgr.hpp"
  17. #include "snfGBUdbmgr.hpp"
  18. #include "mangler.hpp"
  19. class snfScanData; // Declare snfScanData;
  20. class snfLOGmgr; // Declare snfLOGmgr;
  21. class snfGBUdbmgr; // Declare snfGBUdbmgr;
  22. using namespace std;
  23. typedef vector<unsigned char> PadBuffer; // Holds one time pads etc.
  24. const int SNFHandshakeSize = 8; // Size of an SNF Handshake.
  25. const int SNFChallengeSize = 32; // Size of an SNF Challenge.
  26. const int SNFPadSize = 16; // Size of an SNF One Time Pad.
  27. const int SNFSignatureSize = SNFHandshakeSize; // Size of an SNF Signature.
  28. class snfNETmgr : public Thread { // The network process manager.
  29. private:
  30. Mutex myMutex; // Object is busy mutex.
  31. Mutex ResolverMutex; // Mutex to protect lookups.
  32. Mutex ConfigMutex; // Configuration change/use mutex.
  33. Mutex PadMutex; // Pad use/evoloution mutex.
  34. snfLOGmgr* myLOGmgr; // Log manager to use.
  35. snfGBUdbmgr* myGBUdbmgr; // GBUdb manager to use.
  36. volatile bool isTimeToStop; // Time to shutdown flag.
  37. volatile bool isConfigured; // True once ready to run.
  38. Timeout SYNCTimer; // SYNC timer.
  39. void evolvePad(string Entropy = ""); // Add entropy to and evolve.
  40. MANGLER PadGenerator; // Random pad source.
  41. PadBuffer OneTimePad(int Len = SNFPadSize); // Provides Len bytes of one time pad.
  42. // Configuration data
  43. string License; // Node (license) Id?
  44. string SecurityKey; // Security key for this rulebase?
  45. string RulebaseFilePath; // Where we can find our rulebase?
  46. string HandshakeFilePath; // Where do we keep our handshake?
  47. string UpdateReadyFilePath; // Where do I put update trigger files?
  48. string SyncHostName; // Where do we connect to sync?
  49. int SyncHostPort; // What port do we use to sync?
  50. int SyncSecsOverride; // How may secs between sync (override)?
  51. int SyncSecsConfigured; // How many secs to sync (nominally)?
  52. PadBuffer Handshake(); // What is the current handshake?
  53. PadBuffer& Handshake(PadBuffer& NewHandshake); // Store a new handshake.
  54. PadBuffer CurrentHandshake; // Where we keep our current handshake.
  55. void postUpdateTrigger(string& updateUTC); // Post an update trigger file.
  56. string SamplesBuffer; // Message Samples Appended Together.
  57. string getSamples(); // Syncrhonized way to get Samples.
  58. string ReportsBuffer; // Status Reports Appended Together.
  59. string getReports(); // Synchronized way to get Reports.
  60. public:
  61. snfNETmgr(); // Construct and start.
  62. ~snfNETmgr(); // Shutdown and destruct.
  63. void stop(); // How to stop the thread.
  64. void myTask(); // Define the thread task.
  65. void linkLOGmgr(snfLOGmgr& L); // Set the LOGmgr.
  66. void linkGBUdbmgr(snfGBUdbmgr& G); // Set the GBUdbmgr.
  67. void configure(snfCFGData& CFGData); // Update the configuration.
  68. class SyncFailed : public runtime_error { // Thrown if sync doesn't work.
  69. public: SyncFailed(const string& w):runtime_error(w) {}
  70. };
  71. // Operations
  72. // Why have configure AND pass CFGData in action calls?
  73. // The configure() method updates background task configuration itmes.
  74. // The CFGData passed on action calls informs the configuration in use with
  75. // that particular operation -- it might be different than the current CFG
  76. // if the CFG has been updated recently (reload).
  77. void sendSample( // Send a sampled message...
  78. snfCFGData& CFGData, // Use this configuration,
  79. snfScanData& ScanData, // Include this scan data,
  80. const unsigned char* MessageBuffer, // This is the message itself
  81. int MessageLength // and it is this size.
  82. );
  83. void sendReport(const string& StatusReportText); // Send a status report...
  84. void sync(); // Do the whole "sync" thing.
  85. // Utility Functions
  86. unsigned long ResolveHostIPFromName(const string& N); // Find the IP.
  87. string& RulebaseUTC(string& t); // Gets local rulebase file UTC.
  88. const static ThreadType Type; // The thread's type.
  89. const static ThreadState Sleeping; // Taking a break.
  90. const static ThreadState SYNC_Connect; // Connecting to SYNC server.
  91. const static ThreadState SYNC_Read_Challenge; // Reading challenge.
  92. const static ThreadState SYNC_Compute_Response; // Computing crypto response.
  93. const static ThreadState SYNC_Send_Response; // Sending crypto response.
  94. const static ThreadState SYNC_Read_Availabilty; // Reading rulebase status.
  95. const static ThreadState SYNC_Send_GBUdb_Alerts; // Sending GBUdb alerts.
  96. const static ThreadState SYNC_Send_Status_Reports; // Sending status reports.
  97. const static ThreadState SYNC_Send_Samples; // Sending message samples.
  98. const static ThreadState SYNC_Send_End_Of_Report; // Sending end of client data.
  99. const static ThreadState SYNC_Read_Server_Response; // Reading server data.
  100. const static ThreadState SYNC_Close_Connection; // Closing connection.
  101. const static ThreadState SYNC_Parse_GBUdb_Reflections; // Parsing GBUdb reflections.
  102. const static ThreadState SYNC_Log_Event; // Logging SYNC event.
  103. };
  104. #endif