Beispiel #1
0
    def test_hasTC1(self):
        ''' ATR应包含TC1,以解决THD88不支持接收11.8ETU字符的问题
        '''
        # check ATR to determine if it is THD88 chip,
        # if yes, test if TC1 included in ATR
        atr = api_pcsc.getatr()
        ts = int(atr[2:4], 16)
        hasta1 = True if ts&0x01 else False
        hastb1 = True if ts&0x02 else False
        hastc1 = True if ts&0x04 else False
        
        self.logger.info('ATR: ' + atr)
        if hasta1:
            offset = 2
            offset = offset+1 if hasta1 else offset
            offset = offset+1 if hastb1 else offset
            offset = offset * 2
            tc1 = atr[offset:offset+2]

            self.logger.info('TC1: ' + tc1)
            self.logger.info('ATR已包含TC1,可以解决THD88不支持接收11.8ETU字符的问题')
        else:
            self.logger.info('ATR应包含TC1,否则BCTC测试ETC时会出现THD88不支持接收11.8ETU字符的问题')
            self.fail('ATR应包含TC1,否则BCTC测试ETC时会出现THD88不支持接收11.8ETU字符的问题')

        if hastc1:
            etc, cloud = self.etc, self.cloud
            api_pcsc.reset(cold=True)
            etc.select()
            api_pcsc.reset(cold=False)
            etc.select()
Beispiel #2
0
 def OnReset(self, event):
     try:
         api_pcsc.reset()
         atr = api_pcsc.getatr()
         self.showmsg('复位成功', 'ATR: ' + atr)
     except Exception as e:
         self.showlongmsg('复位失败', str(e))
Beispiel #3
0
    def test_Delay_Between_PPS_Request_Response(self, pps1='00'):
        ''' 字符帧测试

            测试标准:传输的字符帧要符合ISO/IEC 7816-3[6]的要求,请结合MPScopeViewer软件进行判定

            PPS请求和响应之间的间隔应当大于4ETU
        '''
        etc, cloud = self.etc, self.cloud
        api_pcsc.reset(cold=True)
        cloud.disable_pps()

        dit = {
                '00': ('FF00FF', 0x174),
                '11': ('FF1011FE', 0x174),
                '94': ('FF10947B', 0x40),
                '95': ('FF10957A', 0x20),
                '96': ('FF109679', 0x10),
                #'97': ('FF109778', 0x08),
                }
        pps, etu = dit['94']
        api_pcsc.reset(cold=True)
        r, sw = cloud.exchange_raw(pps, len(pps)/2) # PPS请求和响应之间的间隔应当大于4ETU
        self.assertEqual(r, pps)
        r, sw = cloud.set_etu(etu)
        self.assertEqual(r, '%.8X'%etu)
        etc.select()

        api_pcsc.reset(cold=False)
        pps, etu = dit['95']
        r, sw = cloud.exchange_raw(pps, len(pps)/2) # PPS请求和响应之间的间隔应当大于4ETU
        self.assertEqual(r, pps)
        r, sw = cloud.set_etu(etu)
        self.assertEqual(r, '%.8X'%etu)
        etc.select()

        api_pcsc.reset(cold=False)
        pps, etu = dit['96']
        r, sw = cloud.exchange_raw(pps, len(pps)/2) # PPS请求和响应之间的间隔应当大于4ETU
        self.assertEqual(r, pps)
        r, sw = cloud.set_etu(etu)
        self.assertEqual(r, '%.8X'%etu)
        etc.select()

        api_pcsc.reset(cold=False)
        pps, etu = dit['11']
        r, sw = cloud.exchange_raw(pps, len(pps)/2) # PPS请求和响应之间的间隔应当大于4ETU
        self.assertEqual(r, pps)
        r, sw = cloud.set_etu(etu)
        self.assertEqual(r, '%.8X'%etu)
        etc.select()

        self.logger.info('PPS请求和响应之间的间隔应当大于4ETU,请使用Salea Logic测量确认')
        self.logger.info('注意:以上出现的PPS请求和响应的间隔必须全部测量确认')
        self.fail('PPS请求和响应之间的间隔应当大于4ETU,请使用Salea Logic测量确认')
Beispiel #4
0
    def test_Electrical_Class_A(self):
        ''' 与电相关的参数(Class A)测试:应用选择的功耗应符合规范要求,Icc应在0mA至60mA范围内

                测试标准:
                应用选择的功耗应符合规范要求,Icc应在0mA至60mA范围内
        '''
        etc, cloud = self.etc, self.cloud
        api_pcsc.reset(cold=True)
        etc.select()
        etc.verifypin(etc.PIN)
        api_pcsc.reset(cold=False)
        etc.select()
        etc.verifypin(etc.PIN)
    def setUpClass(cls):
        # delete, load, install
        app = Performace_arrayCopy()
        instance, pkg, applet = app.getaids()

        api_pcsc.connectreader()
        api_gp.card()
        api_gp.auth()
        api_gp.deleteaid(pkg, True, expectSW='')  # omit delete result
        api_gp.upload(app.getcappath(), pkg)
        api_gp.install(instance, pkg, applet)

        api_pcsc.reset()
        cls.app = app
Beispiel #6
0
    def reset(self):
        ''' Reset usim

            returns ATR
        '''
        atr = api_pcsc.reset()
        return atr
    def test_reset(self):
        ''' 每次复位之后,生成的随机数是否相同 '''
        alg = self.alg
        alg.select()

        # 'The random number sequence generated by this algorithm need not be the same even if seeded with the same seed data.'
        api_pcsc.reset()
        alg.select()
        data1 = alg.generateData(1)[0]
        api_pcsc.reset()
        alg.select()
        data2 = alg.generateData(1)[0]
        if data1 == data2:
            self.logger.info(u'每次复位之后,产生的随机数序列相同')
        else:
            self.logger.info(u'每次复位之后,产生的随机数序列不相同')
Beispiel #8
0
    def test_T0_Case2(self):
        ''' T=0命令方式二测试: 卡应能正确处理命令方式二
            测试标准:
            卡应能正确处理命令方式二

            成功初始化Log过程
            卡复位:ATR= 3B789600000073C84013009000
            Select Usim:00 A4 04 00 09   Data:A00000000386980701 SW:9000
            Read Binary:00 B0 95 00 00  SW:6A82
            Read Binary命令返回状态码错误! 
        '''
        etc, cloud = self.etc, self.cloud
        api_pcsc.reset(cold=True)
        etc.select()
        etc.readbinary()
        api_pcsc.reset(cold=False)
        etc.select()
        etc.readbinary()
Beispiel #9
0
    def test_9600bps(self, pps1='00'):
        ''' TA1=0x00
        '''
        etc, cloud = self.etc, self.cloud
        api_pcsc.reset(cold=True)
        cloud.disable_pps()

        dit = {
                '00': ('FF00FF', 0x174),
                '11': ('FF1011FE', 0x174),
                '94': ('FF10947B', 0x40),
                '95': ('FF10957A', 0x20),
                '96': ('FF109679', 0x10),
                #'97': ('FF109778', 0x08),
                }
        pps, etu = dit[pps1]

        # cold reset
        # ATR
        # PPSS
        # select
        # warm reset
        # ATR
        # PPSS
        # select
        api_pcsc.reset(cold=True)
        r, sw = cloud.exchange_raw(pps, len(pps)/2)
        self.assertEqual(r, pps)
        r, sw = cloud.set_etu(etu)
        self.assertEqual(r, '%.8X'%etu)
        etc.select()

        api_pcsc.reset(cold=False)
        r, sw = cloud.exchange_raw(pps, len(pps)/2)
        self.assertEqual(r, pps)
        r, sw = cloud.set_etu(etu)
        self.assertEqual(r, '%.8X'%etu)
        etc.select()

        cloud.enable_pps()
        api_pcsc.reset(cold=True)
        etc.select()
        api_pcsc.reset(cold=False)
        etc.select()
Beispiel #10
0
    def setUpClass(cls):
        # delete, load, install
        etc = Applet_ETC_ITS_BCTC()
        instance, pkg, applet = etc.getaids()

        api_pcsc.connectreader(Cloud4700.READER_NAME) # 指明读卡器名字,因为目前只有4700可以通过APDU方式设定各类电压是否支持
        api_gp.card()
        api_gp.auth()
        api_gp.deleteaid(pkg, True, expectSW='') # omit delete result
        api_gp.upload(etc.getcappath(), pkg)
        api_gp.install(instance, pkg, applet)

        cloud = Cloud4700()
        cloud.enable_all_classes()
        cloud.set_clock_divison(4) # restore to 4.8 MHz
        api_pcsc.reset()

        cls.etc = etc
        cls.cloud = cloud
Beispiel #11
0
def card(aid=CardManagerAID,
         apduheader='00A40400',
         expectData='',
         expectSW='9000',
         info='',
         name='GP, /card'):
    ''' Resets the inserted card, requests the ATR and selects the CardManager (default=GlobalPlatform CardManager)
        via the default logical channel (zero).

        Returns a tuple: (response_data, sw1sw2). 
    '''
    api_pcsc.reset()
    ret, sw = select(aid,
                     expectData=expectData,
                     expectSW=expectSW,
                     info=info,
                     name=name,
                     header=apduheader)
    LogMessage('Select Card Manager, Response: %s' % ret)
    return ret, sw
Beispiel #12
0
    def test_ClockFrequency_4(self, clk=4):
        ''' 时钟频率范围测试:4 MHz
        '''
        etc, cloud = self.etc, self.cloud
        api_pcsc.reset(cold=True)

        dit_clk = {
                4 : 12,
                4.8 : 10,
                6 : 8,
                6.8 : 7,
                8 : 6,
                9.6 : 5,
                12 : 4,
                16 : 3,
                }
        divison = dit_clk[clk]
        cloud.set_clock_divison(divison)
        r, sw = cloud.get_clock_divison()
        self.assertEqual(r, '%.2X'%divison)

        api_pcsc.reset(cold=True)
        cloud.disable_pps()
        dit_pps = {
                '00': ('FF00FF', 0x174),
                '11': ('FF1011FE', 0x174),
                '94': ('FF10947B', 0x40),
                '95': ('FF10957A', 0x20),
                '96': ('FF109679', 0x10),
                #'97': ('FF109778', 0x08),
                }
        for k in sorted(dit_pps.keys()):
            pps, etu = dit_pps[k]
            api_pcsc.reset(cold=True)
            r, sw = cloud.exchange_raw(pps, len(pps)/2)
            self.assertEqual(r, pps)
            r, sw = cloud.set_etu(etu)
            self.assertEqual(r, '%.8X'%etu)
            etc.select()

            api_pcsc.reset(cold=False)
            r, sw = cloud.exchange_raw(pps, len(pps)/2)
            self.assertEqual(r, pps)
            r, sw = cloud.set_etu(etu)
            self.assertEqual(r, '%.8X'%etu)
            etc.select()

            self.logger.info('Clock Frequency %d, TA1 %s passed' % (clk, k))
Beispiel #13
0
    def test_Voltage_Class_A(self, a=True, b=False, c=False):
        ''' 电压限值测试 - 5V
        '''
        etc, cloud = self.etc, self.cloud
        
        api_pcsc.reset()
        r, sw = cloud.enable_class(a=a, b=b, c=c) # enable Class A only

        # 卡复位成功,ATR: 3B789400000073C84013009000
        # Select 应用:00 A4 04 00 09   Data:A00000000386980701   SW:9000

        # 设置VCC=4500mV successful!
        # 卡复位,ATR: 3B789400000073C84013009000 ///////////////////////////////////////热复位
        # 选择应用失败!
        # 设置VCC=5500mV successful!
        # 卡复位,ATR: 3B789400000073C84013009000
        # Select 应用:00 A4 04 00 09   Data:A00000000386980701   SW:9000
        # Change PIN:80 5E 01 00 05  Data:1234FF0000  SW:9000
        # Change PIN:80 5E 01 00 05  Data:0000FF1234  SW:9000
        # 对应以下测试

        api_pcsc.reset(cold=True)
        etc.select()

        api_pcsc.reset(cold=False) # 目前无法设置电压为4500mV,暂时用5V热复位替代
        etc.select()

        api_pcsc.reset(cold=False) # 目前无法设置电压为5500mV,暂时用5V热复位替代
        etc.select()
        old, new = etc.PIN, '0000'
        etc.changepin(old, new)
        etc.changepin(new, old)

        # BCTC测试结束
        # 下面是另外增加的测试
        api_pcsc.reset()
        etc.select()

        api_pcsc.reset(cold=True) # 目前无法设置电压为4500mV,暂时用5V冷复位替代
        etc.select()

        api_pcsc.reset(cold=True) # 目前无法设置电压为5500mV,暂时用5V冷复位替代
        etc.select()
        old, new = etc.PIN, '0000'
        etc.changepin(old, new)
        etc.changepin(new, old)