account

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

account packages an account which stores the identity, one time keys and fallback keys.

Index

Constants

View Source
const (
	MaxOneTimeKeys int = 100 //maximum number of stored one time keys per Account
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	IdKeys struct {
		Ed25519    crypto.Ed25519KeyPair    `json:"ed25519,omitempty"`
		Curve25519 crypto.Curve25519KeyPair `json:"curve25519,omitempty"`
	} `json:"identity_keys"`
	OTKeys             []crypto.OneTimeKey `json:"one_time_keys"`
	CurrentFallbackKey crypto.OneTimeKey   `json:"current_fallback_key,omitempty"`
	PrevFallbackKey    crypto.OneTimeKey   `json:"prev_fallback_key,omitempty"`
	NextOneTimeKeyID   uint32              `json:"next_one_time_key_id,omitempty"`
	NumFallbackKeys    uint8               `json:"number_fallback_keys"`
}

Account stores an account for end to end encrypted messaging via the olm protocol. An Account can not be used to en/decrypt messages. However it can be used to contruct new olm sessions, which in turn do the en/decryption. There is no tracking of sessions in an account.

func AccountFromJSONPickled

func AccountFromJSONPickled(pickled, key []byte) (*Account, error)

AccountFromJSONPickled loads the Account details from a pickled base64 string. The input is decrypted with the supplied key.

func AccountFromPickled

func AccountFromPickled(pickled, key []byte) (*Account, error)

AccountFromPickled loads the Account details from a pickled base64 string. The input is decrypted with the supplied key.

func NewAccount

func NewAccount(reader io.Reader) (*Account, error)

NewAccount creates a new Account. If reader is nil, crypto/rand is used for the key creation.

func (*Account) FallbackKey

func (a *Account) FallbackKey() map[string]id.Curve25519

FallbackKey returns the public part of the current fallback key of the Account. The returned data is a map with the mapping of key id to base64-encoded Curve25519 key.

func (*Account) FallbackKeyJSON

func (a *Account) FallbackKeyJSON() ([]byte, error)

FallbackKeyJSON returns the public part of the current fallback key of the Account as a JSON string.

The returned JSON is of format:

{
    curve25519: {
        "AAAAAA": "wo76WcYtb0Vk/pBOdmduiGJ0wIEjW4IBMbbQn7aSnTo"
    }
}

func (*Account) FallbackKeyUnpublished

func (a *Account) FallbackKeyUnpublished() map[string]id.Curve25519

FallbackKeyUnpublished returns the public part of the current fallback key of the Account only if it is unpublished. The returned data is a map with the mapping of key id to base64-encoded Curve25519 key.

func (*Account) FallbackKeyUnpublishedJSON

func (a *Account) FallbackKeyUnpublishedJSON() ([]byte, error)

FallbackKeyUnpublishedJSON returns the public part of the current fallback key, only if it is unpublished, of the Account as a JSON string.

The returned JSON is of format:

{
    curve25519: {
        "AAAAAA": "wo76WcYtb0Vk/pBOdmduiGJ0wIEjW4IBMbbQn7aSnTo"
    }
}

func (*Account) ForgetOldFallbackKey

func (a *Account) ForgetOldFallbackKey()

ForgetOldFallbackKey resets the previous fallback key in the account.

func (*Account) GenFallbackKey

func (a *Account) GenFallbackKey(reader io.Reader) error

GenFallbackKey generates a new fallback key. The old fallback key is stored in a.PrevFallbackKey overwriting any previous PrevFallbackKey. If reader is nil, crypto/rand is used for the key creation.

func (*Account) GenOneTimeKeys

func (a *Account) GenOneTimeKeys(reader io.Reader, num uint) error

GenOneTimeKeys generates a number of new one time keys. If the total number of keys stored by this Account exceeds MaxOneTimeKeys then the older keys are discarded. If reader is nil, crypto/rand is used for the key creation.

func (*Account) IdentityKeys

func (a *Account) IdentityKeys() (id.Ed25519, id.Curve25519, error)

IdentityKeys returns the public parts of the Ed25519 and Curve25519 identity keys for the Account.

func (*Account) IdentityKeysJSON

func (a *Account) IdentityKeysJSON() ([]byte, error)

IdentityKeysJSON returns the public parts of the identity keys for the Account in a JSON string.

func (*Account) MarkKeysAsPublished

func (a *Account) MarkKeysAsPublished()

MarkKeysAsPublished marks the current set of one time keys and the fallback key as being published.

func (*Account) MaxNumberOfOneTimeKeys

func (a *Account) MaxNumberOfOneTimeKeys() uint

MaxNumberOfOneTimeKeys returns the largest number of one time keys this Account can store.

func (*Account) NewInboundSession

func (a *Account) NewInboundSession(oneTimeKeyMsg string) (olm.Session, error)

NewInboundSession creates a new in-bound session for sending/receiving messages from an incoming PRE_KEY message. Returns error on failure.

func (*Account) NewInboundSessionFrom

func (a *Account) NewInboundSessionFrom(theirIdentityKey *id.Curve25519, oneTimeKeyMsg string) (olm.Session, error)

NewInboundSessionFrom creates a new inbound session from an incoming PRE_KEY message.

func (*Account) NewOutboundSession

func (a *Account) NewOutboundSession(theirIdentityKey, theirOneTimeKey id.Curve25519) (olm.Session, error)

NewOutboundSession creates a new outbound session to a given curve25519 identity Key and one time key.

func (*Account) OneTimeKeys

func (a *Account) OneTimeKeys() (map[string]id.Curve25519, error)

OneTimeKeys returns the public parts of the unpublished one time keys of the Account.

The returned data is a map with the mapping of key id to base64-encoded Curve25519 key.

func (*Account) Pickle

func (a *Account) Pickle(key []byte) ([]byte, error)

Pickle returns a base64 encoded and with key encrypted pickled account using PickleLibOlm().

func (*Account) PickleAsJSON

func (a *Account) PickleAsJSON(key []byte) ([]byte, error)

PickleAsJSON returns an Account as a base64 string encrypted using the supplied key. The unencrypted representation of the Account is in JSON format.

func (*Account) PickleLen

func (a *Account) PickleLen() int

PickleLen returns the number of bytes the pickled Account will have.

func (*Account) PickleLibOlm

func (a *Account) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the Account into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*Account) RemoveOneTimeKeys

func (a *Account) RemoveOneTimeKeys(s olm.Session) error

RemoveOneTimeKeys removes the one time key in this Account which matches the one time key in the session s.

func (*Account) Sign

func (a *Account) Sign(message []byte) ([]byte, error)

Sign returns the base64-encoded signature of a message using the Ed25519 key for this Account.

func (*Account) Unpickle

func (a *Account) Unpickle(pickled, key []byte) error

Unpickle decodes the base64 encoded string and decrypts the result with the key. The decrypted value is then passed to UnpickleLibOlm.

func (*Account) UnpickleAsJSON

func (a *Account) UnpickleAsJSON(pickled, key []byte) error

UnpickleAsJSON updates an Account by a base64 encrypted string using the supplied key. The unencrypted representation has to be in JSON format.

func (*Account) UnpickleLibOlm

func (a *Account) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the Account accordingly. It returns the number of bytes read.

Jump to

Keyboard shortcuts

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