keydb

package
v0.0.0-...-6d2d128 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: GPL-3.0 Imports: 16 Imported by: 3

Documentation

Overview

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

Index

Constants

View Source
const (
	DB_DIR_FILE_MODE = 0700
	DB_REC_FILE_MODE = 0600
)
View Source
const (
	CurrentRecordVersion = 2 // CurrentRecordVersion is the version of new database records to be created by cryptctl.
)

Variables

View Source
var RegexUUID = regexp.MustCompile("^[a-zA-Z0-9-]+$") // RegexUUID matches characters that are allowed in a UUID

Functions

func ValidateUUID

func ValidateUUID(in string) error

ValidateUUID returns an error only if the input string is empty, or if there are illegal characters among the input.

Types

type AliveMessage

type AliveMessage struct {
	Hostname  string // Hostname is the host name reported by client computer itself.
	IP        string // IP is the client computer's IP as seen by cryptctl server.
	Timestamp int64  // Timestamp is the moment the message arrived at cryptctl server.
}

AliveMessage is a component of key database record, it represents a heartbeat sent by a computer who is actively using an encryption key - i.e. the encrypted disk is currently unlocked and online.

type DB

type DB struct {
	Dir             string
	RecordsByUUID   map[string]Record // key is record UUID string
	RecordsByID     map[string]Record // when saved by built-in KMIP server, the ID is a sequence number; otherwise it can be anything.
	LastSequenceNum int64             // the last sequence number currently in-use
	Lock            *sync.RWMutex     // prevent concurrent access to records
}

The database of key records reside in a directory, each key record is serialised into a file. All key records are read into memory upon startup for fast retrieval. All exported functions are safe for concurrent usage.

func OpenDB

func OpenDB(dir string) (db *DB, err error)

Open a key database directory and read all key records into memory. Caller should consider to lock memory.

func OpenDBOneRecord

func OpenDBOneRecord(dir, recordUUID string) (db *DB, err error)

Open a key database directory but only load a single record into memory. If the specified record is not found in file system, an error is returned Caller should consider ot lock memory.

func (*DB) Erase

func (db *DB) Erase(uuid string) error

Erase a record from both memory and disk.

func (*DB) GetByID

func (db *DB) GetByID(id string) (rec Record, found bool)

Retrieve a key record by its KMIP ID.

func (*DB) GetByUUID

func (db *DB) GetByUUID(uuid string) (rec Record, found bool)

Retrieve a key record by its disk UUID.

func (*DB) List

func (db *DB) List() (sortedRecords RecordSlice)

Return all key records (not including key content) sorted according to latest usage.

func (*DB) ReadRecord

func (db *DB) ReadRecord(absPath string) (keyRecord Record, err error)

Read and deserialise a key record from file system.

func (*DB) ReloadDB

func (db *DB) ReloadDB() error

(Re)load database records.

func (*DB) ReloadRecord

func (db *DB) ReloadRecord(uuid string) error

ReloadRecord reads the latest record content corresponding to the UUID from disk file and loads it into memory. The function panics if the record version is not the latest.

func (*DB) Select

func (db *DB) Select(aliveMessage AliveMessage, checkMaxActive bool, uuids ...string) (found map[string]Record, rejected, missing []string)

Retrieve key records that belong to those UUIDs, and immediately persist last-retrieval information on those records.

func (*DB) UpdateAliveMessage

func (db *DB) UpdateAliveMessage(latest AliveMessage, uuids ...string) (rejected []string)

Record and immediately persist alive message that came from a host.

func (*DB) UpdateCommandResult

func (db *DB) UpdateCommandResult(uuid, ip string, content interface{}, result string)

UpdateCommandResult updates execution result of a pending command. The pending command is updated by looking for a command record matched to the specified UUID, IP, and content. If a matching record is not found, the function will do nothing.

func (*DB) UpdateSeenFlag

func (db *DB) UpdateSeenFlag(uuid, ip string, content interface{})

UpdateSeenFlag updates "seen" flag of a pending command to true. The flag is updated by looking for a command record matched to the specified IP, array index, and content. If a matching record is not found, the function will do nothing.

func (*DB) UpgradeRecord

func (db *DB) UpgradeRecord(record Record) error

Upgrade a record to the latest version.

func (*DB) UpgradeRecordToVersion1

func (db *DB) UpgradeRecordToVersion1(record Record) error

Record version 0 was the first version prior and equal to cryptctl 1.99 pre-release. Version number 1 gives each record a KMIP key ID, a creation time, and knows whether key content is located on external KMIP server.

func (*DB) Upsert

func (db *DB) Upsert(rec Record) (kmipID string, err error)

Create/update and immediately persist a key record. IO errors are returned and logged to stderr.