Beispiel #1
0
 def CheckSuccessOrRaise(self):
   if self.sw1 == 0x69 and self.sw2 == 0x85:  # SW_CONDITIONS_NOT_SATISFIED
     raise errors.TUPRequiredError()
   elif self.sw1 == 0x6a and self.sw2 == 0x80:  # SW_WRONG_DATA
     raise errors.InvalidKeyHandleError()
   elif self.sw1 == 0x67 and self.sw2 == 0x00:  # SW_WRONG_LENGTH
     raise errors.InvalidKeyHandleError()
   elif not self.IsSuccess():
     raise errors.ApduError(self.sw1, self.sw2)
Beispiel #2
0
 def CheckSuccessOrRaise(self):
   if self.sw1 == 0x69 and self.sw2 == 0x85:
     raise errors.TUPRequiredError()
   elif self.sw1 == 0x6a and self.sw2 == 0x80:
     raise errors.InvalidKeyHandleError()
   elif self.sw1 == 0x69 and self.sw2 == 0x84:
     raise errors.InvalidKeyHandleError()
   elif not self.IsSuccess():
     raise errors.ApduError(self.sw1, self.sw2)
    def testRegisterError(self):
        mock_sk = mock.MagicMock()
        mock_sk.CmdRegister.side_effect = errors.ApduError(0xff, 0xff)
        mock_sk.CmdVersion.return_value = b'U2F_V2'
        u2f_api = u2f.U2FInterface(mock_sk)

        with self.assertRaises(errors.U2FError) as cm:
            u2f_api.Register('testapp', b'ABCD', [])
        self.assertEquals(cm.exception.code, errors.U2FError.BAD_REQUEST)
        self.assertEquals(cm.exception.cause.sw1, 0xff)
        self.assertEquals(cm.exception.cause.sw2, 0xff)

        self.assertEquals(mock_sk.CmdRegister.call_count, 1)
        self.assertEquals(mock_sk.CmdWink.call_count, 0)
Beispiel #4
0
    def testAuthenticateError(self):
        mock_sk = mock.MagicMock()
        mock_sk.CmdAuthenticate.side_effect = errors.ApduError(0xff, 0xff)
        mock_sk.CmdVersion.return_value = 'U2F_V2'
        u2f_api = u2f.U2FInterface(mock_sk)

        with self.assertRaises(errors.U2FError) as cm:
            u2f_api.Authenticate('testapp', 'ABCD',
                                 [model.RegisteredKey('khA')])
        self.assertEquals(cm.exception.code, errors.U2FError.BAD_REQUEST)
        self.assertEquals(cm.exception.cause.sw1, 0xff)
        self.assertEquals(cm.exception.cause.sw2, 0xff)

        self.assertEquals(mock_sk.CmdAuthenticate.call_count, 1)
        self.assertEquals(mock_sk.CmdWink.call_count, 0)
    def CmdVersion(self):
        """Obtain the version of the device and test transport format.

    Obtains the version of the device and determines whether to use ISO
    7816-4 or the U2f variant.  This function should be called at least once
    before CmdAuthenticate or CmdRegister to make sure the object is using the
    proper transport for the device.

    Returns:
      The version of the U2F protocol in use.
    """
        self.logger.debug('CmdVersion')
        response = self.InternalSendApdu(
            apdu.CommandApdu(0, apdu.CMD_VERSION, 0x00, 0x00))

        if not response.IsSuccess():
            raise errors.ApduError(response.sw1, response.sw2)

        return response.body