Package org.kapott.hbci.protocol

Examples of org.kapott.hbci.protocol.SEG


      super(Integer.parseInt(HBCIUtils.getParam("kernel.objpool.SEG","128")));
    }
   
    public SEG createSEG(String type, String name, String path, char predelim, int idx, StringBuffer res, int fullResLen, Document syntax, Hashtable<String, String> predefs,Hashtable<String, String> valids)
    {
        SEG ret=(SEG)getFreeObject();
       
        if (ret==null) {
            // HBCIUtils.log("creating new SEG object",HBCIUtils.LOG_DEBUG);
            ret=new SEG(type,name,path,predelim,idx,res,fullResLen,syntax,predefs,valids);
            addToUsedPool(ret);
        } else {
            // HBCIUtils.log("reusing SEG object",HBCIUtils.LOG_DEBUG);
            try {
                ret.init(type,name,path,predelim,idx,res,fullResLen,syntax,predefs,valids);
                addToUsedPool(ret);
            } catch (RuntimeException e) {
                addToFreePool(ret);
                throw e;
            }
View Full Code Here


        return ret;
    }
   
    public SEG createSEG(String type, String name, String path, int idx, Document syntax)
    {
        SEG ret=(SEG)getFreeObject();
       
        if (ret==null) {
            // HBCIUtils.log("creating new SEG object",HBCIUtils.LOG_DEBUG);
            ret=new SEG(type, name, path, idx, syntax);
            addToUsedPool(ret);
        } else {
            // HBCIUtils.log("reusing SEG object",HBCIUtils.LOG_DEBUG);
            try {
                ret.init(type, name, path, idx, syntax);
                addToUsedPool(ret);
            } catch (RuntimeException e) {
                addToFreePool(ret);
                throw e;
            }
View Full Code Here

                    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);
View Full Code Here

    {
        boolean ret = true;
        MultipleSyntaxElements seglist = (msg.getChildContainers().get(1));

        if (seglist instanceof MultipleSEGs) {
            SEG crypthead = null;

            try {
                crypthead = (SEG)(seglist.getElements().get(0));
            } catch (Exception e) {
                ret = false;
            }

            if (ret) {
                String sigheadCode = "HNVSK";
                MsgGen gen=handlerdata.getMsgGen();

                if (!crypthead.getCode(gen).equals(sigheadCode))
                    ret = false;
            }
        }
        else ret = false;
View Full Code Here

            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);
                    }
View Full Code Here

                    setLowlevelParam(destination,content);
            }
        }
       
        // verify if segment can be created
        SEG seg=null;
        try {
            seg=createJobSegment();
            seg.validate();
        } catch (Exception ex) {
            throw new HBCI_Exception("*** the job segment for this task can not be created",ex);
        } finally {
            if (seg!=null) {
                SEGFactory.getInstance().unuseObject(seg);
View Full Code Here

        return createJobSegment(0);
    }
   
    public SEG createJobSegment(int segnum)
    {
        SEG seg=null;
        try {
            MsgGen gen=getParentHandler().getMsgGen();
            seg=SEGFactory.getInstance().createSEG(getName(),getName(),null,0,gen.getSyntax());
            for (Enumeration e=getLowlevelParams().propertyNames();e.hasMoreElements();) {
                String key=(String)e.nextElement();
                String value=getLowlevelParams().getProperty(key);
                seg.propagateValue(key,value,
                                   SyntaxElement.TRY_TO_CREATE,
                                   SyntaxElement.DONT_ALLOW_OVERWRITE);
            }
            seg.propagateValue(getName()+".SegHead.seq",Integer.toString(segnum),
                               SyntaxElement.DONT_TRY_TO_CREATE,
                               SyntaxElement.ALLOW_OVERWRITE);
        } catch (Exception ex) {
            throw new HBCI_Exception("*** the job segment for this task can not be created",ex);
        }
View Full Code Here

                try {
                    int numOfPassports=passports.size();
                   
                    // create an empty sighead and sigtail segment for each required signature
                    for (int idx=0;idx<numOfPassports;idx++) {
                        SEG sighead=SEGFactory.getInstance().createSEG("SigHeadUser","SigHead",msgName,numOfPassports-1-idx,gen.getSyntax());
                        SEG sigtail=SEGFactory.getInstance().createSEG("SigTailUser","SigTail",msgName,idx,gen.getSyntax());
                       
                        List<MultipleSyntaxElements> msgelements=msg.getChildContainers();
                        List<SyntaxElement> sigheads=((MultipleSEGs)(msgelements.get(1))).getElements();
                        List<SyntaxElement> sigtails=((MultipleSEGs)(msgelements.get(msgelements.size()-2))).getElements();

                        // insert sighead segment in msg
                        if ((numOfPassports-1-idx)<sigheads.size()) {
                            SEGFactory.getInstance().unuseObject(sigheads.get(numOfPassports-1-idx));
                        } else {
                            for (int i=sigheads.size()-1;i<numOfPassports-1-idx;i++) {
                                sigheads.add(null);
                            }
                        }
                        sigheads.set(numOfPassports-1-idx,sighead);
                       
                        // insert sigtail segment in message
                        if (idx<sigtails.size()) {
                            SEGFactory.getInstance().unuseObject(sigtails.get(idx));
                        } else {
                            for (int i=sigtails.size()-1;i<idx;i++) {
                                sigtails.add(null);
                            }
                        }
                        sigtails.set(idx,sigtail);
                    }
                   
                    // fill all sighead and sigtail segments
                    for (int idx=0;idx<numOfPassports;idx++) {
                        HBCIPassportInternal passport=passports.getPassport(idx);
                        String               role=passports.getRole(idx);
                       
                        setParam("secfunc",passport.getSigFunction());
                        setParam("cid",passport.getCID());
                        setParam("role",role);
                        setParam("range","1");
                        setParam("keyblz",passport.getBLZ());
                        setParam("keycountry",passport.getCountry());
                        setParam("keyuserid",passport.getMySigKeyName());
                        setParam("keynum",passport.getMySigKeyNum());
                        setParam("keyversion",passport.getMySigKeyVersion());
                        setParam("sysid",passport.getSysId());
                        setParam("sigid",passport.getSigId().toString());
                        setParam("sigalg",passport.getSigAlg());
                        setParam("sigmode",passport.getSigMode());
                        setParam("hashalg",passport.getHashAlg());
                        passport.incSigId();
                        passport.saveChanges();
                       
                        List<MultipleSyntaxElements> msgelements=msg.getChildContainers();
                        List<SyntaxElement> sigheads=((MultipleSEGs)(msgelements.get(1))).getElements();
                        List<SyntaxElement> sigtails=((MultipleSEGs)(msgelements.get(msgelements.size()-2))).getElements();

                        SEG sighead=(SEG)sigheads.get(numOfPassports-1-idx);
                        SEG sigtail=(SEG)sigtails.get(idx);
                       
                        fillSigHead(sighead);
                        fillSigTail(sighead,sigtail);
                    }
                    
                    msg.enumerateSegs(0,SyntaxElement.ALLOW_OVERWRITE);
                    msg.validate();
                    msg.enumerateSegs(1,SyntaxElement.ALLOW_OVERWRITE);

                    // calculate signatures for each segment
                    for (int idx=0;idx<numOfPassports;idx++) {
                        HBCIPassportInternal passport=passports.getPassport(idx);
                        List<MultipleSyntaxElements>                 msgelements=msg.getChildContainers();
                        List<SyntaxElement>                 sigtails=((MultipleSEGs)(msgelements.get(msgelements.size()-2))).getElements();
                        SEG                  sigtail=(SEG)sigtails.get(idx);

                        /* first calculate hash-result, then sign the hashresult. In
                         * most cases, the hash() step will be executed by the signature
                         * algorithm, so the hash() call returns the message as-is.
                         * Currently the only exception is PKCS#1-10, where an extra
                         * round of hashing must be executed before applying the
                         * signature process */
                        String hashdata=collectHashData(idx);
                        byte[] hashresult=passport.hash(hashdata.getBytes(Comm.ENCODING));
                        byte[] signature=passport.sign(hashresult);

                        if (passport.needUserSig()) {
                            String pintan=new String(signature,Comm.ENCODING);
                            int pos=pintan.indexOf("|");
                           
                            if (pos!=-1) {
                                // wenn �berhaupt eine signatur existiert
                                // (wird f�r server ben�tigt)
                                String pin=pintan.substring(0,pos);
                                msg.propagateValue(sigtail.getPath()+".UserSig.pin",pin,
                                        SyntaxElement.DONT_TRY_TO_CREATE,
                                        SyntaxElement.DONT_ALLOW_OVERWRITE);
                               
                                if (pos<pintan.length()-1) {
                                    String tan=pintan.substring(pos+1);
                                    msg.propagateValue(sigtail.getPath()+".UserSig.tan",tan,
                                            SyntaxElement.DONT_TRY_TO_CREATE,
                                            SyntaxElement.DONT_ALLOW_OVERWRITE);
                                }
                            }
                        } else { // normale signatur
                            msg.propagateValue(sigtail.getPath()+".sig","B"+new String(signature,Comm.ENCODING),
                                    SyntaxElement.DONT_TRY_TO_CREATE,
                                    SyntaxElement.DONT_ALLOW_OVERWRITE);
                        }
                       
                        msg.validate();
View Full Code Here

    {
        boolean ret = true;
        MultipleSyntaxElements seglist = (msg.getChildContainers().get(1));

        if (seglist instanceof MultipleSEGs) {
            SEG sighead = null;
            try {
                /* TODO: multiple signatures not supported until now */
                sighead = (SEG)(seglist.getElements().get(0));
            } catch (IndexOutOfBoundsException e) {
                ret = false;
            }

            if (ret) {
                String sigheadCode = "HNSHK";
              MsgGen gen=handlerdata.getMsgGen();

                if (!sighead.getCode(gen).equals(sigheadCode))
                    ret = false;
            }
        }
        else ret = false;

View Full Code Here

                           
                            // orderhash ermitteln
                            try {
                                // TODO: hier wird jetzt *immer* segnum=3 angenommen,
                                // kann in Einzelf�llen evtl. auch anders sein (?)
                                SEG seg=task.createJobSegment(3);
                                seg.validate();
                                String segdata=seg.toString(0);
                                HBCIUtils.log("calculating hash for jobsegment: "+segdata,HBCIUtils.LOG_DEBUG2);
                               
                                // zu verwendenden Hash-Algorithmus von dem Wert "orderhashmode" aus den BPD abh�ngig machen
                                String orderhashmode=getOrderHashMode();
                                String alg=null;
View Full Code Here

TOP

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

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.