client

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

client package for 'secret service' as described at: http://standards.freedesktop.org/secret-service

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Epoch

func Epoch() uint64

func SliceContains

func SliceContains(slice, elem interface{}) (bool, error)

SliceContains returns true if a slice contains an element otherwise false

Types

type CliSession added in v0.2.0

type CliSession struct {
	// reference to parent (client)
	Parent *Client
	// symmetric key used or AES encryption/decryption. Needs IV as well
	SymmetricKey []byte // 16 bytes (128 bits)
}

func NewCliSession added in v0.2.0

func NewCliSession(parent *Client) *CliSession

type Client

type Client struct {
	// dbus session connection
	Connection *dbus.Conn
	// dbus object used to call dbus methods
	DbusObject dbus.BusObject
	// Signal channel
	SignalChan chan *dbus.Signal
	// SecretService session
	SecretService *SecretService
	// Mutex for lock/unlock Sessions map
	SessionsMutex *sync.RWMutex
	// sessions map. key: session dbus object path, value: session object
	Sessions map[string]*Session
	// Cli session
	// CliSession *CliSession // TODO: REMOVE ME
	// Mutex for lock/unlock Collections map
	CollectionsMutex *sync.RWMutex
	// Collections map. key: Collection dbus object path, value: Collection object
	Collections map[string]*Collection
}

secret service client data structure

func New

func New() (*Client, error)

New returns a new client connected to session dbus

func (*Client) AddCollection

func (client *Client) AddCollection(collection *Collection)

AddCollection adds a new collection to client's collection map

func (*Client) AddSession

func (client *Client) AddSession(session *Session)

AddSession adds a new session to client's session map

func (*Client) Call

func (client *Client) Call(destination string, dbusPath dbus.ObjectPath,
	dbusInterface string, methodName string, args ...interface{}) (*dbus.Call, error)

Call performs low-level method Call on org.freedesktop.secrets objects Don't use this method directly unless you know what you are doing!

func (*Client) Connected

func (client *Client) Connected() bool

Connected returns true if client is connected to session dbus otherwise false

func (*Client) CreateCollection

func (client *Client) CreateCollection(properties map[string]dbus.Variant,
	alias string) (*Collection, dbus.ObjectPath, error)

CreateCollection creates a collection for storing items item = secret + lookup attributes + label

func (*Client) Disconnect

func (client *Client) Disconnect() error

Disconnect from session dbus CAUTION: connection is shared by all clients by closing it all clients fail on subsequent operations

func (*Client) GetCollectionByPath

func (client *Client) GetCollectionByPath(collectionPath dbus.ObjectPath) *Collection

GetCollectionByPath returns a collection based on its path, otherwise null

func (*Client) GetSecrets

func (client *Client) GetSecrets(items []dbus.ObjectPath,
	session dbus.ObjectPath) (map[dbus.ObjectPath]SecretApi, error)

GetSecrets returns secrets associated to given object paths

func (*Client) GetSessionByPath

func (client *Client) GetSessionByPath(sessionPath dbus.ObjectPath) *Session

GetSessionByPath returns a session based on its path otherwise null

func (*Client) HasCollection

func (client *Client) HasCollection(collectionPath dbus.ObjectPath) bool

HasCollection returns true if collection exists otherwise false

func (*Client) HasSession

func (client *Client) HasSession(sessionPath dbus.ObjectPath) bool

HasSession returns true if session exists otherwise false

func (*Client) Lock

func (client *Client) Lock(
	objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, error)

Lock, locks given objects based on their paths and returns an array of locked object paths

func (*Client) OpenSession

func (client *Client) OpenSession(algorithm EncryptionAlgorithm) (*Session, error)

OpenSession creates a session for encrypted or non-encrypted further communication

func (*Client) PropertyGetCollections

func (client *Client) PropertyGetCollections() ([]string, error)

PropertyGetCollections returns Collections property of Service

func (*Client) ReadAlias

func (client *Client) ReadAlias(name string) (dbus.ObjectPath, error)

ReadAlias returns the collection with given alias

func (*Client) RemoveCollection

func (client *Client) RemoveCollection(collection *Collection) error

RemoveCollection removes a collection from client's Collections map

func (*Client) SearchItems

func (client *Client) SearchItems(
	attributes map[string]string) ([]dbus.ObjectPath, []dbus.ObjectPath, error)

SearchItems searches for items in this collection matching the lookup attributes

func (*Client) SecretServiceCommand added in v0.2.0

func (client *Client) SecretServiceCommand(
	command string, params string) (string, error)

OpenSession creates a session for encrypted or non-encrypted further communication

func (*Client) SetAlias

func (client *Client) SetAlias(name string, collection dbus.ObjectPath) error

SetAlias sets (or removes) an alias for given collection

func (*Client) Unlock

func (client *Client) Unlock(
	objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, error)

Unlock, unlocks given objects based on their paths and returns an array of unlocked object paths

func (*Client) WatchSignal

func (client *Client) WatchSignal(signal ServiceSignal, timeout ...time.Duration) (bool, error)

WatchSignal watches for desired signal within a time period If signal is received it returns true, otherwise false

type Collection

type Collection struct {
	// reference to parent (client)
	Parent *Client
	// Signal channel
	SignalChan chan *dbus.Signal
	// Mutex for lock/unlock Items slice
	ItemsMutex *sync.RWMutex
	// Items map. key: Item dbus object path, value: Item object
	Items map[string]*Item
	// collection full dbus object path
	ObjectPath dbus.ObjectPath

	// Mutex for lock/unlock Properties map
	PropertiesMutex *sync.RWMutex
	// collection Properties map
	Properties map[string]dbus.Variant
	// collection alias (friendly name)
	Alias string
	// Mutex to lock/unlock Locked status of collection
	LockMutex *sync.Mutex
	// collection Label
	Label string
	// true if collection is locked otherwise false
	Locked bool
	// Unix time collection created
	Created uint64
	// Unix time collection modified
	Modified uint64
	// contains filtered or unexported fields
}

Collection data structure collection consists of items

func NewCollection

func NewCollection(parent *Client) (*Collection, error)

NewCollection creates and initialize a new collection and returns it

func (*Collection) AddItem

func (collection *Collection) AddItem(item *Item) error

AddItem adds given item to the collection

func (*Collection) CreateItem

func (collection *Collection) CreateItem(properties map[string]dbus.Variant,
	secretApi *SecretApi, replace bool) (*Item, string, error)

CreateItem creates an Item in a collection item = secret + lookup attributes + label

func (*Collection) Delete

func (collection *Collection) Delete() (dbus.ObjectPath, error)

Delete removes the collection

func (*Collection) GetItemByPath

func (collection *Collection) GetItemByPath(itemPath dbus.ObjectPath) *Item

GetItemByPath returns an item based on its path, otherwise null

func (*Collection) GetProperty

func (collection *Collection) GetProperty(name string) (dbus.Variant, error)

GetProperty returns given dbus property value

func (*Collection) Lock

func (collection *Collection) Lock()

Lock, locks a collection

func (*Collection) PropertyCreated

func (collection *Collection) PropertyCreated() (uint64, error)

PropertyCreated returns 'Created' property of the collection

func (*Collection) PropertyGetItems

func (collection *Collection) PropertyGetItems() ([]string, error)

PropertyGetItems returns 'Items' property of the collection

func (*Collection) PropertyGetLabel

func (collection *Collection) PropertyGetLabel() (string, error)

PropertyGetLabel returns 'Label' property of the collection

func (*Collection) PropertyGetLocked

func (collection *Collection) PropertyGetLocked() (bool, error)

PropertyGetLocked returns 'Locked' property of the collection

func (*Collection) PropertyModified

func (collection *Collection) PropertyModified() (uint64, error)

PropertyModified returns 'Modified' property of the collection

func (*Collection) PropertySetLabel

func (collection *Collection) PropertySetLabel(label string) error

PropertySetLabel changes 'Label' property of the collection to the given value

func (*Collection) RemoveItem

func (collection *Collection) RemoveItem(itemPath dbus.ObjectPath) error

RemoveItem removes an item from the collection

func (*Collection) SearchItems

func (collection *Collection) SearchItems(attributes map[string]string) ([]dbus.ObjectPath, error)

SearchItems Searches for items in this collection matching the lookup attributes

func (*Collection) SetProperties

func (collection *Collection) SetProperties(properties map[string]dbus.Variant)

SetProperties processes raw properties and sets collection.Properties

func (*Collection) SetProperty

func (collection *Collection) SetProperty(name string, value interface{}) error

SetProperty sets given dbus property name to given value

func (*Collection) Unlock

func (collection *Collection) Unlock()

Unlock, unlocks a collection

func (*Collection) WatchSignal

func (collection *Collection) WatchSignal(signal CollectionSignal, timeout ...time.Duration) (bool, error)

WatchSignal watches for desired signal within a time period If signal is received it returns true, otherwise false

type CollectionSignal

type CollectionSignal uint8

org.freedesktop.Secret.Collection signals

const (
	ItemCreated CollectionSignal = iota
	ItemDeleted
	ItemChanged
)

type EncryptionAlgorithm

type EncryptionAlgorithm uint8

encryption algorithm type plain or Dh_ietf1024_sha256_aes128_cbc_pkcs7

const (
	// Plain algorithm (no encryption)
	Plain EncryptionAlgorithm = iota
	// Dh_ietf1024_sha256_aes128_cbc_pkcs7 algorithm
	Dh_ietf1024_sha256_aes128_cbc_pkcs7
	// Unsupported algorithm (used in tests)
	Unsupported
)

type Item

type Item struct {
	// reference to parent (collection)
	Parent *Collection
	// item full dbus object path
	ObjectPath dbus.ObjectPath
	// secret contained in this item
	Secret *Secret
	// Mutex for lock/unlock LookupAttributes slice
	LookupAttributesMutex *sync.RWMutex
	// LookupAttributes (name + value) contained in this item
	LookupAttributes map[string]string
	// label of this item
	Label string
	// Mutex to lock/unlock Locked status of item
	LockMutex *sync.Mutex
	// true if item is locked otherwise false
	Locked bool
	// Unix time item created
	Created uint64
	// Unix time item modified
	Modified uint64
}

Item data structure item = secret + lookup attributes + label

func NewItem

func NewItem(parent *Collection) *Item

NewCollection creates and initialize a new collection and returns it

func (*Item) Delete

func (item *Item) Delete() (dbus.ObjectPath, error)

Delete removes an item from a collection

func (*Item) GetProperty

func (item *Item) GetProperty(name string) (dbus.Variant, error)

GetProperty returns given dbus property value

func (*Item) GetSecret

func (item *Item) GetSecret(session dbus.ObjectPath) (*SecretApi, error)

GetSecret retrieves the secret for this item

func (*Item) Lock

func (item *Item) Lock()

Lock, locks the item

func (*Item) PropertyCreated

func (item *Item) PropertyCreated() (uint64, error)

PropertyCreated returns 'Created' property of the item

func (*Item) PropertyGetAttributes

func (item *Item) PropertyGetAttributes() (map[string]string, error)

PropertyGeAttributes returns 'Attributes' property of the item

func (*Item) PropertyGetLabel

func (item *Item) PropertyGetLabel() (string, error)

PropertyGetLabel returns 'Label' property of the item

func (*Item) PropertyGetLocked

func (item *Item) PropertyGetLocked() (bool, error)

PropertyGetLocked returns 'Locked' property of the item

func (*Item) PropertyModified

func (item *Item) PropertyModified() (uint64, error)

PropertyModified returns 'Modified' property of the item

func (*Item) PropertySetAttributes

func (item *Item) PropertySetAttributes(attributes map[string]string) error

PropertySetAttributes changes 'Attributes' property of the item to the given value

func (*Item) PropertySetLabel

func (item *Item) PropertySetLabel(label string) error

PropertySetLabel changes 'Label' property of the item to the given value

func (*Item) SetProperty

func (item *Item) SetProperty(name string, value interface{}) error

SetProperty sets given dbus property name to given value

func (*Item) SetSecret

func (item *Item) SetSecret(secretApi *SecretApi) error

SetSecret sets the secret for this item

func (*Item) Unlock

func (item *Item) Unlock()

Unlock, unlocks the item

type Prompt

type Prompt struct {
	// reference to parent (client)
	Parent *Client
	// Signal channel
	SignalChan chan *dbus.Signal
	// prompt full dbus object path
	ObjectPath dbus.ObjectPath
	// client applications can use the window-id to
	// display the prompt attached to their application window
	WindowId string
}

Prompt data structure

func NewPrompt

func NewPrompt(parent *Client) (*Prompt, error)

NewPrompt creates and initialize a new prompt

func (*Prompt) Dismiss

func (prompt *Prompt) Dismiss() error

Dismiss dismisses the prompt

func (*Prompt) Prompt

func (prompt *Prompt) Prompt(windowId string) error

Prompt performs the prompt. A prompt necessary to complete an operation windowId: Platform specific window handle to use for showing the prompt

func (*Prompt) WatchSignal

func (prompt *Prompt) WatchSignal(signal PromptSignal, timeout ...time.Duration) (bool, error)

WatchSignal watches for desired signal within a time period If signal is received it returns true, otherwise false

type PromptSignal

type PromptSignal uint8

org.freedesktop.Secret.Prompt signal

const (
	Completed PromptSignal = iota
)

type Secret

type Secret struct {
	// reference to parent (item)
	Parent *Item
	// Unencrypted secret
	PlainSecret string
	// Secret type needed bu API
	SecretApi *SecretApi
}

Secret data structure

func NewSecret

func NewSecret(parent *Item) *Secret

NewSecret returns a new instance of Secret

type SecretApi

type SecretApi struct {
	// The session full dbus object path that was used to encode the secret
	Session dbus.ObjectPath
	// Algorithm dependent parameters for secret value encoding
	Parameters []byte
	// Possibly encoded secret value
	Value []byte
	//The content type of the secret i.e. ‘text/plain; charset=utf8’
	ContentType string
}

Secret data structure needed bu API

func NewSecretApi

func NewSecretApi() *SecretApi

NewSecret returns a new instance of SecretApi SecretApi is the exact secret structure accordinf to API Secret is a wrapper around SecretApi to hold extra information

type SecretMap

type SecretMap map[dbus.ObjectPath]Secret

A mapping from object-paths to Secret structs

type SecretService added in v0.2.0

type SecretService struct {
	// reference to parent (service)
	Parent *Client
	// session (public key negotiation)
	Session *SecretServiceCLiSession
}

CLI interface data structure

type SecretServiceCLiSession added in v0.2.0

type SecretServiceCLiSession struct {
	// symmetric key used or AES encryption/decryption. Needs IV as well
	SymmetricKey []byte // 16 bytes (128 bits)
}

session (public key negotiation)

type ServiceSignal

type ServiceSignal uint8

org.freedesktop.Secret.Service signals

const (
	CollectionCreated ServiceSignal = iota
	CollectionDeleted
	CollectionChanged
)

type Session

type Session struct {
	// reference to parent (client)
	Parent *Client
	// session full dbus object path
	ObjectPath dbus.ObjectPath
	// encryption algorithm type
	EncryptionAlgorithm EncryptionAlgorithm
	// symmetric key used or AES encryption/decryption. Needs IV as well
	SymmetricKey []byte // 16 bytes (128 bits)
	// client public key used or AES encryption/decryption
	ServicePublicKey []byte // 128 bytes (1024 bits)
}

Session data structure

func NewSession

func NewSession(parent *Client) *Session

NewSession creates and initialize a new session

func (*Session) Close

func (session *Session) Close() error

Close closes a session

func (*Session) Remove

func (session *Session) Remove() error

Remove remove a session from client's Sessions map

Jump to

Keyboard shortcuts

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