File newKey = new File(newFile);
if (!newKey.getParentFile().canWrite())
throw new ApplicationException(i18n.tr("Keine Schreibberechtigung"));
// BUGZILLA 289
Settings settings = res.getSettings();
HBCICallback callback = plugin.getHBCICallback();
try
{
////////////////////////////////////////////////////////////////////////
// Erst laden wir den SizRDH-Schluessel
Logger.info("loading sizrdh key");
if (callback != null && (callback instanceof HBCICallbackSWT))
((HBCICallbackSWT)callback).setCurrentHandle(new PassportHandleImpl());
// Abfrage des Passwortes erzwingen
settings.setAttribute("hbcicallback.askpassphrase.force",true);
HBCIUtils.setParam("client.passport.SIZRDHFile.filename",file.getAbsolutePath());
HBCIUtils.setParam("client.passport.SIZRDHFile.libname",getRDHLib());
HBCIUtils.setParam("client.passport.SIZRDHFile.init","0");
HBCIPassportInternal source = (HBCIPassportInternal) AbstractHBCIPassport.getInstance("SIZRDHFile");
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Jetzt erzeugen wir einen im HBCI4Java-Format und kopieren die Daten
Logger.info("converting into hbci4java format");
HBCIUtils.setParam("client.passport.default","RDHNew");
HBCIUtils.setParam("client.passport.RDHNew.filename",newKey.getAbsolutePath());
HBCIUtils.setParam("client.passport.RDHNew.init","0");
HBCIPassportInternal target = (HBCIPassportInternal) AbstractHBCIPassport.getInstance("RDHNew");
target.setCountry(source.getCountry());
target.setBLZ(source.getBLZ());
target.setHost(source.getHost());
target.setPort(source.getPort());
target.setUserId(source.getUserId());
target.setCustomerId(source.getCustomerId());
target.setSysId(source.getSysId());
target.setSigId(source.getSigId());
target.setHBCIVersion(source.getHBCIVersion());
target.setBPD(source.getBPD());
target.setUPD(source.getUPD());
((HBCIPassportRDHNew)target).setInstSigKey(source.getInstSigKey());
((HBCIPassportRDHNew)target).setInstEncKey(source.getInstEncKey());
((HBCIPassportRDHNew)target).setMyPublicSigKey(source.getMyPublicSigKey());
((HBCIPassportRDHNew)target).setMyPrivateSigKey(source.getMyPrivateSigKey());
((HBCIPassportRDHNew)target).setMyPublicEncKey(source.getMyPublicEncKey());
((HBCIPassportRDHNew)target).setMyPrivateEncKey(source.getMyPrivateEncKey());
target.saveChanges();
target.close();
source.close();
////////////////////////////////////////////////////////////////////////
RDHKeyImpl key = new RDHKeyImpl(newKey);
key.setFormat(new HBCI4JavaFormat()); // wir tragen nicht uns selbst ein - da wir den ja ins HBCI4Java-Format konvertiert haben
return key;
}
catch (ApplicationException ae)
{
throw ae;
}
catch (OperationCanceledException oce)
{
throw oce;
}
catch (Exception e)
{
OperationCanceledException oce = (OperationCanceledException) HBCIProperties.getCause(e,OperationCanceledException.class);
if (oce != null)
throw oce;
ApplicationException ae = (ApplicationException) HBCIProperties.getCause(e,ApplicationException.class);
if (ae != null)
throw ae;
Logger.error("unable to import key " + file.getAbsolutePath(),e);
throw new ApplicationException(i18n.tr("Schl�sseldatei kann nicht importiert werden: {0}",e.getMessage()));
}
finally
{
settings.setAttribute("hbcicallback.askpassphrase.force",false);
if (callback != null && (callback instanceof HBCICallbackSWT))
((HBCICallbackSWT)callback).setCurrentHandle(null);
}
}