Package org.kapott.hbci.passport

Examples of org.kapott.hbci.passport.HBCIPassportInternal


    private HBCIMsgStatus doDialogInit()
    {
        HBCIMsgStatus ret=new HBCIMsgStatus();
       
        try {
            HBCIPassportInternal mainPassport=(HBCIPassportInternal)getParentHandler().getPassport();
            HBCIKernelImpl       kernel=(HBCIKernelImpl)getParentHandler().getKernel();
           
            // autosecmech
            HBCIUtils.log("checking whether passport is supported (but ignoring result)",HBCIUtils.LOG_DEBUG);
            boolean s=mainPassport.isSupported();
            HBCIUtils.log("passport supported: "+s,HBCIUtils.LOG_DEBUG);
           
            HBCIUtils.log("processing dialog init",HBCIUtils.LOG_INFO);
            HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_DIALOG_INIT,null);
            String country=mainPassport.getCountry();
            String blz=mainPassport.getBLZ();
   
            boolean restarted=false;
            while (true) {
                kernel.rawNewMsg("DialogInit"+anonSuffix);
                kernel.rawSet("Idn.KIK.blz", blz);
                kernel.rawSet("Idn.KIK.country", country);
                if (!isAnon) {
                    kernel.rawSet("Idn.customerid", mainPassport.getCustomerId());
                    kernel.rawSet("Idn.sysid", mainPassport.getSysId());
                    String sysstatus=mainPassport.getSysStatus();
                    kernel.rawSet("Idn.sysStatus",sysstatus);
                    if (mainPassport.needInstKeys()) {
                        kernel.rawSet("KeyReq.SecProfile.method",mainPassport.getProfileMethod());
                        kernel.rawSet("KeyReq.SecProfile.version",mainPassport.getProfileVersion());
                        kernel.rawSet("KeyReq.KeyName.keytype", "V");
                        kernel.rawSet("KeyReq.KeyName.KIK.country", country);
                        kernel.rawSet("KeyReq.KeyName.KIK.blz", blz);
                        kernel.rawSet("KeyReq.KeyName.userid", mainPassport.getInstEncKeyName());
                        kernel.rawSet("KeyReq.KeyName.keynum", mainPassport.getInstEncKeyNum());
                        kernel.rawSet("KeyReq.KeyName.keyversion", mainPassport.getInstEncKeyVersion());

                        if (mainPassport.hasInstSigKey()) {
                            kernel.rawSet("KeyReq_2.SecProfile.method",mainPassport.getProfileMethod());
                            kernel.rawSet("KeyReq_2.SecProfile.version",mainPassport.getProfileVersion());
                            kernel.rawSet("KeyReq_2.KeyName.keytype", "S");
                            kernel.rawSet("KeyReq_2.KeyName.KIK.country", country);
                            kernel.rawSet("KeyReq_2.KeyName.KIK.blz", blz);
                            kernel.rawSet("KeyReq_2.KeyName.userid", mainPassport.getInstSigKeyName());
                            kernel.rawSet("KeyReq_2.KeyName.keynum", mainPassport.getInstSigKeyNum());
                            kernel.rawSet("KeyReq_2.KeyName.keyversion", mainPassport.getInstSigKeyVersion());
                        }
                    }
                }
                kernel.rawSet("ProcPrep.BPD", mainPassport.getBPDVersion());
                kernel.rawSet("ProcPrep.UPD", mainPassport.getUPDVersion());
                kernel.rawSet("ProcPrep.lang",mainPassport.getDefaultLang());
                kernel.rawSet("ProcPrep.prodName",HBCIUtils.getParam("client.product.name","HBCI4Java"));
                kernel.rawSet("ProcPrep.prodVersion",HBCIUtils.getParam("client.product.version","2.5"));
                ret=kernel.rawDoIt(!isAnon && HBCIKernelImpl.SIGNIT,
                        !isAnon && HBCIKernelImpl.CRYPTIT,
                        !isAnon && HBCIKernelImpl.NEED_SIG,
                        !isAnon && HBCIKernelImpl.NEED_CRYPT);

                boolean need_restart=mainPassport.postInitResponseHook(ret,isAnon);
                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()) {
                HBCIInstitute inst=new HBCIInstitute(kernel,mainPassport,false);
                inst.updateBPD(result);
                inst.extractKeys(result);
   
                HBCIUser user=new HBCIUser(kernel,mainPassport,false);
                user.updateUPD(result);
              
                mainPassport.saveChanges();
   
                msgnum=2;
                dialogid=result.getProperty("MsgHead.dialogid");
                HBCIUtils.log("dialog-id set to "+dialogid,HBCIUtils.LOG_DEBUG);

View Full Code Here


       
        ArrayList<HBCIMsgStatus>        msgstatus_a=new ArrayList<HBCIMsgStatus>();
        HBCIPassportList msgPassports=new HBCIPassportList();
       
        HBCIKernelImpl       kernel=(HBCIKernelImpl)getParentHandler().getKernel();
        HBCIPassportInternal mainPassport=(HBCIPassportInternal)getParentHandler().getPassport();

        // durch die liste aller auszuf�hrenden nachrichten durchloopen
        int nof_messages=msgs.size();
        for (int j=0;j<nof_messages;j++) {
            // tasks ist liste aller jobs, die in dieser nachricht ausgef�hrt werden sollen
View Full Code Here

    private HBCIMsgStatus doDialogEnd()
    {
        HBCIMsgStatus ret=new HBCIMsgStatus();
       
        HBCIHandler          handler=getParentHandler();
        HBCIPassportInternal mainPassport=(HBCIPassportInternal)handler.getPassport();
        HBCIKernelImpl       kernel=(HBCIKernelImpl)handler.getKernel();
       
        try {
            HBCIUtils.log("processing dialog end",HBCIUtils.LOG_INFO);
            HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_DIALOG_END,null);
View Full Code Here

    {
        try {
            HBCIUtils.log("executing dialog",HBCIUtils.LOG_DEBUG);
            HBCIDialogStatus ret=new HBCIDialogStatus();
           
            HBCIPassportInternal passport=(HBCIPassportInternal)getParentHandler().getPassport();
           
            // first call passports's before-dialog-hook
            passport.beforeCustomDialogHook(this);
           
            HBCIMsgStatus initStatus=doDialogInit();
            ret.setInitStatus(initStatus);
               
            // so that e.g. pintan-passports can patch the list of messages to
            // be executed (needed for twostep-mech)
            passport.afterCustomDialogInitHook(this);
           
            if (initStatus.isOK()) {
                ret.setMsgStatus(doJobs());
                ret.setEndStatus(doDialogEnd());
            }
View Full Code Here

            total_counter++;
            if (counter_st==null) {
                gva_counter++;
            }

            HBCIPassportInternal passport=(HBCIPassportInternal)getParentHandler().getPassport();
           
            // BPD: max. Anzahl GV-Arten
            int maxGVA=passport.getMaxGVperMsg();
            // BPD: max. Anzahl von Job-Segmenten eines bestimmten Typs
            int maxGVSegJob=job.getMaxNumberPerMsg();       
            // Passport: evtl. weitere Einschr�nkungen bzgl. der Max.-Anzahl
            // von Auftragssegmenten pro Nachricht
            int maxGVSegTotal=passport.getMaxGVSegsPerMsg()
           
            if ((maxGVA>0 && gva_counter>maxGVA) ||
                    (maxGVSegJob>0 && gv_counter>maxGVSegJob) ||
                    (maxGVSegTotal>0 && total_counter>maxGVSegTotal))
            {
View Full Code Here

    }
   
    public HBCIMsgStatus rawDoIt(boolean signit,boolean cryptit,boolean needSig,boolean needCrypt)
    {
        HBCIPassportList     passports=new HBCIPassportList();
        HBCIPassportInternal passport=(HBCIPassportInternal)getParentHandlerData().getPassport();
        passports.addPassport(passport,HBCIPassport.ROLE_ISS);
        return rawDoIt(passports,signit,cryptit,needSig,needCrypt);
    }
View Full Code Here

    {
        HBCIMsgStatus ret=new HBCIMsgStatus();
        MSG           msg=null;
       
        try {
            HBCIPassportInternal mainPassport=passports.getMainPassport();

            HBCIUtils.log("generating raw message "+currentMsgName,HBCIUtils.LOG_DEBUG);
            HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_CREATE,currentMsgName);

            // plaintextnachricht erzeugen
            msg=gen.generate(currentMsgName);

            // alle daten f�r den rewriter setzen
            Rewrite.setData("passports",passports);
            Rewrite.setData("msgStatus",ret);
            Rewrite.setData("msgName",currentMsgName);
            Rewrite.setData("signIt",Boolean.valueOf(signit));
            Rewrite.setData("cryptIt",Boolean.valueOf(cryptit));
            Rewrite.setData("needSig",Boolean.valueOf(needSig));
            Rewrite.setData("needCrypt",Boolean.valueOf(needCrypt));

            // liste der rewriter erzeugen
            String rewriters_st=HBCIUtils.getParam("kernel.rewriter");
            ArrayList<Rewrite> al=new ArrayList<Rewrite>();
            StringTokenizer tok=new StringTokenizer(rewriters_st,",");
            while (tok.hasMoreTokens()) {
                String rewriterName=tok.nextToken().trim();
                if (rewriterName.length()!=0) {
                    Class cl=this.getClass().getClassLoader().loadClass("org.kapott.hbci.rewrite.R"+
                                                                        rewriterName);
                    Constructor con=cl.getConstructor((Class[])null);
                    Rewrite rewriter=(Rewrite)(con.newInstance((Object[])null));
                    al.add(rewriter);
                }
            }
            Rewrite[] rewriters=al.toArray(new Rewrite[al.size()]);
           
            // alle rewriter durchlaufen und plaintextnachricht patchen
            for (int i=0;i<rewriters.length;i++) {
                MSG old=msg;
                msg=rewriters[i].outgoingClearText(old,gen);
                if (msg!=old) {
                    MSGFactory.getInstance().unuseObject(old);
                }
            }
           
            // HBCIUtils.log("sending msg: "+msg.toString(0));
           
            // wenn nachricht signiert werden soll
            if (signit) {
                HBCIUtils.log("trying to insert signature",HBCIUtils.LOG_DEBUG);
                HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_SIGN,null);
               
                // signatur erzeugen und an nachricht anh�ngen
                Sig sig=SigFactory.getInstance().createSig(getParentHandlerData(),msg,passports);
                try {
                    if (!sig.signIt()) {
                        String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CANTSIGN");
                        if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreSignErrors",errmsg)) {
                            throw new HBCI_Exception(errmsg);
                        }
                    }
                } finally {
                    SigFactory.getInstance().unuseObject(sig);
                }

                // alle rewrites erledigen, die *nach* dem hinzuf�gen der signatur stattfinden m�ssen
                for (int i=0;i<rewriters.length;i++) {
                    MSG old=msg;
                    msg=rewriters[i].outgoingSigned(old,gen);
                    if (msg!=old) {
                        MSGFactory.getInstance().unuseObject(old);
                    }
                }
            }
           
            /* zu jeder SyntaxElement-Referenz (2:3,1)==(SEG:DEG,DE) den Pfad
               des jeweiligen Elementes speichern */
            Properties paths=new Properties();
            msg.getElementPaths(paths,null,null,null);
            ret.addData(paths);
           
            /* f�r alle Elemente (Pfadnamen) die aktuellen Werte speichern,
               wie sie bei der ausgehenden Nachricht versandt werden */
            Hashtable<String,String> current=new Hashtable<String,String>();
            msg.extractValues(current);
            Properties origs=new Properties();
            for (Enumeration<String> e=current.keys();e.hasMoreElements();) {
                String key= e.nextElement();
                String value= current.get(key);
                origs.setProperty("orig_"+key,value);
            }
            ret.addData(origs);
           
            // zu versendene nachricht loggen
            String outstring=msg.toString(0);
            HBCIUtils.log("sending message: "+outstring,HBCIUtils.LOG_DEBUG2);

            // max. nachrichtengr��e aus BPD �berpr�fen
            int maxmsgsize=mainPassport.getMaxMsgSizeKB();
            if (maxmsgsize!=0 && (outstring.length()>>10)>maxmsgsize) {
                String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_MSGTOOLARGE",
                                                  new Object[] {Integer.toString(outstring.length()>>10),Integer.toString(maxmsgsize)});
                if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreMsgSizeErrors",errmsg))
                    throw new HBCI_Exception(errmsg);
            }
           
            // soll nachricht verschl�sselt werden?
            if (cryptit) {
                HBCIUtils.log("trying to encrypt message",HBCIUtils.LOG_DEBUG);
                HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_CRYPT,null);
               
                // nachricht verschl�sseln
                MSG   old=msg;
                Crypt crypt=CryptFactory.getInstance().createCrypt(getParentHandlerData(),old);
                try {
                    msg=crypt.cryptIt("Crypted");
                } finally {
                    CryptFactory.getInstance().unuseObject(crypt);
                    if (msg!=old) {
                        MSGFactory.getInstance().unuseObject(old);
                    }
                }
               
                if (!msg.getName().equals("Crypted")) {
                    String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CANTCRYPT");
                    if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreCryptErrors",errmsg))
                        throw new HBCI_Exception(errmsg);
                }

                // verschl�sselte nachricht patchen
                for (int i=0;i<rewriters.length;i++) {
                    MSG oldMsg=msg;
                    msg=rewriters[i].outgoingCrypted(oldMsg,gen);
                    if (msg!=oldMsg) {
                        MSGFactory.getInstance().unuseObject(oldMsg);
                    }
                }
               
                HBCIUtils.log("encrypted message to be sent: "+msg.toString(0),HBCIUtils.LOG_DEBUG2);
            }

            // basic-values der ausgehenden nachricht merken
            String msgPath=msg.getPath();
            String msgnum=msg.getValueOfDE(msgPath+".MsgHead.msgnum");
            String dialogid=msg.getValueOfDE(msgPath+".MsgHead.dialogid");
            String hbciversion=msg.getValueOfDE(msgPath+".MsgHead.hbciversion");
           
            // nachricht versenden und antwortnachricht empfangen
            HBCIUtils.log("communicating dialogid/msgnum "+dialogid+"/"+msgnum,HBCIUtils.LOG_DEBUG);
            MSG old=msg;
            msg=mainPassport.getComm().pingpong(currentMsgName,old);
            if (msg!=old) {
                MSGFactory.getInstance().unuseObject(old);
            }

            // ist antwortnachricht verschl�sselt?
View Full Code Here

    }

    public MSG cryptIt(String newName)
    {
        MSG                  newmsg=msg;
        HBCIPassportInternal passport=(HBCIPassportInternal)handlerdata.getPassport();

        if (passport.hasInstEncKey()) {
            String msgName = msg.getName();
            MsgGen gen=handlerdata.getMsgGen();
            Node msgNode = msg.getSyntaxDef(msgName, gen.getSyntax());
            String dontcryptAttr = ((Element)msgNode).getAttribute("dontcrypt");

            if (dontcryptAttr.length() == 0) {
                try {
                    setParam("secfunc",passport.getCryptFunction());
                    setParam("keytype",passport.getCryptKeyType());
                    setParam("blz",passport.getBLZ());
                    setParam("country",passport.getCountry());
                    setParam("keyuserid",passport.getInstEncKeyName());
                    setParam("keynum",passport.getInstEncKeyNum());
                    setParam("keyversion",passport.getInstEncKeyVersion());
                    setParam("cid",passport.getCID());
                    setParam("sysId",passport.getSysId());
                    setParam("role","1");
                    setParam("alg",passport.getCryptAlg());
                    setParam("mode",passport.getCryptMode());
                    setParam("compfunc","0"); // TODO: spaeter kompression implementieren

                    byte[][] crypteds=passport.encrypt(getPlainString());

                    String msgPath=msg.getPath();
                    String dialogid=msg.getValueOfDE(msgPath+".MsgHead.dialogid");
                    String msgnum=msg.getValueOfDE(msgPath+".MsgHead.msgnum");
                    String segnum=msg.getValueOfDE(msgPath+".MsgTail.SegHead.seq");
                   
                    Date d=new Date();

                    gen.set(newName+".CryptData.data","B"+new String(crypteds[1],Comm.ENCODING));
                    gen.set(newName+".CryptHead.CryptAlg.alg",u_alg);
                    gen.set(newName+".CryptHead.CryptAlg.mode",u_mode);
                    gen.set(newName+".CryptHead.CryptAlg.enckey","B"+new String(crypteds[0],Comm.ENCODING));
                    gen.set(newName+".CryptHead.CryptAlg.keytype",u_keytype);
                    gen.set(newName+".CryptHead.SecIdnDetails.func",(newmsg.getName().endsWith("Res")?"2":"1"));
                    gen.set(newName+".CryptHead.KeyName.KIK.blz",u_blz);
                    gen.set(newName+".CryptHead.KeyName.KIK.country",u_country);
                    gen.set(newName+".CryptHead.KeyName.userid",u_keyuserid);
                    gen.set(newName+".CryptHead.KeyName.keynum",u_keynum);
                    gen.set(newName+".CryptHead.KeyName.keyversion",u_keyversion);
                    gen.set(newName+".CryptHead.SecProfile.method",passport.getProfileMethod());
                    gen.set(newName+".CryptHead.SecProfile.version",passport.getProfileVersion());
                    if (passport.getSysStatus().equals("0")) {
                        gen.set(newName+".CryptHead.SecIdnDetails.cid","B"+u_cid);
                    } else {
                        gen.set(newName+".CryptHead.SecIdnDetails.sysid",u_sysId);
                    }
                    gen.set(newName+".CryptHead.SecTimestamp.date",HBCIUtils.date2StringISO(d));
View Full Code Here

    }

    public String decryptIt()
    {
        StringBuffer ret=new StringBuffer(msg.toString(0));
        HBCIPassportInternal passport=(HBCIPassportInternal)handlerdata.getPassport();

        if (passport.hasMyEncKey()) {
            if (isCrypted()) {
                try {
                    String msgName=msg.getName();

                    List<MultipleSyntaxElements> childs=msg.getChildContainers();
                    SEG msghead=(SEG)(((MultipleSEGs)(childs.get(0))).getElements().get(0));
                    SEG msgtail=(SEG)(((MultipleSEGs)(childs.get(childs.size()-1))).getElements().get(0));

                    // verschluesselte daten extrahieren
                    SEG cryptdata=(SEG)(((MultipleSEGs)(childs.get(2))).getElements().get(0));
                    byte[] cryptedstring=cryptdata.getValueOfDE(msgName+".CryptData.data").getBytes(Comm.ENCODING);

                    // key extrahieren
                    SEG crypthead=(SEG)(((MultipleSEGs)(childs.get(1))).getElements().get(0));
                    byte[] cryptedkey=crypthead.getValueOfDE(msgName+
                                      ".CryptHead.CryptAlg.enckey").getBytes(Comm.ENCODING);

                    // neues secfunc (klartext/encrypted)
                    String secfunc=crypthead.getValueOfDE(msgName+".CryptHead.secfunc");
                    if (!secfunc.equals(passport.getCryptFunction())) {
                        String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CRYPTSFFAIL",new Object[] {secfunc,
                                                          passport.getCryptFunction()});
                        if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreCryptErrors",errmsg))
                            throw new HBCI_Exception(errmsg);
                    }

                    // TODO: diese checks werden vorerst abgeschaltet, damit pin-tan reibungslos geht
                    /*
                                     // constraint checking
                                     String keytype=crypthead.getValueOfDE(msgName+".CryptHead.CryptAlg.keytype");
                         if (!keytype.equals(passport.getSecMethod56()) && !(passport instanceof HBCIPassportPinTan))
                        throw new HBCI_Exception(HBCIUtils.getLocMsg("EXCMSG_CRYPTMETHODFAIL",new Object[] {keytype,passport.getSecMethod56()}));
                                     String mode=crypthead.getValueOfDE(msgName+".CryptHead.CryptAlg.mode");
                                     if (!mode.equals(passport.getCryptMode()))
                         throw new HBCI_Exception(HBCIUtils.getLocMsg("EXCMSG_CRYPTMODEFAIL",new Object[] {keytype,passport.getCryptMode()}));
                     */

                    /* TODO: removed code because no real checks are done here
                    if (passport.getSysStatus().equals("1")) {
                        String sysid=null;
                        try {
                            // falls noch keine system-id ausgehandelt wurde, so sendet der
                            // hbci-server auch keine... deshalb der try-catch-block
                            sysid=crypthead.getValueOfDE(msgName+".CryptHead.SecIdnDetails.sysid");
                        } catch (Exception e) {
                            sysid="0";
                        }
                       
                        // TODO: sysid checken (kann eigentlich auch entfallen, weil
                        // das jeweils auf h�herer ebene geschehen sollte!)
                    } else {
                        String cid=crypthead.getValueOfDE(msgName+".CryptHead.SecIdnDetails.cid");
                        if (!cid.equals(passport.getCID())) {
                            String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CRYPTCIDFAIL");
                            if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreCryptErrors",errmsg))
                                throw new HBCI_Exception(errmsg);
                        }
                       
                        // TODO: cid checken
                    }
                    */

                    // TODO spaeter kompression implementieren
                    String compfunc=crypthead.getValueOfDE(msgName+".CryptHead.compfunc");
                    if (!compfunc.equals("0")) {
                        String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CRYPTCOMPFUNCFAIL",compfunc);
                        if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreCryptErrors",errmsg))
                            throw new HBCI_Exception(errmsg);
                    }
                   
                    // TODO: hier auch die DEG SecProfile lesen und �berpr�fen

                    byte[] plainMsg=passport.decrypt(cryptedkey,cryptedstring);
                    int padLength=plainMsg[plainMsg.length-1];

                    // FileOutputStream fo=new FileOutputStream("decrypt.dat");
                    // fo.write(plainMsg);
                    // fo.close();
View Full Code Here

       
        Properties   data=new Properties();
        data.setProperty("blz",blz);
        data.setProperty("host",HBCIUtils.getHBCIHostForBLZ(blz));
       
        HBCIPassportInternal passport=(HBCIPassportInternal)AbstractHBCIPassport.getInstance("RDHNew",data);
        HBCIKernelImpl       kernel=(HBCIKernelImpl)HBCIKernelFactory.getKernel(null,"210");
        HBCIInstitute inst=new HBCIInstitute(kernel,passport,true);
       
        try {
            inst.fetchBPD();
        } catch (Exception e) {
            System.out.println("  "+blz+": fetching BPD failed");
        }
       
        if (passport.isSupported()) {
            try {
                inst.fetchKeys();
                System.out.println("  "+blz+": found hashvalue "+data.getProperty("hash"));
            } catch (Exception e) {
                System.out.println("  "+blz+": fetching keys failed");
View Full Code Here

TOP

Related Classes of org.kapott.hbci.passport.HBCIPassportInternal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.