Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Automatisches Abrufen der TAN-Medienbezeichnungen (zusammen mit den S…
Browse files Browse the repository at this point in the history
…EPA-Infos der Konten) und Bereitstellen dieser im HBCI-Callback NEED_PT_TANMEDIA (identisches Verfahren zu Callback NEED_PT_SECMECH). Damit kann HBCI4Java jetzt die Liste der TAN-Medienbezeichnungen bequem dem Aufrufer im Callback anbieten, ohne dass dieser sie manuell abrufen muss.
  • Loading branch information
willuhn committed Jan 5, 2015
1 parent 91feafc commit 6d6831c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 11 deletions.
28 changes: 27 additions & 1 deletion src/org/kapott/hbci/GV/GVTANMediaList.java
@@ -1,6 +1,7 @@
package org.kapott.hbci.GV;

import java.util.Properties;

import org.kapott.hbci.GV_Result.GVRTANMediaList;
import org.kapott.hbci.manager.HBCIHandler;
import org.kapott.hbci.manager.HBCIUtils;
Expand All @@ -18,7 +19,7 @@ public static String getLowlevelName()
public GVTANMediaList(HBCIHandler handler)
{
super(handler,getLowlevelName(),new GVRTANMediaList());
addConstraint("mediatype","mediatype","1", LogFilter.FILTER_NONE);
addConstraint("mediatype","mediatype","0", LogFilter.FILTER_NONE); // "1" gibts nicht. Siehe FinTS_3.0_Security_Sicherheitsverfahren_PINTAN_Rel_20101027_final_version.pdf "TAN-Medium-Art"
addConstraint("mediacategory", "mediacategory", "A", LogFilter.FILTER_NONE);
}

Expand All @@ -30,6 +31,9 @@ public void extractResults(HBCIMsgStatus msgstatus,String header,int idx)
if(s != null) {
((GVRTANMediaList)jobResult).setTanOption(Integer.parseInt(s));
}

// Da drin speichern wir die Namen der TAN-Medien - kommt direkt in die UPD im Passport
StringBuffer mediaNames = new StringBuffer();

for (int i=0;;i++) {
String mediaheader=HBCIUtilsInternal.withCounter(header+".MediaInfo",i);
Expand Down Expand Up @@ -76,6 +80,28 @@ public void extractResults(HBCIMsgStatus msgstatus,String header,int idx)
}

((GVRTANMediaList)jobResult).add(info);

// Es gibt auch noch "verfuegbar", da muss das Medium aber erst noch freigeschaltet werden
boolean isActive = info.status != null && info.status.equals("1");
boolean haveName = info.mediaName != null && info.mediaName.length() > 0;
// boolean isMobileTan = info.mediaCategory != null && info.mediaCategory.equalsIgnoreCase("M");

// Zu den UPD hinzufuegen
if (isActive && haveName)
{
if (mediaNames.length() != 0)
mediaNames.append("|");

mediaNames.append(info.mediaName);
}
}

String names = mediaNames.toString();
if (names.length() > 0)
{
HBCIUtils.log("adding TAN media names to UPD: " + names, HBCIUtils.LOG_INFO);
Properties upd = getParentHandler().getPassport().getUPD();
upd.setProperty("tanmedia.names",names);
}
}

Expand Down
71 changes: 65 additions & 6 deletions src/org/kapott/hbci/manager/HBCIHandler.java
Expand Up @@ -23,6 +23,7 @@

import java.lang.reflect.Constructor;
import java.security.KeyPair;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
Expand Down Expand Up @@ -141,19 +142,77 @@ public HBCIHandler(String hbciversion,HBCIPassport passport)
throw new HBCI_Exception(HBCIUtilsInternal.getLocMsg("EXCMSG_CANT_CREATE_HANDLE"),e);
}

// wenn in den UPD noch keine SEPA-Informationen ueber die Konten enthalten
// wenn in den UPD noch keine SEPA- und TAN-Medien-Informationen ueber die Konten enthalten
// sind, versuchen wir, diese zu holen
Properties upd=passport.getUPD();
if (upd!=null && !upd.getProperty("_fetchedSEPA","").equals("1")) {
// wir haben UPD, in denen aber nicht "_fetchedSEPA=1" drinsteht
updateSEPAInfo();
if (upd!=null && !upd.containsKey("_fetchedMetaInfo"))
{
// wir haben UPD, in denen aber nicht "_fetchedMetaInfo" drinsteht
updateMetaInfo();
}
}

/* wenn der GV SEPAInfo unterstützt wird, heißt das, dass die Bank mit
/**
* Ruft die SEPA-Infos der Konten sowie die TAN-Medienbezeichnungen ab.
* unterstuetzt wird und speichert diese Infos in den UPD.
*/
public void updateMetaInfo()
{
Properties bpd = passport.getBPD();
if (bpd == null)
{
HBCIUtils.log("have no bpd, skip fetching of meta info", HBCIUtils.LOG_WARN);
return;
}

try
{
final Properties lowlevel = this.getSupportedLowlevelJobs();

// SEPA-Infos abrufen
if (lowlevel.getProperty("SEPAInfo") != null)
{
HBCIUtils.log("fetching SEPA information", HBCIUtils.LOG_INFO);
HBCIJob sepainfo = this.newJob("SEPAInfo");
sepainfo.addToQueue();
}

// TAN-Medien abrufen - aber nur bei PIN/TAN-Verfahren
if (lowlevel.getProperty("TANMediaList") != null && (this.passport instanceof AbstractPinTanPassport))
{
HBCIUtils.log("fetching TAN media list", HBCIUtils.LOG_INFO);
HBCIJob tanMedia = this.newJob("TANMediaList");
tanMedia.addToQueue();
}

HBCIExecStatus status = this.execute();
if (status.isOK())
{
HBCIUtils.log("successfully fetched meta info", HBCIUtils.LOG_INFO);
passport.getUPD().setProperty("_fetchedMetaInfo",new Date().toString());
passport.saveChanges();
}
else
{
HBCIUtils.log("error while fetching meta info: " + status.toString(), HBCIUtils.LOG_ERR);
}
}
catch (Exception e)
{
// Wir werfen das nicht als Exception. Unschoen, wenn das nicht klappt.
// Aber kein Grund zur Panik.
HBCIUtils.log(e);
}
}


/**
* Wenn der GV SEPAInfo unterstützt wird, heißt das, dass die Bank mit
* SEPA-Konten umgehen kann. In diesem Fall holen wir die SEPA-Informationen
* über die Konten von der Bank ab - für jedes SEPA-fähige Konto werden u.a.
* BIC/IBAN geliefert */
* BIC/IBAN geliefert
* @deprecated Bitte <code>updateMetaInfo</code> verwenden. Das aktualisiert auch die TAN-Medien.
*/
public void updateSEPAInfo()
{
Properties bpd = passport.getBPD();
Expand Down
20 changes: 19 additions & 1 deletion src/org/kapott/hbci/manager/HBCIUser.java
Expand Up @@ -565,8 +565,26 @@ public void updateUPD(Properties result)

if (p.size()!=0) {
p.setProperty("_hbciversion",kernel.getHBCIVersion());

// Wir sichern wenigstens noch die TAN-Media-Infos, die vom HBCIHandler vorher abgerufen wurden
// Das ist etwas unschoen. Sinnvollerweise sollten die SEPA-Infos und TAN-Medien nicht in den
// UPD gespeichert werden. Dann gehen die auch nicht jedesmal wieder verloren und muessen nicht
// dauernd neu abgerufen werden. Das wuerde aber einen groesseren Umbau erfordern
Properties upd = passport.getUPD();
if (upd != null)
{
String mediaInfo = upd.getProperty("tanmedia.names");
if (mediaInfo != null)
{
HBCIUtils.log("rescued TAN media info to new UPD: " + mediaInfo,HBCIUtils.LOG_INFO);
p.setProperty("tanmedia.names",mediaInfo);
}
}

String oldVersion = passport.getUPDVersion();
passport.setUPD(p);
HBCIUtils.log("installed new UPD with version "+passport.getUPDVersion(),HBCIUtils.LOG_INFO);

HBCIUtils.log("installed new UPD [old version: " + oldVersion + ", new version: " + passport.getUPDVersion() + "]",HBCIUtils.LOG_INFO);
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_INIT_UPD_DONE,passport.getUPD());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/org/kapott/hbci/passport/AbstractPinTanPassport.java
Expand Up @@ -1237,6 +1237,7 @@ private void applyTanMedia(GVTAN2Step hktan)
HBCIUtils.log("we have to add the tan media",HBCIUtils.LOG_DEBUG);

StringBuffer retData=new StringBuffer();
retData.append(this.getUPD().getProperty("tanmedia.names",""));
HBCIUtilsInternal.getCallback().callback(this,HBCICallback.NEED_PT_TANMEDIA,
"*** Enter the name of your TAN media",
HBCICallback.TYPE_TEXT,
Expand Down
9 changes: 6 additions & 3 deletions src/org/kapott/hbci/passport/HBCIPassportPinTan.java
Expand Up @@ -252,9 +252,12 @@ public void saveChanges()
HBCIUtils.log("closing output stream", HBCIUtils.LOG_DEBUG);
o.close();

HBCIUtils.log("deleting old passport file " + passportfile, HBCIUtils.LOG_DEBUG);
if (!passportfile.delete())
HBCIUtils.log("delete method for " + passportfile + " returned false", HBCIUtils.LOG_ERR);
if (passportfile.exists()) // Nur loeschen, wenn es ueberhaupt existiert
{
HBCIUtils.log("deleting old passport file " + passportfile, HBCIUtils.LOG_DEBUG);
if (!passportfile.delete())
HBCIUtils.log("delete method for " + passportfile + " returned false", HBCIUtils.LOG_ERR);
}

// Wenn die Datei noch existiert, warten wir noch etwas
int retry = 0;
Expand Down

0 comments on commit 6d6831c

Please sign in to comment.