Exemplo n.º 1
0
def uri(ctx, uri, touch, force):
    """
    Add a new credential from URI.

    Use a URI to add a new credential to your YubiKey.
    """

    if not uri:
        while True:
            uri = click_prompt("Enter an OATH URI")
            try:
                uri = CredentialData.parse_uri(uri)
                break
            except Exception as e:
                click.echo(e)

    ensure_validated(ctx)
    data = uri

    # Steam is a special case where we allow the otpauth
    # URI to contain a 'digits' value of '5'.
    if data.digits == 5 and is_steam(data):
        data.digits = 6

    _add_cred(ctx, data, touch, force)
Exemplo n.º 2
0
    def test_parse_uri_issuer(self):
        no_issuer = CredentialData.parse_uri("otpauth://totp/account"
                                             "?secret=abba")
        self.assertIsNone(no_issuer.issuer)

        from_param = CredentialData.parse_uri("otpauth://totp/account"
                                              "?secret=abba&issuer=Test")
        self.assertEqual("Test", from_param.issuer)

        from_name = CredentialData.parse_uri("otpauth://totp/Test:account"
                                             "?secret=abba")
        self.assertEqual("Test", from_name.issuer)

        with_both = CredentialData.parse_uri("otpauth://totp/TestA:account"
                                             "?secret=abba&issuer=TestB")
        self.assertEqual("TestB", with_both.issuer)
Exemplo n.º 3
0
 def test_parse_uri(self):
     data = CredentialData.parse_uri("otpauth://totp/Issuer:account"
                                     "?secret=abba&issuer=Issuer"
                                     "&algorithm=SHA256&digits=7"
                                     "&period=20&counter=5")
     self.assertEqual(b"\0B", data.secret)
     self.assertEqual("Issuer", data.issuer)
     self.assertEqual("account", data.name)
     self.assertEqual(OATH_TYPE.TOTP, data.oath_type)
     self.assertEqual(HASH_ALGORITHM.SHA256, data.hash_algorithm)
     self.assertEqual(7, data.digits)
     self.assertEqual(20, data.period)
     self.assertEqual(5, data.counter)
Exemplo n.º 4
0
 def parse_qr(self, screenshot):
     data = b64decode(screenshot["data"])
     image = PixelImage(data, screenshot["width"], screenshot["height"])
     for qr in qrparse.parse_qr_codes(image, 2):
         try:
             return success(
                 credential_data_to_dict(
                     CredentialData.parse_uri(qrdecode.decode_qr_data(qr))
                 )
             )
         except Exception as e:
             logger.error("Failed to parse uri", exc_info=e)
             return failure("failed_to_parse_uri")
     return failure("no_credential_found")
Exemplo n.º 5
0
def uri(ctx, data, touch, force, password, remember):
    """
    Add a new account from an otpauth:// URI.

    Use a URI to add a new account to the YubiKey.
    """

    if not data:
        while True:
            uri = click_prompt("Enter an OATH URI")
            try:
                data = CredentialData.parse_uri(uri)
                break
            except Exception as e:
                click.echo(e)

    # Steam is a special case where we allow the otpauth
    # URI to contain a 'digits' value of '5'.
    if data.digits == 5 and is_steam(data):
        data.digits = 6

    _init_session(ctx, password, remember)
    _add_cred(ctx, data, touch, force)
Exemplo n.º 6
0
def click_parse_uri(ctx, param, val):
    try:
        return CredentialData.parse_uri(val)
    except ValueError:
        raise click.BadParameter("URI seems to have the wrong format.")