2021-11-21 23:05:13 -05:00
|
|
|
package gosecret
|
2021-11-21 14:25:31 -05:00
|
|
|
|
|
|
|
import (
|
2021-11-28 21:43:30 -05:00
|
|
|
"time"
|
2021-11-27 02:24:22 -05:00
|
|
|
|
2021-11-28 21:43:30 -05:00
|
|
|
"github.com/godbus/dbus"
|
2021-11-21 14:25:31 -05:00
|
|
|
)
|
|
|
|
|
2021-11-27 02:24:22 -05:00
|
|
|
/*
|
|
|
|
MultiError is a type of error.Error that can contain multiple error.Errors. Confused? Don't worry about it.
|
|
|
|
*/
|
|
|
|
type MultiError struct {
|
|
|
|
// Errors is a slice of errors to combine/concatenate when .Error() is called.
|
2021-11-28 21:43:30 -05:00
|
|
|
Errors []error `json:"errors"`
|
2021-11-27 02:24:22 -05:00
|
|
|
// ErrorSep is a string to use to separate errors for .Error(). The default is "\n".
|
2021-11-28 21:43:30 -05:00
|
|
|
ErrorSep string `json:"separator"`
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SecretServiceError is a translated error from SecretService API.
|
|
|
|
See https://developer-old.gnome.org/libsecret/unstable/libsecret-SecretError.html#SecretError and
|
|
|
|
ErrSecretService* errors.
|
|
|
|
*/
|
|
|
|
type SecretServiceError struct {
|
|
|
|
// ErrCode is the SecretService API's enum value.
|
|
|
|
ErrCode SecretServiceErrEnum `json:"code"`
|
|
|
|
// ErrName is the SecretService API's error name.
|
|
|
|
ErrName string `json:"name"`
|
|
|
|
/*
|
|
|
|
ErrDesc is the actual error description/text.
|
|
|
|
This is what should be displayed to users, and is returned by SecretServiceError.Error.
|
|
|
|
*/
|
|
|
|
ErrDesc string `json:"desc"`
|
2021-11-27 02:24:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConnPathCheckResult contains the result of validConnPath.
|
|
|
|
type ConnPathCheckResult struct {
|
|
|
|
// ConnOK is true if the dbus.Conn is valid.
|
2021-11-28 21:43:30 -05:00
|
|
|
ConnOK bool `json:"conn"`
|
2021-11-27 02:24:22 -05:00
|
|
|
// PathOK is true if the Dbus path given is a valid type and value.
|
2021-11-28 21:43:30 -05:00
|
|
|
PathOK bool `json:"path"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DbusObject is a base struct type to be anonymized by other types.
|
|
|
|
type DbusObject struct {
|
|
|
|
// Conn is an active connection to the Dbus.
|
|
|
|
Conn *dbus.Conn `json:"-"`
|
|
|
|
// Dbus is the Dbus bus object.
|
|
|
|
Dbus dbus.BusObject `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Prompt is an interface to handling unlocking prompts.
|
|
|
|
https://developer-old.gnome.org/libsecret/0.18/SecretPrompt.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/ch09.html
|
|
|
|
*/
|
|
|
|
type Prompt struct {
|
|
|
|
*DbusObject
|
2021-11-27 02:24:22 -05:00
|
|
|
}
|
|
|
|
|
2021-11-28 21:43:30 -05:00
|
|
|
/*
|
|
|
|
Service is a general SecretService interface, sort of handler for Dbus - it's used for fetching a Session, Collections, etc.
|
|
|
|
https://developer-old.gnome.org/libsecret/0.18/SecretService.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/re01.html
|
|
|
|
*/
|
|
|
|
type Service struct {
|
|
|
|
*DbusObject
|
|
|
|
Session *Session `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Session is a session/instance/connection to SecretService.
|
|
|
|
https://developer-old.gnome.org/libsecret/0.18/SecretService.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/ch06.html
|
|
|
|
*/
|
|
|
|
type Session struct {
|
|
|
|
*DbusObject
|
2021-11-21 18:07:52 -05:00
|
|
|
}
|
|
|
|
|
2021-11-21 14:25:31 -05:00
|
|
|
/*
|
2021-11-21 18:07:52 -05:00
|
|
|
Collection is an accessor for libsecret collections, which contain multiple Secret Item items.
|
2021-11-21 14:25:31 -05:00
|
|
|
Reference:
|
|
|
|
https://developer-old.gnome.org/libsecret/0.18/SecretCollection.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/ch03.html
|
|
|
|
*/
|
|
|
|
type Collection struct {
|
2021-11-28 21:43:30 -05:00
|
|
|
*DbusObject
|
2021-11-27 02:24:22 -05:00
|
|
|
// lastModified is unexported because it's important that API users don't change it; it's used by Collection.Modified.
|
|
|
|
lastModified time.Time
|
2021-12-04 19:38:26 -05:00
|
|
|
// lastModifiedSet is unexported; it's only used to determine if this is a first-initialization of the modification time or not.
|
|
|
|
lastModifiedSet bool
|
|
|
|
// name is used for the Collection's name/label so the Dnus path doesn't need to be parsed all the time.
|
|
|
|
name string
|
2021-11-21 18:07:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Item is an entry in a Collection that contains a Secret.
|
|
|
|
https://developer-old.gnome.org/libsecret/0.18/SecretItem.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/re03.html
|
|
|
|
*/
|
|
|
|
type Item struct {
|
2021-11-28 21:43:30 -05:00
|
|
|
*DbusObject
|
2021-11-21 18:07:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Secret is the "Good Stuff" - the actual secret content.
|
|
|
|
https://developer-old.gnome.org/libsecret/0.18/SecretValue.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/re03.html
|
|
|
|
https://specifications.freedesktop.org/secret-service/latest/ch14.html#type-Secret
|
|
|
|
*/
|
|
|
|
type Secret struct {
|
|
|
|
// Session is a Dbus object path for the associated Session.
|
2021-11-28 21:43:30 -05:00
|
|
|
Session dbus.ObjectPath `json:"-"`
|
2021-11-21 18:07:52 -05:00
|
|
|
// Parameters are "algorithm dependent parameters for secret value encoding" - likely this will just be an empty byteslice.
|
2021-11-28 21:43:30 -05:00
|
|
|
Parameters []byte `json:"params"`
|
2021-11-21 18:07:52 -05:00
|
|
|
// Value is the secret's content in []byte format.
|
2021-11-28 21:43:30 -05:00
|
|
|
Value []byte `json:"value"`
|
2021-11-21 18:07:52 -05:00
|
|
|
// ContentType is the MIME type of Value.
|
2021-11-28 21:43:30 -05:00
|
|
|
ContentType string `json:"content_type"`
|
2021-11-21 14:25:31 -05:00
|
|
|
}
|