OverSim
CryptoModule Class Reference

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

#include <CryptoModule.h>

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.

{
overlay = NULL;
}
CryptoModule::~CryptoModule ( )
virtual

Definition at line 40 of file CryptoModule.cc.

{
}

Member Function Documentation

void CryptoModule::finish ( )
protectedvirtual

Definition at line 122 of file CryptoModule.cc.

{
if (numSign > 0) {
globalStatistics->addStdDev("CryptoModule: Sign Operations/s",
numSign / time);
}
}
}
void CryptoModule::handleMessage ( cMessage *  msg)
protectedvirtual

Definition at line 117 of file CryptoModule.cc.

{
delete msg; // just discard everything we receive
}
void CryptoModule::initialize ( )
protectedvirtual

Definition at line 44 of file CryptoModule.cc.

{
numSign = 0;
// EV << "[CryptoModule::initialize() @ " << overlay->getThisNode().getIp()
// << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
// << " Reading key from file " << par("keyFile").stdstringValue()
// << endl;
}
void CryptoModule::signMessage ( BaseRpcMessage msg)
virtual

Signs an RPC message.

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

Parameters
msgthe message to sign

Definition at line 57 of file CryptoModule.cc.

{
// need to remove controlInfo before serializing
BaseRpcMessage *msgStripped = static_cast<BaseRpcMessage*>(msg->dup());
if (msgStripped->getControlInfo() != NULL) {
delete msgStripped->removeControlInfo();
}
// serialize message (needed to calculate message hash)
commBuffer.reset();
commBuffer.packObject(msgStripped);
delete msgStripped;
// calculate hash and signature
// commBuffer.getBuffer(), commBuffer.getBufferLength()
// ...
// append public key and signature
msg->getAuthBlock(0).setCert(BinaryValue("789"));
// record statistics
}
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
msgthe message to verify
Returns
true, if the message contains a valid signature

Definition at line 86 of file CryptoModule.cc.

{
if (msg->getAuthBlockArraySize() == 0) {
// message contains no signature
return false;
}
// need to remove controlInfo before serializing
BaseRpcMessage *msgStripped = static_cast<BaseRpcMessage*>(msg->dup());
if (msgStripped->getControlInfo() != NULL) {
delete msgStripped->removeControlInfo();
}
// serialize message (needed to calculate message hash)
commBuffer.reset();
commBuffer.packObject(msgStripped);
delete msgStripped;
// calculate hash and signature
commBuffer.getBuffer();
//const BinaryValue& pubKey = msg->getAuthBlock(0).getPubKey();
//const BinaryValue& signature = msg->getAuthBlock(0).getSignature();
//const BinaryValue& cert = msg->getAuthBlock(0).getCert();
//...
return true;
}

Member Data Documentation

cNetCommBuffer CryptoModule::commBuffer
private

the buffer used to serialize messages

Definition at line 84 of file CryptoModule.h.

GlobalStatistics* CryptoModule::globalStatistics
private

pointer to GlobalStatistics module in this node

Definition at line 81 of file CryptoModule.h.

int CryptoModule::numSign
private

message signature counter for statistics

Definition at line 86 of file CryptoModule.h.

BaseOverlay* CryptoModule::overlay
private

pointer to the overlay module in this node

Definition at line 82 of file CryptoModule.h.


The documentation for this class was generated from the following files: