Пример #1
0
int AH_ImExporterCtxFile_Import(AB_IMEXPORTER *ie,
				AB_IMEXPORTER_CONTEXT *ctx,
				GWEN_SYNCIO *sio,
				GWEN_DB_NODE *params){
  AH_IMEXPORTER_CTXFILE *ieh;
  GWEN_DB_NODE *dbData;
  int rv;

  assert(ie);
  ieh=GWEN_INHERIT_GETDATA(AB_IMEXPORTER, AH_IMEXPORTER_CTXFILE, ie);
  assert(ieh);

  dbData=GWEN_DB_Group_new("context");
  rv=GWEN_DB_ReadFromIo(dbData,
			sio,
			GWEN_DB_FLAGS_DEFAULT |
			GWEN_PATH_FLAGS_CREATE_GROUP);
  if (rv) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error importing data (%d)", rv);
    GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error,
			 "Error importing data");
    GWEN_DB_Group_free(dbData);
    return GWEN_ERROR_GENERIC;
  }

  /* transform DB to transactions */
  GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Notice,
		       I18N("Data imported, transforming to UTF-8"));
  rv=AB_ImExporter_DbFromIso8859_1ToUtf8(dbData);
  if (rv) {
    GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error,
			 "Error converting data");
    GWEN_DB_Group_free(dbData);
    return rv;
  }
  GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Notice,
		       "Transforming data to transactions");

  rv=AB_ImExporterContext_ReadDb(ctx, dbData);
  if (rv) {
    GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error,
			 "Error importing data");
    GWEN_DB_Group_free(dbData);
    return rv;
  }

  GWEN_DB_Group_free(dbData);
  return 0;
}
Пример #2
0
int test2(int argc, char **argv) {
  int rv;
  uint32_t id1;
  uint32_t id2;
  uint64_t i1;
  uint64_t i2;
  GWEN_GUI *gui;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  gui=Gtk2_Gui_new();
  GWEN_Gui_SetGui(gui);

  id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
                             GWEN_GUI_PROGRESS_SHOW_ABORT |
                             GWEN_GUI_PROGRESS_KEEP_OPEN,
                             "Progress-Title",
                             "<html>"
                             "<p><b>This</b> is an example <i>text</i>..</p>"
                             "<p>As you can see <font color=red>colors</font> can "
                             "be used.</p>"
                             "</html>",
                             10,
                             0);
  for (i1=1; i1<=10; i1++) {
    char numbuf[128];

    snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
    GWEN_Gui_ProgressLog(id1, GWEN_LoggerLevel_Notice, numbuf);
    id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
                               GWEN_GUI_PROGRESS_DELAY |
                               GWEN_GUI_PROGRESS_SHOW_ABORT,
                               "2nd progress",
                               "Starting 2nd progress...",
                               10,
                               id1);
    for (i2=1; i2<=10; i2++) {
      sleep(1);
      fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
      rv=GWEN_Gui_ProgressAdvance(id2, i2);
      if (rv==GWEN_ERROR_USER_ABORTED) {
        fprintf(stderr, "Aborted by user (2)\n");
        break;
      }
    }
    GWEN_Gui_ProgressEnd(id2);

    rv=GWEN_Gui_ProgressAdvance(id1, i1);
    if (rv==GWEN_ERROR_USER_ABORTED) {
      fprintf(stderr, "Aborted by user (1)\n");
      break;
    }
  }

  GWEN_Gui_ProgressEnd(id1);

  return 0;
}
Пример #3
0
LC_CLIENT_RESULT LC_Client_Init(LC_CLIENT *cl) {
  LONG rv;

  assert(cl);
  if (LC_Client_InitCommon()) {
    DBG_ERROR(LC_LOGDOMAIN, "Error on init");
    return LC_Client_ResultInternal;
  }

  /* establish context */
  rv=SCardEstablishContext(SCARD_SCOPE_SYSTEM,    /* scope */
			   NULL,                  /* reserved1 */
			   NULL,                  /* reserved2 */
			   &(cl->scardContext));  /* ptr to context */
  if (rv!=SCARD_S_SUCCESS) {
    if (rv == SCARD_E_NO_SERVICE) {
      DBG_ERROR(LC_LOGDOMAIN,
		"SCardEstablishContext: "
		"Error SCARD_E_NO_SERVICE: "
		"The Smartcard resource manager is not running. "
		"Maybe you have to start the Smartcard service manually?");
      GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error,
			   I18N("The PC/SC service is not running.\n"
				"Please make sure that the package \"pcscd\" is\n"
				"installed along with the appropriate driver.\n"
				"For cyberJack devices you will need to install\n"
				"the package \"ifd-cyberjack\" (Debian) or\n"
				"\"cyberjack-ifd\" (SuSE).\n"
				"For most other readers the package \"libccid\"\n"
				"needs to be installed."
				"<html>"
				"<p>The PC/SC service is not running.</p>"
				"<p>Please make sure that the package <b>pcscd</b> is "
				"installed along with the appropriate driver.</p>"
				"<p>For cyberJack devices you will need to install "
				"the package <b>ifd-cyberjack</b> (Debian) or "
				"<b>cyberjack-ifd</b> (SuSE).</p>"
				"<p>For most other readers the package <b>libccid</b> "
				"needs to be installed.</p>"
                                "</html>"));
    }
    else {
      DBG_ERROR(LC_LOGDOMAIN,
		"SCardEstablishContext: %ld (%04lx)", (long int) rv,
		rv);
    }
    LC_Client_FiniCommon();
    return LC_Client_ResultIoError;
  }

  return LC_Client_ResultOk;
}
Пример #4
0
int AH_ImExporterCtxFile_Export(AB_IMEXPORTER *ie,
				AB_IMEXPORTER_CONTEXT *ctx,
				GWEN_SYNCIO *sio,
				GWEN_DB_NODE *params){
  AH_IMEXPORTER_CTXFILE *ieh;
  GWEN_DB_NODE *dbData;
  int rv;

  assert(ie);
  ieh=GWEN_INHERIT_GETDATA(AB_IMEXPORTER, AH_IMEXPORTER_CTXFILE, ie);
  assert(ieh);

  /* create db, store context in it */
  dbData=GWEN_DB_Group_new("context");

  rv=AB_ImExporterContext_toDb(ctx, dbData);
  if (rv) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error exporting data (%d)", rv);
    GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error,
			 "Error exporting data");
    GWEN_DB_Group_free(dbData);
    return GWEN_ERROR_GENERIC;
  }

  rv=GWEN_DB_WriteToIo(dbData, sio, GWEN_DB_FLAGS_DEFAULT);
  if (rv) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error exporting data (%d)", rv);
    GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error,
			 "Error exporting data");
    GWEN_DB_Group_free(dbData);
    return GWEN_ERROR_GENERIC;
  }
  GWEN_DB_Group_free(dbData);

  return 0;
}
Пример #5
0
int EBC_Provider_ExecAccountQueue(AB_PROVIDER *pro,
				  AB_IMEXPORTER_CONTEXT *ctx,
				  AB_USER *u,
				  GWEN_HTTP_SESSION *sess,
				  EBC_ACCOUNTQUEUE *aq){
  EBC_PROVIDER *dp;
  int errors=0;
  int oks=0;
  AB_ACCOUNT *a;
  EBC_CONTEXT_LIST *cl;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  a=EBC_AccountQueue_GetAccount(aq);

  cl=EBC_AccountQueue_GetContextList(aq);
  if (cl) {
    EBC_CONTEXT *ectx;

    ectx=EBC_Context_List_First(cl);
    while(ectx) {
      int rv;

      rv=EBC_Provider_ExecContext(pro, ctx, u, a, sess, ectx);
      if (!rv)
	oks++;
      else
	errors++;

      if (rv==GWEN_ERROR_USER_ABORTED) {
	DBG_INFO(AQEBICS_LOGDOMAIN, "User aborted");
	GWEN_Gui_ProgressLog(0,
			     GWEN_LoggerLevel_Error,
			     I18N("User aborted"));
	return rv;
      }

      ectx=EBC_Context_List_Next(ectx);
    }
  }

  return 0;
}
Пример #6
0
int EBC_Provider_AddJob(AB_PROVIDER *pro, AB_JOB *j) {
  EBC_PROVIDER *dp;
  AB_ACCOUNT *a;
  AB_USER *u;
  EBC_USERQUEUE *uq;
  int doAdd=1;
  GWEN_DB_NODE *dbJob;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  a=AB_Job_GetAccount(j);
  assert(a);

  u=AB_Account_GetFirstUser(a);
  if (u==NULL) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "No user assigned to account.");
    GWEN_Gui_ProgressLog(0,
			 GWEN_LoggerLevel_Error,
			 I18N("No user assigned to account."));
    GWEN_Gui_ShowError(I18N("Setup Error"),
		       I18N("No user assigned to this account. Please assign one in the online banking setup dialog "
			    "for this account.\n"));
    return GWEN_ERROR_INTERNAL;
  }

  dbJob=AB_Job_GetProviderData(j, pro);
  assert(dbJob);

  switch(AB_Job_GetType(j)) {
  case AB_Job_TypeGetTransactions:
  case AB_Job_TypeTransfer:
  case AB_Job_TypeDebitNote:
    break;
  case AB_Job_TypeGetBalance:
  default:
    DBG_INFO(AQEBICS_LOGDOMAIN,
	     "Job not yet supported (%d)",
	     AB_Job_GetType(j));
    return GWEN_ERROR_NOT_SUPPORTED;
  } /* switch */

  uq=EBC_Queue_GetUserQueue(dp->queue, u);
  assert(uq);

  if (AB_Job_GetType(j)==AB_Job_TypeGetTransactions) {
    AB_JOB *firstJob;

    firstJob=EBC_Queue_FindFirstJobLikeThis(dp->queue, u, j);
    if (firstJob) {
      GWEN_DB_NODE *dbCurrJob;

      /* this job is just a copy of the firstJob, reference it */
      dbCurrJob=AB_Job_GetProviderData(j, pro);
      assert(dbCurrJob);

      GWEN_DB_SetIntValue(dbCurrJob,
			  GWEN_DB_FLAGS_OVERWRITE_VARS,
			  "refJob",
			  AB_Job_GetJobId(firstJob));
      /* don't add to queues */
      doAdd=0;
    }
  }

  if (doAdd) {
    /* only add to queue if needed */
    EBC_UserQueue_AddJob(uq, j);
  }

  /* always add to linear list */
  AB_Job_List2_PushBack(dp->bankingJobs, j);
  return 0;
}
Пример #7
0
int EBC_Provider_UpdateJob(AB_PROVIDER *pro, AB_JOB *j) {
  EBC_PROVIDER *dp;
  AB_ACCOUNT *a;
  AB_USER *u;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  a=AB_Job_GetAccount(j);
  assert(a);

  u=AB_Account_GetFirstUser(a);
  if (u==NULL) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "No user assigned to this account.");
    GWEN_Gui_ProgressLog(0,
			 GWEN_LoggerLevel_Error,
			 I18N("No user assigned to this account."));
    GWEN_Gui_ShowError(I18N("Setup Error"),
		       I18N("No user assigned to this account. Please assign one in the online banking setup dialog "
			    "for this account.\n"));
    return GWEN_ERROR_INTERNAL;
  }

  switch(AB_Job_GetType(j)) {
  case AB_Job_TypeTransfer: {
    AB_TRANSACTION_LIMITS *lim;

    lim=AB_TransactionLimits_new();
    AB_TransactionLimits_SetMaxLenPurpose(lim, 27);
    AB_TransactionLimits_SetMaxLenRemoteName(lim, 27);
    AB_TransactionLimits_SetMaxLinesRemoteName(lim, 1);
    AB_TransactionLimits_SetMaxLinesPurpose(lim, 2);

    AB_TransactionLimits_AddValuesTextKey(lim, "51", 0);
    AB_Job_SetFieldLimits(j, lim);
    AB_TransactionLimits_free(lim);

    break;
  }

  case AB_Job_TypeDebitNote: {
    AB_TRANSACTION_LIMITS *lim;

    lim=AB_TransactionLimits_new();
    AB_TransactionLimits_SetMaxLenPurpose(lim, 27);
    AB_TransactionLimits_SetMaxLenRemoteName(lim, 27);
    AB_TransactionLimits_SetMaxLinesRemoteName(lim, 1);
    AB_TransactionLimits_SetMaxLinesPurpose(lim, 2);

    AB_TransactionLimits_AddValuesTextKey(lim, "05", 0);
    AB_Job_SetFieldLimits(j, lim);
    AB_TransactionLimits_free(lim);

    break;
  }

  case AB_Job_TypeGetTransactions:
    break;

  case AB_Job_TypeGetBalance:
  default:
    DBG_INFO(AQEBICS_LOGDOMAIN,
	     "Job not yet supported (%d)",
	     AB_Job_GetType(j));
    return GWEN_ERROR_NOT_SUPPORTED;
  } /* switch */
  return 0;
}
Пример #8
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);
}
Пример #9
0
int APY_NewUserDialog_DoIt(GWEN_DIALOG *dlg) {
  APY_NEWUSER_DIALOG *xdlg;
  AB_USER *u;
  int rv;
  uint32_t pid;
  AB_PROVIDER *pro;

  DBG_INFO(0, "Doit");
  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_NEWUSER_DIALOG, dlg);
  assert(xdlg);

  pro=AB_Banking_GetProvider(xdlg->banking, "aqpaypal");
  if (pro==NULL) {
    DBG_ERROR(AQPAYPAL_LOGDOMAIN, "Could not find backend, maybe some plugins are not installed?");
    // TODO: show error message
    return GWEN_DialogEvent_ResultHandled;
  }

  DBG_INFO(0, "Creating user");
  u=AB_Banking_CreateUser(xdlg->banking, "aqpaypal");
  if (u==NULL) {
    DBG_ERROR(AQPAYPAL_LOGDOMAIN, "Could not create user, maybe backend missing?");
    // TODO: show error message
    return GWEN_DialogEvent_ResultHandled;
  }

  /* generic setup */
  AB_User_SetUserName(u, xdlg->userName);
  AB_User_SetUserId(u, xdlg->userId);
  AB_User_SetCustomerId(u, xdlg->userId);
  AB_User_SetCountry(u, "de");
  AB_User_SetBankCode(u, "PAYPAL");

  APY_User_SetServerUrl(u, xdlg->url);
  APY_User_SetHttpVMajor(u, xdlg->httpVMajor);
  APY_User_SetHttpVMinor(u, xdlg->httpVMinor);

  DBG_INFO(0, "Adding user");
  rv=AB_Banking_AddUser(xdlg->banking, u);
  if (rv<0) {
    DBG_ERROR(AQPAYPAL_LOGDOMAIN, "Could not add user (%d)", rv);
    AB_User_free(u);
    return GWEN_DialogEvent_ResultHandled;
  }

  pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
			     GWEN_GUI_PROGRESS_ALLOW_EMBED |
			     GWEN_GUI_PROGRESS_SHOW_PROGRESS |
			     GWEN_GUI_PROGRESS_SHOW_ABORT,
			     I18N("Setting Up Paypal User"),
			     I18N("The user will be created."),
			     3,
			     0);
  /* lock new user */
  DBG_INFO(0, "Locking user");
  rv=AB_Banking_BeginExclUseUser(xdlg->banking, u);
  if (rv<0) {
    DBG_ERROR(AQPAYPAL_LOGDOMAIN, "Could not lock user (%d)", rv);
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Unable to lock users"));
    AB_Banking_DeleteUser(xdlg->banking, u);
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

#if 0
  DBG_INFO(0, "Getting certs (%08x)", AH_User_GetFlags(u));
  GWEN_Gui_ProgressLog(pid,
		       GWEN_LoggerLevel_Notice,
		       I18N("Retrieving SSL certificate"));
  rv=APY_Provider_GetCert(pro, u, 0, 1, 0);
  if (rv<0) {
    // TODO: retry with SSLv3 if necessary
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_ERROR(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
  if (rv==GWEN_ERROR_USER_ABORTED) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Aborted by user."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }
#endif

  GWEN_Gui_ProgressLog(pid,
		       GWEN_LoggerLevel_Notice,
		       I18N("Creating API credentials file"));
  rv=APY_User_SetApiSecrets(u, xdlg->apiPassword, xdlg->apiSignature, xdlg->apiUserId);
  if (rv<0) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Aborted by user."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }


  /* unlock user */
  DBG_INFO(0, "Unlocking user");
  rv=AB_Banking_EndExclUseUser(xdlg->banking, u, 0);
  if (rv<0) {
    DBG_INFO(AQPAYPAL_LOGDOMAIN,
	     "Could not unlock user [%s] (%d)",
	     AB_User_GetUserId(u), rv);
    GWEN_Gui_ProgressLog2(pid,
			  GWEN_LoggerLevel_Error,
			  I18N("Could not unlock user %s (%d)"),
			  AB_User_GetUserId(u), rv);
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    AB_Banking_DeleteUser(xdlg->banking, u);
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  if (1) {
    AB_ACCOUNT *account;
    int rv;
    static char accountname[256];

    account=AB_Banking_CreateAccount(xdlg->banking, APY_PROVIDER_NAME);
    assert(account);
#if 0
    AB_User_SetUserName(u, xdlg->userName);
    AB_User_SetUserId(u, xdlg->userId);
#endif
    AB_Account_SetOwnerName(account, AB_User_GetUserName(u));
    AB_Account_SetAccountNumber(account, AB_User_GetUserId(u));
    AB_Account_SetBankCode(account, "PAYPAL");
    AB_Account_SetBankName(account, "PAYPAL");
    strcpy(accountname, "PP ");
    strcat(accountname, AB_User_GetUserName(u));
    AB_Account_SetAccountName(account, accountname);
    AB_Account_SetUser(account, u);
    AB_Account_SetSelectedUser(account, u);

    rv=AB_Banking_AddAccount(xdlg->banking, account);
    if (rv<0) {
      DBG_INFO(AQPAYPAL_LOGDOMAIN, "Error adding account (%d)", rv);
      AB_Account_free(account);
      AB_Banking_DeleteUser(xdlg->banking, u);
      GWEN_Gui_ProgressEnd(pid);
      return GWEN_DialogEvent_ResultHandled;
    }
  }

  GWEN_Dialog_SetCharProperty(dlg,
			      "wiz_end_label",
			      GWEN_DialogProperty_Title,
			      0,
			      I18N("The user has been successfully setup."),
			      0);
  GWEN_Gui_ProgressEnd(pid);
  APY_NewUserDialog_EnterPage(dlg, PAGE_END, 1);

  xdlg->user=u;

  return GWEN_DialogEvent_ResultHandled;
}
Пример #10
0
int EBC_Provider_XchgIniRequest_H002(AB_PROVIDER *pro,
                                     GWEN_HTTP_SESSION *sess,
                                     AB_USER *u)
{
  int rv;
  GWEN_CRYPT_TOKEN *ct;
  const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
  uint32_t kid;
  const GWEN_CRYPT_TOKEN_KEYINFO *signKeyInfo=NULL;
  xmlNsPtr ns;
  EB_MSG *msg;
  const char *userId;
  EB_MSG *mRsp;
  EB_RC rc;
  xmlDocPtr doc;
  xmlNodePtr root_node = NULL;
  xmlNodePtr node = NULL;
  GWEN_BUFFER *tbuf;
  const char *signVersion;
  const char *s;
  GWEN_BUFFER *bufKey;
  GWEN_BUFFER *bufZip;
  GWEN_BUFFER *bufB64;

  userId=AB_User_GetUserId(u);

  /* 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 crypt key info */
  kid=GWEN_Crypt_Token_Context_GetSignKeyId(ctx);
  if (kid) {
    signKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
                                            0);
    if (signKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Sign key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
                           GWEN_LoggerLevel_Error,
                           I18N("Sign key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  signVersion=EBC_User_GetSignVersion(u);
  if (!(signVersion && *signVersion))
    signVersion="A004";

  if (strcasecmp(signVersion, "A004")==0) {
    /* encode according to "DFUE-Abkommen" */
    bufKey=GWEN_Buffer_new(0, 512, 0, 1);
    rc=EB_Key_Info_toBin(signKeyInfo, userId, "A004", 1024, bufKey);
    if (rc) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error writing key (rc=%06x)", rc);
      GWEN_Buffer_free(bufKey);
      return GWEN_ERROR_GENERIC;
    }

    /* zip order */
    bufZip=GWEN_Buffer_new(0, 512, 0, 1);
    if (EB_Zip_Deflate(GWEN_Buffer_GetStart(bufKey),
                       GWEN_Buffer_GetUsedBytes(bufKey),
                       bufZip)) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Unable to zip key data");
      GWEN_Buffer_free(bufZip);
      GWEN_Buffer_free(bufKey);
      return GWEN_ERROR_GENERIC;
    }
    GWEN_Buffer_free(bufKey);

    /* base64 encode for order */
    bufB64=GWEN_Buffer_new(0, 800, 0, 1);
    if (GWEN_Base64_Encode((const unsigned char *)GWEN_Buffer_GetStart(bufZip),
                           GWEN_Buffer_GetUsedBytes(bufZip),
                           bufB64, 0)) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error encoding key");
      GWEN_Buffer_free(bufB64);
      GWEN_Buffer_free(bufZip);
      return GWEN_ERROR_GENERIC;
    }
    GWEN_Buffer_free(bufZip);
  }
  else {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Unsupported sign version [%s]", signVersion);
    return GWEN_ERROR_INTERNAL;
  }

  /* create request */
  msg=EB_Msg_new();
  doc=EB_Msg_GetDoc(msg);
  root_node=xmlNewNode(NULL, BAD_CAST "ebicsUnsecuredRequest");
  xmlDocSetRootElement(doc, root_node);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.ebics.org/H002",
              NULL);
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
              BAD_CAST "ds");
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
              BAD_CAST "xsi");
  xmlNewNsProp(root_node,
               ns,
               BAD_CAST "schemaLocation", /* xsi:schemaLocation */
               BAD_CAST "http://www.ebics.org/H002 "
               "http://www.ebics.org/H002/ebics_keymgmt_request.xsd");
  xmlNewProp(root_node, BAD_CAST "Version", BAD_CAST "H002");
  xmlNewProp(root_node, BAD_CAST "Revision", BAD_CAST "1");

  /* header */
  node=xmlNewChild(root_node, NULL, BAD_CAST "header", NULL);
  xmlNewProp(node, BAD_CAST "authenticate", BAD_CAST "true");
  xmlNewChild(node, NULL, BAD_CAST "static", NULL);
  xmlNewChild(node, NULL, BAD_CAST "mutable", NULL);

  /* body */
  node=xmlNewChild(root_node, NULL, BAD_CAST "body", NULL);

  /* fill */
  s=EBC_User_GetPeerId(u);
  if (s)
    EB_Msg_SetCharValue(msg, "header/static/HostID", s);
  s=AB_User_GetCustomerId(u);
  if (s)
    EB_Msg_SetCharValue(msg, "header/static/PartnerID", s);
  EB_Msg_SetCharValue(msg, "header/static/UserID",
                      AB_User_GetUserId(u));
  EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderType", "INI");
  tbuf=GWEN_Buffer_new(0, 16, 0, 1);
  rv=EBC_Provider_Generate_OrderId(pro, tbuf);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error creating order id (%d)", rv);
    GWEN_Buffer_free(tbuf);
    GWEN_Buffer_free(bufB64);
    EB_Msg_free(msg);
    return rv;
  }
  EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderID",
                      GWEN_Buffer_GetStart(tbuf));
  GWEN_Buffer_free(tbuf);
  EB_Msg_SetCharValue(msg,
                      "header/static/OrderDetails/OrderAttribute",
                      "DZNNN");
  EB_Msg_SetCharValue(msg, "header/static/SecurityMedium", "0000");
  EB_Msg_SetCharValue(msg, "body/DataTransfer/OrderData",
                      GWEN_Buffer_GetStart(bufB64));
  GWEN_Buffer_free(bufB64);

  /* exchange requests */
  rv=EBC_Dialog_ExchangeMessages(sess, msg, &mRsp);
  if (rv<0 || rv>=300) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error exchanging messages (%d)", rv);
    EB_Msg_free(msg);
    return rv;
  }
  EB_Msg_free(msg);

  /* check response */
  assert(mRsp);

  /* log results */
  EBC_Provider_LogRequestResults(pro, mRsp, NULL);

  rc=EB_Msg_GetResultCode(mRsp);
  if ((rc & 0xff0000)==0x090000 ||
      (rc & 0xff0000)==0x060000) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc);
    EB_Msg_free(mRsp);
    return AB_ERROR_SECURITY;
  }
  rc=EB_Msg_GetBodyResultCode(mRsp);
  if (rc) {
    if ((rc & 0xff0000)==0x090000 ||
        (rc & 0xff0000)==0x060000) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc);
      EB_Msg_free(mRsp);
      if ((rc & 0xfff00)==0x091300 ||
          (rc & 0xfff00)==0x091200)
        return AB_ERROR_SECURITY;
      else
        return GWEN_ERROR_GENERIC;
    }
  }

  EB_Msg_free(mRsp);

  /* adjust user status and flags */
  DBG_NOTICE(AQEBICS_LOGDOMAIN, "Adjusting user flags");
  EBC_User_AddFlags(u, EBC_USER_FLAGS_INI);
  if ((EBC_User_GetFlags(u) & (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA))
      ==
      (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA))
    EBC_User_SetStatus(u, EBC_UserStatus_Init2);
  else
    EBC_User_SetStatus(u, EBC_UserStatus_Init1);

  return 0;
}
Пример #11
0
int EBC_Provider_ExecQueue(AB_PROVIDER *pro,
			   AB_IMEXPORTER_CONTEXT *ctx) {
  EBC_PROVIDER *dp;
  EBC_USERQUEUE_LIST *uql;
  int errors=0;
  int oks=0;
  int rv;
  AB_BANKING *ab;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  ab=AB_Provider_GetBanking(pro);
  assert(ab);

  uql=EBC_Queue_GetUserQueues(dp->queue);
  if (uql) {
    EBC_USERQUEUE *uq;

    uq=EBC_UserQueue_List_First(uql);
    while(uq) {
      AB_USER *u;

      u=EBC_UserQueue_GetUser(uq);
      assert(u);
      GWEN_Gui_ProgressLog(0,
			   GWEN_LoggerLevel_Info,
			   I18N("Locking user"));
      rv=AB_Banking_BeginExclUseUser(ab, u);
      if (rv) {
	DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
	errors++;
      }
      else {
	GWEN_Gui_ProgressLog(0,
			     GWEN_LoggerLevel_Info,
			     I18N("Executing user queue"));
	rv=EBC_Provider_ExecUserQueue(pro, ctx, uq);
	if (rv)
	  errors++;
	else
	  oks++;
	if (rv==GWEN_ERROR_USER_ABORTED) {
	  DBG_INFO(AQEBICS_LOGDOMAIN, "User aborted");
	  GWEN_Gui_ProgressLog(0,
			       GWEN_LoggerLevel_Info,
			       I18N("Unlocking user"));
	  AB_Banking_EndExclUseUser(ab, u, 1);
	  return rv;
	}
	rv=AB_Banking_EndExclUseUser(ab, u, 0);
	if (rv<0) {
	  DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
	}
      }
      uq=EBC_UserQueue_List_Next(uq);
    } /* while */
  }

  return 0;
}
Пример #12
0
int AO_NewUserDialog_DoIt(GWEN_DIALOG *dlg)
{
  AO_NEWUSER_DIALOG *xdlg;
  AB_USER *u;
  int rv;
  uint32_t pid;

  DBG_ERROR(0, "Doit");
  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
  assert(xdlg);

  DBG_ERROR(0, "Creating user");
  u=AB_Provider_CreateUserObject(xdlg->provider);
  if (u==NULL) {
    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "Could not create user, maybe backend missing?");
    // TODO: show error message
    return GWEN_DialogEvent_ResultHandled;
  }

  /* generic setup */
  AB_User_SetUserName(u, xdlg->userName);
  AB_User_SetUserId(u, xdlg->userId);
  AB_User_SetCustomerId(u, xdlg->userId);
  AB_User_SetCountry(u, "us");
  AO_User_SetBankName(u, xdlg->bankName);
  AB_User_SetBankCode(u, "0000000000");

  AO_User_SetFlags(u, xdlg->flags);
  AO_User_SetBrokerId(u, xdlg->brokerId);
  AO_User_SetOrg(u, xdlg->org);
  AO_User_SetFid(u, xdlg->fid);

  AO_User_SetAppId(u, xdlg->appId);
  AO_User_SetAppVer(u, xdlg->appVer);
  AO_User_SetHeaderVer(u, xdlg->headerVer);
  AO_User_SetClientUid(u, xdlg->clientUid);
  AO_User_SetSecurityType(u, xdlg->securityType);

  AO_User_SetServerAddr(u, xdlg->url);
  AO_User_SetHttpVMajor(u, xdlg->httpVMajor);
  AO_User_SetHttpVMinor(u, xdlg->httpVMinor);

  DBG_ERROR(0, "Adding user");
  rv=AB_Provider_AddUser(xdlg->provider, u);
  if (rv<0) {
    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "Could not add user (%d)", rv);
    AB_User_free(u);
    return GWEN_DialogEvent_ResultHandled;
  }

  pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
                             GWEN_GUI_PROGRESS_ALLOW_EMBED |
                             GWEN_GUI_PROGRESS_SHOW_PROGRESS |
                             GWEN_GUI_PROGRESS_SHOW_ABORT,
                             I18N("Setting Up OFX DirectConnect User"),
                             I18N("The user will be created and the certificate retrieved."),
                             1,
                             0);
  /* lock new user */
  DBG_ERROR(0, "Locking user");
  rv=AB_Provider_BeginExclUseUser(xdlg->provider, u);
  if (rv<0) {
    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "Could not lock user (%d)", rv);
    GWEN_Gui_ProgressLog(pid,
                         GWEN_LoggerLevel_Error,
                         I18N("Unable to lock users"));
    AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  GWEN_Gui_ProgressLog(pid,
                       GWEN_LoggerLevel_Notice,
                       I18N("Retrieving SSL certificate"));
  rv=AO_Provider_GetCert(xdlg->provider, u);
  if (rv<0) {
    AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
    AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
  if (rv==GWEN_ERROR_USER_ABORTED) {
    AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
    DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
    AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
    GWEN_Gui_ProgressLog(pid,
                         GWEN_LoggerLevel_Error,
                         I18N("Aborted by user."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  /* unlock user */
  DBG_ERROR(0, "Unlocking user");
  rv=AB_Provider_EndExclUseUser(xdlg->provider, u, 0);
  if (rv<0) {
    DBG_INFO(AQOFXCONNECT_LOGDOMAIN,
             "Could not unlock user [%s] (%d)",
             AB_User_GetUserId(u), rv);
    GWEN_Gui_ProgressLog2(pid,
                          GWEN_LoggerLevel_Error,
                          I18N("Could not unlock user %s (%d)"),
                          AB_User_GetUserId(u), rv);
    AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
    AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  GWEN_Gui_ProgressEnd(pid);
  AO_NewUserDialog_EnterPage(dlg, PAGE_END, 1);

  xdlg->user=u;

  return GWEN_DialogEvent_ResultHandled;
}
Пример #13
0
/* --------------------------------------------------------------- FUNCTION */
AH_JOB *AH_AccountJob_new(const char *name,
                          AB_USER *u,
                          AB_ACCOUNT *account){
  AH_ACCOUNTJOB *aj;
  AH_JOB *j;
  GWEN_DB_NODE *dbArgs;
  const char *s;
  int jobVersion=0;

  assert(name);
  assert(u);
  assert(account);

  if (!(AH_Account_GetFlags(account) & AH_BANK_FLAGS_KTV2)) {
    int maxVer=0;

    /* no account suffix, so we try to determine the highest usable
     * version of the job which still doesn't need the suffix
     */
    if (strcasecmp(name, "JobGetTransactions")==0)
      maxVer=4;
    else if (strcasecmp(name, "JobGetBalance")==0)
      maxVer=4;
    else if (strcasecmp(name, "JobSingleTransfer")==0)
      maxVer=3;
    else if (strcasecmp(name, "JobSingleDebitNote")==0)
      maxVer=3;
    else if (strcasecmp(name, "JobInternalTransfer")==0 ||
	     strcasecmp(name, "JobLoadCellPhone")==0)
      /* this job needs a suffix, so if there is none you don't get it */
      maxVer=-1;
    else if (strcasecmp(name, "JobGetDatedTransfers")==0)
      maxVer=1;
    else if (strcasecmp(name, "JobCreateDatedTransfer")==0)
      maxVer=2;
    else if (strcasecmp(name, "JobModifyDatedTransfer")==0)
      maxVer=2;
    else if (strcasecmp(name, "JobDeleteDatedTransfer")==0)
      maxVer=1;
    else if (strcasecmp(name, "JobCreateStandingOrder")==0)
      maxVer=2;
    else if (strcasecmp(name, "JobModifyStandingOrder")==0)
      maxVer=2;
    else if (strcasecmp(name, "JobDeleteStandingOrder")==0)
      maxVer=1;
    if (maxVer==-1) {
      DBG_ERROR(AQHBCI_LOGDOMAIN,
		"This job needs an account suffix, but your bank didn't provide one. "
		"Therefore this job is not supported with your account.");
      GWEN_Gui_ProgressLog(0,
			   GWEN_LoggerLevel_Error,
			   I18N("This job needs an account suffix, but your bank did not provide one. "
                                "Therefore this job is not supported with your account.\n"
                                "Setting a higher HBCI version in the user settings might fix "
                                "the problem."));
      return NULL;
    }
    if (maxVer>0) {
      jobVersion=AH_Job_GetMaxVersionUpUntil(name, u, maxVer);
      if (jobVersion<1) {
	DBG_ERROR(AQHBCI_LOGDOMAIN, "No job [%s] below version %d, falling back to 0", name, maxVer);
	GWEN_Gui_ProgressLog2(0,
			      GWEN_LoggerLevel_Warning,
			      "No version for job [%s] up to %d found, falling back to 0", name, maxVer);
	jobVersion=0;
      }
      else {
        DBG_INFO(AQHBCI_LOGDOMAIN, "Reducing version of job [%s] to %d", name, jobVersion);
      }
    }
  }

  j=AH_Job_new(name, u,
               AB_Account_GetAccountNumber(account),
               AB_Account_GetSubAccountId(account),
               jobVersion);
  if (!j)
    return 0;

  GWEN_NEW_OBJECT(AH_ACCOUNTJOB, aj);
  GWEN_INHERIT_SETDATA(AH_JOB, AH_ACCOUNTJOB, j, aj, AH_AccountJob_FreeData);
  aj->account=account;

  /* set some known arguments */
  dbArgs=AH_Job_GetArguments(j);
  assert(dbArgs);

  s=AB_Account_GetAccountNumber(account);
  if (s && *s)
    GWEN_DB_SetCharValue(dbArgs, GWEN_DB_FLAGS_DEFAULT, "accountId", s);

  s=AB_Account_GetSubAccountId(account);
  if (s && *s)
    GWEN_DB_SetCharValue(dbArgs, GWEN_DB_FLAGS_DEFAULT, "accountSubId", s);

  s=AB_Account_GetBankCode(account);
  if (s && *s)
    GWEN_DB_SetCharValue(dbArgs, GWEN_DB_FLAGS_DEFAULT, "bankCode", s);

  GWEN_DB_SetIntValue(dbArgs, GWEN_DB_FLAGS_DEFAULT,
                      "country", 280);

  /* new for SEPA jobs */
  s=AB_Account_GetIBAN(account);
  if (s && *s)
    GWEN_DB_SetCharValue(dbArgs, GWEN_DB_FLAGS_DEFAULT, "iban", s);

  s=AB_Account_GetBIC(account);
  if (s && *s)
    GWEN_DB_SetCharValue(dbArgs, GWEN_DB_FLAGS_DEFAULT, "bic", s);

  return j;
}
Пример #14
0
int AO_Provider_SendAndReceive(AB_PROVIDER *pro,
			       AB_USER *u,
                               const uint8_t *p,
                               unsigned int plen,
			       GWEN_BUFFER **pRbuf) {
  AO_PROVIDER *dp;
  GWEN_HTTP_SESSION *sess=NULL;
  GWEN_BUFFER *rbuf;
  int rv;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, AO_PROVIDER, pro);
  assert(dp);

  if (getenv("AQOFX_LOG_COMM")) {
    FILE *f;

    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN,
	      "Saving response in \"/tmp/ofx.log\" ...");
    GWEN_Gui_ProgressLog(0,
			 GWEN_LoggerLevel_Warning,
			 I18N("Saving communication log to /tmp/ofx.log"));

    f=fopen("/tmp/ofx.log", "a+");
    if (!f) {
      DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "fopen: %s", strerror(errno));
    }
    else {
      fprintf(f, "\n\nSending:\n");
      fprintf(f, "-------------------------------------\n");
      if (fwrite(p,
		 plen,
                 1,
                 f)!=1) {
        DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "fwrite: %s", strerror(errno));
      }
      if (fclose(f)) {
	DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "fclose: %s", strerror(errno));
      }
    }
  }

  /* setup connection */
  rv=AO_Provider_CreateConnection(pro, u, &sess);
  if (rv) {
    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN,
	      "Could not create connection");
    GWEN_Gui_ProgressLog2(0,
			  GWEN_LoggerLevel_Error,
			  I18N("Could not create connection (%d)"),
			  rv);
    return rv;
  }

  /* send request */
  GWEN_Gui_ProgressLog(0,
		       GWEN_LoggerLevel_Info,
		       I18N("Sending request..."));
  rv=GWEN_HttpSession_SendPacket(sess, "POST", p, plen);
  if (rv<0) {
    DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
    GWEN_HttpSession_Fini(sess);
    GWEN_HttpSession_free(sess);
    return rv;
  }

  /* wait for response */
  GWEN_Gui_ProgressLog(0,
		       GWEN_LoggerLevel_Info,
		       I18N("Waiting for response..."));
  rbuf=GWEN_Buffer_new(0, 1024, 0, 1);
  rv=GWEN_HttpSession_RecvPacket(sess, rbuf);
  if (rv<0) {
    DBG_INFO(AQOFXCONNECT_LOGDOMAIN,
             "Error receiving packet (%d)", rv);
    GWEN_Gui_ProgressLog(0,
			 GWEN_LoggerLevel_Error,
			 I18N("Network error while waiting for response"));
    GWEN_Buffer_free(rbuf);
    GWEN_HttpSession_Fini(sess);
    GWEN_HttpSession_free(sess);
    return rv;
  }
  else if (!(rv>=200 && rv<=299)) {
    /* not a HTTP: ok code */
    DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(rbuf);
    GWEN_HttpSession_Fini(sess);
    GWEN_HttpSession_free(sess);
    return rv;
  }

  /* disconnect (ignore result) */
  GWEN_HttpSession_Fini(sess);
  GWEN_HttpSession_free(sess);

  /* found a response, transform it */
  GWEN_Gui_ProgressLog(0,
		       GWEN_LoggerLevel_Info,
		       I18N("Parsing response..."));

  *pRbuf=rbuf;

  if (getenv("AQOFX_LOG_COMM")) {
    FILE *f;

    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN,
	      "Saving response in \"/tmp/ofx.log\" ...");
    f=fopen("/tmp/ofx.log", "a+");
    if (!f) {
      DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "fopen: %s", strerror(errno));
    }
    else {
      fprintf(f, "\n\nReceived:\n");
      fprintf(f, "-------------------------------------\n");
      if (fwrite(GWEN_Buffer_GetStart(rbuf),
		 GWEN_Buffer_GetUsedBytes(rbuf),
		 1,
		 f)!=1) {
	DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "fwrite: %s", strerror(errno));
      }
      if (fclose(f)) {
	DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "fclose: %s", strerror(errno));
      }
    }
  }

  return 0;
}
Пример #15
0
int AH_Msg_VerifyRdh2(AH_MSG *hmsg, GWEN_DB_NODE *gr) {
  AH_HBCI *h;
  GWEN_LIST *sigheads;
  GWEN_LIST *sigtails;
  GWEN_DB_NODE *n;
  int nonSigHeads;
  int nSigheads;
  unsigned int dataBegin;
  char *dataStart;
  unsigned int dataLength;
  unsigned int i;
  AB_USER *u;
  GWEN_CRYPT_TOKEN *ct;
  const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
  const GWEN_CRYPT_TOKEN_KEYINFO *ki;
  uint32_t keyId;
  int ksize;
  int rv;
  uint32_t gid;

  assert(hmsg);
  h=AH_Dialog_GetHbci(hmsg->dialog);
  assert(h);
  u=AH_Dialog_GetDialogOwner(hmsg->dialog);
  assert(u);

  gid=0;

  /* get crypt token of signer */
  rv=AB_Banking_GetCryptToken(AH_HBCI_GetBankingApi(h),
			   AH_User_GetTokenType(u),
			   AH_User_GetTokenName(u),
			   &ct);
  if (rv) {
    DBG_INFO(AQHBCI_LOGDOMAIN,
	     "Could not get crypt token for user \"%s\" (%d)",
	     AB_User_GetUserId(u), rv);
    return rv;
  }

  /* open CryptToken if necessary */
  if (!GWEN_Crypt_Token_IsOpen(ct)) {
    GWEN_Crypt_Token_AddModes(ct, GWEN_CRYPT_TOKEN_MODE_DIRECT_SIGN);
    rv=GWEN_Crypt_Token_Open(ct, 0, gid);
    if (rv) {
      DBG_INFO(AQHBCI_LOGDOMAIN,
	       "Could not open crypt token for user \"%s\" (%d)",
	       AB_User_GetUserId(u), rv);
      return rv;
    }
  }

  /* get context and key info */
  ctx=GWEN_Crypt_Token_GetContext(ct,
				  AH_User_GetTokenContextId(u),
				  gid);
  if (ctx==NULL) {
    DBG_INFO(AQHBCI_LOGDOMAIN,
	     "Context %d not found on crypt token [%s:%s]",
	     AH_User_GetTokenContextId(u),
	     GWEN_Crypt_Token_GetTypeName(ct),
	     GWEN_Crypt_Token_GetTokenName(ct));
    return GWEN_ERROR_NOT_FOUND;
  }

  /* let's go */
  sigheads=GWEN_List_new();

  /* enumerate signature heads */
  nonSigHeads=0;
  nSigheads=0;
  n=GWEN_DB_GetFirstGroup(gr);
  while(n) {
    if (strcasecmp(GWEN_DB_GroupName(n), "SigHead")==0) {
      /* found a signature head */
      if (nonSigHeads) {
	DBG_ERROR(AQHBCI_LOGDOMAIN,
		  "Found some unsigned parts at the beginning");
        GWEN_List_free(sigheads);
        return GWEN_ERROR_BAD_DATA;
      }
      GWEN_List_PushBack(sigheads, n);
      nSigheads++;
    }
    else if (strcasecmp(GWEN_DB_GroupName(n), "MsgHead")!=0) {
      if (nSigheads)
        break;
      nonSigHeads++;
    }
    n=GWEN_DB_GetNextGroup(n);
  } /* while */

  if (!n) {
    if (nSigheads) {
      DBG_ERROR(AQHBCI_LOGDOMAIN,
		"Found Signature heads but no other segments");
      GWEN_List_free(sigheads);
      return GWEN_ERROR_BAD_DATA;
    }
    DBG_DEBUG(AQHBCI_LOGDOMAIN, "No signatures");
    GWEN_List_free(sigheads);
    return 0;
  }

  /* only now we need the verify key */
  keyId=GWEN_Crypt_Token_Context_GetVerifyKeyId(ctx);
  if (keyId==0) {
    DBG_INFO(AQHBCI_LOGDOMAIN,
	     "No verify key id on crypt token [%s:%s]",
	     GWEN_Crypt_Token_GetTypeName(ct),
	     GWEN_Crypt_Token_GetTokenName(ct));
    return GWEN_ERROR_NOT_FOUND;
  }
  ki=GWEN_Crypt_Token_GetKeyInfo(ct,
				 keyId,
				 0xffffffff,
				 gid);
  if (ki==NULL) {
    DBG_INFO(AQHBCI_LOGDOMAIN,
	     "Keyinfo %04x not found on crypt token [%s:%s]",
	     keyId,
	     GWEN_Crypt_Token_GetTypeName(ct),
	     GWEN_Crypt_Token_GetTokenName(ct));
    /* no longer return an error, it might be ok to not have a key info
     * even if we do not propagate the error here the check functions will
     * later find out that the signature is missing */
    return 0;
  }

  ksize=GWEN_Crypt_Token_KeyInfo_GetKeySize(ki);
  assert(ksize<=256);

  /* store begin of signed data */
  dataBegin=GWEN_DB_GetIntValue(n, "segment/pos", 0, 0);
  if (!dataBegin) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No position specifications in segment");
    GWEN_List_free(sigheads);
    return GWEN_ERROR_BAD_DATA;
  }

  /* now get first signature tail */
  while(n) {
    if (strcasecmp(GWEN_DB_GroupName(n), "SigTail")==0) {
      unsigned int currpos;

      /* found a signature tail */
      currpos=GWEN_DB_GetIntValue(n, "segment/pos", 0, 0);
      if (!currpos || dataBegin>currpos) {
        DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad position specification in Signature tail");
        GWEN_List_free(sigheads);
        return GWEN_ERROR_BAD_DATA;
      }
      dataLength=currpos-dataBegin;
      break;
    }
    n=GWEN_DB_GetNextGroup(n);
  } /* while */

  if (!n) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No signature tail found");
    GWEN_List_free(sigheads);
    return GWEN_ERROR_BAD_DATA;
  }

  sigtails=GWEN_List_new();
  while(n) {
    if (strcasecmp(GWEN_DB_GroupName(n), "SigTail")!=0)
      break;
    GWEN_List_PushBack(sigtails, n);
    n=GWEN_DB_GetNextGroup(n);
  } /* while */

  if (!n) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Message tail expected");
    GWEN_List_free(sigheads);
    GWEN_List_free(sigtails);
    return GWEN_ERROR_BAD_DATA;
  }

  if (strcasecmp(GWEN_DB_GroupName(n), "MsgTail")!=0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Unexpected segment (msg tail expected)");
    GWEN_List_free(sigheads);
    GWEN_List_free(sigtails);
    return GWEN_ERROR_BAD_DATA;
  }

  n=GWEN_DB_GetNextGroup(n);
  if (n) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Unexpected segment (end expected)");
    GWEN_List_free(sigheads);
    GWEN_List_free(sigtails);
    return GWEN_ERROR_BAD_DATA;
  }

  if (GWEN_List_GetSize(sigheads)!=
      GWEN_List_GetSize(sigtails)) {
    DBG_ERROR(AQHBCI_LOGDOMAIN,
              "Number of signature heads (%d) does not match "
              "number of signature tails (%d)",
              GWEN_List_GetSize(sigheads),
              GWEN_List_GetSize(sigtails));
    GWEN_List_free(sigheads);
    GWEN_List_free(sigtails);
    return GWEN_ERROR_BAD_DATA;
  }

  /* ok, now verify all signatures */
  dataStart=GWEN_Buffer_GetStart(hmsg->buffer)+dataBegin;
  for (i=0; i< GWEN_List_GetSize(sigtails); i++) {
    GWEN_DB_NODE *sighead;
    GWEN_DB_NODE *sigtail;
    const uint8_t *p;
    uint32_t l;
    int rv;
    uint8_t hash[20];
    const char *signerId;

    /* get signature tail */
    sigtail=(GWEN_DB_NODE*)GWEN_List_GetBack(sigtails);

    /* get corresponding signature head */
    sighead=(GWEN_DB_NODE*)GWEN_List_GetFront(sigheads);

    if (!sighead || !sigtail) {
      DBG_ERROR(AQHBCI_LOGDOMAIN,
		"No signature head/tail left (internal error)");
      GWEN_List_free(sigheads);
      GWEN_List_free(sigtails);
      return GWEN_ERROR_INTERNAL;
    }

    GWEN_List_PopBack(sigtails);
    GWEN_List_PopFront(sigheads);

    signerId=GWEN_DB_GetCharValue(sighead, "key/userid", 0,
				  I18N("unknown"));

    /* some checks */
    if (strcasecmp(GWEN_DB_GetCharValue(sighead, "ctrlref", 0, ""),
                   GWEN_DB_GetCharValue(sigtail, "ctrlref", 0, ""))!=0) {
      DBG_ERROR(AQHBCI_LOGDOMAIN, "Non-matching signature tail");
      GWEN_List_free(sigheads);
      GWEN_List_free(sigtails);
      return GWEN_ERROR_BAD_DATA;
    }

    /* hash signature head and data */
    if (1) {
      GWEN_MDIGEST *md;

      /* hash sighead + data */
      p=(const uint8_t*)GWEN_Buffer_GetStart(hmsg->buffer);
      p+=GWEN_DB_GetIntValue(sighead,
			     "segment/pos",
			     0,
			     0);
      l=GWEN_DB_GetIntValue(sighead,
			    "segment/length",
			    0,
			    0);

      md=GWEN_MDigest_Rmd160_new();
      rv=GWEN_MDigest_Begin(md);
      if (rv==0)
        /* digest signature head */
	rv=GWEN_MDigest_Update(md, p, l);
      if (rv==0)
	/* digest data */
	rv=GWEN_MDigest_Update(md, (const uint8_t*)dataStart, dataLength);
      if (rv==0)
	rv=GWEN_MDigest_End(md);
      if (rv<0) {
	DBG_ERROR(AQHBCI_LOGDOMAIN, "Hash error (%d)", rv);
	GWEN_MDigest_free(md);
	GWEN_List_free(sigheads);
	GWEN_List_free(sigtails);
	return rv;
      }
      memmove(hash,
	      GWEN_MDigest_GetDigestPtr(md),
	      GWEN_MDigest_GetDigestSize(md));
      GWEN_MDigest_free(md);
    }

    /* verify signature */
    p=GWEN_DB_GetBinValue(sigtail, "signature", 0, 0, 0, &l);
    if (p && l) {
      GWEN_CRYPT_PADDALGO *algo;

      algo=GWEN_Crypt_PaddAlgo_new(GWEN_Crypt_PaddAlgoId_Iso9796_2);
      GWEN_Crypt_PaddAlgo_SetPaddSize(algo, ksize);
      rv=GWEN_Crypt_Token_Verify(ct, keyId,
				 algo,
				 hash, 20, p, l, 0, gid);
      GWEN_Crypt_PaddAlgo_free(algo);
      if (rv) {
	if (rv==GWEN_ERROR_NO_KEY) {
	  DBG_ERROR(AQHBCI_LOGDOMAIN,
		    "Unable to verify signature of user \"%s\" (no key)",
		    signerId);
	  GWEN_Gui_ProgressLog(gid,
			       GWEN_LoggerLevel_Error,
			       I18N("Unable to verify signature (no key)"));
	}
	else {
	  GWEN_BUFFER *tbuf;

	  tbuf=GWEN_Buffer_new(0, 32, 0, 1);
	  if (rv==GWEN_ERROR_VERIFY) {
	    DBG_ERROR(AQHBCI_LOGDOMAIN,
		      "Invalid signature of user \"%s\"", signerId);
	    GWEN_Gui_ProgressLog(gid,
				 GWEN_LoggerLevel_Error,
				 I18N("Invalid signature!!!"));
	    GWEN_Buffer_AppendString(tbuf, "!");
	  }
	  else {
	    GWEN_Gui_ProgressLog(gid,
				 GWEN_LoggerLevel_Error,
				 I18N("Could not verify signature"));
	    DBG_ERROR(AQHBCI_LOGDOMAIN,
		      "Could not verify data with medium of user \"%s\" (%d)",
		      AB_User_GetUserId(u), rv);
	    GWEN_Buffer_AppendString(tbuf, "?");
	  }

	  GWEN_Buffer_AppendString(tbuf, signerId);
	  AH_Msg_AddSignerId(hmsg, GWEN_Buffer_GetStart(tbuf));
	  GWEN_Buffer_free(tbuf);
	}
      }
      else {
	DBG_INFO(AQHBCI_LOGDOMAIN, "Message signed by \"%s\"", signerId);
	AH_Msg_AddSignerId(hmsg, signerId);
      }
    }
    else {
      DBG_DEBUG(AQHBCI_LOGDOMAIN, "No signature");
      GWEN_List_free(sigheads);
      GWEN_List_free(sigtails);
      return GWEN_ERROR_BAD_DATA;
    }

    DBG_DEBUG(AQHBCI_LOGDOMAIN, "Verification done");
  } /* for */

  GWEN_List_free(sigheads);
  GWEN_List_free(sigtails);
  return 0;
}
Пример #16
0
int GWEN_Crypt_Token_PluginManager_CheckToken(GWEN_PLUGIN_MANAGER *pm,
                                              GWEN_CRYPT_TOKEN_DEVICE devt,
                                              GWEN_BUFFER *typeName,
                                              GWEN_BUFFER *tokenName,
                                              uint32_t guiid)
{
  GWEN_PLUGIN_DESCRIPTION_LIST2 *pdl;

  assert(pm);

  pdl=GWEN_Crypt_Token_PluginManager_GetPluginDescrs(pm, devt);
  if (pdl==NULL) {
    DBG_ERROR(GWEN_LOGDOMAIN, "No plugin descriptions found for this device type");
    GWEN_Gui_ProgressLog(guiid,
                         GWEN_LoggerLevel_Error,
                         I18N("No plugin found for this device type"));
    GWEN_Gui_ProgressLog(guiid,
                         GWEN_LoggerLevel_Error,
                         I18N("If you're using a Debian/Ubuntu based system "
                              "please consider to install package "
                              LIBCHIPCARD_GWENHYWFAR_PLUGIN_PACKAGE));
    return GWEN_ERROR_NOT_FOUND;
  }
  else {
    GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *pit;

    pit=GWEN_PluginDescription_List2_First(pdl);
    if (pit) {
      GWEN_PLUGIN_DESCRIPTION *pd;
      uint32_t progressId;
      unsigned int pdcount;
      unsigned int cnt=0;

      pdcount=GWEN_PluginDescription_List2_GetSize(pdl);
      progressId=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
                                        GWEN_GUI_PROGRESS_ALLOW_EMBED |
                                        GWEN_GUI_PROGRESS_SHOW_PROGRESS |
                                        GWEN_GUI_PROGRESS_SHOW_LOG |
                                        GWEN_GUI_PROGRESS_ALWAYS_SHOW_LOG |
                                        GWEN_GUI_PROGRESS_SHOW_ABORT,
                                        I18N("Determining plugin module..."),
                                        NULL,
                                        pdcount,
                                        guiid);

      pd=GWEN_PluginDescription_List2Iterator_Data(pit);
      assert(pd);
      while (pd) {
        GWEN_XMLNODE *n;
        int err;
        GWEN_PLUGIN *pl;
        char logbuffer[256];

        n=GWEN_PluginDescription_GetXmlNode(pd);
        assert(n);

        snprintf(logbuffer, sizeof(logbuffer)-1,
                 I18N("Loading plugin \"%s\""),
                 GWEN_PluginDescription_GetName(pd));
        logbuffer[sizeof(logbuffer)-1]=0;
        GWEN_Gui_ProgressLog(progressId,
                             GWEN_LoggerLevel_Notice,
                             logbuffer);

        /* device type matches, check this plugin */
        pl=GWEN_PluginManager_GetPlugin(pm, GWEN_PluginDescription_GetName(pd));
        if (pl) {
          GWEN_BUFFER *lTokenName;
          int rv;

          lTokenName=GWEN_Buffer_dup(tokenName);

          snprintf(logbuffer, sizeof(logbuffer)-1,
                   I18N("Checking plugin \"%s\""),
                   GWEN_Plugin_GetName(pl));
          logbuffer[sizeof(logbuffer)-1]=0;
          GWEN_Gui_ProgressLog(progressId,
                               GWEN_LoggerLevel_Notice,
                               logbuffer);

          DBG_INFO(GWEN_LOGDOMAIN,
                   "Checking plugin \"%s\" for [%s]",
                   GWEN_Plugin_GetName(pl),
                   GWEN_Buffer_GetStart(lTokenName));

          rv=GWEN_Crypt_Token_Plugin_CheckToken(pl, lTokenName);
          switch (rv) {
          case 0:
            /* responsive plugin found */
            snprintf(logbuffer, sizeof(logbuffer)-1,
                     I18N("Plugin \"%s\" supports this token"),
                     GWEN_Plugin_GetName(pl));
            logbuffer[sizeof(logbuffer)-1]=0;
            err=GWEN_Gui_ProgressLog(progressId,
                                     GWEN_LoggerLevel_Notice,
                                     logbuffer);
            if (err==GWEN_ERROR_USER_ABORTED) {
              GWEN_Gui_ProgressEnd(progressId);
              GWEN_Buffer_free(lTokenName);
              GWEN_PluginDescription_List2Iterator_free(pit);
              GWEN_PluginDescription_List2_freeAll(pdl);
              return err;
            }

            GWEN_Buffer_Reset(typeName);
            GWEN_Buffer_AppendString(typeName, GWEN_Plugin_GetName(pl));
            GWEN_Buffer_Reset(tokenName);
            GWEN_Buffer_AppendBuffer(tokenName, lTokenName);
            GWEN_Buffer_free(lTokenName);
            GWEN_PluginDescription_List2Iterator_free(pit);
            GWEN_PluginDescription_List2_freeAll(pdl);
            GWEN_Gui_ProgressEnd(progressId);
            return 0;

          case GWEN_ERROR_NOT_IMPLEMENTED:
            snprintf(logbuffer, sizeof(logbuffer)-1,
                     I18N("Plugin \"%s\": Function not implemented"),
                     GWEN_Plugin_GetName(pl));
            logbuffer[sizeof(logbuffer)-1]=0;
            GWEN_Gui_ProgressLog(progressId,
                                 GWEN_LoggerLevel_Notice,
                                 logbuffer);
            break;

          case GWEN_ERROR_NOT_SUPPORTED:
            snprintf(logbuffer, sizeof(logbuffer)-1,
                     I18N("Plugin \"%s\" does not support this token"),
                     GWEN_Plugin_GetName(pl));
            logbuffer[sizeof(logbuffer)-1]=0;
            GWEN_Gui_ProgressLog(progressId,
                                 GWEN_LoggerLevel_Info,
                                 logbuffer);
            break;

          case GWEN_ERROR_BAD_NAME:
            snprintf(logbuffer, sizeof(logbuffer)-1,
                     I18N("Plugin \"%s\" supports this token, but the name "
                          "did not match"),
                     GWEN_Plugin_GetName(pl));
            logbuffer[sizeof(logbuffer)-1]=0;
            GWEN_Gui_ProgressLog(progressId,
                                 GWEN_LoggerLevel_Info,
                                 logbuffer);
            break;

          default:
            snprintf(logbuffer, sizeof(logbuffer)-1,
                     I18N("Plugin \"%s\": Unexpected error (%d)"),
                     GWEN_Plugin_GetName(pl), rv);
            logbuffer[sizeof(logbuffer)-1]=0;
            GWEN_Gui_ProgressLog(progressId,
                                 GWEN_LoggerLevel_Info,
                                 logbuffer);
            break;
          } /* switch */
        } /* if plugin loaded */
        else {
          snprintf(logbuffer, sizeof(logbuffer)-1,
                   I18N("Could not load plugin \"%s\""),
                   GWEN_PluginDescription_GetName(pd));
          logbuffer[sizeof(logbuffer)-1]=0;
          GWEN_Gui_ProgressLog(progressId,
                               GWEN_LoggerLevel_Warning,
                               logbuffer);
        }

        cnt++;
        err=GWEN_Gui_ProgressAdvance(progressId, cnt);
        if (err) {
          DBG_INFO(GWEN_LOGDOMAIN, "User aborted");
          GWEN_Gui_ProgressEnd(progressId);
          GWEN_PluginDescription_List2Iterator_free(pit);
          GWEN_PluginDescription_List2_freeAll(pdl);
          GWEN_Gui_ProgressEnd(progressId);
          return err;
        }

        pd=GWEN_PluginDescription_List2Iterator_Next(pit);
      }

      GWEN_Gui_ProgressEnd(progressId);
      GWEN_PluginDescription_List2Iterator_free(pit);
    }
    GWEN_PluginDescription_List2_freeAll(pdl);
  }

  return GWEN_ERROR_NOT_SUPPORTED;
}
Пример #17
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;
}
Пример #18
0
int EBC_Provider_ExecUserQueue(AB_PROVIDER *pro,
			       AB_IMEXPORTER_CONTEXT *ctx,
			       EBC_USERQUEUE *uq){
  EBC_PROVIDER *dp;
  int errors=0;
  int oks=0;
  GWEN_HTTP_SESSION *sess;
  int rv;
  EBC_ACCOUNTQUEUE_LIST *al;
  AB_BANKING *ab;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  ab=AB_Provider_GetBanking(pro);
  assert(ab);

  /* create and open session */
  sess=EBC_Dialog_new(pro,
		      EBC_UserQueue_GetUser(uq));
  rv=GWEN_HttpSession_Init(sess);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Could not open session");
    GWEN_HttpSession_free(sess);
    return rv;
  }

  al=EBC_UserQueue_GetAccountQueues(uq);
  if (al) {
    EBC_ACCOUNTQUEUE *aq;

    aq=EBC_AccountQueue_List_First(al);
    while(aq) {
      AB_ACCOUNT *a;

      a=EBC_AccountQueue_GetAccount(aq);
      assert(a);

      /* lock account */
      GWEN_Gui_ProgressLog(0,
			   GWEN_LoggerLevel_Info,
			   I18N("Locking account"));
      rv=AB_Banking_BeginExclUseAccount(ab, a);
      if (rv<0) {
        DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
	GWEN_Gui_ProgressLog(0,
			     GWEN_LoggerLevel_Error,
			     I18N("Could not lock account"));
      }
      else {
	GWEN_Gui_ProgressLog(0,
			     GWEN_LoggerLevel_Info,
			     I18N("Executing account queue"));
	rv=EBC_Provider_ExecAccountQueue(pro, ctx,
					 EBC_UserQueue_GetUser(uq),
					 sess, aq);
	if (!rv)
	  oks++;
	else {
	  errors++;
	  if (rv==GWEN_ERROR_USER_ABORTED) {
	    DBG_INFO(AQEBICS_LOGDOMAIN, "User aborted");
	    AB_Banking_EndExclUseAccount(ab, a, 1); /* abandon */
	    GWEN_HttpSession_Fini(sess);
	    GWEN_HttpSession_free(sess);
	    return rv;
	  }
	  else {
	    DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
	  }
	}

        /* unlock account */
	GWEN_Gui_ProgressLog(0,
			     GWEN_LoggerLevel_Info,
			     I18N("Unlocking account"));
	rv=AB_Banking_EndExclUseAccount(ab, a, 0);
	if (rv<0) {
	  DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
	  GWEN_Gui_ProgressLog(0,
			       GWEN_LoggerLevel_Error,
			       I18N("Could not unlock account"));
	}
      }

      aq=EBC_AccountQueue_List_Next(aq);
    }
  }

  /* close and destroy session */
  GWEN_HttpSession_Fini(sess);
  GWEN_HttpSession_free(sess);

  return 0;
}
Пример #19
0
/* --------------------------------------------------------------- FUNCTION */
int AH_Job_GetTransactions__ReadTransactions(AH_JOB *j,
                                             AB_IMEXPORTER_ACCOUNTINFO *ai,
					     const char *docType,
                                             int noted,
					     GWEN_BUFFER *buf){
  GWEN_DBIO *dbio;
  GWEN_SYNCIO *sio;
  int rv;
  GWEN_DB_NODE *db;
  GWEN_DB_NODE *dbDay;
  GWEN_DB_NODE *dbParams;
  AB_ACCOUNT *a;
  AB_USER *u;
  uint32_t progressId;
  uint64_t cnt=0;

  a=AH_AccountJob_GetAccount(j);
  assert(a);
  u=AH_Job_GetUser(j);
  assert(u);

  dbio=GWEN_DBIO_GetPlugin("swift");
  if (!dbio) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Plugin SWIFT is not found");
    GWEN_Gui_ProgressLog(0,
			 GWEN_LoggerLevel_Error,
			 I18N("Plugin \"SWIFT\" not found."));
    return AB_ERROR_PLUGIN_MISSING;
  }

  GWEN_Buffer_Rewind(buf);
  sio=GWEN_SyncIo_Memory_new(buf, 0);

  db=GWEN_DB_Group_new("transactions");
  dbParams=GWEN_DB_Group_new("params");
  GWEN_DB_SetCharValue(dbParams, GWEN_DB_FLAGS_OVERWRITE_VARS,
		       "type", docType);
  if (AH_User_GetFlags(u) & AH_USER_FLAGS_KEEP_MULTIPLE_BLANKS)
    GWEN_DB_SetIntValue(dbParams, GWEN_DB_FLAGS_OVERWRITE_VARS,
			"keepMultipleBlanks", 1);
  else
    GWEN_DB_SetIntValue(dbParams, GWEN_DB_FLAGS_OVERWRITE_VARS,
			"keepMultipleBlanks", 0);

  rv=GWEN_DBIO_Import(dbio, sio,
		      db, dbParams,
		      GWEN_PATH_FLAGS_CREATE_GROUP);
  if (rv<0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN,
	      "Error parsing SWIFT %s (%d)",
	      docType, rv);
    GWEN_DB_Group_free(dbParams);
    GWEN_DB_Group_free(db);
    GWEN_SyncIo_free(sio);
    GWEN_DBIO_free(dbio);
    return rv;
  }
  GWEN_DB_Group_free(dbParams);
  GWEN_SyncIo_free(sio);
  GWEN_DBIO_free(dbio);

  /* first count the groups */
  dbDay=GWEN_DB_FindFirstGroup(db, "day");
  while(dbDay) {
    GWEN_DB_NODE *dbT;

    dbT=GWEN_DB_FindFirstGroup(dbDay, "transaction");
    while(dbT) {
      cnt++;
      dbT=GWEN_DB_FindNextGroup(dbT, "transaction");
    } /* while */
    dbDay=GWEN_DB_FindNextGroup(dbDay, "day");
  } /* while */

  progressId=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
				    GWEN_GUI_PROGRESS_ALLOW_EMBED |
				    GWEN_GUI_PROGRESS_SHOW_PROGRESS |
				    GWEN_GUI_PROGRESS_SHOW_ABORT,
				    I18N("Importing transactions..."),
				    NULL,
				    cnt,
				    0);

  /* add transactions to list */
  dbDay=GWEN_DB_FindFirstGroup(db, "day");
  while(dbDay) {
    GWEN_DB_NODE *dbT;

    dbT=GWEN_DB_FindFirstGroup(dbDay, "transaction");
    while(dbT) {
      AB_TRANSACTION *t;

      t=AB_Transaction_fromDb(dbT);
      if (!t) {
        DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad transaction data:");
        GWEN_DB_Dump(dbT, 2);
      }
      else {
	const char *s;

        AB_Transaction_SetLocalBankCode(t, AB_User_GetBankCode(u));
        AB_Transaction_SetLocalAccountNumber(t,
                                             AB_Account_GetAccountNumber(a));

	/* some translations */
	s=AB_Transaction_GetRemoteIban(t);
	if (!(s && *s)) {
	  const char *sAid;

	  /* no remote IBAN set, check whether the bank sends this info in the
	   * fields for national account specifications (instead of the SWIFT
	   * field "?38" which was specified for this case) */
	  sAid=AB_Transaction_GetRemoteAccountNumber(t);
	  if (sAid && *sAid && AB_Banking_CheckIban(sAid)==0) {
	    /* there is a remote account number specification, and that is an IBAN,
	     * so we set that accordingly */
	    DBG_INFO(AQBANKING_LOGDOMAIN, "Setting remote IBAN from account number");
	    AB_Transaction_SetRemoteIban(t, sAid);

	    /* set remote BIC if it not already is */
	    s=AB_Transaction_GetRemoteBic(t);
	    if (!(s && *s)) {
	      const char *sBid;

	      sBid=AB_Transaction_GetRemoteBankCode(t);
	      if (sBid && *sBid) {
		DBG_INFO(AQBANKING_LOGDOMAIN, "Setting remote BIC from bank code");
		AB_Transaction_SetRemoteBic(t, sBid);
	      }
	    }
	  }
	}


        DBG_INFO(AQHBCI_LOGDOMAIN, "Adding transaction");
        if (noted)
	  AB_ImExporterAccountInfo_AddNotedTransaction(ai, t);
	else
          AB_ImExporterAccountInfo_AddTransaction(ai, t);
      }

      if (GWEN_ERROR_USER_ABORTED==
	  GWEN_Gui_ProgressAdvance(progressId, GWEN_GUI_PROGRESS_ONE)) {
	GWEN_Gui_ProgressEnd(progressId);
	return GWEN_ERROR_USER_ABORTED;
      }

      dbT=GWEN_DB_FindNextGroup(dbT, "transaction");
    } /* while */

    /* read all endsaldos */
    if (!noted) {
      dbT=GWEN_DB_FindFirstGroup(dbDay, "endSaldo");
      while (dbT) {
	GWEN_DB_NODE *dbX;
	GWEN_TIME *ti=0;
  
	dbX=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "date");
	if (dbX)
	  ti=GWEN_Time_fromDb(dbX);
	dbX=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "value");
	if (dbX) {
	  AB_VALUE *v;
  
	  v=AB_Value_fromDb(dbX);
	  if (v) {
	    AB_BALANCE *bal;
	    AB_ACCOUNT_STATUS *as;
  
	    bal=AB_Balance_new(v, ti);
	    AB_Value_free(v);
	    as=AB_AccountStatus_new();
	    if (ti)
	      AB_AccountStatus_SetTime(as, ti);
	    AB_AccountStatus_SetNotedBalance(as, bal);
	    AB_Balance_free(bal);
	    AB_ImExporterAccountInfo_AddAccountStatus(ai, as);
	  }
	}
	GWEN_Time_free(ti);
  
	dbT=GWEN_DB_FindNextGroup(dbT, "endSaldo");
      } /* while */
    }

    dbDay=GWEN_DB_FindNextGroup(dbDay, "day");
  } /* while */

  GWEN_Gui_ProgressEnd(progressId);

  GWEN_DB_Group_free(db);
  return 0;
}
Пример #20
0
int AH_NewKeyFileDialog_DoIt(GWEN_DIALOG *dlg) {
  AH_NEWKEYFILE_DIALOG *xdlg;
  AB_USER *u;
  GWEN_URL *url;
  int rv;
  uint32_t pid;
  AB_IMEXPORTER_CONTEXT *ctx;
  AB_PROVIDER *pro;
  GWEN_PLUGIN_MANAGER *pm;
  GWEN_PLUGIN *pl;
  GWEN_CRYPT_TOKEN *ct;

  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_NEWKEYFILE_DIALOG, dlg);
  assert(xdlg);

  rv=AH_NewKeyFileDialog_GetFilePageData(dlg);
  if (rv<0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No file?");
    // TODO: show error message
    return GWEN_DialogEvent_ResultHandled;
  }

  pro=AB_Banking_GetProvider(xdlg->banking, "aqhbci");
  if (pro==NULL) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not find backend, maybe some plugins are not installed?");
    GWEN_Gui_ShowError(I18N("Error"),
		       "%s",
		       I18N("Could not find HBCI backend, maybe some plugins are not installed?"));
    return GWEN_DialogEvent_ResultHandled;
  }

  u=AB_Banking_CreateUser(xdlg->banking, "aqhbci");
  if (u==NULL) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create user, maybe backend missing?");
    GWEN_Gui_ShowError(I18N("Error"), "%s", I18N("Could not find HBCI backend, maybe some plugins are not installed?"));
    return GWEN_DialogEvent_ResultHandled;
  }

  /* generic setup */
  AB_User_SetUserName(u, xdlg->userName);
  AB_User_SetUserId(u, xdlg->userId);
  if (xdlg->customerId && *(xdlg->customerId))
    AB_User_SetCustomerId(u, xdlg->customerId);
  else
    AB_User_SetCustomerId(u, xdlg->userId);
  AB_User_SetCountry(u, "de");

  AB_User_SetBankCode(u, xdlg->bankCode);

  /* HBCI setup */
  AH_User_SetTokenType(u, "ohbci");
  AH_User_SetTokenName(u, AH_NewKeyFileDialog_GetFileName(dlg));
  AH_User_SetTokenContextId(u, 1);
  AH_User_SetCryptMode(u, AH_CryptMode_Rdh);
  AH_User_SetStatus(u, AH_UserStatusPending);
  AH_User_SetHbciVersion(u, xdlg->hbciVersion);
  AH_User_SetRdhType(u, xdlg->rdhVersion);
  AH_User_SetFlags(u, xdlg->flags);

  /* create CryptToken */
  pm=GWEN_PluginManager_FindPluginManager(GWEN_CRYPT_TOKEN_PLUGIN_TYPENAME);
  if (pm==0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Plugin manager not found");
    GWEN_Gui_ShowError(I18N("Error"),
		       I18N("CryptToken plugin for type %s is not available. Did you install all necessary packages?"),
		       GWEN_CRYPT_TOKEN_PLUGIN_TYPENAME);
    return 3;
  }

  pl=GWEN_PluginManager_GetPlugin(pm, AH_User_GetTokenType(u));
  if (pl==0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Plugin not found");
    GWEN_Gui_ShowError(I18N("Error"),
		       I18N("CryptToken plugin for type %s is not available. Did you install all necessary packages?"),
		       AH_User_GetTokenType(u));
    AB_User_free(u);
    return GWEN_DialogEvent_ResultHandled;
  }

  ct=GWEN_Crypt_Token_Plugin_CreateToken(pl, AH_User_GetTokenName(u));
  if (ct==0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create crypt token");
    AB_User_free(u);
    return GWEN_DialogEvent_ResultHandled;
  }

  /* create crypt token */
  rv=GWEN_Crypt_Token_Create(ct, 0);
  if (rv<0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create token");
    GWEN_Gui_ShowError(I18N("Error"),
		       I18N("The keyfile %s could not be created. Maybe there already is a file of that name (%d)."),
		       GWEN_Crypt_Token_GetTokenName(ct),
		       rv);
    AB_User_free(u);
    return GWEN_DialogEvent_ResultHandled;
  }

  /* close crypt token */
  rv=GWEN_Crypt_Token_Close(ct, 0, 0);
  if (rv) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not close token");
    GWEN_Gui_ShowError(I18N("Error"),
		       I18N("The keyfile %s could not be closed. Please check disc space."),
		       GWEN_Crypt_Token_GetTokenName(ct),
		       rv);
    AB_User_free(u);
    unlink(AH_User_GetTokenName(u));
    return GWEN_DialogEvent_ResultHandled;
  }

  url=GWEN_Url_fromString(xdlg->url);
  assert(url);
  GWEN_Url_SetProtocol(url, "hbci");
  if (GWEN_Url_GetPort(url)==0)
    GWEN_Url_SetPort(url, 3000);
  AH_User_SetServerUrl(u, url);
  GWEN_Url_free(url);

  rv=AB_Banking_AddUser(xdlg->banking, u);
  if (rv<0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not add user (%d)", rv);
    GWEN_Gui_ShowError(I18N("Error"),
		       I18N("Could not add HBCI user, maybe there already is a user of that id (%d)"),
		       rv);
    AB_User_free(u);
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not add user, maybe there already is a user of the same id (%d)?", rv);
    return GWEN_DialogEvent_ResultHandled;
  }

  pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
			     GWEN_GUI_PROGRESS_ALLOW_EMBED |
			     GWEN_GUI_PROGRESS_SHOW_PROGRESS |
			     GWEN_GUI_PROGRESS_SHOW_ABORT,
			     I18N("Setting Up Keyfile User"),
			     I18N("The server keys will now be retrieved, keys created and sent to the bank."),
			     3, /* getkeys, mkKeys, sendKeys */
			     0);
  /* lock new user */
  rv=AB_Banking_BeginExclUseUser(xdlg->banking, u);
  if (rv<0) {
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not lock user (%d)", rv);
    GWEN_Gui_ProgressLog2(pid,
			  GWEN_LoggerLevel_Error,
			  I18N("Unable to lock users (%d)"), rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  /* get server keys id */
  GWEN_Gui_ProgressLog(pid,
		       GWEN_LoggerLevel_Notice,
		       I18N("Retrieving server keys"));
  ctx=AB_ImExporterContext_new();
  rv=AH_Provider_GetServerKeys(pro, u, ctx, 0, 1, 0);
  if (rv<0) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  rv=AH_NewKeyFileDialog_CheckBankIniLetter(dlg, u);
  if (rv<0) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Bad bank keys, you should contact your bank."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
  if (rv==GWEN_ERROR_USER_ABORTED) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Aborted by user."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  /* generate keys */
  rv=AH_Provider_CreateKeys(pro, u, 0);
  if (rv<0) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressLog2(pid,
			  GWEN_LoggerLevel_Error,
			  I18N("Error generating keys: %d"), rv);
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
  if (rv==GWEN_ERROR_USER_ABORTED) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Aborted by user."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  /* send user keys */
  GWEN_Gui_ProgressLog(pid,
		       GWEN_LoggerLevel_Notice,
		       I18N("Sending user keys"));
  ctx=AB_ImExporterContext_new();
  rv=AH_Provider_SendUserKeys2(pro, u, ctx, 0, 0, 1, 0); /* withAuthKey, withProgress, nounmount, doLock */
  if (rv<0) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
  if (rv==GWEN_ERROR_USER_ABORTED) {
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_Banking_DeleteUser(xdlg->banking, u);
    //unlink(AH_NewKeyFileDialog_GetFileName(dlg));
    GWEN_Gui_ProgressLog(pid,
			 GWEN_LoggerLevel_Error,
			 I18N("Aborted by user."));
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }


  /* unlock user */
  rv=AB_Banking_EndExclUseUser(xdlg->banking, u, 0);
  if (rv<0) {
    DBG_INFO(AQHBCI_LOGDOMAIN,
	     "Could not unlock customer [%s] (%d)",
	     AB_User_GetCustomerId(u), rv);
    GWEN_Gui_ProgressLog2(pid,
			  GWEN_LoggerLevel_Error,
			  I18N("Could not unlock user %s (%d)"),
			  AB_User_GetUserId(u), rv);
    AB_Banking_EndExclUseUser(xdlg->banking, u, 1);
    AB_Banking_DeleteUser(xdlg->banking, u);
    GWEN_Gui_ProgressEnd(pid);
    return GWEN_DialogEvent_ResultHandled;
  }

  GWEN_Gui_ProgressEnd(pid);
  AH_NewKeyFileDialog_EnterPage(dlg, PAGE_END, 1);

  xdlg->user=u;

  return GWEN_DialogEvent_ResultHandled;
}
Пример #21
0
int EBC_Provider_XchgHiaRequest_H003(AB_PROVIDER *pro,
                                     GWEN_HTTP_SESSION *sess,
                                     AB_USER *u)
{
  int rv;
  GWEN_CRYPT_TOKEN *ct;
  const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
  uint32_t kid;
  const GWEN_CRYPT_TOKEN_KEYINFO *cryptKeyInfo=NULL;
  const GWEN_CRYPT_TOKEN_KEYINFO *authKeyInfo=NULL;
  xmlNsPtr ns;
  EB_MSG *msg;
  const char *userId;
  const char *partnerId;
  EB_MSG *mRsp;
  EB_RC rc;
  xmlDocPtr doc;
  xmlNodePtr root_node = NULL;
  xmlNodePtr node = NULL;
  /*xmlNodePtr nodeX = NULL;*/
  GWEN_BUFFER *mbuf;
  GWEN_BUFFER *tbuf;
  const char *s;

  userId=AB_User_GetUserId(u);
  partnerId=AB_User_GetCustomerId(u);

  /* 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 crypt key info */
  kid=GWEN_Crypt_Token_Context_GetDecipherKeyId(ctx);
  if (kid) {
    cryptKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
                                             0);
    if (cryptKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Crypt key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
                           GWEN_LoggerLevel_Error,
                           I18N("Crypt key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  /* get auth sign key info */
  kid=GWEN_Crypt_Token_Context_GetAuthSignKeyId(ctx);
  if (kid) {
    authKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
                                            0);
    if (authKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Auth key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
                           GWEN_LoggerLevel_Error,
                           I18N("Auth key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  /* create HIARequestOrderData */
  doc=xmlNewDoc(BAD_CAST "1.0");
  doc->encoding=xmlCharStrdup("UTF-8");
  root_node=xmlNewNode(NULL, BAD_CAST "HIARequestOrderData");
  xmlDocSetRootElement(doc, root_node);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.ebics.org/H003",
              NULL);
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
              BAD_CAST "ds");
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
              BAD_CAST "xsi");
  xmlNewNsProp(root_node,
               ns,
               BAD_CAST "schemaLocation", /* xsi:schemaLocation */
               BAD_CAST "http://www.ebics.org/H003 "
               "http://www.ebics.org/H003/ebics_orders.xsd");

  /* create auth key tree */
  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "AuthenticationPubKeyInfo", NULL);
  rv=EB_Key_Info_toXml(authKeyInfo, node);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%d)", rv);
    xmlFreeDoc(doc);
    return GWEN_ERROR_INVALID;
  }
  xmlNewChild(node, NULL,
              BAD_CAST "AuthenticationVersion",
              BAD_CAST "X002");

  /* create crypt key tree */
  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "EncryptionPubKeyInfo", NULL);
  rv=EB_Key_Info_toXml(cryptKeyInfo, node);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%d)", rv);
    xmlFreeDoc(doc);
    return rv;
  }
  xmlNewChild(node, NULL,
              BAD_CAST "EncryptionVersion",
              BAD_CAST "E002");

  /* store partner id and user id */
  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "PartnerID",
                   BAD_CAST partnerId);

  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "UserID",
                   BAD_CAST userId);

  /* compress and base64 doc */
  mbuf=GWEN_Buffer_new(0, 512, 0, 1);
  rv=EB_Xml_Compress64Doc(doc, mbuf);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error compressing/encoding doc (%d)", rv);
    xmlFreeDoc(doc);
    return rv;
  }
  xmlFreeDoc(doc);

  /* create request */
  msg=EB_Msg_new();
  doc=EB_Msg_GetDoc(msg);
  root_node=xmlNewNode(NULL, BAD_CAST "ebicsUnsecuredRequest");
  xmlDocSetRootElement(doc, root_node);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.ebics.org/H003",
              NULL);
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
              BAD_CAST "ds");
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
              BAD_CAST "xsi");
  xmlNewNsProp(root_node,
               ns,
               BAD_CAST "schemaLocation", /* xsi:schemaLocation */
               BAD_CAST "http://www.ebics.org/H003 "
               "http://www.ebics.org/H003/ebics_keymgmt_request.xsd");
  xmlNewProp(root_node, BAD_CAST "Version", BAD_CAST "H003");
  xmlNewProp(root_node, BAD_CAST "Revision", BAD_CAST "1");

  /* header */
  node=xmlNewChild(root_node, NULL, BAD_CAST "header", NULL);
  xmlNewProp(node, BAD_CAST "authenticate", BAD_CAST "true");
  xmlNewChild(node, NULL, BAD_CAST "static", NULL);
  xmlNewChild(node, NULL, BAD_CAST "mutable", NULL);

  /* body */
  node=xmlNewChild(root_node, NULL, BAD_CAST "body", NULL);

  /* fill */
  s=EBC_User_GetPeerId(u);
  if (s)
    EB_Msg_SetCharValue(msg, "header/static/HostID", s);
  s=AB_User_GetCustomerId(u);
  if (s)
    EB_Msg_SetCharValue(msg, "header/static/PartnerID", s);
  EB_Msg_SetCharValue(msg, "header/static/UserID",
                      AB_User_GetUserId(u));
  EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderType", "HIA");
  tbuf=GWEN_Buffer_new(0, 16, 0, 1);
  rv=EBC_Provider_Generate_OrderId(pro, tbuf);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error exchanging messages (%d)", rv);
    GWEN_Buffer_free(tbuf);
    GWEN_Buffer_free(mbuf);
    EB_Msg_free(msg);
    return rv;
  }
  EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderID",
                      GWEN_Buffer_GetStart(tbuf));
  GWEN_Buffer_free(tbuf);
  EB_Msg_SetCharValue(msg,
                      "header/static/OrderDetails/OrderAttribute",
                      "DZNNN");
  EB_Msg_SetCharValue(msg, "header/static/SecurityMedium", "0200");
  EB_Msg_SetCharValue(msg, "body/DataTransfer/OrderData",
                      GWEN_Buffer_GetStart(mbuf));
  GWEN_Buffer_free(mbuf);

  /* exchange requests */
  rv=EBC_Dialog_ExchangeMessages(sess, msg, &mRsp);
  if (rv<0 || rv>=300) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error exchanging messages (%d)", rv);
    EB_Msg_free(msg);
    return rv;
  }
  EB_Msg_free(msg);

  /* check response */
  assert(mRsp);

  /* log results */
  EBC_Provider_LogRequestResults(pro, mRsp, NULL);

  rc=EB_Msg_GetResultCode(mRsp);
  if ((rc & 0xff0000)==0x090000 ||
      (rc & 0xff0000)==0x060000) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc);
    EB_Msg_free(mRsp);
    return AB_ERROR_SECURITY;
  }
  rc=EB_Msg_GetBodyResultCode(mRsp);
  if (rc) {
    if ((rc & 0xff0000)==0x090000 ||
        (rc & 0xff0000)==0x060000) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc);
      EB_Msg_free(mRsp);
      if ((rc & 0xfff00)==0x091300 ||
          (rc & 0xfff00)==0x091200)
        return AB_ERROR_SECURITY;
      else
        return GWEN_ERROR_GENERIC;
    }
  }

  EB_Msg_free(mRsp);

  /* adjust user status and flags */
  DBG_NOTICE(AQEBICS_LOGDOMAIN, "Adjusting user flags");
  EBC_User_AddFlags(u, EBC_USER_FLAGS_HIA);
  if ((EBC_User_GetFlags(u) & (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA))
      ==
      (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA))
    EBC_User_SetStatus(u, EBC_UserStatus_Init2);
  else
    EBC_User_SetStatus(u, EBC_UserStatus_Init1);

  return 0;
}
Пример #22
0
int AO_Provider__AddSignOn(AB_PROVIDER *pro,
			   AB_USER *u,
			   GWEN_BUFFER *buf) {
  GWEN_TIME *ti;
  const char *s;
  char userpass[64];

  ti=GWEN_CurrentTime();
  assert(ti);

  GWEN_Buffer_AppendString(buf, "<SIGNONMSGSRQV1>");
  GWEN_Buffer_AppendString(buf, "<SONRQ>");
  GWEN_Buffer_AppendString(buf, "<DTCLIENT>");
  if (AO_User_GetFlags(u) & AO_USER_FLAGS_SEND_SHORT_DATE)
    GWEN_Time_toString(ti, "YYYYMMDDhhmmss", buf);
  else
    GWEN_Time_toString(ti, "YYYYMMDDhhmmss.000", buf);

  s=AB_User_GetUserId(u);
  if (s) {
    GWEN_Buffer_AppendString(buf, "<USERID>");
    GWEN_Buffer_AppendString(buf, s);
    GWEN_Buffer_AppendString(buf, "\r\n");
  }
  else {
    DBG_ERROR(AQOFXCONNECT_LOGDOMAIN,
	      "Missing user id, should not happen");
    GWEN_Gui_ProgressLog(0,
			 GWEN_LoggerLevel_Error,
			 I18N("Missing user id, should not happen"));
    return GWEN_ERROR_INTERNAL;
  }

  /* get password */
  userpass[0]=0;
  while (strlen(userpass)<4) {
    GWEN_BUFFER *nbuf;
    int rv;
    char msg[]=I18S("Please enter the password for user %s"
                    "<html>"
                    "Please enter the password for user <b>%s</b>"
                    "</html>");
    char msgbuf[512];

    nbuf=GWEN_Buffer_new(0, 64, 0, 1);
    GWEN_Buffer_AppendString(nbuf, "OFX::userpass::");
    GWEN_Buffer_AppendString(nbuf, s);
    snprintf(msgbuf, sizeof(msgbuf), I18N(msg), s, s);
    rv=GWEN_Gui_GetPassword(0,
			    GWEN_Buffer_GetStart(nbuf),
			    I18N("Enter Password"),
			    msgbuf,
			    userpass,
			    4,
			    sizeof(userpass),
			    0);
    GWEN_Buffer_free(nbuf);
    if (rv<0) {
      memset(userpass, 0, sizeof(userpass));
      GWEN_Time_free(ti);
      return rv;
    }
  } /* while */

  GWEN_Buffer_AppendString(buf, "<USERPASS>");
  GWEN_Buffer_AppendString(buf, userpass);
  GWEN_Buffer_AppendString(buf, "\r\n");
  memset(userpass, 0, sizeof(userpass));

  GWEN_Buffer_AppendString(buf, "<LANGUAGE>ENG");

  /* possibly add FI */
  if (!(AO_User_GetFlags(u) & AO_USER_FLAGS_EMPTY_FID)) {
    if (AO_User_GetFid(u)) {
      GWEN_Buffer_AppendString(buf, "<FI>");
      s=AO_User_GetOrg(u);
      if (s) {
	GWEN_Buffer_AppendString(buf, "<ORG>");
	GWEN_Buffer_AppendString(buf, s);
      }
      s=AO_User_GetFid(u);
      if (s) {
	GWEN_Buffer_AppendString(buf, "<FID>");
	GWEN_Buffer_AppendString(buf, s);
      }
      GWEN_Buffer_AppendString(buf, "</FI>");
    }
  }

  /* add APPID */
  s=AO_User_GetAppId(u);
  if (s==NULL || *s==0)
    s="QWIN";
  GWEN_Buffer_AppendString(buf, "<APPID>");
  GWEN_Buffer_AppendString(buf, s);

  /* add APPVER */
  s=AO_User_GetAppVer(u);
  if (s==NULL || *s==0)
    s="1200";
  GWEN_Buffer_AppendString(buf, "<APPVER>");
  GWEN_Buffer_AppendString(buf, s);

  /* add CLIENTUID, if known */
  s=AO_User_GetClientUid(u);
  if (s && *s) {
    GWEN_Buffer_AppendString(buf, "<CLIENTUID>");
    GWEN_Buffer_AppendString(buf, s);
  }

  /* close elements */
  GWEN_Buffer_AppendString(buf, "</SONRQ>");
  GWEN_Buffer_AppendString(buf, "</SIGNONMSGSRQV1>");

  GWEN_Time_free(ti);

  return 0;
}
Пример #23
0
int EBC_Provider_XchgPubRequest_H002(AB_PROVIDER *pro,
				     GWEN_HTTP_SESSION *sess,
				     AB_USER *u,
				     const char *signVersion) {
  EBC_PROVIDER *dp;
  int rv;
  const char *userId;
  const char *partnerId;
  GWEN_BUFFER *bufKey;
  GWEN_CRYPT_TOKEN *ct;
  const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
  uint32_t kid;
  const GWEN_CRYPT_TOKEN_KEYINFO *signKeyInfo=NULL;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  userId=AB_User_GetUserId(u);
  partnerId=AB_User_GetCustomerId(u);

  /* 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 crypt key info */
  kid=GWEN_Crypt_Token_Context_GetTempSignKeyId(ctx);
  if (kid) {
    signKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
					    0);
    if (signKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Sign key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
			   GWEN_LoggerLevel_Error,
			   I18N("Sign key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  if (strcasecmp(signVersion, "A004")==0) {
    EB_RC rc;

    /* encode according to "DFUE-Abkommen" */
    bufKey=GWEN_Buffer_new(0, 512, 0, 1);
    rc=EB_Key_Info_toBin(signKeyInfo, userId, "A004", 1024, bufKey);
    if (rc) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error writing key (rc=%06x)", rc);
      GWEN_Buffer_free(bufKey);
      return GWEN_ERROR_GENERIC;
    }
  }
  else {
    xmlDocPtr doc;
    xmlNodePtr root_node = NULL;
    xmlNodePtr node = NULL;
    xmlNsPtr ns;

    /* create INIRequestOrderData */
    doc=xmlNewDoc(BAD_CAST "1.0");
    doc->encoding=xmlCharStrdup("UTF-8");
    root_node=xmlNewNode(NULL, BAD_CAST "PUBRequestOrderData");
    xmlDocSetRootElement(doc, root_node);
    ns=xmlNewNs(root_node,
		BAD_CAST "http://www.ebics.org/H002",
		NULL);
    assert(ns);
    ns=xmlNewNs(root_node,
		BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
		BAD_CAST "ds");
    assert(ns);
    ns=xmlNewNs(root_node,
		BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
		BAD_CAST "xsi");
    xmlNewNsProp(root_node,
		 ns,
		 BAD_CAST "schemaLocation", /* xsi:schemaLocation */
		 BAD_CAST "http://www.ebics.org/H002 "
		 "http://www.ebics.org/H002/ebics_orders.xsd");
  
    /* create sign key tree */
    node=xmlNewChild(root_node, NULL,
		     BAD_CAST "SignaturePubKeyInfo", NULL);
    rv=EB_Key_Info_toXml(signKeyInfo, node);
    if (rv<0) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%d)", rv);
      xmlFreeDoc(doc);
      return GWEN_ERROR_INVALID;
    }
    xmlNewChild(node, NULL,
                BAD_CAST "SignatureVersion",
                BAD_CAST signVersion);

    /* store partner id and user id */
    node=xmlNewChild(root_node, NULL,
		     BAD_CAST "PartnerID",
		     BAD_CAST partnerId);
  
    node=xmlNewChild(root_node, NULL,
		     BAD_CAST "UserID",
		     BAD_CAST userId);
  
    /* compress and base64 doc */
    bufKey=GWEN_Buffer_new(0, 4096, 0, 1);
    rv=EB_Xml_Compress64Doc(doc, bufKey);
    if (rv<0) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error compressing/encoding doc (%d)", rv);
      xmlFreeDoc(doc);
      return rv;
    }
    xmlFreeDoc(doc);
  }

  rv=EBC_Provider_XchgUploadRequest(pro, sess, u, "PUB",
				    (const uint8_t*)GWEN_Buffer_GetStart(bufKey),
				    GWEN_Buffer_GetUsedBytes(bufKey));
  if (rv<0) {
    DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(bufKey);
    return rv;
  }

  GWEN_Buffer_free(bufKey);
  return 0;
}