CryptoModule Class Reference

The CryptoModule contains several method needed for message authentication. More...

#include <CryptoModule.h>

List of all members.

Public Member Functions

 CryptoModule ()
virtual ~CryptoModule ()
virtual void signMessage (BaseRpcMessage *msg)
 Signs an RPC message.
virtual bool verifyMessage (BaseRpcMessage *msg)
 Verifies the signature of an RPC message.

Protected Member Functions

virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void finish ()

Private Attributes

GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
BaseOverlayoverlay
 pointer to the overlay module in this node
cNetCommBuffer commBuffer
 the buffer used to serialize messages
int numSign
 message signature counter for statistics

Detailed Description

The CryptoModule contains several method needed for message authentication.

The CryptoModule contains several method needed for message authentication.

Author:
Ingmar Baumgart

Definition at line 41 of file CryptoModule.h.


Constructor & Destructor Documentation

CryptoModule::CryptoModule (  ) 

Definition at line 34 of file CryptoModule.cc.

00035 {
00036     globalStatistics = NULL;
00037     overlay = NULL;
00038 }

CryptoModule::~CryptoModule (  )  [virtual]

Definition at line 40 of file CryptoModule.cc.

00041 {
00042 }


Member Function Documentation

void CryptoModule::finish (  )  [protected, virtual]

Definition at line 122 of file CryptoModule.cc.

00123 {
00124     simtime_t time = globalStatistics->calcMeasuredLifetime(
00125                              overlay->getCreationTime());
00126 
00127     if (time >= GlobalStatistics::MIN_MEASURED) {
00128         if (numSign > 0) {
00129             globalStatistics->addStdDev("CryptoModule: Sign Operations/s",
00130                                         numSign / time);
00131         }
00132     }
00133 }

void CryptoModule::handleMessage ( cMessage *  msg  )  [protected, virtual]

Definition at line 117 of file CryptoModule.cc.

00118 {
00119     delete msg; // just discard everything we receive
00120 }

void CryptoModule::initialize (  )  [protected, virtual]

Definition at line 44 of file CryptoModule.cc.

00045 {
00046     globalStatistics = GlobalStatisticsAccess().get();
00047     overlay = OverlayAccess().get(this);
00048 
00049     numSign = 0;
00050 
00051 //    EV << "[CryptoModule::initialize() @ " << overlay->getThisNode().getAddress()
00052 //       << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
00053 //       << "    Reading key from file " << par("keyFile").stdstringValue()
00054 //       << endl;
00055 }

void CryptoModule::signMessage ( BaseRpcMessage *  msg  )  [virtual]

Signs an RPC message.

This method signs the given BaseRpcMessage msg with the node private key.

Parameters:
msg the message to sign

Definition at line 57 of file CryptoModule.cc.

00058 {
00059     // need to remove controlInfo before serializing
00060     BaseRpcMessage *msgStripped = static_cast<BaseRpcMessage*>(msg->dup());
00061 
00062     if (msgStripped->getControlInfo() != NULL) {
00063             delete msgStripped->removeControlInfo();
00064     }
00065 
00066     // serialize message (needed to calculate message hash)
00067     commBuffer.reset();
00068     commBuffer.packObject(msgStripped);
00069     delete msgStripped;
00070 
00071     // calculate hash and signature
00072     // commBuffer.getBuffer(), commBuffer.getBufferLength()
00073 
00074     // ...
00075 
00076     // append public key and signature
00077     msg->setAuthBlockArraySize(1);
00078     msg->getAuthBlock(0).setPubKey(BinaryValue("123"));
00079     msg->getAuthBlock(0).setSignature(BinaryValue("456"));
00080     msg->getAuthBlock(0).setCert(BinaryValue("789"));
00081 
00082     // record statistics
00083     RECORD_STATS(numSign++);
00084 }

bool CryptoModule::verifyMessage ( BaseRpcMessage *  msg  )  [virtual]

Verifies the signature of an RPC message.

This method verifies the signature of the BaseRpcMessage msg and returns true, if the signature is valid.

Parameters:
msg the message to verify
Returns:
true, if the message contains a valid signature

Definition at line 86 of file CryptoModule.cc.

00087 {
00088     if (msg->getAuthBlockArraySize() == 0) {
00089         // message contains no signature
00090         return false;
00091     }
00092 
00093     // need to remove controlInfo before serializing
00094     BaseRpcMessage *msgStripped = static_cast<BaseRpcMessage*>(msg->dup());
00095 
00096     if (msgStripped->getControlInfo() != NULL) {
00097             delete msgStripped->removeControlInfo();
00098     }
00099 
00100     // serialize message (needed to calculate message hash)
00101     commBuffer.reset();
00102     commBuffer.packObject(msgStripped);
00103     delete msgStripped;
00104 
00105     // calculate hash and signature
00106     commBuffer.getBuffer();
00107 
00108     //const BinaryValue& pubKey = msg->getAuthBlock(0).getPubKey();
00109     //const BinaryValue& signature = msg->getAuthBlock(0).getSignature();
00110     //const BinaryValue& cert = msg->getAuthBlock(0).getCert();
00111 
00112     //...
00113 
00114     return true;
00115 }


Member Data Documentation

the buffer used to serialize messages

Definition at line 84 of file CryptoModule.h.

Referenced by signMessage(), and verifyMessage().

pointer to GlobalStatistics module in this node

Definition at line 81 of file CryptoModule.h.

Referenced by CryptoModule(), finish(), and initialize().

int CryptoModule::numSign [private]

message signature counter for statistics

Definition at line 86 of file CryptoModule.h.

Referenced by finish(), initialize(), and signMessage().

pointer to the overlay module in this node

Definition at line 82 of file CryptoModule.h.

Referenced by CryptoModule(), finish(), and initialize().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3