config

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2016 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default encrypts conversations with this peer depending on the account
	// configuration (config.Account#AlwaysEncrypt)
	Default EncryptionSettings = "default"
	// AlwaysEncrypt always encrypts conversations with this peer
	AlwaysEncrypt = "always"
	// NeverEncrypt never encrypts conversations with this peer
	NeverEncrypt = "never"
)

Variables

View Source
var (
	ConfigFile          = flag.String("config-file", "", "Location of the config file")
	ConfigFileEncrypted = flag.Bool("config-file-encrypted", false, "Force config file to be encrypted even if the file name doesn't match the expected pattern")
	CreateAccount       = flag.Bool("create", false, "If true, attempt to create account")
	DebugFlag           = flag.Bool("debug", false, "Enable debug logging")
	AccountFlag         = flag.String("account", "", "The account the CLI should connect to, if more than one is configured")
	MultiFlag           = flag.Bool("multi", false, "If true, will not try to unify the windows, but create separate instances")
	VersionFlag         = flag.Bool("version", false, "Print CoyIM version and exit")
)

These flags represent all the available command line flags

View Source
var (
	// ErrTorNotRunning is the error returned when Tor is required by the policy
	// but it was not found to be running (on port 9050 or 9051).
	ErrTorNotRunning = errors.New("Tor is not running")
)

Functions

func FindFile added in v0.3.7

func FindFile(places []string) (string, bool)

FindFile will check each path and if that file exists return the file name and true

func FormatFingerprint

func FormatFingerprint(fpr []byte) string

FormatFingerprint returns a formatted string of the fingerprint

func GenerateKeys

func GenerateKeys(password string, params EncryptionParameters) ([]byte, []byte)

GenerateKeys takes a password and encryption parameters and generates an AES key and a MAC key using SCrypt

func IsWindows

func IsWindows() bool

IsWindows returns true if this is running under windows

func ParseYes

func ParseYes(input string) bool

ParseYes returns true if the string is any combination of yes

func SerializedKeys

func SerializedKeys(keys []otr3.PrivateKey) [][]byte

SerializedKeys will generate a new slice of a byte slice containing serializations of all keys given

func SystemConfigDir

func SystemConfigDir() string

SystemConfigDir returns the application data directory, valid on both windows and posix systems

func WithHome

func WithHome(file string) string

WithHome returns the given relative file/dir with the $HOME prepended

func XdgCacheDir

func XdgCacheDir() string

XdgCacheDir returns the standardized XDG Cache directory

func XdgConfigHome

func XdgConfigHome() string

XdgConfigHome returns the standardized XDG Configuration directory

func XdgDataDirs added in v0.3.7

func XdgDataDirs() []string

XdgDataDirs returns the standardized XDG Data directory

func XdgDataHome added in v0.3.7

func XdgDataHome() string

XdgDataHome returns the standardized XDG Data directory

Types

type Account

type Account struct {

	//TODO: this should be JID
	Account              string
	Nickname             string   `json:",omitempty"`
	Server               string   `json:",omitempty"`
	Proxies              []string `json:",omitempty"`
	Password             string   `json:",omitempty"`
	Port                 int      `json:",omitempty"`
	PrivateKeys          [][]byte `json:",omitempty"`
	Peers                []*Peer
	HideStatusUpdates    bool
	OTRAutoTearDown      bool
	OTRAutoAppendTag     bool
	OTRAutoStartSession  bool
	AlwaysEncrypt        bool   `json:",omitempty"`
	InstanceTag          uint32 `json:",omitempty"`
	ConnectAutomatically bool
	Certificates         []*CertificatePin `json:",omitempty"`
	PinningPolicy        string            `json:",omitempty"`

	LegacyKnownFingerprints       []KnownFingerprint `json:"KnownFingerprints,omitempty"`
	DeprecatedPrivateKey          []byte             `json:"PrivateKey,omitempty"`
	LegacyServerCertificateSHA256 string             `json:"ServerCertificateSHA256,omitempty"`

	// AlwaysEncryptWith and DontEncryptWith should be promoted to legacy and replaced with the peer settings
	AlwaysEncryptWith []string `json:",omitempty"`
	DontEncryptWith   []string `json:",omitempty"`
	// contains filtered or unexported fields
}

Account contains the configuration for one account

func NewAccount

func NewAccount() (*Account, error)

NewAccount creates a new account

func (*Account) AddTrustedFingerprint

func (a *Account) AddTrustedFingerprint(fpr []byte, uid string)

AddTrustedFingerprint adds a new fingerprint for the given user

func (*Account) AllPrivateKeys

func (a *Account) AllPrivateKeys() [][]byte

AllPrivateKeys returns all private keys for this account

func (*Account) AuthorizeFingerprint

func (a *Account) AuthorizeFingerprint(uid string, fingerprint []byte) error

AuthorizeFingerprint will authorize and add the fingerprint for the given user or return an error if the fingerprint is already associated with another user

func (*Account) EnsurePeer

func (a *Account) EnsurePeer(uid string) *Peer

EnsurePeer returns the first peer with the given uid, or creates and adds a new one if none exist

func (*Account) EnsurePrivateKey

func (a *Account) EnsurePrivateKey() (hasUpdate bool, e error)

EnsurePrivateKey generates a private key for the account in case it's missing

func (*Account) GetPeer

func (a *Account) GetPeer(uid string) (*Peer, bool)

GetPeer returns the first peer with the given uid, or false if none is found

func (*Account) HasFingerprint

func (a *Account) HasFingerprint(uid string) bool

HasFingerprint returns true if we have the fingerprint for the given user

func (*Account) HasTorAuto

func (a *Account) HasTorAuto() bool

HasTorAuto check if account has proxy with prefix "tor-auto://"

func (*Account) ID

func (a *Account) ID() string

ID returns the unique identifier for this account

func (*Account) Is

func (a *Account) Is(jid string) bool

Is returns true if this account represents the same identity as the given JID

func (*Account) RemoveFingerprint

func (a *Account) RemoveFingerprint(uid string, fpr []byte) bool

RemoveFingerprint removes the fingerprint for the given uid

func (*Account) RemovePeer

func (a *Account) RemovePeer(uid string)

RemovePeer removes the given peer

func (*Account) SaveCert

func (a *Account) SaveCert(subject, issuer string, sha3Digest []byte)

SaveCert will put the given certificate as a pinned certificate. It expects a SHA3-256 hash of the certificate.

func (*Account) SavePeerDetails

func (a *Account) SavePeerDetails(jid, nickname string, groups []string)

SavePeerDetails store peer identifiable information only locally

func (*Account) SetOTRPoliciesFor

func (a *Account) SetOTRPoliciesFor(jid string, c *otr3.Conversation)

SetOTRPoliciesFor will set the OTR policies on the given conversation based on the users settings

func (*Account) ShouldEncryptTo

func (a *Account) ShouldEncryptTo(jid string) bool

ShouldEncryptTo returns true if the connection with this peer should be encrypted

func (*Account) ToggleAlwaysEncrypt

func (a *Account) ToggleAlwaysEncrypt()

ToggleAlwaysEncrypt toggles the state of AlwaysEncrypt config

func (*Account) ToggleConnectAutomatically

func (a *Account) ToggleConnectAutomatically()

ToggleConnectAutomatically toggles the state of ConnectAutomatically config

func (*Account) UpdateEncryptionRequired

func (a *Account) UpdateEncryptionRequired(jid string, requireEnc bool)

UpdateEncryptionRequired will set a specific encryption setting for this peer

func (*Account) UserIDForVerifiedFingerprint

func (a *Account) UserIDForVerifiedFingerprint(fpr []byte) string

UserIDForVerifiedFingerprint returns the user ID for the given verified fingerprint

type ApplicationConfig

type ApplicationConfig struct {
	Accounts                      []*Account
	RawLogFile                    string   `json:",omitempty"`
	NotifyCommand                 []string `json:",omitempty"`
	IdleSecondsBeforeNotification int      `json:",omitempty"`
	Bell                          bool
	ConnectAutomatically          bool
	Display                       DisplayConfig `json:",omitempty"`
	AdvancedOptions               bool
	UniqueConfigurationID         string
	// contains filtered or unexported fields
}

ApplicationConfig contains the configuration for the application, including account information.

func LoadOrCreate

func LoadOrCreate(configFile string, ks KeySupplier) (a *ApplicationConfig, ok bool, e error)

LoadOrCreate will try to load the configuration from the given configuration file or from the standard configuration file. If no file exists or it is malformed, or it could not be decrypted, an error will be returned. However, the returned Accounts instance will always be usable

func (*ApplicationConfig) Add

func (a *ApplicationConfig) Add(ac *Account)

Add will add the account to the application configuration

func (*ApplicationConfig) AddNewAccount

func (a *ApplicationConfig) AddNewAccount() (ac *Account, err error)

AddNewAccount creates a new account and adds it to the list of accounts

func (*ApplicationConfig) GetAccount

func (a *ApplicationConfig) GetAccount(jid string) (*Account, bool)

GetAccount will return the account with the given JID or not OK if it doesn't exist

func (*ApplicationConfig) GetUniqueID added in v0.3.3

func (a *ApplicationConfig) GetUniqueID() string

GetUniqueID returns a unique id for this application config

func (*ApplicationConfig) HasEncryptedStorage

func (a *ApplicationConfig) HasEncryptedStorage() bool

HasEncryptedStorage returns true if this configuration file is stored encrypt

func (*ApplicationConfig) Remove

func (a *ApplicationConfig) Remove(toRemove *Account)

Remove will update the accounts to exclude the account to remove, if it does exist

func (*ApplicationConfig) Save

func (a *ApplicationConfig) Save(ks KeySupplier) error

Save will save the application configuration

func (*ApplicationConfig) SetShouldSaveFileEncrypted

func (a *ApplicationConfig) SetShouldSaveFileEncrypted(val bool) bool

SetShouldSaveFileEncrypted will change whether the file is saved in encrypted form or not It will immediately ask for a password if turning on encryption, and it will remove the old configuration file

func (*ApplicationConfig) UpdateToLatestVersion

func (a *ApplicationConfig) UpdateToLatestVersion() bool

UpdateToLatestVersion will run through all accounts and update their configuration to latest version for cases where we have changed the configuration format. It returns true if any changes were made

func (*ApplicationConfig) WhenLoaded

func (a *ApplicationConfig) WhenLoaded(f func(*ApplicationConfig))

WhenLoaded will ensure that the function f is not called until the configuration has been loaded

type ByAccountNameAlphabetic

type ByAccountNameAlphabetic []*Account

ByAccountNameAlphabetic sorts the accounts based on their account names

func (ByAccountNameAlphabetic) Len

func (s ByAccountNameAlphabetic) Len() int

func (ByAccountNameAlphabetic) Less

func (s ByAccountNameAlphabetic) Less(i, j int) bool

func (ByAccountNameAlphabetic) Swap

func (s ByAccountNameAlphabetic) Swap(i, j int)

type ByNaturalOrder

type ByNaturalOrder []*Fingerprint

ByNaturalOrder sorts fingerprints according to the fingerprint

func (ByNaturalOrder) Len

func (s ByNaturalOrder) Len() int

func (ByNaturalOrder) Less

func (s ByNaturalOrder) Less(i, j int) bool

func (ByNaturalOrder) Swap

func (s ByNaturalOrder) Swap(i, j int)

type CertificatePin

type CertificatePin struct {
	Subject         string
	Issuer          string
	Fingerprint     []byte
	FingerprintType string
}

CertificatePin represents a known certificate hash to accept as a given

func (*CertificatePin) MarshalJSON

func (v *CertificatePin) MarshalJSON() ([]byte, error)

MarshalJSON is used to create a JSON representation of this certificate pin

func (*CertificatePin) Matches

func (v *CertificatePin) Matches(cert *x509.Certificate) bool

Matches returns true if this pin matches the given certificate

func (*CertificatePin) UnmarshalJSON

func (v *CertificatePin) UnmarshalJSON(data []byte) error

UnmarshalJSON is used to parse the JSON representation of a certificate pin

type CertificatePinForSerialization

type CertificatePinForSerialization struct {
	Subject         string `json:",omitempty"`
	Issuer          string `json:",omitempty"`
	FingerprintHex  string
	FingerprintType string
}

CertificatePinForSerialization represents a certificate pin in its serialized form

type CertificatePinsByNaturalOrder

type CertificatePinsByNaturalOrder []*CertificatePin

CertificatePinsByNaturalOrder sorts certificate pins by the fingerprints

func (CertificatePinsByNaturalOrder) Len

func (CertificatePinsByNaturalOrder) Less

func (s CertificatePinsByNaturalOrder) Less(i, j int) bool

func (CertificatePinsByNaturalOrder) Swap

func (s CertificatePinsByNaturalOrder) Swap(i, j int)

type ConnectionPolicy

type ConnectionPolicy struct {
	// Logger logs connection information.
	Logger io.Writer

	// XMPPLogger logs XMPP messages
	XMPPLogger io.Writer

	DialerFactory interfaces.DialerFactory
	// contains filtered or unexported fields
}

ConnectionPolicy represents a policy to connect to XMPP servers

func (*ConnectionPolicy) Connect

func (p *ConnectionPolicy) Connect(password string, conf *Account, verifier ourtls.Verifier) (interfaces.Conn, error)

Connect to the server and authenticates with the password

func (*ConnectionPolicy) RegisterAccount

func (p *ConnectionPolicy) RegisterAccount(createCallback data.FormCallback, conf *Account, verifier ourtls.Verifier) (interfaces.Conn, error)

RegisterAccount register the account on the XMPP server.

type DisplayConfig

type DisplayConfig struct {
	MergeAccounts   bool
	ShowOnlyOnline  bool
	HideFeedbackBar bool
}

DisplayConfig contains display parameters

type EncryptionParameters

type EncryptionParameters struct {
	Nonce string
	Salt  string
	N     int
	R     int
	P     int
	// contains filtered or unexported fields
}

EncryptionParameters contains the parameters used for scrypting the password and encrypting the configuration file

type EncryptionSettings

type EncryptionSettings string

EncryptionSettings configures the encryption setting for this peer

type Fingerprint

type Fingerprint struct {
	Fingerprint []byte
	Trusted     bool
}

Fingerprint represents a known fingerprint for a specific peer

func (*Fingerprint) MarshalJSON

func (k *Fingerprint) MarshalJSON() ([]byte, error)

MarshalJSON is used to create a JSON representation of this fingerprint

func (*Fingerprint) UnmarshalJSON

func (k *Fingerprint) UnmarshalJSON(data []byte) error

UnmarshalJSON is used to parse the JSON representation of a fingerprint

type FingerprintForSerialization

type FingerprintForSerialization struct {
	FingerprintHex string
	Trusted        bool
}

FingerprintForSerialization represents a fingerprint in its serialized form

type KeySupplier

type KeySupplier interface {
	GenerateKey(params EncryptionParameters) ([]byte, []byte, bool)
	Invalidate()
	LastAttemptFailed()
}

KeySupplier is a function that can be used to get key data from a user

func CachingKeySupplier

func CachingKeySupplier(getKeys func(params EncryptionParameters, lastAttemptFailed bool) ([]byte, []byte, bool)) KeySupplier

CachingKeySupplier is a key supplier that only asks the user for a password if it doesn't already have the key material

func FunctionKeySupplier

func FunctionKeySupplier(getKeys func(params EncryptionParameters, lastAttemptFailed bool) ([]byte, []byte, bool)) KeySupplier

FunctionKeySupplier is a key supplier that wraps a function to ask for the password

type KnownFingerprint

type KnownFingerprint struct {
	UserID      string
	Fingerprint []byte
	Untrusted   bool
}

KnownFingerprint represents one fingerprint

func (KnownFingerprint) MarshalJSON

func (k KnownFingerprint) MarshalJSON() ([]byte, error)

MarshalJSON is used to create a JSON representation of this known fingerprint

func (*KnownFingerprint) UnmarshalJSON

func (k *KnownFingerprint) UnmarshalJSON(data []byte) error

UnmarshalJSON is used to parse the JSON representation of a known fingerprint

type LegacyByNaturalOrder

type LegacyByNaturalOrder []*KnownFingerprint

LegacyByNaturalOrder sorts fingerprints according to first the user ID and then the fingerprint

func (LegacyByNaturalOrder) Len

func (s LegacyByNaturalOrder) Len() int

func (LegacyByNaturalOrder) Less

func (s LegacyByNaturalOrder) Less(i, j int) bool

func (LegacyByNaturalOrder) Swap

func (s LegacyByNaturalOrder) Swap(i, j int)

type Peer

type Peer struct {
	UserID             string
	Nickname           string
	EncryptionSettings EncryptionSettings `json:",omitempty"`

	Groups       []string `json:",omitempty"`
	Fingerprints []*Fingerprint
}

Peer represents one peer

func (*Peer) EnsureHasFingerprint

func (p *Peer) EnsureHasFingerprint(fpr []byte) (*Fingerprint, bool)

EnsureHasFingerprint ensures that the peer has the given fingerprint and returns the Fingerprint instance

func (*Peer) HasTrustedFingerprint

func (p *Peer) HasTrustedFingerprint(fpr []byte) bool

HasTrustedFingerprint returns true if the peer has the given fingerprint and it is trusted

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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