Package org.kapott.hbci.protocol

Examples of org.kapott.hbci.protocol.MSG


      super(Integer.parseInt(HBCIUtils.getParam("kernel.objpool.MSG","8")));
    }
   
    public MSG createMSG(String type,MsgGen gen,Hashtable<String,String> clientValues)
    {
        MSG ret=(MSG)getFreeObject();
       
        if (ret==null) {
            // HBCIUtils.log("creating new MSG object",HBCIUtils.LOG_DEBUG);
            ret=new MSG(type,gen,clientValues);
            addToUsedPool(ret);
        } else {
            // HBCIUtils.log("resuing MSG object",HBCIUtils.LOG_DEBUG);
            try {
                ret.init(type,gen,clientValues);
                addToUsedPool(ret);
            } catch (Exception e) {
                addToFreePool(ret);
                throw (RuntimeException)e;
            }
View Full Code Here


        return createMSG(type,res,fullResLen,gen,checkSeq,true);
    }
   
    public MSG createMSG(String type,String res,int fullResLen,MsgGen gen,boolean checkSeq,boolean checkValids)
    {
        MSG ret=(MSG)getFreeObject();
       
        if (ret==null) {
            // HBCIUtils.log("creating new MSG object",HBCIUtils.LOG_DEBUG);
            ret=new MSG(type,res,fullResLen,gen,checkSeq,checkValids);
            addToUsedPool(ret);
        } else {
            // HBCIUtils.log("reusing MSG object",HBCIUtils.LOG_DEBUG);
            try {
                ret.init(type,res,fullResLen,gen,checkSeq,checkValids);
                addToUsedPool(ret);
            } catch (Exception e) {
                addToFreePool(ret);
                throw (RuntimeException)e;
            }
View Full Code Here

        @return A Properties object that contains a path-value-pair for each dataelement of
                the received message. */
    public HBCIMsgStatus rawDoIt(HBCIPassportList passports,boolean signit,boolean cryptit,boolean needSig,boolean needCrypt)
    {
        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?
            boolean crypted=msg.getName().equals("CryptedRes");
            if (crypted) {
                HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_DECRYPT,null);
               
                // wenn ja, dann nachricht entschl�sseln
                Crypt  crypt=CryptFactory.getInstance().createCrypt(getParentHandlerData(),msg);
                String newmsgstring;
                try {
                    newmsgstring=crypt.decryptIt();
                } finally {
                    CryptFactory.getInstance().unuseObject(crypt);
                }
                gen.set("_origSignedMsg",newmsgstring);
               
                // alle patches f�r die unverschl�sselte nachricht durchlaufen
                for (int i=0;i<rewriters.length;i++) {
                    newmsgstring=rewriters[i].incomingClearText(newmsgstring,gen);
                }
               
                HBCIUtils.log("decrypted message after rewriting: "+newmsgstring,HBCIUtils.LOG_DEBUG2);
               
                // nachricht als plaintextnachricht parsen
                try {
                    HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_PARSE,currentMsgName+"Res");
                    HBCIUtils.log("message to pe parsed: "+msg.toString(0),HBCIUtils.LOG_DEBUG2);
                    MSG oldMsg=msg;
                    msg=MSGFactory.getInstance().createMSG(currentMsgName+"Res",newmsgstring,newmsgstring.length(),gen);
                    if (msg!=oldMsg) {
                        MSGFactory.getInstance().unuseObject(oldMsg);
                    }
                } catch (Exception ex) {
                    throw new CanNotParseMessageException(HBCIUtilsInternal.getLocMsg("EXCMSG_CANTPARSE"),newmsgstring,ex);
                }
            }
           
            HBCIUtils.log("received message after decryption: "+msg.toString(0),HBCIUtils.LOG_DEBUG2);

            // alle patches f�r die plaintextnachricht durchlaufen
            for (int i=0;i<rewriters.length;i++) {
                MSG oldMsg=msg;
                msg=rewriters[i].incomingData(oldMsg,gen);
                if (msg!=oldMsg) {
                    MSGFactory.getInstance().unuseObject(oldMsg);
                }
            }
View Full Code Here

        HBCIUtilsInternal.getCallback().status(getParentPassport(),HBCICallback.STATUS_MSG_RECV,null);
        String st = pong(gen).toString();
        HBCIUtilsInternal.getCallback().status(getParentPassport(),HBCICallback.STATUS_MSG_RAW_RECV,st);

        HBCIUtils.log("received message: "+st,HBCIUtils.LOG_DEBUG2);
        MSG retmsg=null;

        try {
            // erzeugen der liste aller rewriter
            String rewriters_st=HBCIUtils.getParam("kernel.rewriter");
            ArrayList<Rewrite> al=new ArrayList<Rewrite>();
View Full Code Here

    // nachricht hier tats�chlich schon geparst werden kann
    public String incomingClearText(String st,MsgGen gen)
    {
        // empfangene Nachricht parsen, dabei die validvalues-�berpr�fung weglassen
        String myMsgName=(String)getData("msgName")+"Res";
        MSG    msg=MSGFactory.getInstance().createMSG(myMsgName,st,st.length(),
                gen,
                MSG.CHECK_SEQ,MSG.DONT_CHECK_VALIDS);
       
        // in einer Schleife durch alle SuppSecMethods-Datens�tze laufen
        for (int i=0;;i++) {
            String        elemBaseName=HBCIUtilsInternal.withCounter(myMsgName+".BPD.SecMethod.SuppSecMethods",i);
            SyntaxElement elem=msg.getElement(elemBaseName+".method");

            if (elem==null) {
                break;
            }
           
            // Methodenbezeichner extrahieren
            String method=elem.toString();
            if (method.equals("TAN")) { // "TAN" ist ung�ltiger Bezeichner
                HBCIUtils.log("there is an invalid sec type (TAN) in this BPD - removing it",HBCIUtils.LOG_WARN);

                // Elternelement finden (Segment "SecMethods")
                SyntaxElement parent=elem.getParent().getParent().getParent().getParent();
                String        parentPath=parent.getPath();
                int           number=0;
               
                // durch alle Elemente dieses Segmentes laufen, bis die Multiple-DEG
                // mit den unterst�tzten SecMethods gefunden wurde
                for (Iterator<MultipleSyntaxElements> it=parent.getChildContainers().iterator();it.hasNext();) {
                    MultipleSyntaxElements childContainer= it.next();
                    if (childContainer.getPath().equals(parentPath+".SuppSecMethods")) {
                        // die Anzahl der eingestellten unterst�tzten SecMethods herausholen
                        number=childContainer.getElements().size();
                        break;
                    }
                }
               
                int startpos;
                int endpos;
               
                /* wenn mehr als eine SecMethod im Segment stand, dann braucht nur
                 * das eine der multiplen DEGs entfernt werden. Wenn aber nur die eine
                 * fehlerhafte Info enthalten war, dann muss das gesamte Segment
                 * entfernt werden, weil ein SecMethods-Segment ohne tats�chliche Daten
                 * �ber unterst�tzte SecMethods ung�ltig ist. */
               
                if (number>1) { // nur das eine fehlerhafte TAN:1 l�schen
                    startpos=elem.getPosInMsg();
                    endpos=startpos
                        +1
                        +elem.toString(0).length()
                        +1
                        +msg.getElement(elemBaseName+".version").toString(0).length();
                } else { // komplettes segment "SecMethod" l�schen
                    startpos=parent.getPosInMsg()+1;
                    endpos=startpos+parent.toString(0).length();
                    /* der Fehler, der hier gemacht wird (nachfolgende Segment-
                     * Sequenznummern sind falsch), wird durch ein nachgeschaltetes
View Full Code Here

    // nachricht hier tats�chlich schon geparst werden kann
    public String incomingClearText(String st,MsgGen gen)
    {
        // empfangene Nachricht parsen, dabei die validvalues-�berpr�fung weglassen
        String myMsgName=(String)getData("msgName")+"Res";
        MSG    msg=MSGFactory.getInstance().createMSG(myMsgName,st,st.length(),
                gen,
                MSG.DONT_CHECK_SEQ,MSG.DONT_CHECK_VALIDS);
       
        // in einer Schleife durch alle SuppVersions-Datens�tze laufen
        for (int i=0;;i++) {
            String        elemName=HBCIUtilsInternal.withCounter(myMsgName+".BPD.BPA.SuppVersions.version",i);
            SyntaxElement elem=msg.getElement(elemName);

            if (elem==null) {
                break;
            }
           
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));
                    gen.set(newName+".CryptHead.SecTimestamp.time",HBCIUtils.time2StringISO(d));
                    gen.set(newName+".CryptHead.role",u_role);
                    gen.set(newName+".CryptHead.secfunc",u_secfunc);
                    gen.set(newName+".CryptHead.compfunc",u_compfunc);
                    gen.set(newName+".MsgHead.dialogid",dialogid);
                    gen.set(newName+".MsgHead.msgnum",msgnum);
                    gen.set(newName+".MsgTail.msgnum",msgnum);
                   
                    if (newName.endsWith("Res")) {
                        gen.set(newName+".MsgHead.MsgRef.dialogid",dialogid);
                        gen.set(newName+".MsgHead.MsgRef.msgnum",msgnum);
                    }

                    newmsg=gen.generate(newName);

                    // renumerate crypto-segments
                    for (int i=1;i<=2;i++) {
                        SEG seg=(SEG)(((MultipleSEGs)((newmsg.getChildContainers()).get(i))).getElements().get(0));
                        seg.setSeq(997+i,SyntaxElement.ALLOW_OVERWRITE);
                    }

                    newmsg.propagateValue(newmsg.getPath()+".MsgTail.SegHead.seq",segnum,
                            SyntaxElement.DONT_TRY_TO_CREATE,
                            SyntaxElement.ALLOW_OVERWRITE);
                    newmsg.autoSetMsgSize(gen);
                } catch (Exception ex) {
                    throw new HBCI_Exception("*** error while encrypting",ex);
                }
            }
            else HBCIUtils.log("did not encrypt - message does not want to be encrypted",HBCIUtils.LOG_DEBUG);
View Full Code Here

        fi.close();
       
        MsgGen gen=new MsgGen(SyntaxCheck.class.getClassLoader().getResourceAsStream("hbci-"+version+".xml"));
       
        if (msgName!=null && msgName.length()!=0) {
            MSG msg=new MSG(msgName,st.toString(),st.length(),gen,checkSeq,checkValids);
            String st2=msg.toString(0);
           
            if (st2.equals(st.toString())) {
                System.out.println("ok");
            } else {
                System.out.println("detected, but different in- and output");
                System.out.println(st2);
            }
           
            Properties p=msg.getData();
            ArrayList al=new ArrayList();
            for (Enumeration e=p.propertyNames();e.hasMoreElements();) {
                al.add(e.nextElement());
            }
            String[] sa=(String[])al.toArray(new String[al.size()]);
            Arrays.sort(sa);
           
            for (int i=0;i<sa.length;i++) {
                String value=p.getProperty(sa[i]);
                System.out.println(sa[i]+" = "+value+" ("+value.length()+" Bytes)");
            }
        } else {
            NodeList list=gen.getSyntax().getElementsByTagName("MSGdef");
            int      size=list.getLength();
            MSG      msg;
           
            for (int i=0;i<size;i++) {
                msgName=((Element)list.item(i)).getAttribute("id");
                System.out.println("checking for '"+msgName+"'");
                try {
                    msg=new MSG(msgName,st.toString(),st.length(),gen,checkSeq,checkValids);
                } catch (Exception e) {
                    msg=null;
                }
                if (msg!=null) {
                    String st2=msg.toString(0);
                   
                    if (st2.equals(st.toString())) {
                        System.out.println("ok");
                    } else {
                        System.out.println("detected, but different in- and output");
View Full Code Here

    String data = getFile("msg/bugzilla-1129.txt");
    HBCIKernelImpl kernel = new HBCIKernelImpl(null,"plus");
    kernel.rawNewMsg("DauerList");
   
    MsgGen gen = kernel.getMsgGen();
    MSG msg = MSGFactory.getInstance().createMSG("CustomMsgRes",data,data.length(),gen);

    Hashtable<String,String> ht = new Hashtable<String,String>();
    msg.extractValues(ht);
    return ht;
  }
View Full Code Here

    String data = getFile(file);
    HBCIKernelImpl kernel = new HBCIKernelImpl(null,version);
    kernel.rawNewMsg("DialogInitAnon");
   
    MsgGen gen = kernel.getMsgGen();
    MSG msg = MSGFactory.getInstance().createMSG("DialogInitAnonRes",data,data.length(),gen);
    Hashtable<String,String> ht = new Hashtable<String,String>();
    msg.extractValues(ht);
     
    // Prefix abschneiden
    Properties bpd = new Properties();
    for (Enumeration<String> e=ht.keys();e.hasMoreElements();)
    {
View Full Code Here

TOP

Related Classes of org.kapott.hbci.protocol.MSG

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.