Documentation ¶
Index ¶
- type CertService
- type CertServiceImpl
- func (cs *CertServiceImpl) AddCert(cert model.EncKey) error
- func (cs *CertServiceImpl) CountCerts() (int, error)
- func (cs *CertServiceImpl) GetCert(name string) (*model.EncKey, error)
- func (cs *CertServiceImpl) LoadCerts(pwd string) error
- func (cs *CertServiceImpl) RemoveCert(name string) error
- func (cs *CertServiceImpl) SaveCerts(pwd string) error
- type ConfigService
- type ConfigServiceImpl
- func (c *ConfigServiceImpl) GetConfig(key string) (string, error)
- func (c *ConfigServiceImpl) GetConfigBytes(key string) ([]byte, error)
- func (c *ConfigServiceImpl) GetGlobal(key string) (string, error)
- func (c *ConfigServiceImpl) GetGlobalBytes(key string) ([]byte, error)
- func (c *ConfigServiceImpl) GetResourcePath() string
- func (c *ConfigServiceImpl) LoadConfig() error
- func (c *ConfigServiceImpl) ParseConfigTree(configTree *toml.Tree)
- func (c *ConfigServiceImpl) SaveConfig() error
- func (c *ConfigServiceImpl) SetConfig(key string, value string) error
- func (c *ConfigServiceImpl) SetConfigBytes(key string, value []byte) error
- func (c *ConfigServiceImpl) SetGlobal(key string, value string)
- func (c *ConfigServiceImpl) SetGlobalBytes(key string, value []byte)
- type CryptoService
- type CryptoServiceAES
- func (cs *CryptoServiceAES) Decrypt(ciphertext []byte) ([]byte, error)
- func (cs *CryptoServiceAES) Encrypt(plaintext []byte) ([]byte, error)
- func (cs *CryptoServiceAES) GetAlgorithm() string
- func (cs *CryptoServiceAES) GetKeyManager() KeyManagementService
- func (cs *CryptoServiceAES) Sign(plaintext []byte) ([]byte, error)
- func (cs *CryptoServiceAES) Verify(plaintext, signature []byte) error
- type CryptoServiceFactory
- type CryptoServiceFactoryImpl
- type CryptoServiceRSAImpl
- func (cs *CryptoServiceRSAImpl) Decrypt(ciphertext []byte) ([]byte, error)
- func (cs *CryptoServiceRSAImpl) Encrypt(plaintext []byte) ([]byte, error)
- func (cs *CryptoServiceRSAImpl) GetAlgorithm() string
- func (cs *CryptoServiceRSAImpl) GetKeyManager() KeyManagementService
- func (cs *CryptoServiceRSAImpl) Sign(plaintext []byte) ([]byte, error)
- func (cs *CryptoServiceRSAImpl) Verify(plaintext, signature []byte) error
- type KeyManagementService
- type KeyManagementServiceAES
- func (kms *KeyManagementServiceAES) GenerateKey() ([]byte, error)
- func (kms *KeyManagementServiceAES) GetCertificate() model.EncKey
- func (kms *KeyManagementServiceAES) GetPrivateKey() ([]byte, error)
- func (kms *KeyManagementServiceAES) GetPublicKey() ([]byte, error)
- func (kms *KeyManagementServiceAES) ImportKey(key []byte, keyName string) error
- type KeyManagementServiceRSAImpl
- func (kms *KeyManagementServiceRSAImpl) GenerateKey() ([]byte, error)
- func (kms *KeyManagementServiceRSAImpl) GetCertificate() model.EncKey
- func (kms *KeyManagementServiceRSAImpl) GetPrivateKey() ([]byte, error)
- func (kms *KeyManagementServiceRSAImpl) GetPublicKey() ([]byte, error)
- func (kms *KeyManagementServiceRSAImpl) ImportKey(key []byte, keyName string) error
- type NoteService
- type NoteServiceImpl
- func (ns *NoteServiceImpl) CreateNote(note *model.Note) error
- func (ns *NoteServiceImpl) DecryptNote(note *model.Note) error
- func (ns *NoteServiceImpl) DeleteNote(id int) error
- func (ns *NoteServiceImpl) EncryptNote(note *model.Note) error
- func (ns *NoteServiceImpl) GetNoteIDFromTitle(title string) int
- func (ns *NoteServiceImpl) GetNoteWithContent(id int) (*model.Note, error)
- func (ns *NoteServiceImpl) GetNotes() ([]model.Note, error)
- func (ns *NoteServiceImpl) GetTitles() []string
- func (ns *NoteServiceImpl) ReEncryptNotes(notes []model.Note, cert model.EncKey) error
- func (ns *NoteServiceImpl) SaveEncryptedNotes(notes []model.Note) error
- func (ns *NoteServiceImpl) SearchNotes(query string, fuzzySearch bool) ([]string, error)
- func (ns *NoteServiceImpl) UpdateNoteContent(note *model.Note) error
- func (ns *NoteServiceImpl) UpdateNoteTitle(oldTitle, newTitle string) (noteID int, err error)
- type NoteServiceRepository
- type NoteServiceRepositoryImpl
- func (nsr *NoteServiceRepositoryImpl) CreateNote(note *model.Note) error
- func (nsr *NoteServiceRepositoryImpl) DeleteNote(id int) error
- func (nsr *NoteServiceRepositoryImpl) GetAllNotes() ([]model.Note, error)
- func (nsr *NoteServiceRepositoryImpl) GetIDFromTitle(title string) int
- func (nsr *NoteServiceRepositoryImpl) GetNote(id int) (*model.Note, error)
- func (nsr *NoteServiceRepositoryImpl) NoteExists(id int) (bool, error)
- func (nsr *NoteServiceRepositoryImpl) UpdateNote(note *model.Note) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CertService ¶
type CertServiceImpl ¶
type CertServiceImpl struct { Keys map[string]model.EncKey KeysMutex *sync.Mutex Loaded bool KeysFilePath string }
func NewCertService ¶
func NewCertService(keysFilePath string) *CertServiceImpl
NewCertService creates new CertService
func (*CertServiceImpl) AddCert ¶
func (cs *CertServiceImpl) AddCert(cert model.EncKey) error
AddCert adds cert to map
func (*CertServiceImpl) CountCerts ¶
func (cs *CertServiceImpl) CountCerts() (int, error)
CountCerts returns number of certs in certificate store
func (*CertServiceImpl) GetCert ¶
func (cs *CertServiceImpl) GetCert(name string) (*model.EncKey, error)
GetCert returns cert by name
func (*CertServiceImpl) LoadCerts ¶
func (cs *CertServiceImpl) LoadCerts(pwd string) error
LoadCerts loads certs from file, decrypts them and adds them to map
func (*CertServiceImpl) RemoveCert ¶
func (cs *CertServiceImpl) RemoveCert(name string) error
RemoveCert removes cert from map
func (*CertServiceImpl) SaveCerts ¶
func (cs *CertServiceImpl) SaveCerts(pwd string) error
SaveCerts saves certs to file, encrypts them and writes them to file
type ConfigService ¶
type ConfigService interface { GetResourcePath() string GetGlobal(key string) (string, error) GetGlobalBytes(key string) ([]byte, error) SetGlobal(key string, value string) SetGlobalBytes(key string, value []byte) GetConfig(key string) (string, error) GetConfigBytes(key string) ([]byte, error) SetConfig(key string, value string) error SetConfigBytes(key string, value []byte) error LoadConfig() error ParseConfigTree(configTree *toml.Tree) SaveConfig() error }
ConfigService ....
type ConfigServiceImpl ¶
type ConfigServiceImpl struct { ResourcePath string Config map[string]string // configuration from config file Globals map[string]string // global variables (loaded in memory only) Loaded bool ConfigMux *sync.RWMutex GlobalsMux *sync.RWMutex }
ConfigServiceImpl ....
func (*ConfigServiceImpl) GetConfig ¶
func (c *ConfigServiceImpl) GetConfig(key string) (string, error)
GetConfig return the value of the given key from the config map
func (*ConfigServiceImpl) GetConfigBytes ¶
func (c *ConfigServiceImpl) GetConfigBytes(key string) ([]byte, error)
GetGlobalBytes same as above, for byte arrays
func (*ConfigServiceImpl) GetGlobal ¶
func (c *ConfigServiceImpl) GetGlobal(key string) (string, error)
GetGlobal ....
func (*ConfigServiceImpl) GetGlobalBytes ¶
func (c *ConfigServiceImpl) GetGlobalBytes(key string) ([]byte, error)
GetGlobalBytes same as above, for byte arrays
func (*ConfigServiceImpl) GetResourcePath ¶
func (c *ConfigServiceImpl) GetResourcePath() string
GetResourcePath ....
func (*ConfigServiceImpl) LoadConfig ¶
func (c *ConfigServiceImpl) LoadConfig() error
LoadConfig loads the config from the config file. * * This function is thread safe.
LoadConfig ....
func (*ConfigServiceImpl) ParseConfigTree ¶
func (c *ConfigServiceImpl) ParseConfigTree(configTree *toml.Tree)
ParseConfigTree ....
func (*ConfigServiceImpl) SaveConfig ¶
func (c *ConfigServiceImpl) SaveConfig() error
SaveConfig ....
func (*ConfigServiceImpl) SetConfig ¶
func (c *ConfigServiceImpl) SetConfig(key string, value string) error
SetConfig ....
func (*ConfigServiceImpl) SetConfigBytes ¶
func (c *ConfigServiceImpl) SetConfigBytes(key string, value []byte) error
SetConfigBytes same as above, for byte arrays note: the byte array is encoded as hexadecimal string
func (*ConfigServiceImpl) SetGlobal ¶
func (c *ConfigServiceImpl) SetGlobal(key string, value string)
SetGlobal ....
func (*ConfigServiceImpl) SetGlobalBytes ¶
func (c *ConfigServiceImpl) SetGlobalBytes(key string, value []byte)
SetGlobalBytes same as above, for byte arrays
type CryptoService ¶
type CryptoService interface { // Encrypt encrypt plaintext Encrypt(plaintext []byte) ([]byte, error) // Decrypt decrypt ciphertext Decrypt(ciphertext []byte) ([]byte, error) // Sign sign plaintext Sign(plaintext []byte) ([]byte, error) // Verify verify signature Verify(plaintext, signature []byte) error // GetKeyManager get the key management service GetKeyManager() KeyManagementService // GetAlgorithm get the algorithm GetAlgorithm() string }
CryptoService interface for crypto service implementation (encryption, signing, etc)
func NewCryptoServiceAES ¶
func NewCryptoServiceAES(keyManagementService KeyManagementService) CryptoService
NewCryptoServiceAES the crypto service interface using the AES key generation scheme
func NewCryptoServiceFactory ¶
func NewCryptoServiceFactory(algorithm string) CryptoService
NewCrytpServiceFactory create a new crypto service bases on the given key management service and algorithm and inject it into the CryptoServiceImpl
func NewCryptoServiceRSA ¶
func NewCryptoServiceRSA(keyManagementService KeyManagementService) CryptoService
NewCryptoServiceRSA NewCryptoServiceRSA implement the crypto service interface using the key management service and RSA OAEP encryption scheme
type CryptoServiceAES ¶
type CryptoServiceAES struct {
// contains filtered or unexported fields
}
CryptoServiceAES interface for crypto service implementation (encryption, signing, etc)
func (*CryptoServiceAES) Decrypt ¶
func (cs *CryptoServiceAES) Decrypt(ciphertext []byte) ([]byte, error)
Decrypt ciphertext
func (*CryptoServiceAES) Encrypt ¶
func (cs *CryptoServiceAES) Encrypt(plaintext []byte) ([]byte, error)
Encrypt plaintext using AES encryption
func (*CryptoServiceAES) GetAlgorithm ¶
func (cs *CryptoServiceAES) GetAlgorithm() string
GetAlgorithm get the algorithm name
func (*CryptoServiceAES) GetKeyManager ¶
func (cs *CryptoServiceAES) GetKeyManager() KeyManagementService
GetKeyManager get the key management service
func (*CryptoServiceAES) Sign ¶
func (cs *CryptoServiceAES) Sign(plaintext []byte) ([]byte, error)
Sign This method always return err because signing is proper of public key cryptography and not of symmetric cryptography
func (*CryptoServiceAES) Verify ¶
func (cs *CryptoServiceAES) Verify(plaintext, signature []byte) error
Verify This method always return err because signing is proper of public key cryptography and not of symmetric cryptography
type CryptoServiceFactory ¶
type CryptoServiceFactory interface { GetSrv() CryptoService SetSrv(srv CryptoService) }
type CryptoServiceFactoryImpl ¶
type CryptoServiceFactoryImpl struct {
Srv CryptoService
}
func (*CryptoServiceFactoryImpl) GetSrv ¶
func (c *CryptoServiceFactoryImpl) GetSrv() CryptoService
func (*CryptoServiceFactoryImpl) SetSrv ¶
func (c *CryptoServiceFactoryImpl) SetSrv(srv CryptoService)
type CryptoServiceRSAImpl ¶
type CryptoServiceRSAImpl struct {
// contains filtered or unexported fields
}
CryptoServiceRSAImpl implementation of the crypto service interface
func (*CryptoServiceRSAImpl) Decrypt ¶
func (cs *CryptoServiceRSAImpl) Decrypt(ciphertext []byte) ([]byte, error)
Decrypt decrypt ciphertext using the key management service
func (*CryptoServiceRSAImpl) Encrypt ¶
func (cs *CryptoServiceRSAImpl) Encrypt(plaintext []byte) ([]byte, error)
Encrypt encrypt plaintext using the key management service
func (*CryptoServiceRSAImpl) GetAlgorithm ¶
func (cs *CryptoServiceRSAImpl) GetAlgorithm() string
GetAlgorithm get the algorithm
func (*CryptoServiceRSAImpl) GetKeyManager ¶
func (cs *CryptoServiceRSAImpl) GetKeyManager() KeyManagementService
GetKeyManagementService get the key management service
func (*CryptoServiceRSAImpl) Sign ¶
func (cs *CryptoServiceRSAImpl) Sign(plaintext []byte) ([]byte, error)
Sign sign plaintext using the key management service
func (*CryptoServiceRSAImpl) Verify ¶
func (cs *CryptoServiceRSAImpl) Verify(plaintext, signature []byte) error
Verify verify signature using the key management service
type KeyManagementService ¶
type KeyManagementService interface { // GenerateKey generate a new key GenerateKey() ([]byte, error) // GetPublicKey get the public key GetPublicKey() ([]byte, error) // GetPrivateKey get the private key GetPrivateKey() ([]byte, error) // ImportKey import a key into the key management service ImportKey(key []byte, keyName string) error // GetCertificate get the certificate for the given key GetCertificate() model.EncKey }
KeyManagementService interface for key management service implementation (key generation, etc)
func NewKeyManagementServiceAES ¶
func NewKeyManagementServiceAES() KeyManagementService
NewKeyManagementServiceAES the key management service interface using the AES key generation scheme
func NewKeyManagementServiceRSA ¶
func NewKeyManagementServiceRSA() KeyManagementService
NewKeyManagementServiceRSA the key management service interface using the RSA OAEP key generation scheme
type KeyManagementServiceAES ¶
type KeyManagementServiceAES struct {
// contains filtered or unexported fields
}
KeyManagementServiceAES interface for key management service implementation (key generation, etc)
func (*KeyManagementServiceAES) GenerateKey ¶
func (kms *KeyManagementServiceAES) GenerateKey() ([]byte, error)
GenerateKey generate a new key for AES (symmetric) encryption
func (*KeyManagementServiceAES) GetCertificate ¶
func (kms *KeyManagementServiceAES) GetCertificate() model.EncKey
GetCertificate get the certificate of the key
func (*KeyManagementServiceAES) GetPrivateKey ¶
func (kms *KeyManagementServiceAES) GetPrivateKey() ([]byte, error)
GetPrivateKey validates and get back the private key in bytes
func (*KeyManagementServiceAES) GetPublicKey ¶
func (kms *KeyManagementServiceAES) GetPublicKey() ([]byte, error)
GetPublicKey get the public key Since AES is symmetric, the public key is the same as the private key
type KeyManagementServiceRSAImpl ¶
type KeyManagementServiceRSAImpl struct {
// contains filtered or unexported fields
}
KeyManagementServiceRSAImpl implementation of the key management service interface
func (*KeyManagementServiceRSAImpl) GenerateKey ¶
func (kms *KeyManagementServiceRSAImpl) GenerateKey() ([]byte, error)
GenerateKey generate a new key
func (*KeyManagementServiceRSAImpl) GetCertificate ¶
func (kms *KeyManagementServiceRSAImpl) GetCertificate() model.EncKey
GetCertificate get the certificate of the key
func (*KeyManagementServiceRSAImpl) GetPrivateKey ¶
func (kms *KeyManagementServiceRSAImpl) GetPrivateKey() ([]byte, error)
GetPrivateKey validates and get back the private key in bytes
func (*KeyManagementServiceRSAImpl) GetPublicKey ¶
func (kms *KeyManagementServiceRSAImpl) GetPublicKey() ([]byte, error)
GetPublicKey get the public key
type NoteService ¶
type NoteService interface { GetNoteWithContent(id int) (*model.Note, error) GetNotes() ([]model.Note, error) GetTitles() []string SearchNotes(query string, fuzzySearch bool) ([]string, error) CreateNote(note *model.Note) error SaveEncryptedNotes(notes []model.Note) error ReEncryptNotes(notes []model.Note, cert model.EncKey) error UpdateNoteContent(note *model.Note) error UpdateNoteTitle(oldTitle, newTitle string) (noteID int, err error) DeleteNote(id int) error EncryptNote(note *model.Note) error DecryptNote(note *model.Note) error GetNoteIDFromTitle(title string) int }
NoteService ....
func NewNoteService ¶
func NewNoteService( noteRepo NoteServiceRepository, configService ConfigService, observer observer.Observer, crypto CryptoServiceFactory, ) NoteService
NewNoteService ....
type NoteServiceImpl ¶
type NoteServiceImpl struct { NoteRepo NoteServiceRepository ConfigService ConfigService Observer observer.Observer Crypto CryptoServiceFactory // Titles an array with all note Titles in db Titles []string }
NoteServiceImpl ....
func (*NoteServiceImpl) CreateNote ¶
func (ns *NoteServiceImpl) CreateNote(note *model.Note) error
CreateNote ....
func (*NoteServiceImpl) DecryptNote ¶
func (ns *NoteServiceImpl) DecryptNote(note *model.Note) error
DecryptNote ....
func (*NoteServiceImpl) DeleteNote ¶
func (ns *NoteServiceImpl) DeleteNote(id int) error
DeleteNote ....
func (*NoteServiceImpl) EncryptNote ¶
func (ns *NoteServiceImpl) EncryptNote(note *model.Note) error
EncryptNote ....
func (*NoteServiceImpl) GetNoteIDFromTitle ¶
func (ns *NoteServiceImpl) GetNoteIDFromTitle(title string) int
GetNoteIDFromTitle returns the note ID from the title
func (*NoteServiceImpl) GetNoteWithContent ¶
func (ns *NoteServiceImpl) GetNoteWithContent(id int) (*model.Note, error)
GetNote retreives a note from the db by id and decrypts it
func (*NoteServiceImpl) GetNotes ¶
func (ns *NoteServiceImpl) GetNotes() ([]model.Note, error)
GetNotes returns all note titles from the db and populate Titles array and TitlesIDMap with the results note: the note content is returned encrypted
func (*NoteServiceImpl) GetTitles ¶
func (ns *NoteServiceImpl) GetTitles() []string
GetTitles returns all note titles from memory
func (*NoteServiceImpl) ReEncryptNotes ¶
ReEncryptNotes re-encrypts a batch of notes with a given key and encryption algorithm
func (*NoteServiceImpl) SaveEncryptedNotes ¶
func (ns *NoteServiceImpl) SaveEncryptedNotes(notes []model.Note) error
CreateEncryptedNotes save to db a batch of (already) encrypted notes TODO: refactor this method to use a batch insert instead of a loop
func (*NoteServiceImpl) SearchNotes ¶
func (ns *NoteServiceImpl) SearchNotes(query string, fuzzySearch bool) ([]string, error)
SearchNotes ....
func (*NoteServiceImpl) UpdateNoteContent ¶
func (ns *NoteServiceImpl) UpdateNoteContent(note *model.Note) error
UpdateNoteContent update the content of an existing note
func (*NoteServiceImpl) UpdateNoteTitle ¶
func (ns *NoteServiceImpl) UpdateNoteTitle(oldTitle, newTitle string) (noteID int, err error)
UpdateNoteTitle update the title of an existing UpdateNote since the title is used as a key in db we need to delete the old note and create a new one the new note is a copy of the old note with the new title
type NoteServiceRepository ¶
type NoteServiceRepository interface { GetAllNotes() ([]model.Note, error) GetNote(id int) (*model.Note, error) CreateNote(note *model.Note) error UpdateNote(note *model.Note) error DeleteNote(id int) error NoteExists(id int) (bool, error) GetIDFromTitle(title string) int }
NoteServiceRepository interface for querying notes
func NewNoteServiceRepository ¶
func NewNoteServiceRepository( dbPath string, bucket string, resetDB bool, ) (NoteServiceRepository, error)
NewNoteServiceRepository constructor for NoteServiceRepositoryImpl
type NoteServiceRepositoryImpl ¶
type NoteServiceRepositoryImpl struct {
// contains filtered or unexported fields
}
NoteServiceRepositoryImpl implementation of NoteServiceRepository that uses nutsdb
func (*NoteServiceRepositoryImpl) CreateNote ¶
func (nsr *NoteServiceRepositoryImpl) CreateNote(note *model.Note) error
CreateNote adds a new note to the db model.Note: note's content has already been encrypted at service layer
func (*NoteServiceRepositoryImpl) DeleteNote ¶
func (nsr *NoteServiceRepositoryImpl) DeleteNote(id int) error
DeleteNote deletes a note from the db
func (*NoteServiceRepositoryImpl) GetAllNotes ¶
func (nsr *NoteServiceRepositoryImpl) GetAllNotes() ([]model.Note, error)
GetAllNotes retreives all notes from the db (already decrypted)
func (*NoteServiceRepositoryImpl) GetIDFromTitle ¶
func (nsr *NoteServiceRepositoryImpl) GetIDFromTitle(title string) int
GetIDFromTitle retreives a note's ID from its title
func (*NoteServiceRepositoryImpl) GetNote ¶
func (nsr *NoteServiceRepositoryImpl) GetNote(id int) (*model.Note, error)
GetNote retreives a note from the db by its ID (already decrypted)
func (*NoteServiceRepositoryImpl) NoteExists ¶
func (nsr *NoteServiceRepositoryImpl) NoteExists(id int) (bool, error)
NoteExists checks if a note exists in the db
func (*NoteServiceRepositoryImpl) UpdateNote ¶
func (nsr *NoteServiceRepositoryImpl) UpdateNote(note *model.Note) error
UpdateNote update a note in the db