{
if (!passport.needUserKeys() ||
!passport.hasMySigKey()) {
if (!passport.needUserKeys()) {
throw new HBCI_Exception(HBCIUtilsInternal.getLocMsg("EXCMSG_USR_DONTHAVEUSRKEYS"));
}
throw new HBCI_Exception(HBCIUtilsInternal.getLocMsg("EXCMSG_USR_NOUSRKEYSAVAIL"));
}
try {
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_DIALOG_INIT,null);
HBCIUtils.log("locking user keys",HBCIUtils.LOG_INFO);
String blz=passport.getBLZ();
String country=passport.getCountry();
HBCIMsgStatus status=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());
kernel.rawSet("Idn.sysStatus",passport.getSysStatus());
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"));
status=kernel.rawDoIt(HBCIKernelImpl.SIGNIT,HBCIKernelImpl.CRYPTIT,
HBCIKernelImpl.NEED_SIG,HBCIKernelImpl.NEED_CRYPT);
boolean need_restart=passport.postInitResponseHook(status, 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=status.getData();
if (!status.isOK())
throw new ProcessException(HBCIUtilsInternal.getLocMsg("EXCMSG_LOCKFAILED"),status);
String dialogid=result.getProperty("MsgHead.dialogid");
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_DIALOG_INIT_DONE,new Object[] {status,dialogid});
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_LOCK_KEYS,null);
kernel.rawNewMsg("LockKeys");
kernel.rawSet("MsgHead.dialogid",dialogid);
kernel.rawSet("MsgHead.msgnum","2");
kernel.rawSet("MsgTail.msgnum","2");
kernel.rawSet("KeyLock.KeyName.KIK.country",country);
kernel.rawSet("KeyLock.KeyName.KIK.blz",blz);
kernel.rawSet("KeyLock.KeyName.userid",passport.getMySigKeyName());
kernel.rawSet("KeyLock.KeyName.keynum",passport.getMySigKeyNum());
kernel.rawSet("KeyLock.KeyName.keyversion",passport.getMySigKeyVersion());
kernel.rawSet("KeyLock.SecProfile.method", passport.getProfileMethod());
kernel.rawSet("KeyLock.SecProfile.version", passport.getProfileVersion());
kernel.rawSet("KeyLock.locktype","999");
status=kernel.rawDoIt(HBCIKernelImpl.SIGNIT,HBCIKernelImpl.CRYPTIT,
HBCIKernelImpl.NEED_SIG,HBCIKernelImpl.DONT_NEED_CRYPT);
if (!status.isOK())
throw new ProcessException(HBCIUtilsInternal.getLocMsg("EXCMSG_LOCKFAILED"),status);
passport.clearMyDigKey();
passport.clearMySigKey();
passport.clearMyEncKey();
passport.setSigId(new Long(1));
passport.saveChanges();
HBCIUtilsInternal.getCallback().status(passport,HBCICallback.STATUS_LOCK_KEYS_DONE,status);
doDialogEnd(dialogid,"3",HBCIKernelImpl.DONT_SIGNIT,HBCIKernelImpl.CRYPTIT,HBCIKernelImpl.DONT_NEED_CRYPT);
} catch (Exception e) {
throw new HBCI_Exception(HBCIUtilsInternal.getLocMsg("EXCMSG_LOCKFAILED"),e);
} finally {
passport.closeComm();
}
}