IBR-DTNSuite
0.8
|
00001 #ifndef _PAYLOAD_INTEGRITY_BLOCK_H_ 00002 #define _PAYLOAD_INTEGRITY_BLOCK_H_ 00003 00004 #include "ibrdtn/security/SecurityBlock.h" 00005 #include "ibrdtn/security/SecurityKey.h" 00006 #include "ibrdtn/data/ExtensionBlock.h" 00007 #include "ibrdtn/data/Bundle.h" 00008 #include <openssl/evp.h> 00009 00010 namespace dtn 00011 { 00012 namespace security 00013 { 00022 class PayloadIntegrityBlock : public SecurityBlock 00023 { 00024 friend class dtn::data::Bundle; 00025 public: 00026 class Factory : public dtn::data::ExtensionBlock::Factory 00027 { 00028 public: 00029 Factory() : dtn::data::ExtensionBlock::Factory(PayloadIntegrityBlock::BLOCK_TYPE) {}; 00030 virtual ~Factory() {}; 00031 virtual dtn::data::Block* create(); 00032 }; 00033 00035 static const char BLOCK_TYPE = SecurityBlock::PAYLOAD_INTEGRITY_BLOCK; 00036 00039 virtual ~PayloadIntegrityBlock(); 00040 00046 static void sign(dtn::data::Bundle &bundle, const SecurityKey &key, const dtn::data::EID& destination); 00047 00056 static void verify(const dtn::data::Bundle &bundle, const SecurityKey &key); 00057 00064 static void strip(dtn::data::Bundle& bundle, const SecurityKey &key, const bool all = false); 00065 00070 static void strip(dtn::data::Bundle& bundle); 00071 00076 virtual std::istream &deserialize(std::istream &stream, const size_t length); 00077 00078 protected: 00083 PayloadIntegrityBlock(); 00084 00090 virtual size_t getSecurityResultSize() const; 00091 00092 private: 00096 int result_size; 00097 00104 static const std::string calcHash(const dtn::data::Bundle &bundle, const SecurityKey &key, PayloadIntegrityBlock& ignore); 00105 00116 static void verify(const dtn::data::Bundle& bundle, const SecurityKey &key, const PayloadIntegrityBlock &sb, const bool use_eid = true); 00117 00125 void setResultSize(const SecurityKey &key); 00126 }; 00127 00131 static PayloadIntegrityBlock::Factory __PayloadIntegrityBlockFactory__; 00132 } 00133 } 00134 #endif /* _PAYLOAD_INTEGRITY_BLOCK_H_ */