Esempio n. 1
0
    def __init__(self, mf, sam, ins2handler=None, maxle=MAX_EXTENDED_LE, ef_cardsecurity=None, ef_cardaccess=None, ca_key=None, cvca=None, disable_checks=False, esign_key=None, esign_ca_cert=None, esign_cert=None):
        Iso7816OS.__init__(self, mf, sam, ins2handler, maxle)
        self.ins2handler[0x86] = self.SAM.general_authenticate
        self.ins2handler[0x2c] = self.SAM.reset_retry_counter

        # different ATR (Answer To Reset) values depending on used Chip version
        # It's just a playground, because in past one of all those eID clients did not recognize the card correctly with newest ATR values
        self.atr = '\x3B\x8A\x80\x01\x80\x31\xF8\x73\xF7\x41\xE0\x82\x90\x00\x75'
        #self.atr = '\x3B\x8A\x80\x01\x80\x31\xB8\x73\x84\x01\xE0\x82\x90\x00\x06'
        #self.atr = '\x3B\x88\x80\x01\x00\x00\x00\x00\x00\x00\x00\x00\x09'
        #self.atr = '\x3B\x87\x80\x01\x80\x31\xB8\x73\x84\x01\xE0\x19'

        self.SAM.current_SE.disable_checks = disable_checks
        if ef_cardsecurity:
            ef = self.mf.select('fid', 0x011d)
            ef.data = ef_cardsecurity
        if ef_cardaccess:
            ef = self.mf.select('fid', 0x011c)
            ef.data = ef_cardaccess
        if cvca:
            self.SAM.current_SE.cvca = cvca
        if ca_key:
            self.SAM.current_SE.ca_key = ca_key
        esign = self.mf.select('dfname', '\xA0\x00\x00\x01\x67\x45\x53\x49\x47\x4E')
        if esign_ca_cert:
            ef = esign.select('fid', 0xC000)
            ef.data = esign_ca_cert
        if esign_cert:
            ef = esign.select('fid', 0xC001)
            ef.data = esign_cert
Esempio n. 2
0
 def __init__(self, mf, sam, ins2handler=None, maxle=MAX_SHORT_LE):
     Iso7816OS.__init__(self, mf, sam, ins2handler, maxle)
     self.ins2handler = {
         0xc0: self.getResponse,
         0xa4: self.mf.selectFile,
         0xb0: self.mf.readBinaryPlain,
         0x20: self.SAM.verify,
         0x24: self.SAM.change_reference_data,
         0x22: self.SAM.manage_security_environment,
         0x2a: self.SAM.perform_security_operation,
         0xe4: self.getCardData,
         0xe6: self.logOff
     }
     self.atr = '\x3B\x98\x13\x40\x0A\xA5\x03\x01\x01\x01\xAD\x13\x11'
Esempio n. 3
0
    def __init__(self,
                 mf,
                 sam,
                 ins2handler=None,
                 maxle=MAX_EXTENDED_LE,
                 ef_cardsecurity=None,
                 ef_cardaccess=None,
                 ca_key=None,
                 cvca=None,
                 disable_checks=False,
                 esign_key=None,
                 esign_ca_cert=None,
                 esign_cert=None):
        Iso7816OS.__init__(self, mf, sam, ins2handler, maxle)
        self.ins2handler[0x86] = self.SAM.general_authenticate
        self.ins2handler[0x2c] = self.SAM.reset_retry_counter

        # different ATR (Answer To Reset) values depending on used Chip version
        # It's just a playground, because in past one of all those eID clients
        # did not recognize the card correctly with newest ATR values
        self.atr = b'\x3B\x8A\x80\x01\x80\x31\xF8\x73\xF7\x41\xE0\x82\x90' + \
                   b'\x00\x75'
        # self.atr = b'\x3B\x8A\x80\x01\x80\x31\xB8\x73\x84\x01\xE0\x82\x90' + \
        #            b'\x00\x06'
        # self.atr = b'\x3B\x88\x80\x01\x00\x00\x00\x00\x00\x00\x00\x00\x09'
        # self.atr = b'\x3B\x87\x80\x01\x80\x31\xB8\x73\x84\x01\xE0\x19'

        self.SAM.current_SE.disable_checks = disable_checks
        if ef_cardsecurity:
            ef = self.mf.select('fid', 0x011d)
            ef.data = ef_cardsecurity
        if ef_cardaccess:
            ef = self.mf.select('fid', 0x011c)
            ef.data = ef_cardaccess
        if cvca:
            self.SAM.current_SE.cvca = cvca
        if ca_key:
            self.SAM.current_SE.ca_key = ca_key
        esign = self.mf.select('dfname',
                               b'\xA0\x00\x00\x01\x67\x45\x53\x49\x47\x4E')
        if esign_ca_cert:
            ef = esign.select('fid', 0xC000)
            ef.data = esign_ca_cert
        if esign_cert:
            ef = esign.select('fid', 0xC001)
            ef.data = esign_cert
Esempio n. 4
0
    def formatResult(self, ins, le, data, sw):
        if le == 0 and len(data):
            # cryptoflex does not inpterpret le==0 as maxle
            self.lastCommandSW = sw
            self.lastCommandOffcut = data
            r = R_APDU(inttostring(SW["ERR_WRONGLENGTH"] +\
                    min(0xff, len(data)))).render()
        else:
            if ins == 0xa4 and len(data):
                # get response should be followed by select file
                self.lastCommandSW = sw
                self.lastCommandOffcut = data
                r = R_APDU(inttostring(SW["NORMAL_REST"] +\
                    min(0xff, len(data)))).render()
            else:
                r = Iso7816OS.formatResult(self, Iso7816OS.seekable(ins), le, data, sw, False)

        return r
Esempio n. 5
0
 def formatResult(self, seekable, le, data, sw, sm):
     r = R_APDU(Iso7816OS.formatResult(self, seekable, le, data, sw, sm))
     # The Belpic applet provides a bogus file length of 65536 for
     # every file, and does not return an error or warning when the
     # actual file length is shorter that the file as found; so
     # filter out the EOFBEFORENEREAD warning
     if (r.sw1 == 0x62 and r.sw2 == 0x82):
         logging.info("Filtering out warning")
         r.sw = "9000".decode("hex")
     return r.render()
Esempio n. 6
0
 def execute(self, msg):
     c = C_APDU(msg)
     if (c.ins == 0xa4 and c.p1 == 0x02):
         # The belpic applet is a bit loose with interpretation of
         # the ISO 7816 standard on the A4 command:
         # - The MF can be selected by name from anywhere with P1 ==
         #   0x02, rather than 0x00 as ISO 7816 requires
         if (c.data == '3F00'.decode('hex')):
             logging.info("Original APDU:\n%s\nRewritten to:\n", str(c))
             c.p1 = 0
             msg = c.render()
         # - Child DFs can be selected with P1 == 0x02, rather than
         #   0x01 as ISO 7816 requires
         if (c.data == 'DF00'.decode('hex')
                 or c.data == 'DF01'.decode('hex')):
             logging.info("Original APDU:\n%s\nRewritten to:\n", str(c))
             c.p1 = 1
             msg = c.render()
     return Iso7816OS.execute(self, msg)
Esempio n. 7
0
 def __init__(self, mf, sam, ins2handler=None, maxle=MAX_SHORT_LE):
     Iso7816OS.__init__(self, mf, sam, ins2handler, maxle)
     self.atr = '\x3B\xE2\x00\x00\x40\x20\x49\x06'
Esempio n. 8
0
 def getATR(self):
     return Iso7816OS.makeATR(directConvention=True)
Esempio n. 9
0
 def __init__(self, mf, sam, ins2handler=None, maxle=MAX_SHORT_LE):
     Iso7816OS.__init__(self, mf, sam, ins2handler, maxle)
     self.atr = '\x3B\xE2\x00\x00\x40\x20\x49\x06'