⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cuppbocep.java

📁 在java卡上实现的PBOC电子钱包应用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

       if ( ef17 == null )
           ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);

       ((tjpbocIDU)ef17).getrnd(apduin.pdata);
       apduin.le = (short)4;
       return true;
    }
    //------------------------------------------------
    private boolean check_ac(byte ac)
    {
        if (!bPersoed) return true;

        if ( ac == (byte)0x0)  return true;
        if ( ac == (byte)0x01) return pinOwner.certified();
        if ( ac == (byte)0x02) if( (byte)(apduin.cla&0x0F) == (byte)0x04) return true;
        return false;
    }
    //------------------------------------------------
    private boolean operate_file(byte opt, tjefbinary fp) throws ISOException
    {
        short offset,rc;
        
        if ( opt == (byte)'R' ) {
           if ( (short)(apduin.p2+apduin.le) > fp.fsize ) {
              offset = (short)(fp.fsize-apduin.p2);
              ISOException.throwIt((short)(0x6c00 + offset));
           }
           apduin.lc = (short)(apduin.p2&0x0FF);
           if (!check_ac(fp.acr))
               ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);

           fp.readbin(apduin.lc,apduin.le,apduin.pdata);
           return true;
        } else if ( opt == (byte)'U' ) { // update binary

           offset = (short)(apduin.p2&0x0FF);
           if ( (short)(offset+apduin.lc) > fp.fsize )
               ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);

           if (!check_ac(fp.acw)) 
        	   ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);

           if( apduin.cla == (byte)0x04) {
         	   rc = ((tjpbocIDU)ef17).unwrap_apdu((byte)0x06,apduin,false);
               switch(rc) {
                  case (short)0x01: ISOException.throwIt(constdef.SW_E_REFDATA);            
                  case (short)0x02: ISOException.throwIt(constdef.SW_E_SMDATA);        	
               }
           }
          
           fp.writebin(offset,apduin.lc,apduin.pdata);
           if (fp == ef17)
                ((tjpbocIDU)ef17).updateEDC();

           apduin.le = (short)0;
           return true;
        }
        ISOException.throwIt(constdef.SW_E_INTERNAL);
        return false;
    }
    //------------------------------------------------
    public boolean read_update_binary(byte opt ) throws ISOException
    {
        byte  fid;

        if( (apduin.cla != (byte)0x0) && (apduin.cla != (byte)0x04))
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
       
        fid = (byte)(apduin.p1&0x80);
        if (fid == (byte)0x80) {
            fid = (byte)(apduin.p1 & (byte)0x1f);
        } else ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        switch (fid) {
            case (byte)21:  return operate_file(opt,ef15);
            case (byte)22:  return operate_file(opt,ef16);
            case (byte)23:  return operate_file(opt,ef17);
        }

        ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
        return false;
    }
    //------------------------------------------------
    public boolean read_record() throws ISOException
    {
      byte  tb;

      if( apduin.cla != (byte)0x0)
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
     
      if( apduin.p1 ==(byte)0 )
          ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

      tb = (byte)((apduin.p2&0x0f8)>>3);

      if (tb != (byte)0x18)
          ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);

      if ( (short)(apduin.p1) > ef18.recordNumber() )
          ISOException.throwIt(ISO7816.SW_RECORD_NOT_FOUND);

      if (!check_ac(ef18.acr))
           ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);

      if( apduin.le > (short)0 ) {
            if ( apduin.le != ef18.recordLength() )
               ISOException.throwIt((short)(0x6c00 + ef18.recordLength()));
      }

      apduin.le = ef18.readrec(apduin.p1,apduin.pdata);

      return true;
    }
    //------------------------------------------------
    public boolean update_record() throws ISOException
    {
      byte  tb;
      short rc;
      tjelinearfix  fp=null;

      if( (apduin.cla != (byte)0x0) && (apduin.cla != (byte)0x04))
          ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
      
      tb = (byte)((apduin.p2&0x0f8)>>3);
      if (tb == (byte)0x18) fp = ef18;
      else if (tb == (byte)0x19) fp = ef19;
      else ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);

      if ( fp.isCyclicMode()) {
         if( apduin.p1 !=(byte)0 ) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
      } else {
         if( apduin.p1 ==(byte)0 ) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
      }

      if ( (short)(apduin.p1) > fp.recordNumber() )
          ISOException.throwIt(ISO7816.SW_RECORD_NOT_FOUND);

      if (!check_ac(fp.acw))
          ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
      
      if( apduin.cla == (byte)0x04) {
    	  rc = ((tjpbocIDU)ef17).unwrap_apdu((byte)0x06,apduin,false);
          switch(rc) {
             case (short)0x01: ISOException.throwIt(constdef.SW_E_REFDATA);            
             case (short)0x02: ISOException.throwIt(constdef.SW_E_SMDATA);        	
          }
      }

      if( apduin.lc > (short)0 ) {
            if ( apduin.lc != fp.recordLength() )
               ISOException.throwIt((short)(0x6c00 + fp.recordLength()));
      } else ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);

      if(!fp.writerec(apduin.p1,apduin.pdata))
          ISOException.throwIt(constdef.SW_E_INTERNAL);

      apduin.le = (short)0;
      return true;
    }
    //------------------------------------------------
    public boolean get_balance() throws ISOException
    {
        if( apduin.cla != constdef.CUP_CLA )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        if ( apduin.p1 != (byte)0 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if ( apduin.p2 != (byte)0x02 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if (apduin.lc!=(short)0x0)
           ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        //JCSystem.beginTransaction();
        ((tjpbocIDU)ef17).getBalanceEP(apduin.pdata);
        //JCSystem.commitTransaction();
        apduin.le = (short)4;
        return true;
    }
    //------------------------------------------------
    public boolean init_purchase() throws ISOException
    {
        if ( apduin.p2 != (byte)0x02 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if (apduin.lc!=(short)0x0b)
           ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);

        //JCSystem.beginTransaction();
        short rc = ((tjpbocIDU)ef17).init4purchase(apduin.pdata);
        //JCSystem.commitTransaction();
        if ( rc > (short)0 )
           switch(rc) {
              case (short)1: ISOException.throwIt((short)0x9401);
              case (short)2: ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
              case (short)3: ISOException.throwIt((short)0x9403);
              default:       ISOException.throwIt(constdef.SW_E_INTERNAL);
           }

        apduin.le = (short)0x0F;
        return true;
    }
    //------------------------------------------------
    public boolean debit_purchase() throws ISOException
    {
        if( apduin.cla != constdef.CUP_CLA )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
  
        if ( apduin.p1 != (byte)0x1 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if ( apduin.p2 != (byte)0x00 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if (apduin.lc!=(short)0x0F)
           ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
 
        if (ef17==null)
            ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);

        if ( !((tjpbocIDU)ef17).checkStateMachine((byte)0x0)) {
            //JCSystem.abortTransaction();
            ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
        }
        
        //JCSystem.beginTransaction();
        short rc = ((tjpbocIDU)ef17).debit4purchase(apduin.pdata);
        //JCSystem.commitTransaction();
        if ( rc > (short)0 )
           switch(rc) {
              case (short)1: ISOException.throwIt((short)0x6901);
              case (short)2: ISOException.throwIt((short)0x9302);
              case (short)4: ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
              default:       ISOException.throwIt(constdef.SW_E_INTERNAL);
           }
         
        apduin.le = (short)0x8;
        return true;
    }
    //------------------------------------------------
    public boolean init_load() throws ISOException
    {
        if ( apduin.p2 != (byte)0x02 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if (apduin.lc!=(short)0x0b)
           ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);

        if(!pinOwner.certified())
           ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);

        short rc = ((tjpbocIDU)ef17).init4load(apduin.pdata);

        if ( rc > (short)0 )
           switch(rc) {
              case (short)1: ISOException.throwIt((short)0x9401);
              case (short)2: ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED); // overflow
              default:       ISOException.throwIt(constdef.SW_E_INTERNAL);
           }

        apduin.le = (short)0x10;
        return true;
    }
    //------------------------------------------------
    public boolean credit_load() throws ISOException
    {
        if( apduin.cla != constdef.CUP_CLA )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        if ( apduin.p1 != (byte)0x0 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if ( apduin.p2 != (byte)0x0 )
           ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if (apduin.lc!=(short)0x0b)
           ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);

        if (ef17==null)
            ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);

        if ( !((tjpbocIDU)ef17).checkStateMachine((byte)0x01))
            ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);

        short rc = ((tjpbocIDU)ef17).credit4load(apduin.pdata);

        if ( rc > (short)0 )
           switch(rc) {
             case (short)1: ISOException.throwIt((short)0x9302);
             default:       ISOException.throwIt(constdef.SW_E_INTERNAL);
           }

        apduin.le = (short)0x4;
        return true;
    }
    //------------------------------------------------
    public boolean get_tp() throws ISOException
    {
        if( apduin.cla != constdef.CUP_CLA )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        if ( apduin.p1 != (byte)0x00)
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if (apduin.lc!=(short)0x02)
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);

        if ( !((tjpbocIDU)ef17).can_gtp())
        	ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
        
        if ( !((tjpbocIDU)ef17).match_tn(apduin.p2,Util.makeShort(apduin.pdata[0],apduin.pdata[1])))
        	ISOException.throwIt((short)0x9406);
        
        ((tjpbocIDU)ef17).copy_tac(apduin.pdata);
        apduin.le = (short)0x8;
    	return true;
    }
    //------------------------------------------------
    public boolean app_block() throws ISOException
    {
    	short rc;
        
    	if( apduin.cla != (byte)0x84 )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        if ( apduin.p1 != (byte)0x00)
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
        
        if ( apduin.lc != (byte)0x04)
        	ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        
        rc = ((tjpbocIDU)ef17).unwrap_apdu((byte)0x06,apduin,false);
        switch(rc) {
           case (short)0x01: ISOException.throwIt(constdef.SW_E_REFDATA);            
           case (short)0x02: ISOException.throwIt(constdef.SW_E_SMDATA);        	
        }
        
        if (apduin.p2 ==(byte)0x0) bAppBlocked = true; 
        else if (apduin.p2 ==(byte)0x01) bAppBLKALWS  = true;
        else ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
        
        apduin.le = (short)0x0;
    	return true;
    }
    //------------------------------------------------
    public boolean app_unblock() throws ISOException
    {
    	short rc;

    	if( apduin.cla != (byte)0x84  )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        if ( apduin.p1 != (byte)0x00)
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if ( apduin.p2 != (byte)0x00)
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if ( apduin.lc != (byte)0x04)
        	ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        
        if(bAppBLKALWS)
        	ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
        
        rc = ((tjpbocIDU)ef17).unwrap_apdu((byte)0x06,apduin,false);
        switch(rc) {
           case (short)0x01: ISOException.throwIt(constdef.SW_E_REFDATA);            
           case (short)0x02: ISOException.throwIt(constdef.SW_E_SMDATA);        	
        }
        
        if(bAppBlocked) bAppBlocked = false;
        else ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
        
        apduin.le = (short)0x0;
    	return true;
    }
    //------------------------------------------------
    public boolean card_block() throws ISOException
    {
    	short rc;

    	if( apduin.cla != (byte)0x84 )
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        if ( apduin.p1 != (byte)0x00)
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
        if ( apduin.p2 != (byte)0x00)
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);

        if ( apduin.lc != (byte)0x04)
        	ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
       
        rc = ((tjpbocIDU)ef17).unwrap_apdu((byte)0x06,apduin,false);
        switch(rc) {
           case (short)0x01: ISOException.throwIt(constdef.SW_E_REFDATA);            
           case (short)0x02: ISOException.throwIt(constdef.SW_E_SMDATA);        	
        }
        
        bCardBlocked = true;
        apduin.le = (short)0x0;
    	return true;
    }
    //------------------------------------------------
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -