Mixe for Privacy and Anonymity in the Internet
Macros | Functions | Variables
CAUtil.cpp File Reference
#include "StdAfx.h"
#include "CAUtil.hpp"
#include "CABase64.hpp"
#include "CAMsg.hpp"
#include "xml/DOM_Output.hpp"
#include "CASymCipher.hpp"
Include dependency graph for CAUtil.cpp:

Go to the source code of this file.

Macros

#define XML_ENCODE_KEY_TEMPLATE   "<EncryptedKey><EncryptionMethod Algorithm=\"RSA\"/><CipherData><CipherValue>%s</CipherValue></CipherData></EncryptedKey>"
 

Functions

UINT32 strtrim (UINT8 *s)
 Removes leading and ending whitespaces (chars<=32) from a zero terminated string. More...
 
UINT32 toLower (UINT8 *a_string)
 
UINT8bytes2hex (const void *bytes, UINT32 len)
 Converts the byte array to a hex string. More...
 
SINT32 memtrim (UINT8 *dest, const UINT8 *src, UINT32 size)
 Removes leading and ending whitespaces (chars<=32) from a byte array. More...
 
char * strins (const char *src, UINT32 pos, const char *ins)
 Inserts a String ins in a String src starting after pos chars. More...
 
char * strins (const char *src, const char *pos, const char *ins)
 Inserts a String ins in a String src starting at the char pos points to. More...
 
void logMemoryUsage ()
 Log information about the current memory (heap) usage. More...
 
SINT32 getcurrentTime (timespec &t)
 Gets the current Systemtime in milli seconds. More...
 
SINT32 getcurrentTimeMillis (UINT64 &u64Time)
 Gets the current Systemtime in milli seconds. More...
 
SINT32 getcurrentTimeMicros (UINT64 &u64Time)
 Gets the current Systemtime in micros seconds. More...
 
SINT32 initRandom ()
 
SINT32 compDate (struct tm *date1, struct tm *date2)
 
SINT32 getRandom (UINT32 *val)
 Gets 32 random bits. More...
 
SINT32 getRandom (UINT16 *val)
 Gets 16 random bits. More...
 
SINT32 getRandom (UINT64 *val)
 
SINT32 getRandom (UINT8 *buff, UINT32 len)
 Gets some random bytes. More...
 
SINT32 msSleep (UINT32 ms)
 Sleeps ms milliseconds. More...
 
SINT32 sSleep (UINT32 sec)
 Sleeps sec Seconds. More...
 
UINT32 getMemoryUsage ()
 
SINT32 getDOMChildByName (const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
 
SINT32 getDOMChildByName (const DOMNode *pNode, const XMLCh *const name, DOMNode *&a_child, bool deep)
 
SINT32 getDOMChildByName (const DOMNode *pNode, const char *const name, DOMNode *&a_child, bool deep)
 
SINT32 getSignatureElements (DOMNode *parent, DOMNode **signatureNodes, UINT32 *length)
 
SINT32 integrateDOMNode (const DOMNode *srcNode, DOMNode *dstNode, bool recursive, bool replace)
 integrates the source node in the destination Node. More...
 
bool equals (const XMLCh *const e1, const char *const e2)
 
void initDOMParser ()
 
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument (const UINT8 *const buff, UINT32 len)
 Parses a buffer containing an XML document and returns this document. More...
 
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument (const UINT8 *const pathOrURL)
 parses a file via path or URL More...
 
void releaseDOMParser ()
 
SINT32 getNodeName (const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
 
SINT32 getDOMElementValue (const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
 Returns the content of the text node(s) under elem as null-terminated C String. More...
 
SINT32 getDOMElementAttribute (const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
 
SINT32 getDOMElementAttribute (const DOMNode *const elem, const char *attrName, SINT32 *value)
 
DOMElement * createDOMElement (XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
 Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc. More...
 
DOMText * createDOMText (XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const text)
 Creates a new DOMText with the given value which belongs to the DOMDocument owernDoc. More...
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, const char *value)
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, const UINT8 *value)
 
SINT32 setCurrentTimeMilliesAsDOMAttribute (DOMNode *pElem)
 
UINT8getTermsAndConditionsTemplateRefId (DOMNode *tcTemplateRoot)
 
SINT32 getDOMElementValue (const DOMElement *pElem, UINT32 &value, UINT32 defaultValue)
 Gets the value from an DOM-Element as UINT32. More...
 
SINT32 getDOMElementValue (const DOMElement *const pElem, UINT32 *value)
 
SINT32 setDOMElementValue (DOMElement *pElem, SINT32 value)
 
SINT32 setDOMElementValue (DOMElement *pElem, double floatValue)
 
SINT32 setDOMElementValue (DOMElement *pElem, const UINT64 text)
 Sets the decimal text representation of a 64bit integer as node value TODO: implement this for non-64bit platforms. More...
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, UINT64 value)
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, SINT64 value)
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, SINT32 value)
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, bool value)
 
SINT32 setDOMElementValue (DOMElement *pElem, bool value)
 
SINT32 getDOMElementValue (const DOMElement *const pElem, SINT32 *value)
 
SINT32 getDOMElementValue (const DOMElement *const pElem, double *value)
 
SINT32 getDOMElementValue (const DOMNode *const pElem, UINT64 &value)
 
SINT32 getDOMElementValue (const DOMElement *const pElem, SINT64 &value)
 
SINT32 encryptXMLElement (DOMNode *node, CAASymCipher *pRSA)
 The resulting encrypted xml struct is as follows: More...
 
UINT8encryptXMLElement (UINT8 *inbuff, UINT32 inlen, UINT32 &outlen, CAASymCipher *pRSA)
 Encrypts an XML-Element by wrapping it with: More...
 
SINT32 decryptXMLElement (DOMNode *node, CAASymCipher *pRSA)
 Replaces a DOM element with a deencrypted version of this element. More...
 
UINT8readFile (const UINT8 *const name, UINT32 *size)
 ONLY_LOCAL_PROXY or first. More...
 
SINT32 saveFile (const UINT8 *const name, const UINT8 *const buff, UINT32 buffSize)
 
SINT32 parseUINT16 (const UINT8 *str, UINT16 &value)
 Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in milliseconds since the epoch. More...
 
SINT32 parseU64 (const UINT8 *str, UINT64 &value)
 Parses a 64bit unsigned integer. More...
 
SINT32 parseS64 (const UINT8 *str, SINT64 &value)
 Parses a 64bit signed integer. More...
 
SINT32 readPasswd (UINT8 *buff, UINT32 len)
 Read a passwd (i.e. More...
 
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument ()
 Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in seconds since the epoch. More...
 
SINT32 setDOMElementValue (DOMElement *pElem, UINT32 value)
 
SINT32 setDOMElementValue (DOMElement *pElem, const UINT8 *value)
 
SINT32 setDOMElementAttribute (DOMNode *pElem, const char *attrName, UINT32 value)
 
SINT32 getDOMElementAttribute (const DOMNode *const elem, const char *attrName, UINT32 &value)
 
SINT32 decodeXMLEncryptedKey (UINT8 *key, UINT32 *keylen, const UINT8 *const xml, UINT32 xmllen, CAASymCipher *pRSA)
 
SINT32 decodeXMLEncryptedKey (UINT8 *key, UINT32 *keylen, const DOMNode *root, CAASymCipher *pRSA)
 
void __encryptKey (UINT8 *key, UINT32 keylen, UINT8 *outBuff, UINT32 *outLen, CAASymCipher *pRSA)
 
SINT32 encodeXMLEncryptedKey (UINT8 *key, UINT32 keylen, UINT8 *xml, UINT32 *xmllen, CAASymCipher *pRSA)
 
SINT32 encodeXMLEncryptedKey (UINT8 *key, UINT32 keylen, DOMElement *&elemRootEncodedKey, XERCES_CPP_NAMESPACE::DOMDocument *docOwner, CAASymCipher *pRSA)
 
DOMNodeList * getElementsByTagName (DOMElement *pElem, const char *const name)
 
SINT32 getLastDOMChildByName (const DOMNode *pNode, const char *const name, DOMElement *&a_child)
 
SINT32 getLastDOMChildByName (const DOMNode *pNode, const char *const name, DOMNode *&a_child)
 
SINT32 getLastDOMChildByName (const DOMNode *pNode, const XMLCh *const name, DOMNode *&a_child)
 
SINT32 getDOMElementAttribute (const DOMNode *const elem, const char *attrName, bool &value)
 
SINT32 getDOMElementAttribute (const DOMNode *const elem, const char *attrName, SINT64 &value)
 
SINT32 getDOMElementAttribute (const DOMNode *const elem, const char *attrName, UINT64 &value)
 
SINT32 getDOMElementValue (const DOMElement *const pElem, UINT16 *value)
 
void formatBytesPerSecond (UINT8 *buff, UINT32 buffsize, UINT64 bytespersecond)
 

Variables

XercesDOMParser * theDOMParser =NULL
 
CAMutextheParseDOMDocumentLock = NULL
 

Macro Definition Documentation

◆ XML_ENCODE_KEY_TEMPLATE

#define XML_ENCODE_KEY_TEMPLATE   "<EncryptedKey><EncryptionMethod Algorithm=\"RSA\"/><CipherData><CipherValue>%s</CipherValue></CipherData></EncryptedKey>"

Function Documentation

◆ __encryptKey()

void __encryptKey ( UINT8 key,
UINT32  keylen,
UINT8 outBuff,
UINT32 outLen,
CAASymCipher pRSA 
)

Definition at line 1673 of file CAUtil.cpp.

1674 {
1675  UINT8 tmpBuff[1024];
1676  memset(tmpBuff,0,sizeof(tmpBuff));
1677  memcpy(tmpBuff+128-keylen,key,keylen);
1678  pRSA->encrypt(tmpBuff,tmpBuff);
1679  CABase64::encode(tmpBuff,128,outBuff,outLen);
1680  outBuff[*outLen]=0;
1681 }
unsigned char UINT8
Definition: basetypedefs.h:135
SINT32 encrypt(const UINT8 *from, UINT8 *to)
Encrypts exactly one block which is stored in from.
static SINT32 encode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
Definition: CABase64.cpp:102

References CABase64::encode(), and CAASymCipher::encrypt().

Referenced by encodeXMLEncryptedKey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bytes2hex()

UINT8* bytes2hex ( const void *  bytes,
UINT32  len 
)

Converts the byte array to a hex string.

the caller is responsible for deleting the string

Definition at line 90 of file CAUtil.cpp.

91  {
92  if(bytes==NULL||len==0)
93  return NULL;
94  UINT8* buff=new UINT8[len*3+1];
95  UINT32 aktInd=0;
96  for(UINT32 i=0;i<len;i++)
97  {
98  UINT8 b1=((UINT8*)bytes)[i];
99  UINT8 b=(b1>>4);
100  if(b>9)
101  b+=55;
102  else
103  b+=48;
104  buff[aktInd++]=b;
105  b=(b1&0x0F);
106  if(b>9)
107  b+=55;
108  else
109  b+=48;
110  buff[aktInd++]=b;
111  buff[aktInd++]=32;
112  }
113  buff[len*3]=0;
114  return buff;
115  }
unsigned int UINT32
Definition: basetypedefs.h:131
UINT16 len
Definition: typedefs.hpp:0

References len.

Referenced by CAChain::getPrintableChainId(), and CAThread::start().

Here is the caller graph for this function:

◆ compDate()

SINT32 compDate ( struct tm *  date1,
struct tm *  date2 
)

Definition at line 323 of file CAUtil.cpp.

324 {
325  //year
326  if(date1->tm_year != date2->tm_year)
327  {
328  return (date1->tm_year < date2->tm_year) ? -1 : 1;
329  }
330  if(date1->tm_mon != date2->tm_mon)
331  {
332  return (date1->tm_mon < date2->tm_mon) ? -1 : 1;
333  }
334  if(date1->tm_mday != date2->tm_mday)
335  {
336  return (date1->tm_mday < date2->tm_mday) ? -1 : 1;
337  }
338  return 0;
339 }

◆ createDOMDocument()

XERCES_CPP_NAMESPACE::DOMDocument* createDOMDocument ( )

Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in seconds since the epoch.

Creates an empty DOM DOcument.

Parameters
strTimestampthe string containing the timestamp
secondsan integer variable that gets the seconds value.
Todo:
think about timezone handling

Converts a timestamp (in seconds) to the String JDBC timestamp escape format (YYYY-MM-DD HH:MM:SS)

Parameters
secondsinteger value containing the timestamp in seconds since the epoch
strTimestampa string buffer that gets the result
lenthe buffer length
Todo:
think about timezone handling

Definition at line 1568 of file CAUtil.cpp.

1569  {
1570  DOMImplementation* pImpl=DOMImplementation::getImplementation();
1571  return pImpl->createDocument();
1572  }

Referenced by CACmdLnOptions::CACmdLnOptions(), CACmdLnOptions::createMixOnCDConfiguration(), CAFirstMix::doUserLogin_internal(), CAASymCipher::getPublicKeyAsXML(), CAAccountingInstance::handleAccountCertificate_internal(), CAFirstMix::handleTermsAndConditionsLogin(), CAFirstMix::init(), CAMix::initMixCascadeInfo(), CAReplayCtrlChannelMsgProc::initTimestampsMessageTemplate(), CAAccountingInstance::makeCCRequest(), CAAccountingInstance::makeInitialCCRequest(), CAAccountingInstance::prepareCCRequest(), CAReplayCtrlChannelMsgProc::proccessGetTimestamp(), CAReplayCtrlChannelMsgProc::proccessGotTimestamp(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CAAccountingInstance::sendAILoginConfirmation(), CAReplayCtrlChannelMsgProc::sendGetTimestamp(), CAAbstractXMLSignable::setSignature(), CACmdLnOptions::setTermsAndConditionsList(), CAAccountingBIInterface::settleAll(), TermsAndConditions::TermsAndConditions(), and CAAbstractXMLEncodable::toXmlDocument().

Here is the caller graph for this function:

◆ createDOMElement()

DOMElement* createDOMElement ( XERCES_CPP_NAMESPACE::DOMDocument *  pOwnerDoc,
const char *const  name 
)

Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.

Definition at line 814 of file CAUtil.cpp.

815  {
816  XMLCh* n=XMLString::transcode(name);
817  DOMElement* ret=pOwnerDoc->createElement(n);
818  XMLString::release(&n);
819  return ret;
820  }

Referenced by CAASymCipher::addKeyPart(), CAMix::appendCompatibilityInfo(), CACmdLnOptions::buildDefaultConfig(), CAFirstMix::doUserLogin_internal(), CACertStore::encode(), CACertificate::encode(), encodeXMLEncryptedKey(), encryptXMLElement(), CAInfoService::getCascadeHeloXMLAsString(), CACmdLnOptions::getMixXml(), CAASymCipher::getPublicKeyAsDOMElement(), CASignature::getSignKey(), CAAccountingInstance::handleAccountCertificate_internal(), CAFirstMix::handleTermsAndConditionsLogin(), CAMix::initMixCascadeInfo(), CAReplayCtrlChannelMsgProc::initTimestampsMessageTemplate(), CAAccountingInstance::makeCCRequest(), CAAccountingInstance::makeInitialCCRequest(), CAAccountingInstance::prepareCCRequest(), CAReplayCtrlChannelMsgProc::proccessGetTimestamp(), CAReplayCtrlChannelMsgProc::proccessGotTimestamp(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CACmdLnOptions::processXmlConfiguration(), CAAccountingInstance::sendAILoginConfirmation(), CAReplayCtrlChannelMsgProc::sendGetTimestamp(), CACmdLnOptions::setMixName(), CACmdLnOptions::setNextMix(), CACmdLnOptions::setPrepaidInterval(), CACmdLnOptions::setPrevMix(), CACmdLnOptions::setSymChannelCipherAlgorithm(), CACmdLnOptions::setTargetInterfaces(), CAAccountingBIInterface::settleAll(), CAMultiSignature::signXML(), CAListenerInterface::toDOMElement(), and CAXMLErrorMessage::toXmlElement().

Here is the caller graph for this function:

◆ createDOMText()

DOMText * createDOMText ( XERCES_CPP_NAMESPACE::DOMDocument *  pOwnerDoc,
const char *const  text 
)

Creates a new DOMText with the given value which belongs to the DOMDocument owernDoc.

Definition at line 822 of file CAUtil.cpp.

823  {
824  XMLCh* t=XMLString::transcode(text);
825  DOMText* ret= pOwnerDoc->createTextNode(t);
826  XMLString::release(&t);
827  return ret;
828  }

Referenced by CAASymCipher::addKeyPart().

Here is the caller graph for this function:

◆ decodeXMLEncryptedKey() [1/2]

SINT32 decodeXMLEncryptedKey ( UINT8 key,
UINT32 keylen,
const DOMNode *  root,
CAASymCipher pRSA 
)

Definition at line 1646 of file CAUtil.cpp.

1647 {
1648  DOMNode* elemCipherValue=NULL;
1649  if(getDOMChildByName(root,"CipherValue",elemCipherValue,true)!=E_SUCCESS)
1650  return E_UNKNOWN;
1651  UINT8 buff[2048];
1652  UINT32 bufflen=2048;
1653  if(getDOMElementValue(elemCipherValue,buff,&bufflen)!=E_SUCCESS)
1654  return E_UNKNOWN;
1655  CABase64::decode(buff,bufflen,buff,&bufflen);
1656  pRSA->decrypt(buff,buff);
1657  for(SINT32 i=127;i>=0;i--)
1658  {
1659  if(buff[i]!=0)
1660  {
1661  if(i>32)
1662  *keylen=64;
1663  else if(i>16)
1664  *keylen=32;
1665  else
1666  *keylen=16;
1667  }
1668  }
1669  memcpy(key,buff+128-(*keylen),(*keylen));
1670  return E_SUCCESS;
1671 }
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
Definition: CAUtil.cpp:746
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
Definition: CAUtil.cpp:458
signed int SINT32
Definition: basetypedefs.h:132
SINT32 decrypt(const UINT8 *from, UINT8 *to)
Decrypts exactly one block which is stored in from.
static SINT32 decode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
Definition: CABase64.cpp:41
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References CABase64::decode(), CAASymCipher::decrypt(), E_SUCCESS, E_UNKNOWN, getDOMChildByName(), and getDOMElementValue().

Here is the call graph for this function:

◆ decodeXMLEncryptedKey() [2/2]

SINT32 decodeXMLEncryptedKey ( UINT8 key,
UINT32 keylen,
const UINT8 *const  xml,
UINT32  xmllen,
CAASymCipher pRSA 
)

Definition at line 1625 of file CAUtil.cpp.

1626 {
1627  XERCES_CPP_NAMESPACE::DOMDocument* pDoc=parseDOMDocument(xml,xmllen);
1628  if(pDoc == NULL)
1629  {
1630  return E_UNKNOWN;
1631  }
1632  DOMElement* root=pDoc->getDocumentElement();
1633  if(root == NULL)
1634  {
1635  return E_UNKNOWN;
1636  }
1637  SINT32 ret=decodeXMLEncryptedKey(key,keylen,root,pRSA);
1638  if (pDoc != NULL)
1639  {
1640  pDoc->release();
1641  pDoc = NULL;
1642  }
1643  return ret;
1644 }
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
Definition: CAUtil.cpp:663
SINT32 decodeXMLEncryptedKey(UINT8 *key, UINT32 *keylen, const UINT8 *const xml, UINT32 xmllen, CAASymCipher *pRSA)
Definition: CAUtil.cpp:1625

References E_UNKNOWN, and parseDOMDocument().

Referenced by CALastMix::processKeyExchange(), and CAMiddleMix::processKeyExchange().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decryptXMLElement()

SINT32 decryptXMLElement ( DOMNode *  node,
CAASymCipher pRSA 
)

Replaces a DOM element with a deencrypted version of this element.

Definition at line 1224 of file CAUtil.cpp.

1225 {
1226  XERCES_CPP_NAMESPACE::DOMDocument* doc=node->getOwnerDocument();
1227  if(! equals(node->getNodeName(),"EncryptedData"))
1228  return E_UNKNOWN;
1229  DOMNode* elemKeyInfo=NULL;
1230  getDOMChildByName(node,"ds:KeyInfo",elemKeyInfo,false);
1231  DOMNode* elemEncKey=NULL;
1232  getDOMChildByName(elemKeyInfo,"EncryptedKey",elemEncKey,false);
1233  DOMNode* elemCipherValue=NULL;
1234  getDOMChildByName(elemEncKey,"CipherValue",elemCipherValue,true);
1235  UINT8* cipherValue=new UINT8[1000];
1236  UINT32 len=1000;
1237  if(getDOMElementValue(elemCipherValue,cipherValue,&len)!=E_SUCCESS)
1238  {
1239  delete[] cipherValue;
1240  cipherValue = NULL;
1241  return E_UNKNOWN;
1242  }
1243  CABase64::decode(cipherValue,len,cipherValue,&len);
1244  if( pRSA->decryptOAEP(cipherValue,cipherValue,&len)!=E_SUCCESS||
1245  len!=32)
1246  {
1247  delete[] cipherValue;
1248  cipherValue = NULL;
1249  return E_UNKNOWN;
1250  }
1251  CASymCipher *pSymCipher=new CASymCipher();
1252  pSymCipher->setKey(cipherValue,false);
1253  pSymCipher->setIV(cipherValue+16);
1254 
1255  DOMNode* elemCipherData=NULL;
1256  getDOMChildByName(node,"CipherData",elemCipherData,false);
1257  getDOMChildByName(elemCipherData,"CipherValue",elemCipherValue,false);
1258  len=1000;
1259  if(getDOMElementValue(elemCipherValue,cipherValue,&len)!=E_SUCCESS)
1260  {
1261  delete pSymCipher;
1262  pSymCipher = NULL;
1263  delete[] cipherValue;
1264  cipherValue = NULL;
1265  return E_UNKNOWN;
1266  }
1267  if(CABase64::decode(cipherValue,len,cipherValue,&len)!=E_SUCCESS)
1268  {
1269  delete pSymCipher;
1270  pSymCipher = NULL;
1271  delete[] cipherValue;
1272  cipherValue = NULL;
1273  return E_UNKNOWN;
1274  }
1275  SINT32 ret=pSymCipher->decryptCBCwithPKCS7(cipherValue,cipherValue,&len);
1276  delete pSymCipher;
1277  pSymCipher = NULL;
1278  if(ret!=E_SUCCESS)
1279  {
1280  delete[] cipherValue;
1281  cipherValue = NULL;
1282  return E_UNKNOWN;
1283  }
1284  //now the need to parse the plaintext...
1285  XERCES_CPP_NAMESPACE::DOMDocument* docPlain=parseDOMDocument(cipherValue,len);
1286  delete[] cipherValue;
1287  cipherValue = NULL;
1288  DOMNode* elemPlainRoot=NULL;
1289  if(docPlain==NULL)
1290  return E_UNKNOWN;
1291  if((elemPlainRoot=docPlain->getDocumentElement())==NULL)
1292  {
1293  if (docPlain != NULL)
1294  {
1295  docPlain->release();
1296  docPlain = NULL;
1297  }
1298  return E_UNKNOWN;
1299  }
1300  elemPlainRoot=doc->importNode(elemPlainRoot,true);
1301  DOMNode* parent=node->getParentNode();
1302  if(parent->getNodeType()==DOMNode::DOCUMENT_NODE)
1303  {
1304  DOMNode* n=parent->removeChild(node);
1305  if (n != NULL)
1306  {
1307  n->release();
1308  n = NULL;
1309  }
1310  parent->appendChild(elemPlainRoot);
1311  }
1312  else
1313  {
1314  DOMNode* n=parent->replaceChild(elemPlainRoot,node);
1315  if (n != NULL)
1316  {
1317  n->release();
1318  n = NULL;
1319  }
1320  }
1321  if (docPlain != NULL)
1322  {
1323  docPlain->release();
1324  docPlain = NULL;
1325  }
1326  return E_SUCCESS;
1327 }
bool equals(const XMLCh *const e1, const char *const e2)
Definition: CAUtil.cpp:645
SINT32 decryptOAEP(const UINT8 *from, UINT8 *to, UINT32 *len)
Decrypts one OAEP encoded block which is stored in from.
This class could be used for encryption/decryption of data (streams) with AES using 128bit CBC mode.
Definition: CASymCipher.hpp:42
SINT32 setIV(const UINT8 *p_iv)
Sets iv to p_iv.
SINT32 setKey(const UINT8 *key)
Sets the key for encryption.
Definition: CASymCipher.cpp:52
SINT32 decryptCBCwithPKCS7(const UINT8 *in, UINT8 *out, UINT32 *len)
En-/Decryptes in to out using iv1 and key1.

References CABase64::decode(), CASymCipher::decryptCBCwithPKCS7(), CAASymCipher::decryptOAEP(), E_SUCCESS, E_UNKNOWN, equals(), getDOMChildByName(), getDOMElementValue(), len, parseDOMDocument(), CASymCipher::setIV(), and CASymCipher::setKey().

Referenced by CAFirstMix::doUserLogin_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeXMLEncryptedKey() [1/2]

SINT32 encodeXMLEncryptedKey ( UINT8 key,
UINT32  keylen,
DOMElement *&  elemRootEncodedKey,
XERCES_CPP_NAMESPACE::DOMDocument *  docOwner,
CAASymCipher pRSA 
)

Definition at line 1694 of file CAUtil.cpp.

1695 {
1696  elemRootEncodedKey=createDOMElement(docOwner,"EncryptedKey");
1697  DOMElement* elem1=createDOMElement(docOwner,"EncryptionMethod");
1698  setDOMElementAttribute(elem1,"Algorithm",(UINT8*)"RSA");
1699  elemRootEncodedKey->appendChild(elem1);
1700  DOMElement* elem2=createDOMElement(docOwner,"CipherData");
1701  elem1->appendChild(elem2);
1702  elem1=createDOMElement(docOwner,"CipherValue");
1703  elem2->appendChild(elem1);
1704  UINT8 tmpBuff[1024];
1705  UINT32 tmpLen=1024;
1706  __encryptKey(key,keylen,tmpBuff,&tmpLen,pRSA);
1707  setDOMElementValue(elem1,tmpBuff);
1708  return E_SUCCESS;
1709 }
SINT32 setDOMElementAttribute(DOMNode *pElem, const char *attrName, const char *value)
Definition: CAUtil.cpp:831
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
Definition: CAUtil.cpp:939
void __encryptKey(UINT8 *key, UINT32 keylen, UINT8 *outBuff, UINT32 *outLen, CAASymCipher *pRSA)
Definition: CAUtil.cpp:1673
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
Definition: CAUtil.cpp:814

References __encryptKey(), createDOMElement(), E_SUCCESS, setDOMElementAttribute(), and setDOMElementValue().

Here is the call graph for this function:

◆ encodeXMLEncryptedKey() [2/2]

SINT32 encodeXMLEncryptedKey ( UINT8 key,
UINT32  keylen,
UINT8 xml,
UINT32 xmllen,
CAASymCipher pRSA 
)

Definition at line 1683 of file CAUtil.cpp.

1684 {
1685 #define XML_ENCODE_KEY_TEMPLATE "<EncryptedKey><EncryptionMethod Algorithm=\"RSA\"/><CipherData><CipherValue>%s</CipherValue></CipherData></EncryptedKey>"
1686  UINT8 tmpBuff[1024];
1687  UINT32 len=1024;
1688  __encryptKey(key,keylen,tmpBuff,&len,pRSA);
1689  sprintf((char*)xml,XML_ENCODE_KEY_TEMPLATE,tmpBuff);
1690  *xmllen=strlen((char*)xml);
1691  return E_SUCCESS;
1692 }
#define XML_ENCODE_KEY_TEMPLATE

References __encryptKey(), E_SUCCESS, len, and XML_ENCODE_KEY_TEMPLATE.

Referenced by CAMiddleMix::processKeyExchange().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encryptXMLElement() [1/2]

SINT32 encryptXMLElement ( DOMNode *  node,
CAASymCipher pRSA 
)

The resulting encrypted xml struct is as follows:

Replaces a DOM element with an encrypted version of this element.

  * <EncryptedData Type='http://www.w3.org/2001/04/xmlenc#Element'>
  *   <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
  *   <ds:KeyInfo xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>
  *     <EncryptedKey>
  *       <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
  *       <CipherData>
  *         <CipherValue>...</CipherValue>
  *       </CipherData>
  *     </EncryptedKey>
  *   </ds:KeyInfo>
  *   <CipherData>
  *     <CipherValue>...</CipherValue>
  *   </CipherData>
  * </EncryptedData>
  *

Definition at line 1086 of file CAUtil.cpp.

1087 {
1088  XERCES_CPP_NAMESPACE::DOMDocument* doc=NULL;
1089  DOMNode* parent=NULL;
1090  if(node->getNodeType()==DOMNode::DOCUMENT_NODE)
1091  {
1092  doc=(XERCES_CPP_NAMESPACE::DOMDocument*)node;
1093  parent=doc;
1094  node=doc->getDocumentElement();
1095  }
1096  else
1097  {
1098  doc=node->getOwnerDocument();
1099  parent=node->getParentNode();
1100  }
1101  DOMElement* elemRoot=createDOMElement(doc,"EncryptedData");
1102  DOMElement* elemKeyInfo=createDOMElement(doc,"ds:KeyInfo");
1103  elemRoot->appendChild(elemKeyInfo);
1104  DOMElement* elemEncKey=createDOMElement(doc,"EncryptedKey");
1105  elemKeyInfo->appendChild(elemEncKey);
1106  DOMElement* elemCipherData=createDOMElement(doc,"CipherData");
1107  elemEncKey->appendChild(elemCipherData);
1108  DOMElement* elemCipherValue=createDOMElement(doc,"CipherValue");
1109  elemCipherData->appendChild(elemCipherValue);
1110  UINT8 key[32];
1111  getRandom(key,32);
1112  UINT8* pBuff=new UINT8[1000];
1113  UINT32 bufflen=255;
1114  pRSA->encryptOAEP(key,32,pBuff,&bufflen);
1115  UINT8* pOutBuff=new UINT8[1000];
1116  UINT32 outbufflen=255;
1117  CABase64::encode(pBuff,bufflen,pOutBuff,&outbufflen);
1118  pOutBuff[outbufflen]=0;
1119  setDOMElementValue(elemCipherValue,pOutBuff);
1120  delete[] pOutBuff;
1121  pOutBuff = NULL;
1122  delete[] pBuff;
1123  pBuff = NULL;
1124  CASymCipher *pSymCipher=new CASymCipher();
1125  pSymCipher->setKey(key,true);
1126  pSymCipher->setIV(key+16);
1127  elemCipherData=createDOMElement(doc,"CipherData");
1128  elemRoot->appendChild(elemCipherData);
1129  elemCipherValue=createDOMElement(doc,"CipherValue");
1130  elemCipherData->appendChild(elemCipherValue);
1131  UINT8* b=DOM_Output::dumpToMem(node,&bufflen);
1132  outbufflen=bufflen+1000;
1133  pOutBuff=new UINT8[outbufflen];
1134  pSymCipher->encryptCBCwithPKCS7(b,bufflen,pOutBuff,&outbufflen);
1135  delete[] b;
1136  b = NULL;
1137  bufflen=outbufflen*3/2+1000;
1138  pBuff=new UINT8[bufflen];
1139  CABase64::encode(pOutBuff,outbufflen,pBuff,&bufflen);
1140  pBuff[bufflen]=0;
1141  setDOMElementValue(elemCipherValue,pBuff);
1142  delete[] pOutBuff;
1143  pOutBuff = NULL;
1144  delete[] pBuff;
1145  pBuff = NULL;
1146  if(parent->getNodeType()==DOMNode::DOCUMENT_NODE)
1147  {
1148  DOMNode* n=parent->removeChild(node);
1149  if (n != NULL)
1150  {
1151  n->release();
1152  n = NULL;
1153  }
1154  parent->appendChild(elemRoot);
1155  }
1156  else
1157  {
1158  DOMNode* n=parent->replaceChild(elemRoot,node);
1159  if (n != NULL)
1160  {
1161  n->release();
1162  n = NULL;
1163  }
1164  }
1165  return E_SUCCESS;
1166 }
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
SINT32 encryptOAEP(const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
Encrypts one block of plain text using OAEP padding.
SINT32 encryptCBCwithPKCS7(const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *len)
En-/Decryptes in to out using IV1 and key1.
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161

References createDOMElement(), DOM_Output::dumpToMem(), E_SUCCESS, CABase64::encode(), CASymCipher::encryptCBCwithPKCS7(), CAASymCipher::encryptOAEP(), getRandom(), setDOMElementValue(), CASymCipher::setIV(), and CASymCipher::setKey().

Referenced by CALocalProxy::processKeyExchange().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encryptXMLElement() [2/2]

UINT8* encryptXMLElement ( UINT8 inbuff,
UINT32  inlen,
UINT32 outlen,
CAASymCipher pRSA 
)

Encrypts an XML-Element by wrapping it with:

ONLY_LOCAL_PROXY or first.

 * \<EncryptedData Type='http://www.w3.org/2001/04/xmlenc#Element'>
 *    \<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
 *   \<ds:KeyInfo xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>
 *      \<EncryptedKey>
 *        \<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
 *        \<CipherData\>
 *          \<CipherValue>...\</CipherValue>
 *        \</CipherData>
 *      \</EncryptedKey>
 *    \</ds:KeyInfo>
 *    \<CipherData>
 *      \<CipherValue>...\</CipherValue>
 *    \</CipherData>
 *  \</EncryptedData>
 *
Returns
a buffer with the encyrpted element (the caller is responsible for freeing it), or NULL

Definition at line 1188 of file CAUtil.cpp.

1189 {
1190  const char* XML_ENC_TEMPLATE="<EncryptedData><ds:KeyInfo><EncryptedKey><CipherData><CipherValue>%s</CipherValue></CipherData></EncryptedKey></ds:KeyInfo><CipherData><CipherValue>%s</CipherValue></CipherData></EncryptedData>";
1191  UINT8 key[32];
1192  getRandom(key,32);
1193  UINT8 buff[1000];
1194  UINT32 bufflen=255;
1195  pRSA->encryptOAEP(key,32,buff,&bufflen);
1196  UINT8 keyoutbuff[1000];
1197  UINT32 keyoutbufflen=255;
1198  CABase64::encode(buff,bufflen,keyoutbuff,&keyoutbufflen);
1199  keyoutbuff[keyoutbufflen]=0;
1200  CASymCipher* pSymCipher=new CASymCipher();
1201  pSymCipher->setKey(key,true);
1202  pSymCipher->setIV(key+16);
1203  UINT32 msgoutbufflen=inlen+1000;
1204  UINT8* msgoutbuff=new UINT8[msgoutbufflen];
1205  pSymCipher->encryptCBCwithPKCS7(inbuff,inlen,msgoutbuff,&msgoutbufflen);
1206  delete pSymCipher;
1207  pSymCipher = NULL;
1208  UINT32 encmsgoutbufflen=msgoutbufflen*3/2+1000;
1209  UINT8* encmsgoutbuff=new UINT8[encmsgoutbufflen];
1210  CABase64::encode(msgoutbuff,msgoutbufflen,encmsgoutbuff,&encmsgoutbufflen);
1211  delete[] msgoutbuff;
1212  msgoutbuff = NULL;
1213  encmsgoutbuff[encmsgoutbufflen]=0;
1214  msgoutbufflen=encmsgoutbufflen+1000;
1215  msgoutbuff=new UINT8[msgoutbufflen];
1216  sprintf((char*)msgoutbuff,XML_ENC_TEMPLATE,keyoutbuff,encmsgoutbuff);
1217  outlen=strlen((char*)msgoutbuff);
1218  delete[] encmsgoutbuff;
1219  encmsgoutbuff = NULL;
1220  return msgoutbuff;
1221 }

References CABase64::encode(), CASymCipher::encryptCBCwithPKCS7(), CAASymCipher::encryptOAEP(), getRandom(), CASymCipher::setIV(), and CASymCipher::setKey().

Here is the call graph for this function:

◆ equals()

bool equals ( const XMLCh *const  e1,
const char *const  e2 
)

Definition at line 645 of file CAUtil.cpp.

646  {
647  XMLCh* e3=XMLString::transcode(e2);
648  bool ret=XMLString::equals(e1,e3);
649  XMLString::release(&e3);
650  return ret;
651  }

Referenced by CACmdLnOptions::addVisibleAddresses(), CACertificate::decode(), decryptXMLElement(), CAFirstMix::doUserLogin_internal(), getDOMChildByName(), getLastDOMChildByName(), getSignatureElements(), CAFirstMix::handleTermsAndConditionsLogin(), CAMix::initMixCascadeInfo(), integrateDOMNode(), CASignature::parseSignKeyXML(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CAReplayControlChannel::processXMLMessage(), CAASymCipher::setPublicKeyAsDOMNode(), CASignature::setSignKey(), and CASignature::setVerifyKey().

Here is the caller graph for this function:

◆ formatBytesPerSecond()

void formatBytesPerSecond ( UINT8 buff,
UINT32  buffsize,
UINT64  bytespersecond 
)

Definition at line 1821 of file CAUtil.cpp.

1822 {
1823  if (bytespersecond < 1000)
1824  {
1825  snprintf((char*)buff, buffsize, "%llu Bytes/s", bytespersecond);
1826  }
1827  else if (bytespersecond < 1000000)
1828  {
1829  snprintf((char*)buff, buffsize, "%.2f KBytes/s", bytespersecond/1000.0);
1830 
1831  }
1832  else if (bytespersecond < 1000000000)
1833  {
1834  snprintf((char*)buff, buffsize, "%.2f MBytes/s", bytespersecond/1000000.0);
1835 
1836  }
1837  else
1838  {
1839  snprintf((char*)buff, buffsize, "%.2f GBytes/s", bytespersecond/1000000000.0);
1840  }
1841 
1842 }

Referenced by CACryptoBenchmark::benchmarkThread(), and CACryptoBenchmark::doBenchmark().

Here is the caller graph for this function:

◆ getcurrentTime()

SINT32 getcurrentTime ( timespec &  t)

Gets the current Systemtime in milli seconds.

Parameters
bnTime- Big Number, in which the current time is placed
Return values
E_UNSPECIFIED,ifbnTime was NULL
E_UNKNOWN,ifan error occurs
E_SUCCESS,otherwise

Definition at line 227 of file CAUtil.cpp.

228  {
229  #ifdef _WIN32
230  timeb timebuffer;
231  ftime(&timebuffer);
232  /* Hack what should be solved better...*/
233  t.tv_sec=timebuffer.time;
234  t.tv_nsec=timebuffer.millitm*1000000;
235  /* end of hack..*/
236  return E_SUCCESS;
237  #else //we dont use ftime due to a bug in glibc2.0
238  //we use gettimeofday() in order to get the millis...
239  struct timeval tv;
240  gettimeofday(&tv,NULL); //getting millis...
241  t.tv_sec=tv.tv_sec;
242  t.tv_nsec=tv.tv_usec*1000;
243  return E_SUCCESS;
244  #endif
245  }

References E_SUCCESS.

Referenced by CAChain::addChannel(), CAChain::forceImmediateResponsesInternal(), CAAccountingInstance::handleAccountCertificate_internal(), initRandom(), CAChain::processDownstream(), and CAConditionVariable::wait().

Here is the caller graph for this function:

◆ getcurrentTimeMicros()

SINT32 getcurrentTimeMicros ( UINT64 u64Time)

Gets the current Systemtime in micros seconds.

Depending on the operating system, the time may not be so accurat.

Parameters
u64Time- 64 bit Integer, in which the current time is placed
Return values
E_UNKNOWN,ifan error occurs
E_SUCCESS,otherwise

Definition at line 280 of file CAUtil.cpp.

281  {
282  #ifdef _WIN32
283  timeb timebuffer;
284  ftime(&timebuffer);
285  /* Hack what should be solved better...*/
286  u64Time=((UINT64)timebuffer.time)*1000000+((UINT64)timebuffer.millitm)*1000;
287  /* end of hack..*/
288  return E_SUCCESS;
289  #else //we dont use ftime due to a bug in glibc2.0
290  //we use gettimeofday() in order to get the millis...
291  struct timeval tv;
292  gettimeofday(&tv,NULL); //getting millis...
293  #ifdef HAVE_NATIVE_UINT64
294  u64Time=((UINT64)tv.tv_sec)*1000000+((UINT64)tv.tv_usec);
295  return E_SUCCESS;
296  #else
297  return E_UNKNOWN;
298  #endif
299  #endif
300  }
struct __UINT64__t_ UINT64

References E_SUCCESS, and E_UNKNOWN.

Referenced by CAChain::CAChain(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), CADatabase::measurePerformance(), CAReplayDatabase::measurePerformance(), CAFirstMixA::sendToUsers(), and CAChain::~CAChain().

Here is the caller graph for this function:

◆ getcurrentTimeMillis()

SINT32 getcurrentTimeMillis ( UINT64 u64Time)

Gets the current Systemtime in milli seconds.

Parameters
u64Time- 64 bit Integer, in which the current time is placed
Return values
E_UNKNOWN,ifan error occurs
E_SUCCESS,otherwise

Definition at line 252 of file CAUtil.cpp.

253  {
254  #ifdef _WIN32
255  timeb timebuffer;
256  ftime(&timebuffer);
257  /* Hack what should be solved better...*/
258  u64Time=((UINT64)timebuffer.time)*1000+((UINT64)timebuffer.millitm);
259  /* end of hack..*/
260  return E_SUCCESS;
261  #else //we dont use ftime due to a bug in glibc2.0
262  //we use gettimeofday() in order to get the millis...
263  struct timeval tv;
264  gettimeofday(&tv,NULL); //getting millis...
265  #ifdef HAVE_NATIVE_UINT64
266  u64Time=((UINT64)tv.tv_sec)*1000+((UINT64)tv.tv_usec)/1000;
267  return E_SUCCESS;
268  #else
269  return E_UNKNOWN;
270  #endif
271  #endif
272  }

References E_SUCCESS, and E_UNKNOWN.

Referenced by CAFirstMixChannelList::add(), CACryptoBenchmark::benchmarkThread(), CATempIPBlockList::checkIP(), CATempIPBlockList::cleanupThreadMainLoop(), CAFirstMixA::closeConnection(), CACryptoBenchmark::doBenchmark(), CAInfoService::getCascadeHeloXMLAsString(), CACmdLnOptions::getMixXml(), CAInfoService::getStatusXMLAsString(), CAAccountingInstance::handleCostConfirmation_internal(), CATempIPBlockList::insertIP(), CALastMixA::loop(), CAFirstMixB::loop(), CAHttpClient::parseHTTPHeader(), CAFirstMixChannelToQueueList::performanceTest(), CAMuxSocket::receive(), CASocket::receiveFullyT(), CASocket::receiveLine(), CAInfoService::sendCascadeHelo(), CASocket::sendFullyTimeOut(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), setCurrentTimeMilliesAsDOMAttribute(), CAMix::start(), and CAASymCipher::testSpeed().

Here is the caller graph for this function:

◆ getDOMChildByName() [1/3]

SINT32 getDOMChildByName ( const DOMNode *  pNode,
const char *const  name,
DOMElement *&  child,
bool  deep 
)

Definition at line 458 of file CAUtil.cpp.

459  {
460  return getDOMChildByName(pNode,name,(DOMNode*&)child,deep);
461  }

Referenced by CACmdLnOptions::addVisibleAddresses(), CAMix::checkCompatibility(), decodeXMLEncryptedKey(), decryptXMLElement(), CAFirstMix::doUserLogin_internal(), CAInfoService::getCascadeHeloXMLAsString(), getDOMChildByName(), CAListenerInterface::getInstance(), CACmdLnOptions::getMixXml(), CAAccountingInstance::handleAccountCertificate_internal(), CAAccountingInstance::handleChallengeResponse_internal(), CAFirstMix::handleKeyInfoExtensions(), CAFirstMix::handleTermsAndConditionsExtension(), CAFirstMix::handleTermsAndConditionsLogin(), CAMix::initMixCascadeInfo(), CAAccountingInstance::makeCCRequest(), CAAccountingInstance::makeInitialCCRequest(), CACmdLnOptions::parseInfoServices(), CASignature::parseSignKeyXML(), CAAccountingInstance::prepareCCRequest(), CAReplayCtrlChannelMsgProc::proccessGetTimestamp(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CACmdLnOptions::processXmlConfiguration(), CAReplayControlChannel::processXMLMessage(), CAReplayCtrlChannelMsgProc::propagateCurrentReplayTimestamp(), CACmdLnOptions::setAccessControlCredential(), CACmdLnOptions::setAccountingDatabase(), CACmdLnOptions::setAccountingHardLimit(), CACmdLnOptions::setAccountingOptions(), CACmdLnOptions::setAccountingSoftLimit(), CACmdLnOptions::setCascadeNameFromOptions(), CACmdLnOptions::setCertificateOptions(), CACmdLnOptions::setDaemonMode(), CACmdLnOptions::setDynamicMix(), CACmdLnOptions::setGeneralOptions(), CACmdLnOptions::setInfoServices(), CACmdLnOptions::setKeepAliveTraffic(), CACmdLnOptions::setListenerInterfaces(), CACmdLnOptions::setLoggingOptions(), CACmdLnOptions::setMaxUsers(), CACmdLnOptions::setMinCascadeLength(), CACmdLnOptions::setMixCertificateVerification(), CACmdLnOptions::setMixDescription(), CACmdLnOptions::setMixID(), CACmdLnOptions::setMixName(), CACmdLnOptions::setMixType(), CACmdLnOptions::setNetworkOptions(), CACmdLnOptions::setNextMix(), CACmdLnOptions::setNextMixCertificate(), CACmdLnOptions::setNrOfFileDescriptors(), CACmdLnOptions::setOwnCertificate(), CACmdLnOptions::setOwnOperatorCertificate(), CACmdLnOptions::setPaymentInstance(), CACmdLnOptions::setPaymentReminder(), CACmdLnOptions::setPrepaidInterval(), CACmdLnOptions::setPrevMix(), CACmdLnOptions::setPrevMixCertificate(), CACmdLnOptions::setPriceCertificate(), CACmdLnOptions::setRessourceOptions(), CACmdLnOptions::setServerMonitoring(), CACmdLnOptions::setSettleInterval(), CACmdLnOptions::setSymChannelCipherAlgorithm(), CACmdLnOptions::setTargetInterfaces(), CACmdLnOptions::setTermsAndConditions(), CACmdLnOptions::setTermsAndConditionsList(), CACmdLnOptions::setTermsAndConditionsTemplates(), CACmdLnOptions::setTrustedRootCertificates(), CACmdLnOptions::setUserID(), CAXMLErrorMessage::setValues(), CASignature::setVerifyKey(), CAMultiSignature::signXML(), CACertStore::verifyMixCert(), CAMultiSignature::verifyXML(), and CASignature::verifyXML().

◆ getDOMChildByName() [2/3]

SINT32 getDOMChildByName ( const DOMNode *  pNode,
const char *const  name,
DOMNode *&  a_child,
bool  deep 
)

Definition at line 485 of file CAUtil.cpp.

486  {
487  a_child=NULL;
488  if(pNode==NULL)
489  return E_UNKNOWN;
490  XMLCh* tmpName=XMLString::transcode((const char * const)name);
491  SINT32 ret=getDOMChildByName(pNode,tmpName,a_child,deep);
492  XMLString::release(&tmpName);
493  return ret;
494  }

References E_UNKNOWN, and getDOMChildByName().

Here is the call graph for this function:

◆ getDOMChildByName() [3/3]

SINT32 getDOMChildByName ( const DOMNode *  pNode,
const XMLCh *const  name,
DOMNode *&  a_child,
bool  deep 
)

Definition at line 462 of file CAUtil.cpp.

463  {
464  a_child=NULL;
465  if(pNode==NULL)
466  return E_UNKNOWN;
467  DOMNode *pChild=pNode->getFirstChild();
468  while(pChild!=NULL)
469  {
470  if(XMLString::equals(pChild->getNodeName(),name))
471  {
472  a_child=pChild;
473  return E_SUCCESS;
474  }
475  if(deep)
476  {
477  if(getDOMChildByName(pChild,name,a_child,deep)==E_SUCCESS)
478  return E_SUCCESS;
479  }
480  pChild=pChild->getNextSibling();
481  }
482  return E_UNKNOWN;
483  }

References E_SUCCESS, E_UNKNOWN, equals(), and getDOMChildByName().

Here is the call graph for this function:

◆ getDOMElementAttribute() [1/6]

SINT32 getDOMElementAttribute ( const DOMNode *const  elem,
const char *  attrName,
bool &  value 
)

Definition at line 1756 of file CAUtil.cpp.

1757 {
1758  UINT8 val[50];
1759  UINT32 len=50;
1760  if(getDOMElementAttribute(elem,attrName,val,&len) != E_SUCCESS)
1761  {
1762  return E_UNKNOWN;
1763  }
1764  SINT32 ret = E_UNSPECIFIED;
1765  if(strncasecmp((char*)val, STR_VALUE_TRUE, strlen(STR_VALUE_TRUE)) == 0)
1766  {
1767  value = true;
1768  ret = E_SUCCESS;
1769  }
1770  else if(strncasecmp((char*)val, STR_VALUE_FALSE, strlen(STR_VALUE_FALSE)) == 0)
1771  {
1772  value = false;
1773  ret = E_SUCCESS;
1774  }
1775  return ret;
1776 }
SINT32 getDOMElementAttribute(const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
Definition: CAUtil.cpp:780
#define STR_VALUE_FALSE
Definition: CAUtil.hpp:36
#define STR_VALUE_TRUE
Definition: CAUtil.hpp:35
#define E_UNSPECIFIED
Definition: errorcodes.hpp:6

References E_SUCCESS, E_UNKNOWN, E_UNSPECIFIED, getDOMElementAttribute(), len, STR_VALUE_FALSE, and STR_VALUE_TRUE.

Here is the call graph for this function:

◆ getDOMElementAttribute() [2/6]

SINT32 getDOMElementAttribute ( const DOMNode *const  elem,
const char *  attrName,
SINT32 value 
)

Definition at line 804 of file CAUtil.cpp.

805  {
806  UINT8 val[50];
807  UINT32 len=50;
808  if(getDOMElementAttribute(elem,attrName,val,&len)!=E_SUCCESS)
809  return E_UNKNOWN;
810  *value=atol((char*)val);
811  return E_SUCCESS;
812  }

References E_SUCCESS, E_UNKNOWN, getDOMElementAttribute(), and len.

Here is the call graph for this function:

◆ getDOMElementAttribute() [3/6]

SINT32 getDOMElementAttribute ( const DOMNode *const  elem,
const char *  attrName,
SINT64 value 
)

Definition at line 1778 of file CAUtil.cpp.

1779 {
1780  UINT8 val[50];
1781  UINT32 len=50;
1782  if(getDOMElementAttribute(elem,attrName,val,&len)!=E_SUCCESS)
1783  {
1784  return E_UNKNOWN;
1785  }
1786  if(parseS64(val,value)!=E_SUCCESS)
1787  {
1788  return E_UNKNOWN;
1789  }
1790  return E_SUCCESS;
1791 }
SINT32 parseS64(const UINT8 *str, SINT64 &value)
Parses a 64bit signed integer.
Definition: CAUtil.cpp:1430

References E_SUCCESS, E_UNKNOWN, getDOMElementAttribute(), len, and parseS64().

Here is the call graph for this function:

◆ getDOMElementAttribute() [4/6]

SINT32 getDOMElementAttribute ( const DOMNode *const  elem,
const char *  attrName,
UINT32 value 
)

Definition at line 1613 of file CAUtil.cpp.

1614 {
1615  UINT8 val[50];
1616  UINT32 len=50;
1617  if(getDOMElementAttribute(elem,attrName,val,&len)!=E_SUCCESS)
1618  return E_UNKNOWN;
1619  long l=atol((char*)val);
1620  if(l<0)
1621  return E_UNKNOWN;
1622  value=(UINT32)l;
1623  return E_SUCCESS;
1624 }

References E_SUCCESS, E_UNKNOWN, getDOMElementAttribute(), and len.

Here is the call graph for this function:

◆ getDOMElementAttribute() [5/6]

SINT32 getDOMElementAttribute ( const DOMNode *const  elem,
const char *  attrName,
UINT64 value 
)

Definition at line 1793 of file CAUtil.cpp.

1794 {
1795  UINT8 val[50];
1796  UINT32 len=50;
1797  if(getDOMElementAttribute(elem,attrName,val,&len)!=E_SUCCESS)
1798  {
1799  return E_UNKNOWN;
1800  }
1801  if(parseU64(val,value)!=E_SUCCESS)
1802  {
1803  return E_UNKNOWN;
1804  }
1805  return E_SUCCESS;
1806 }
SINT32 parseU64(const UINT8 *str, UINT64 &value)
Parses a 64bit unsigned integer.
Definition: CAUtil.cpp:1378

References E_SUCCESS, E_UNKNOWN, getDOMElementAttribute(), len, and parseU64().

Here is the call graph for this function:

◆ getDOMElementAttribute() [6/6]

SINT32 getDOMElementAttribute ( const DOMNode *const  elem,
const char *  attrName,
UINT8 value,
UINT32 len 
)

Definition at line 780 of file CAUtil.cpp.

781  {
782  if(elem==NULL||attrName==NULL||value==NULL||len==NULL||elem->getNodeType()!=DOMNode::ELEMENT_NODE)
783  return E_UNKNOWN;
784  XMLCh* name=XMLString::transcode(attrName);
785  const XMLCh* tmpCh=((DOMElement*)elem)->getAttribute(name);
786  XMLString::release(&name);
787  char* tmpStr=XMLString::transcode(tmpCh);
788  if (tmpStr == NULL)
789  {
790  return E_UNKNOWN;
791  }
792  UINT32 l=strlen(tmpStr);
793  if(l>=*len)
794  {
795  XMLString::release(&tmpStr);
796  return E_SPACE;
797  }
798  *len=l;
799  memcpy(value,tmpStr,l+1);
800  XMLString::release(&tmpStr);
801  return E_SUCCESS;
802  }
#define E_SPACE
Definition: errorcodes.hpp:7

References E_SPACE, E_SUCCESS, E_UNKNOWN, and len.

Referenced by CAMix::checkCompatibility(), getDOMElementAttribute(), CAListenerInterface::getInstance(), CAInfoService::getOperatorTnCsAsStrings(), getTermsAndConditionsTemplateRefId(), CAFirstMix::handleTermsAndConditionsExtension(), CAFirstMix::handleTermsAndConditionsLogin(), CAFirstMix::initMixParameters(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CACmdLnOptions::processXmlConfiguration(), CAReplayControlChannel::processXMLMessage(), CACmdLnOptions::setLoggingOptions(), CACmdLnOptions::setMixName(), CACmdLnOptions::setPaymentReminder(), CACmdLnOptions::setTermsAndConditionsList(), CAAccountingBIInterface::settleAll(), CAXMLErrorMessage::setValues(), CASignature::setVerifyKey(), and CAMultiSignature::verifyXML().

Here is the caller graph for this function:

◆ getDOMElementValue() [1/8]

SINT32 getDOMElementValue ( const DOMElement *const  pElem,
double *  value 
)

Definition at line 1021 of file CAUtil.cpp.

1022 {
1023  ASSERT(value!=NULL,"Value is null");
1024  ASSERT(pElem!=NULL,"Element is NULL");
1025  UINT8 buff[255];
1026  UINT32 buffLen=255;
1027  if(getDOMElementValue(pElem,buff,&buffLen)!=E_SUCCESS)
1028  return E_UNKNOWN;
1029  *value=atof((char*)buff);
1030 
1031  return E_SUCCESS;
1032 }
#define ASSERT(cond, msg)
Definition: StdAfx.h:546

References ASSERT, E_SUCCESS, E_UNKNOWN, and getDOMElementValue().

Here is the call graph for this function:

◆ getDOMElementValue() [2/8]

SINT32 getDOMElementValue ( const DOMElement *const  pElem,
SINT32 value 
)

Definition at line 1008 of file CAUtil.cpp.

1009 {
1010  ASSERT(value!=NULL,"Value is null");
1011  ASSERT(pElem!=NULL,"Element is NULL");
1012  UINT8 buff[255];
1013  UINT32 buffLen=255;
1014  if(getDOMElementValue(pElem,buff,&buffLen)!=E_SUCCESS)
1015  return E_UNKNOWN;
1016  *value=atol((char*)buff);
1017 
1018  return E_SUCCESS;
1019 }

References ASSERT, E_SUCCESS, E_UNKNOWN, and getDOMElementValue().

Here is the call graph for this function:

◆ getDOMElementValue() [3/8]

SINT32 getDOMElementValue ( const DOMElement *const  pElem,
SINT64 value 
)

Definition at line 1051 of file CAUtil.cpp.

1052 {
1053  ASSERT(pElem!=NULL, "Element is NULL");
1054  UINT8 buf[256];
1055  UINT32 bufLen = 256;
1056  if(getDOMElementValue(pElem,buf,&bufLen)!=E_SUCCESS)
1057  {
1058  return E_UNKNOWN;
1059  }
1060  if(parseS64(buf, value)!=E_SUCCESS)
1061  {
1062  return E_UNKNOWN;
1063  }
1064  return E_SUCCESS;
1065 }

References ASSERT, E_SUCCESS, E_UNKNOWN, getDOMElementValue(), and parseS64().

Here is the call graph for this function:

◆ getDOMElementValue() [4/8]

SINT32 getDOMElementValue ( const DOMElement *const  pElem,
UINT16 value 
)

Definition at line 1808 of file CAUtil.cpp.

1809 {
1810  UINT32 tmp;
1811  if(getDOMElementValue(pElem,&tmp)!=E_SUCCESS)
1812  return E_UNKNOWN;
1813  if(tmp>0xFFFF)
1814  return E_UNKNOWN;
1815  *value=(UINT16)tmp;
1816  return E_SUCCESS;
1817 }
unsigned short UINT16
Definition: basetypedefs.h:133

References E_SUCCESS, E_UNKNOWN, and getDOMElementValue().

Here is the call graph for this function:

◆ getDOMElementValue() [5/8]

SINT32 getDOMElementValue ( const DOMElement *const  pElem,
UINT32 value 
)

Definition at line 920 of file CAUtil.cpp.

921  {
922  ASSERT(value!=NULL,"Value is null");
923  ASSERT(pElem!=NULL,"Element is NULL");
924  UINT8 buff[255];
925  UINT32 buffLen=255;
926  if(getDOMElementValue(pElem,buff,&buffLen)!=E_SUCCESS)
927  return E_UNKNOWN;
928  *value=atol((char*)buff);
929 
930  return E_SUCCESS;
931  }

References ASSERT, E_SUCCESS, E_UNKNOWN, and getDOMElementValue().

Here is the call graph for this function:

◆ getDOMElementValue() [6/8]

SINT32 getDOMElementValue ( const DOMElement *const  pElem,
UINT32 value,
UINT32  defaultValue 
)

Gets the value from an DOM-Element as UINT32.

If an error occurs, the default value is returned.

Definition at line 908 of file CAUtil.cpp.

909  {
910  UINT32 v;
911  if(getDOMElementValue(pElem,&v)!=E_SUCCESS)
912  {
913  value=defaultValue;
914  }
915  else
916  value=v;
917  return E_SUCCESS;
918  }

References E_SUCCESS, and getDOMElementValue().

Here is the call graph for this function:

◆ getDOMElementValue() [7/8]

SINT32 getDOMElementValue ( const DOMNode *const  pElem,
UINT64 value 
)

Definition at line 1034 of file CAUtil.cpp.

1035 {
1036  ASSERT(pElem!=NULL, "Element is NULL");
1037  UINT8 buf[256];
1038  UINT32 bufLen = 256;
1039  if(getDOMElementValue(pElem,buf,&bufLen)!=E_SUCCESS)
1040  {
1041  return E_UNKNOWN;
1042  }
1043  if(parseU64(buf, value)!=E_SUCCESS)
1044  {
1045  return E_UNKNOWN;
1046  }
1047 
1048  return E_SUCCESS;
1049 }

References ASSERT, E_SUCCESS, E_UNKNOWN, getDOMElementValue(), and parseU64().

Here is the call graph for this function:

◆ getDOMElementValue() [8/8]

SINT32 getDOMElementValue ( const DOMNode *const  pElem,
UINT8 value,
UINT32 valuelen 
)

Returns the content of the text node(s) under elem as null-terminated C String.

If there is no text node len is set to 0.

TODO: Why is elem a DOM_Node and not a DOM_Element here?

Parameters
elemthe element which has a text node under it
valuea buffer that gets the text value
valuelenon call contains the buffer size, on return contains the number of bytes copied
Return values
E_SPACEif the buffer is too small
E_UNKNOWNif the element is NULL
E_SUCCESSotherwise

Definition at line 746 of file CAUtil.cpp.

747  {
748  ASSERT(value!=NULL,"Value is null");
749  ASSERT(valuelen!=NULL,"ValueLen is null");
750  ASSERT(pElem!=NULL,"Element is NULL");
751  if(pElem==NULL)
752  return E_UNKNOWN;
753  DOMNode* pText=pElem->getFirstChild();
754  UINT32 spaceLeft=*valuelen;
755  *valuelen=0;
756  while(pText!=NULL)
757  {
758  if(pText->getNodeType()==DOMNode::TEXT_NODE)
759  {
760  const XMLCh* str=pText->getNodeValue();
761  char* tmpStr=XMLString::transcode(str);
762  UINT32 tmpStrLen=strlen(tmpStr);
763  if(tmpStrLen>=spaceLeft)
764  {
765  *valuelen=tmpStrLen+1;
766  XMLString::release(&tmpStr);
767  return E_SPACE;
768  }
769  memcpy(value+(*valuelen),tmpStr,tmpStrLen);
770  *valuelen+=tmpStrLen;
771  spaceLeft-=tmpStrLen;
772  XMLString::release(&tmpStr);
773  }
774  pText=pText->getNextSibling();
775  }
776  value[*valuelen]=0;
777  return E_SUCCESS;
778  }

References ASSERT, E_SPACE, E_SUCCESS, and E_UNKNOWN.

Referenced by CACmdLnOptions::addVisibleAddresses(), CACertificate::decode(), decodeXMLEncryptedKey(), decryptXMLElement(), CAFirstMix::doUserLogin_internal(), getDOMElementValue(), CAListenerInterface::getInstance(), CAASymCipher::getKeyPart(), CAAccountingInstance::handleAccountCertificate_internal(), CAAccountingInstance::handleChallengeResponse_internal(), CACmdLnOptions::parseInfoServices(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CACmdLnOptions::processXmlConfiguration(), CAReplayControlChannel::processXMLMessage(), CACmdLnOptions::setAccessControlCredential(), CACmdLnOptions::setAccountingDatabase(), CACmdLnOptions::setAccountingHardLimit(), CACmdLnOptions::setAccountingSoftLimit(), CACmdLnOptions::setCascadeNameFromOptions(), CACmdLnOptions::setDaemonMode(), CACmdLnOptions::setDynamicMix(), CACmdLnOptions::setInfoServices(), CACmdLnOptions::setKeepAliveTraffic(), CACmdLnOptions::setLoggingOptions(), CACmdLnOptions::setMaxUsers(), CACmdLnOptions::setMixCertificateVerification(), CACmdLnOptions::setMixID(), CACmdLnOptions::setMixName(), CACmdLnOptions::setMixType(), CACmdLnOptions::setNrOfFileDescriptors(), CACmdLnOptions::setPaymentReminder(), CACmdLnOptions::setPrepaidInterval(), CACmdLnOptions::setRessourceOptions(), CACmdLnOptions::setServerMonitoring(), CACmdLnOptions::setSettleInterval(), CASignature::setSignKey(), CACmdLnOptions::setTargetInterfaces(), CACmdLnOptions::setTermsAndConditionsTemplates(), CACmdLnOptions::setUserID(), CAXMLErrorMessage::setValues(), CASignature::setVerifyKey(), CAMultiSignature::verifyXML(), and CASignature::verifyXML().

Here is the caller graph for this function:

◆ getElementsByTagName()

DOMNodeList* getElementsByTagName ( DOMElement *  pElem,
const char *const  name 
)

◆ getLastDOMChildByName() [1/3]

SINT32 getLastDOMChildByName ( const DOMNode *  pNode,
const char *const  name,
DOMElement *&  a_child 
)

Definition at line 1719 of file CAUtil.cpp.

1720  {
1721  return getLastDOMChildByName(pNode,name,(DOMNode*&)a_child);
1722  }
SINT32 getLastDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&a_child)
Definition: CAUtil.cpp:1719

Referenced by getLastDOMChildByName(), and CAMix::initMixCascadeInfo().

Here is the caller graph for this function:

◆ getLastDOMChildByName() [2/3]

SINT32 getLastDOMChildByName ( const DOMNode *  pNode,
const char *const  name,
DOMNode *&  a_child 
)

Definition at line 1724 of file CAUtil.cpp.

1725 {
1726  a_child=NULL;
1727  if(pNode==NULL)
1728  return E_UNKNOWN;
1729  XMLCh* tmpName=XMLString::transcode((const char * const)name);
1730  SINT32 ret=getLastDOMChildByName(pNode,tmpName,a_child);
1731  XMLString::release(&tmpName);
1732  return ret;
1733 }

References E_UNKNOWN, and getLastDOMChildByName().

Here is the call graph for this function:

◆ getLastDOMChildByName() [3/3]

SINT32 getLastDOMChildByName ( const DOMNode *  pNode,
const XMLCh *const  name,
DOMNode *&  a_child 
)

Definition at line 1735 of file CAUtil.cpp.

1736 {
1737  a_child=NULL;
1738  if(pNode==NULL)
1739  {
1740  return E_UNKNOWN;
1741  }
1742  DOMNode* pChild;
1743  pChild=pNode->getLastChild();
1744  while(pChild!=NULL)
1745  {
1746  if(XMLString::equals(pChild->getNodeName(),name))
1747  {
1748  a_child = pChild; // found a child
1749  return E_SUCCESS;
1750  }
1751  pChild=pChild->getPreviousSibling();
1752  }
1753  return E_UNKNOWN;
1754 }

References E_SUCCESS, E_UNKNOWN, and equals().

Here is the call graph for this function:

◆ getMemoryUsage()

UINT32 getMemoryUsage ( )

Definition at line 443 of file CAUtil.cpp.

444  {
445 #ifndef _WIN32
446  struct rusage usage_self;
447  if(getrusage(RUSAGE_SELF,&usage_self)==-1)
448  return 0;
449  struct rusage usage_children;
450  if(getrusage(RUSAGE_CHILDREN,&usage_children)==-1)
451  return 0;
452  return usage_self.ru_idrss+usage_children.ru_idrss;
453 #else
454  return 0;
455 #endif
456  }

Referenced by CAFirstMix::clean(), and CAFirstMixB::loop().

Here is the caller graph for this function:

◆ getNodeName()

SINT32 getNodeName ( const DOMNode *const  pElem,
UINT8 value,
UINT32 valuelen 
)

Definition at line 707 of file CAUtil.cpp.

708 {
709  ASSERT(value!=NULL,"Value is null");
710  ASSERT(valuelen!=NULL,"ValueLen is null");
711  ASSERT(pElem!=NULL,"Element is NULL");
712  if(pElem==NULL)
713  return E_UNKNOWN;
714 
715  UINT32 spaceLeft=*valuelen;
716  *valuelen=0;
717  const XMLCh* str=pElem->getNodeName();
718  char* tmpStr=XMLString::transcode(str);
719  UINT32 tmpStrLen=strlen(tmpStr);
720  if(tmpStrLen>=spaceLeft)
721  {
722  *valuelen=tmpStrLen+1;
723  XMLString::release(&tmpStr);
724  return E_SPACE;
725  }
726  memcpy(value+(*valuelen),tmpStr,tmpStrLen);
727  *valuelen+=tmpStrLen;
728  XMLString::release(&tmpStr);
729  value[*valuelen] = 0;
730  return E_SUCCESS;
731 }

References ASSERT, E_SPACE, E_SUCCESS, and E_UNKNOWN.

Referenced by CAMix::checkCompatibility().

Here is the caller graph for this function:

◆ getRandom() [1/4]

SINT32 getRandom ( UINT16 val)

Gets 16 random bits.

Parameters
val- on return the bits are random
Return values
E_UNKNOWN,ifan error occured
E_SUCCESS,ifsuccessful

Definition at line 363 of file CAUtil.cpp.

364 {
365  ASSERT(val != NULL, "VAL should be not NULL");
366  if (RAND_bytes((UINT8*)val, 2) != 1
367 #if OPENSSL_VERSION_NUMBER <0x10100000L
368  && RAND_pseudo_bytes((UINT8*)val, 4) < 0
369 #endif
370  )
371  return E_UNKNOWN;
372  return E_SUCCESS;
373 }

References ASSERT, E_SUCCESS, and E_UNKNOWN.

◆ getRandom() [2/4]

SINT32 getRandom ( UINT32 val)

Gets 32 random bits.

Parameters
val- on return the bits are random
Return values
E_UNKNOWN,ifan error occured
E_SUCCESS,ifsuccessful

Definition at line 346 of file CAUtil.cpp.

347  {
348  ASSERT(val!=NULL,"VAL should be not NULL");
349  if(RAND_bytes((UINT8*)val,4)!=1
350 #if OPENSSL_VERSION_NUMBER <0x10100000L
351  && RAND_pseudo_bytes((UINT8*)val,4)<0
352 #endif
353  )
354  return E_UNKNOWN;
355  return E_SUCCESS;
356  }

References ASSERT, E_SUCCESS, and E_UNKNOWN.

Referenced by CAFirstMixChannelList::add(), CASocketList::add(), CAMiddleMixChannelList::add(), CAFirstMixChannelList::addChannel(), CAIPList::CAIPList(), CAPool::CAPool(), CAFirstMixA::closeConnection(), CAChainTable::createEntry(), encryptXMLElement(), CADatabase::fill(), CAReplayDatabase::fill(), CAAccountingInstance::handleAccountCertificate_internal(), CALocalProxy::loop(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), CADatabase::measurePerformance(), CAReplayDatabase::measurePerformance(), CAFirstMixA::notifyAllUserChannels(), CAMsg::openEncryptedLog(), CAFirstMixChannelToQueueList::performanceTest(), CAPool::pool(), CAChain::processDownstream(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CALastMixChannelList::test(), CAMiddleMixChannelList::test(), CAQueue::test(), CAReplayDatabase::test(), and CAASymCipher::testSpeed().

Here is the caller graph for this function:

◆ getRandom() [3/4]

SINT32 getRandom ( UINT64 val)

Definition at line 375 of file CAUtil.cpp.

376  {
377  ASSERT(val!=NULL,"VAL should be not NULL");
378  if(RAND_bytes((UINT8*)val,sizeof(UINT64))!=1
379 #if OPENSSL_VERSION_NUMBER <0x10100000L
380  && RAND_pseudo_bytes((UINT8*)val,sizeof(UINT64))<0
381 #endif
382  )
383  return E_UNKNOWN;
384  return E_SUCCESS;
385  }

References ASSERT, E_SUCCESS, and E_UNKNOWN.

◆ getRandom() [4/4]

SINT32 getRandom ( UINT8 buff,
UINT32  len 
)

Gets some random bytes.

Parameters
buff- buff which is filled with randomness
len- number of bytes requested
Return values
E_UNKNOWN,ifan error occured
E_SUCCESS,ifsuccessful

Definition at line 393 of file CAUtil.cpp.

394  {
395  ASSERT(buff!=NULL,"BUFF should be not NULL")
396  if(RAND_bytes(buff,len)!=1
397 #if OPENSSL_VERSION_NUMBER <0x10100000L
398  && RAND_pseudo_bytes(buff,len)<0
399 #endif
400  )
401  return E_UNKNOWN;
402  return E_SUCCESS;
403  }

References ASSERT, E_SUCCESS, E_UNKNOWN, and len.

◆ getSignatureElements()

SINT32 getSignatureElements ( DOMNode *  parent,
DOMNode **  signatureNodes,
UINT32 length 
)

Definition at line 496 of file CAUtil.cpp.

497 {
498  if(parent == NULL)
499  {
500  return E_UNKNOWN;
501  }
502 
503  DOMNode* child = parent->getFirstChild();
504  UINT32 count = 0;
505 
506  while(child != NULL)
507  {
508  if(XMLString::equals(child->getNodeName(), XMLString::transcode("Signature")))
509  {
510  if(count < *length)
511  {
512  signatureNodes[count] = child;
513  count++;
514  }
515  else
516  {
517  return E_UNKNOWN;
518  }
519  }
520  child = child->getNextSibling();
521  }
522  *length = count;
523 
524  return E_SUCCESS;
525 }

References E_SUCCESS, E_UNKNOWN, and equals().

Referenced by CACertStore::verifyMixCert(), and CAMultiSignature::verifyXML().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTermsAndConditionsTemplateRefId()

UINT8* getTermsAndConditionsTemplateRefId ( DOMNode *  tcTemplateRoot)

Definition at line 865 of file CAUtil.cpp.

866 {
867  UINT32 tmpTypeLen = TMP_BUFF_SIZE;
868  UINT8 tmpType[TMP_BUFF_SIZE];
869 
870  UINT32 tmpLocaleLen = TMP_LOCALE_SIZE;
871  UINT8 tmpLocale[TMP_LOCALE_SIZE];
872 
873  UINT32 tmpDateLen = TMP_DATE_SIZE;
874  UINT8 tmpDate[TMP_DATE_SIZE];
875  memset(tmpDate, 0, TMP_DATE_SIZE);
876  memset(tmpLocale, 0, TMP_LOCALE_SIZE);
877  memset(tmpType, 0, TMP_BUFF_SIZE);
878 
879  //TODO replace magic strings
880  if(getDOMElementAttribute(tcTemplateRoot, "type", tmpType, &tmpTypeLen) != E_SUCCESS)
881  {
882  return NULL;
883  }
884  else if(getDOMElementAttribute(tcTemplateRoot, "locale", tmpLocale, &tmpLocaleLen) != E_SUCCESS)
885  {
886  return NULL;
887  }
888  else if(getDOMElementAttribute(tcTemplateRoot, "date", tmpDate, &tmpDateLen) != E_SUCCESS)
889  {
890  return NULL;
891  }
892  if( (tmpTypeLen == 0) ||
893  (tmpLocaleLen == 0) ||
894  (tmpDateLen) == 0)
895  {
896  return NULL;
897  }
898  //reserve 2 more chars for the both underlines between the fields ...
899  size_t templateRefIdLen = tmpTypeLen+tmpLocaleLen+tmpDateLen+2;
900  //... and 1 more for zero termination.
901  char *templateRefId = new char[templateRefIdLen+1];
902  memset(templateRefId, 0, templateRefIdLen+1);
903  snprintf(templateRefId, templateRefIdLen+1, "%s_%s_%s", (char *) tmpType, (char *) tmpLocale, (char *) tmpDate);
904 
905  return (UINT8 *) templateRefId;
906 }
#define TMP_LOCALE_SIZE
Definition: CAUtil.hpp:39
#define TMP_BUFF_SIZE
Definition: CAUtil.hpp:38
#define TMP_DATE_SIZE
Definition: CAUtil.hpp:40

References E_SUCCESS, getDOMElementAttribute(), TMP_BUFF_SIZE, TMP_DATE_SIZE, and TMP_LOCALE_SIZE.

Referenced by CAFirstMix::getTermsAndConditionsTemplate(), and CACmdLnOptions::setTermsAndConditionsTemplates().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initDOMParser()

void initDOMParser ( )

Definition at line 656 of file CAUtil.cpp.

657 {
659  theDOMParser = new XercesDOMParser();
660 }
XercesDOMParser * theDOMParser
Definition: CAUtil.cpp:653
CAMutex * theParseDOMDocumentLock
Definition: CAUtil.cpp:654

References theDOMParser, and theParseDOMDocumentLock.

Referenced by CALibProxytest::init().

Here is the caller graph for this function:

◆ initRandom()

SINT32 initRandom ( )

Definition at line 302 of file CAUtil.cpp.

303  {
304  #if _WIN32
305  RAND_screen();
306  #else
307  #ifndef __linux
308  unsigned char randbuff[255];
309  getcurrentTime(*((timespec*)randbuff));
310  RAND_seed(randbuff,sizeof(randbuff));
311  #endif
312  #endif
313  return E_SUCCESS;
314  }
SINT32 getcurrentTime(timespec &t)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:227

References E_SUCCESS, and getcurrentTime().

Referenced by CALibProxytest::init(), CADatabase::measurePerformance(), and CAReplayDatabase::measurePerformance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ integrateDOMNode()

SINT32 integrateDOMNode ( const DOMNode *  srcNode,
DOMNode *  dstNode,
bool  recursive,
bool  replace 
)

integrates the source node in the destination Node.

TODO 1. test for XERCES >= 3.0.1

  1. specification
Todo:
: check!

Definition at line 533 of file CAUtil.cpp.

534 {
535  if( (srcNode->getNodeType() != DOMNode::ELEMENT_NODE) ||
536  (dstNode->getNodeType() != DOMNode::ELEMENT_NODE) )
537  {
538  return E_UNKNOWN;
539  }
540 
541  DOMNodeList *srcList = srcNode->getChildNodes();
542  XERCES_CPP_NAMESPACE::DOMDocument *srcOwnerDoc = srcNode->getOwnerDocument();
543  XERCES_CPP_NAMESPACE::DOMDocument *dstOwnerDoc = dstNode->getOwnerDocument();
544 
545  short int pos =
546 #if _XERCES_VERSION >= 30001
547  srcNode->compareDocumentPosition(dstNode);
548 #else
549  srcNode->compareTreePosition(dstNode);
550 #endif
551  if( (pos & INTEGRATE_NOT_ALLOWED_POSITIONS) )
552  {
553  CAMsg::printMsg(LOG_ERR,"integrate impossible due to illegal tree positions, (pos: 0x%x)\n", pos);
554  return E_UNKNOWN;
555  }
556 
557  if(srcList->getLength() == 0)
558  {
559  return E_SUCCESS;
560  }
561 
562  DOMElement *srcElem = (DOMElement *) srcNode;
563  DOMElement *dstElem = (DOMElement *) dstNode;
564 
565  DOMNode *currSrcChild = NULL;
566  XMLCh** nodeNames=new XMLCh*[srcList->getLength()];
567  memset(nodeNames,0,sizeof(XMLCh*)*srcList->getLength());
568  UINT32 nodeNamesIndex = 0;
569  XMLCh *currSrcChildName = NULL;
570 
571  DOMNodeList *currSrcChildren = NULL;
572  DOMNodeList *currDstChildren = NULL;
573  bool nodeAlreadyFinished = false;
574 
575  for(XMLSize_t i = 0; i < srcList->getLength(); i++)
576  {
577  currSrcChild = srcList->item(i);
578  if( currSrcChild->getNodeType() == DOMNode::ELEMENT_NODE )
579  {
580  nodeAlreadyFinished = false;
581  currSrcChildName = (XMLCh *) ((DOMElement *) currSrcChild)->getTagName();
582  /*UINT8 *tn = (UINT8 *) XMLString::transcode(currSrcChildName);
583  CAMsg::printMsg(LOG_DEBUG,"handle %s\n", tn);
584  XMLString::release(&tn);*/
585  for(UINT32 j = 0; j < nodeNamesIndex; j++ )
586  {
587  if(XMLString::equals(currSrcChildName, nodeNames[j]))
588  {
589  nodeAlreadyFinished = true;
590  break;
591  }
592  }
593 
594  if(nodeAlreadyFinished)
595  {
596  continue;
597  }
598  currDstChildren = dstElem->getElementsByTagName(currSrcChildName);
599  currSrcChildren = srcElem->getElementsByTagName(currSrcChildName);
600 
601  for(XMLSize_t j = 0;
602  j < currSrcChildren->getLength(); j++ )
603  {
604  if(j >= currDstChildren->getLength())
605  {
606  if( (dstOwnerDoc != NULL) && (srcOwnerDoc != dstOwnerDoc) )
607  {
608  dstNode->appendChild(dstOwnerDoc->importNode(currSrcChildren->item(j), true));
609  }
610  else
611  {
612  dstNode->appendChild(currSrcChildren->item(j)->cloneNode(true));
613  }
614  }
615  else if(replace)
616  {
617  if( (dstOwnerDoc != NULL) && (srcOwnerDoc != dstOwnerDoc) )
618  {
619  dstElem->replaceChild(dstOwnerDoc->importNode(currSrcChildren->item(j),true),currDstChildren->item(j));
620  }
621  else
622  {
624  //This seems to be wrong!!
625  dstElem->replaceChild(dstOwnerDoc->cloneNode(currSrcChildren->item(j)),currDstChildren->item(j));
626  }
627  continue;
628  }
629  else if(recursive)
630  {
631  if(currSrcChildren->item(j)->hasChildNodes() )
632  {
633  integrateDOMNode(currSrcChildren->item(j), currDstChildren->item(j), true, false);
634  }
635  }
636  nodeNames[nodeNamesIndex++] = currSrcChildName;
637  }
638  }
639  }
640  delete[] nodeNames;
641  return E_SUCCESS;
642 }
SINT32 integrateDOMNode(const DOMNode *srcNode, DOMNode *dstNode, bool recursive, bool replace)
integrates the source node in the destination Node.
Definition: CAUtil.cpp:533
#define INTEGRATE_NOT_ALLOWED_POSITIONS
Definition: CAUtil.hpp:48
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251

References E_SUCCESS, E_UNKNOWN, equals(), INTEGRATE_NOT_ALLOWED_POSITIONS, and CAMsg::printMsg().

Referenced by CACmdLnOptions::setTermsAndConditionsList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logMemoryUsage()

void logMemoryUsage ( )

Log information about the current memory (heap) usage.

Definition at line 177 of file CAUtil.cpp.

178  {
179 #ifdef HAVE_SBRK
180  CAMsg::printMsg(LOG_DEBUG,"Memory consumption reported by sbrk(): %u\n",(long)((char*)sbrk(0)-internal_sbrk_start));
181 #endif
182 #ifdef HAVE_MALLINFO
183  struct mallinfo malli=mallinfo();
184  //memset(&malli,0,sizeo(malli));
185  CAMsg::printMsg(LOG_DEBUG,"Memory consumption reported by mallinfo():\n");
186  CAMsg::printMsg(LOG_DEBUG,"\t Total size of memory allocated with sbrk() by malloc() [bytes]: %i\n",malli.arena);
187  CAMsg::printMsg(LOG_DEBUG,"\t Number of chunks not in use: %i\n",malli.ordblks);
188  CAMsg::printMsg(LOG_DEBUG,"\t Total number of chunks allocated with mmap(): %i\n",malli.hblks);
189  CAMsg::printMsg(LOG_DEBUG,"\t Total size of memory allocated with mmap() [byte]: %i\n",malli.hblkhd);
190  CAMsg::printMsg(LOG_DEBUG,"\t Total size of memory occupied by chunks handed out by malloc(): %i\n",malli.uordblks);
191  CAMsg::printMsg(LOG_DEBUG,"\t Total size of memory occupied by free (not in use) chunks: %i\n",malli.fordblks);
192  CAMsg::printMsg(LOG_DEBUG,"\t Size of the top-most releasable chunk that normally borders the end of the heap: %i\n",malli.keepcost);
193 #endif
194  }

References CAMsg::printMsg().

Here is the call graph for this function:

◆ memtrim()

SINT32 memtrim ( UINT8 dest,
const UINT8 src,
UINT32  size 
)

Removes leading and ending whitespaces (chars<=32) from a byte array.

Parameters
srcinput byte array
destoutput byte array
sizesize of the input byte array
Return values
E_UNSPECIFIED,ifdest was NULL
Returns
size of output otherwise
Todo:
replace UINT32 size with SINT32 size

Definition at line 126 of file CAUtil.cpp.

127  {
128  if(src==NULL||size==0)
129  return 0;
130  if(dest==NULL)
131  return E_UNSPECIFIED;
132  UINT32 start=0;
133  UINT32 end=size-1;
134  while(start<=end&&src[start]<=32)
135  start++;
136  if(start>end) //empty string....
137  return 0;
138  while(end>start&&src[end]<=32)
139  end--;
140  size=(end+1)-start;
141  memmove(dest,src+start,size);
142  return (SINT32)size;
143  }

References E_UNSPECIFIED.

◆ msSleep()

SINT32 msSleep ( UINT32  ms)

Sleeps ms milliseconds.

Definition at line 406 of file CAUtil.cpp.

407  {//Do not us usleep for this --> because it doesnt seam to work on irix, multithreaded
408  #ifdef _WIN32
409  Sleep(ms);
410  #else
411  struct timespec req;
412  struct timespec rem;
413  req.tv_sec=ms/1000;
414  req.tv_nsec=(ms%1000)*1000000;
415  while(nanosleep(&req,&rem)==-1)
416  {
417  req.tv_sec=rem.tv_sec;
418  req.tv_nsec=rem.tv_nsec;
419  }
420  #endif
421  return E_SUCCESS;
422  }

References E_SUCCESS.

Referenced by consumer(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), my_terminate(), CAHttpClient::parseHTTPHeader(), producer(), CAClientSocket::receiveFully(), CASocket::sendTimeOut(), and CACryptoBenchmark::timerThread().

Here is the caller graph for this function:

◆ parseDOMDocument() [1/2]

XERCES_CPP_NAMESPACE::DOMDocument* parseDOMDocument ( const UINT8 *const  buff,
UINT32  len 
)

Parses a buffer containing an XML document and returns this document.

Definition at line 663 of file CAUtil.cpp.

664  {
666  MemBufInputSource in(buff,len,"tmpBuff");
667  theDOMParser->parse(in);
668  XERCES_CPP_NAMESPACE::DOMDocument* ret=NULL;
669  if(theDOMParser->getErrorCount()==0)
670  ret=theDOMParser->adoptDocument();
672  return ret;
673  }
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41

References len, CAMutex::lock(), theDOMParser, theParseDOMDocumentLock, and CAMutex::unlock().

Referenced by CAXMLErrorMessage::CAXMLErrorMessage(), CACertificate::decode(), decodeXMLEncryptedKey(), decryptXMLElement(), CAFirstMix::doUserLogin_internal(), CAInfoService::getPaymentInstance(), CASignature::parseSignKeyXML(), CASyncControlChannel::proccessMessageComplete(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CACmdLnOptions::readXmlConfiguration(), CAASymCipher::setPublicKeyAsXML(), CACmdLnOptions::setTermsAndConditionsTemplates(), CAAccountingBIInterface::settleAll(), CAMultiSignature::signXML(), and CAMultiSignature::verifyXML().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseDOMDocument() [2/2]

XERCES_CPP_NAMESPACE::DOMDocument* parseDOMDocument ( const UINT8 *const  pathOrURL)

parses a file via path or URL

Definition at line 679 of file CAUtil.cpp.

680 {
682 
683  theDOMParser->parse((const char *const) pathOrURL);
684  XERCES_CPP_NAMESPACE::DOMDocument* ret=NULL;
685  if(theDOMParser->getErrorCount()==0)
686  {
687  ret=theDOMParser->adoptDocument();
688  }
690  return ret;
691 }

References CAMutex::lock(), theDOMParser, theParseDOMDocumentLock, and CAMutex::unlock().

Here is the call graph for this function:

◆ parseS64()

SINT32 parseS64 ( const UINT8 str,
SINT64 value 
)

Parses a 64bit signed integer.

Note: If the value is out of range or not parseable an erro is returned.

Todo:
code if we do not have native UINT64

Definition at line 1430 of file CAUtil.cpp.

1431 {
1432  #ifdef HAVE_ATOLL
1433  value = atoll((const char *) str);
1434  return E_SUCCESS;
1435  #else
1436  #ifdef HAVE_NATIVE_UINT64
1437  if (str == NULL)
1438  {
1439  return E_UNKNOWN;
1440  }
1441  UINT32 len=strlen((char*)str);
1442  if (len < 1)
1443  {
1444  return E_UNKNOWN;
1445  }
1446  SINT64 s64 = 0;
1447  for (UINT32 i = 0; i < len; i++)
1448  {
1449  UINT8 c=str[i];
1450  if (c >= '0' && c <= '9')
1451  {
1452  s64 *= 10;
1453  s64 += c - '0';
1454  }
1455  else if (i != 0 || str[i] != '+'||str[i]!='-')
1456  {
1457  return E_UNKNOWN;
1458  }
1459  }
1460  if(str[0]=='-')
1461  value=-s64;
1462  else
1463  value = s64;
1464  return E_SUCCESS;
1465  #else
1466  #warning parseS64() is not implemented for platforms without native INT64 support!!!
1468  return E_UNKNOWN;
1469  #endif
1470  #endif
1471 }

References E_SUCCESS, E_UNKNOWN, and len.

Referenced by getDOMElementAttribute(), and getDOMElementValue().

Here is the caller graph for this function:

◆ parseU64()

SINT32 parseU64 ( const UINT8 str,
UINT64 value 
)

Parses a 64bit unsigned integer.

Note: If the value is out of range or not parseable an error is returned.

Todo:
code if we do not have native UINT64

Definition at line 1378 of file CAUtil.cpp.

1379 {
1380  #ifdef HAVE_STRTOULL
1381  //strtoull() will silently accept negative values --> below is a simple chekc to detect negative values...
1382  if(strchr((const char*)str,'-')!=NULL)
1383  {
1384  return E_UNKNOWN;
1385  }
1386  char *endptr = NULL;
1387  value = strtoull((const char *) str, &endptr, 0);
1388  if(endptr!=NULL&&*endptr==0) //check if whole string was parsed...
1389  return E_SUCCESS;
1390  return E_UNKNOWN;
1391  #else
1392  #ifdef HAVE_NATIVE_UINT64
1393  if (str == NULL)
1394  {
1395  return E_UNKNOWN;
1396  }
1397  UINT32 len=strlen((char*)str);
1398  if (len < 1)
1399  {
1400  return E_UNKNOWN;
1401  }
1402  UINT64 u64 = 0;
1403  for (UINT32 i = 0; i < len; i++)
1404  {
1405  UINT8 c=str[i];
1406  if (c >= '0' && c <= '9')
1407  {
1408  u64 *= 10;
1409  u64 += c - '0';
1410  }
1411  else if (i != 0 || str[i] != '+')
1412  {
1413  return E_UNKNOWN;
1414  }
1415  }
1416  value = u64;
1417  return E_SUCCESS;
1418  #else
1419  #warning parseU64() is not implemented for platforms without native UINT64 support!!!
1421  return E_UNKNOWN;
1422  #endif
1423  #endif
1424 }

References E_SUCCESS, E_UNKNOWN, and len.

Referenced by getDOMElementAttribute(), and getDOMElementValue().

Here is the caller graph for this function:

◆ parseUINT16()

SINT32 parseUINT16 ( const UINT8 str,
UINT16 value 
)

Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in milliseconds since the epoch.

Parameters
strTimestampthe string containing the timestamp
valuean integer variable that gets the milliseconds value. Converts a timestamp (in seconds) to the String JDBC timestamp escape format (YYYY-MM-DD HH:MM:SS)
secondsinteger value containing the timestamp in seconds since the epoch
strTimestampa string buffer that gets the result
lenthe buffer length
Todo:
think about timezone handling

Parses a 16bit unsigned integer

Definition at line 1367 of file CAUtil.cpp.

1368 {
1369  UINT16 v = atol((const char*)str);
1370  value = v;
1371  return E_SUCCESS;
1372 }

References E_SUCCESS.

◆ readFile()

UINT8* readFile ( const UINT8 *const  name,
UINT32 size 
)

ONLY_LOCAL_PROXY or first.

Definition at line 1330 of file CAUtil.cpp.

1331 {
1332  int handle=open((char*)name,O_BINARY|O_RDONLY);
1333  if(handle<0)
1334  return NULL;
1335  *size=filesize32(handle);
1336  UINT8* buff=new UINT8[*size];
1337  if (buff == NULL)
1338  {
1339  close(handle);
1340  return NULL;
1341  }
1342  if (read(handle, buff, *size) != *size)
1343  {
1344  close(handle);
1345  delete[] buff;
1346  return NULL;
1347  }
1348  close(handle);
1349  return buff;
1350 }
SINT32 filesize32(int handle)
Definition: CAUtil.hpp:102
#define O_BINARY
Definition: config.h:179

References filesize32(), and O_BINARY.

Referenced by CALastMix::init(), and CAMiddleMix::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readPasswd()

SINT32 readPasswd ( UINT8 buff,
UINT32  len 
)

Read a passwd (i.e.

without echoing the chars typed in)

Definition at line 1473 of file CAUtil.cpp.

1474 {
1475  if(len==0)
1476  return E_SUCCESS;
1477 
1478 #ifndef _WIN32
1479  termios tmpTermios;
1480  UINT32 flags;
1481  bool bRestore=true;
1482  if(tcgetattr(STDIN_FILENO,&tmpTermios)!=0)
1483  {
1484  bRestore=false;
1485  }
1486  flags=tmpTermios.c_lflag;
1487  tmpTermios.c_lflag&=~(ECHO);
1488  if(bRestore)
1489  tcsetattr(STDIN_FILENO,TCSAFLUSH,&tmpTermios);
1490 #endif
1491 
1492  UINT32 i=0;
1493  for(i=0;i<len-1;i++)
1494  {
1495 #ifdef _WIN32
1496  int c=::getch();
1497 #else
1498  int c=getchar();
1499 #endif
1500  if(c<=0||c=='\r'||c=='\n')
1501  break;
1502  buff[i]=(UINT8)c;
1503  }
1504  buff[i]=0;
1505 
1506 #ifndef _WIN32
1507  tmpTermios.c_lflag=flags;
1508  if(bRestore)
1509  tcsetattr(STDIN_FILENO,TCSAFLUSH,&tmpTermios);
1510 #endif
1511  return E_SUCCESS;
1512 }
UINT16 flags
Definition: typedefs.hpp:1

References E_SUCCESS, flags, and len.

Referenced by CACmdLnOptions::setOwnCertificate().

Here is the caller graph for this function:

◆ releaseDOMParser()

void releaseDOMParser ( )

Definition at line 694 of file CAUtil.cpp.

695  {
696  if( theParseDOMDocumentLock!=NULL)
697  {
699  delete theDOMParser;
700  theDOMParser=NULL;
704  }
705  }

References CAMutex::lock(), theDOMParser, theParseDOMDocumentLock, and CAMutex::unlock().

Referenced by CALibProxytest::cleanup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveFile()

SINT32 saveFile ( const UINT8 *const  name,
const UINT8 *const  buff,
UINT32  buffSize 
)

Definition at line 1352 of file CAUtil.cpp.

1353 {
1354  int handle = open((char *)name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, S_IWRITE | S_IREAD);
1355  if(handle<0)
1356  return E_UNKNOWN;
1357  if(myfilewrite(handle,buff,buffSize)!=buffSize)
1358  {
1359  close(handle);
1360  return E_UNKNOWN;
1361  }
1362  close(handle);
1363  return E_SUCCESS;
1364 }
#define myfilewrite
Definition: StdAfx.h:493
#define S_IWRITE
Definition: StdAfx.h:491
#define S_IREAD
Definition: StdAfx.h:488

References E_SUCCESS, E_UNKNOWN, myfilewrite, O_BINARY, S_IREAD, and S_IWRITE.

Referenced by CALastMix::init(), and CAMiddleMix::init().

Here is the caller graph for this function:

◆ setCurrentTimeMilliesAsDOMAttribute()

SINT32 setCurrentTimeMilliesAsDOMAttribute ( DOMNode *  pElem)

Definition at line 848 of file CAUtil.cpp.

849 {
850  if( pElem == NULL || pElem->getNodeType() != DOMNode::ELEMENT_NODE )
851  {
852  return E_UNKNOWN;
853  }
854  UINT64 currentMillis;
855  getcurrentTimeMillis(currentMillis);
856  UINT8 tmpStrCurrentMillis[50];
857  print64(tmpStrCurrentMillis,currentMillis);
859  (pElem,UNIVERSAL_ATTRIBUTE_LAST_UPDATE, tmpStrCurrentMillis );
860  return E_SUCCESS;
861 
862 }
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:252
void print64(UINT8 *buff, UINT64 num)
Definition: CAUtil.hpp:482
#define UNIVERSAL_ATTRIBUTE_LAST_UPDATE
Definition: CAUtil.hpp:32

References E_SUCCESS, E_UNKNOWN, getcurrentTimeMillis(), print64(), setDOMElementAttribute(), and UNIVERSAL_ATTRIBUTE_LAST_UPDATE.

Referenced by CAInfoService::getOperatorTnCsAsStrings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDOMElementAttribute() [1/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
bool  value 
)

Definition at line 996 of file CAUtil.cpp.

997 {
998  return setDOMElementAttribute(pElem, attrName,
999  ((UINT8*) (value ? STR_VALUE_TRUE : STR_VALUE_FALSE)));
1000 }

References setDOMElementAttribute(), STR_VALUE_FALSE, and STR_VALUE_TRUE.

Here is the call graph for this function:

◆ setDOMElementAttribute() [2/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
const char *  value 
)

◆ setDOMElementAttribute() [3/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
const UINT8 value 
)

Definition at line 836 of file CAUtil.cpp.

837 {
838  if(pElem==NULL||pElem->getNodeType()!=DOMNode::ELEMENT_NODE||attrName==NULL||value==NULL)
839  return E_UNKNOWN;
840  XMLCh* name=XMLString::transcode(attrName);
841  XMLCh* val=XMLString::transcode((const char*)value);
842  ((DOMElement*)pElem)->setAttribute(name,val);
843  XMLString::release(&name);
844  XMLString::release(&val);
845  return E_SUCCESS;
846 }

References E_SUCCESS, and E_UNKNOWN.

◆ setDOMElementAttribute() [4/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
SINT32  value 
)

Definition at line 988 of file CAUtil.cpp.

989 {
990  UINT8 tmp[10];
991  sprintf((char*)tmp, "%i", value);
992  return setDOMElementAttribute(pElem, attrName, tmp);
993 }

References setDOMElementAttribute().

Here is the call graph for this function:

◆ setDOMElementAttribute() [5/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
SINT64  value 
)

Definition at line 980 of file CAUtil.cpp.

981 {
982  UINT8 tmp[50];
983  memset(tmp, 0, 50);
984  snprintf((char *) tmp, 50, "%lld", value);
985  return setDOMElementAttribute(pElem, attrName, tmp);
986 }

References setDOMElementAttribute().

Here is the call graph for this function:

◆ setDOMElementAttribute() [6/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
UINT32  value 
)

Definition at line 1606 of file CAUtil.cpp.

1607 {
1608  UINT8 tmp[12];
1609  sprintf((char*)tmp, "%u", value);
1610  return setDOMElementAttribute(pElem, attrName, tmp);
1611 }

References setDOMElementAttribute().

Here is the call graph for this function:

◆ setDOMElementAttribute() [7/7]

SINT32 setDOMElementAttribute ( DOMNode *  pElem,
const char *  attrName,
UINT64  value 
)

Definition at line 973 of file CAUtil.cpp.

974 {
975  UINT8 tmp[50];
976  print64(tmp, value);
977  return setDOMElementAttribute(pElem, attrName, tmp);
978 }

References print64(), and setDOMElementAttribute().

Here is the call graph for this function:

◆ setDOMElementValue() [1/6]

SINT32 setDOMElementValue ( DOMElement *  pElem,
bool  value 
)

Definition at line 1002 of file CAUtil.cpp.

1003 {
1004  return setDOMElementValue(pElem,((UINT8*) (value ? STR_VALUE_TRUE : STR_VALUE_FALSE)));
1005 }

References setDOMElementValue(), STR_VALUE_FALSE, and STR_VALUE_TRUE.

Here is the call graph for this function:

◆ setDOMElementValue() [2/6]

SINT32 setDOMElementValue ( DOMElement *  pElem,
const UINT64  text 
)

Sets the decimal text representation of a 64bit integer as node value TODO: implement this for non-64bit platforms.

Returns the content of the text node under elem as 64bit unsigned integer.

Definition at line 962 of file CAUtil.cpp.

963  {
964  UINT8 tmp[32];
965  memset(tmp, 0, 32);
966  print64(tmp,text);
967  setDOMElementValue(pElem,tmp);
968  return E_SUCCESS;
969  }

References E_SUCCESS, print64(), and setDOMElementValue().

Here is the call graph for this function:

◆ setDOMElementValue() [3/6]

SINT32 setDOMElementValue ( DOMElement *  pElem,
const UINT8 value 
)

Definition at line 1582 of file CAUtil.cpp.

1583  {
1584  XMLCh* val=XMLString::transcode((const char *)value);
1585  DOMText* pText=pElem->getOwnerDocument()->createTextNode(val);
1586  XMLString::release(&val);
1587  //Remove all "old" text Elements...
1588  DOMNode* pChild=pElem->getFirstChild();
1589  while(pChild!=NULL)
1590  {
1591  if(pChild->getNodeType()==DOMNode::TEXT_NODE)
1592  {
1593  DOMNode* n=pElem->removeChild(pChild);
1594  if (n != NULL)
1595  {
1596  n->release();
1597  n = NULL;
1598  }
1599  }
1600  pChild=pChild->getNextSibling();
1601  }
1602  pElem->appendChild(pText);
1603  return E_SUCCESS;
1604  }

References E_SUCCESS.

◆ setDOMElementValue() [4/6]

SINT32 setDOMElementValue ( DOMElement *  pElem,
double  floatValue 
)

Definition at line 949 of file CAUtil.cpp.

950  {
951  char tmp[400];
952  snprintf(tmp,400, "%.2f", floatValue);
953  setDOMElementValue(pElem,(UINT8 *)tmp);
954  return E_SUCCESS;
955  }

References E_SUCCESS, and setDOMElementValue().

Here is the call graph for this function:

◆ setDOMElementValue() [5/6]

SINT32 setDOMElementValue ( DOMElement *  pElem,
SINT32  value 
)

Definition at line 939 of file CAUtil.cpp.

940  {
941  //One more char for the sign of negative numbers
942  UINT8 tmp[12];
943  memset(tmp, 0, 12);
944  snprintf((char*)tmp, 11, "%d", value);
945  setDOMElementValue(pElem,tmp);
946  return E_SUCCESS;
947  }

References E_SUCCESS.

Referenced by CACmdLnOptions::buildDefaultConfig(), CAFirstMix::doUserLogin_internal(), CACertificate::encode(), encodeXMLEncryptedKey(), encryptXMLElement(), CAInfoService::getCascadeHeloXMLAsString(), CACmdLnOptions::getMixXml(), CASignature::getSignKey(), CAAccountingInstance::handleAccountCertificate_internal(), CAMix::initMixCascadeInfo(), CAReplayCtrlChannelMsgProc::initTimestampsMessageTemplate(), CAAccountingInstance::makeCCRequest(), CAAccountingInstance::makeInitialCCRequest(), CAAccountingInstance::prepareCCRequest(), CAReplayCtrlChannelMsgProc::proccessGetTimestamp(), CAReplayCtrlChannelMsgProc::proccessGotTimestamp(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CACmdLnOptions::processXmlConfiguration(), CAReplayCtrlChannelMsgProc::propagateCurrentReplayTimestamp(), CAAccountingInstance::sendAILoginConfirmation(), setDOMElementValue(), CACmdLnOptions::setMixName(), CACmdLnOptions::setPrepaidInterval(), CACmdLnOptions::setSymChannelCipherAlgorithm(), CACmdLnOptions::setTargetInterfaces(), CAMultiSignature::signXML(), CAListenerInterface::toDOMElement(), and CAXMLErrorMessage::toXmlElement().

Here is the caller graph for this function:

◆ setDOMElementValue() [6/6]

SINT32 setDOMElementValue ( DOMElement *  pElem,
UINT32  value 
)

Definition at line 1574 of file CAUtil.cpp.

1575  {
1576  UINT8 tmp[11];
1577  memset(tmp, 0, 11);
1578  snprintf((char*)tmp, 10, "%u", value);
1579  setDOMElementValue(pElem,tmp);
1580  return E_SUCCESS;
1581  }

References E_SUCCESS, and setDOMElementValue().

Here is the call graph for this function:

◆ sSleep()

SINT32 sSleep ( UINT32  sec)

Sleeps sec Seconds.

Definition at line 425 of file CAUtil.cpp.

426  {
427  #ifdef _WIN32
428  Sleep(sec*1000);
429  #else
430  struct timespec req;
431  struct timespec rem;
432  req.tv_sec=sec;
433  req.tv_nsec=0;
434  while(nanosleep(&req,&rem)==-1)
435  {
436  req.tv_sec=rem.tv_sec;
437  req.tv_nsec=rem.tv_nsec;
438  }
439  #endif
440  return E_SUCCESS;
441  }

References E_SUCCESS.

Referenced by CATempIPBlockList::cleanupThreadMainLoop(), CASocket::connect(), CAFirstMix::connectToNextMix(), CAMiddleMix::connectToNextMix(), CAInfoService::InfoLoop(), CALocalProxy::loop(), signal_segv(), CALocalProxy::start(), and CAMix::start().

Here is the caller graph for this function:

◆ strins() [1/2]

char* strins ( const char *  src,
const char *  pos,
const char *  ins 
)

Inserts a String ins in a String src starting at the char pos points to.

Returns a newly allocated String which must be freed using delete.

Definition at line 168 of file CAUtil.cpp.

169  {
170  if(pos==NULL||pos<src)
171  return NULL;
172  return strins(src,pos-src,ins);
173  }
char * strins(const char *src, UINT32 pos, const char *ins)
Inserts a String ins in a String src starting after pos chars.
Definition: CAUtil.cpp:148

References strins().

Here is the call graph for this function:

◆ strins() [2/2]

char* strins ( const char *  src,
UINT32  pos,
const char *  ins 
)

Inserts a String ins in a String src starting after pos chars.

Returns a newly allocated String which must be freed using delete.

Definition at line 148 of file CAUtil.cpp.

149  {
150  if(src==NULL||ins==NULL)
151  return NULL;
152  UINT32 srcLen=strlen(src);
153  if(pos>srcLen)
154  return NULL;
155  UINT32 insLen=strlen(ins);
156  char* newString=new char[srcLen+insLen+1];
157  if(newString==NULL)
158  return NULL;
159  memcpy(newString,src,pos);
160  memcpy(newString+pos,ins,insLen);
161  memcpy(newString+pos+insLen,src+pos,srcLen-pos+1); //copy includes the \0
162  return newString;
163  }

Referenced by strins().

Here is the caller graph for this function:

◆ strtrim()

UINT32 strtrim ( UINT8 s)

Removes leading and ending whitespaces (chars<=32) from a zero terminated string.

Parameters
sinput string (null terminated)
Returns
new size of string
Return values
0means, that either s was NULL or that the new string has a zero length (that means, that the old string only contains whitespaces)

Definition at line 49 of file CAUtil.cpp.

50  {
51  if(s==NULL)
52  return 0;
53  UINT32 end=strlen((char*)s);
54  if(end==0)
55  return 0;
56  end--;
57  UINT32 start=0;
58  UINT32 size;
59  while(start<=end&&s[start]<=32)
60  start++;
61  if (start > end) //empty string....
62  {
63  s[0]=0;
64  return 0;
65  }
66  while(end>start&&s[end]<=32)
67  end--;
68  size=(end+1)-start;
69  memmove(s,s+start,size);
70  s[size]=0;
71  return size;
72  }

Referenced by CAListenerInterface::getInstance(), CAChain::getPrintableChainId(), CAMultiSignature::getSKI(), CAAccountingInstance::prepareCCRequest(), CACmdLnOptions::setAccountingDatabase(), CACmdLnOptions::setLoggingOptions(), CACmdLnOptions::setMixID(), and CACmdLnOptions::setTargetInterfaces().

Here is the caller graph for this function:

◆ toLower()

UINT32 toLower ( UINT8 a_string)

Definition at line 74 of file CAUtil.cpp.

75 {
76  const UINT8 differ =(UINT8) ('A'-'a');
77  int ii = strlen((char*)a_string);
78  for (int i=0; i <ii;i++)
79  {
80  UINT8 ch=a_string[i];
81  if (ch>='A' && ch<='Z')
82  {
83  ch = ch-differ;
84  a_string[i]=ch;
85  }
86  }
87  return E_SUCCESS;
88 }

References E_SUCCESS.

Referenced by CACmdLnOptions::setLoggingOptions().

Here is the caller graph for this function:

Variable Documentation

◆ theDOMParser

XercesDOMParser* theDOMParser =NULL

Definition at line 653 of file CAUtil.cpp.

Referenced by initDOMParser(), parseDOMDocument(), and releaseDOMParser().

◆ theParseDOMDocumentLock

CAMutex* theParseDOMDocumentLock = NULL

Definition at line 654 of file CAUtil.cpp.

Referenced by initDOMParser(), parseDOMDocument(), and releaseDOMParser().