app

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Copyright © 2024-2025 Thomas von Dein

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	ArgonMem      uint32 = 64 * 1024
	ArgonIter     uint32 = 5
	ArgonParallel uint8  = 2
	ArgonSaltLen  int    = 16
	ArgonKeyLen   uint32 = 32
	B64SaltLen    int    = 16 //22
)
View Source
const BucketData string = "data"
View Source
const MaxValueWidth int = 60

Variables

View Source
var File_app_dbentry_proto protoreflect.FileDescriptor

Functions

func AskForPassword

func AskForPassword() ([]byte, error)

called from interactive thread, hides input and returns clear text password

func Decrypt

func Decrypt(pass []byte, cipherb []byte) ([]byte, error)

Do the reverse

func Encrypt

func Encrypt(pass []byte, attr *DbAttr) error

Encrypt clear text given in attr using ChaCha20 and auhtenticate using the mac Poly1305. The cipher text will be put into attr, thus modifying it.

The cipher text consists of: password-salt) + (12 byte nonce + ciphertext + 16 byte mac)

func Exists

func Exists[K comparable, V any](m map[K]V, v K) bool

look if a key in a map exists, generic variant

func GetDbFile

func GetDbFile(file string) string

func GetRandom

func GetRandom(size int, capacity int) ([]byte, error)

Retrieve a random chunk of given size

Types

type BucketInfo

type BucketInfo struct {
	Name     string
	Keys     int
	Size     int
	Sequence uint64
	Stats    bolt.BucketStats
}

type DB

type DB struct {
	Debug  bool
	Dbfile string
	Bucket string
	DB     *bolt.DB
}

func New

func New(file string, bucket string, debug bool) (*DB, error)

func (*DB) Close

func (db *DB) Close()

func (*DB) Del

func (db *DB) Del(attr *DbAttr) error

func (*DB) Get

func (db *DB) Get(attr *DbAttr) (*DbEntry, error)

func (*DB) Getall

func (db *DB) Getall(attr *DbAttr) (DbEntries, error)

func (*DB) Import

func (db *DB) Import(attr *DbAttr) (string, error)

func (*DB) Info

func (db *DB) Info() (*DbInfo, error)

func (*DB) List

func (db *DB) List(attr *DbAttr, fulltext bool) (DbEntries, error)

func (*DB) Open

func (db *DB) Open() error

func (*DB) Set

func (db *DB) Set(attr *DbAttr) error

type DbAttr

type DbAttr struct {
	Key       string
	Preview   string
	Val       []byte
	Data      string // alias
	Args      []string
	Tags      []string
	File      string
	Encrypted bool
	Binary    bool

	// conf flags, needed for incoming rest requests
	Fulltext bool
}

func (*DbAttr) GetFileValue

func (attr *DbAttr) GetFileValue() error

func (*DbAttr) ParseKV

func (attr *DbAttr) ParseKV() error

check if value is to be read from a file or stdin, setup preview text according to flags, lowercase key

func (*DbAttr) SetPreview

func (attr *DbAttr) SetPreview()

type DbEntries

type DbEntries []*DbEntry

type DbEntry

type DbEntry struct {
	Id        string                 `protobuf:"bytes,1,opt,name=Id,proto3" json:"Id,omitempty"`
	Key       string                 `protobuf:"bytes,2,opt,name=Key,proto3" json:"Key,omitempty"`
	Preview   string                 `protobuf:"bytes,3,opt,name=Preview,proto3" json:"Preview,omitempty"`
	Tags      []string               `protobuf:"bytes,4,rep,name=Tags,proto3" json:"Tags,omitempty"`
	Created   *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=Created,proto3" json:"Created,omitempty"`
	Size      uint64                 `protobuf:"varint,6,opt,name=Size,proto3" json:"Size,omitempty"`
	Encrypted bool                   `protobuf:"varint,7,opt,name=Encrypted,proto3" json:"Encrypted,omitempty"`
	Binary    bool                   `protobuf:"varint,8,opt,name=Binary,proto3" json:"Binary,omitempty"`
	Value     string                 `protobuf:"bytes,9,opt,name=Value,proto3" json:"Value,omitempty"`
	// contains filtered or unexported fields
}

func (*DbEntry) Descriptor deprecated

func (*DbEntry) Descriptor() ([]byte, []int)

Deprecated: Use DbEntry.ProtoReflect.Descriptor instead.

func (*DbEntry) GetBinary

func (x *DbEntry) GetBinary() bool

func (*DbEntry) GetCreated

func (x *DbEntry) GetCreated() *timestamppb.Timestamp

func (*DbEntry) GetEncrypted

func (x *DbEntry) GetEncrypted() bool

func (*DbEntry) GetId

func (x *DbEntry) GetId() string

func (*DbEntry) GetKey

func (x *DbEntry) GetKey() string

func (*DbEntry) GetPreview

func (x *DbEntry) GetPreview() string

func (*DbEntry) GetSize

func (x *DbEntry) GetSize() uint64

func (*DbEntry) GetTags

func (x *DbEntry) GetTags() []string

func (*DbEntry) GetValue

func (x *DbEntry) GetValue() string

func (*DbEntry) ProtoMessage

func (*DbEntry) ProtoMessage()

func (*DbEntry) ProtoReflect

func (x *DbEntry) ProtoReflect() protoreflect.Message

func (*DbEntry) Reset

func (x *DbEntry) Reset()

func (*DbEntry) String

func (x *DbEntry) String() string

func (*DbEntry) Taglist

func (entry *DbEntry) Taglist() string

type DbInfo

type DbInfo struct {
	Buckets []BucketInfo
	Path    string
}

type DbTag

type DbTag struct {
	Keys []string `json:"key"`
}

type Key

type Key struct {
	Salt []byte
	Key  []byte
}

func DeriveKey

func DeriveKey(password []byte, salt []byte) (*Key, error)

We're using the Argon2id key derivation algorithm to derive a secure key from the given password. This is important, because users might use unsecure passwords. The resulting encrypted data might of course easily be decrypted using brute force methods if a weak password was used, but that would cost, because of the key derivation. It does several rounds of hash calculations which take a considerable amount of cpu time. For our legal user that's no problem because it's being executed only once, but an attacker has to do it in a forever loop, which will take a lot of time.

Jump to

Keyboard shortcuts

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