Example #1
0
    def test_01_create_token(self):
        pin = "test"
        # Init step1
        token = init_token({"type": "u2f", "pin": pin})
        serial = token.token.serial

        self.assertEqual(token.type, "u2f")

        prefix = U2fTokenClass.get_class_prefix()
        self.assertEqual(prefix, "U2F")

        info = U2fTokenClass.get_class_info()
        self.assertEqual(info.get("type"), "u2f")

        info = U2fTokenClass.get_class_info("type")
        self.assertEqual(info, "u2f")

        idetail = token.get_init_detail()
        detail_serial = idetail.get("serial")
        self.assertEqual(serial, detail_serial)

        registerRequest = idetail.get("u2fRegisterRequest")
        version = registerRequest.get("version")
        self.assertEqual(version, "U2F_V2")
        challenge = registerRequest.get("challenge")
        self.assertEqual(len(challenge), 43)

        # Init step 2
        token = init_token({
            "type": "u2f",
            "serial": serial,
            "regdata": REG_DATA,
            "clientdata": CLIENT_DATA_HASH
        })
        idetail = token.get_init_detail()
        subject = idetail.get("u2fRegisterResponse").get("subject")
        self.assertEqual(subject, 'Yubico U2F EE Serial 13831167861')

        # check the tokeninfo of the attestation certificate
        issuer = token.get_tokeninfo("attestation_issuer")
        subject = token.get_tokeninfo("attestation_subject")
        serial = token.get_tokeninfo("attestation_serial")
        self.assertEqual(issuer, "CN=Yubico U2F Root CA Serial 457200631")
        self.assertEqual(subject, "CN=Yubico U2F EE Serial 13831167861")
        self.assertEqual(serial, "946265973")

        #
        # Do some authentication
        #

        # challenge
        # check challenge
        is_chalrequest = token.is_challenge_request(pin)
        self.assertEqual(is_chalrequest, True)

        # create challenge
        res, message, t_id, response = token.create_challenge()
        self.assertTrue(res)
        expected_text = _("Please confirm with your U2F token ({0!s})").format(
            "Yubico U2F EE Serial 13831167861")
        self.assertEqual(message, expected_text)
        self.assertEqual(len(t_id), 20)
        u2f_sign_request = response.get("u2fSignRequest")
        version = u2f_sign_request.get("version")
        self.assertEqual(version, "U2F_V2")
        key_handle = u2f_sign_request.get("keyHandle")
        key_handle_hex = hexlify_and_unicode(key_handle)
        self.assertTrue("appId" in u2f_sign_request, u2f_sign_request)
        self.assertTrue("challenge" in u2f_sign_request, u2f_sign_request)
        self.assertTrue("keyHandle" in u2f_sign_request, u2f_sign_request)
        self.assertEqual(key_handle_hex, KEY_HANDLE_HEX)
        self.assertEqual(u2f_sign_request.get("appId"), APP_ID)
        self.assertEqual(len(u2f_sign_request.get("challenge")), 43)
    def test_01_create_token(self):
        pin = "test"
        # Init step1
        token = init_token({"type": "u2f", "pin": pin})
        serial = token.token.serial

        self.assertEqual(token.type, "u2f")

        prefix = U2fTokenClass.get_class_prefix()
        self.assertEqual(prefix, "U2F")

        info = U2fTokenClass.get_class_info()
        self.assertEqual(info.get("type"), "u2f")

        info = U2fTokenClass.get_class_info("type")
        self.assertEqual(info, "u2f")

        idetail = token.get_init_detail()
        detail_serial = idetail.get("serial")
        self.assertEqual(serial, detail_serial)

        registerRequest = idetail.get("u2fRegisterRequest")
        version = registerRequest.get("version")
        self.assertEqual(version, "U2F_V2")
        challenge = registerRequest.get("challenge")
        self.assertEqual(len(challenge), 44)

        # Init step 2
        token = init_token({
            "type": "u2f",
            "serial": serial,
            "regdata": REG_DATA,
            "clientdata": CLIENT_DATA
        })
        idetail = token.get_init_detail()
        subject = idetail.get("u2fRegisterResponse").get("subject")
        self.assertEqual(subject, 'Yubico U2F EE Serial 13831167861')

        #
        # Do some authentication
        #

        # challenge
        # check challenge
        is_chalrequest = token.is_challenge_request(pin)
        self.assertEqual(is_chalrequest, True)

        # create challenge
        res, message, t_id, response = token.create_challenge()
        self.assertTrue(res)
        self.assertTrue("Please confirm with your U2F token" in message)
        self.assertEqual(len(t_id), 20)
        u2f_sign_request = response.get("u2fSignRequest")
        version = u2f_sign_request.get("version")
        self.assertEqual(version, "U2F_V2")
        key_handle = u2f_sign_request.get("keyHandle")
        key_handle_hex = binascii.hexlify(key_handle)
        self.assertTrue("appId" in u2f_sign_request, u2f_sign_request)
        self.assertTrue("challenge" in u2f_sign_request, u2f_sign_request)
        self.assertTrue("keyHandle" in u2f_sign_request, u2f_sign_request)
        self.assertEqual(key_handle_hex, KEY_HANDLE_HEX)
        self.assertEqual(u2f_sign_request.get("appId"), APP_ID)
        self.assertEqual(len(u2f_sign_request.get("challenge")), 43)
    def test_01_create_token(self):
        pin = "test"
        # Init step1
        token = init_token({"type": "u2f",
                            "pin": pin})
        serial = token.token.serial

        self.assertEqual(token.type, "u2f")

        prefix = U2fTokenClass.get_class_prefix()
        self.assertEqual(prefix, "U2F")

        info = U2fTokenClass.get_class_info()
        self.assertEqual(info.get("type"), "u2f")

        info = U2fTokenClass.get_class_info("type")
        self.assertEqual(info, "u2f")

        idetail = token.get_init_detail()
        detail_serial = idetail.get("serial")
        self.assertEqual(serial, detail_serial)

        registerRequest = idetail.get("u2fRegisterRequest")
        version = registerRequest.get("version")
        self.assertEqual(version, "U2F_V2")
        challenge = registerRequest.get("challenge")
        self.assertEqual(len(challenge), 44)

        # Init step 2
        token = init_token({"type": "u2f",
                            "serial": serial,
                            "regdata": REG_DATA,
                            "clientdata": CLIENT_DATA})
        idetail = token.get_init_detail()
        subject = idetail.get("u2fRegisterResponse").get("subject")
        self.assertEqual(subject, 'Yubico U2F EE Serial 13831167861')

        # check the tokeninfo of the attestation certificate
        issuer = token.get_tokeninfo("attestation_issuer")
        subject = token.get_tokeninfo("attestation_subject")
        serial = token.get_tokeninfo("attestation_serial")
        self.assertEqual(issuer, "CN=Yubico U2F Root CA Serial 457200631")
        self.assertEqual(subject, "CN=Yubico U2F EE Serial 13831167861")
        self.assertEqual(serial, "946265973")

        #
        # Do some authentication
        #

        # challenge
        # check challenge
        is_chalrequest = token.is_challenge_request(pin)
        self.assertEqual(is_chalrequest, True)

        # create challenge
        res, message, t_id, response = token.create_challenge()
        self.assertTrue(res)
        expected_text = _("Please confirm with your U2F token ({0!s})").format("Yubico U2F EE Serial 13831167861")
        self.assertEqual(message, expected_text)
        self.assertEqual(len(t_id), 20)
        u2f_sign_request = response.get("u2fSignRequest")
        version = u2f_sign_request.get("version")
        self.assertEqual(version, "U2F_V2")
        key_handle = u2f_sign_request.get("keyHandle")
        key_handle_hex = binascii.hexlify(key_handle)
        self.assertTrue("appId" in u2f_sign_request, u2f_sign_request)
        self.assertTrue("challenge" in u2f_sign_request, u2f_sign_request)
        self.assertTrue("keyHandle" in u2f_sign_request, u2f_sign_request)
        self.assertEqual(key_handle_hex, KEY_HANDLE_HEX)
        self.assertEqual(u2f_sign_request.get("appId"), APP_ID)
        self.assertEqual(len(u2f_sign_request.get("challenge")), 43)