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)"); GWEN_StringList_free(purposeList); return -1; } extSets++; } /* for */ /* check number of extension sets */ if (extSets>15) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many extension sets (%d)", extSets); GWEN_StringList_free(purposeList); return -1; } /* ______________________________________________________________________ * actually write C set */ /* field 1, 2: record header */ snprintf(buffer, sizeof(buffer), "%04d", 187+(extSets*29)); GWEN_Buffer_AppendString(dst, buffer); GWEN_Buffer_AppendByte(dst, 'C'); /* field 3: acting bank code */ if (AHB_DTAUS__AddNum(dst, 8, GWEN_DB_GetCharValue(cfg, "bankCode", 0, ""))) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 4: destination bank code */ p=GWEN_DB_GetCharValue(xa, "remoteBankCode", 0, 0); if (p) { val=AB_Value_fromString(p); if (val==NULL) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad bank code"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumBankCodes, val); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 8, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer bank code missing"); GWEN_StringList_free(purposeList); return -1; } /* field 5: destination account id */ p=GWEN_DB_GetCharValue(xa, "remoteAccountNumber", 0, 0); if (p) { val=AB_Value_fromString(p); if (val==NULL) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad account id"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumAccountIds, val); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 10, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer account id missing"); GWEN_StringList_free(purposeList); return -1; } /* field 6: internal customer number (0s for now) */ for (i=0; i<13; i++) GWEN_Buffer_AppendByte(dst, '0'); /* field 7a: text key */ snprintf(buffer, sizeof(buffer), "%02d", GWEN_DB_GetIntValue(xa, "textkey", 0, isDebitNote?5:51)); if (AHB_DTAUS__AddNum(dst, 2, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 7b: text key extension */ snprintf(buffer, sizeof(buffer), "%03d", GWEN_DB_GetIntValue(xa, "textkeyext", 0, 0)); if (AHB_DTAUS__AddNum(dst, 3, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 8: bank internal field */ GWEN_Buffer_AppendByte(dst, ' '); /* field 9: value in DEM */ if (!isEuro) { val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0")); if (val==NULL || AB_Value_IsZero(val)) { AB_Value_free(val); DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad DEM value:"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumDEM, val); snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 11, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { if (AHB_DTAUS__AddNum(dst, 11, "0")) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } /* field 10: local bank code */ p=GWEN_DB_GetCharValue(xa, "localbankCode", 0, 0); if (!p) p=GWEN_DB_GetCharValue(cfg, "bankCode", 0, 0); if (!p) { DBG_ERROR(AQBANKING_LOGDOMAIN, "No local bank code"); GWEN_StringList_free(purposeList); return -1; } if (AHB_DTAUS__AddNum(dst, 8, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 11: local account id */ p=GWEN_DB_GetCharValue(xa, "localAccountNumber", 0, 0); if (!p) GWEN_DB_GetCharValue(cfg, "accountId", 0, 0); if (!p) { DBG_ERROR(AQBANKING_LOGDOMAIN, "No local account number"); GWEN_StringList_free(purposeList); return -1; } if (AHB_DTAUS__AddNum(dst, 10, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 12: value in EUR */ if (isEuro) { val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0")); if (val==NULL || AB_Value_IsZero(val)) { AB_Value_free(val); DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad EUR value:"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumEUR, val); snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 11, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { if (AHB_DTAUS__AddNum(dst, 11, "0")) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } /* field 13: blanks */ for (i=0; i<3; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 14a: peer name */ if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "remoteName", 0, ""))) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 14b: blanks */ for (i=0; i<8; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 15: name */ if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "localname", 0, ""))) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 16: purpose */ p=GWEN_StringList_FirstString(purposeList); if (p==NULL) p=""; if (AHB_DTAUS__AddWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 17a: currency */ if (isEuro) GWEN_Buffer_AppendByte(dst, '1'); else GWEN_Buffer_AppendByte(dst, ' '); /* field 17b: blanks */ for (i=0; i<2; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 18: number of extension sets */ snprintf(buffer, sizeof(buffer), "%02d", extSets); if (AHB_DTAUS__AddNum(dst, 2, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } if (extSets) { unsigned int writtenExtSets=0; /* now append extension sets */ /* add peer name lines */ for (i=1; i<2; i++) { /* max: 1 extset */ unsigned int j; p=GWEN_DB_GetCharValue(xa, "remoteName", i, 0); if (!p) break; /* append extension set */ GWEN_Buffer_AppendString(dst, "01"); if (AHB_DTAUS__AddWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } writtenExtSets++; if (writtenExtSets==2) /* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */ for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' '); else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0) /* "C 3-5.Satzabschnitt" complete, align to 128 bytes */ for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' '); } /* for */ /* add purpose lines */ for (i=1; i<GWEN_StringList_Count(purposeList); i++) { unsigned int j; p=GWEN_StringList_StringAt(purposeList, i); if (!p) break; /* append extension set */ GWEN_Buffer_AppendString(dst, "02"); /* strings in the list are already in DTA charset */ if (AHB_DTAUS__AddDtaWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } writtenExtSets++; if (writtenExtSets==2) /* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */ for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' '); else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0) /* "C 3-5.Satzabschnitt" complete, align to 128 bytes */ for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' '); } /* for */ /* add name lines */ for (i=1; i<2; i++) { /* max: 1 extset */ unsigned int j; p=GWEN_DB_GetCharValue(xa, "localname", i, 0); if (!p) break; /* append extension set */ GWEN_Buffer_AppendString(dst, "03"); if (AHB_DTAUS__AddWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } writtenExtSets++; if (writtenExtSets==2) /* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */ for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' '); else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0) /* "C 3-5.Satzabschnitt" complete, align to 128 bytes */ for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' '); } /* for */ } i=((GWEN_Buffer_GetUsedBytes(dst)+127) & ~127)-GWEN_Buffer_GetUsedBytes(dst); while(i--) GWEN_Buffer_AppendByte(dst, ' '); GWEN_StringList_free(purposeList); return 0; }
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; }
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; }
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; }
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) { DBG_INFO(AQHBCI_LOGDOMAIN, "Could not create CryptData (%d)", rv); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return rv; } /* replace existing buffer by encrypted one */ GWEN_Buffer_free(hmsg->buffer); hmsg->buffer=hbuf; GWEN_DB_Group_free(cfg); return 0; }
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; }
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, "*"); ul=AB_Banking_FindUsers(ab, AH_PROVIDER_NAME, "de", bankId, userId, customerId); if (ul) { if (AB_User_List2_GetSize(ul)!=1) { DBG_ERROR(0, "Ambiguous customer specification"); return 3; } else { AB_USER_LIST2_ITERATOR *uit; uit=AB_User_List2_First(ul); assert(uit); u=AB_User_List2Iterator_Data(uit); AB_User_List2Iterator_free(uit); } AB_User_List2_free(ul); } if (!u) { DBG_ERROR(0, "No matching customer"); return 3; } else { const AH_TAN_METHOD_LIST *tl; tl=AH_User_GetTanMethodDescriptions(u); if (tl) { const AH_TAN_METHOD *tm; tm=AH_TanMethod_List_First(tl); fprintf(stdout, "TAN Methods\n"); while(tm) { const char *mid; const char *mname; int combinedVersion; combinedVersion=AH_TanMethod_GetFunction(tm)+(AH_TanMethod_GetGvVersion(tm)*1000); fprintf(stdout, "- %4d (F%3d/V%1d/P%1d)", combinedVersion, AH_TanMethod_GetFunction(tm), AH_TanMethod_GetGvVersion(tm), AH_TanMethod_GetProcess(tm)); mid=AH_TanMethod_GetMethodId(tm); mname=AH_TanMethod_GetMethodName(tm); if (mid && mname) { fprintf(stdout, ": %s (%s)", mid, mname); } else if (mid && !mname) { fprintf(stdout, ": %s", mid); } else if (!mid && mname) { fprintf(stdout, ": %s", mname); } if (AH_User_HasTanMethod(u, AH_TanMethod_GetFunction(tm))) { if (AH_User_GetSelectedTanMethod(u)==combinedVersion) fprintf(stdout, " [available and selected]"); else fprintf(stdout, " [available]"); } else fprintf(stdout, " [not available]"); fprintf(stdout, "\n"); tm=AH_TanMethod_List_Next(tm); } } } rv=AB_Banking_OnlineFini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
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; }
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; }
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, "Reading configuration file \"%s\"", GWEN_Buffer_GetStart(fbuf)); rv=GWEN_DB_ReadFile(db, GWEN_Buffer_GetStart(fbuf), GWEN_DB_FLAGS_DEFAULT | GWEN_PATH_FLAGS_CREATE_GROUP); if (rv<0) { DBG_ERROR(LC_LOGDOMAIN, "Error in configuration file \"%s\" (%d)", GWEN_Buffer_GetStart(fbuf), rv); GWEN_Buffer_free(fbuf); /* undo all init stuff so far */ GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR); GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR); return rv; } } GWEN_Buffer_free(fbuf); lc_client__config=db; } else { DBG_ERROR(LC_LOGDOMAIN, "Internal error: Paths not found"); return GWEN_ERROR_INTERNAL; } #else lc_client__config=GWEN_DB_Group_new("config"); #endif /* load XML files */ paths=GWEN_PathManager_GetPaths(LCC_PM_LIBNAME, LCC_PM_DATADIR); if (paths) { GWEN_XMLNODE *n; GWEN_DB_NODE *db; GWEN_BUFFER *fbuf; uint32_t bpos; fbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=GWEN_Directory_FindPathForFile(paths, "cards/README", fbuf); GWEN_StringList_free(paths); if (rv) { DBG_ERROR(LC_LOGDOMAIN, "Data files not found (%d)", rv); /* undo all init stuff so far */ GWEN_Buffer_free(fbuf); GWEN_DB_Group_free(lc_client__config); lc_client__config=NULL; GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR); GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR); return rv; } /* load card files */ n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "cards"); if (LC_Client_ReadXmlFiles(n, GWEN_Buffer_GetStart(fbuf), "cards", "card")) { DBG_ERROR(LC_LOGDOMAIN, "Could not read card files"); GWEN_XMLNode_free(n); /* undo all init stuff so far */ GWEN_Buffer_free(fbuf); GWEN_DB_Group_free(lc_client__config); lc_client__config=NULL; GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR); GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR); return GWEN_ERROR_GENERIC; } lc_client__card_nodes=n; /* load app files */ n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "apps"); if (LC_Client_ReadXmlFiles(n, GWEN_Buffer_GetStart(fbuf), "apps", "app")) { DBG_ERROR(LC_LOGDOMAIN, "Could not read app files"); GWEN_XMLNode_free(n); /* undo all init stuff so far */ GWEN_XMLNode_free(lc_client__card_nodes); lc_client__card_nodes=NULL; GWEN_Buffer_free(fbuf); GWEN_DB_Group_free(lc_client__config); lc_client__config=NULL; GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR); GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR); return GWEN_ERROR_GENERIC; } lc_client__app_nodes=n; /*GWEN_XMLNode_WriteFile(n, "/tmp/apps", GWEN_XML_FLAGS_DEFAULT);*/ /* load driver files (if any) */ bpos=GWEN_Buffer_GetPos(fbuf); GWEN_Buffer_AppendString(fbuf, DIRSEP "drivers"); db=GWEN_DB_Group_new("drivers"); rv=LC_DriverInfo_ReadDrivers(GWEN_Buffer_GetStart(fbuf), db, 0, 1); if (rv) { DBG_INFO(LC_LOGDOMAIN, "here (%d)", rv); GWEN_DB_Group_free(db); /* undo all init stuff so far */ GWEN_XMLNode_free(lc_client__app_nodes); lc_client__app_nodes=NULL; GWEN_XMLNode_free(lc_client__card_nodes); lc_client__card_nodes=NULL; GWEN_Buffer_free(fbuf); GWEN_DB_Group_free(lc_client__config); lc_client__config=NULL; GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR); GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR); return rv; } lc_client__driver_db=db; GWEN_Buffer_Crop(fbuf, 0, bpos); /* insert more loading here */ GWEN_Buffer_free(fbuf); } else { DBG_ERROR(LC_LOGDOMAIN, "No data files found."); /* undo all init stuff so far */ GWEN_DB_Group_free(lc_client__config); lc_client__config=NULL; GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_DATADIR); GWEN_PathManager_UndefinePath(LCC_PM_LIBNAME, LCC_PM_SYSCONFDIR); return GWEN_ERROR_GENERIC; } } lc_client__initcounter++; return 0; }
static int listBal(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; int rv; const char *ctxFile; const char *outFile; AB_IMEXPORTER_CONTEXT *ctx=0; AB_IMEXPORTER_ACCOUNTINFO *iea=0; const char *bankId; const char *accountId; const char *bankName; const char *accountName; FILE *f; 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 */ "accountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "a", /* short option */ "account", /* long option */ "Specify the account number", /* short description */ "Specify the account number" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankName", /* name */ 0, /* minnum */ 1, /* maxnum */ "N", /* short option */ "bankname", /* long option */ "Specify the bank name", /* short description */ "Specify the bank name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountName", /* name */ 0, /* minnum */ 1, /* maxnum */ "n", /* short option */ "accountname", /* long option */ "Specify the account name", /* short description */ "Specify the account name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "ctxFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "c", /* short option */ "ctxfile", /* long option */ "Specify the file to store the context in", /* short description */ "Specify the file to store the context in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "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 f=fopen(outFile, "w+"); if (f==0) { DBG_ERROR(0, "Error selecting output file: %s", strerror(errno)); return 4; } iea=AB_ImExporterContext_GetFirstAccountInfo(ctx); while(iea) { int matches=1; const char *s; if (matches && bankId) { s=AB_ImExporterAccountInfo_GetBankCode(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankId, 0)) matches=0; } if (matches && bankName) { s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s || !*s) s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankName, 0)) matches=0; } if (matches && accountId) { s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountId, 0)) matches=0; } if (matches && accountName) { s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s || !*s) s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountName, 0)) matches=0; } if (matches) { AB_ACCOUNT_STATUS *ast; ast=_getLastAccountStatus(iea); if (ast) { const GWEN_TIME *ti; const char *s; fprintf(f, "Account\t"); s=AB_ImExporterAccountInfo_GetBankCode(iea); if (!s) s=""; fprintf(f, "%s\t", s); s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (!s) s=""; fprintf(f, "%s\t", s); s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s) s=""; fprintf(f, "%s\t", s); s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s) s=""; fprintf(f, "%s\t", s); ti=AB_AccountStatus_GetTime(ast); _dumpBal(AB_AccountStatus_GetBookedBalance(ast), ti, f); _dumpBal(AB_AccountStatus_GetNotedBalance(ast), ti, f); fprintf(f, "\n"); } } /* if matches */ iea=AB_ImExporterContext_GetNextAccountInfo(ctx); } /* while */ if (outFile) { if (fclose(f)) { DBG_ERROR(0, "Error closing output file: %s", strerror(errno)); return 4; } } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
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 */ /* complete card data */ LC_Card_SetDriverType(card, GWEN_Buffer_GetStart(bDriverType)); LC_Card_SetReaderType(card, GWEN_Buffer_GetStart(bReaderType)); GWEN_Buffer_free(bReaderType); GWEN_Buffer_free(bDriverType); *pCard=card; return LC_Client_ResultOk; }
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)); GWEN_Buffer_free(hbuf); /* build hash over SignedInfo */ bbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=EB_Xml_BuildNodeHashSha1(nodeX, "#xpointer(//*)", bbuf); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(bbuf); return rv; } /* sign hash */ if (1) { GWEN_CRYPT_PADDALGO *algo; int ksize; uint32_t l; const uint8_t prefix[]={ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14}; /* add prefix to hash of SignedInfo */ hbuf=GWEN_Buffer_new(0, 256, 0, 1); ksize=GWEN_Crypt_Token_KeyInfo_GetKeySize(ki); GWEN_Buffer_AppendBytes(hbuf, (const char*)prefix, sizeof(prefix)); GWEN_Buffer_AppendBuffer(hbuf, bbuf); GWEN_Buffer_Reset(bbuf); /* select padd algo */ algo=GWEN_Crypt_PaddAlgo_new(GWEN_Crypt_PaddAlgoId_Pkcs1_1); GWEN_Crypt_PaddAlgo_SetPaddSize(algo, ksize); /* actually sign */ GWEN_Buffer_AllocRoom(bbuf, ksize+16); l=GWEN_Buffer_GetMaxUnsegmentedWrite(bbuf); rv=GWEN_Crypt_Token_Sign(ct, keyId, algo, (const uint8_t*)GWEN_Buffer_GetStart(hbuf), GWEN_Buffer_GetUsedBytes(hbuf), (uint8_t*)GWEN_Buffer_GetPosPointer(bbuf), &l, NULL, /* ignore seq counter */ 0); GWEN_Crypt_PaddAlgo_free(algo); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(bbuf); GWEN_Buffer_free(hbuf); return rv; } GWEN_Buffer_IncrementPos(bbuf, l); GWEN_Buffer_AdjustUsedBytes(bbuf); /* base 64 encode signature */ GWEN_Buffer_Reset(hbuf); 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); /* store signature */ xmlNewTextChild(node, ns, BAD_CAST "SignatureValue", BAD_CAST GWEN_Buffer_GetStart(hbuf)); GWEN_Buffer_free(hbuf); } return 0; }
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; } GWEN_Buffer_free(dst); return 0; }
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; }
int GWEN_CryptMgr_Decrypt(GWEN_CRYPTMGR *cm, const uint8_t *pData, uint32_t lData, GWEN_BUFFER *dbuf) { GWEN_TAG16 *tag; const uint8_t *p; uint32_t l; GWEN_CRYPTHEAD *ch=NULL; const uint8_t *pEncryptedData=NULL; uint32_t lEncryptedData=0; int rv; GWEN_BUFFER *tbuf; GWEN_CRYPT_KEY *mkey; assert(cm); if (lData<3) { DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes"); return GWEN_ERROR_BAD_DATA; } tag=GWEN_Tag16_fromBuffer2(pData, lData, 0); if (tag==NULL) { DBG_ERROR(GWEN_LOGDOMAIN, "Data doesn't contain a valid TLV"); return GWEN_ERROR_BAD_DATA; } if (GWEN_Tag16_GetTagType(tag)!=GWEN_CRYPTMGR_TLV_ENCRYPTEDOBJECT) { DBG_ERROR(GWEN_LOGDOMAIN, "Data does not contain an encrypted object"); GWEN_Tag16_free(tag); return GWEN_ERROR_BAD_DATA; } p=GWEN_Tag16_GetTagData(tag); l=GWEN_Tag16_GetTagLength(tag); /* read crypthead */ if (l) { GWEN_TAG16 *subtag; subtag=GWEN_Tag16_fromBuffer2(p, l, 0); if (subtag) { if (GWEN_Tag16_GetTagType(subtag)==GWEN_CRYPTMGR_TLV_CRYPTHEAD) { ch=GWEN_CryptHead_fromBuffer(GWEN_Tag16_GetTagData(subtag), GWEN_Tag16_GetTagLength(subtag)); } p+=GWEN_Tag16_GetTagSize(subtag); l-=GWEN_Tag16_GetTagSize(subtag); GWEN_Tag16_free(subtag); } } /* read encrypted data */ if (l) { GWEN_TAG16 *subtag; subtag=GWEN_Tag16_fromBuffer2(p, l, 0); if (subtag) { if (GWEN_Tag16_GetTagType(subtag)==GWEN_CRYPTMGR_TLV_CRYPTDATA) { pEncryptedData=GWEN_Tag16_GetTagData(subtag); lEncryptedData=GWEN_Tag16_GetTagLength(subtag); } p+=GWEN_Tag16_GetTagSize(subtag); l-=GWEN_Tag16_GetTagSize(subtag); GWEN_Tag16_free(subtag); } } /* check for all needed components */ if (!(ch && pEncryptedData && lEncryptedData)) { DBG_ERROR(GWEN_LOGDOMAIN, "Encrypted object is not complete"); GWEN_CryptHead_free(ch); GWEN_Tag16_free(tag); return GWEN_ERROR_BAD_DATA; } /* store or check peer key info */ if (cm->localKeyName) { const char *s; /* compare peer info with expected info */ s=GWEN_CryptHead_GetKeyName(ch); if (!(cm->localKeyName && s && (strcasecmp(cm->localKeyName, s)==0) && (cm->localKeyNumber==GWEN_CryptHead_GetKeyNumber(ch)) && (cm->localKeyVersion==GWEN_CryptHead_GetKeyVersion(ch)))) { DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected local key information in signature"); GWEN_CryptHead_free(ch); GWEN_Tag16_free(tag); return GWEN_ERROR_BAD_DATA; } } /* decrypt message key */ tbuf=GWEN_Buffer_new(0, GWEN_CryptHead_GetKeyLen(ch), 0, 1); rv=GWEN_CryptMgr_DecryptKey(cm, GWEN_CryptHead_GetKeyPtr(ch), GWEN_CryptHead_GetKeyLen(ch), tbuf); GWEN_CryptHead_free(ch); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); GWEN_Tag16_free(tag); return rv; } /* create message key */ mkey=GWEN_Crypt_KeyBlowFish_fromData(GWEN_Crypt_CryptMode_Cbc, 256/8, (const uint8_t*) GWEN_Buffer_GetStart(tbuf), GWEN_Buffer_GetUsedBytes(tbuf)); GWEN_Buffer_free(tbuf); if (mkey==NULL) { DBG_ERROR(GWEN_LOGDOMAIN, "Unable to create BLOWFISH key from received data"); GWEN_Tag16_free(tag); return GWEN_ERROR_BAD_DATA; } /* decrypt data with message key */ tbuf=GWEN_Buffer_new(0, lEncryptedData+256, 0, 1); l=GWEN_Buffer_GetMaxUnsegmentedWrite(tbuf); rv=GWEN_Crypt_Key_Decipher(mkey, pEncryptedData, lEncryptedData, (uint8_t*)GWEN_Buffer_GetStart(tbuf), &l); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); GWEN_Crypt_Key_free(mkey); GWEN_Tag16_free(tag); return rv; } GWEN_Buffer_IncrementPos(tbuf, l); GWEN_Buffer_AdjustUsedBytes(tbuf); /* unpadd data */ rv=GWEN_Padd_UnpaddWithAnsiX9_23(tbuf); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); GWEN_Crypt_Key_free(mkey); GWEN_Tag16_free(tag); return rv; } /* store data */ GWEN_Buffer_AppendBuffer(dbuf, tbuf); GWEN_Buffer_free(tbuf); GWEN_Crypt_Key_free(mkey); GWEN_Tag16_free(tag); return 0; }
int mkPinList(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; AB_PROVIDER *pro; GWEN_SYNCIO *sio; AB_USER_LIST2 *ul; int rv; const char *outFile; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "outFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "o", /* short option */ "outfile", /* long option */ "Specify the name of the output file", /* short description */ "Specify the name of the output file" /* 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; } outFile=GWEN_DB_GetCharValue(db, "outfile", 0, 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, "aqebics"); assert(pro); if (outFile==0) { sio=GWEN_SyncIo_File_fromStdout(); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FLAGS_DONTCLOSE); } else { sio=GWEN_SyncIo_File_new(outFile, GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_GREAD | GWEN_SYNCIO_FILE_FLAGS_GWRITE); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "Error opening output file: %s", strerror(errno)); return 4; } } GWEN_SyncIo_WriteLine(sio, "# This is a PIN file to be used " "with AqBanking"); GWEN_SyncIo_WriteLine(sio, "# Please insert the PINs/passwords " "for the users below"); ul=AB_Banking_FindUsers(ab, "aqebics", "*", "*", "*", "*"); if (ul) { AB_USER_LIST2_ITERATOR *uit; uit=AB_User_List2_First(ul); if (uit) { AB_USER *u; u=AB_User_List2Iterator_Data(uit); assert(u); while(u) { const char *s; GWEN_BUFFER *nbuf; int rv; GWEN_SyncIo_WriteLine(sio, ""); GWEN_SyncIo_WriteString(sio, "# User \""); s=AB_User_GetUserId(u); assert(s); GWEN_SyncIo_WriteString(sio, s); GWEN_SyncIo_WriteString(sio, "\" at \""); s=AB_User_GetBankCode(u); GWEN_SyncIo_WriteString(sio, s); GWEN_SyncIo_WriteLine(sio, "\""); nbuf=GWEN_Buffer_new(0, 256 ,0 ,1); rv=EBC_User_MkPasswdName(u, nbuf); if (rv==0) { GWEN_BUFFER *obuf; obuf=GWEN_Buffer_new(0, 256 ,0 ,1); if (GWEN_Text_EscapeToBufferTolerant(GWEN_Buffer_GetStart(nbuf), obuf)) { DBG_ERROR(0, "Error escaping name to buffer"); return 3; } GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(obuf)); GWEN_SyncIo_WriteLine(sio, " = \"\""); GWEN_Buffer_free(obuf); } GWEN_Buffer_free(nbuf); u=AB_User_List2Iterator_Next(uit); } AB_User_List2Iterator_free(uit); } AB_User_List2_free(ul); } rv=GWEN_SyncIo_Disconnect(sio); if (rv<0) { DBG_ERROR_ERR(0, rv); GWEN_SyncIo_free(sio); return 4; } GWEN_SyncIo_free(sio); rv=AB_Banking_OnlineFini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
void EBC_Provider_LogRequestResults(AB_PROVIDER *pro, EB_MSG *mRsp, GWEN_BUFFER *logbuf) { const char *tcode; const char *bcode; const char *s; GWEN_BUFFER *tbuf; tcode=EB_Msg_GetCharValue(mRsp, "header/mutable/ReturnCode", NULL); bcode=EB_Msg_GetCharValue(mRsp, "body/ReturnCode", NULL); tbuf=GWEN_Buffer_new(0, 256, 0, 1); if (tcode) { GWEN_Buffer_AppendString(tbuf, I18N("EBICS (Technical Code):")); GWEN_Buffer_AppendString(tbuf, " "); GWEN_Buffer_AppendString(tbuf, tcode); s=EBC_Provider_TechnicalCodeToString(tcode); if (s) { GWEN_Buffer_AppendString(tbuf, " ["); GWEN_Buffer_AppendString(tbuf, s); GWEN_Buffer_AppendString(tbuf, "]"); } if (logbuf) { GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendBuffer(logbuf, tbuf); } GWEN_Gui_ProgressLog(0, EBC_Provider_ResultCodeToLogLevel(pro, tcode), GWEN_Buffer_GetStart(tbuf)); DBG_INFO(AQEBICS_LOGDOMAIN, "%s", GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_Reset(tbuf); } s=EB_Msg_GetCharValue(mRsp, "header/mutable/ReportText", NULL); if (s) { GWEN_Buffer_AppendString(tbuf, I18N("EBICS (Technical Report):")); GWEN_Buffer_AppendString(tbuf, " "); GWEN_Buffer_AppendString(tbuf, s); if (logbuf) { GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendBuffer(logbuf, tbuf); } GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Notice, GWEN_Buffer_GetStart(tbuf)); DBG_INFO(AQEBICS_LOGDOMAIN, "%s", GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_Reset(tbuf); } s=EB_Msg_GetCharValue(mRsp, "body/ReturnCode", NULL); if (bcode) { GWEN_Buffer_AppendString(tbuf, I18N("EBICS (Bank Code):")); GWEN_Buffer_AppendString(tbuf, " "); GWEN_Buffer_AppendString(tbuf, bcode); s=EBC_Provider_BankCodeToString(bcode); if (s) { GWEN_Buffer_AppendString(tbuf, " ["); GWEN_Buffer_AppendString(tbuf, s); GWEN_Buffer_AppendString(tbuf, "]"); } if (logbuf) { GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendBuffer(logbuf, tbuf); } GWEN_Gui_ProgressLog(0, EBC_Provider_ResultCodeToLogLevel(pro, bcode), GWEN_Buffer_GetStart(tbuf)); DBG_INFO(AQEBICS_LOGDOMAIN, "%s", GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_Reset(tbuf); } GWEN_Buffer_free(tbuf); }
int AH_NewKeyFileDialog_CheckBankIniLetter(GWEN_DIALOG *dlg, AB_USER *u) { AH_NEWKEYFILE_DIALOG *xdlg; int rv; GWEN_BUFFER *tbuf; assert(dlg); xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_NEWKEYFILE_DIALOG, dlg); assert(xdlg); tbuf=GWEN_Buffer_new(0, 1024, 0, 1); /* add HTML version of the INI letter */ GWEN_Buffer_AppendString(tbuf, "<html>"); GWEN_Buffer_AppendString(tbuf, I18N("<p>The following is the INI letter describing the keys of your bank. " "Please look at it carefully and compare the information against that " "in the letter from your bank.</p>" "<p><font color=red><b>Important Warning:</b></font> Only proceed if the hash matches! " "Contact your bank immediately if the hash does not match!</p>")); rv=AH_Provider_GetIniLetterHtml(AB_User_GetProvider(u), u, 1, 0, tbuf, 1); if (rv<0) { DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv); // TODO: show error message GWEN_Buffer_free(tbuf); return GWEN_DialogEvent_ResultHandled; } GWEN_Buffer_AppendString(tbuf, "</html>"); /* add ASCII version of the INI letter for frontends which don't support HTML */ GWEN_Buffer_AppendString(tbuf, I18N("The following is the INI letter describing the keys of your bank.\n" "Please look at it carefully and compare the information against that\n" "in the letter from your bank.\n" "\n" "IMPORTANT WARNING: Only proceed if the hash matches!\n" "Contact your bank immediately if the hash does not match!\n\n")); rv=AH_Provider_GetIniLetterTxt(AB_User_GetProvider(u), u, 1, 0, tbuf, 0); if (rv<0) { DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv); // TODO: show error message GWEN_Buffer_free(tbuf); return GWEN_DialogEvent_ResultHandled; } if (1!=GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_TYPE_INFO | GWEN_GUI_MSG_FLAGS_CONFIRM_B1 | GWEN_GUI_MSG_FLAGS_SEVERITY_DANGEROUS, I18N("Check Bank Keys"), GWEN_Buffer_GetStart(tbuf), I18N("Keys are ok"), I18N("Keys do not match!"), NULL, 0)) { GWEN_Buffer_free(tbuf); return GWEN_ERROR_VERIFY; } GWEN_Buffer_free(tbuf); return 0; }
int EBC_Provider_FillDataEncryptionInfoNode(AB_PROVIDER *pro, AB_USER *u, const GWEN_CRYPT_KEY *skey, 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; xmlNodePtr nodeX = NULL; const char *s; 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 for server crypt key */ keyId=GWEN_Crypt_Token_Context_GetEncipherKeyId(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; } hbuf=GWEN_Buffer_new(0, 256, 0, 1); s=EBC_User_GetCryptVersion(u); if (!(s && *s)) s="E001"; if (strcasecmp(s, "E001")==0) { rv=EB_Key_Info_BuildHashSha1(ki, hbuf, 1); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(hbuf); GWEN_Crypt_Token_Close(ct, 0, 0); return rv; } nodeX=xmlNewTextChild(node, NULL, BAD_CAST "EncryptionPubKeyDigest", BAD_CAST GWEN_Buffer_GetStart(hbuf)); GWEN_Buffer_free(hbuf); assert(nodeX); xmlNewProp(nodeX, BAD_CAST "Version", BAD_CAST "E001"); xmlNewProp(nodeX, BAD_CAST "Algorithm", BAD_CAST "http://www.w3.org/2000/09/xmldsig#sha1"); } else if (strcasecmp(s, "E002")==0) { rv=EB_Key_Info_BuildHashSha256(ki, hbuf, 1); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(hbuf); GWEN_Crypt_Token_Close(ct, 0, 0); return rv; } nodeX=xmlNewTextChild(node, NULL, BAD_CAST "EncryptionPubKeyDigest", BAD_CAST GWEN_Buffer_GetStart(hbuf)); GWEN_Buffer_free(hbuf); assert(nodeX); xmlNewProp(nodeX, BAD_CAST "Version", BAD_CAST "E002"); xmlNewProp(nodeX, BAD_CAST "Algorithm", BAD_CAST "http://www.w3.org/2001/04/xmlenc#sha256"); } /* add encrypted transactio key */ hbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=EBC_Provider_EncryptKey(pro, u, skey, hbuf); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(hbuf); GWEN_Crypt_Token_Close(ct, 0, 0); return rv; } nodeX=xmlNewTextChild(node, NULL, BAD_CAST "TransactionKey", BAD_CAST GWEN_Buffer_GetStart(hbuf)); GWEN_Buffer_free(hbuf); assert(nodeX); return 0; }
void AB_SelectBankInfoDialog_UpdateList(GWEN_DIALOG *dlg) { AB_SELECTBANKINFO_DIALOG *xdlg; AB_BANKINFO *tbi; const char *s; AB_BANKINFO_LIST2 *bl; int rv; assert(dlg); xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_SELECTBANKINFO_DIALOG, dlg); assert(xdlg); /* clear bank info list */ GWEN_Dialog_SetIntProperty(dlg, "listBox", GWEN_DialogProperty_ClearValues, 0, 0, 0); if (xdlg->matchingBankInfos) AB_BankInfo_List2_freeAll(xdlg->matchingBankInfos); xdlg->matchingBankInfos=NULL; /* setup template */ tbi=AB_BankInfo_new(); /* set country */ AB_BankInfo_SetCountry(tbi, xdlg->country); /* set bank code */ s=GWEN_Dialog_GetCharProperty(dlg, "blzEdit", GWEN_DialogProperty_Value, 0, NULL); if (s && *s) { int len; char *cpy; len=strlen(s); cpy=(char *) malloc(len+2); assert(cpy); memmove(cpy, s, len+1); /* copy including terminating zero char */ removeAllSpaces((uint8_t *)cpy); len=strlen(cpy); if (len) { /* append joker */ cpy[len]='*'; cpy[len+1]=0; } AB_BankInfo_SetBankId(tbi, cpy); free(cpy); } /* set bank code */ s=GWEN_Dialog_GetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, NULL); if (s && *s) { int len; char *cpy; len=strlen(s); cpy=(char *) malloc(len+2); assert(cpy); memmove(cpy, s, len+1); /* copy including terminating zero char */ removeAllSpaces((uint8_t *)cpy); len=strlen(cpy); if (len) { /* append joker */ cpy[len]='*'; cpy[len+1]=0; } AB_BankInfo_SetBic(tbi, cpy); free(cpy); } /* set bank name */ s=GWEN_Dialog_GetCharProperty(dlg, "nameEdit", GWEN_DialogProperty_Value, 0, NULL); if (s && *s) { GWEN_BUFFER *tbuf; tbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(tbuf, s); GWEN_Text_CondenseBuffer(tbuf); GWEN_Buffer_AppendString(tbuf, "*"); AB_BankInfo_SetBankName(tbi, GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_free(tbuf); } /* set bank name */ s=GWEN_Dialog_GetCharProperty(dlg, "locationEdit", GWEN_DialogProperty_Value, 0, NULL); if (s && *s) { GWEN_BUFFER *tbuf; tbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(tbuf, s); GWEN_Text_CondenseBuffer(tbuf); GWEN_Buffer_AppendString(tbuf, "*"); AB_BankInfo_SetLocation(tbi, GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_free(tbuf); } bl=AB_BankInfo_List2_new(); rv=AB_Banking_GetBankInfoByTemplate(xdlg->banking, xdlg->country, tbi, bl); if (rv<0) { DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv); AB_BankInfo_List2_freeAll(bl); } else { AB_BANKINFO_LIST2_ITERATOR *it; it=AB_BankInfo_List2_First(bl); if (it) { AB_BANKINFO *bi; GWEN_BUFFER *tbuf; tbuf=GWEN_Buffer_new(0, 256, 0, 1); bi=AB_BankInfo_List2Iterator_Data(it); while (bi) { createListBoxString(bi, tbuf); GWEN_Dialog_SetCharProperty(dlg, "listBox", GWEN_DialogProperty_AddValue, 0, GWEN_Buffer_GetStart(tbuf), 0); GWEN_Buffer_Reset(tbuf); bi=AB_BankInfo_List2Iterator_Next(it); } GWEN_Buffer_free(tbuf); AB_BankInfo_List2Iterator_free(it); } xdlg->matchingBankInfos=bl; } AB_BankInfo_free(tbi); if (GWEN_Dialog_GetIntProperty(dlg, "listBox", GWEN_DialogProperty_Value, 0, -1)>=0) GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 1, 0); else GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0); }
int EBC_Provider_ExecContext__IZV(AB_PROVIDER *pro, AB_IMEXPORTER_CONTEXT *ctx, AB_USER *u, AB_ACCOUNT *a, GWEN_HTTP_SESSION *sess, EBC_CONTEXT *ectx){ EBC_PROVIDER *dp; AB_JOB_LIST2_ITERATOR *jit; AB_JOB_STATUS js; AB_IMEXPORTER_CONTEXT *exCtx; AB_IMEXPORTER_ACCOUNTINFO *ai; GWEN_BUFFER *bufDtaus; GWEN_TIME *currentTime; GWEN_BUFFER *logbuf; int rv; const char *profileName=NULL; const char *s; const char *rqType; uint32_t groupId=0; assert(pro); dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro); assert(dp); /* prepare CTX log */ logbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(logbuf, "BEGIN"); currentTime=GWEN_CurrentTime(); GWEN_Time_toString(currentTime, I18N("YYYY/MM/DD-hh:mm:ss"), logbuf); GWEN_Time_free(currentTime); GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendString(logbuf, I18N("National Mass Transfer")); GWEN_Buffer_AppendString(logbuf, "\n"); GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendString(logbuf, I18N("Transfer type: ")); GWEN_Buffer_AppendString(logbuf, "\t"); switch(EBC_Context_GetJobType(ectx)) { case AB_Job_TypeTransfer: if (!profileName) profileName="transfer"; GWEN_Buffer_AppendString(logbuf, I18N("Transfer")); break; case AB_Job_TypeDebitNote: if (!profileName) profileName="debitnote"; GWEN_Buffer_AppendString(logbuf, I18N("Debit Note")); break; default: GWEN_Buffer_AppendString(logbuf, I18N("unknown")); break; } GWEN_Buffer_AppendString(logbuf, "\n"); GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendString(logbuf, I18N("Account: ")); GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendString(logbuf, AB_Account_GetBankCode(a)); GWEN_Buffer_AppendString(logbuf, " / "); GWEN_Buffer_AppendString(logbuf, AB_Account_GetAccountNumber(a)); GWEN_Buffer_AppendString(logbuf, "\n"); /* add a tab-less line to start a new table */ GWEN_Buffer_AppendString(logbuf, "Transactions\n"); DBG_INFO(AQEBICS_LOGDOMAIN, "Sampling transactions from jobs"); exCtx=AB_ImExporterContext_new(); ai=AB_ImExporterAccountInfo_new(); AB_ImExporterAccountInfo_FillFromAccount(ai, a); jit=AB_Job_List2_First(EBC_Context_GetJobs(ectx)); if (jit) { AB_JOB *uj; uj=AB_Job_List2Iterator_Data(jit); assert(uj); while(uj) { AB_TRANSACTION *t; const GWEN_STRINGLIST *sl; const char *s; const AB_VALUE *v; switch(EBC_Context_GetJobType(ectx)) { case AB_Job_TypeTransfer: case AB_Job_TypeDebitNote: t=AB_Job_GetTransaction(uj); break; default: t=NULL; } assert(t); if (groupId==0) /* take id from first job of the created DTAUS doc */ groupId=AB_Job_GetJobId(uj); AB_Transaction_SetGroupId(t, groupId); AB_ImExporterAccountInfo_AddTransaction(ai, AB_Transaction_dup(t)); sl=AB_Transaction_GetRemoteName(t); s=NULL; if (sl) s=GWEN_StringList_FirstString(sl); if (!s) s=I18N("unknown"); GWEN_Buffer_AppendString(logbuf, s); GWEN_Buffer_AppendString(logbuf, "\t"); s=AB_Transaction_GetRemoteBankCode(t); if (!s) s="????????"; GWEN_Buffer_AppendString(logbuf, s); GWEN_Buffer_AppendString(logbuf, "\t"); s=AB_Transaction_GetRemoteAccountNumber(t); if (!s) s="??????????"; GWEN_Buffer_AppendString(logbuf, s); GWEN_Buffer_AppendString(logbuf, "\t"); sl=AB_Transaction_GetPurpose(t); s=NULL; if (sl) s=GWEN_StringList_FirstString(sl); if (!s) s=""; GWEN_Buffer_AppendString(logbuf, s); GWEN_Buffer_AppendString(logbuf, "\t"); v=AB_Transaction_GetValue(t); if (v) AB_Value_toHumanReadableString(v, logbuf, 2); else GWEN_Buffer_AppendString(logbuf, "0,00 EUR"); GWEN_Buffer_AppendString(logbuf, "\n"); uj=AB_Job_List2Iterator_Next(jit); } /* while */ AB_Job_List2Iterator_free(jit); } AB_ImExporterContext_AddAccountInfo(exCtx, ai); GWEN_Buffer_AppendString(logbuf, I18N("Results:\n")); /* export as DTAUS to bufDtaus */ bufDtaus=GWEN_Buffer_new(0, 1024, 0, 1); DBG_INFO(AQEBICS_LOGDOMAIN, "Exporting transactions to DTAUS[default]"); rv=AB_Banking_ExportToBuffer(AB_Provider_GetBanking(pro), exCtx, "dtaus", profileName, bufDtaus); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(bufDtaus); EBC_Provider_SetJobListStatus(EBC_Context_GetJobs(ectx), AB_Job_StatusError); GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendString(logbuf, I18N("Error while exporting to DTAUS\n")); GWEN_Buffer_AppendString(logbuf, "END\n"); AB_ImExporterContext_AddLog(ctx, GWEN_Buffer_GetStart(logbuf)); GWEN_Buffer_free(logbuf); return rv; } GWEN_Buffer_AppendString(logbuf, "\t"); GWEN_Buffer_AppendString(logbuf, I18N("Exporting to DTAUS: ok\n")); /* exchange upload request */ DBG_INFO(AQEBICS_LOGDOMAIN, "Uploading."); AB_HttpSession_ClearLog(sess); if (EBC_Context_GetJobType(ectx)==AB_Job_TypeDebitNote) { if (EBC_User_GetFlags(u) & EBC_USER_FLAGS_USE_IZL) rqType="IZL"; else rqType="IZV"; } else rqType="IZV"; rv=EBC_Provider_XchgUploadRequest(pro, sess, u, rqType, (const uint8_t*)GWEN_Buffer_GetStart(bufDtaus), GWEN_Buffer_GetUsedBytes(bufDtaus)); if (rv<0 || rv>=300) js=AB_Job_StatusError; else js=AB_Job_StatusFinished; s=AB_HttpSession_GetLog(sess); if (s) GWEN_Buffer_AppendString(logbuf, s); GWEN_Buffer_AppendString(logbuf, "END\n"); AB_ImExporterContext_AddLog(ctx, GWEN_Buffer_GetStart(logbuf)); GWEN_Buffer_free(logbuf); EBC_Provider_SetJobListStatus(EBC_Context_GetJobs(ectx), js); DBG_INFO(AQEBICS_LOGDOMAIN, "Done"); return 0; }
int AH_Msg_SignPinTan(AH_MSG *hmsg, GWEN_BUFFER *rawBuf, const char *signer) { AH_HBCI *h; GWEN_XMLNODE *node; GWEN_DB_NODE *cfg; GWEN_BUFFER *hbuf; int rv; char ctrlref[15]; const char *p; GWEN_MSGENGINE *e; AB_USER *su; uint32_t uFlags; char pin[64]; uint32_t tm; assert(hmsg); h=AH_Dialog_GetHbci(hmsg->dialog); assert(h); e=AH_Dialog_GetMsgEngine(hmsg->dialog); assert(e); GWEN_MsgEngine_SetMode(e, "pintan"); su=AB_Banking_FindUser(AH_HBCI_GetBankingApi(h), AH_PROVIDER_NAME, "de", "*", signer, "*"); if (!su) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Unknown user \"%s\"", signer); return GWEN_ERROR_NOT_FOUND; } uFlags=AH_User_GetFlags(su); node=GWEN_MsgEngine_FindNodeByPropertyStrictProto(e, "SEG", "id", 0, "SigHead"); if (!node) { DBG_INFO(AQHBCI_LOGDOMAIN, "Segment \"SigHead\" not found"); return GWEN_ERROR_INTERNAL; } /* for iTAN mode: set selected mode (Sicherheitsfunktion, kodiert) */ tm=AH_Msg_GetItanMethod(hmsg); if (tm==0) { tm=AH_Dialog_GetItanMethod(hmsg->dialog); if (tm) /* this is needed by AH_MsgPinTan_PrepareCryptoSeg */ AH_Msg_SetItanMethod(hmsg, tm); } /* prepare config for segment */ cfg=GWEN_DB_Group_new("sighead"); rv=AH_MsgPinTan_PrepareCryptoSeg(hmsg, su, cfg, 0, 1); if (rv) { DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv); GWEN_DB_Group_free(cfg); return rv; } /* set expected signer */ if (!(uFlags & AH_USER_FLAGS_BANK_DOESNT_SIGN)) { const char *remoteId; remoteId=AH_User_GetPeerId(su); if (!remoteId || *remoteId==0) remoteId=AB_User_GetUserId(su); assert(remoteId); assert(*remoteId); DBG_DEBUG(AQHBCI_LOGDOMAIN, "Expecting \"%s\" to sign the response", remoteId); AH_Msg_SetExpectedSigner(hmsg, remoteId); } /* store system id */ p=NULL; if (!hmsg->noSysId) p=AH_User_GetSystemId(su); if (!p) p="0"; GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "SecDetails/SecId", p); if (tm) { GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "function", tm); } /* retrieve control reference for sigtail (to be used later) */ p=GWEN_DB_GetCharValue(cfg, "ctrlref", 0, ""); if (strlen(p)>=sizeof(ctrlref)) { DBG_INFO(AQHBCI_LOGDOMAIN, "Control reference too long (14 bytes maximum)"); GWEN_DB_Group_free(cfg); return -1; } strcpy(ctrlref, p); /* create SigHead */ hbuf=GWEN_Buffer_new(0, 128+GWEN_Buffer_GetUsedBytes(rawBuf), 0, 1); GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "head/seq", hmsg->firstSegment-1); GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "signseq", 1); /* create signature head segment */ rv=GWEN_MsgEngine_CreateMessageFromNode(e, node, hbuf, cfg); GWEN_DB_Group_free(cfg); cfg=0; if (rv) { DBG_INFO(AQHBCI_LOGDOMAIN, "Could not create SigHead"); GWEN_Buffer_free(hbuf); return rv; } /* insert new SigHead at beginning of message buffer */ DBG_DEBUG(AQHBCI_LOGDOMAIN, "Inserting signature head"); GWEN_Buffer_Rewind(hmsg->buffer); GWEN_Buffer_InsertBytes(hmsg->buffer, GWEN_Buffer_GetStart(hbuf), GWEN_Buffer_GetUsedBytes(hbuf)); /* create sigtail */ DBG_DEBUG(AQHBCI_LOGDOMAIN, "Completing signature tail"); cfg=GWEN_DB_Group_new("sigtail"); GWEN_Buffer_Reset(hbuf); GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "head/seq", hmsg->lastSegment+1); /* store to DB */ GWEN_DB_SetBinValue(cfg, GWEN_DB_FLAGS_DEFAULT, "signature", "NOSIGNATURE", 11); GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "ctrlref", ctrlref); /* handle pin */ memset(pin, 0, sizeof(pin)); rv=AH_User_InputPin(su, pin, 4, sizeof(pin), 0); if (rv<0) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Error getting pin from medium (%d)", rv); GWEN_DB_Group_free(cfg); GWEN_Buffer_free(hbuf); memset(pin, 0, sizeof(pin)); return rv; } GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "pin", pin); AH_Msg_SetPin(hmsg, pin); memset(pin, 0, sizeof(pin)); /* handle tan */ if (hmsg->needTan) { DBG_NOTICE(AQHBCI_LOGDOMAIN, "This queue needs a TAN"); if (hmsg->usedTan) { DBG_NOTICE(AQHBCI_LOGDOMAIN, "Using existing TAN"); GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "tan", hmsg->usedTan); } else { char tan[16]; memset(tan, 0, sizeof(tan)); DBG_NOTICE(AQHBCI_LOGDOMAIN, "Asking for TAN"); rv=AH_User_InputTan(su, tan, 4, sizeof(tan)); if (rv<0) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Error getting TAN from medium"); GWEN_DB_Group_free(cfg); GWEN_Buffer_free(hbuf); return rv; } GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "tan", tan); AH_Msg_SetTan(hmsg, tan); } } else { DBG_NOTICE(AQHBCI_LOGDOMAIN, "This queue doesn't need a TAN"); } /* get node */ node=GWEN_MsgEngine_FindNodeByPropertyStrictProto(e, "SEG", "id", 0, "SigTail"); if (!node) { DBG_INFO(AQHBCI_LOGDOMAIN, "Segment \"SigTail\"not found"); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return GWEN_ERROR_INTERNAL; } rv=GWEN_MsgEngine_CreateMessageFromNode(e, node, hbuf, cfg); if (rv) { DBG_INFO(AQHBCI_LOGDOMAIN, "Could not create SigTail (%d)", rv); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return rv; } /* append sigtail */ DBG_DEBUG(AQHBCI_LOGDOMAIN, "Appending signature tail"); if (GWEN_Buffer_AppendBuffer(hmsg->buffer, hbuf)) { DBG_INFO(AQHBCI_LOGDOMAIN, "here"); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return GWEN_ERROR_MEMORY_FULL; } DBG_DEBUG(AQHBCI_LOGDOMAIN, "Appending signature tail: done"); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); /* adjust segment numbers (for next signature and message tail */ hmsg->firstSegment--; hmsg->lastSegment++; return 0; }
int addsubAccountFlags(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv, int is_add ) { GWEN_DB_NODE *db; AB_PROVIDER *pro; AB_ACCOUNT_LIST2 *al; AB_ACCOUNT *a=0; int rv; const char *bankId; const char *accountId; const char *subAccountId; 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 */ "accountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "a", /* short option */ "account", /* long option */ "Specify the account id (Kontonummer)", /* short description */ "Specify the account id (Kontonummer)" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "subAccountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "aa", /* short option */ "subaccount", /* long option */ "Specify the sub account id (Unterkontomerkmal)", /* short description */ "Specify the sub account id (Unterkontomerkmal)" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "flags", /* name */ 1, /* minnum */ 99, /* maxnum */ "f", /* short option */ "flags", /* long option */ "Specify the user flags", /* short description */ "Specify the user flags" /* 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, "*"); accountId=GWEN_DB_GetCharValue(db, "accountId", 0, "*"); subAccountId=GWEN_DB_GetCharValue(db, "subAccountId", 0, "*"); al=AB_Banking_FindAccounts(ab, AH_PROVIDER_NAME, "de", bankId, accountId, subAccountId); if (al) { if (AB_Account_List2_GetSize(al)!=1) { DBG_ERROR(0, "Ambiguous account specification"); AB_Account_List2_free(al); return 3; } else { AB_ACCOUNT_LIST2_ITERATOR *ait; ait=AB_Account_List2_First(al); assert(ait); a=AB_Account_List2Iterator_Data(ait); AB_Account_List2Iterator_free(ait); } AB_Account_List2_free(al); } if (!a) { DBG_ERROR(0, "No matching customer"); return 3; } else { GWEN_DB_NODE *vn; uint32_t flags, bf, c=0; /* parse flags */ flags=AH_Account_Flags_fromDb(db, "flags"); for (bf=flags; bf; bf>>=1) { if (bf&1) c++; } vn=GWEN_DB_FindFirstVar(db, "flags"); if (GWEN_DB_Values_Count(vn)!=c) { fprintf(stderr, "ERROR: Specified flag(s) unknown\n"); AB_Banking_OnlineFini(ab); AB_Banking_Fini(ab); return 4; } /* lock account */ rv=AB_Banking_BeginExclUseAccount(ab, a); if (rv<0) { fprintf(stderr, "ERROR: Could not lock account, maybe it is used in another application? (%d)\n", rv); AB_Banking_OnlineFini(ab); AB_Banking_Fini(ab); return 4; } /* modify account */ if( is_add ) { fprintf(stderr, "Adding flags: %08x\n", flags); AH_Account_AddFlags(a, flags); } else { fprintf(stderr, "Removing flags: %08x\n", flags); AH_Account_SubFlags(a, flags); } /* unlock account */ rv=AB_Banking_EndExclUseAccount(ab, a, 0); if (rv<0) { fprintf(stderr, "ERROR: Could not unlock account (%d)\n", rv); AB_Banking_OnlineFini(ab); AB_Banking_Fini(ab); return 4; } } rv=AB_Banking_OnlineFini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
int AH_Msg_DecryptPinTan(AH_MSG *hmsg, GWEN_DB_NODE *gr){ AH_HBCI *h; GWEN_BUFFER *mbuf; uint32_t l; const uint8_t *p; GWEN_MSGENGINE *e; AB_USER *u; const char *peerId; // uint32_t uFlags; GWEN_DB_NODE *nhead=NULL; GWEN_DB_NODE *ndata=NULL; const char *crypterId; 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); /* get encrypted session key */ nhead=GWEN_DB_GetGroup(gr, GWEN_DB_FLAGS_DEFAULT | GWEN_PATH_FLAGS_NAMEMUSTEXIST, "CryptHead"); if (!nhead) { DBG_ERROR(AQHBCI_LOGDOMAIN, "No crypt head"); return GWEN_ERROR_BAD_DATA; } ndata=GWEN_DB_GetGroup(gr, GWEN_DB_FLAGS_DEFAULT | GWEN_PATH_FLAGS_NAMEMUSTEXIST, "CryptData"); if (!ndata) { DBG_ERROR(AQHBCI_LOGDOMAIN, "No crypt data"); return GWEN_ERROR_BAD_DATA; } crypterId=GWEN_DB_GetCharValue(nhead, "key/userId", 0, I18N("unknown")); /* get encrypted data */ p=GWEN_DB_GetBinValue(ndata, "CryptData", 0, 0,0, &l); if (!p || !l) { DBG_ERROR(AQHBCI_LOGDOMAIN, "No crypt data"); return GWEN_ERROR_BAD_DATA; } /* decipher message with session key */ mbuf=GWEN_Buffer_new(0, l, 0, 1); GWEN_Buffer_AppendBytes(mbuf, (const char*)p, l); /* store crypter id */ AH_Msg_SetCrypterId(hmsg, crypterId); /* store new buffer inside message */ GWEN_Buffer_free(hmsg->origbuffer); hmsg->origbuffer=hmsg->buffer; GWEN_Buffer_Rewind(mbuf); hmsg->buffer=mbuf; return 0; }
GWEN_PROCESS_STATE GWEN_Process_Start(GWEN_PROCESS *pr, const char *prg, const char *args) { pid_t pid; char *argv[32]; int argc; const char *p, *p2; GWEN_BUFFER *wbuf; assert(pr); if (GWEN_Process_Redirect(pr)) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirections"); pr->state=GWEN_ProcessStateNotStarted; pr->pid=-1; return GWEN_ProcessStateNotStarted; } pid=fork(); if (pid==-1) { /* error in fork */ pr->state=GWEN_ProcessStateNotStarted; pr->pid=-1; /* close all pipes */ if (pr->filesStdin[0]!=-1) { close(pr->filesStdin[0]); close(pr->filesStdin[1]); } if (pr->filesStdout[0]!=-1) { close(pr->filesStdout[0]); close(pr->filesStdout[1]); } if (pr->filesStderr[0]!=-1) { close(pr->filesStderr[0]); close(pr->filesStderr[1]); } return GWEN_ProcessStateNotStarted; } else if (pid!=0) { /* parent */ DBG_INFO(GWEN_LOGDOMAIN, "Process started with id %d", (int)pid); pr->state=GWEN_ProcessStateRunning; pr->pid=pid; /* setup redirections */ if (pr->filesStdin[0]!=-1) { close(pr->filesStdin[1]); pr->stdIn=GWEN_SyncIo_File_fromFd(pr->filesStdin[0]); } if (pr->filesStdout[0]!=-1) { close(pr->filesStdout[1]); pr->stdOut=GWEN_SyncIo_File_fromFd(pr->filesStdout[0]); } if (pr->filesStderr[0]!=-1) { close(pr->filesStderr[1]); pr->stdErr=GWEN_SyncIo_File_fromFd(pr->filesStdout[0]); } return GWEN_ProcessStateRunning; } /* child, build arguments */ argc=0; DBG_DEBUG(GWEN_LOGDOMAIN, "I'm the child process"); /* setup redirections */ if (pr->filesStdin[0]!=-1) { close(pr->filesStdin[0]); close(0); if (dup(pr->filesStdin[1])==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirection"); } } if (pr->filesStdout[0]!=-1) { close(pr->filesStdout[0]); close(1); if (dup(pr->filesStdout[1])==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirection"); } } if (pr->filesStderr[0]!=-1) { close(pr->filesStderr[0]); close(2); if (dup(pr->filesStderr[1])==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirection"); } } argv[0]=strdup(prg); argc++; p=args; wbuf=GWEN_Buffer_new(0, 256, 0, 1); while(argc<32 && *p) { while(*p && isspace((int)*p)) p++; if (!(*p)) break; if (GWEN_Text_GetWordToBuffer(p, " ", wbuf, GWEN_TEXT_FLAGS_NULL_IS_DELIMITER | GWEN_TEXT_FLAGS_DEL_QUOTES | GWEN_TEXT_FLAGS_CHECK_BACKSLASH, &p)) break; p2=GWEN_Buffer_GetStart(wbuf); argv[argc]=strdup(p2); GWEN_Buffer_Reset(wbuf); argc++; } /* while */ GWEN_Buffer_free(wbuf); argv[argc]=0; /* parameters ready, exec */ execvp(prg, argv); /* if we reach this point an error occurred */ DBG_ERROR(GWEN_LOGDOMAIN, "Could not start program \"%s\": %s", prg, strerror(errno)); exit(EXIT_FAILURE); }
AB_IMEXPORTER_ACCOUNTINFO *AB_ImExporterYN__ReadAccountInfo(AB_IMEXPORTER *ie, AB_IMEXPORTER_CONTEXT *ctx, GWEN_XMLNODE *doc) { GWEN_XMLNODE *n; AB_IMEXPORTER_ACCOUNTINFO *ai; ai=AB_ImExporterAccountInfo_new(); n=GWEN_XMLNode_FindFirstTag(doc, "SG2", 0, 0); if (n) n=GWEN_XMLNode_FindFirstTag(n, "FII", 0, 0); if (n) { GWEN_XMLNODE *nn; const char *s; nn=GWEN_XMLNode_FindFirstTag(n, "C078", 0, 0); if (nn) { GWEN_XMLNODE *nnn; /* account number */ s=GWEN_XMLNode_GetCharValue(nn, "D_3194", 0); if (s) AB_ImExporterAccountInfo_SetAccountNumber(ai, s); /* IBAN */ s=GWEN_XMLNode_GetCharValue(nn, "D_3192", 0); if (s) AB_ImExporterAccountInfo_SetIban(ai, s); /* currency */ nnn=GWEN_XMLNode_FindFirstTag(nn, "D_6345", 0, 0); if (nnn) { s=GWEN_XMLNode_GetProperty(nnn, "value", 0); if (s) AB_ImExporterAccountInfo_SetCurrency(ai, s); } } /* account number */ s=GWEN_XMLNode_GetCharValue(n, "PF:D_5388", 0); if (s) AB_ImExporterAccountInfo_SetAccountName(ai, s); } /* owner name */ n=GWEN_XMLNode_GetNodeByXPath(doc, "SG3[1]/NAD", GWEN_PATH_FLAGS_NAMEMUSTEXIST); if (n) { GWEN_XMLNODE *nn; nn=GWEN_XMLNode_FindFirstTag(n, "D_3035", 0, 0); if (nn) { const char *s; s=GWEN_XMLNode_GetProperty(nn, "Value", 0); if (s && strcasecmp(s, "HQ")==0) { nn=GWEN_XMLNode_FindFirstTag(n, "C058", 0, 0); if (nn) { s=GWEN_XMLNode_GetCharValue(nn, "D_3124", 0); if (s && *s) { GWEN_BUFFER *xbuf; xbuf=GWEN_Buffer_new(0, 256, 0, 1); AB_ImExporter_Iso8859_1ToUtf8(s, strlen(s), xbuf); AB_ImExporterAccountInfo_SetOwner(ai, GWEN_Buffer_GetStart(xbuf)); GWEN_Buffer_free(xbuf); } } } } } return ai; }
int write_hp_file_c(ARGUMENTS *args, GWEN_XMLNODE *node) { int rv; const char *f; GWEN_BUFFER *fname; GWEN_BUFFER *hbuf; const char *s; GWEN_SYNCIO *sio; int err; const char *nacc; const char *constAcc; const char *constName; const char *fromDbAcc; const char *fromDbName; const char *dupAcc; const char *dupName; const char *id; const char *prefix; id=get_struct_property(node, "id", 0); if (!id) { DBG_ERROR(0, "No id for struct"); return -1; } prefix=get_struct_property(node, "prefix", 0); if (!prefix) { DBG_ERROR(0, "No prefix for struct"); return -1; } f=get_struct_property(node, "filename", 0); if (!f) { DBG_ERROR(0, "No filename given"); return -1; } nacc=get_struct_property(node, "access", "public"); constAcc=get_struct_property(node, "constructor-access", nacc); constName=get_struct_property(node, "constructor-name", 0); fromDbAcc=get_struct_property(node, "fromdb-access", nacc); fromDbName=get_struct_property(node, "fromdb-name", 0); dupAcc=get_struct_property(node, "dup-access", nacc); dupName=get_struct_property(node, "fromdb-name", 0); fname=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(fname, f); GWEN_Buffer_AppendString(fname, "_p.h"); sio=GWEN_SyncIo_File_new(GWEN_Buffer_GetStart(fname), GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_GREAD | GWEN_SYNCIO_FILE_FLAGS_GWRITE); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "open(%s): %s", GWEN_Buffer_GetStart(fname), strerror(errno)); GWEN_Buffer_free(fname); GWEN_SyncIo_free(sio); return -1; } GWEN_Buffer_free(fname); /* Insert the auto-generation warning */ GWEN_SyncIo_WriteString(sio, "/* This file is auto-generated from \""); GWEN_SyncIo_WriteString(sio, f); GWEN_SyncIo_WriteLine(sio, ".xml\" by the typemaker"); GWEN_SyncIo_WriteLine(sio, " tool of Gwenhywfar. "); GWEN_SyncIo_WriteLine(sio, " Do not edit this file -- all changes will be lost! */"); hbuf=GWEN_Buffer_new(0, 256, 0, 1); s=f; while (*s) { GWEN_Buffer_AppendByte(hbuf, toupper(*s)); s++; } GWEN_Buffer_AppendString(hbuf, "_P_H"); GWEN_SyncIo_WriteString(sio, "#ifndef "); GWEN_SyncIo_WriteLine(sio, GWEN_Buffer_GetStart(hbuf)); GWEN_SyncIo_WriteString(sio, "#define "); GWEN_SyncIo_WriteLine(sio, GWEN_Buffer_GetStart(hbuf)); GWEN_SyncIo_WriteLine(sio, ""); if (strcasecmp(get_struct_property(node, "inherit", ""), "private")==0) { GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/inherit.h>"); } if (strcasecmp(get_struct_property(node, "list", ""), "private")==0) { GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/misc.h>"); } if (strcasecmp(get_struct_property(node, "list2", ""), "private")==0) { GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/list2.h>"); } fname=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(fname, f); GWEN_Buffer_AppendString(fname, "_l.h"); GWEN_SyncIo_WriteString(sio, "#include \""); GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(fname)); GWEN_SyncIo_WriteLine(sio, "\""); GWEN_Buffer_free(fname); GWEN_SyncIo_WriteLine(sio, ""); rv=write_h_struct_c(args, node, sio); if (rv) { GWEN_Buffer_free(hbuf); GWEN_SyncIo_free(sio); return rv; } GWEN_SyncIo_WriteLine(sio, ""); /* include private functions */ if (strcasecmp(constAcc, "private")==0) { GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, " *"); GWEN_SyncIo_WriteString(sio, prefix); if (constName) GWEN_SyncIo_WriteString(sio, constName); else GWEN_SyncIo_WriteString(sio, "_new"); GWEN_SyncIo_WriteLine(sio, "(void);"); } /* FromDb */ if (strcasecmp(fromDbAcc, "private")==0) { GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, " *"); GWEN_SyncIo_WriteString(sio, prefix); if (fromDbName) GWEN_SyncIo_WriteString(sio, fromDbName); else GWEN_SyncIo_WriteString(sio, "_fromDb"); GWEN_SyncIo_WriteLine(sio, "(GWEN_DB_NODE *db);"); } /* dup */ if (strcasecmp(dupAcc, "private")==0) { GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, " *"); GWEN_SyncIo_WriteString(sio, prefix); if (dupName) GWEN_SyncIo_WriteString(sio, dupName); else GWEN_SyncIo_WriteString(sio, "_dup"); GWEN_SyncIo_WriteString(sio, "(const "); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, "*st);"); } if (strcasecmp(nacc, "private")==0) { GWEN_SyncIo_WriteString(sio, "void "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_free("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st);"); GWEN_SyncIo_WriteString(sio, "void "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_Attach("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st);"); /* ReadDb */ GWEN_SyncIo_WriteString(sio, "int "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_ReadDb("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st, GWEN_DB_NODE *db);"); /* ToDb */ GWEN_SyncIo_WriteString(sio, "int "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_toDb(const "); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, "*st, GWEN_DB_NODE *db);"); GWEN_SyncIo_WriteString(sio, "int "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_IsModified(const "); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st);"); GWEN_SyncIo_WriteString(sio, "void "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_SetModified("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st, int i);"); } rv=write_h_setget_c(args, node, sio, "private"); if (rv) { GWEN_Buffer_free(hbuf); GWEN_SyncIo_free(sio); return rv; } /* write trailing endif */ err=GWEN_SyncIo_WriteLine(sio, ""); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_WriteString(sio, "#endif /* "); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(hbuf)); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_WriteLine(sio, " */"); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_Disconnect(sio); if (err) { DBG_ERROR_ERR(0, err); GWEN_SyncIo_free(sio); GWEN_Buffer_free(hbuf); return -1; } GWEN_Buffer_free(hbuf); return 0; }
GWENHYWFAR_CB int GWEN_CryptMgrKeys_VerifyData(GWEN_CRYPTMGR *cm, const uint8_t *pData, uint32_t lData, const uint8_t *pSignature, uint32_t lSignature) { GWEN_CRYPTMGR_KEYS *xcm; GWEN_MDIGEST *md; int rv; GWEN_BUFFER *tbuf; int ksize; uint32_t l; assert(cm); xcm=GWEN_INHERIT_GETDATA(GWEN_CRYPTMGR, GWEN_CRYPTMGR_KEYS, cm); assert(xcm); if (xcm->peerKey==NULL) { DBG_ERROR(GWEN_LOGDOMAIN, "No peer key"); return GWEN_ERROR_GENERIC; } ksize=GWEN_Crypt_Key_GetKeySize(xcm->peerKey); /* the padding algo uses random numbers, so we must use the encrypt function and * compare the decoded and unpadded signature with the hash of the source data */ tbuf=GWEN_Buffer_new(0, ksize+16, 0, 1); l=GWEN_Buffer_GetMaxUnsegmentedWrite(tbuf); rv=GWEN_Crypt_Key_Encipher(xcm->peerKey, pSignature, lSignature, (uint8_t*)GWEN_Buffer_GetPosPointer(tbuf), &l); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); return rv; } GWEN_Buffer_IncrementPos(tbuf, l); GWEN_Buffer_AdjustUsedBytes(tbuf); /* unpadd */ rv=GWEN_Padd_UnpaddWithIso9796_2(tbuf); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); return rv; } /* tbuf now contains the hash */ /* hash source data */ md=GWEN_MDigest_Rmd160_new(); rv=GWEN_MDigest_Begin(md); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_MDigest_free(md); GWEN_Buffer_free(tbuf); return rv; } rv=GWEN_MDigest_Update(md, pData, lData); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_MDigest_free(md); GWEN_Buffer_free(tbuf); return rv; } rv=GWEN_MDigest_End(md); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_MDigest_free(md); GWEN_Buffer_free(tbuf); return rv; } if (GWEN_MDigest_GetDigestSize(md)!=GWEN_Buffer_GetUsedBytes(tbuf)) { DBG_ERROR(GWEN_LOGDOMAIN, "Invalid signature"); GWEN_MDigest_free(md); GWEN_Buffer_free(tbuf); return GWEN_ERROR_VERIFY; } if (memcmp(GWEN_MDigest_GetDigestPtr(md), GWEN_Buffer_GetStart(tbuf), GWEN_MDigest_GetDigestSize(md))!=0) { DBG_ERROR(GWEN_LOGDOMAIN, "Invalid signature"); GWEN_MDigest_free(md); GWEN_Buffer_free(tbuf); return GWEN_ERROR_VERIFY; } GWEN_MDigest_free(md); GWEN_Buffer_free(tbuf); return 0; }
int doBuildDefs(GWEN_DB_NODE *dbArgs, const char *fname) { TYPEMAKER2_TYPEMANAGER *tym; TYPEMAKER2_BUILDER *tb=NULL; TYPEMAKER2_TYPE *ty; GWEN_STRINGLIST *sl; TYPEMAKER2_TYPE_LIST2 *tlist; TYPEMAKER2_TYPE_LIST2_ITERATOR *it; const char *s; int i; int rv; tym=Typemaker2_TypeManager_new(); s=GWEN_DB_GetCharValue(dbArgs, "api", 0, NULL); if (s && *s) Typemaker2_TypeManager_SetApiDeclaration(tym, s); s=GWEN_DB_GetCharValue(dbArgs, "language", 0, "c"); if (s && *s) { Typemaker2_TypeManager_SetLanguage(tym, s); if (strcasecmp(s, "c")==0) { tb=Typemaker2_Builder_C_new(); Typemaker2_Builder_SetTypeManager(tb, tym); } else { DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported language [%s]", s); return 1; } } else { DBG_ERROR(GWEN_LOGDOMAIN, "Missing language specification"); return 1; } Typemaker2_Builder_SetSourceFileName(tb, fname); for (i=0; i<99; i++) { s=GWEN_DB_GetCharValue(dbArgs, "include", i, NULL); if (s && *s) Typemaker2_TypeManager_AddFolder(tym, s); else break; } sl=GWEN_PathManager_GetPaths(GWEN_PM_LIBNAME, GWEN_PM_DATADIR); if (sl) { GWEN_STRINGLISTENTRY *se; se=GWEN_StringList_FirstEntry(sl); while(se) { s=GWEN_StringListEntry_Data(se); if (s) { GWEN_BUFFER *xbuf; xbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(xbuf, s); GWEN_Buffer_AppendString(xbuf, "/typemaker2/"); s=Typemaker2_TypeManager_GetLanguage(tym); if (s && *s) GWEN_Buffer_AppendString(xbuf, s); Typemaker2_TypeManager_AddFolder(tym, GWEN_Buffer_GetStart(xbuf)); GWEN_Buffer_free(xbuf); } se=GWEN_StringListEntry_Next(se); } GWEN_StringList_free(sl); } tlist=Typemaker2_Type_List2_new(); rv=Typemaker2_TypeManager_LoadTypeFileNoLookup(tym, fname, tlist); if (rv<0) { DBG_ERROR(GWEN_LOGDOMAIN, "Unable to load file [%s] (%d)", fname, rv); return 2; } it=Typemaker2_Type_List2_First(tlist); if(it) { ty=Typemaker2_Type_List2Iterator_Data(it); while(ty) { /* DEBUG */ #if 0 Typemaker2_TypeManager_Dump(tym, stderr, 2); #endif /* only write typedef files */ rv=Typemaker2_Builder_WriteFiles(tb, ty, 1); if (rv<0) { DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv); return 2; } /* handle next type */ ty=Typemaker2_Type_List2Iterator_Next(it); } Typemaker2_Type_List2Iterator_free(it); } Typemaker2_Type_List2_free(tlist); return 0; }