core

package
v0.0.0-...-2667b67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2017 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Alphas []Alphabet = []Alphabet{

	Alphabet{
		"[0-9]",
		"0123456789",
	},

	Alphabet{
		"[a-zA-Z]",
		"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
	},

	Alphabet{
		"[a-zA-Z0-9]",
		"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
	},

	Alphabet{
		"[a-zA-Z0-9!&()*+,-./?[]~]",
		"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!&()*+,-./?[]~",
	},

	Alphabet{
		"[a-zA-Z0-9 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]",
		"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]",
	},
}

Alphas contains all the pre-defined alphabets.

Functions

This section is empty.

Types

type Alphabet

type Alphabet struct {
	// String to display on the prompt
	Display string
	// contains filtered or unexported fields
}

An Alphabet abstract the character set from which the password will be randomly created.

func (Alphabet) GenPassword

func (a Alphabet) GenPassword(n int) string

GenPassword creates a random password of given length, using Golang's cryptographically secure PRNG (which is just a wrapper around your OS's cryptographically secure PRNG, so if you find a problem of randomness in it, that's something you can be proud of).

type PasswordTranscoder

type PasswordTranscoder interface {
	// DecodePassword takes an encoded password as an input, and decode if then decypts it.
	DecodePassword(pass string) ([]byte, error)
	// EncodePassword takes a password as an input, and encrypts then encode it to printable characters. If an error occurs, it should raise it.
	EncodePassword(pass string) ([]byte, error)
}

Interface to be implemented for an encryption and encoding scheme

func NewTranscoder

func NewTranscoder(s string) PasswordTranscoder

type Storage

type Storage struct {
	// Passphrase of the user. That's a bcrypt hash.
	Passphrase string `json:"Pass"`
	// The different sections of the file. The format is the following:
	//     - section_name_1:
	//         * pass_name_1: encrypted_pass_1
	//         * pass_name_2: encrypted_pass_2
	//     - section_name_2:
	//         * pass_name_1: encrypted_pass_1
	//         * pass_name_2: encrypted_pass_2
	Sections map[string]map[string]string `json:"Sections"`
}

Storage is used to keep track of both the user master file

func GetStorage

func GetStorage() (*Storage, error)

GetStorage reads the master file, and creates the matching storage object if possible. If not, an error is raised (invalid permissions, non-existent file, wrong formatting, etc ...

func InitPassphrase

func InitPassphrase(new []byte) *Storage

InitPassphrase creates a new storage with given passphrase

func (*Storage) AddSection

func (s *Storage) AddSection(section string) error

AddSection adds a section to the storage.

func (*Storage) CheckPassphrase

func (s *Storage) CheckPassphrase(pass string) error

CheckPassphrase verifies the given passphrase against the stored hash using bcrypt's hash function.

func (*Storage) DumpOnDisk

func (s *Storage) DumpOnDisk() error

Saves the file on the disk, raises an error if necessary with JSON formatting

func (*Storage) Get

func (s *Storage) Get(section string, password string) (string, error)

Get retrieves an encrypted password from the storage. If the section or the password do not exist, an error is raised.

func (*Storage) ListAll

func (s *Storage) ListAll() map[string][]string

List all lists all the sections and their passwords from the storage.

func (*Storage) ListPasswords

func (s *Storage) ListPasswords(section string) []string

ListPasswords lists all the password contained in the section.

func (*Storage) ListSections

func (s *Storage) ListSections() []string

ListSections retrieves all the sections from the storage.

func (*Storage) Set

func (s *Storage) Set(section string, password string, data string)

Set puts a new encrypted password on the storage. Be extra-careful, it does not actually encrypts and encode it.

func (*Storage) SetNewPassphrase

func (s *Storage) SetNewPassphrase(old string, new string) error

SetNewPassphrase changes from the old passphrase to the new one. It checks for validity of the old one first, then decrypts all passwords and re-encrypts them with the new passphrase. If there is an error during this operation, nothing is comitted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL