Skip to content

Development #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Table of Contents
* [Encryption and Security](#encryption-and-security)
* [Databases](#databases)
* [Listing and Searching](#listing-and-searching)
* [Misc](#misc)
* [Export](#export)
* [Configuration](#configuration)
* [License](#license)
Expand Down Expand Up @@ -67,6 +68,7 @@ Usage

$ varuh -h


SYNOPSIS

varuh [options] [flags]
Expand All @@ -75,22 +77,26 @@ Usage

EDIT/CREATE ACTIONS:

-C --clone <id> Clone an entry
-U --use-db <path> Set as active database
-E --edit <id> Edit entry by id
-A --add Add a new entry
-I --init <path> Initialize a new database
-d --decrypt <path> Decrypt password database
-e --encrypt Encrypt the current database
-R --remove <id> Remove an entry
-e --encrypt Encrypt the current database
-d --decrypt <path> Decrypt password database
-C --clone <id> Clone an entry
-U --use-db <path> Set as active database
-E --edit <id> Edit entry by id

FIND/LIST ACTIONS:

-x --export <filename> Export all entries to <filename>
-a --list-all List all entries in current database
-p --path Show current database path
-f --find <term> Search entries
-l --list-entry <id> List entry by id
-x --export <filename> Export all entries to <filename>
-p --path Show current database path
-a --list-all List all entries in current database

MISC ACTIONS:

-g --genpass <length> Generate password of given length

HELP ACTIONS:

Expand All @@ -104,10 +110,10 @@ Usage


AUTHORS
Copyright (C) 2021 Anand B Pillai <[email protected]>
Copyright (C) 2021 Anand B Pillai <[email protected]>


The command line flags are grouped into `Edit/Create`, `Find/List` and `Help` actions. The first group of actions allows you to work with password databases and perform create/edit as well as encrypt/decrypt actions. The second set of actions allows you to work with an active decrypted database and view/search/list entries.
The command line flags are grouped into `Edit/Create`, `Find/List`, `Misc` and `Help` actions. The first group of actions allows you to work with password databases and perform create/edit as well as encrypt/decrypt actions. The second set of actions allows you to work with an active decrypted database and view/search/list entries.

Encryption and Security
=======================
Expand Down Expand Up @@ -439,6 +445,22 @@ If `pdftk` is installed, the PDF files will be encrypted with an (optional) pass
Added password to passwds.pdf.
Exported to passwds.pdf.

Misc
====

The following miscellaneous actions are supported.

Generate a secure password of given length.

$ varuh -g
7nhga7tkk9LNafz

By passing the `-c` option, the password is also copied to the clipboard.

$ varuh -g 15 -c
yeXlLlk??IOsvL6
Password copied to clipboard


Configuration
=============
Expand Down
2 changes: 1 addition & 1 deletion crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func decryptFileXChachaPoly(encDbPath string, password string) error {
func generateRandomPassword(length int) (error, string) {

var data []byte
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#!+$@~"
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?)(/%#!?)="

data = make([]byte, length)

Expand Down
29 changes: 27 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ package main

import (
"fmt"
"strconv"
getopt "github.com/pborman/getopt/v2"
"os"
)

const VERSION = 0.2
const APP = "varuh"
const AUTHOR_EMAIL = "Anand B Pillai <[email protected]>"
const AUTHOR_EMAIL = "Anand B Pillai <[email protected]>"

type actionFunc func(string) error
type actionFunc2 func(string) (error, string)
Expand All @@ -32,6 +33,30 @@ func printVersionInfo() error {
return nil
}

// Command-line wrapper to generateRandomPassword
func generatePassword(length string) (error, string) {
var iLength int
var err error
var passwd string

iLength, _ = strconv.Atoi(length)
err, passwd = generateRandomPassword(iLength)

if err != nil {
fmt.Printf("Error generating password - \"%s\"\n", err.Error())
return err, ""
}

fmt.Println(passwd)

if settingsRider.CopyPassword {
copyPasswordToClipboard(passwd)
fmt.Println("Password copied to clipboard")
}

return nil, passwd
}

// Perform an action by using the command line options map
func performAction(optMap map[string]interface{}, optionMap map[string]interface{}) {

Expand Down Expand Up @@ -59,6 +84,7 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface

stringActions2Map := map[string]actionFunc2{
"decrypt": decryptDatabase,
"genpass": generatePassword,
}

flagsActionsMap := map[string]voidFunc{
Expand All @@ -70,7 +96,6 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
for key, mappedFunc := range flagsActionsMap {
if *optMap[key].(*bool) {
mappedFunc()
break
}
}

Expand Down
18 changes: 15 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ OPTIONS

FIND/LIST ACTIONS:

%s

MISC ACTIONS:

%s

HELP ACTIONS:
Expand All @@ -53,6 +57,7 @@ func usageString(optMap map[string]interface{}) {
var findActions []string
var helpActions []string
var flagActions []string
var miscActions []string

var maxLen1 int
var maxLen2 int
Expand Down Expand Up @@ -95,12 +100,18 @@ func usageString(optMap map[string]interface{}) {
helpActions = append(helpActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help))
case 3:
flagActions = append(flagActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help))
case 4:
miscActions = append(miscActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help))
}
}

fmt.Println(fmt.Sprintf(HELP_STRING, APP, strings.Join(editActions, "\n"),
strings.Join(findActions, "\n"), strings.Join(helpActions, "\n"),
strings.Join(flagActions, "\n"), AUTHOR_EMAIL))
fmt.Println(fmt.Sprintf(HELP_STRING, APP,
strings.Join(editActions, "\n"),
strings.Join(findActions, "\n"),
strings.Join(miscActions, "\n"),
strings.Join(helpActions, "\n"),
strings.Join(flagActions, "\n"),
AUTHOR_EMAIL))

}

Expand All @@ -122,6 +133,7 @@ func initializeCommandLine() (map[string]interface{}, map[string]interface{}) {
{'E', "edit", "<id>", "Edit entry by id", 0},
{'l', "list-entry", "<id>", "List entry by id", 1},
{'x', "export", "<filename>", "Export all entries to <filename>", 1},
{'g', "genpass", "<length>", "Generate password of given length", 4},
}

for _, opt := range stringOptions {
Expand Down