Exemplo n.º 1
0
    public int OnExecute()
    {
        var sess = _main.GetSession(skipLoad: true);

        using var client = sess.GetClient(skipCopyToClient: true);

        if (!sess.TryLoad(client))
        {
            return(1);
        }

        if (client.IsAccountLocked())
        {
            if (string.IsNullOrWhiteSpace(Password))
            {
                Password = Prompt.GetPassword("Master Password: ");
            }

            client.UnlockAccount(Password);

            sess.Save(client);
        }

        return(0);
    }
Exemplo n.º 2
0
    public async Task OnExecuteAsync()
    {
        if (string.IsNullOrWhiteSpace(Password))
        {
            Password = Prompt.GetPassword("Master Password: "******"Confirm Password: "******"passwords don't match");
            }
        }

        var sess = _main.GetSession(skipLoad: true);

        using var client = sess.GetClient();

        await client.CreateAccountAsync(Email !, Password);

        sess.Init(client);
        sess.Save();

        var sessKey = sess.SessionEnvVar;

        if (RawSession)
        {
            _console.WriteLine(sessKey);
        }
        else
        {
            _console.WriteLine($"$ export KYPR_SESSION = \"{sessKey}\"");
            _console.WriteLine($"> $env:KYPR_SESSION = \"{sessKey}\"");
        }
    }
Exemplo n.º 3
0
    public int OnExecute()
    {
        var sess = _main.GetSession(skipLoad: true);

        if (sess.TryLoad())
        {
            sess.Delete();
        }

        _console.WriteLine("Local Session has been deleted, you can optionally clear your environment:");
        _console.WriteLine($"$ export KYPR_SESSION = \"\"");
        _console.WriteLine($"> $env:KYPR_SESSION = \"\"");
        return(0);
    }
Exemplo n.º 4
0
    public async Task <int> OnExecuteAsync()
    {
        var sess = _main.GetSession();

        using var client = sess.GetClient();

        var vault = await client.CreateVaultAsync(Label !);

        sess.Save(client);

        _console.WriteLine(vault.Id !);

        return(0);
    }
Exemplo n.º 5
0
    public int OnExecute()
    {
        var sess = _main.GetSession(skipLoad: true);

        using var client = sess.GetClient(skipCopyToClient: true);

        if (sess.TryLoad(client))
        {
            client.LockAccount();
            sess.Save(client);
            return(0);
        }

        return(1);
    }
Exemplo n.º 6
0
    public async Task OnExecuteAsync()
    {
        if (string.IsNullOrWhiteSpace(Password))
        {
            Password = Prompt.GetPassword("Master Password: "******"$ export KYPR_SESSION = \"{sessKey}\"");
        _console.WriteLine($"> $env:KYPR_SESSION = \"{sessKey}\"");
    }
Exemplo n.º 7
0
    public async Task <int> OnExecuteAsync()
    {
        var sess = _main.GetSession();

        using var client = sess.GetClient();

        var vault = _main.GetVault(client, Vault !);

        if (vault == null)
        {
            return(1);
        }

        client.UnlockVault(vault);
        vault.Summary !.Label = Label;
        await client.SaveVaultAsync(vault);

        sess.Save(client);

        _console.WriteLine(vault.Id !);

        return(0);
    }
Exemplo n.º 8
0
    public void OnExecute()
    {
        var sess = _main.GetSession(skipLoad: true);

        using var client = sess.GetClient(skipCopyToClient: true);

        if (!sess.TryLoad(client))
        {
            _console.WriteLine("none");
        }
        else if (sess.Details?.ServerSession == null ||
                 sess.Details.Account == null)
        {
            _console.WriteLine("session-locked");
        }
        else if (client.IsAccountLocked())
        {
            _console.WriteLine("account-locked");
        }
        else
        {
            _console.WriteLine("unlocked");
        }
    }
Exemplo n.º 9
0
    public int OnExecute()
    {
        var sess = _main.GetSession();

        using var client = sess.GetClient();

        var vault = Vault == null
            ? null
            : _main.GetVault(client, Vault !);

        if (vault == null && Vault != null)
        {
            return(1);
        }

        var record = _main.GetRecord(client, ref vault, Record !);

        if (record == null)
        {
            return(1);
        }

        client.UnlockRecord(vault !, record);

        string?totpConfig = null;
        string?totpSeed   = null;

        if (record.Content !.Fields != null)
        {
            totpConfig = record.Content.Fields.FirstOrDefault(x =>
                                                              object.Equals(TotpConfigFieldName, x.Name))?.Value;
            totpSeed = record.Content.Fields.FirstOrDefault(x =>
                                                            object.Equals(TotpSeedFieldName, x.Name))?.Value;
        }

        if (totpConfig == null || totpSeed == null)
        {
            _console.WriteError("record is not configured for OTP generation");
            return(1);
        }

        var totpConfigParts = totpConfig.Split(';');

        if (totpConfigParts.Length < 3 || totpConfigParts[0] != TotpConfigVersion)
        {
            _console.WriteError("TOTP configuration is invalid or incompatible");
            return(1);
        }

        if (!int.TryParse(totpConfigParts[1], out var totpStep) ||
            !int.TryParse(totpConfigParts[2], out var totpSize))
        {
            _console.WriteError("TOTP configuration is malformed");
            return(1);
        }

        totpSeed = totpSeed.Replace(" ", "");
        var totpKey = Base32Encoding.ToBytes(totpSeed);
        var totp    = new Totp(totpKey, step: totpStep, totpSize: totpSize);

        _console.WriteLine(totp.ComputeTotp());

        return(0);
    }