org.kapott.hbci.manager.HBCIUser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbci4j-core Show documentation
Show all versions of hbci4j-core Show documentation
HBCI4j - Home Banking Computer Interface for Java
/* $Id: HBCIUser.java,v 1.2 2011/08/31 14:05:21 willuhn Exp $
This file is part of HBCI4Java
Copyright (C) 2001-2008 Stefan Palme
HBCI4Java is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
HBCI4Java is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.kapott.hbci.manager;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.spec.RSAPublicKeySpec;
import java.util.Enumeration;
import java.util.Properties;
import org.kapott.hbci.callback.HBCICallback;
import org.kapott.hbci.comm.Comm;
import org.kapott.hbci.exceptions.HBCI_Exception;
import org.kapott.hbci.exceptions.NeedKeyAckException;
import org.kapott.hbci.exceptions.ProcessException;
import org.kapott.hbci.passport.HBCIPassport;
import org.kapott.hbci.passport.HBCIPassportInternal;
import org.kapott.hbci.status.HBCIMsgStatus;
/* @brief Instances of this class represent a certain user in combination with
a certain institute. */
public final class HBCIUser
implements IHandlerData
{
private HBCIPassportInternal passport;
private HBCIKernelImpl kernel;
private boolean isAnon;
private String anonSuffix;
/** @brief This constructor initializes a new user instance with the given values */
public HBCIUser(HBCIKernelImpl kernel,HBCIPassportInternal passport,boolean forceAsParent)
{
this.kernel=kernel;
if (forceAsParent || this.kernel.getParentHandlerData()==null) {
// Dieser Fall tritt im HBCI4Java-PE ein, wenn ein HBCIInstitute()
// erzeugt wird, ohne dass es einen HBCIHandler() gäbe
this.kernel.setParentHandlerData(this);
}
this.passport=passport;
if (forceAsParent || this.passport.getParentHandlerData()==null) {
// Dieser Fall tritt im HBCI4Java-PE ein, wenn ein HBCIInstitute()
// erzeugt wird, ohne dass es einen HBCIHandler() gäbe
this.passport.setParentHandlerData(this);
}
this.isAnon=passport.isAnonymous();
this.anonSuffix=isAnon?"Anon":"";
}
private void doDialogEnd(String dialogid,String msgnum,boolean signIt,boolean cryptIt,boolean needCrypt)
{
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_DIALOG_END,null);
kernel.rawNewMsg("DialogEnd"+anonSuffix);
kernel.rawSet("MsgHead.dialogid",dialogid);
kernel.rawSet("MsgHead.msgnum",msgnum);
kernel.rawSet("DialogEndS.dialogid",dialogid);
kernel.rawSet("MsgTail.msgnum",msgnum);
HBCIMsgStatus status=kernel.rawDoIt(!isAnon && signIt,
!isAnon && cryptIt,
!isAnon && HBCIKernelImpl.NEED_SIG,
!isAnon && needCrypt);
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_DIALOG_END_DONE,status);
if (!status.isOK()) {
HBCIUtils.log("dialog end failed: "+status.getErrorString(),HBCIUtils.LOG_ERR);
String msg=HBCIUtilsInternal.getLocMsg("ERR_INST_ENDFAILED");
if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreDialogEndErrors",msg+": "+status.getErrorString()))
throw new ProcessException(msg,status);
}
}
// TODO: dig keys unterstützen
private void sendAndActivateNewUserKeys(HBCIKey[] sigKey,HBCIKey[] encKey)
{
try {
HBCIUtils.log("sending user keys to institute",HBCIUtils.LOG_INFO);
String country=passport.getCountry();
String blz=passport.getBLZ();
String[] exponent = new String[2];
String[] modulus = new String[2];
for (int i=0;i<2;i++) {
KeyFactory fac = KeyFactory.getInstance("RSA");
RSAPublicKeySpec spec=null;
if (i==0) {
spec=fac.getKeySpec(sigKey[0].key,RSAPublicKeySpec.class);
} else if (i==1) {
spec=fac.getKeySpec(encKey[0].key,RSAPublicKeySpec.class);
} else {
// TODO: dig key senden
}
byte[] ba=spec.getPublicExponent().toByteArray();
int len=ba.length;
int startpos=0;
while (startpos