passport.saveChanges();
} else {
HBCIUtils.log("keys have not been thrown away",HBCIUtils.LOG_WARN);
}
throw new ProcessException(HBCIUtilsInternal.getLocMsg("EXCMSG_SENDKEYERR"),ret);
}
try {
doDialogEnd(result.getProperty("MsgHead.dialogid"),"2",HBCIKernelImpl.DONT_SIGNIT,HBCIKernelImpl.CRYPTIT,
HBCIKernelImpl.DONT_NEED_CRYPT);
} catch (Exception e) {
HBCIUtils.log(e);
}
triggerNewKeysEvent();
} else {
// aendern der aktuellen Nutzerschluessel
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_DIALOG_INIT,null);
// als erstes Dialog-Initialisierung
HBCIMsgStatus ret=null;
boolean restarted=false;
while (true) {
kernel.rawNewMsg("DialogInit");
kernel.rawSet("Idn.KIK.blz", blz);
kernel.rawSet("Idn.KIK.country", country);
kernel.rawSet("Idn.customerid", passport.getCustomerId());
kernel.rawSet("Idn.sysid", passport.getSysId());
String sysstatus=passport.getSysStatus();
kernel.rawSet("Idn.sysStatus",sysstatus);
kernel.rawSet("ProcPrep.BPD",passport.getBPDVersion());
kernel.rawSet("ProcPrep.UPD",passport.getUPDVersion());
kernel.rawSet("ProcPrep.lang",passport.getLang());
kernel.rawSet("ProcPrep.prodName",HBCIUtils.getParam("client.product.name","HBCI4Java"));
kernel.rawSet("ProcPrep.prodVersion",HBCIUtils.getParam("client.product.version","2.5"));
ret=kernel.rawDoIt(HBCIKernelImpl.SIGNIT,HBCIKernelImpl.CRYPTIT,
HBCIKernelImpl.NEED_SIG,HBCIKernelImpl.NEED_CRYPT);
boolean need_restart=passport.postInitResponseHook(ret, passport.isAnonymous());
if (need_restart) {
HBCIUtils.log("for some reason we have to restart this dialog", HBCIUtils.LOG_INFO);
if (restarted) {
HBCIUtils.log("this dialog already has been restarted once - to avoid endless loops we stop here", HBCIUtils.LOG_WARN);
throw new HBCI_Exception("*** restart loop - aborting");
}
restarted=true;
} else {
break;
}
}
Properties result=ret.getData();
if (!ret.isOK())
throw new ProcessException(HBCIUtilsInternal.getLocMsg("EXCMSG_GETUPDFAIL"),ret);
// evtl. Passport-Daten aktualisieren
HBCIInstitute inst=new HBCIInstitute(kernel,passport,false);
inst.updateBPD(result);
updateUPD(result);
passport.saveChanges();
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_DIALOG_INIT_DONE,new Object[] {ret,result.getProperty("MsgHead.dialogid")});
// neue Schl�ssel senden
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_SEND_KEYS,null);
kernel.rawNewMsg("ChangeKeys");
kernel.rawSet("MsgHead.dialogid",result.getProperty("MsgHead.dialogid"));
kernel.rawSet("MsgHead.msgnum","2");
kernel.rawSet("MsgTail.msgnum","2");
kernel.rawSet("KeyChange.KeyName.KIK.blz", blz);
kernel.rawSet("KeyChange.KeyName.KIK.country", country);
kernel.rawSet("KeyChange.KeyName.userid", passport.getUserId());
kernel.rawSet("KeyChange.KeyName.keynum", sigKey[0].num);
kernel.rawSet("KeyChange.KeyName.keytype", "S"); // TODO: keytype "D"
kernel.rawSet("KeyChange.KeyName.keyversion", sigKey[0].version);
kernel.rawSet("KeyChange.SecProfile.method", passport.getProfileMethod());
kernel.rawSet("KeyChange.SecProfile.version", passport.getProfileVersion());
kernel.rawSet("KeyChange.PubKey.mode", "16"); // TODO: later real mode
kernel.rawSet("KeyChange.PubKey.exponent", "B" + exponent[0]);
kernel.rawSet("KeyChange.PubKey.modulus", "B" + modulus[0]);
kernel.rawSet("KeyChange.PubKey.usage", "6");
kernel.rawSet("KeyChange_2.KeyName.KIK.blz", blz);
kernel.rawSet("KeyChange_2.KeyName.KIK.country", country);
kernel.rawSet("KeyChange_2.KeyName.userid", passport.getUserId());
kernel.rawSet("KeyChange_2.KeyName.keynum", encKey[0].num);
kernel.rawSet("KeyChange_2.KeyName.keytype", "V");
kernel.rawSet("KeyChange_2.KeyName.keyversion", encKey[0].version);
kernel.rawSet("KeyChange_2.SecProfile.method", passport.getProfileMethod());
kernel.rawSet("KeyChange_2.SecProfile.version", passport.getProfileVersion());
kernel.rawSet("KeyChange_2.PubKey.mode", "16"); // TODO: later real mode
kernel.rawSet("KeyChange_2.PubKey.exponent", "B" + exponent[1]);
kernel.rawSet("KeyChange_2.PubKey.modulus", "B" + modulus[1]);
kernel.rawSet("KeyChange_2.PubKey.usage", "5");
// TODO: KeyChange_3
HBCIKey[] oldEncKeys=new HBCIKey[2];
oldEncKeys[0]=passport.getMyPublicEncKey();
oldEncKeys[1]=passport.getMyPrivateEncKey();
passport.setMyPublicEncKey(encKey[0]);
passport.setMyPrivateEncKey(encKey[1]);
passport.saveChanges();
ret=kernel.rawDoIt(HBCIKernelImpl.SIGNIT,HBCIKernelImpl.CRYPTIT,
HBCIKernelImpl.NEED_SIG,HBCIKernelImpl.NEED_CRYPT);
if (!ret.isOK()) {
// TODO: hier muessen am besten beide schluessel im passport
// gesichert werden, damit spaeter ueberprueft werden
// kann, welcher der beiden denn nun beim server
// gespeichert ist. das ist dann kritisch, wenn eine
// eingereichte schl�ssel�nderung vom server nicht
// ausgef�hrt wird: dann tritt hier eine exception auf,
// aber es sind noch die alten schl�ssel aktiv
if (!ret.hasExceptions()) {
HBCIUtils.log("deleting locally generated user keys",HBCIUtils.LOG_WARN);
passport.setMyPublicEncKey(oldEncKeys[0]);
passport.setMyPrivateEncKey(oldEncKeys[1]);
passport.saveChanges();
} else {
HBCIUtils.log("keys have not been thrown away",HBCIUtils.LOG_WARN);
}
throw new ProcessException(HBCIUtilsInternal.getLocMsg("EXCMSG_SENDKEYERR"),ret);
}
passport.setSigId(new Long(1));
passport.setMyPublicSigKey(sigKey[0]);
passport.setMyPrivateSigKey(sigKey[1]);