Skip to content

Commit a8a3ac3

Browse files
authored
Merge pull request #17 from pythonhacker/release
Release
2 parents dff7829 + bbe53fa commit a8a3ac3

File tree

7 files changed

+238
-244
lines changed

7 files changed

+238
-244
lines changed

README.md

+40-49
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ should work.
5050

5151
Then,
5252

53-
$ make
54-
go: downloading github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
55-
go: downloading github.com/pborman/getopt/v2 v2.1.0
56-
go: downloading golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
57-
go: downloading gorm.io/driver/sqlite v1.2.3
58-
...
53+
$ make
54+
Building varuh
55+
go: downloading github.com/akamensky/argparse v1.3.1
56+
go: downloading golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
57+
go: downloading github.com/atotto/clipboard v0.1.4
58+
go: downloading github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
59+
go: downloading github.com/pythonhacker/argparse v1.3.2
60+
go: downloading gorm.io/driver/sqlite v1.2.3
61+
...
5962

6063
$ sudo make install
6164
Installing varuh...done
@@ -66,55 +69,43 @@ The binary will be installed in `/usr/local/bin` folder.
6669
Usage
6770
=====
6871

69-
$ varuh -h
70-
71-
72-
SYNOPSIS
73-
74-
varuh [options] [flags]
75-
76-
OPTIONS
77-
78-
EDIT/CREATE ACTIONS:
79-
80-
-A --add Add a new entry
81-
-I --init <path> Initialize a new database
82-
-R --remove <id> Remove an entry
83-
-e --encrypt Encrypt the current database
84-
-d --decrypt <path> Decrypt password database
85-
-C --clone <id> Clone an entry
86-
-U --use-db <path> Set as active database
87-
-E --edit <id> Edit entry by id
88-
89-
FIND/LIST ACTIONS:
90-
91-
-f --find <term> Search entries
92-
-l --list-entry <id> List entry by id
93-
-x --export <filename> Export all entries to <filename>
94-
-p --path Show current database path
95-
-a --list-all List all entries in current database
96-
97-
MISC ACTIONS:
98-
99-
-g --genpass <length> Generate password of given length
100-
101-
HELP ACTIONS:
102-
103-
-h --help Print this help message and exit
104-
-v --version Show version information and exit
105-
106-
FLAGS:
107-
108-
-s --show Show passwords when listing entries
109-
-c --copy Copy password to clipboard
72+
$ ./varuh -h
73+
usage: varuh [-h|--help] [-I|--init "<value>"] [-d|--decrypt "<value>"]
74+
[-C|--clone "<value>"] [-R|--remove "<value>"] [-U|--use-db
75+
"<value>"] [-f|--find "<value>"] [-E|--edit "<value>"]
76+
[-l|--list-entry "<value>"] [-x|--export "<value>"] [-e|--encrypt]
77+
[-A|--add] [-p|--path] [-a|--list-all] [-g|--genpass] [-s|--show]
78+
[-c|--copy] [-v|--version]
79+
80+
Password manager for the command line for Unix like operating
81+
systems
82+
83+
Options:
84+
85+
-h --help Print help information
86+
-I --init <path> Initialize a new database
87+
-d --decrypt <path> Decrypt password database
88+
-C --clone <id> Clone an entry with <id>
89+
-R --remove <id> Remove an entry with <id>
90+
-U --use-db <path> Set <path> as active database
91+
-f --find <term> Search entries with <term>
92+
-E --edit <id> Edit entry by <id>
93+
-l --list-entry <id> List entry by <id>
94+
-x --export <filename> Export all entries to <filename>
95+
-e --encrypt Encrypt the current database
96+
-A --add Add a new entry
97+
-p --path Show current database path
98+
-a --list-all List all entries in current database
99+
-g --genpass Generate a strong password of length from 12 - 16
100+
-s --show Show passwords when listing entries
101+
-c --copy Copy password to clipboard
102+
-v --version Show version information and exit
110103

111104

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

115108

116-
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.
117-
118109
Encryption and Security
119110
=======================
120111

actions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func addNewEntry() error {
239239

240240
if len(passwd) == 0 {
241241
fmt.Printf("\nGenerating password ...")
242-
err, passwd = generateRandomPassword(16)
242+
err, passwd = generateStrongPassword()
243243
fmt.Printf("done")
244244
}
245245
// fmt.Printf("Password => %s\n", passwd)
@@ -315,7 +315,7 @@ func editCurrentEntry(idString string) error {
315315

316316
if strings.ToLower(passwd) == "y" {
317317
fmt.Printf("\nGenerating new password ...")
318-
err, passwd = generateRandomPassword(16)
318+
err, passwd = generateStrongPassword()
319319
}
320320
// fmt.Printf("Password => %s\n", passwd)
321321

crypto.go

+98-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
"golang.org/x/crypto/pbkdf2"
1414
"io"
1515
"math/big"
16+
"math/rand"
1617
"os"
18+
"time"
1719
"unsafe"
1820

1921
crand "crypto/rand"
@@ -435,10 +437,10 @@ func decryptFileXChachaPoly(encDbPath string, password string) error {
435437
}
436438

437439
// Generate a random password - for adding listings
438-
func generateRandomPassword(length int) (error, string) {
440+
func generatePassword(length int) (error, string) {
439441

440442
var data []byte
441-
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?)(/%#!?)="
443+
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=+_()$#@!~:/%"
442444

443445
data = make([]byte, length)
444446

@@ -453,3 +455,97 @@ func generateRandomPassword(length int) (error, string) {
453455

454456
return nil, string(data)
455457
}
458+
459+
// Generate a "strong" password
460+
// A strong password is defined as,
461+
// A mix of upper and lower case alphabets
462+
// at least one number [0-9]
463+
// at least one upper case alphabet [A-Z]
464+
// at least one punctuation character
465+
// at least length 12
466+
func generateStrongPassword() (error, string) {
467+
468+
var data []byte
469+
var length int
470+
471+
const sourceAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
472+
const sourceLargeAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
473+
const sourceNum = "0123456789"
474+
const sourcePunct = "=+_()$#@!~:/%"
475+
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=+_()$#@!~:/%"
476+
477+
// Generate in range 12 - 16
478+
rand.Seed(time.Now().UnixNano())
479+
480+
length = rand.Intn(4) + 12
481+
482+
data = make([]byte, length)
483+
484+
var lengthAlpha int
485+
var i, j, k, l int
486+
487+
// Alpha chars is at least length 3-5
488+
lengthAlpha = rand.Intn(2) + 3
489+
490+
for i = 0; i < lengthAlpha; i++ {
491+
num, err := crand.Int(crand.Reader, big.NewInt(int64(len(sourceAlpha))))
492+
if err != nil {
493+
return err, ""
494+
}
495+
496+
data[i] = sourceAlpha[num.Int64()]
497+
}
498+
499+
// Add in numbers 1 or 2
500+
var lengthNum int
501+
502+
lengthNum = rand.Intn(2) + 1
503+
504+
for j = i; j < i+lengthNum; j++ {
505+
num, err := crand.Int(crand.Reader, big.NewInt(int64(len(sourceNum))))
506+
if err != nil {
507+
return err, ""
508+
}
509+
510+
data[j] = sourceNum[num.Int64()]
511+
}
512+
513+
// Add in punctuations 1 or 2
514+
var lengthPunc int
515+
516+
lengthPunc = rand.Intn(2) + 1
517+
518+
for k = j; k < j+lengthPunc; k++ {
519+
num, err := crand.Int(crand.Reader, big.NewInt(int64(len(sourcePunct))))
520+
if err != nil {
521+
return err, ""
522+
}
523+
524+
data[k] = sourcePunct[num.Int64()]
525+
}
526+
527+
// Fill in the rest
528+
var lengthRem int
529+
530+
lengthRem = length - k
531+
532+
if lengthRem > 0 {
533+
for l = k; l < k+lengthRem; l++ {
534+
num, err := crand.Int(crand.Reader, big.NewInt(int64(len(source))))
535+
if err != nil {
536+
return err, ""
537+
}
538+
539+
data[l] = source[num.Int64()]
540+
}
541+
}
542+
543+
// Shuffle a few times
544+
for i = 0; i < 5; i++ {
545+
rand.Shuffle(len(data), func(i, j int) {
546+
data[i], data[j] = data[j], data[i]
547+
})
548+
}
549+
550+
return nil, string(data)
551+
}

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module varuh
33
go 1.16
44

55
require (
6+
github.com/akamensky/argparse v1.3.1
67
github.com/atotto/clipboard v0.1.4
78
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
8-
github.com/pborman/getopt/v2 v2.1.0
9+
github.com/pythonhacker/argparse v1.3.2
910
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
1011
gorm.io/driver/sqlite v1.2.3
1112
gorm.io/gorm v1.22.2

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g=
2+
github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
13
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
24
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -11,10 +13,10 @@ github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNq
1113
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0=
1214
github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA=
1315
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
14-
github.com/pborman/getopt/v2 v2.1.0 h1:eNfR+r+dWLdWmV8g5OlpyrTYHkhVNxHBdN2cCrJmOEA=
15-
github.com/pborman/getopt/v2 v2.1.0/go.mod h1:4NtW75ny4eBw9fO1bhtNdYTlZKYX5/tBLtsOpwKIKd0=
1616
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1717
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18+
github.com/pythonhacker/argparse v1.3.2 h1:JOojnYFHk7oap+MQiFgiPAHlzvhJfqukErLneWaHR/M=
19+
github.com/pythonhacker/argparse v1.3.2/go.mod h1:gdUstTr/g1ojhRwrF9gKFOVLwsNfwarBg8aCQRjtvo8=
1820
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1921
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
2022
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=

0 commit comments

Comments
 (0)