本文整理汇总了C++中GWEN_Buffer_new函数的典型用法代码示例。如果您正苦于以下问题:C++ GWEN_Buffer_new函数的具体用法?C++ GWEN_Buffer_new怎么用?C++ GWEN_Buffer_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GWEN_Buffer_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AHB_DTAUS__CreateSetC
int AHB_DTAUS__CreateSetC(GWEN_BUFFER *dst,
GWEN_DB_NODE *cfg,
GWEN_DB_NODE *xa,
AB_VALUE *sumEUR,
AB_VALUE *sumDEM,
AB_VALUE *sumBankCodes,
AB_VALUE *sumAccountIds){
unsigned int i;
const char *p;
char buffer[32];
int isDebitNote;
int isEuro;
unsigned int extSets;
//unsigned int startPos;
AB_VALUE *val;
GWEN_STRINGLIST *purposeList;
DBG_DEBUG(AQBANKING_LOGDOMAIN, "Creating C set");
/* ______________________________________________________________________
* preparations
*/
purposeList=GWEN_StringList_new();
/* cut purpose lines into manageable portions (max 27 chars) */
for (i=0; ; i++) {
int slen;
GWEN_BUFFER *nbuf;
p=GWEN_DB_GetCharValue(xa, "purpose", i, 0);
if (p==NULL)
break;
if (i>14) {
DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many purpose lines (maxmimum is 14)");
GWEN_StringList_free(purposeList);
return -1;
}
slen=strlen(p);
nbuf=GWEN_Buffer_new(0, slen+1, 0, 1);
AB_ImExporter_Utf8ToDta(p, -1, nbuf);
p=GWEN_Buffer_GetStart(nbuf);
while(*p) {
while(*p>0 && *p<33)
p++;
slen=strlen(p);
if (slen==0)
break;
else if (slen>27) {
char *ns;
ns=(char*) malloc(28);
assert(ns);
memmove(ns, p, 27);
ns[27]=0;
/* let stringlist take over ownership of the the string */
GWEN_StringList_AppendString(purposeList, ns, 1, 0);
p+=27;
}
else {
GWEN_StringList_AppendString(purposeList, p, 0, 0);
break;
}
}
GWEN_Buffer_free(nbuf);
} /* for */
//startPos=GWEN_Buffer_GetPos(dst);
GWEN_Buffer_AllocRoom(dst, 256);
isDebitNote=(strcasecmp(GWEN_DB_GetCharValue(cfg, "type", 0, "transfer"),
"debitnote")==0);
isEuro=(strcasecmp(GWEN_DB_GetCharValue(cfg, "currency", 0, "EUR"),
"EUR")==0);
/* compute number of extension sets */
extSets=0;
/* add purpose */
if (GWEN_StringList_Count(purposeList))
extSets+=GWEN_StringList_Count(purposeList)-1;
/* add name */
for (i=1; i<2; i++) { /* max 1 extset for local name */
if (GWEN_DB_GetCharValue(xa, "localName", i, 0)==0)
break;
if (i>1) {
DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many name lines (maxmimum is 2)");
GWEN_StringList_free(purposeList);
return -1;
}
extSets++;
} /* for */
/* add other name */
for (i=1; i<2; i++) { /* max 1 extset for remote name */
if (GWEN_DB_GetCharValue(xa, "remoteName", i, 0)==0)
break;
if (i>1) {
DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many peer name lines (maxmimum is 2)");
//.........这里部分代码省略.........
示例2: AB_Transaction_SetValutaDate
AB_TRANSACTION *AB_ImExporterYN__ReadLNE_LNS(AB_IMEXPORTER *ie,
AB_IMEXPORTER_ACCOUNTINFO *ai,
GWEN_XMLNODE *node)
{
AB_TRANSACTION *t;
GWEN_XMLNODE *nn;
GWEN_DATE *da=NULL;
AB_VALUE *val=NULL;
t=AB_Transaction_new();
/* get date */
nn=GWEN_XMLNode_FindFirstTag(node, "DTM", 0, 0);
if (nn)
da=AB_ImExporterYN__ReadDate(ie, nn, 209);
AB_Transaction_SetValutaDate(t, da);
GWEN_Date_free(da);
da=NULL;
/* read amount */
nn=GWEN_XMLNode_FindFirstTag(node, "MOA", 0, 0);
if (nn) {
/* Gutschrift */
val=AB_ImExporterYN__ReadValue(ie, nn, 210);
if (val) {
if (AB_Value_IsZero(val)) {
AB_Value_free(val);
val=NULL;
}
}
if (val==NULL) {
val=AB_ImExporterYN__ReadValue(ie, nn, 211);
if (val)
AB_Value_Negate(val);
}
}
if (val==NULL)
val=AB_Value_new();
AB_Value_SetCurrency(val, AB_ImExporterAccountInfo_GetCurrency(ai));
AB_Transaction_SetValue(t, val);
AB_Value_free(val);
val=0;
/* read purpose */
nn=GWEN_XMLNode_GetNodeByXPath(node, "FTX/C108",
GWEN_PATH_FLAGS_NAMEMUSTEXIST);
if (nn) {
GWEN_XMLNODE *nnn;
nnn=GWEN_XMLNode_FindFirstTag(nn, "D_4440", 0, 0);
while (nnn) {
GWEN_XMLNODE *nData;
nData=GWEN_XMLNode_GetFirstData(nnn);
if (nData) {
const char *s;
s=GWEN_XMLNode_GetData(nData);
if (s) {
GWEN_BUFFER *xbuf;
xbuf=GWEN_Buffer_new(0, 256, 0, 1);
AB_ImExporter_Iso8859_1ToUtf8(s, strlen(s), xbuf);
AB_Transaction_AddPurposeLine(t, GWEN_Buffer_GetStart(xbuf));
GWEN_Buffer_free(xbuf);
}
}
nnn=GWEN_XMLNode_FindNextTag(nnn, "D_4440", 0, 0);
}
}
return t;
}
示例3: GWEN_CryptMgrKeys_SignData
GWENHYWFAR_CB
int GWEN_CryptMgrKeys_SignData(GWEN_CRYPTMGR *cm,
const uint8_t *pData, uint32_t lData,
GWEN_BUFFER *dbuf) {
GWEN_CRYPTMGR_KEYS *xcm;
GWEN_MDIGEST *md;
int rv;
GWEN_BUFFER *tbuf;
int ksize;
uint32_t signatureLen;
assert(cm);
xcm=GWEN_INHERIT_GETDATA(GWEN_CRYPTMGR, GWEN_CRYPTMGR_KEYS, cm);
assert(xcm);
if (xcm->localKey==NULL) {
DBG_ERROR(GWEN_LOGDOMAIN, "No local key");
return GWEN_ERROR_GENERIC;
}
ksize=GWEN_Crypt_Key_GetKeySize(xcm->localKey);
/* hash pData */
md=GWEN_MDigest_Rmd160_new();
rv=GWEN_MDigest_Begin(md);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_MDigest_free(md);
return rv;
}
rv=GWEN_MDigest_Update(md, pData, lData);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_MDigest_free(md);
return rv;
}
rv=GWEN_MDigest_End(md);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_MDigest_free(md);
return rv;
}
/* padd */
tbuf=GWEN_Buffer_new(0, ksize, 0, 1);
GWEN_Buffer_AppendBytes(tbuf,
(const char*)GWEN_MDigest_GetDigestPtr(md),
GWEN_MDigest_GetDigestSize(md));
GWEN_MDigest_free(md);
GWEN_Padd_PaddWithIso9796_2(tbuf, ksize);
/* sign */
GWEN_Buffer_AllocRoom(dbuf, ksize);
signatureLen=GWEN_Buffer_GetMaxUnsegmentedWrite(dbuf);
rv=GWEN_Crypt_Key_Sign(xcm->localKey,
(uint8_t*)GWEN_Buffer_GetStart(tbuf),
GWEN_Buffer_GetUsedBytes(tbuf),
(uint8_t*)GWEN_Buffer_GetPosPointer(dbuf),
&signatureLen);
GWEN_Buffer_free(tbuf);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
return rv;
}
GWEN_Buffer_IncrementPos(dbuf, signatureLen);
GWEN_Buffer_AdjustUsedBytes(dbuf);
return 0;
}
示例4: AIO_OfxGroup_STATUS_EndTag
int AIO_OfxGroup_STATUS_EndTag(AIO_OFX_GROUP *g, const char *tagName)
{
AIO_OFX_GROUP_STATUS *xg;
//GWEN_XML_CONTEXT *ctx;
assert(g);
xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_STATUS, g);
assert(xg);
//ctx=AIO_OfxGroup_GetXmlContext(g);
assert(tagName);
if (strcasecmp(tagName, AIO_OfxGroup_GetGroupName(g))!=0) {
/* tag does not close this one */
DBG_DEBUG(AQBANKING_LOGDOMAIN,
"Tag [%s] does not close [%s], ignoring",
tagName, AIO_OfxGroup_GetGroupName(g));
return 0;
}
/* show status message */
if (xg->description) {
GWEN_BUFFER *buf;
char numbuf[32];
const AIO_OFX_GROUP_STATUS_ERROR *e;
e=AIO_OfxGroup_STATUS__getErrorStruct(xg->code);
buf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendString(buf, xg->description);
GWEN_Buffer_AppendString(buf, ": ");
/* append error string if available */
if (e && e->name) {
GWEN_Buffer_AppendString(buf, I18N(e->name));
GWEN_Buffer_AppendString(buf, " (");
}
GWEN_Buffer_AppendString(buf, I18N("Code"));
GWEN_Buffer_AppendString(buf, " ");
snprintf(numbuf, sizeof(numbuf)-1, "%d", xg->code);
numbuf[sizeof(numbuf)-1]=0;
GWEN_Buffer_AppendString(buf, numbuf);
if (xg->severity) {
GWEN_Buffer_AppendString(buf, ", ");
GWEN_Buffer_AppendString(buf, I18N("severity"));
GWEN_Buffer_AppendString(buf, " \"");
GWEN_Buffer_AppendString(buf, xg->severity);
GWEN_Buffer_AppendString(buf, "\"");
}
if (e && e->name) {
GWEN_Buffer_AppendString(buf, ")");
}
/* append error description if available */
if (e && e->description) {
GWEN_Buffer_AppendString(buf, "\n");
GWEN_Buffer_AppendString(buf, I18N(e->description));
}
DBG_INFO(AQBANKING_LOGDOMAIN,
"%s", GWEN_Buffer_GetStart(buf));
GWEN_Gui_ProgressLog(0,
GWEN_LoggerLevel_Notice,
GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
}
if (xg->oldEndTagFn)
return xg->oldEndTagFn(g, tagName);
else
return 1;
}
示例5: AH_Msg_EncryptPinTan
int AH_Msg_EncryptPinTan(AH_MSG *hmsg) {
AH_HBCI *h;
GWEN_XMLNODE *node;
GWEN_DB_NODE *cfg;
GWEN_BUFFER *hbuf;
int rv;
const char *p;
GWEN_MSGENGINE *e;
AB_USER *u;
const char *peerId;
// uint32_t uFlags;
assert(hmsg);
h=AH_Dialog_GetHbci(hmsg->dialog);
assert(h);
e=AH_Dialog_GetMsgEngine(hmsg->dialog);
assert(e);
GWEN_MsgEngine_SetMode(e, "pintan");
u=AH_Dialog_GetDialogOwner(hmsg->dialog);
// uFlags=AH_User_GetFlags(u);
peerId=AH_User_GetPeerId(u);
if (!peerId || *peerId==0)
peerId=AB_User_GetUserId(u);
/* create crypt head */
node=GWEN_MsgEngine_FindNodeByPropertyStrictProto(e,
"SEG",
"id",
0,
"CryptHead");
if (!node) {
DBG_INFO(AQHBCI_LOGDOMAIN, "Segment \"CryptHead\" not found");
return GWEN_ERROR_INTERNAL;
}
/* create CryptHead */
cfg=GWEN_DB_Group_new("crypthead");
GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT,
"head/seq", 998);
rv=AH_MsgPinTan_PrepareCryptoSeg(hmsg, u, cfg, 1, 0);
if (rv) {
DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
GWEN_DB_Group_free(cfg);
return rv;
}
/* store system id */
p=NULL;
if (!hmsg->noSysId)
p=AH_User_GetSystemId(u);
if (!p)
p="0";
GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "SecDetails/SecId", p);
/* store encrypted message key */
GWEN_DB_SetBinValue(cfg, GWEN_DB_FLAGS_DEFAULT,
"CryptAlgo/MsgKey",
"NOKEY", 5);
hbuf=GWEN_Buffer_new(0, 256+GWEN_Buffer_GetUsedBytes(hmsg->buffer), 0, 1);
rv=GWEN_MsgEngine_CreateMessageFromNode(e,
node,
hbuf,
cfg);
if (rv) {
DBG_INFO(AQHBCI_LOGDOMAIN, "Could not create CryptHead (%d)", rv);
GWEN_Buffer_free(hbuf);
GWEN_DB_Group_free(cfg);
return rv;
}
GWEN_DB_Group_free(cfg);
/* create cryptdata */
cfg=GWEN_DB_Group_new("cryptdata");
GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT,
"head/seq", 999);
GWEN_DB_SetBinValue(cfg, GWEN_DB_FLAGS_DEFAULT,
"cryptdata",
GWEN_Buffer_GetStart(hmsg->buffer),
GWEN_Buffer_GetUsedBytes(hmsg->buffer));
node=GWEN_MsgEngine_FindNodeByPropertyStrictProto(e,
"SEG",
"id",
0,
"CryptData");
if (!node) {
DBG_INFO(AQHBCI_LOGDOMAIN, "Segment \"CryptData\"not found");
GWEN_Buffer_free(hbuf);
GWEN_DB_Group_free(cfg);
return -1;
}
rv=GWEN_MsgEngine_CreateMessageFromNode(e,
node,
hbuf,
cfg);
if (rv) {
//.........这里部分代码省略.........
示例6: EBC_Dialog_ExchangeMessages
int EBC_Dialog_ExchangeMessages(GWEN_HTTP_SESSION *sess,
EB_MSG *msg,
EB_MSG **pResponse) {
AB_USER *u;
int rv;
GWEN_BUFFER *sendBuf;
GWEN_BUFFER *recvBuf;
EB_MSG *mResponse;
/* preparations */
u=AB_HttpSession_GetUser(sess);
assert(u);
sendBuf=GWEN_Buffer_new(0, 1024, 0, 1);
recvBuf=GWEN_Buffer_new(0, 1024, 0, 1);
/* convert message to buffer for sending */
EB_Msg_toBuffer(msg, sendBuf);
#if 0
if (GWEN_Logger_GetLevel(AQEBICS_LOGDOMAIN)>=GWEN_LoggerLevel_Debug) {
DBG_ERROR(AQEBICS_LOGDOMAIN, "Sending this:");
fprintf(stderr, "====================================\n");
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(sendBuf));
fprintf(stderr, "====================================\n");
}
#endif
/* send request */
rv=GWEN_HttpSession_SendPacket(sess,
"POST",
(const uint8_t*)GWEN_Buffer_GetStart(sendBuf),
GWEN_Buffer_GetUsedBytes(sendBuf));
if (rv<0) {
DBG_ERROR(AQEBICS_LOGDOMAIN, "Error sending request (%d)", rv);
GWEN_Buffer_free(recvBuf);
GWEN_Buffer_free(sendBuf);
return rv;
}
GWEN_Buffer_free(sendBuf);
/* receive response */
rv=GWEN_HttpSession_RecvPacket(sess, recvBuf);
if (rv<0 || rv>=300) {
DBG_ERROR(AQEBICS_LOGDOMAIN, "Error sending request (%d)", rv);
GWEN_Buffer_free(recvBuf);
return rv;
}
#if 0
if (GWEN_Logger_GetLevel(AQEBICS_LOGDOMAIN)>=GWEN_LoggerLevel_Debug) {
DBG_ERROR(AQEBICS_LOGDOMAIN, "Received this:");
fprintf(stderr, "====================================\n");
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(recvBuf));
fprintf(stderr, "====================================\n");
}
#endif
/* convert buffer to EBICS message */
mResponse=EB_Msg_fromBuffer(GWEN_Buffer_GetStart(recvBuf),
GWEN_Buffer_GetUsedBytes(recvBuf));
GWEN_Buffer_free(recvBuf);
if (!mResponse) {
DBG_ERROR(AQEBICS_LOGDOMAIN, "Invalid response (no EBICS message)");
return GWEN_ERROR_BAD_DATA;
}
*pResponse=mResponse;
return 0;
}
示例7: listItanModes
int listItanModes(AB_BANKING *ab,
GWEN_DB_NODE *dbArgs,
int argc,
char **argv) {
GWEN_DB_NODE *db;
AB_PROVIDER *pro;
AB_USER_LIST2 *ul;
AB_USER *u=0;
int rv;
const char *bankId;
const char *userId;
const char *customerId;
const GWEN_ARGS args[]={
{
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
GWEN_ArgsType_Char, /* type */
"bankId", /* name */
0, /* minnum */
1, /* maxnum */
"b", /* short option */
"bank", /* long option */
"Specify the bank code", /* short description */
"Specify the bank code" /* long description */
},
{
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
GWEN_ArgsType_Char, /* type */
"userId", /* name */
0, /* minnum */
1, /* maxnum */
"u", /* short option */
"user", /* long option */
"Specify the user id (Benutzerkennung)", /* short description */
"Specify the user id (Benutzerkennung)" /* long description */
},
{
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
GWEN_ArgsType_Char, /* type */
"customerId", /* name */
0, /* minnum */
1, /* maxnum */
"c", /* short option */
"customer", /* long option */
"Specify the customer id (Kundennummer)", /* short description */
"Specify the customer id (Kundennummer)" /* long description */
},
{
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
GWEN_ArgsType_Int, /* type */
"help", /* name */
0, /* minnum */
0, /* maxnum */
"h", /* short option */
"help", /* long option */
"Show this help screen", /* short description */
"Show this help screen" /* long description */
}
};
db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
rv=GWEN_Args_Check(argc, argv, 1,
0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/,
args,
db);
if (rv==GWEN_ARGS_RESULT_ERROR) {
fprintf(stderr, "ERROR: Could not parse arguments\n");
return 1;
}
else if (rv==GWEN_ARGS_RESULT_HELP) {
GWEN_BUFFER *ubuf;
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
fprintf(stderr, "ERROR: Could not create help string\n");
return 1;
}
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
GWEN_Buffer_free(ubuf);
return 0;
}
rv=AB_Banking_Init(ab);
if (rv) {
DBG_ERROR(0, "Error on init (%d)", rv);
return 2;
}
rv=AB_Banking_OnlineInit(ab);
if (rv) {
DBG_ERROR(0, "Error on init (%d)", rv);
return 2;
}
pro=AB_Banking_GetProvider(ab, "aqhbci");
assert(pro);
bankId=GWEN_DB_GetCharValue(db, "bankId", 0, "*");
userId=GWEN_DB_GetCharValue(db, "userId", 0, "*");
customerId=GWEN_DB_GetCharValue(db, "customerId", 0, "*");
//.........这里部分代码省略.........
示例8: GWEN_CryptMgr_Sign
int GWEN_CryptMgr_Sign(GWEN_CRYPTMGR *cm, const uint8_t *pData, uint32_t lData, GWEN_BUFFER *dbuf) {
GWEN_SIGHEAD *sh;
GWEN_SIGTAIL *st;
GWEN_TIME *ti;
uint32_t pos;
uint32_t shPos;
uint8_t *p;
uint32_t l;
int rv;
GWEN_BUFFER *sigbuf;
assert(cm);
GWEN_Buffer_AppendByte(dbuf, GWEN_CRYPTMGR_TLV_SIGNEDOBJECT);
pos=GWEN_Buffer_GetPos(dbuf);
GWEN_Buffer_AppendByte(dbuf, 0);
GWEN_Buffer_AppendByte(dbuf, 0);
/* prepare signature head */
sh=GWEN_SigHead_new();
GWEN_SigHead_SetKeyName(sh, cm->localKeyName);
GWEN_SigHead_SetKeyNumber(sh, cm->localKeyNumber);
GWEN_SigHead_SetKeyVersion(sh, cm->localKeyVersion);
ti=GWEN_CurrentTime();
GWEN_SigHead_SetDateTime(sh, ti);
GWEN_Time_free(ti);
GWEN_SigHead_SetSignatureProfile(sh, cm->signatureProfile);
GWEN_SigHead_SetSignatureNumber(sh, 1);
/* write signature head to buffer */
shPos=GWEN_Buffer_GetPos(dbuf);
rv=GWEN_SigHead_toBuffer(sh, dbuf, GWEN_CRYPTMGR_TLV_SIGHEAD);
GWEN_SigHead_free(sh);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
return rv;
}
/* write data to buffer */
if (pData && lData)
GWEN_Tag16_DirectlyToBuffer(GWEN_CRYPTMGR_TLV_SIGDATA,
(const char*)pData,
lData,
dbuf);
/* sign data: signature head TLV + data TLV */
sigbuf=GWEN_Buffer_new(0, 300, 0, 1);
p=((uint8_t*)GWEN_Buffer_GetStart(dbuf))+shPos;
l=GWEN_Buffer_GetPos(dbuf)-shPos;
rv=GWEN_CryptMgr_SignData(cm, p, l, sigbuf);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(sigbuf);
return rv;
}
/* create signature tail */
st=GWEN_SigTail_new();
GWEN_SigTail_SetSignature(st,
(const uint8_t*)GWEN_Buffer_GetStart(sigbuf),
GWEN_Buffer_GetUsedBytes(sigbuf));
GWEN_Buffer_free(sigbuf);
GWEN_SigTail_SetSignatureNumber(st, 1);
/* write signature tail */
rv=GWEN_SigTail_toBuffer(st, dbuf, GWEN_CRYPTMGR_TLV_SIGTAIL);
GWEN_SigTail_free(st);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
return rv;
}
/* write complete size */
l=GWEN_Buffer_GetPos(dbuf)-pos-2;
p=(uint8_t*)GWEN_Buffer_GetStart(dbuf)+pos;
*(p++)=l & 0xff;
*p=(l>>8) & 0xff;
return 0;
}
示例9: GWEN_CryptMgr_Encrypt
int GWEN_CryptMgr_Encrypt(GWEN_CRYPTMGR *cm, const uint8_t *pData, uint32_t lData, GWEN_BUFFER *dbuf) {
GWEN_CRYPTHEAD *ch;
uint32_t pos;
uint8_t *p;
uint32_t l;
int rv;
GWEN_BUFFER *cryptbuf;
GWEN_BUFFER *tbuf;
GWEN_CRYPT_KEY *mkey;
assert(cm);
/* generate a message key */
mkey=GWEN_Crypt_KeyBlowFish_Generate(GWEN_Crypt_CryptMode_Cbc, 256/8, 2);
if (mkey==NULL) {
DBG_ERROR(GWEN_LOGDOMAIN, "Unable to generate BLOWFISH key");
return GWEN_ERROR_GENERIC;
}
GWEN_Buffer_AppendByte(dbuf, GWEN_CRYPTMGR_TLV_ENCRYPTEDOBJECT);
pos=GWEN_Buffer_GetPos(dbuf);
GWEN_Buffer_AppendByte(dbuf, 0);
GWEN_Buffer_AppendByte(dbuf, 0);
/* prepare signature head */
ch=GWEN_CryptHead_new();
GWEN_CryptHead_SetKeyName(ch, cm->peerKeyName);
GWEN_CryptHead_SetKeyNumber(ch, cm->peerKeyNumber);
GWEN_CryptHead_SetKeyVersion(ch, cm->peerKeyVersion);
GWEN_CryptHead_SetCryptProfile(ch, cm->signatureProfile);
/* encrypt key */
cryptbuf=GWEN_Buffer_new(0, lData+256, 0, 1);
rv=GWEN_CryptMgr_EncryptKey(cm,
GWEN_Crypt_KeyBlowFish_GetKeyDataPtr(mkey),
GWEN_Crypt_KeyBlowFish_GetKeyDataLen(mkey),
cryptbuf);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(cryptbuf);
GWEN_CryptHead_free(ch);
GWEN_Crypt_Key_free(mkey);
return rv;
}
GWEN_CryptHead_SetKey(ch,
(const uint8_t*)GWEN_Buffer_GetStart(cryptbuf),
GWEN_Buffer_GetUsedBytes(cryptbuf));
GWEN_Buffer_free(cryptbuf);
/* write crypt head to buffer */
rv=GWEN_CryptHead_toBuffer(ch, dbuf, GWEN_CRYPTMGR_TLV_CRYPTHEAD);
GWEN_CryptHead_free(ch);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_Crypt_Key_free(mkey);
return rv;
}
/* padd plain text data */
tbuf=GWEN_Buffer_new(0, lData+256, 0, 1);
GWEN_Buffer_AppendBytes(tbuf, (const char*)pData, lData);
GWEN_Padd_PaddWithAnsiX9_23(tbuf);
/* encrypt with message key */
cryptbuf=GWEN_Buffer_new(0, lData+256, 0, 1);
l=GWEN_Buffer_GetMaxUnsegmentedWrite(cryptbuf);
rv=GWEN_Crypt_Key_Encipher(mkey,
(const uint8_t*)GWEN_Buffer_GetStart(tbuf),
GWEN_Buffer_GetUsedBytes(tbuf),
(uint8_t*)GWEN_Buffer_GetStart(cryptbuf),
&l);
GWEN_Buffer_free(tbuf);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(cryptbuf);
GWEN_Crypt_Key_free(mkey);
return rv;
}
GWEN_Buffer_IncrementPos(cryptbuf, l);
GWEN_Buffer_AdjustUsedBytes(cryptbuf);
/* write encrypted data */
GWEN_Tag16_DirectlyToBuffer(GWEN_CRYPTMGR_TLV_CRYPTDATA,
GWEN_Buffer_GetStart(cryptbuf),
GWEN_Buffer_GetUsedBytes(cryptbuf),
dbuf);
GWEN_Buffer_free(cryptbuf);
GWEN_Crypt_Key_free(mkey);
/* write complete size */
l=GWEN_Buffer_GetPos(dbuf)-pos-2;
p=(uint8_t*)GWEN_Buffer_GetStart(dbuf)+pos;
*(p++)=l & 0xff;
*p=(l>>8) & 0xff;
return 0;
}
示例10: LC_Client_InitCommon
int LC_Client_InitCommon() {
if (lc_client__initcounter==0) {
int rv;
GWEN_STRINGLIST *paths;
rv=GWEN_Init();
if (rv) {
DBG_ERROR_ERR(LC_LOGDOMAIN, rv);
return rv;
}
if (!GWEN_Logger_IsOpen(LC_LOGDOMAIN)) {
const char *s;
/* only set our logger if it not already has been */
GWEN_Logger_Open(LC_LOGDOMAIN, "chipcard3-client", 0,
GWEN_LoggerType_Console,
GWEN_LoggerFacility_User);
GWEN_Logger_SetLevel(LC_LOGDOMAIN, GWEN_LoggerLevel_Warning);
s=getenv("LC_LOGLEVEL");
if (s) {
GWEN_LOGGER_LEVEL ll;
ll=GWEN_Logger_Name2Level(s);
if (ll!=GWEN_LoggerLevel_Unknown) {
GWEN_Logger_SetLevel(LC_LOGDOMAIN, ll);
DBG_WARN(LC_LOGDOMAIN,
"Overriding loglevel for Libchipcard-Client with \"%s\"",
s);
}
else {
DBG_ERROR(0, "Unknown loglevel \"%s\"", s);
}
}
else {
GWEN_Logger_SetLevel(LC_LOGDOMAIN, GWEN_LoggerLevel_Warning);
}
}
/* define sysconf path */
GWEN_PathManager_DefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR);
#if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
/* add folder relative to EXE */
GWEN_PathManager_AddRelPath(LCC_PM_LIBNAME,
LCC_PM_LIBNAME,
LCC_PM_SYSCONFDIR,
LC_CLIENT_CONFIG_DIR,
GWEN_PathManager_RelModeExe);
#else
/* add absolute folder */
GWEN_PathManager_AddPath(LCC_PM_LIBNAME,
LCC_PM_LIBNAME,
LCC_PM_SYSCONFDIR,
LC_CLIENT_CONFIG_DIR);
#endif
/* define data path */
GWEN_PathManager_DefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR);
#if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
/* add folder relative to EXE */
GWEN_PathManager_AddRelPath(LCC_PM_LIBNAME,
LCC_PM_LIBNAME,
LCC_PM_DATADIR,
LC_CLIENT_XML_DIR,
GWEN_PathManager_RelModeExe);
#else
/* add absolute folder */
GWEN_PathManager_AddPath(LCC_PM_LIBNAME,
LCC_PM_LIBNAME,
LCC_PM_DATADIR,
LC_CLIENT_XML_DIR);
#endif
/* load configuration file */
#if 0
paths=GWEN_PathManager_GetPaths(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR);
if (paths) {
GWEN_DB_NODE *db;
GWEN_BUFFER *fbuf;
db=GWEN_DB_Group_new("config");
fbuf=GWEN_Buffer_new(0, 256, 0, 1);
rv=GWEN_Directory_FindFileInPaths(paths,
LC_CLIENT_CONFIG_FILE,
fbuf);
if (rv) {
DBG_INFO(LC_LOGDOMAIN,
"Trying config file with suffix \".default\"");
rv=GWEN_Directory_FindFileInPaths(paths,
LC_CLIENT_CONFIG_FILE".default",
fbuf);
}
GWEN_StringList_free(paths);
if (rv) {
DBG_WARN(LC_LOGDOMAIN,
"No configuration file found, using defaults");
}
else {
DBG_INFO(LC_LOGDOMAIN,
//.........这里部分代码省略.........
示例11: listBal
//.........这里部分代码省略.........
"outFile", /* name */
0, /* minnum */
1, /* maxnum */
"o", /* short option */
"outfile", /* long option */
"Specify the file to store the data in", /* short description */
"Specify the file to store the data in" /* long description */
},
{
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
GWEN_ArgsType_Int, /* type */
"help", /* name */
0, /* minnum */
0, /* maxnum */
"h", /* short option */
"help", /* long option */
"Show this help screen", /* short description */
"Show this help screen" /* long description */
}
};
db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
rv=GWEN_Args_Check(argc, argv, 1,
0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/,
args,
db);
if (rv==GWEN_ARGS_RESULT_ERROR) {
fprintf(stderr, "ERROR: Could not parse arguments\n");
return 1;
}
else if (rv==GWEN_ARGS_RESULT_HELP) {
GWEN_BUFFER *ubuf;
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
fprintf(stderr, "ERROR: Could not create help string\n");
return 1;
}
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
GWEN_Buffer_free(ubuf);
return 0;
}
bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0);
bankName=GWEN_DB_GetCharValue(db, "bankName", 0, 0);
accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0);
accountName=GWEN_DB_GetCharValue(db, "accountName", 0, 0);
rv=AB_Banking_Init(ab);
if (rv) {
DBG_ERROR(0, "Error on init (%d)", rv);
return 2;
}
ctxFile=GWEN_DB_GetCharValue(db, "ctxfile", 0, 0);
rv=readContext(ctxFile, &ctx, 1);
if (rv<0) {
DBG_ERROR(0, "Error reading context (%d)", rv);
return 4;
}
/* open output stream */
outFile=GWEN_DB_GetCharValue(db, "outFile", 0, 0);
if (outFile==0)
f=stdout;
else
示例12: LC_Client_ConnectCard
LC_CLIENT_RESULT LC_Client_ConnectCard(LC_CLIENT *cl,
const char *rname,
LC_CARD **pCard) {
LC_CLIENT_RESULT res;
LONG rv;
SCARDHANDLE scardHandle;
DWORD dwActiveProtocol;
LC_CARD *card;
char readerName[256];
DWORD pcchReaderLen;
BYTE pbAtr[MAX_ATR_SIZE];
DWORD dwAtrLen;
DWORD dwState;
GWEN_BUFFER *bDriverType;
GWEN_BUFFER *bReaderType;
uint32_t rflags=0;
assert(cl);
DBG_INFO(LC_LOGDOMAIN, "Trying protocol T1");
rv=SCardConnect(cl->scardContext,
rname,
SCARD_SHARE_EXCLUSIVE,
SCARD_PROTOCOL_T1,
&scardHandle,
&dwActiveProtocol);
if (rv!=SCARD_S_SUCCESS) {
DBG_INFO(LC_LOGDOMAIN, "Trying protocol T0");
rv=SCardConnect(cl->scardContext,
rname,
SCARD_SHARE_EXCLUSIVE,
SCARD_PROTOCOL_T0,
&scardHandle,
&dwActiveProtocol);
}
#ifdef SCARD_PROTOCOL_RAW
if (rv!=SCARD_S_SUCCESS) {
DBG_INFO(LC_LOGDOMAIN, "Trying protocol RAW");
rv=SCardConnect(cl->scardContext,
rname,
SCARD_SHARE_EXCLUSIVE,
SCARD_PROTOCOL_RAW,
&scardHandle,
&dwActiveProtocol);
}
#endif
if (rv!=SCARD_S_SUCCESS) {
DBG_INFO(LC_LOGDOMAIN,
"SCardConnect: %04lx", (long unsigned int) rv);
return LC_Client_ResultIoError;
}
/* get protocol and ATR */
DBG_INFO(LC_LOGDOMAIN, "Reading protocol and ATR");
pcchReaderLen=sizeof(readerName);
dwAtrLen=sizeof(pbAtr);
rv=SCardStatus(scardHandle,
readerName,
&pcchReaderLen,
&dwState,
&dwActiveProtocol,
pbAtr,
&dwAtrLen);
if (rv!=SCARD_S_SUCCESS) {
DBG_ERROR(LC_LOGDOMAIN,
"SCardStatus: %04lx", (long unsigned int) rv);
SCardDisconnect(scardHandle, SCARD_UNPOWER_CARD);
return LC_Client_ResultIoError;
}
/* derive reader and driver type from name */
DBG_INFO(LC_LOGDOMAIN, "Getting reader- and driver type");
bDriverType=GWEN_Buffer_new(0, 32, 0, 1);
bReaderType=GWEN_Buffer_new(0, 32, 0, 1);
res=LC_Client_GetReaderAndDriverType(cl,
readerName,
bDriverType,
bReaderType,
&rflags);
if (res) {
DBG_INFO(LC_LOGDOMAIN,
"Unable to determine type of reader [%s] (%d), assuming generic pcsc",
readerName,
res);
GWEN_Buffer_AppendString(bDriverType, "generic_pcsc");
GWEN_Buffer_AppendString(bReaderType, "generic_pcsc");
}
/* create new card */
card=LC_Card_new(cl,
scardHandle,
readerName,
dwActiveProtocol,
"processor", /* cardType */
rflags,
dwAtrLen?pbAtr:0, /* atrBuf */
dwAtrLen); /* atrLen */
//.........这里部分代码省略.........
示例13: EBC_Provider_SignMessage_X001
static int EBC_Provider_SignMessage_X001(AB_PROVIDER *pro,
EB_MSG *msg,
AB_USER *u,
xmlNodePtr node) {
EBC_PROVIDER *dp;
int rv;
GWEN_CRYPT_TOKEN *ct;
const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
const GWEN_CRYPT_TOKEN_KEYINFO *ki;
uint32_t keyId;
GWEN_BUFFER *hbuf;
GWEN_BUFFER *bbuf;
xmlNodePtr nodeX = NULL;
xmlNodePtr nodeXX = NULL;
xmlNodePtr nodeXXX = NULL;
xmlNodePtr nodeXXXX = NULL;
xmlNsPtr ns;
assert(pro);
dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
assert(dp);
/* get crypt token and context */
rv=EBC_Provider_MountToken(pro, u, &ct, &ctx);
if (rv<0) {
DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
return rv;
}
/* get key id */
keyId=GWEN_Crypt_Token_Context_GetAuthSignKeyId(ctx);
ki=GWEN_Crypt_Token_GetKeyInfo(ct,
keyId,
0xffffffff,
0);
if (ki==NULL) {
DBG_INFO(AQEBICS_LOGDOMAIN,
"Keyinfo %04x not found on crypt token [%s:%s]",
keyId,
GWEN_Crypt_Token_GetTypeName(ct),
GWEN_Crypt_Token_GetTokenName(ct));
GWEN_Crypt_Token_Close(ct, 0, 0);
return GWEN_ERROR_NOT_FOUND;
}
/* prepare signature nodes */
ns=xmlSearchNs(EB_Msg_GetDoc(msg), node, BAD_CAST "ds");
assert(ns);
/* build hash */
bbuf=GWEN_Buffer_new(0, 256, 0, 1);
rv=EB_Msg_BuildHashSha1(msg, bbuf);
if (rv) {
DBG_ERROR(AQEBICS_LOGDOMAIN, "Could not build hash");
GWEN_Buffer_free(bbuf);
return rv;
}
/* base64 encode */
hbuf=GWEN_Buffer_new(0, 256, 0, 1);
rv=GWEN_Base64_Encode((const uint8_t*)GWEN_Buffer_GetStart(bbuf),
GWEN_Buffer_GetUsedBytes(bbuf),
hbuf, 0);
if (rv<0) {
DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(hbuf);
GWEN_Buffer_free(bbuf);
return rv;
}
GWEN_Buffer_free(bbuf);
/* create signature node */
nodeX=xmlNewChild(node, ns, BAD_CAST "SignedInfo", NULL);
nodeXX=xmlNewChild(nodeX, ns, BAD_CAST "CanonicalizationMethod", NULL);
xmlNewProp(nodeXX,
BAD_CAST "Algorithm",
BAD_CAST "http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
nodeXX=xmlNewChild(nodeX, ns, BAD_CAST "SignatureMethod", NULL);
xmlNewProp(nodeXX,
BAD_CAST "Algorithm",
BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
nodeXX=xmlNewChild(nodeX, ns, BAD_CAST "Reference", NULL);
xmlNewProp(nodeXX,
BAD_CAST "URI",
BAD_CAST "#xpointer(//*[@authenticate='true'])");
nodeXXX=xmlNewChild(nodeXX, ns, BAD_CAST "Transforms", NULL);
nodeXXXX=xmlNewChild(nodeXXX, ns, BAD_CAST "Transform", NULL);
xmlNewProp(nodeXXXX,
BAD_CAST "Algorithm",
BAD_CAST "http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
nodeXXX=xmlNewChild(nodeXX, ns, BAD_CAST "DigestMethod", NULL);
xmlNewProp(nodeXXX,
BAD_CAST "Algorithm",
BAD_CAST "http://www.w3.org/2000/09/xmldsig#sha1");
/* store hash value */
xmlNewTextChild(nodeXX, ns,
BAD_CAST "DigestValue",
BAD_CAST GWEN_Buffer_GetStart(hbuf));
//.........这里部分代码省略.........
示例14: AHB_DTAUS__Export
int AHB_DTAUS__Export(GWEN_DBIO *dbio,
GWEN_SYNCIO *sio,
GWEN_DB_NODE *data,
GWEN_DB_NODE *cfg,
uint32_t flags){
AB_VALUE *sumEUR;
AB_VALUE *sumDEM;
AB_VALUE *sumBankCodes;
AB_VALUE *sumAccountIds;
unsigned int cSets;
GWEN_BUFFER *dst;
GWEN_DB_NODE *gr;
int isDebitNote;
//int isEuro;
const uint8_t *p;
uint32_t size;
int rv;
isDebitNote=(strcasecmp(GWEN_DB_GetCharValue(cfg, "type", 0, "transfer"),
"debitnote")==0);
//isEuro=(strcasecmp(GWEN_DB_GetCharValue(cfg, "currency", 0, "EUR"),
// "EUR")==0);
cSets=0;
sumEUR=AB_Value_new();
sumDEM=AB_Value_new();
sumBankCodes=AB_Value_new();
sumAccountIds=AB_Value_new();
dst=GWEN_Buffer_new(0, 1024, 0, 1);
GWEN_Buffer_SetHardLimit(dst, AHB_DTAUS_HARDLIMIT);
/* create A set */
if (AHB_DTAUS__CreateSetA(dst, cfg)) {
DBG_INFO(AQBANKING_LOGDOMAIN, "Error creating A set");
GWEN_Buffer_free(dst);
AB_Value_free(sumAccountIds);
AB_Value_free(sumBankCodes);
AB_Value_free(sumDEM);
AB_Value_free(sumEUR);
return -1;
}
/* create C sets */
gr=GWEN_DB_GetFirstGroup(data);
while(gr) {
const char *gn;
gn=GWEN_DB_GroupName(gr);
if ((isDebitNote && strcasecmp(gn, "debitnote")==0) ||
(!isDebitNote &&
(strcasecmp(gn, "transfer")==0 ||
strcasecmp(gn, "transaction")==0))){
if (AHB_DTAUS__CreateSetC(dst, cfg, gr,
sumEUR, sumDEM,
sumBankCodes, sumAccountIds)) {
DBG_ERROR(AQBANKING_LOGDOMAIN, "Error creating C set from this data:");
GWEN_DB_Dump(gr, 2);
GWEN_Buffer_free(dst);
AB_Value_free(sumAccountIds);
AB_Value_free(sumBankCodes);
AB_Value_free(sumDEM);
AB_Value_free(sumEUR);
return -1;
}
cSets++;
} /* if group matches */
else {
DBG_ERROR(AQBANKING_LOGDOMAIN, "Ignoring group [%s]",
GWEN_DB_GroupName(gr));
}
gr=GWEN_DB_GetNextGroup(gr);
} /* while */
/* create E set */
if (AHB_DTAUS__CreateSetE(dst, cfg, cSets,
sumEUR, sumDEM,
sumBankCodes, sumAccountIds)) {
DBG_INFO(AQBANKING_LOGDOMAIN, "Error creating E set");
GWEN_Buffer_free(dst);
AB_Value_free(sumAccountIds);
AB_Value_free(sumBankCodes);
AB_Value_free(sumDEM);
AB_Value_free(sumEUR);
return -1;
}
AB_Value_free(sumAccountIds);
AB_Value_free(sumBankCodes);
AB_Value_free(sumDEM);
AB_Value_free(sumEUR);
/* DTAUS finished, write it */
p=(const uint8_t*)GWEN_Buffer_GetStart(dst);
size=GWEN_Buffer_GetUsedBytes(dst);
rv=GWEN_SyncIo_WriteForced(sio, p, size);
if (rv<0) {
DBG_ERROR(AQBANKING_LOGDOMAIN, "Broken pipe");
GWEN_Buffer_free(dst);
return GWEN_ERROR_IO;
}
//.........这里部分代码省略.........
示例15: write_h_elem_c
int write_h_elem_c(ARGUMENTS *args, GWEN_XMLNODE *node,
GWEN_SYNCIO *sio)
{
const char *name;
const char *typ;
const char *mode;
GWEN_XMLNODE *tnode;
const char *tmode;
int err;
int isPtr;
name=GWEN_XMLNode_GetProperty(node, "name", 0);
if (!name) {
DBG_ERROR(0, "No name for element");
return -1;
}
typ=GWEN_XMLNode_GetProperty(node, "type", 0);
if (!typ) {
DBG_ERROR(0, "No type for element");
return -1;
}
mode=GWEN_XMLNode_GetProperty(node, "mode", "single");
tnode=get_typedef(node, typ);
if (tnode)
tmode=GWEN_XMLNode_GetProperty(tnode, "mode", "single");
else
tmode=mode;
isPtr=atoi(get_property(node, "ptr", "0"));
err=GWEN_SyncIo_WriteString(sio, " ");
if (err) {
DBG_ERROR_ERR(0, err);
return -1;
}
if (strcasecmp(tmode, "enum")!=0)
GWEN_SyncIo_WriteString(sio, typ);
else {
GWEN_BUFFER *tid;
const char *s;
tid=GWEN_Buffer_new(0, 64, 0, 1);
s=get_struct_property(node, "id", 0);
assert(s);
GWEN_Buffer_AppendString(tid, s);
GWEN_Buffer_AppendString(tid, "_");
GWEN_Buffer_AppendString(tid, typ);
GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(tid));
GWEN_Buffer_free(tid);
}
GWEN_SyncIo_WriteString(sio, " ");
if (isPtr) {
GWEN_SyncIo_WriteString(sio, "*");
}
GWEN_SyncIo_WriteChar(sio, tolower(*name));
GWEN_SyncIo_WriteString(sio, name+1);
GWEN_SyncIo_WriteLine(sio, ";");
return 0;
}