Пример #1
0
    def get_init_detail(self, params=None, user=None):
        """
        At the end of the initialization we ask the user to press the button
        """
        response_detail = {}
        if self.init_step == 1:
            # This is the first step of the init request
            app_id = get_from_config("u2f.appId", "").strip("/")
            from privacyidea.lib.error import TokenAdminError
            if not app_id:
                raise TokenAdminError(_("You need to define the appId in the "
                                        "token config!"))
            nonce = urlsafe_b64encode_and_unicode(geturandom(32))
            response_detail = TokenClass.get_init_detail(self, params, user)
            register_request = {"version": U2F_Version,
                                "challenge": nonce,
                                "appId": app_id}
            response_detail["u2fRegisterRequest"] = register_request
            self.add_tokeninfo("appId", app_id)

        elif self.init_step == 2:
            # This is the second step of the init request
            response_detail["u2fRegisterResponse"] = {"subject":
                                                          self.token.description}

        return response_detail
Пример #2
0
    def get_init_detail(self, params=None, user=None):
        """
        At the end of the initialization we ask the user to press the button
        """
        response_detail = {}
        if self.init_step == 1:
            # This is the first step of the init request
            app_id = get_from_config("u2f.appId", "").strip("/")
            from privacyidea.lib.error import TokenAdminError
            if not app_id:
                raise TokenAdminError(
                    _("You need to define the appId in the "
                      "token config!"))
            nonce = urlsafe_b64encode_and_unicode(geturandom(32))
            response_detail = TokenClass.get_init_detail(self, params, user)
            register_request = {
                "version": U2F_Version,
                "challenge": nonce,
                "appId": app_id
            }
            response_detail["u2fRegisterRequest"] = register_request
            self.add_tokeninfo("appId", app_id)

        elif self.init_step == 2:
            # This is the second step of the init request
            response_detail["u2fRegisterResponse"] = {
                "subject": self.token.description
            }

        return response_detail
Пример #3
0
def url_encode(data):
    """
    Encodes a string base64 websafe and omits trailing padding "=".
    :param data: Some string
    :return: websafe b64 encoded string
    """
    url = urlsafe_b64encode_and_unicode(data)
    return url.strip("=")
Пример #4
0
def url_encode(data):
    """
    Encodes a string base64 websafe and omits trailing padding "=".
    :param data: Some string
    :return: websafe b64 encoded string
    """
    url = urlsafe_b64encode_and_unicode(data)
    return url.strip("=")
Пример #5
0
    def test_26_conversions(self):
        self.assertEquals(hexlify_and_unicode(u'Hallo'), u'48616c6c6f')
        self.assertEquals(hexlify_and_unicode(b'Hallo'), u'48616c6c6f')
        self.assertEquals(hexlify_and_unicode(b'\x00\x01\x02\xab'), u'000102ab')

        self.assertEquals(b32encode_and_unicode(u'Hallo'), u'JBQWY3DP')
        self.assertEquals(b32encode_and_unicode(b'Hallo'), u'JBQWY3DP')
        self.assertEquals(b32encode_and_unicode(b'\x00\x01\x02\xab'), u'AAAQFKY=')

        self.assertEquals(b64encode_and_unicode(u'Hallo'), u'SGFsbG8=')
        self.assertEquals(b64encode_and_unicode(b'Hallo'), u'SGFsbG8=')
        self.assertEquals(b64encode_and_unicode(b'\x00\x01\x02\xab'), u'AAECqw==')

        self.assertEquals(urlsafe_b64encode_and_unicode(u'Hallo'), u'SGFsbG8=')
        self.assertEquals(urlsafe_b64encode_and_unicode(b'Hallo'), u'SGFsbG8=')
        self.assertEquals(urlsafe_b64encode_and_unicode(b'\x00\x01\x02\xab'), u'AAECqw==')
        self.assertEquals(urlsafe_b64encode_and_unicode(b'\xfa\xfb\xfc\xfd\xfe\xff'),
                          u'-vv8_f7_')
Пример #6
0
    def test_26_conversions(self):
        self.assertEquals(hexlify_and_unicode(u'Hallo'), u'48616c6c6f')
        self.assertEquals(hexlify_and_unicode(b'Hallo'), u'48616c6c6f')
        self.assertEquals(hexlify_and_unicode(b'\x00\x01\x02\xab'), u'000102ab')

        self.assertEquals(b32encode_and_unicode(u'Hallo'), u'JBQWY3DP')
        self.assertEquals(b32encode_and_unicode(b'Hallo'), u'JBQWY3DP')
        self.assertEquals(b32encode_and_unicode(b'\x00\x01\x02\xab'), u'AAAQFKY=')

        self.assertEquals(b64encode_and_unicode(u'Hallo'), u'SGFsbG8=')
        self.assertEquals(b64encode_and_unicode(b'Hallo'), u'SGFsbG8=')
        self.assertEquals(b64encode_and_unicode(b'\x00\x01\x02\xab'), u'AAECqw==')

        self.assertEquals(urlsafe_b64encode_and_unicode(u'Hallo'), u'SGFsbG8=')
        self.assertEquals(urlsafe_b64encode_and_unicode(b'Hallo'), u'SGFsbG8=')
        self.assertEquals(urlsafe_b64encode_and_unicode(b'\x00\x01\x02\xab'), u'AAECqw==')
        self.assertEquals(urlsafe_b64encode_and_unicode(b'\xfa\xfb\xfc\xfd\xfe\xff'),
                          u'-vv8_f7_')