1 /***************************************************************************
2     begin       : Mon Mar 01 2004
3     copyright   : (C) 2018 by Martin Preuss
4     email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  *          Please see toplevel file COPYING for license details           *
8  ***************************************************************************/
9 
10 
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14 
15 #include "aqbanking/i18n_l.h"
16 #include "user_p.h"
17 #include "hbci_l.h"
18 #include "provider_l.h"
19 #include "hbci-updates_l.h"
20 #include "msgengine_l.h"
21 #include "tanmethod_l.h"
22 #include "aqhbci/banking/provider.h"
23 #include "adminjobs_l.h"
24 
25 #include "hhd_l.h"
26 
27 #include <aqbanking/banking_be.h>
28 
29 #include <gwenhywfar/debug.h>
30 #include <gwenhywfar/text.h>
31 
32 #include <assert.h>
33 
34 
GWEN_INHERIT(AB_USER,AH_USER)35 GWEN_INHERIT(AB_USER, AH_USER)
36 
37 
38 const char *AH_User_Status_toString(AH_USER_STATUS st)
39 {
40   switch (st) {
41   case AH_UserStatusNew:
42     return "new";
43   case AH_UserStatusEnabled:
44     return "enabled";
45   case AH_UserStatusPending:
46     return "pending";
47   case AH_UserStatusDisabled:
48     return "disabled";
49   default:
50     return "unknown";
51   } /* switch */
52 }
53 
54 
55 
AH_User_Status_fromString(const char * s)56 AH_USER_STATUS AH_User_Status_fromString(const char *s)
57 {
58   assert(s);
59   if (strcasecmp(s, "new")==0)
60     return AH_UserStatusNew;
61   else if (strcasecmp(s, "enabled")==0)
62     return AH_UserStatusEnabled;
63   else if (strcasecmp(s, "pending")==0)
64     return AH_UserStatusPending;
65   else if (strcasecmp(s, "disabled")==0)
66     return AH_UserStatusDisabled;
67   else
68     return AH_UserStatusUnknown;
69 }
70 
71 
72 
AH_User_Flags_toDb(GWEN_DB_NODE * db,const char * name,uint32_t flags)73 void AH_User_Flags_toDb(GWEN_DB_NODE *db, const char *name,
74                         uint32_t flags)
75 {
76   GWEN_DB_DeleteVar(db, name);
77   if (flags & AH_USER_FLAGS_BANK_DOESNT_SIGN)
78     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "bankDoesntSign");
79   if (flags & AH_USER_FLAGS_BANK_USES_SIGNSEQ)
80     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "bankUsesSignSeq");
81   if (flags & AH_USER_FLAGS_IGNORE_UPD)
82     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "ignoreUpd");
83   if (flags & AH_USER_FLAGS_NO_BASE64)
84     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "noBase64");
85   if (flags & AH_USER_FLAGS_KEEP_MULTIPLE_BLANKS)
86     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "keepMultipleBlanks");
87   if (flags & AH_USER_FLAGS_TAN_OMIT_SMS_ACCOUNT)
88     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "omitSmsAccount");
89   if (flags & AH_USER_FLAGS_USE_STRICT_SEPA_CHARSET)
90     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "useStrictSepaCharset");
91   if (flags & AH_USER_FLAGS_VERIFY_NO_BANKSIGNKEY)
92     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT, name, "verifyNoBankSignKey");
93 }
94 
95 
96 
AH_User_Flags_fromDb(GWEN_DB_NODE * db,const char * name)97 uint32_t AH_User_Flags_fromDb(GWEN_DB_NODE *db, const char *name)
98 {
99   uint32_t fl=0;
100   int i;
101 
102   for (i=0; ; i++) {
103     const char *s;
104 
105     s=GWEN_DB_GetCharValue(db, name, i, 0);
106     if (!s)
107       break;
108     if (strcasecmp(s, "bankDoesntSign")==0)
109       fl|=AH_USER_FLAGS_BANK_DOESNT_SIGN;
110     else if (strcasecmp(s, "bankUsesSignSeq")==0)
111       fl|=AH_USER_FLAGS_BANK_USES_SIGNSEQ;
112     else if (strcasecmp(s, "ignoreUpd")==0)
113       fl|=AH_USER_FLAGS_IGNORE_UPD;
114     else if (strcasecmp(s, "noBase64")==0)
115       fl|=AH_USER_FLAGS_NO_BASE64;
116     else if (strcasecmp(s, "keepMultipleBlanks")==0)
117       fl|=AH_USER_FLAGS_KEEP_MULTIPLE_BLANKS;
118     else if (strcasecmp(s, "omitSmsAccount")==0)
119       fl|=AH_USER_FLAGS_TAN_OMIT_SMS_ACCOUNT;
120     else if (strcasecmp(s, "useStrictSepaCharset")==0)
121       fl|=AH_USER_FLAGS_USE_STRICT_SEPA_CHARSET;
122     else if (strcasecmp(s, "tlsIgnPrematureClose")==0) {
123       DBG_INFO(AQHBCI_LOGDOMAIN, "Flag \"tlsIgnPrematureClose\" is default now, ignoring.");
124     }
125     else if (strcasecmp(s, "verifyNoBankSignKey")==0)
126       fl|=AH_USER_FLAGS_VERIFY_NO_BANKSIGNKEY;
127     else {
128       DBG_WARN(AQHBCI_LOGDOMAIN, "Unknown user flag \"%s\"", s);
129     }
130   }
131 
132   return fl;
133 }
134 
135 
136 
137 
138 
AH_User_new(AB_PROVIDER * pro)139 AB_USER *AH_User_new(AB_PROVIDER *pro)
140 {
141   AB_USER *u;
142   AH_USER *ue;
143 
144   assert(pro);
145   u=AB_User_new();
146   assert(u);
147   GWEN_NEW_OBJECT(AH_USER, ue);
148   GWEN_INHERIT_SETDATA(AB_USER, AH_USER, u, ue, AH_User_freeData);
149 
150   AB_User_SetProvider(u, pro);
151   AB_User_SetBackendName(u, "aqhbci");
152 
153   ue->readFromDbFn=AB_User_SetReadFromDbFn(u, AH_User_ReadFromDb);
154   ue->writeToDbFn=AB_User_SetWriteToDbFn(u, AH_User_WriteToDb);
155 
156   ue->tanMethodList[0]=-1;
157   ue->tanMethodCount=0;
158 
159   ue->hbci=AH_Provider_GetHbci(pro);
160   ue->tanMethodDescriptions=AH_TanMethod_List_new();
161   ue->sepaDescriptors=GWEN_StringList_new();
162 
163   AB_User_SetCountry(u, "de");
164 
165   ue->msgEngine=AH_MsgEngine_new();
166   GWEN_MsgEngine_SetEscapeChar(ue->msgEngine, '?');
167   GWEN_MsgEngine_SetCharsToEscape(ue->msgEngine, ":+\'@");
168   AH_MsgEngine_SetUser(ue->msgEngine, u);
169   GWEN_MsgEngine_SetDefinitions(ue->msgEngine, AH_HBCI_GetDefinitions(ue->hbci), 0);
170 
171   ue->hbciVersion=210;
172   ue->bpd=AH_Bpd_new();
173   ue->dbUpd=GWEN_DB_Group_new("upd");
174   ue->maxTransfersPerJob=AH_USER_MAX_TRANSFERS_PER_JOB;
175   ue->maxDebitNotesPerJob=AH_USER_MAX_DEBITNOTES_PER_JOB;
176 
177   return u;
178 }
179 
180 
181 
AH_User_freeData(void * bp,void * p)182 void GWENHYWFAR_CB AH_User_freeData(void *bp, void *p)
183 {
184   AH_USER *ue;
185 
186   ue=(AH_USER *)p;
187   free(ue->tanMediumId);
188   free(ue->peerId);
189   free(ue->systemId);
190   free(ue->httpContentType);
191   free(ue->httpUserAgent);
192   free(ue->tokenType);
193   free(ue->tokenName);
194   free(ue->prompt);
195   GWEN_Url_free(ue->serverUrl);
196   GWEN_DB_Group_free(ue->dbUpd);
197   GWEN_Crypt_Key_free(ue->bankPubSignKey);
198   GWEN_Crypt_Key_free(ue->bankPubCryptKey);
199   AH_Bpd_free(ue->bpd);
200   GWEN_MsgEngine_free(ue->msgEngine);
201   AH_TanMethod_List_free(ue->tanMethodDescriptions);
202   GWEN_StringList_free(ue->sepaDescriptors);
203   GWEN_FREE_OBJECT(ue);
204 }
205 
206 
207 
AH_User_ReadFromDb(AB_USER * u,GWEN_DB_NODE * db)208 int AH_User_ReadFromDb(AB_USER *u, GWEN_DB_NODE *db)
209 {
210   AH_USER *ue;
211   int rv;
212   GWEN_DB_NODE *dbP;
213   AB_PROVIDER *pro;
214 
215   assert(u);
216   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
217   assert(ue);
218 
219   DBG_INFO(AQHBCI_LOGDOMAIN, "Reading user from db (%u)", (unsigned int) GWEN_DB_GetIntValue(db, "uniqueId", 0, 0));
220 
221   /* save provider, because AB_User_ReadFromDb clears it */
222   pro=AB_User_GetProvider(u);
223 
224   /* read data for base class */
225   rv=(ue->readFromDbFn)(u, db);
226   if (rv<0) {
227     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
228     return rv;
229   }
230 
231   /* set provider again */
232   AB_User_SetProvider(u, pro);
233 
234   /* read data for provider */
235   dbP=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "data/backend");
236   AH_User__ReadDb(u, dbP);
237 
238   AH_User_LoadTanMethods(u);
239   AH_User_LoadSepaDescriptors(u);
240 
241   return 0;
242 }
243 
244 
245 
AH_User_WriteToDb(const AB_USER * u,GWEN_DB_NODE * db)246 int AH_User_WriteToDb(const AB_USER *u, GWEN_DB_NODE *db)
247 {
248   AH_USER *ue;
249   int rv;
250   GWEN_DB_NODE *dbP;
251 
252   assert(u);
253   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
254   assert(ue);
255 
256   DBG_INFO(AQHBCI_LOGDOMAIN, "Writing user db (%u)", (unsigned int) AB_User_GetUniqueId(u));
257 
258   /* write data for base class */
259   rv=(ue->writeToDbFn)(u, db);
260   if (rv<0) {
261     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
262     return rv;
263   }
264 
265 
266   /* write data for provider */
267   dbP=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "data/backend");
268   AH_User__WriteDb(u, dbP);
269 
270   return 0;
271 }
272 
273 
274 
AH_User__ReadDb(AB_USER * u,GWEN_DB_NODE * db)275 void AH_User__ReadDb(AB_USER *u, GWEN_DB_NODE *db)
276 {
277   AH_USER *ue;
278   const char *s;
279   GWEN_DB_NODE *gr;
280   int i;
281 
282   DBG_INFO(AQHBCI_LOGDOMAIN, "Reading HBCI data for user (%u)", (unsigned int) AB_User_GetUniqueId(u));
283 
284   assert(u);
285   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
286   assert(ue);
287 
288   s=GWEN_DB_GetCharValue(db, "cryptMode", 0, "unknown");
289   ue->cryptMode=AH_CryptMode_fromString(s);
290 
291   s=GWEN_DB_GetCharValue(db, "status", 0, "unknown");
292   ue->status=AH_User_Status_fromString(s);
293 
294   ue->hbciVersion=GWEN_DB_GetIntValue(db, "hbciVersion", 0, 210);
295 
296   ue->selectedTanInputMechanism=GWEN_DB_GetIntValue(db, "selectedTanInputMechanism", 0, 0);
297 
298   /* load server address */
299   GWEN_Url_free(ue->serverUrl);
300   s=GWEN_DB_GetCharValue(db, "server", 0, 0);
301   if (s) {
302     ue->serverUrl=GWEN_Url_fromString(s);
303     assert(ue->serverUrl);
304     if (GWEN_Url_GetPort(ue->serverUrl)==0) {
305       if (AH_User_GetCryptMode(u)==AH_CryptMode_Pintan) {
306         GWEN_Url_SetPort(ue->serverUrl, 443);
307         GWEN_Url_SetProtocol(ue->serverUrl, "https");
308       }
309       else {
310         GWEN_Url_SetProtocol(ue->serverUrl, "hbci");
311         GWEN_Url_SetPort(ue->serverUrl, 3000);
312       }
313     }
314   }
315   else
316     ue->serverUrl=NULL;
317 
318   /* load bankPubCryptKey */
319   GWEN_Crypt_Key_free(ue->bankPubCryptKey);
320   gr=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "bankPubCryptKey");
321   if (gr==NULL)
322     gr=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "bankPubKey");
323   if (gr) {
324     ue->bankPubCryptKey=GWEN_Crypt_KeyRsa_fromDb(gr);
325     assert(ue->bankPubCryptKey);
326   }
327   else
328     ue->bankPubCryptKey=NULL;
329 
330   /* load bankPubKey */
331   GWEN_Crypt_Key_free(ue->bankPubSignKey);
332   gr=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "bankPubSignKey");
333   if (gr) {
334     ue->bankPubSignKey=GWEN_Crypt_KeyRsa_fromDb(gr);
335     assert(ue->bankPubSignKey);
336   }
337   else
338     ue->bankPubSignKey=NULL;
339 
340   /* load BPD */
341   AH_Bpd_free(ue->bpd);
342   gr=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "bpd");
343   if (gr) {
344     ue->bpd=AH_Bpd_FromDb(gr);
345     assert(ue->bpd);
346   }
347   else
348     ue->bpd=AH_Bpd_new();
349 
350   /* load UPD */
351   if (ue->dbUpd)
352     GWEN_DB_Group_free(ue->dbUpd);
353   gr=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "upd");
354   if (gr) {
355     ue->dbUpd=GWEN_DB_Group_dup(gr);
356   }
357   else
358     ue->dbUpd=GWEN_DB_Group_new("upd");
359 
360   /* get peer id */
361   free(ue->peerId);
362   s=GWEN_DB_GetCharValue(db, "peerId", 0, 0);
363   if (s)
364     ue->peerId=strdup(s);
365   else
366     ue->peerId=NULL;
367 
368   /* get system id */
369   free(ue->systemId);
370   s=GWEN_DB_GetCharValue(db, "systemId", 0, 0);
371   if (s)
372     ue->systemId=strdup(s);
373   else
374     ue->systemId=NULL;
375 
376   ue->updVersion=GWEN_DB_GetIntValue(db, "updVersion", 0, 0);
377 
378   /* setup HTTP version */
379   ue->httpVMajor=GWEN_DB_GetIntValue(db, "httpVMajor", 0, -1);
380   ue->httpVMinor=GWEN_DB_GetIntValue(db, "httpVMinor", 0, -1);
381   if (ue->httpVMajor==-1 || ue->httpVMinor==-1) {
382     ue->httpVMajor=1;
383     ue->httpVMinor=0;
384   }
385 
386   free(ue->httpContentType);
387   s=GWEN_DB_GetCharValue(db, "httpContentType", 0, 0);
388   if (s)
389     ue->httpContentType=strdup(s);
390   else
391     ue->httpContentType=NULL;
392 
393   /* read user flags */
394   ue->flags=AH_User_Flags_fromDb(db, "userFlags");
395 
396   /* setup medium stuff */
397   free(ue->tokenType);
398   s=GWEN_DB_GetCharValue(db, "tokenType", 0, 0);
399   if (s)
400     ue->tokenType=strdup(s);
401   else
402     ue->tokenType=NULL;
403 
404   free(ue->tokenName);
405   s=GWEN_DB_GetCharValue(db, "tokenName", 0, 0);
406   if (s)
407     ue->tokenName=strdup(s);
408   else
409     ue->tokenName=NULL;
410 
411   ue->tokenContextId=GWEN_DB_GetIntValue(db, "tokenContextId", 0, 1);
412 
413   /* get rdh type */
414   ue->rdhType=GWEN_DB_GetIntValue(db, "rdhType", 0, -1);
415   if (ue->rdhType<1)
416     ue->rdhType=1;
417 
418   /* read supported TAN methods */
419   DBG_INFO(AQHBCI_LOGDOMAIN, "Reading supported TAN methods (max %d)", AH_USER_MAX_TANMETHODS);
420   for (i=0; i<AH_USER_MAX_TANMETHODS; i++)
421     ue->tanMethodList[i]=-1;
422   ue->tanMethodCount=0;
423 
424   for (i=0; i<AH_USER_MAX_TANMETHODS; i++) {
425     int method;
426 
427     method=GWEN_DB_GetIntValue(db, "tanMethodList", i, -1);
428     if (method==-1)
429       break;
430     ue->tanMethodList[ue->tanMethodCount++]=method;
431     /*ue->tanMethodList[ue->tanMethodCount]=-1;*/
432     DBG_INFO(AQHBCI_LOGDOMAIN, "- added TAN method %d (%d)", method, ue->tanMethodCount);
433   }
434 
435   ue->selectedTanMethod=GWEN_DB_GetIntValue(db, "selectedTanMethod", 0, 0);
436 
437   /* read some settings */
438   ue->maxTransfersPerJob=GWEN_DB_GetIntValue(db, "maxTransfersPerJob", 0, AH_USER_MAX_TRANSFERS_PER_JOB);
439   ue->maxDebitNotesPerJob=GWEN_DB_GetIntValue(db, "maxDebitNotesPerJob", 0, AH_USER_MAX_DEBITNOTES_PER_JOB);
440 
441   free(ue->sepaTransferProfile);
442   s=GWEN_DB_GetCharValue(db, "sepaTransferProfile", 0, NULL);
443   if (s)
444     ue->sepaTransferProfile=strdup(s);
445   else
446     ue->sepaTransferProfile=NULL;
447 
448   free(ue->sepaDebitNoteProfile);
449   s=GWEN_DB_GetCharValue(db, "sepaDebitNoteProfile", 0, NULL);
450   if (s)
451     ue->sepaDebitNoteProfile=strdup(s);
452   else
453     ue->sepaDebitNoteProfile=NULL;
454 
455   free(ue->tanMediumId);
456   s=GWEN_DB_GetCharValue(db, "tanMediumId", 0, NULL);
457   if (s)
458     ue->tanMediumId=strdup(s);
459   else
460     ue->tanMediumId=NULL;
461 }
462 
463 
464 
AH_User__WriteDb(const AB_USER * u,GWEN_DB_NODE * db)465 void AH_User__WriteDb(const AB_USER *u, GWEN_DB_NODE *db)
466 {
467   const AH_USER *ue;
468   int i;
469   GWEN_DB_NODE *gr;
470   const char *s;
471 
472   assert(u);
473   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
474   assert(ue);
475 
476   DBG_INFO(AQHBCI_LOGDOMAIN, "Writing HBCI data for user (%u)", (unsigned int) AB_User_GetUniqueId(u));
477 
478   /* save crypt mode */
479   s=AH_CryptMode_toString(ue->cryptMode);
480   GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
481                        "cryptMode", s);
482 
483   /* save status */
484   s=AH_User_Status_toString(ue->status);
485   GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
486                        "status", s);
487 
488   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
489                       "hbciVersion", ue->hbciVersion);
490 
491   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
492                       "selectedTanInputMechanism", ue->selectedTanInputMechanism);
493 
494   if (ue->httpContentType)
495     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
496                          "httpContentType", ue->httpContentType);
497   else
498     GWEN_DB_DeleteVar(db, "httpContentType");
499 
500   /* save URL */
501   if (ue->serverUrl) {
502     GWEN_BUFFER *nbuf;
503 
504     nbuf=GWEN_Buffer_new(0, 256, 0, 1);
505     if (GWEN_Url_toString(ue->serverUrl, nbuf)) {
506       DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not store url");
507       GWEN_Buffer_free(nbuf);
508       assert(0);
509     }
510     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
511                          "server", GWEN_Buffer_GetStart(nbuf));
512     GWEN_Buffer_free(nbuf);
513   } /* if serverUrl */
514 
515   /* save bankPubCryptKey */
516   if (ue->bankPubCryptKey) {
517     assert(ue->bankPubCryptKey);
518     gr=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "bankPubCryptKey");
519     assert(gr);
520     GWEN_Crypt_KeyRsa_toDb(ue->bankPubCryptKey, gr, 1);
521   }
522   else
523     GWEN_DB_DeleteVar(db, "bankPubCryptKey");
524 
525   /* save bankPubSignKey */
526   if (ue->bankPubSignKey) {
527     assert(ue->bankPubSignKey);
528     gr=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "bankPubSignKey");
529     assert(gr);
530     GWEN_Crypt_KeyRsa_toDb(ue->bankPubSignKey, gr, 1);
531   }
532   else
533     GWEN_DB_DeleteVar(db, "bankPubSignKey");
534 
535   /* save BPD */
536   assert(ue->bpd);
537   gr=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "bpd");
538   assert(gr);
539   AH_Bpd_ToDb(ue->bpd, gr);
540 
541   /* save UPD */
542   if (ue->dbUpd) {
543     gr=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "upd");
544     assert(gr);
545     GWEN_DB_AddGroupChildren(gr, ue->dbUpd);
546   }
547 
548   if (ue->peerId)
549     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
550                          "peerId", ue->peerId);
551 
552   if (ue->systemId)
553     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
554                          "systemId", ue->systemId);
555 
556   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
557                       "updVersion", ue->updVersion);
558 
559   /* save http settings */
560   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
561                       "httpVMajor", ue->httpVMajor);
562   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
563                       "httpVMinor", ue->httpVMinor);
564   if (ue->httpUserAgent)
565     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
566                          "httpUserAgent", ue->httpUserAgent);
567 
568   /* save flags */
569   AH_User_Flags_toDb(db, "userFlags", ue->flags);
570 
571   /* save crypt token settings */
572   if (ue->tokenType)
573     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
574                          "tokenType", ue->tokenType);
575   if (ue->tokenName)
576     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
577                          "tokenName", ue->tokenName);
578   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
579                       "tokenContextId", ue->tokenContextId);
580   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
581                       "rdhType", ue->rdhType);
582 
583   /* store list of supported/allowed tan methods */
584   GWEN_DB_DeleteVar(db, "tanMethodList");
585   for (i=0; i<ue->tanMethodCount; i++) {
586     if (ue->tanMethodList[i]==-1)
587       break;
588     GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_DEFAULT,
589                         "tanMethodList",
590                         ue->tanMethodList[i]);
591   }
592 
593   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
594                       "selectedTanMethod",
595                       ue->selectedTanMethod);
596 
597   /* store some settings */
598   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
599                       "maxTransfersPerJob",
600                       ue->maxTransfersPerJob);
601   GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
602                       "maxDebitNotesPerJob",
603                       ue->maxDebitNotesPerJob);
604   if (ue->sepaTransferProfile)
605     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
606                          "sepaTransferProfile", ue->sepaTransferProfile);
607   if (ue->sepaDebitNoteProfile)
608     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
609                          "sepaDebitNoteProfile", ue->sepaDebitNoteProfile);
610   if (ue->tanMediumId)
611     GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS,
612                          "tanMediumId", ue->tanMediumId);
613 }
614 
615 
616 
AH_User_GetPeerId(const AB_USER * u)617 const char *AH_User_GetPeerId(const AB_USER *u)
618 {
619   AH_USER *ue;
620 
621   assert(u);
622   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
623   assert(ue);
624 
625   return ue->peerId;
626 }
627 
628 
629 
AH_User_SetPeerId(AB_USER * u,const char * s)630 void AH_User_SetPeerId(AB_USER *u, const char *s)
631 {
632   AH_USER *ue;
633 
634   assert(u);
635   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
636   assert(ue);
637 
638   free(ue->peerId);
639   if (s)
640     ue->peerId=strdup(s);
641   else
642     ue->peerId=NULL;
643 }
644 
645 
646 
AH_User_GetTokenContextId(const AB_USER * u)647 uint32_t AH_User_GetTokenContextId(const AB_USER *u)
648 {
649   AH_USER *ue;
650 
651   assert(u);
652   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
653   assert(ue);
654 
655   return ue->tokenContextId;
656 }
657 
658 
659 
AH_User_SetTokenContextId(AB_USER * u,uint32_t id)660 void AH_User_SetTokenContextId(AB_USER *u, uint32_t id)
661 {
662   AH_USER *ue;
663 
664   assert(u);
665   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
666   assert(ue);
667 
668   ue->tokenContextId=id;
669 }
670 
671 
672 
AH_User_GetCryptMode(const AB_USER * u)673 AH_CRYPT_MODE AH_User_GetCryptMode(const AB_USER *u)
674 {
675   AH_USER *ue;
676 
677   assert(u);
678   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
679   assert(ue);
680 
681   return ue->cryptMode;
682 }
683 
684 
685 
AH_User_SetCryptMode(AB_USER * u,AH_CRYPT_MODE m)686 void AH_User_SetCryptMode(AB_USER *u, AH_CRYPT_MODE m)
687 {
688   AH_USER *ue;
689 
690   assert(u);
691   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
692   assert(ue);
693 
694   ue->cryptMode=m;
695 }
696 
697 
698 
AH_User_GetStatus(const AB_USER * u)699 AH_USER_STATUS AH_User_GetStatus(const AB_USER *u)
700 {
701   AH_USER *ue;
702 
703   assert(u);
704   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
705   assert(ue);
706 
707   return ue->status;
708 }
709 
710 
711 
AH_User_SetStatus(AB_USER * u,AH_USER_STATUS i)712 void AH_User_SetStatus(AB_USER *u, AH_USER_STATUS i)
713 {
714   AH_USER *ue;
715 
716   assert(u);
717   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
718   assert(ue);
719 
720   ue->status=i;
721 }
722 
723 
724 
AH_User_GetHbci(const AB_USER * u)725 AH_HBCI *AH_User_GetHbci(const AB_USER *u)
726 {
727   AH_USER *ue;
728 
729   assert(u);
730   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
731   assert(ue);
732 
733   return ue->hbci;
734 }
735 
736 
737 
AH_User_GetServerUrl(const AB_USER * u)738 const GWEN_URL *AH_User_GetServerUrl(const AB_USER *u)
739 {
740   AH_USER *ue;
741 
742   assert(u);
743   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
744   assert(ue);
745 
746   return ue->serverUrl;
747 }
748 
749 
750 
AH_User_SetServerUrl(AB_USER * u,const GWEN_URL * url)751 void AH_User_SetServerUrl(AB_USER *u, const GWEN_URL *url)
752 {
753   AH_USER *ue;
754 
755   assert(u);
756   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
757   assert(ue);
758 
759   GWEN_Url_free(ue->serverUrl);
760   if (url)
761     ue->serverUrl=GWEN_Url_dup(url);
762   else
763     ue->serverUrl=0;
764 }
765 
766 
767 
AH_User_GetUpdVersion(const AB_USER * u)768 int AH_User_GetUpdVersion(const AB_USER *u)
769 {
770   AH_USER *ue;
771 
772   assert(u);
773   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
774   assert(ue);
775 
776   return ue->updVersion;
777 }
778 
779 
780 
AH_User_SetUpdVersion(AB_USER * u,int i)781 void AH_User_SetUpdVersion(AB_USER *u, int i)
782 {
783   AH_USER *ue;
784 
785   assert(u);
786   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
787   assert(ue);
788 
789   ue->updVersion=i;
790 }
791 
792 
793 
AH_User_GetUpd(const AB_USER * u)794 GWEN_DB_NODE *AH_User_GetUpd(const AB_USER *u)
795 {
796   AH_USER *ue;
797 
798   assert(u);
799   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
800   assert(ue);
801 
802   return ue->dbUpd;
803 }
804 
805 
806 
AH_User_GetUpdForAccountIdAndSuffix(const AB_USER * u,const char * sAccountNumber,const char * sAccountSuffix)807 GWEN_DB_NODE *AH_User_GetUpdForAccountIdAndSuffix(const AB_USER *u,
808                                                   const char *sAccountNumber,
809                                                   const char *sAccountSuffix)
810 {
811   AH_USER *ue;
812   GWEN_DB_NODE *db;
813   GWEN_BUFFER *tbuf;
814 
815   assert(u);
816   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
817   assert(ue);
818 
819   db=AH_User_GetUpd(u);
820   if (db==NULL) {
821     DBG_INFO(AQHBCI_LOGDOMAIN, "No upd");
822     return NULL;
823   }
824 
825   tbuf=GWEN_Buffer_new(0, 64, 0, 1);
826   GWEN_Buffer_AppendString(tbuf, sAccountNumber);
827   GWEN_Buffer_AppendString(tbuf, "-");
828   /* take into account the "Unterkontomerkmal", don't rely solely on account id */
829   if (sAccountSuffix && *sAccountSuffix)
830     GWEN_Buffer_AppendString(tbuf, sAccountSuffix);
831   else
832     GWEN_Buffer_AppendString(tbuf, "none");
833   DBG_INFO(AQHBCI_LOGDOMAIN, "Checking upd for account \"%s\"", GWEN_Buffer_GetStart(tbuf));
834   db=GWEN_DB_GetGroup(db,
835                       GWEN_PATH_FLAGS_NAMEMUSTEXIST,
836                       GWEN_Buffer_GetStart(tbuf));
837   GWEN_Buffer_free(tbuf);
838 
839   if (db==NULL) {
840     DBG_INFO(AQHBCI_LOGDOMAIN, "Falling back to old storage of UPD for account \"%s\"", sAccountNumber);
841     db=AH_User_GetUpd(u);
842     db=GWEN_DB_GetGroup(db,
843                         GWEN_PATH_FLAGS_NAMEMUSTEXIST,
844                         sAccountNumber);
845   }
846 
847   return db;
848 }
849 
850 
851 
AH_User_GetUpdForAccount(const AB_USER * u,const AB_ACCOUNT * acc)852 GWEN_DB_NODE *AH_User_GetUpdForAccount(const AB_USER *u, const AB_ACCOUNT *acc)
853 {
854   GWEN_DB_NODE *db=NULL;
855 
856   db=AH_User_GetUpdForAccountUniqueId(u, AB_Account_GetUniqueId(acc));
857   if (db==NULL) {
858     DBG_INFO(AQHBCI_LOGDOMAIN,
859              "Falling back to previous storage of UPD for account \"%u\"",
860              AB_Account_GetUniqueId(acc));
861     db=AH_User_GetUpdForAccountIdAndSuffix(u,
862                                            AB_Account_GetAccountNumber(acc),
863                                            AB_Account_GetSubAccountId(acc));
864   }
865 
866   return db;
867 }
868 
869 
870 
AH_User_GetUpdForAccountUniqueId(const AB_USER * u,uint32_t uid)871 GWEN_DB_NODE *AH_User_GetUpdForAccountUniqueId(const AB_USER *u, uint32_t uid)
872 {
873   AH_USER *ue;
874   GWEN_DB_NODE *db;
875   char numbuf[32];
876 
877   assert(u);
878   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
879   assert(ue);
880 
881   db=AH_User_GetUpd(u);
882   if (db==NULL) {
883     DBG_INFO(AQHBCI_LOGDOMAIN, "No upd");
884     return NULL;
885   }
886 
887   snprintf(numbuf, sizeof(numbuf)-1, "uaid-%08" PRIx32,
888            uid);
889   numbuf[sizeof(numbuf)-1]=0;
890 
891   DBG_INFO(AQHBCI_LOGDOMAIN, "Checking upd for \"%s\"", numbuf);
892   db=GWEN_DB_GetGroup(db,
893                       GWEN_PATH_FLAGS_NAMEMUSTEXIST,
894                       numbuf);
895 
896   return db;
897 }
898 
899 
900 
AH_User_GetBankPubCryptKey(const AB_USER * u)901 GWEN_CRYPT_KEY *AH_User_GetBankPubCryptKey(const AB_USER *u)
902 {
903   AH_USER *ue;
904 
905   assert(u);
906   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
907   assert(ue);
908 
909   return ue->bankPubCryptKey;
910 }
911 
AH_User_SetBankPubCryptKey(AB_USER * u,GWEN_CRYPT_KEY * bankPubCryptKey)912 void AH_User_SetBankPubCryptKey(AB_USER *u, GWEN_CRYPT_KEY *bankPubCryptKey)
913 {
914   AH_USER *ue;
915 
916   assert(bankPubCryptKey);
917   assert(u);
918   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
919   assert(ue);
920 
921   if (ue->bankPubCryptKey!=bankPubCryptKey) {
922     //GWEN_Crypt_KeyRsa_free(ue->bankPubKey);
923     if (ue->bankPubCryptKey)
924       GWEN_Crypt_Key_free(ue->bankPubCryptKey);
925     ue->bankPubCryptKey=GWEN_Crypt_KeyRsa_dup(bankPubCryptKey);
926   }
927 }
928 
AH_User_GetBankPubSignKey(const AB_USER * u)929 GWEN_CRYPT_KEY *AH_User_GetBankPubSignKey(const AB_USER *u)
930 {
931   AH_USER *ue;
932 
933   assert(u);
934   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
935   assert(ue);
936 
937   return ue->bankPubSignKey;
938 }
939 
AH_User_SetBankPubSignKey(AB_USER * u,GWEN_CRYPT_KEY * bankPubSignKey)940 void AH_User_SetBankPubSignKey(AB_USER *u, GWEN_CRYPT_KEY *bankPubSignKey)
941 {
942   AH_USER *ue;
943 
944   assert(bankPubSignKey);
945   assert(u);
946   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
947   assert(ue);
948 
949   if (ue->bankPubSignKey!=bankPubSignKey) {
950     //GWEN_Crypt_KeyRsa_free(ue->bankPubKey);
951     if (ue->bankPubSignKey)
952       GWEN_Crypt_Key_free(ue->bankPubSignKey);
953     ue->bankPubSignKey=GWEN_Crypt_KeyRsa_dup(bankPubSignKey);
954   }
955 }
956 
AH_User_GetBpd(const AB_USER * u)957 AH_BPD *AH_User_GetBpd(const AB_USER *u)
958 {
959   AH_USER *ue;
960 
961   assert(u);
962   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
963   assert(ue);
964 
965   return ue->bpd;
966 }
967 
AH_User_SetBpd(AB_USER * u,AH_BPD * bpd)968 void AH_User_SetBpd(AB_USER *u, AH_BPD *bpd)
969 {
970   AH_USER *ue;
971 
972   assert(bpd);
973   assert(u);
974   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
975   assert(ue);
976 
977   if (ue->bpd!=bpd) {
978     AH_Bpd_free(ue->bpd);
979     ue->bpd=AH_Bpd_dup(bpd);
980   }
981 }
982 
983 
984 
AH_User_GetBpdVersion(const AB_USER * u)985 int AH_User_GetBpdVersion(const AB_USER *u)
986 {
987   AH_USER *ue;
988 
989   assert(u);
990   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
991   assert(ue);
992 
993   assert(ue->bpd);
994   return AH_Bpd_GetBpdVersion(ue->bpd);
995 }
996 
997 
998 
AH_User_SetBpdVersion(AB_USER * u,int i)999 void AH_User_SetBpdVersion(AB_USER *u, int i)
1000 {
1001   AH_USER *ue;
1002 
1003   assert(u);
1004   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1005   assert(ue);
1006 
1007   assert(ue->bpd);
1008   AH_Bpd_SetBpdVersion(ue->bpd, i);
1009 }
1010 
1011 
1012 
AH_User_GetBpdJobForParamNameAndVersion(const AB_USER * u,const char * paramName,int version)1013 GWEN_DB_NODE *AH_User_GetBpdJobForParamNameAndVersion(const AB_USER *u, const char *paramName, int version)
1014 {
1015   AH_USER *ue;
1016 
1017   assert(u);
1018   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1019   assert(ue);
1020 
1021   if (ue->bpd) {
1022     GWEN_DB_NODE *dbJob;
1023 
1024     dbJob=AH_Bpd_GetBpdJobs(ue->bpd, ue->hbciVersion);
1025     if (dbJob) {
1026       dbJob=GWEN_DB_GetGroup(dbJob, GWEN_PATH_FLAGS_NAMEMUSTEXIST, paramName);
1027       if (dbJob) {
1028         char numbuf[64];
1029 
1030         if (snprintf(numbuf, sizeof(numbuf), "%d", version)>=sizeof(numbuf)) {
1031           DBG_ERROR(AQHBCI_LOGDOMAIN, "Error writing version number to buffer!");
1032           return NULL;
1033         }
1034         dbJob=GWEN_DB_GetGroup(dbJob, GWEN_PATH_FLAGS_NAMEMUSTEXIST, numbuf);
1035         if (dbJob)
1036           return dbJob;
1037       }
1038     }
1039   }
1040 
1041   return NULL;
1042 }
1043 
1044 
1045 
AH_User_GetSystemId(const AB_USER * u)1046 const char *AH_User_GetSystemId(const AB_USER *u)
1047 {
1048   AH_USER *ue;
1049 
1050   assert(u);
1051   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1052   assert(ue);
1053 
1054   return ue->systemId;
1055 }
1056 
1057 
1058 
AH_User_SetSystemId(AB_USER * u,const char * s)1059 void AH_User_SetSystemId(AB_USER *u, const char *s)
1060 {
1061   AH_USER *ue;
1062 
1063   assert(u);
1064   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1065   assert(ue);
1066 
1067   free(ue->systemId);
1068   if (s)
1069     ue->systemId=strdup(s);
1070   else
1071     ue->systemId=NULL;
1072 }
1073 
1074 
1075 
AH_User_GetMsgEngine(const AB_USER * u)1076 GWEN_MSGENGINE *AH_User_GetMsgEngine(const AB_USER *u)
1077 {
1078   AH_USER *ue;
1079 
1080   assert(u);
1081   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1082   assert(ue);
1083 
1084   return ue->msgEngine;
1085 }
1086 
1087 
1088 
AH_User_GetFlags(const AB_USER * u)1089 uint32_t AH_User_GetFlags(const AB_USER *u)
1090 {
1091   AH_USER *ue;
1092 
1093   assert(u);
1094   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1095   assert(ue);
1096 
1097   return ue->flags;
1098 }
1099 
1100 
1101 
AH_User_SetFlags(AB_USER * u,uint32_t flags)1102 void AH_User_SetFlags(AB_USER *u, uint32_t flags)
1103 {
1104   AH_USER *ue;
1105 
1106   assert(u);
1107   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1108   assert(ue);
1109 
1110   ue->flags=flags;
1111 }
1112 
1113 
1114 
AH_User_AddFlags(AB_USER * u,uint32_t flags)1115 void AH_User_AddFlags(AB_USER *u, uint32_t flags)
1116 {
1117   AH_USER *ue;
1118 
1119   assert(u);
1120   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1121   assert(ue);
1122 
1123   ue->flags|=flags;
1124 }
1125 
1126 
1127 
AH_User_SubFlags(AB_USER * u,uint32_t flags)1128 void AH_User_SubFlags(AB_USER *u, uint32_t flags)
1129 {
1130   AH_USER *ue;
1131 
1132   assert(u);
1133   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1134   assert(ue);
1135 
1136   ue->flags&=~flags;
1137 }
1138 
1139 
1140 
AH_User_GetHbciVersion(const AB_USER * u)1141 int AH_User_GetHbciVersion(const AB_USER *u)
1142 {
1143   AH_USER *ue;
1144 
1145   assert(u);
1146   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1147   assert(ue);
1148 
1149   return ue->hbciVersion;
1150 }
1151 
1152 
1153 
AH_User_SetHbciVersion(AB_USER * u,int i)1154 void AH_User_SetHbciVersion(AB_USER *u, int i)
1155 {
1156   AH_USER *ue;
1157 
1158   assert(u);
1159   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1160   assert(ue);
1161 
1162   ue->hbciVersion=i;
1163 }
1164 
1165 
1166 
AH_User_GetHttpUserAgent(const AB_USER * u)1167 const char *AH_User_GetHttpUserAgent(const AB_USER *u)
1168 {
1169   AH_USER *ue;
1170 
1171   assert(u);
1172   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1173   assert(ue);
1174 
1175   return ue->httpUserAgent;
1176 }
1177 
1178 
1179 
AH_User_SetHttpUserAgent(AB_USER * u,const char * s)1180 void AH_User_SetHttpUserAgent(AB_USER *u, const char *s)
1181 {
1182   AH_USER *ue;
1183 
1184   assert(u);
1185   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1186   assert(ue);
1187 
1188   free(ue->httpUserAgent);
1189   if (s)
1190     ue->httpUserAgent=strdup(s);
1191   else
1192     ue->httpUserAgent=NULL;
1193 }
1194 
1195 
1196 
AH_User_GetHttpVMajor(const AB_USER * u)1197 int AH_User_GetHttpVMajor(const AB_USER *u)
1198 {
1199   AH_USER *ue;
1200 
1201   assert(u);
1202   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1203   assert(ue);
1204 
1205   return ue->httpVMajor;
1206 }
1207 
1208 
1209 
AH_User_SetHttpVMajor(AB_USER * u,int i)1210 void AH_User_SetHttpVMajor(AB_USER *u, int i)
1211 {
1212   AH_USER *ue;
1213 
1214   assert(u);
1215   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1216   assert(ue);
1217 
1218   ue->httpVMajor=i;
1219 }
1220 
1221 
1222 
AH_User_GetHttpVMinor(const AB_USER * u)1223 int AH_User_GetHttpVMinor(const AB_USER *u)
1224 {
1225   AH_USER *ue;
1226 
1227   assert(u);
1228   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1229   assert(ue);
1230 
1231   return ue->httpVMinor;
1232 }
1233 
1234 
1235 
AH_User_SetHttpVMinor(AB_USER * u,int i)1236 void AH_User_SetHttpVMinor(AB_USER *u, int i)
1237 {
1238   AH_USER *ue;
1239 
1240   assert(u);
1241   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1242   assert(ue);
1243 
1244   ue->httpVMinor=i;
1245 }
1246 
1247 
1248 
AH_User_GetTanMethods(const AB_USER * u)1249 uint32_t AH_User_GetTanMethods(const AB_USER *u)
1250 {
1251   AH_USER *ue;
1252 
1253   assert(u);
1254   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1255   assert(ue);
1256 
1257   return ue->tanMethods;
1258 }
1259 
1260 
1261 
AH_User_SetTanMethods(AB_USER * u,uint32_t m)1262 void AH_User_SetTanMethods(AB_USER *u, uint32_t m)
1263 {
1264   AH_USER *ue;
1265 
1266   assert(u);
1267   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1268   assert(ue);
1269 
1270   ue->tanMethods=m;
1271 }
1272 
1273 
1274 
AH_User_AddTanMethods(AB_USER * u,uint32_t m)1275 void AH_User_AddTanMethods(AB_USER *u, uint32_t m)
1276 {
1277   AH_USER *ue;
1278 
1279   assert(u);
1280   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1281   assert(ue);
1282 
1283   ue->tanMethods|=m;
1284 }
1285 
1286 
1287 
AH_User_SubTanMethods(AB_USER * u,uint32_t m)1288 void AH_User_SubTanMethods(AB_USER *u, uint32_t m)
1289 {
1290   AH_USER *ue;
1291 
1292   assert(u);
1293   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1294   assert(ue);
1295 
1296   ue->tanMethods&=~m;
1297 }
1298 
1299 
1300 
AH_User_GetSelectedTanInputMechanism(const AB_USER * u)1301 int AH_User_GetSelectedTanInputMechanism(const AB_USER *u)
1302 {
1303   AH_USER *ue;
1304 
1305   assert(u);
1306   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1307   assert(ue);
1308 
1309   return ue->selectedTanInputMechanism;
1310 }
1311 
1312 
1313 
AH_User_SetSelectedTanInputMechanism(AB_USER * u,int i)1314 void AH_User_SetSelectedTanInputMechanism(AB_USER *u, int i)
1315 {
1316   AH_USER *ue;
1317 
1318   assert(u);
1319   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1320   assert(ue);
1321 
1322   ue->selectedTanInputMechanism=i;
1323 }
1324 
1325 
1326 
AH_User_GetRdhType(const AB_USER * u)1327 int AH_User_GetRdhType(const AB_USER *u)
1328 {
1329   AH_USER *ue;
1330 
1331   assert(u);
1332   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1333   assert(ue);
1334 
1335   return ue->rdhType;
1336 }
1337 
1338 
1339 
AH_User_SetRdhType(AB_USER * u,int i)1340 void AH_User_SetRdhType(AB_USER *u, int i)
1341 {
1342   AH_USER *ue;
1343 
1344   assert(u);
1345   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1346   assert(ue);
1347 
1348   ue->rdhType=i;
1349 }
1350 
1351 
1352 
AH_User_GetTokenType(const AB_USER * u)1353 const char *AH_User_GetTokenType(const AB_USER *u)
1354 {
1355   AH_USER *ue;
1356 
1357   assert(u);
1358   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1359   assert(ue);
1360 
1361   return ue->tokenType;
1362 }
1363 
1364 
1365 
AH_User_SetTokenType(AB_USER * u,const char * s)1366 void AH_User_SetTokenType(AB_USER *u, const char *s)
1367 {
1368   AH_USER *ue;
1369 
1370   assert(u);
1371   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1372   assert(ue);
1373 
1374   free(ue->tokenType);
1375   if (s)
1376     ue->tokenType=strdup(s);
1377   else
1378     ue->tokenType=NULL;
1379 }
1380 
1381 
1382 
AH_User_GetTokenName(const AB_USER * u)1383 const char *AH_User_GetTokenName(const AB_USER *u)
1384 {
1385   AH_USER *ue;
1386 
1387   assert(u);
1388   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1389   assert(ue);
1390 
1391   return ue->tokenName;
1392 }
1393 
1394 
1395 
AH_User_SetTokenName(AB_USER * u,const char * s)1396 void AH_User_SetTokenName(AB_USER *u, const char *s)
1397 {
1398   AH_USER *ue;
1399 
1400   assert(u);
1401   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1402   assert(ue);
1403 
1404   free(ue->tokenName);
1405   if (s)
1406     ue->tokenName=strdup(s);
1407   else
1408     ue->tokenName=NULL;
1409 }
1410 
1411 
1412 
AH_User_MkPasswdName(const AB_USER * u,GWEN_BUFFER * buf)1413 int AH_User_MkPasswdName(const AB_USER *u, GWEN_BUFFER *buf)
1414 {
1415   AH_USER *ue;
1416 
1417   assert(u);
1418   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1419   assert(ue);
1420 
1421   if (ue->tokenType==NULL) {
1422     DBG_ERROR(AQHBCI_LOGDOMAIN, "Missing tokenType or tokenName");
1423     return GWEN_ERROR_NO_DATA;
1424   }
1425 
1426   if (strcasecmp(ue->tokenType, "pintan")==0) {
1427     const char *s;
1428 
1429     GWEN_Buffer_AppendString(buf, "PIN_");
1430     s=AB_User_GetBankCode(u);
1431     if (s)
1432       GWEN_Buffer_AppendString(buf, s);
1433     GWEN_Buffer_AppendString(buf, "_");
1434     GWEN_Buffer_AppendString(buf, AB_User_GetUserId(u));
1435     return 0;
1436   }
1437   else {
1438     if (ue->tokenName) {
1439       GWEN_Buffer_AppendString(buf, "PASSWORD_");
1440       GWEN_Buffer_AppendString(buf, ue->tokenType);
1441       GWEN_Buffer_AppendString(buf, "_");
1442       GWEN_Buffer_AppendString(buf, ue->tokenName);
1443       return 0;
1444     }
1445     else {
1446       DBG_ERROR(AQHBCI_LOGDOMAIN, "Missing tokenName");
1447       return GWEN_ERROR_NO_DATA;
1448     }
1449   }
1450 }
1451 
1452 
1453 
AH_User_MkPinName(const AB_USER * u,GWEN_BUFFER * buf)1454 int AH_User_MkPinName(const AB_USER *u, GWEN_BUFFER *buf)
1455 {
1456   return AH_User_MkPasswdName(u, buf);
1457 }
1458 
1459 
1460 
AH_User_MkTanName(const AB_USER * u,const char * challenge,GWEN_BUFFER * buf)1461 int AH_User_MkTanName(const AB_USER *u,
1462                       const char *challenge,
1463                       GWEN_BUFFER *buf)
1464 {
1465   AH_USER *ue;
1466 
1467   assert(u);
1468   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1469   assert(ue);
1470 
1471   if (ue->tokenType && ue->tokenName) {
1472     GWEN_Buffer_AppendString(buf, "TAN_");
1473     GWEN_Buffer_AppendString(buf, ue->tokenType);
1474     GWEN_Buffer_AppendString(buf, "_");
1475     GWEN_Buffer_AppendString(buf, ue->tokenName);
1476     if (challenge) {
1477       GWEN_Buffer_AppendString(buf, "_");
1478       GWEN_Buffer_AppendString(buf, challenge);
1479     }
1480     return 0;
1481   }
1482   else {
1483     const char *s;
1484 
1485     DBG_DEBUG(AQHBCI_LOGDOMAIN, "No tokenType or tokenName");
1486     GWEN_Buffer_AppendString(buf, "TAN_");
1487     s=AB_User_GetBankCode(u);
1488     if (s)
1489       GWEN_Buffer_AppendString(buf, s);
1490     GWEN_Buffer_AppendString(buf, "_");
1491     GWEN_Buffer_AppendString(buf, AB_User_GetUserId(u));
1492     if (challenge) {
1493       GWEN_Buffer_AppendString(buf, "_");
1494       GWEN_Buffer_AppendString(buf, challenge);
1495     }
1496     return 0;
1497   }
1498 }
1499 
1500 
1501 
AH_User_InputPin(AB_USER * u,char * pwbuffer,int minLen,int maxLen,int flags)1502 int AH_User_InputPin(AB_USER *u,
1503                      char *pwbuffer,
1504                      int minLen, int maxLen,
1505                      int flags)
1506 {
1507   AB_PROVIDER *pro;
1508   AB_BANKING *ab;
1509   GWEN_BUFFER *nbuf;
1510   int rv;
1511   const char *numeric_warning = "";
1512   char buffer[512];
1513   const char *un;
1514   const char *bn=NULL;
1515   AB_BANKINFO *bi;
1516 
1517   assert(u);
1518   un=AB_User_GetUserId(u);
1519 
1520   pro=AB_User_GetProvider(u);
1521   assert(pro);
1522   ab=AB_Provider_GetBanking(pro);
1523   assert(ab);
1524 
1525   /* find bank name */
1526   bi=AB_Banking_GetBankInfo(ab, "de", "*", AB_User_GetBankCode(u));
1527   if (bi)
1528     bn=AB_BankInfo_GetBankName(bi);
1529   if (!bn)
1530     bn=AB_User_GetBankCode(u);
1531 
1532   buffer[0]=0;
1533   buffer[sizeof(buffer)-1]=0;
1534   if (flags & GWEN_GUI_INPUT_FLAGS_NUMERIC) {
1535     numeric_warning = I18N(" You must only enter numbers, not letters.");
1536   }
1537   if (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
1538     snprintf(buffer, sizeof(buffer)-1,
1539              I18N("Please enter a new PIN for \n"
1540                   "user %s at %s\n"
1541                   "The input must be at least %d characters long.%s"
1542                   "<html>"
1543                   "<p>"
1544                   "Please enter a new PIN for user <i>%s</i> at "
1545                   "<i>%s</i>."
1546                   "</p>"
1547                   "<p>"
1548                   "The input must be at least %d characters long.%s"
1549                   "</p>"
1550                   "</html>"),
1551              un, bn,
1552              minLen,
1553              numeric_warning,
1554              un, bn,
1555              minLen,
1556              numeric_warning);
1557   }
1558   else {
1559     snprintf(buffer, sizeof(buffer)-1,
1560              I18N("Please enter the PIN for \n"
1561                   "user %s at %s\n"
1562                   "%s"
1563                   "<html>"
1564                   "Please enter the PIN for user <i>%s</i> at "
1565                   "<i>%s</i>.<br>"
1566                   "%s"
1567                   "</html>"),
1568              un, bn,
1569              numeric_warning,
1570              un, bn,
1571              numeric_warning);
1572   }
1573   buffer[sizeof(buffer)-1]=0;
1574 
1575   AB_BankInfo_free(bi);
1576 
1577   nbuf=GWEN_Buffer_new(0, 256, 0, 1);
1578   AH_User_MkPinName(u, nbuf);
1579 
1580   rv=GWEN_Gui_GetPassword(flags,
1581                           GWEN_Buffer_GetStart(nbuf),
1582                           I18N("Enter PIN"),
1583                           buffer,
1584                           pwbuffer,
1585                           minLen,
1586                           maxLen,
1587                           GWEN_Gui_PasswordMethod_Text, NULL,
1588                           0);
1589   GWEN_Buffer_free(nbuf);
1590 
1591   return rv;
1592 }
1593 
1594 
1595 
AH_User_InputTan(AB_USER * u,char * pwbuffer,int minLen,int maxLen)1596 int AH_User_InputTan(AB_USER *u,
1597                      char *pwbuffer,
1598                      int minLen,
1599                      int maxLen)
1600 {
1601   AB_PROVIDER *pro;
1602   AB_BANKING *ab;
1603   int rv;
1604   char buffer[512];
1605   const char *un;
1606   const char *bn=NULL;
1607   GWEN_BUFFER *nbuf;
1608   AB_BANKINFO *bi;
1609 
1610   assert(u);
1611   un=AB_User_GetUserId(u);
1612 
1613   pro=AB_User_GetProvider(u);
1614   assert(pro);
1615   ab=AB_Provider_GetBanking(pro);
1616   assert(ab);
1617 
1618   /* find bank name */
1619   bi=AB_Banking_GetBankInfo(ab,  "de", "*", AB_User_GetBankCode(u));
1620   if (bi)
1621     bn=AB_BankInfo_GetBankName(bi);
1622   if (!bn)
1623     AB_User_GetBankCode(u);
1624 
1625   buffer[0]=0;
1626   buffer[sizeof(buffer)-1]=0;
1627   snprintf(buffer, sizeof(buffer)-1,
1628            I18N("Please enter the next TAN\n"
1629                 "for user %s at %s."
1630                 "<html>"
1631                 "Please enter the next TAN for user <i>%s</i> at "
1632                 "<i>%s</i>."
1633                 "</html>"),
1634            un, bn,
1635            un, bn);
1636   buffer[sizeof(buffer)-1]=0;
1637 
1638   nbuf=GWEN_Buffer_new(0, 256, 0, 1);
1639   AH_User_MkTanName(u, NULL, nbuf);
1640 
1641   rv=GWEN_Gui_GetPassword(GWEN_GUI_INPUT_FLAGS_TAN |
1642                           /*GWEN_GUI_INPUT_FLAGS_NUMERIC |*/
1643                           GWEN_GUI_INPUT_FLAGS_SHOW,
1644                           GWEN_Buffer_GetStart(nbuf),
1645                           I18N("Enter TAN"),
1646                           buffer,
1647                           pwbuffer,
1648                           minLen,
1649                           maxLen,
1650                           GWEN_Gui_PasswordMethod_Text, NULL,
1651                           0);
1652   GWEN_Buffer_free(nbuf);
1653   AB_BankInfo_free(bi);
1654   return rv;
1655 }
1656 
1657 
AH_User_SetTanStatus(AB_USER * u,const char * challenge,const char * tan,GWEN_GUI_PASSWORD_STATUS status)1658 int AH_User_SetTanStatus(AB_USER *u,
1659                          const char *challenge,
1660                          const char *tan,
1661                          GWEN_GUI_PASSWORD_STATUS status)
1662 {
1663   GWEN_BUFFER *nbuf;
1664   int rv;
1665 
1666   nbuf=GWEN_Buffer_new(0, 256, 0, 1);
1667   AH_User_MkTanName(u, challenge, nbuf);
1668   rv=GWEN_Gui_SetPasswordStatus(GWEN_Buffer_GetStart(nbuf),
1669                                 tan,
1670                                 status,
1671                                 0);
1672   GWEN_Buffer_free(nbuf);
1673   return rv;
1674 }
1675 
1676 
1677 
AH_User_SetPinStatus(AB_USER * u,const char * pin,GWEN_GUI_PASSWORD_STATUS status)1678 int AH_User_SetPinStatus(AB_USER *u,
1679                          const char *pin,
1680                          GWEN_GUI_PASSWORD_STATUS status)
1681 {
1682   GWEN_BUFFER *nbuf;
1683   int rv;
1684 
1685   nbuf=GWEN_Buffer_new(0, 256, 0, 1);
1686   AH_User_MkPinName(u, nbuf);
1687   rv=GWEN_Gui_SetPasswordStatus(GWEN_Buffer_GetStart(nbuf),
1688                                 pin,
1689                                 status,
1690                                 0);
1691   GWEN_Buffer_free(nbuf);
1692   return rv;
1693 }
1694 
1695 
1696 
AH_User_GetHttpContentType(const AB_USER * u)1697 const char *AH_User_GetHttpContentType(const AB_USER *u)
1698 {
1699   AH_USER *ue;
1700 
1701   assert(u);
1702   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1703   assert(ue);
1704 
1705   return ue->httpContentType;
1706 }
1707 
1708 
1709 
AH_User_SetHttpContentType(AB_USER * u,const char * s)1710 void AH_User_SetHttpContentType(AB_USER *u, const char *s)
1711 {
1712   AH_USER *ue;
1713 
1714   assert(u);
1715   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1716   assert(ue);
1717 
1718   free(ue->httpContentType);
1719   if (s)
1720     ue->httpContentType=strdup(s);
1721   else
1722     ue->httpContentType=NULL;
1723 }
1724 
1725 
1726 
AH_User_GetTanMethodList(const AB_USER * u)1727 const int *AH_User_GetTanMethodList(const AB_USER *u)
1728 {
1729   AH_USER *ue;
1730 
1731   assert(u);
1732   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1733   assert(ue);
1734 
1735   return ue->tanMethodList;
1736 }
1737 
1738 
1739 
AH_User_HasTanMethod(const AB_USER * u,int method)1740 int AH_User_HasTanMethod(const AB_USER *u, int method)
1741 {
1742   AH_USER *ue;
1743   int i;
1744 
1745   assert(u);
1746   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1747   assert(ue);
1748 
1749   for (i=0; i<AH_USER_MAX_TANMETHODS; i++) {
1750     if (ue->tanMethodList[i]==method)
1751       return 1;
1752   }
1753 
1754   DBG_INFO(AQHBCI_LOGDOMAIN, "TAN method %d not available", method);
1755   return 0;
1756 }
1757 
1758 
1759 
AH_User_HasTanMethodOtherThan(const AB_USER * u,int method)1760 int AH_User_HasTanMethodOtherThan(const AB_USER *u, int method)
1761 {
1762   AH_USER *ue;
1763   int i;
1764 
1765   assert(u);
1766   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1767   assert(ue);
1768 
1769   DBG_INFO(AQHBCI_LOGDOMAIN, "Checking for methods other than %d in list of %d TAN methods",
1770            method,
1771            ue->tanMethodCount);
1772 
1773   for (i=0; i<ue->tanMethodCount; i++) {
1774     DBG_INFO(AQHBCI_LOGDOMAIN, " - Tan method %d=%d", i, ue->tanMethodList[i]);
1775     if (ue->tanMethodList[i]!=method && ue->tanMethodList[i]!=-1) {
1776       DBG_INFO(AQHBCI_LOGDOMAIN, "   match");
1777       return 1;
1778     }
1779     else {
1780       DBG_INFO(AQHBCI_LOGDOMAIN, "   no match");
1781     }
1782   }
1783 
1784   DBG_INFO(AQHBCI_LOGDOMAIN, " No methods other than %d found", method);
1785   return 0;
1786 }
1787 
1788 
1789 
AH_User_AddTanMethod(AB_USER * u,int method)1790 void AH_User_AddTanMethod(AB_USER *u, int method)
1791 {
1792   AH_USER *ue;
1793 
1794   assert(u);
1795   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1796   assert(ue);
1797 
1798   DBG_INFO(AQHBCI_LOGDOMAIN, "Adding TAN method %d", method);
1799 
1800   if (!AH_User_HasTanMethod(u, method)) {
1801     if (ue->tanMethodCount<AH_USER_MAX_TANMETHODS) {
1802       ue->tanMethodList[ue->tanMethodCount++]=method;
1803       ue->tanMethodList[ue->tanMethodCount]=-1;
1804       DBG_INFO(AQHBCI_LOGDOMAIN, "  Added TAN method %d", method);
1805     }
1806   }
1807 }
1808 
1809 
1810 
AH_User_ClearTanMethodList(AB_USER * u)1811 void AH_User_ClearTanMethodList(AB_USER *u)
1812 {
1813   AH_USER *ue;
1814 
1815   assert(u);
1816   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1817   assert(ue);
1818 
1819   ue->tanMethodList[0]=-1;
1820   ue->tanMethodCount=0;
1821 }
1822 
1823 
1824 
AH_User_GetTanMethodCount(const AB_USER * u)1825 int AH_User_GetTanMethodCount(const AB_USER *u)
1826 {
1827   AH_USER *ue;
1828 
1829   assert(u);
1830   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1831   assert(ue);
1832 
1833   return ue->tanMethodCount;
1834 }
1835 
1836 
1837 
AH_User_GetSelectedTanMethod(const AB_USER * u)1838 int AH_User_GetSelectedTanMethod(const AB_USER *u)
1839 {
1840   AH_USER *ue;
1841 
1842   assert(u);
1843   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1844   assert(ue);
1845 
1846   return ue->selectedTanMethod;
1847 }
1848 
1849 
1850 
AH_User_SetSelectedTanMethod(AB_USER * u,int i)1851 void AH_User_SetSelectedTanMethod(AB_USER *u, int i)
1852 {
1853   AH_USER *ue;
1854 
1855   assert(u);
1856   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1857   assert(ue);
1858 
1859   ue->selectedTanMethod=i;
1860 }
1861 
1862 
1863 
AH_User_GetTanMediumId(const AB_USER * u)1864 const char *AH_User_GetTanMediumId(const AB_USER *u)
1865 {
1866   AH_USER *ue;
1867 
1868   assert(u);
1869   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1870   assert(ue);
1871 
1872   return ue->tanMediumId;
1873 }
1874 
1875 
1876 
AH_User_SetTanMediumId(AB_USER * u,const char * s)1877 void AH_User_SetTanMediumId(AB_USER *u, const char *s)
1878 {
1879   AH_USER *ue;
1880 
1881   assert(u);
1882   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1883   assert(ue);
1884 
1885   free(ue->tanMediumId);
1886   if (s)
1887     ue->tanMediumId=strdup(s);
1888   else
1889     ue->tanMediumId=NULL;
1890 }
1891 
1892 
1893 
AH_User_LoadTanMethods(AB_USER * u)1894 void AH_User_LoadTanMethods(AB_USER *u)
1895 {
1896   AH_USER *ue;
1897 
1898   assert(u);
1899   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1900   assert(ue);
1901 
1902   /* read directly from BPD */
1903   if (ue->cryptMode==AH_CryptMode_Pintan) {
1904     GWEN_DB_NODE *db;
1905     int rv;
1906 
1907     AH_TanMethod_List_Clear(ue->tanMethodDescriptions);
1908     db=GWEN_DB_Group_new("bpd");
1909     rv=AH_Job_SampleBpdVersions("JobTan", u, db);
1910     if (rv<0) {
1911       DBG_INFO(AQHBCI_LOGDOMAIN, "No BPD for TAN job");
1912     }
1913     else {
1914       GWEN_DB_NODE *dbV;
1915 
1916       dbV=GWEN_DB_GetFirstGroup(db);
1917       while (dbV) {
1918         int version;
1919 
1920         version=atoi(GWEN_DB_GroupName(dbV));
1921         if (version>0) {
1922           GWEN_DB_NODE *dbT;
1923 
1924           dbT=GWEN_DB_FindFirstGroup(dbV, "tanMethod");
1925           if (!dbT) {
1926             DBG_INFO(AQHBCI_LOGDOMAIN, "No tan method found");
1927           }
1928           while (dbT) {
1929             AH_TAN_METHOD *tm;
1930             const char *s;
1931 
1932             tm=AH_TanMethod_new();
1933             AH_TanMethod_SetFunction(tm, GWEN_DB_GetIntValue(dbT, "function", 0, 0));
1934             AH_TanMethod_SetProcess(tm, GWEN_DB_GetIntValue(dbT, "process", 0, 0));
1935             AH_TanMethod_SetMethodId(tm, GWEN_DB_GetCharValue(dbT, "methodId", 0, 0));
1936             AH_TanMethod_SetZkaTanName(tm, GWEN_DB_GetCharValue(dbT, "zkaTanName", 0, 0));
1937             AH_TanMethod_SetZkaTanVersion(tm, GWEN_DB_GetCharValue(dbT, "zkaTanVersion", 0, 0));
1938             AH_TanMethod_SetMethodName(tm, GWEN_DB_GetCharValue(dbT, "methodName", 0, 0));
1939             AH_TanMethod_SetTanMaxLen(tm, GWEN_DB_GetIntValue(dbT, "tanMaxLen", 0, 0));
1940             AH_TanMethod_SetFormatId(tm, GWEN_DB_GetCharValue(dbT, "formatId", 0, 0));
1941             AH_TanMethod_SetPrompt(tm, GWEN_DB_GetCharValue(dbT, "prompt", 0, 0));
1942             AH_TanMethod_SetReturnMaxLen(tm, GWEN_DB_GetIntValue(dbT, "returnMaxLen", 0, 0));
1943             AH_TanMethod_SetMaxActiveLists(tm, GWEN_DB_GetIntValue(dbT, "maxActiveLists", 0, 0));
1944             /*AH_TanMethod_SetGvVersion(tm, GWEN_DB_GetIntValue(dbT, "gvVersion", 0, 0));*/
1945             s=GWEN_DB_GetCharValue(dbT, "multiTanAllowed", 0, NULL);
1946             if (s && strcasecmp(s, "j")==0)
1947               AH_TanMethod_SetMultiTanAllowed(tm, 1);
1948             AH_TanMethod_SetTimeShiftAllowed(tm, GWEN_DB_GetIntValue(dbT, "timeShiftAllowed", 0, 0));
1949             AH_TanMethod_SetTanListMode(tm, GWEN_DB_GetIntValue(dbT, "tanListMode", 0, 0));
1950             s=GWEN_DB_GetCharValue(dbT, "stornoAllowed", 0, NULL);
1951             if (s && strcasecmp(s, "j")==0)
1952               AH_TanMethod_SetStornoAllowed(tm, 1);
1953             s=GWEN_DB_GetCharValue(dbT, "needChallengeClass", 0, NULL);
1954             if (s && strcasecmp(s, "j")==0)
1955               AH_TanMethod_SetNeedChallengeClass(tm, 1);
1956             s=GWEN_DB_GetCharValue(dbT, "needChallengeAmount", 0, NULL);
1957             if (s && strcasecmp(s, "j")==0)
1958               AH_TanMethod_SetNeedChallengeAmount(tm, 1);
1959             AH_TanMethod_SetInitMode(tm, GWEN_DB_GetIntValue(dbT, "initMode", 0, 0));
1960             s=GWEN_DB_GetCharValue(dbT, "tanMediumIdNeeded", 0, NULL);
1961             if (s && strcasecmp(s, "j")==0)
1962               AH_TanMethod_SetNeedTanMediumId(tm, 1);
1963             AH_TanMethod_SetMaxActiveTanMedia(tm, GWEN_DB_GetIntValue(dbT, "maxActiveTanMedia", 0, 0));
1964 
1965             DBG_INFO(AQHBCI_LOGDOMAIN,
1966                      "Adding TAN method %d [%s] for GV version %d",
1967                      AH_TanMethod_GetFunction(tm),
1968                      AH_TanMethod_GetMethodId(tm),
1969                      version);
1970             AH_TanMethod_SetGvVersion(tm, version);
1971             AH_TanMethod_List_Add(tm, ue->tanMethodDescriptions);
1972 
1973             dbT=GWEN_DB_FindNextGroup(dbT, "tanMethod");
1974           }
1975         }
1976 
1977         dbV=GWEN_DB_GetNextGroup(dbV);
1978       }
1979     }
1980     GWEN_DB_Group_free(db);
1981   }
1982 }
1983 
1984 
1985 
AH_User_LoadSepaDescriptors(AB_USER * u)1986 void AH_User_LoadSepaDescriptors(AB_USER *u)
1987 {
1988   AH_USER *ue;
1989   GWEN_DB_NODE *db;
1990   int rv;
1991 
1992   assert(u);
1993   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
1994   assert(ue);
1995 
1996   DBG_INFO(AQHBCI_LOGDOMAIN, "Loading SEPA descriptors");
1997 
1998   /* read directly from BPD */
1999 
2000   GWEN_StringList_Clear(ue->sepaDescriptors);
2001   db=GWEN_DB_Group_new("bpd");
2002   rv=AH_Job_SampleBpdVersions("JobGetAccountSepaInfo", u, db);
2003   if (rv<0) {
2004     DBG_INFO(AQHBCI_LOGDOMAIN, "No BPD for TAN job");
2005   }
2006   else {
2007     GWEN_DB_NODE *dbV;
2008 
2009     dbV=GWEN_DB_GetFirstGroup(db);
2010     while (dbV) {
2011       int version;
2012 
2013       version=atoi(GWEN_DB_GroupName(dbV));
2014       if (version>0) {
2015         GWEN_DB_NODE *dbT;
2016 
2017         /* always overwrite with latest version received */
2018         GWEN_StringList_Clear(ue->sepaDescriptors);
2019         dbT=GWEN_DB_FindFirstGroup(dbV, "SupportedSepaFormats");
2020         if (!dbT) {
2021           DBG_INFO(AQHBCI_LOGDOMAIN, "No SEPA descriptor found");
2022         }
2023         while (dbT) {
2024           int i;
2025 
2026           for (i=0; i<100; i++) {
2027             const char *s;
2028 
2029             s=GWEN_DB_GetCharValue(dbT, "format", i, NULL);
2030             if (!(s && *s))
2031               break;
2032             GWEN_StringList_AppendString(ue->sepaDescriptors, s, 0, 1);
2033             DBG_INFO(AQHBCI_LOGDOMAIN,
2034                      "Adding SEPA descriptor [%s] for GV version %d",
2035                      s, version);
2036           }
2037 
2038           dbT=GWEN_DB_FindNextGroup(dbT, "SupportedSepaFormats");
2039         }
2040       }
2041 
2042       dbV=GWEN_DB_GetNextGroup(dbV);
2043     }
2044   }
2045   GWEN_DB_Group_free(db);
2046 }
2047 
2048 
2049 
2050 
AH_User_GetTanMethodDescriptions(AB_USER * u)2051 const AH_TAN_METHOD_LIST *AH_User_GetTanMethodDescriptions(AB_USER *u)
2052 {
2053   AH_USER *ue;
2054 
2055   assert(u);
2056   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2057   assert(ue);
2058 
2059   /* always reload TAN methods from BPD */
2060   AH_User_LoadTanMethods(u);
2061 
2062   return ue->tanMethodDescriptions;
2063 }
2064 
2065 
2066 
AH_User_GetMaxTransfersPerJob(const AB_USER * u)2067 int AH_User_GetMaxTransfersPerJob(const AB_USER *u)
2068 {
2069   AH_USER *ue;
2070 
2071   assert(u);
2072   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2073   assert(ue);
2074 
2075   return ue->maxTransfersPerJob;
2076 }
2077 
2078 
2079 
AH_User_SetMaxTransfersPerJob(AB_USER * u,int i)2080 void AH_User_SetMaxTransfersPerJob(AB_USER *u, int i)
2081 {
2082   AH_USER *ue;
2083 
2084   assert(u);
2085   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2086   assert(ue);
2087 
2088   ue->maxTransfersPerJob=i;
2089 }
2090 
2091 
2092 
AH_User_GetMaxDebitNotesPerJob(const AB_USER * u)2093 int AH_User_GetMaxDebitNotesPerJob(const AB_USER *u)
2094 {
2095   AH_USER *ue;
2096 
2097   assert(u);
2098   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2099   assert(ue);
2100 
2101   return ue->maxDebitNotesPerJob;
2102 }
2103 
2104 
2105 
AH_User_SetMaxDebitNotesPerJob(AB_USER * u,int i)2106 void AH_User_SetMaxDebitNotesPerJob(AB_USER *u, int i)
2107 {
2108   AH_USER *ue;
2109 
2110   assert(u);
2111   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2112   assert(ue);
2113 
2114   ue->maxDebitNotesPerJob=i;
2115 }
2116 
2117 
2118 
AH_User_GetSepaDescriptors(AB_USER * u)2119 const GWEN_STRINGLIST *AH_User_GetSepaDescriptors(AB_USER *u)
2120 {
2121   AH_USER *ue;
2122 
2123   assert(u);
2124   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2125   assert(ue);
2126 
2127   return ue->sepaDescriptors;
2128 }
2129 
2130 
2131 
AH_User_GetSepaTransferProfile(const AB_USER * u)2132 const char *AH_User_GetSepaTransferProfile(const AB_USER *u)
2133 {
2134   const AH_USER *ue;
2135 
2136   assert(u);
2137   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2138   assert(ue);
2139 
2140   return ue->sepaTransferProfile;
2141 }
2142 
2143 
2144 
AH_User_SetSepaTransferProfile(AB_USER * u,const char * profileName)2145 void AH_User_SetSepaTransferProfile(AB_USER *u, const char *profileName)
2146 {
2147   AH_USER *ue;
2148 
2149   assert(u);
2150   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2151   assert(ue);
2152 
2153   free(ue->sepaTransferProfile);
2154   if (profileName)
2155     ue->sepaTransferProfile=strdup(profileName);
2156   else
2157     ue->sepaTransferProfile=NULL;
2158 }
2159 
2160 
2161 
AH_User_GetSepaDebitNoteProfile(const AB_USER * u)2162 const char *AH_User_GetSepaDebitNoteProfile(const AB_USER *u)
2163 {
2164   const AH_USER *ue;
2165 
2166   assert(u);
2167   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2168   assert(ue);
2169 
2170   return ue->sepaDebitNoteProfile;
2171 }
2172 
2173 
2174 
AH_User_SetSepaDebitNoteProfile(AB_USER * u,const char * profileName)2175 void AH_User_SetSepaDebitNoteProfile(AB_USER *u, const char *profileName)
2176 {
2177   AH_USER *ue;
2178 
2179   assert(u);
2180   ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
2181   assert(ue);
2182 
2183   free(ue->sepaDebitNoteProfile);
2184   if (profileName)
2185     ue->sepaDebitNoteProfile=strdup(profileName);
2186   else
2187     ue->sepaDebitNoteProfile=NULL;
2188 }
2189 
AH_User_VerifyInitialKey(GWEN_CRYPT_TOKEN * ct,const GWEN_CRYPT_TOKEN_CONTEXT * ctx,AB_USER * user,GWEN_CRYPT_KEY * key,uint16_t sentModl,const char * keyName)2190 int AH_User_VerifyInitialKey(GWEN_CRYPT_TOKEN *ct,
2191                              const GWEN_CRYPT_TOKEN_CONTEXT *ctx,
2192                              AB_USER *user,
2193                              GWEN_CRYPT_KEY *key,
2194                              uint16_t sentModl,
2195                              const char *keyName)
2196 {
2197 
2198 
2199   uint32_t  keyHashAlgo;
2200   uint32_t  keySize;
2201   uint32_t  keyNum;
2202   uint32_t  keyVer;
2203   uint32_t  expLen;
2204   uint8_t  *modulus;
2205   uint8_t  *exponent;
2206   GWEN_MDIGEST *md;
2207   uint8_t *mdPtr;
2208   unsigned int mdSize;
2209   uint8_t   modBuffer[1024];
2210   uint8_t   expBuffer[256];
2211   uint32_t  keyHashNum;
2212   uint32_t  keyHashVer;
2213   uint8_t   canVerifyWithHash=0;
2214   uint16_t  keySizeForHash=0;
2215   const uint8_t    *keyHash;
2216   uint32_t keyHashLen;
2217   char hashString[1024];
2218   int rv;
2219   int i;
2220 
2221 
2222   /* check if NOTEPAD contained a key hash */
2223   keyHashAlgo=GWEN_Crypt_Token_Context_GetKeyHashAlgo(ctx);
2224 
2225   modulus=&modBuffer[0];
2226   exponent=&expBuffer[0];
2227   keySize=1024;
2228   expLen=256;
2229   GWEN_Crypt_KeyRsa_GetModulus(key, modulus, &keySize);
2230   GWEN_Crypt_KeyRsa_GetExponent(key, exponent, &expLen);
2231   keyNum=GWEN_Crypt_Key_GetKeyNumber(key);
2232   keyVer=GWEN_Crypt_Key_GetKeyVersion(key);
2233 
2234   /* check if we got the keyHashAlgo from a card, otherwise determine it ourselves */
2235 
2236   if (keyHashAlgo == GWEN_Crypt_HashAlgoId_None ||  keyHashAlgo == GWEN_Crypt_HashAlgoId_Unknown) {
2237     uint8_t rxhVersion = AH_User_GetRdhType(user);
2238     if (rxhVersion < 6) {
2239       keyHashAlgo=GWEN_Crypt_HashAlgoId_Rmd160;
2240     }
2241     else {
2242       keyHashAlgo=GWEN_Crypt_HashAlgoId_Sha256;
2243     }
2244   }
2245   if (AH_User_GetCryptMode(user) == AH_CryptMode_Rdh && AH_User_GetRdhType(user) == 1) {
2246     keySizeForHash=128;
2247   }
2248   else {
2249     keySizeForHash=keySize;
2250   }
2251 
2252 
2253   keyHash=GWEN_Crypt_Token_Context_GetKeyHashPtr(ctx);
2254   keyHashLen=GWEN_Crypt_Token_Context_GetKeyHashLen(ctx);
2255 
2256   /* check if we got a hash from a banking card */
2257   if (keyHash != NULL && keyHashLen > 0) {
2258 
2259     keyHashNum=GWEN_Crypt_Token_Context_GetKeyHashNum(ctx);
2260     keyHashVer=GWEN_Crypt_Token_Context_GetKeyHashVer(ctx);
2261     DBG_INFO(AQHBCI_LOGDOMAIN,
2262              "Found bank key hash on the zka card! (Hash Algo Identifier: [%d], keyNum: [%d], keyVer: [%d]", keyHashAlgo, keyHashNum,
2263              keyHashVer);
2264     if (keyHashNum == keyNum && keyHashVer==keyVer) {
2265       DBG_INFO(AQHBCI_LOGDOMAIN,
2266                "Key Number and Key Version of the Hash match transmitted key, try verifying with the Hash.");
2267       canVerifyWithHash=1;
2268     }
2269   }
2270 
2271   /* build key hash */
2272   {
2273     int expPadBytes=keySizeForHash-expLen;
2274     int modPadBytes=keySizeForHash-keySize;
2275 
2276     /* pad exponent to length of modulus */
2277     GWEN_BUFFER *keyBuffer;
2278     keyBuffer=GWEN_Buffer_new(NULL, 2*keySize, 0, 0);
2279     GWEN_Buffer_FillWithBytes(keyBuffer, 0x0, expPadBytes);
2280     GWEN_Buffer_AppendBytes(keyBuffer, (const char *)exponent, expLen);
2281     if (modPadBytes) {
2282       GWEN_Buffer_FillWithBytes(keyBuffer, 0x0, modPadBytes);
2283     }
2284     GWEN_Buffer_AppendBytes(keyBuffer, (const char *)modulus, keySize);
2285 
2286 
2287 
2288     if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Sha256) {
2289       /*SHA256*/
2290       md=GWEN_MDigest_Sha256_new();
2291       DBG_INFO(AQHBCI_LOGDOMAIN, "Hash Algo for key verification is SHA256.");
2292     }
2293     else if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Rmd160) {
2294       md=GWEN_MDigest_Rmd160_new();
2295       DBG_INFO(AQHBCI_LOGDOMAIN, "Hash Algo for key verification is RIPMED160.");
2296     }
2297     else {
2298       /* ERROR, wrong hash algo */
2299       DBG_ERROR(AQHBCI_LOGDOMAIN, "Hash Algorithm of Bank Public %s Key not correct! (Hash Identifier %d)", keyName,
2300                 keyHashAlgo);
2301       return 0;
2302     }
2303 
2304     GWEN_MDigest_Begin(md);
2305     GWEN_MDigest_Update(md, (uint8_t *)GWEN_Buffer_GetStart(keyBuffer), 2*keySize);
2306     GWEN_MDigest_End(md);
2307     mdPtr=GWEN_MDigest_GetDigestPtr(md);
2308     mdSize=GWEN_MDigest_GetDigestSize(md);
2309     GWEN_Buffer_free(keyBuffer);
2310   }
2311 
2312   memset(hashString, 0, 1024);
2313   for (i=0; i<GWEN_MDigest_GetDigestSize(md); i++)
2314     sprintf(hashString+3*i, "%02x ", *(mdPtr+i));
2315   DBG_INFO(AQHBCI_LOGDOMAIN, "Key Hash from the Bank Public %s key: Hash Length: %d, Hash: %s", keyName, keyHashLen,
2316            hashString);
2317 
2318   if (canVerifyWithHash) {
2319 
2320     uint16_t matchingBytes=keySize;
2321 
2322     char cardHashString[1024];
2323 
2324     /* compare hashes */
2325 
2326     memset(cardHashString, 0, 1024);
2327     for (i=0; i<keyHashLen; i++)
2328       sprintf(cardHashString+3*i, "%02x ", keyHash[i]);
2329     DBG_INFO(AQHBCI_LOGDOMAIN, "Key Hash on the Card: Hash Length: %d, Hash: %s", keyHashLen, cardHashString);
2330 
2331 
2332     if (keyHashLen==mdSize) {
2333       for (i = 0; i < mdSize; i++) {
2334         if (mdPtr[i] != (uint8_t) keyHash[i]) {
2335           matchingBytes--;
2336         }
2337       }
2338     }
2339     else {
2340       matchingBytes = 0;
2341     }
2342     GWEN_MDigest_free(md);
2343     DBG_INFO(AQHBCI_LOGDOMAIN, "Hash comparison: of %d bytes %d matched", keyHashLen, matchingBytes);
2344     if (matchingBytes == keySize) {
2345       DBG_INFO(AQHBCI_LOGDOMAIN,
2346                "Verified the bank's public %s key with the hash from the zka card.", keyName);
2347       return 1;
2348     }
2349     else {
2350       GWEN_BUFFER *msgBuffer;
2351       GWEN_BUFFER *titleBuffer;
2352       char numBuf[32];
2353       /* ERROR, hash sizes not identical */
2354 
2355 
2356       DBG_ERROR(AQHBCI_LOGDOMAIN, "Hash Sizes of Bank Public %s Key do not match!", keyName);
2357       DBG_ERROR(AQHBCI_LOGDOMAIN, "Verify new server %s key, please verify! (num: %d, version: %d, hash: %s)", keyName,
2358                 keyNum, keyVer, hashString);
2359       GWEN_Gui_ProgressLog2(0,
2360                             GWEN_LoggerLevel_Warning,
2361                             I18N("Hash Sizes of Bank Public %s Key do not match!"),
2362                             keyName);
2363       GWEN_Gui_ProgressLog2(0,
2364                             GWEN_LoggerLevel_Warning,
2365                             I18N("Received new server %s key, please verify! (num: %d, version: %d, hash: %s)"),
2366                             keyName, keyNum, keyVer, hashString);
2367 
2368       titleBuffer=GWEN_Buffer_new(NULL, 256, 0, 1);
2369       GWEN_Buffer_AppendString(titleBuffer, "Could not verify received public ");
2370       GWEN_Buffer_AppendString(titleBuffer, keyName);
2371       GWEN_Buffer_AppendString(titleBuffer, " bank key with card hash!");
2372 
2373       msgBuffer=GWEN_Buffer_new(NULL, 2048, 0, 1);
2374       GWEN_Buffer_AppendString(msgBuffer,
2375                                "Could not verify the received key with the key hash stored on your banking card!\n");
2376       GWEN_Buffer_AppendString(msgBuffer, "Hashes did not match!\n");
2377       GWEN_Buffer_AppendString(msgBuffer, "Hash on the card has length ");
2378       snprintf(numBuf, sizeof(numBuf), "%d, ",
2379                keyHashLen);
2380       GWEN_Buffer_AppendString(msgBuffer, numBuf);
2381       GWEN_Buffer_AppendString(msgBuffer, "hash value ");
2382       if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Sha256) {
2383         /*SHA256*/
2384         GWEN_Buffer_AppendString(msgBuffer, "(SHA256):\n");
2385 
2386       }
2387       else if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Rmd160) {
2388         GWEN_Buffer_AppendString(msgBuffer, "(RIPEMD-160):\n");
2389       }
2390       GWEN_Buffer_AppendString(msgBuffer, cardHashString);
2391       GWEN_Buffer_AppendString(msgBuffer, "\n\nHash from transmitted key has length ");
2392       snprintf(numBuf, sizeof(numBuf), "%d, ",
2393                mdSize);
2394       GWEN_Buffer_AppendString(msgBuffer, numBuf);
2395       GWEN_Buffer_AppendString(msgBuffer, "hash value ");
2396       if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Sha256) {
2397         /*SHA256*/
2398         GWEN_Buffer_AppendString(msgBuffer, "(SHA256):\n");
2399 
2400       }
2401       else if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Rmd160) {
2402         GWEN_Buffer_AppendString(msgBuffer, "(RIPEMD-160):\n");
2403       }
2404       GWEN_Buffer_AppendString(msgBuffer, hashString);
2405       GWEN_Buffer_AppendString(msgBuffer, "\n\nIMPORTANT WARNING: you normally should only proceed if the hash matches!\n"
2406                                "Contact your bank immediately if the hash does not match!\n\n");
2407       GWEN_Buffer_AppendString(msgBuffer, "Do you really want to import this key?");
2408       rv=GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_TYPE_WARN | GWEN_GUI_MSG_FLAGS_SEVERITY_DANGEROUS,
2409                              I18N(GWEN_Buffer_GetStart(titleBuffer)),
2410                              I18N(GWEN_Buffer_GetStart(msgBuffer)),
2411                              I18N("Import"), I18N("Abort"), NULL, 0);
2412       GWEN_Buffer_free(msgBuffer);
2413       GWEN_Buffer_free(titleBuffer);
2414       if (rv!=1) {
2415         DBG_ERROR(AQHBCI_LOGDOMAIN, "Public %s Key not accepted by user.", keyName);
2416         return 0;
2417       }
2418       else {
2419         DBG_INFO(AQHBCI_LOGDOMAIN,
2420                  "Bank's public %s key accepted by the user.", keyName);
2421         return 1;
2422 
2423       }
2424     }
2425   }
2426 
2427   {
2428     GWEN_BUFFER *titleBuffer;
2429     GWEN_BUFFER *msgBuffer;
2430     char numBuf[32];
2431 
2432     GWEN_MDigest_free(md);
2433 
2434     DBG_ERROR(AQHBCI_LOGDOMAIN, "Received new server %s key, please verify! (num: %d, version: %d, hash: %s)", keyName,
2435               keyNum, keyVer, hashString);
2436     GWEN_Gui_ProgressLog2(0,
2437                           GWEN_LoggerLevel_Warning,
2438                           I18N("Received new server %s key, please verify! (num: %d, version: %d, hash: %s)"),
2439                           keyName, keyNum, keyVer, hashString);
2440 
2441     titleBuffer=GWEN_Buffer_new(NULL, 256, 0, 1);
2442     GWEN_Buffer_AppendString(titleBuffer, "Received Public ");
2443     GWEN_Buffer_AppendString(titleBuffer, keyName);
2444     GWEN_Buffer_AppendString(titleBuffer, " Bank Key");
2445 
2446     msgBuffer=GWEN_Buffer_new(NULL, 2048, 0, 1);
2447     GWEN_Buffer_AppendString(msgBuffer, "Received a unverified public bank key!\n");
2448     GWEN_Buffer_AppendString(msgBuffer, "Key Number: ");
2449     snprintf(numBuf, sizeof(numBuf), "%d",
2450              keyNum);
2451     GWEN_Buffer_AppendString(msgBuffer, numBuf);
2452     GWEN_Buffer_AppendString(msgBuffer, "\nKey Version: ");
2453     snprintf(numBuf, sizeof(numBuf), "%d",
2454              keyNum);
2455     GWEN_Buffer_AppendString(msgBuffer, numBuf);
2456     GWEN_Buffer_AppendString(msgBuffer, "\n\nHash from transmitted key has length ");
2457     snprintf(numBuf, sizeof(numBuf), "%d",
2458              mdSize);
2459     GWEN_Buffer_AppendString(msgBuffer, numBuf);
2460     GWEN_Buffer_AppendString(msgBuffer, ", value ");
2461     if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Sha256) {
2462       /*SHA256*/
2463       GWEN_Buffer_AppendString(msgBuffer, "(SHA256):\n");
2464 
2465     }
2466     else if (keyHashAlgo==GWEN_Crypt_HashAlgoId_Rmd160) {
2467       GWEN_Buffer_AppendString(msgBuffer, "(RIPEMD-160):\n");
2468     }
2469     GWEN_Buffer_AppendString(msgBuffer, hashString);
2470     GWEN_Buffer_AppendString(msgBuffer, "\n\nIMPORTANT WARNING: This hash should match the hash in an INI letter you should"
2471                              "have received from your bank!\n"
2472                              "Contact your bank immediately if the hash does not match!\n\n");
2473     GWEN_Buffer_AppendString(msgBuffer, "Do you really want to import this key?");
2474     rv=GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_TYPE_WARN | GWEN_GUI_MSG_FLAGS_SEVERITY_DANGEROUS,
2475                            I18N(GWEN_Buffer_GetStart(titleBuffer)),
2476                            I18N(GWEN_Buffer_GetStart(msgBuffer)),
2477                            I18N("Import"), I18N("Abort"), NULL, 0);
2478     GWEN_Buffer_free(msgBuffer);
2479     GWEN_Buffer_free(titleBuffer);
2480     if (rv!=1) {
2481       DBG_ERROR(AQHBCI_LOGDOMAIN, "Public %s Key not accepted by user.", keyName);
2482       return 0;
2483     }
2484     else {
2485       DBG_INFO(AQHBCI_LOGDOMAIN,
2486                "Bank's public %s key accepted by the user.", keyName);
2487       return 1;
2488 
2489     }
2490 
2491 
2492   }
2493   return 0;
2494 }
2495 
2496 
2497