From ee7f39ea4fefbd1e1e00a65f1f1b4dd34bf6693c Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 7 Feb 2004 12:39:05 +0000 Subject: [PATCH] more openhbci2 work git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9829 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/import-export/hbci/druid-hbci-initial.c | 21 +++ src/import-export/hbci/druid-hbci-utils.c | 170 ++++++++++++++++++++ src/import-export/hbci/druid-hbci-utils.h | 4 + 3 files changed, 195 insertions(+) diff --git a/src/import-export/hbci/druid-hbci-initial.c b/src/import-export/hbci/druid-hbci-initial.c index 4d96c892bd..b3b03cb485 100644 --- a/src/import-export/hbci/druid-hbci-initial.c +++ b/src/import-export/hbci/druid-hbci-initial.c @@ -1276,6 +1276,21 @@ on_iniletter_info_next (GnomeDruidPage *gnomedruidpage, job = HBCI_OutboxJob_new("JobGetKeys", (HBCI_Customer*)info->newcustomer, ""); + + { + HBCI_Job *jjob = HBCI_OutboxJob_Job(job); + /* Copied from libaqmoney's JobGetKeys::JobGetKeys(Pointer c) */ + HBCI_Job_setIntProperty(jjob, "open/ident/country", HBCI_Bank_country(HBCI_User_bank(HBCI_Customer_user(info->newcustomer)))); + HBCI_Job_setProperty(jjob, "open/ident/bankcode", HBCI_Bank_bankCode(HBCI_User_bank(HBCI_Customer_user(info->newcustomer)))); + HBCI_Job_setProperty(jjob, "open/ident/customerId", "9999999999"); + HBCI_Job_setProperty(jjob, "open/ident/systemId", "0"); + + HBCI_Job_setIntProperty(jjob, "open/signkey/key/country", HBCI_Bank_country(HBCI_User_bank(HBCI_Customer_user(info->newcustomer)))); + HBCI_Job_setProperty(jjob, "open/signkey/key/bankcode", HBCI_Bank_bankCode(HBCI_User_bank(HBCI_Customer_user(info->newcustomer)))); + + HBCI_Job_setIntProperty(jjob, "open/cryptkey/key/country", HBCI_Bank_country(HBCI_User_bank(HBCI_Customer_user(info->newcustomer)))); + HBCI_Job_setProperty(jjob, "open/cryptkey/key/bankcode", HBCI_Bank_bankCode(HBCI_User_bank(HBCI_Customer_user(info->newcustomer)))); + } HBCI_Outbox_addJob (info->outbox, job); /* Execute Outbox. */ @@ -1285,6 +1300,12 @@ on_iniletter_info_next (GnomeDruidPage *gnomedruidpage, return FALSE; } + /* Get keys from Job; store them in the customer's medium @§%&! */ + if (!gnc_hbci_evaluate_GetKeys(info->outbox, job, + (HBCI_Customer *)info->newcustomer)) { + return FALSE; + } + HBCI_Outbox_removeByStatus (info->outbox, HBCI_JOB_STATUS_NONE); info->gotkeysforCustomer = info->newcustomer; diff --git a/src/import-export/hbci/druid-hbci-utils.c b/src/import-export/hbci/druid-hbci-utils.c index a46f5f702c..131559dfb4 100644 --- a/src/import-export/hbci/druid-hbci-utils.c +++ b/src/import-export/hbci/druid-hbci-utils.c @@ -47,6 +47,8 @@ /* #include "top-level.h" */ #include #include +#include +#include #include "gnc-hbci-utils.h" @@ -408,3 +410,171 @@ gnc_processOutboxResponse(HBCI_API *api, HBCI_Outbox *outbox, return accountlist; } + + +gboolean +gnc_hbci_evaluate_GetKeys(HBCI_Outbox *outbox, HBCI_OutboxJob *job, + HBCI_Customer *newcustomer) +{ + GWEN_DB_NODE *rsp; + GWEN_DB_NODE *n; + /*HBCI_Error *err;*/ + HBCI_RSAKey *_cryptKey = NULL; + HBCI_RSAKey *_signKey = NULL; + + g_assert(outbox); + g_assert(newcustomer); + + rsp = HBCI_Job_responseData(HBCI_OutboxJob_Job(job)); + if (!rsp) { + fprintf(stderr, "JobGetKeys::evaluate: no response data\n"); + return FALSE; + } + + printf("JobGetKeys: Complete response:\n"); + GWEN_DB_Dump(rsp, stderr, 1); + + n=GWEN_DB_GetFirstGroup(rsp); + while(n) { + if (strcasecmp(GWEN_DB_GroupName(n), "GetKeyResponse")==0) { + unsigned int bs; + const void *p; + GWEN_DB_NODE *keydb; + const char defaultExpo[3]={0x01, 0x00, 0x01}; + gboolean iscrypt; + + //DBG_NOTICE(0, "Found Key response"); + iscrypt=FALSE; + + keydb=GWEN_DB_Group_new("key"); + GWEN_DB_SetCharValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "type", + "RSA"); + // TODO: check for the correct exponent (for now assume 65537) + GWEN_DB_SetBinValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "data/e", + defaultExpo, + sizeof(defaultExpo)); + + GWEN_DB_SetIntValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "data/public", + 1); + + iscrypt=(strcasecmp(GWEN_DB_GetCharValue(n, + "keyname/keytype", 0, + "V"), "V")==0); + GWEN_DB_SetCharValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "name", + GWEN_DB_GetCharValue(n, + "keyname/keytype", 0, + "V")); + GWEN_DB_SetCharValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "owner", + GWEN_DB_GetCharValue(n, "keyname/userId", 0, "")); + GWEN_DB_SetIntValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "number", + GWEN_DB_GetIntValue(n, "keyname/keynum", 0, 0)); + GWEN_DB_SetIntValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "version", + GWEN_DB_GetIntValue(n, "keyname/keyversion", 0, 0)); + + + p=GWEN_DB_GetBinValue(n, "key/modulus", 0, 0, 0 , &bs); + if (!p || !bs) { + fprintf(stderr, "JobGetKeys::evaluate: no modulus\n"); + return FALSE; + } + GWEN_DB_SetBinValue(keydb, + GWEN_DB_FLAGS_OVERWRITE_VARS, + "data/n", + p, bs); + + if (iscrypt) + _cryptKey = HBCI_RSAKey_new(iscrypt, keydb); + else + _signKey = HBCI_RSAKey_new(iscrypt, keydb); + fprintf(stderr, "Created %s key", iscrypt?"crypt":"sign"); + } // if we have a key response + n=GWEN_DB_GetNextGroup(n); + } // while + + // Key creation finished. Now add them to the medium @§%$!!! + + { + HBCI_MediumRDHBase *mrdh; + HBCI_Medium *medium; + const HBCI_Bank *bank; + const HBCI_User *user; + HBCI_Error *err; + + // get some vars + user = HBCI_Customer_user(newcustomer); + bank = HBCI_User_bank(user); + medium = (HBCI_Medium *) HBCI_User_medium(user); + mrdh = HBCI_Medium_MediumRDHBase (medium); + + // mount medium + err = HBCI_Medium_mountMedium(medium, ""); + if (err && !HBCI_Error_isOk(err)) { + fprintf(stderr, "JobGetKeys::commit: 1\n"); + return FALSE; + } + + // select context + err = HBCI_Medium_selectContext(medium, HBCI_Bank_country(bank), + HBCI_Bank_bankCode(bank), + HBCI_User_userId(user)); + if (err && !HBCI_Error_isOk(err)) { + HBCI_Medium_unmountMedium(medium, ""); + fprintf(stderr, "JobGetKeys::commit: 2\n"); + return FALSE; + } + + // set crypt key + if (_cryptKey) { + fprintf(stderr, "Setting Institute Crypt Key\n"); + if (!HBCI_RSAKey_isCryptoKey(_cryptKey)) { + fprintf(stderr, "Crypt key expected\n"); + return FALSE; + } + err = HBCI_MediumRDHBase_setInstituteCryptKey(mrdh, _cryptKey); + if (err && !HBCI_Error_isOk(err)) { + HBCI_Medium_unmountMedium(medium, ""); + fprintf(stderr, "JobGetKeys::commit: 3\n"); + return FALSE; + } + } + + // set sign key + if (_signKey) { + fprintf(stderr, "Setting Institute Sign Key\n"); + err=HBCI_MediumRDHBase_setInstituteSignKey(mrdh, _signKey); + if (err && !HBCI_Error_isOk(err)) { + HBCI_Medium_unmountMedium(medium, ""); + fprintf(stderr, "JobGetKeys::commit: 4\n"); + return FALSE; + } + if (!HBCI_MediumRDHBase_hasInstSignKey(mrdh)) { + fprintf(stderr, "What ??? I just set the signkey but there is none ?!\n"); + } + } + + err = HBCI_Medium_unmountMedium(medium, ""); + if (err && !HBCI_Error_isOk(err)) { + fprintf(stderr, "JobGetKeys::commit: 5\n"); + return FALSE; + } + fprintf(stderr, "New institute keys activated\n"); + } + + // use result returned from lower class + return TRUE; +} + diff --git a/src/import-export/hbci/druid-hbci-utils.h b/src/import-export/hbci/druid-hbci-utils.h index d37acda5f5..2d234e7998 100644 --- a/src/import-export/hbci/druid-hbci-utils.h +++ b/src/import-export/hbci/druid-hbci-utils.h @@ -58,5 +58,9 @@ GList * gnc_processOutboxResponse(HBCI_API *api, HBCI_Outbox *outbox, GList *accountlist); +/* Get keys from Job; store them in the customer's medium @§%&! */ +gboolean +gnc_hbci_evaluate_GetKeys(HBCI_Outbox *outbox, HBCI_OutboxJob *job, + HBCI_Customer *newcustomer); #endif