00001 #ifndef GOSSIP_COMM_H
00002 #define GOSSIP_COMM_H
00003
00004 #include<vector>
00005 #include<map>
00006 #include<deque>
00007
00008 #include <boost/uuid/uuid.hpp>
00009 #include <boost/uuid/uuid_generators.hpp>
00010
00011 #include "digiSig.h"
00012
00013 #define MAX_SIZE 1500
00014
00015 typedef uint8_t byte;
00016 typedef std::map<std::string, uint8_t> RcvdFileMap;
00017
00018 class CDigiSig;
00019
00032 class CGossipComm{
00033
00034 public:
00040 CGossipComm(std::string sFileName);
00041 virtual ~CGossipComm();
00046 int Run();
00047
00051 void StartNetworkThread();
00059 int SendCommand(const std::string& sCommand);
00064 int SendCommand();
00068 int FindFile(const std::string& sFile);
00074 bool LoadSubscription();
00075
00080 const int* GetSocketPair(){return m_iSockPairFd;}
00081
00082
00083 private:
00087 static void *ThreadCallback(void *arg);
00088
00089 int GetSockFd(){return m_iSockFd;}
00090 void OnCommandReceived(byte* buffer, size_t length);
00091 void CheckEvent(int iFd);
00096 int SendToGossip(const std::string& sFileName, uint8_t module);
00097
00101 int CreateSocket();
00102
00108 void FindBootStrapNode();
00109
00114 int ParseConfig();
00115 std::string GetString(std::vector<std::string> & vConf, const std::string& sLine);
00116 std::string GetTwoSidedString(std::vector<std::string>& vConf, const std::string& sLine, std::string& sLeft);
00117 void StrTrim(std::string& str)const;
00118
00122 bool VerifySignature(const std::string& sFileName);
00123
00127 int PublishCert(const std::string& sCert);
00133 std::string CopyFileToKeyDir(const std::string& sFile);
00137 std::string CopyFileToCommandDir(const std::string & sFile);
00138 std::string MakeAbsPath(const std::string& sPath);
00142 void PublishCACerts();
00143 std::string GetCAName(const std::string& sCert);
00144 bool FileExistsInKeyDir(const std::string& sFileName);
00149 bool VerifyCA();
00154 bool CollectCerts(std::string& sFileName);
00155
00160 bool ReverseVerification(bool bVerifyCA=true);
00161 std::string GetPath(const std::string& sFileName);
00162 std::string GetCertificateName(const std::string& sCert);
00163
00167 bool IsSignedByHigherCA(const std::string& sIssuer);
00168 void DeleteFileFromCache(const std::string& sPath);
00169
00170
00171
00172
00176 bool IsSubscribed(const std::string& sFrom);
00181 void GossipAndExecute(const std::string& sFileName, const std::string& sFileToExecute);
00182
00183 bool IsFirstTimeReceived(const std::string& sFile);
00184 int InitSocketPair();
00185 void ShutdownNetworkThread();
00186
00190 void BootStrapKadReq(int ip, int port);
00191 uint8_t CheckFileType(const std::string& sFile);
00192 int GetKadBootIPandPort(const std::string& sFile, int& ip, int& port)const;
00193 void GetAddrPortFromString(const std::string& sLine, int& ip, int& port)const;
00194 bool CheckSelfReceived(const std::string& sFrom)const;
00198 int ExtractRunLevel(const std::string& sFrom)const;
00202 bool CheckSenderIntigrity(const std::string& sFile, const std::string& sCert);
00203
00207 int LoadPolicyProfile();
00208 uint8_t CheckModuleType(const std::string& sFile);
00209
00214 int ReportFeedback(const std::string& sFileName, bool bSuccess);
00215
00216
00217 private:
00221 std::string m_sConfigFile;
00222 pthread_t m_Thread;
00223 int m_iSockFd;
00227 uint32_t m_uGossipIP;
00231 uint16_t m_uGossipPort;
00232 uint32_t m_uClientIP;
00233 uint16_t m_uClientPort;
00234
00235 std::string m_sTestCertificate;
00236
00240 std::string m_sKeyDir;
00241
00242 bool m_bSignEnable;
00243
00244
00248 boost::uuids::uuid m_ClientName;
00249 std::string m_sClientName;
00250
00254 std::map<std::string, std::string> m_packet;
00258 std::vector<std::string> m_vCAs;
00259
00260
00261 std::vector<std::string> m_vSubscribed;
00262 std::string m_sSubscriptionFileName;
00263 bool m_bSubscribedAll;
00264
00268 std::string m_sTrustedCAName;
00272 std::string m_sTrustedCAPath;
00273 std::string m_sCommandRepository;
00274 std::string m_sLogFileName;
00275 std::string m_sCommandFileName;
00276
00277 std::map<std::string, std::string> m_cert;
00281 CDigiSig m_digisig;
00282 std::map<std::string, int> m_ca_in_file;
00283
00284 std::set<std::string> m_issuer_set;
00288 int m_iTransportProtocol;
00289
00290 std::map<std::string, int> m_MessageIDMap;
00291 int m_iSockPairFd[2];
00292 bool m_bInit;
00293
00294
00295 int m_iBootServerIP;
00296 int m_iBootServerPort;
00297
00298 std::map<std::string, uint8_t> m_recv_file_types;
00299 bool m_bBootstrapEnable;
00300
00301
00302 std::map<std::string, std::string> m_UserId;
00303 std::string m_sDefaultUserId;
00304 std::string m_sClientCertDir;
00305 std::string m_sPolicyProfile;
00306
00310 std::map<int,std::string> m_ProfileMap;
00311 std::map<std::string, uint8_t> m_recv_module_types;
00312
00313
00314 bool m_bValidateCert;
00315 std::deque<std::string> m_vCert;
00316
00317
00318 };
00319
00320
00321
00322 #endif //GOSSIP_COMM_H
00323
00324