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 | |
| GlobalStatistics * | globalStatistics |
| pointer to GlobalStatistics module in this node | |
| BaseOverlay * | overlay |
| pointer to the overlay module in this node | |
| cNetCommBuffer | commBuffer |
| the buffer used to serialize messages | |
| int | numSign |
| message signature counter for statistics | |
The CryptoModule contains several method needed for message authentication.
The CryptoModule contains several method needed for message authentication.
Definition at line 41 of file CryptoModule.h.
| CryptoModule::CryptoModule | ( | ) |
Definition at line 34 of file CryptoModule.cc.
{
globalStatistics = NULL;
overlay = NULL;
}
| CryptoModule::~CryptoModule | ( | ) | [virtual] |
Definition at line 40 of file CryptoModule.cc.
{
}
| void CryptoModule::finish | ( | ) | [protected, virtual] |
Definition at line 122 of file CryptoModule.cc.
{
simtime_t time = globalStatistics->calcMeasuredLifetime(
overlay->getCreationTime());
if (time >= GlobalStatistics::MIN_MEASURED) {
if (numSign > 0) {
globalStatistics->addStdDev("CryptoModule: Sign Operations/s",
numSign / time);
}
}
}
| void CryptoModule::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 117 of file CryptoModule.cc.
{
delete msg; // just discard everything we receive
}
| void CryptoModule::initialize | ( | ) | [protected, virtual] |
Definition at line 44 of file CryptoModule.cc.
{
globalStatistics = GlobalStatisticsAccess().get();
overlay = OverlayAccess().get(this);
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.
| msg | the 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->setAuthBlockArraySize(1);
msg->getAuthBlock(0).setPubKey(BinaryValue("123"));
msg->getAuthBlock(0).setSignature(BinaryValue("456"));
msg->getAuthBlock(0).setCert(BinaryValue("789"));
// record statistics
RECORD_STATS(numSign++);
}
| 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.
| msg | the message to verify |
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;
}
cNetCommBuffer CryptoModule::commBuffer [private] |
the buffer used to serialize messages
Definition at line 84 of file CryptoModule.h.
Referenced by signMessage(), and verifyMessage().
GlobalStatistics* CryptoModule::globalStatistics [private] |
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().
BaseOverlay* CryptoModule::overlay [private] |
pointer to the overlay module in this node
Definition at line 82 of file CryptoModule.h.
Referenced by CryptoModule(), finish(), and initialize().
1.7.1