Esempio n. 1
0
 def __doMutualAuth(self, args):
     scp, scpi, sencKey, smacKey, dekKey = args
     
     if not self.__checkContext(): return
     if not self.__checkCardInfo(): return
     
     self.__handler.handleActionBegin("do mutual authentication")
     
     try:
         self.__handler.handleLog('doMutualAuth(): Start...')
         # Select Card Manager first;
         gp.selectApplication(self.__context, self.__cardInfo, '')
         # Get SCP informations;
         if scp == -1 and scpi == -1:
             scp, scpi = gp.getSCPDetails(self.__context, self.__cardInfo)
             self.__handler.handleSCPInfo(scp, scpi)
         
         if (scp in (1, 2)):
             if (len(sencKey) != 16) or (len(smacKey) != 16) or (len(dekKey) != 16):
                 self.__handler.handleLog('The key of SCP01 shall be 16 bytes long.', wx.LOG_Warning)
                 return
         elif scp == 3:
             keyLen1 = len(sencKey)
             keyLen2 = len(smacKey)
             keyLen3 = len(dekKey)
             if (keyLen1 not in (16, 24, 32)) or (keyLen2 not in (16, 24, 32)) or (keyLen3 not in (16, 24, 32)):
                 self.__handler.handleLog('The key of SCP03 shall be (16 or 24 or 32) bytes long.', wx.LOG_Warning)
                 return
         
         kvn = 0
         self.__securityInfo = gp.mutualAuthentication(self.__context, self.__cardInfo, None, sencKey, smacKey, dekKey, kvn, 0, scp, scpi, 0, 0)
         self.__handler.handleLog('doMutualAuth(): Succeeded.', wx.LOG_Info)
     except Exception, e:
         self.__handler.handleException(e)
Esempio n. 2
0
    def __selectApplication(self, args):
        if not self.__checkContext(): return
        if not self.__checkCardInfo(): return

        instanceAID = args[0]
        
        try:
            self.__handler.handleLog('selectApplication: Start ...')
            gp.selectApplication(self.__context, self.__cardInfo, instanceAID)
            self.__handler.handleLog('selectApplication: succeeded.')
        except Exception, e:
            self.__handler.handleException(e)
Esempio n. 3
0
    def __selectApplication(self, args):
        if not self.__checkContext(): return
        if not self.__checkCardInfo(): return

        self.__handler.handleActionBegin("select application")

        instanceAID = args[0]

        try:
            self.__handler.handleLog('selectApplication: Start ...')
            gp.selectApplication(self.__context, self.__cardInfo, instanceAID)
            self.__handler.handleLog('selectApplication: succeeded.',
                                     wx.LOG_Info)
        except Exception, e:
            self.__handler.handleException(e)
Esempio n. 4
0
    def __doMutualAuth(self, args):
        scp, scpi, sencKey, smacKey, dekKey = args

        if not self.__checkContext(): return
        if not self.__checkCardInfo(): return

        self.__handler.handleActionBegin("do mutual authentication")

        try:
            self.__handler.handleLog('doMutualAuth(): Start...')
            # Select Card Manager first;
            gp.selectApplication(self.__context, self.__cardInfo, '')
            # Get SCP informations;
            if scp == -1 and scpi == -1:
                scp, scpi = gp.getSCPDetails(self.__context, self.__cardInfo)
                self.__handler.handleSCPInfo(scp, scpi)

            if (scp in (1, 2)):
                if (len(sencKey) != 16) or (len(smacKey) != 16) or (len(dekKey)
                                                                    != 16):
                    self.__handler.handleLog(
                        'The key of SCP01 shall be 16 bytes long.',
                        wx.LOG_Warning)
                    return
            elif scp == 3:
                keyLen1 = len(sencKey)
                keyLen2 = len(smacKey)
                keyLen3 = len(dekKey)
                if (keyLen1 not in (16, 24, 32)) or (keyLen2 not in (
                        16, 24, 32)) or (keyLen3 not in (16, 24, 32)):
                    self.__handler.handleLog(
                        'The key of SCP03 shall be (16 or 24 or 32) bytes long.',
                        wx.LOG_Warning)
                    return

            kvn = 0
            self.__securityInfo = gp.mutualAuthentication(
                self.__context, self.__cardInfo, None, sencKey, smacKey,
                dekKey, kvn, 0, scp, scpi, 0, 0)
            self.__handler.handleLog('doMutualAuth(): Succeeded.', wx.LOG_Info)
        except Exception, e:
            self.__handler.handleException(e)
Esempio n. 5
0
 def selectApplication(self, aid):
     self.__checkContext()
     return gp.selectApplication(self.__context, self.__cardInfo, aid)
Esempio n. 6
0
    for i in len(s) >> 1:
        pass
    
if __name__ == "__main__":
    gp.enableTraceMode(True)
    
    c = gp.establishContext()
    
    readernames = gp.listReaders(c)
    for i in range(len(readernames)):
        print('%d - %s' %(i, readernames[i]))
    i = int(input("Please select one reader: "))
    cc = gp.connectCard(c, readernames[i], gp.SCARD_PROTOCOL_T1)
    
    gp.sendApdu(c, cc, None, '\x00\xB0\x00\x00\x00')
    gp.selectApplication(c, cc, '')
    sc = gp.mutualAuthentication(c, cc, gp.DEFAULT_KEY, gp.DEFAULT_KEY, gp.DEFAULT_KEY, gp.DEFAULT_KEY, 0x00, 0x00, 0x02, 0x15, 0, 0)
    
    INFO("Get status:")
    try:
        status10 = gp.getStatus(c, cc, None, gp.GET_STATUS_P1_EXECUTABLE_LOAD_FILES_MODULES)
        INFO("    Status 0x10: " + str(status10))
    except:
        pass
    try:
        status20 = gp.getStatus(c, cc, None, gp.GET_STATUS_P1_EXECUTABLE_LOAD_FILES)
        INFO("    Status 0x20: " + str(status20))
    except:
        pass
    try:
        status40 = gp.getStatus(c, cc, None, gp.GET_STATUS_P1_APP_SSD)