Mixe for Privacy and Anonymity in the Internet
CAUtil.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #include "StdAfx.h"
29 #include "CAUtil.hpp"
30 #include "CABase64.hpp"
31 #include "CAMsg.hpp"
32 #include "xml/DOM_Output.hpp"
33 #include "CASymCipher.hpp"
34 
35 #ifdef HAVE_SBRK
36  char* internal_sbrk_start=(char*)sbrk(0);
37 #endif
38 
39 #ifdef LOG_CRIME
40  #include "tre/tre.h"
41 #endif
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  }
73 
74 UINT32 toLower(UINT8* a_string)
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 }
89 
90 UINT8* bytes2hex(const void* bytes,UINT32 len)
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  }
116 
126 SINT32 memtrim(UINT8* dest,const UINT8* src,UINT32 size)
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  }
144 
148 char* strins(const char* src,UINT32 pos,const char* ins)
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  }
164 
168 char* strins(const char* src,const char * pos,const char* ins)
169  {
170  if(pos==NULL||pos<src)
171  return NULL;
172  return strins(src,pos-src,ins);
173  }
174 
175 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_LAST_MIX
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  }
195 #endif //ONLY_LOCAL_PROXY
196 
203 /*SINT32 getcurrentTimeMillis(BIGNUM* bnTime)
204  {
205  if(bnTime==NULL)
206  return E_UNSPECIFIED;
207  #ifdef _WIN32
208  struct _timeb timebuffer;
209  _ftime(&timebuffer);
210  // Hack what should be solved better...
211  BN_set_word(bnTime,timebuffer.time);
212  BN_mul_word(bnTime,1000);
213  BN_add_word(bnTime,timebuffer.millitm);
214  // end of hack..
215  return E_SUCCESS;
216  #else //we dont use ftime due to a bug in glibc2.0
217  //we use gettimeofday() in order to get the millis...
218  struct timeval tv;
219  gettimeofday(&tv,NULL); //getting millis...
220  BN_set_word(bnTime,tv.tv_sec);
221  BN_mul_word(bnTime,1000);
222  BN_add_word(bnTime,tv.tv_usec/1000);
223  return E_SUCCESS;
224  #endif
225  }*/
226 
227 SINT32 getcurrentTime(timespec& t)
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  }
246 
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  }
273 
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  }
301 
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  }
315 
316 /*
317  * compares date1 with date2. Note: only the date is compared, not the time
318  * returns:
319  * -1 if date1 < date2
320  * 0 if date1 == date2
321  * 1 if date1 > date2
322  */
323 SINT32 compDate(struct tm *date1, struct tm *date2)
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 }
340 
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  }
357 
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 }
374 
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  }
386 
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  }
404 
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  }
423 
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  }
442 
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  }
457 
458 SINT32 getDOMChildByName(const DOMNode* pNode,const char * const name,DOMElement* & child,bool deep)
459  {
460  return getDOMChildByName(pNode,name,(DOMNode*&)child,deep);
461  }
462 SINT32 getDOMChildByName(const DOMNode* pNode,const XMLCh* const name,DOMNode* & a_child,bool deep)
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  }
484 
485 SINT32 getDOMChildByName(const DOMNode* pNode,const char* const name,DOMNode* & a_child,bool deep)
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  }
495 
496 SINT32 getSignatureElements(DOMNode* parent, DOMNode** signatureNodes, UINT32* length)
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 }
526 
532 #if !defined ONLY_LOCAL_PROXY && defined PAYMENT
533 SINT32 integrateDOMNode(const DOMNode *srcNode, DOMNode *dstNode, bool recursive, bool replace)
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 }
643 #endif //ONLY_LOCAL_PROXY
644 
645 bool equals(const XMLCh* const e1,const char* const e2)
646  {
647  XMLCh* e3=XMLString::transcode(e2);
648  bool ret=XMLString::equals(e1,e3);
649  XMLString::release(&e3);
650  return ret;
651  }
652 
653 XercesDOMParser* theDOMParser=NULL;
655 
657 {
659  theDOMParser = new XercesDOMParser();
660 }
661 
662 
663 XERCES_CPP_NAMESPACE::DOMDocument* parseDOMDocument(const UINT8* const buff, UINT32 len)
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  }
674 
678 #if !defined ONLY_LOCAL_PROXY && defined PAYMENT
679 XERCES_CPP_NAMESPACE::DOMDocument* parseDOMDocument(const UINT8* const pathOrURL)
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 }
692 #endif //ONLY_LOCAL_PROXY
693 
695  {
696  if( theParseDOMDocumentLock!=NULL)
697  {
699  delete theDOMParser;
700  theDOMParser=NULL;
704  }
705  }
706 
707 SINT32 getNodeName(const DOMNode * const pElem, UINT8* value,UINT32* valuelen)
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 }
732 
746 SINT32 getDOMElementValue(const DOMNode * const pElem,UINT8* value,UINT32* valuelen)
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  }
779 
780 SINT32 getDOMElementAttribute(const DOMNode * const elem,const char* attrName,UINT8* value,UINT32* len)
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  }
803 
804 SINT32 getDOMElementAttribute(const DOMNode * const elem,const char* attrName,SINT32* value)
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  }
813 
814 DOMElement* createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument* pOwnerDoc,const char * const name)
815  {
816  XMLCh* n=XMLString::transcode(name);
817  DOMElement* ret=pOwnerDoc->createElement(n);
818  XMLString::release(&n);
819  return ret;
820  }
821 
822 DOMText* createDOMText(XERCES_CPP_NAMESPACE::DOMDocument* pOwnerDoc,const char * const text)
823  {
824  XMLCh* t=XMLString::transcode(text);
825  DOMText* ret= pOwnerDoc->createTextNode(t);
826  XMLString::release(&t);
827  return ret;
828  }
829 
830 
831 SINT32 setDOMElementAttribute(DOMNode *pElem, const char *attrName, const char *value)
832  {
833  return setDOMElementAttribute(pElem,attrName,(const UINT8*)value);
834  }
835 
836 SINT32 setDOMElementAttribute(DOMNode* pElem,const char* attrName,const UINT8* value)
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 }
847 
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 }
863 
864 //if not null the returned char pointer must be explicitely freed by the caller with 'delete []'
865 UINT8 *getTermsAndConditionsTemplateRefId(DOMNode *tcTemplateRoot)
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 }
907 
908 SINT32 getDOMElementValue(const DOMElement* pElem, UINT32& value, UINT32 defaultValue)
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  }
919 
920 SINT32 getDOMElementValue(const DOMElement* const pElem, UINT32* value)
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  }
932 
933 
934 
935 #ifndef ONLY_LOCAL_PROXY
936 
937 
938 
939 SINT32 setDOMElementValue(DOMElement* pElem, SINT32 value)
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  }
948 
949 SINT32 setDOMElementValue(DOMElement* pElem,double floatValue)
950  {
951  char tmp[400];
952  snprintf(tmp,400, "%.2f", floatValue);
953  setDOMElementValue(pElem,(UINT8 *)tmp);
954  return E_SUCCESS;
955  }
956 
957 
962 SINT32 setDOMElementValue(DOMElement* pElem, const UINT64 text)
963  {
964  UINT8 tmp[32];
965  memset(tmp, 0, 32);
966  print64(tmp,text);
967  setDOMElementValue(pElem,tmp);
968  return E_SUCCESS;
969  }
970 
971 
972 
973 SINT32 setDOMElementAttribute(DOMNode* pElem, const char* attrName, UINT64 value)
974 {
975  UINT8 tmp[50];
976  print64(tmp, value);
977  return setDOMElementAttribute(pElem, attrName, tmp);
978 }
979 
980 SINT32 setDOMElementAttribute(DOMNode* pElem, const char* attrName, SINT64 value)
981 {
982  UINT8 tmp[50];
983  memset(tmp, 0, 50);
984  snprintf((char *) tmp, 50, "%lld", value);
985  return setDOMElementAttribute(pElem, attrName, tmp);
986 }
987 
988 SINT32 setDOMElementAttribute(DOMNode* pElem,const char* attrName, SINT32 value)
989 {
990  UINT8 tmp[10];
991  sprintf((char*)tmp, "%i", value);
992  return setDOMElementAttribute(pElem, attrName, tmp);
993 }
994 
995 
996 SINT32 setDOMElementAttribute(DOMNode* pElem, const char* attrName, bool value)
997 {
998  return setDOMElementAttribute(pElem, attrName,
999  ((UINT8*) (value ? STR_VALUE_TRUE : STR_VALUE_FALSE)));
1000 }
1001 
1002 SINT32 setDOMElementValue(DOMElement* pElem, bool value)
1003 {
1004  return setDOMElementValue(pElem,((UINT8*) (value ? STR_VALUE_TRUE : STR_VALUE_FALSE)));
1005 }
1006 
1007 
1008 SINT32 getDOMElementValue(const DOMElement* const pElem,SINT32* value)
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 }
1020 
1021 SINT32 getDOMElementValue(const DOMElement* const pElem,double* value)
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 }
1033 
1034 SINT32 getDOMElementValue(const DOMNode* const pElem, UINT64 &value)
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 }
1050 
1051 SINT32 getDOMElementValue(const DOMElement* const pElem, SINT64 &value)
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 }
1066 
1067 
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 }
1167 #endif //ONLY_LOCAL_PROXY
1168 
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 }
1222 
1223 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
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 }
1328 #endif
1329 
1330 UINT8* readFile(const UINT8* const name,UINT32* size)
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 }
1351 
1352 SINT32 saveFile(const UINT8* const name,const UINT8* const buff,UINT32 buffSize)
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 }
1365 
1366 
1367 SINT32 parseUINT16(const UINT8 * str, UINT16& value)
1368 {
1369  UINT16 v = atol((const char*)str);
1370  value = v;
1371  return E_SUCCESS;
1372 }
1373 
1378 SINT32 parseU64(const UINT8 * str, UINT64& value)
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 }
1425 
1430 SINT32 parseS64(const UINT8 * str, SINT64& value)
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 }
1472 
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 }
1513 
1522 /*SINT32 parseJdbcTimestamp(const UINT8 * strTimestamp, SINT32& seconds)
1523 {
1524  struct tm time;
1525  SINT32 rc;
1526 
1527  // parse the formatted string
1528  rc = sscanf((const char*)strTimestamp, "%d-%d-%d %d:%d:%d",
1529  &time.tm_year, &time.tm_mon, &time.tm_mday, &time.tm_hour,
1530  &time.tm_min, &time.tm_sec);
1531  if(rc!=6) return E_UNKNOWN; // parsing error
1532 
1533  // convert values to struct tm semantic
1534  if(time.tm_year<1970) return E_UNKNOWN;
1535  time.tm_year-=1900;
1536  if(time.tm_mon<1 || time.tm_mon>12) return E_UNKNOWN;
1537  time.tm_mon-=1;
1538  seconds = (UINT32)mktime(&time);
1539  if(seconds<0) return E_UNKNOWN;
1540 
1541  return E_SUCCESS;
1542 }*/
1543 
1544 
1553 /*SINT32 formatJdbcTimestamp(const SINT32 seconds, UINT8 * strTimestamp, const UINT32 len)
1554 {
1555  struct tm * time;
1556  time = localtime((time_t *) (&seconds));
1557  // without this line, there are problems on 64 BIT machines!!
1558  CAMsg::printMsg( LOG_DEBUG, "Year: %d Month: %d\n", time->tm_year, time->tm_mon);
1559 
1560  if(strftime((char *)strTimestamp, len, "%Y-%m-%d %H:%M:%S", time) == 0)
1561  {
1562  return E_SPACE;
1563  }
1564  return E_SUCCESS;
1565 }*/
1566 
1567 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
1568 XERCES_CPP_NAMESPACE::DOMDocument* createDOMDocument()
1569  {
1570  DOMImplementation* pImpl=DOMImplementation::getImplementation();
1571  return pImpl->createDocument();
1572  }
1573 
1574 SINT32 setDOMElementValue(DOMElement* pElem, UINT32 value)
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  }
1582 SINT32 setDOMElementValue(DOMElement* pElem,const UINT8* value)
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  }
1605 
1606 SINT32 setDOMElementAttribute(DOMNode* pElem,const char* attrName, UINT32 value)
1607 {
1608  UINT8 tmp[12];
1609  sprintf((char*)tmp, "%u", value);
1610  return setDOMElementAttribute(pElem, attrName, tmp);
1611 }
1612 
1613 SINT32 getDOMElementAttribute(const DOMNode * const elem,const char* attrName,UINT32& value)
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 }
1625 SINT32 decodeXMLEncryptedKey(UINT8* key,UINT32* keylen, const UINT8* const xml, UINT32 xmllen,CAASymCipher* pRSA)
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 }
1645 
1646 SINT32 decodeXMLEncryptedKey(UINT8* key,UINT32* keylen,const DOMNode* root,CAASymCipher* pRSA)
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 }
1672 
1673 void __encryptKey(UINT8* key,UINT32 keylen,UINT8* outBuff,UINT32* outLen,CAASymCipher* pRSA)
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 }
1682 
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 }
1693 
1694 SINT32 encodeXMLEncryptedKey(UINT8* key,UINT32 keylen, DOMElement* & elemRootEncodedKey,XERCES_CPP_NAMESPACE::DOMDocument* docOwner,CAASymCipher* pRSA)
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 }
1710 
1711 DOMNodeList* getElementsByTagName(DOMElement* pElem,const char* const name)
1712  {
1713  XMLCh* tmpCh=XMLString::transcode(name);
1714  DOMNodeList* ret=pElem->getElementsByTagName(tmpCh);
1715  XMLString::release(&tmpCh);
1716  return ret;
1717  }
1718 
1719 SINT32 getLastDOMChildByName(const DOMNode* pNode,const char * const name,DOMElement* & a_child)
1720  {
1721  return getLastDOMChildByName(pNode,name,(DOMNode*&)a_child);
1722  }
1723 
1724 SINT32 getLastDOMChildByName(const DOMNode* pNode,const char* const name,DOMNode* & a_child)
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 }
1734 
1735 SINT32 getLastDOMChildByName(const DOMNode* pNode,const XMLCh* const name,DOMNode* & a_child)
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 }
1755 
1756 SINT32 getDOMElementAttribute(const DOMNode * const elem,const char* attrName,bool& value)
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 }
1777 
1778 SINT32 getDOMElementAttribute(const DOMNode * const elem,const char* attrName,SINT64& value)
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 }
1792 
1793 SINT32 getDOMElementAttribute(const DOMNode * const elem,const char* attrName, UINT64& value)
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 }
1807 
1808 SINT32 getDOMElementValue(const DOMElement* const pElem,UINT16* value)
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 }
1818 
1819 
1820 
1821 void formatBytesPerSecond(UINT8* buff, UINT32 buffsize, UINT64 bytespersecond)
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 }
1843 
1844 
1845 #endif
SINT32 getNodeName(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Definition: CAUtil.cpp:707
SINT32 setDOMElementAttribute(DOMNode *pElem, const char *attrName, const char *value)
Definition: CAUtil.cpp:831
UINT8 * bytes2hex(const void *bytes, UINT32 len)
Converts the byte array to a hex string.
Definition: CAUtil.cpp:90
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:252
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
UINT8 * readFile(const UINT8 *const name, UINT32 *size)
ONLY_LOCAL_PROXY or first.
Definition: CAUtil.cpp:1330
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
Definition: CAUtil.cpp:939
SINT32 setCurrentTimeMilliesAsDOMAttribute(DOMNode *pElem)
Definition: CAUtil.cpp:848
SINT32 readPasswd(UINT8 *buff, UINT32 len)
Read a passwd (i.e.
Definition: CAUtil.cpp:1473
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
SINT32 getcurrentTimeMicros(UINT64 &u64Time)
Gets the current Systemtime in micros seconds.
Definition: CAUtil.cpp:280
UINT32 strtrim(UINT8 *s)
Removes leading and ending whitespaces (chars<=32) from a zero terminated string.
Definition: CAUtil.cpp:49
SINT32 initRandom()
Definition: CAUtil.cpp:302
XercesDOMParser * theDOMParser
Definition: CAUtil.cpp:653
SINT32 parseS64(const UINT8 *str, SINT64 &value)
Parses a 64bit signed integer.
Definition: CAUtil.cpp:1430
UINT32 getMemoryUsage()
Definition: CAUtil.cpp:443
bool equals(const XMLCh *const e1, const char *const e2)
Definition: CAUtil.cpp:645
SINT32 sSleep(UINT32 sec)
Sleeps sec Seconds.
Definition: CAUtil.cpp:425
UINT8 * getTermsAndConditionsTemplateRefId(DOMNode *tcTemplateRoot)
Definition: CAUtil.cpp:865
void __encryptKey(UINT8 *key, UINT32 keylen, UINT8 *outBuff, UINT32 *outLen, CAASymCipher *pRSA)
Definition: CAUtil.cpp:1673
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
DOMNodeList * getElementsByTagName(DOMElement *pElem, const char *const name)
Definition: CAUtil.cpp:1711
SINT32 parseU64(const UINT8 *str, UINT64 &value)
Parses a 64bit unsigned integer.
Definition: CAUtil.cpp:1378
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
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: CAUtil.cpp:822
SINT32 decryptXMLElement(DOMNode *node, CAASymCipher *pRSA)
Replaces a DOM element with a deencrypted version of this element.
Definition: CAUtil.cpp:1224
void initDOMParser()
Definition: CAUtil.cpp:656
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument()
Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in...
Definition: CAUtil.cpp:1568
void releaseDOMParser()
Definition: CAUtil.cpp:694
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
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
Definition: CAUtil.cpp:458
SINT32 getcurrentTime(timespec &t)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:227
CAMutex * theParseDOMDocumentLock
Definition: CAUtil.cpp:654
UINT32 toLower(UINT8 *a_string)
Definition: CAUtil.cpp:74
void formatBytesPerSecond(UINT8 *buff, UINT32 buffsize, UINT64 bytespersecond)
Definition: CAUtil.cpp:1821
SINT32 getDOMElementAttribute(const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
Definition: CAUtil.cpp:780
void logMemoryUsage()
Log information about the current memory (heap) usage.
Definition: CAUtil.cpp:177
SINT32 saveFile(const UINT8 *const name, const UINT8 *const buff, UINT32 buffSize)
Definition: CAUtil.cpp:1352
SINT32 encodeXMLEncryptedKey(UINT8 *key, UINT32 keylen, UINT8 *xml, UINT32 *xmllen, CAASymCipher *pRSA)
Definition: CAUtil.cpp:1683
SINT32 getLastDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&a_child)
Definition: CAUtil.cpp:1719
SINT32 memtrim(UINT8 *dest, const UINT8 *src, UINT32 size)
Removes leading and ending whitespaces (chars<=32) from a byte array.
Definition: CAUtil.cpp:126
SINT32 encryptXMLElement(DOMNode *node, CAASymCipher *pRSA)
The resulting encrypted xml struct is as follows:
Definition: CAUtil.cpp:1086
SINT32 decodeXMLEncryptedKey(UINT8 *key, UINT32 *keylen, const UINT8 *const xml, UINT32 xmllen, CAASymCipher *pRSA)
Definition: CAUtil.cpp:1625
SINT32 getSignatureElements(DOMNode *parent, DOMNode **signatureNodes, UINT32 *length)
Definition: CAUtil.cpp:496
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
Definition: CAUtil.cpp:406
SINT32 integrateDOMNode(const DOMNode *srcNode, DOMNode *dstNode, bool recursive, bool replace)
integrates the source node in the destination Node.
Definition: CAUtil.cpp:533
SINT32 compDate(struct tm *date1, struct tm *date2)
Definition: CAUtil.cpp:323
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...
Definition: CAUtil.cpp:1367
#define XML_ENCODE_KEY_TEMPLATE
#define STR_VALUE_FALSE
Definition: CAUtil.hpp:36
#define TMP_LOCALE_SIZE
Definition: CAUtil.hpp:39
SINT32 filesize32(int handle)
Definition: CAUtil.hpp:102
void print64(UINT8 *buff, UINT64 num)
Definition: CAUtil.hpp:482
#define INTEGRATE_NOT_ALLOWED_POSITIONS
Definition: CAUtil.hpp:48
#define STR_VALUE_TRUE
Definition: CAUtil.hpp:35
#define UNIVERSAL_ATTRIBUTE_LAST_UPDATE
Definition: CAUtil.hpp:32
#define TMP_BUFF_SIZE
Definition: CAUtil.hpp:38
#define TMP_DATE_SIZE
Definition: CAUtil.hpp:40
#define myfilewrite
Definition: StdAfx.h:493
#define S_IWRITE
Definition: StdAfx.h:491
#define S_IREAD
Definition: StdAfx.h:488
#define ASSERT(cond, msg)
Definition: StdAfx.h:546
unsigned short UINT16
Definition: basetypedefs.h:133
signed int SINT32
Definition: basetypedefs.h:132
struct __UINT64__t_ UINT64
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 decryptOAEP(const UINT8 *from, UINT8 *to, UINT32 *len)
Decrypts one OAEP encoded block which is stored in from.
SINT32 encryptOAEP(const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
Encrypts one block of plain text using OAEP padding.
SINT32 decrypt(const UINT8 *from, UINT8 *to)
Decrypts exactly one block which is stored in from.
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
static SINT32 decode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
Definition: CABase64.cpp:41
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
This class could be used for encryption/decryption of data (streams) with AES using 128bit CBC mode.
Definition: CASymCipher.hpp:42
SINT32 encryptCBCwithPKCS7(const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *len)
En-/Decryptes in to out using IV1 and key1.
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.
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161
#define O_BINARY
Definition: config.h:179
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_SPACE
Definition: errorcodes.hpp:7
#define E_UNKNOWN
Definition: errorcodes.hpp:3
#define E_UNSPECIFIED
Definition: errorcodes.hpp:6
UINT16 flags
Definition: typedefs.hpp:1
UINT16 len
Definition: typedefs.hpp:0