libolm

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

Account stores a device account for end to end encrypted messaging.

func AccountFromPickled

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

AccountFromPickled loads an Account from a pickled base64 string. Decrypts the Account using the supplied key. Returns error on failure. If the key doesn't match the one used to encrypt the Account then the error will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then the error will be "INVALID_BASE64".

func NewAccount

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

NewAccount creates a new Account.

func NewBlankAccount

func NewBlankAccount() *Account

func (*Account) Clear

func (a *Account) Clear() error

Clear clears the memory used to back this Account.

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 MaxNumberOfOneTimeKeys then the old keys are discarded.

func (*Account) GobDecode

func (a *Account) GobDecode(rawPickled []byte) error

Deprecated

func (*Account) GobEncode

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

Deprecated

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.

func (*Account) MarkKeysAsPublished

func (a *Account) MarkKeysAsPublished()

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

func (*Account) MarshalJSON

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

Deprecated

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. If the base64 couldn't be decoded then the error will be "INVALID_BASE64". If the message was for an unsupported protocol version then the error will be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then the error will be "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time key then the error will be "BAD_MESSAGE_KEY_ID".

func (*Account) NewInboundSessionFrom

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

NewInboundSessionFrom creates a new in-bound session for sending/receiving messages from an incoming PRE_KEY message. Returns error on failure. If the base64 couldn't be decoded then the error will be "INVALID_BASE64". If the message was for an unsupported protocol version then the error will be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then the error will be "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time key then the error will be "BAD_MESSAGE_KEY_ID".

func (*Account) NewOutboundSession

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

NewOutboundSession creates a new out-bound session for sending messages to a given curve25519 identityKey and oneTimeKey. Returns error on failure. If the keys couldn't be decoded as base64 then the error will be "INVALID_BASE64"

func (*Account) OneTimeKeys

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

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

The returned data is a struct with the single value "Curve25519", which is itself an object mapping key id to base64-encoded Curve25519 key. For example:

{
    Curve25519: {
        "AAAAAA": "wo76WcYtb0Vk/pBOdmduiGJ0wIEjW4IBMbbQn7aSnTo",
        "AAAAAB": "LRvjo46L1X2vx69sS9QNFD29HWulxrmW11Up5AfAjgU"
    }
}

func (*Account) Pickle

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

Pickle returns an Account as a base64 string. Encrypts the Account using the supplied key.

func (*Account) RemoveOneTimeKeys

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

RemoveOneTimeKeys removes the one time keys that the session used from the Account. Returns error on failure. If the Account doesn't have any matching one time keys then the error will be "BAD_MESSAGE_KEY_ID".

func (*Account) Sign

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

Sign returns the signature of a message using the ed25519 key for this Account.

func (*Account) UnmarshalJSON

func (a *Account) UnmarshalJSON(data []byte) error

Deprecated

func (*Account) Unpickle

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

type InboundGroupSession

type InboundGroupSession struct {
	// contains filtered or unexported fields
}

InboundGroupSession stores an inbound encrypted messaging session for a group.

func InboundGroupSessionFromPickled

func InboundGroupSessionFromPickled(pickled, key []byte) (*InboundGroupSession, error)

InboundGroupSessionFromPickled loads an InboundGroupSession from a pickled base64 string. Decrypts the InboundGroupSession using the supplied key. Returns error on failure. If the key doesn't match the one used to encrypt the InboundGroupSession then the error will be "BAD_SESSION_KEY". If the base64 couldn't be decoded then the error will be "INVALID_BASE64".

func InboundGroupSessionImport

func InboundGroupSessionImport(sessionKey []byte) (*InboundGroupSession, error)

InboundGroupSessionImport imports an inbound group session from a previous export. Returns error on failure. If the sessionKey is not valid base64 the error will be "OLM_INVALID_BASE64". If the session_key is invalid the error will be "OLM_BAD_SESSION_KEY".

func NewBlankInboundGroupSession

func NewBlankInboundGroupSession() *InboundGroupSession

newInboundGroupSession initialises an empty InboundGroupSession.

func NewInboundGroupSession

func NewInboundGroupSession(sessionKey []byte) (*InboundGroupSession, error)

NewInboundGroupSession creates a new inbound group session from a key exported from OutboundGroupSession.Key(). Returns error on failure. If the sessionKey is not valid base64 the error will be "OLM_INVALID_BASE64". If the session_key is invalid the error will be "OLM_BAD_SESSION_KEY".

func (*InboundGroupSession) Clear

func (s *InboundGroupSession) Clear() error

Clear clears the memory used to back this InboundGroupSession.

func (*InboundGroupSession) Decrypt

func (s *InboundGroupSession) Decrypt(message []byte) ([]byte, uint, error)

Decrypt decrypts a message using the InboundGroupSession. Returns the the plain-text and message index on success. Returns error on failure. If the base64 couldn't be decoded then the error will be "INVALID_BASE64". If the message is for an unsupported version of the protocol then the error will be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then the error will be BAD_MESSAGE_FORMAT". If the MAC on the message was invalid then the error will be "BAD_MESSAGE_MAC". If we do not have a session key corresponding to the message's index (ie, it was sent before the session key was shared with us) the error will be "OLM_UNKNOWN_MESSAGE_INDEX".

func (*InboundGroupSession) Export

func (s *InboundGroupSession) Export(messageIndex uint32) ([]byte, error)

Export returns the base64-encoded ratchet key for this session, at the given index, in a format which can be used by InboundGroupSession.InboundGroupSessionImport(). Encrypts the InboundGroupSession using the supplied key. Returns error on failure. if we do not have a session key corresponding to the given index (ie, it was sent before the session key was shared with us) the error will be "OLM_UNKNOWN_MESSAGE_INDEX".

func (*InboundGroupSession) FirstKnownIndex

func (s *InboundGroupSession) FirstKnownIndex() uint32

FirstKnownIndex returns the first message index we know how to decrypt.

func (*InboundGroupSession) GobDecode

func (s *InboundGroupSession) GobDecode(rawPickled []byte) error

Deprecated

func (*InboundGroupSession) GobEncode

func (s *InboundGroupSession) GobEncode() ([]byte, error)

Deprecated

func (*InboundGroupSession) ID

ID returns a base64-encoded identifier for this session.

func (*InboundGroupSession) IsVerified

func (s *InboundGroupSession) IsVerified() bool

IsVerified check if the session has been verified as a valid session. (A session is verified either because the original session share was signed, or because we have subsequently successfully decrypted a message.)

func (*InboundGroupSession) MarshalJSON

func (s *InboundGroupSession) MarshalJSON() ([]byte, error)

Deprecated

func (*InboundGroupSession) Pickle

func (s *InboundGroupSession) Pickle(key []byte) ([]byte, error)

Pickle returns an InboundGroupSession as a base64 string. Encrypts the InboundGroupSession using the supplied key.

func (*InboundGroupSession) UnmarshalJSON

func (s *InboundGroupSession) UnmarshalJSON(data []byte) error

Deprecated

func (*InboundGroupSession) Unpickle

func (s *InboundGroupSession) Unpickle(pickled, key []byte) error

type OutboundGroupSession

type OutboundGroupSession struct {
	// contains filtered or unexported fields
}

OutboundGroupSession stores an outbound encrypted messaging session for a group.

func NewBlankOutboundGroupSession

func NewBlankOutboundGroupSession() *OutboundGroupSession

NewBlankOutboundGroupSession initialises an empty OutboundGroupSession.

func NewOutboundGroupSession

func NewOutboundGroupSession() *OutboundGroupSession

func (*OutboundGroupSession) Clear

func (s *OutboundGroupSession) Clear() error

Clear clears the memory used to back this OutboundGroupSession.

func (*OutboundGroupSession) Encrypt

func (s *OutboundGroupSession) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts a message using the Session. Returns the encrypted message as base64.

func (*OutboundGroupSession) GobDecode

func (s *OutboundGroupSession) GobDecode(rawPickled []byte) error

Deprecated

func (*OutboundGroupSession) GobEncode

func (s *OutboundGroupSession) GobEncode() ([]byte, error)

Deprecated

func (*OutboundGroupSession) ID

ID returns a base64-encoded identifier for this session.

func (*OutboundGroupSession) Key

func (s *OutboundGroupSession) Key() string

Key returns the base64-encoded current ratchet key for this session.

func (*OutboundGroupSession) MarshalJSON

func (s *OutboundGroupSession) MarshalJSON() ([]byte, error)

Deprecated

func (*OutboundGroupSession) MessageIndex

func (s *OutboundGroupSession) MessageIndex() uint

MessageIndex returns the message index for this session. Each message is sent with an increasing index; this returns the index for the next message.

func (*OutboundGroupSession) Pickle

func (s *OutboundGroupSession) Pickle(key []byte) ([]byte, error)

Pickle returns an OutboundGroupSession as a base64 string. Encrypts the OutboundGroupSession using the supplied key.

func (*OutboundGroupSession) UnmarshalJSON

func (s *OutboundGroupSession) UnmarshalJSON(data []byte) error

Deprecated

func (*OutboundGroupSession) Unpickle

func (s *OutboundGroupSession) Unpickle(pickled, key []byte) error

type PKDecryption

type PKDecryption struct {
	// contains filtered or unexported fields
}

func NewPkDecryption

func NewPkDecryption(privateKey []byte) (*PKDecryption, error)

func (*PKDecryption) Decrypt

func (p *PKDecryption) Decrypt(ephemeralKey []byte, mac []byte, ciphertext []byte) ([]byte, error)

func (*PKDecryption) PublicKey

func (p *PKDecryption) PublicKey() id.Curve25519

type PKSigning

type PKSigning struct {
	// contains filtered or unexported fields
}

PKSigning stores a key pair for signing messages.

func NewPKSigning

func NewPKSigning() (*PKSigning, error)

NewPKSigning creates a new PKSigning object, containing a key pair for signing messages.

func NewPKSigningFromSeed

func NewPKSigningFromSeed(seed []byte) (*PKSigning, error)

NewPKSigningFromSeed creates a new PKSigning object using the given seed.

func (*PKSigning) PublicKey

func (p *PKSigning) PublicKey() id.Ed25519

func (*PKSigning) Seed

func (p *PKSigning) Seed() []byte

func (*PKSigning) Sign

func (p *PKSigning) Sign(message []byte) ([]byte, error)

Sign creates a signature for the given message using this key.

func (*PKSigning) SignJSON

func (p *PKSigning) SignJSON(obj interface{}) (string, error)

SignJSON creates a signature for the given object after encoding it to canonical JSON.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session stores an end to end encrypted messaging session.

func NewBlankSession

func NewBlankSession() *Session

func SessionFromPickled

func SessionFromPickled(pickled, key []byte) (*Session, error)

SessionFromPickled loads a Session from a pickled base64 string. Decrypts the Session using the supplied key. Returns error on failure. If the key doesn't match the one used to encrypt the Session then the error will be "BAD_SESSION_KEY". If the base64 couldn't be decoded then the error will be "INVALID_BASE64".

func (*Session) Clear

func (s *Session) Clear() error

Clear clears the memory used to back this Session.

func (*Session) Decrypt

func (s *Session) Decrypt(message string, msgType id.OlmMsgType) ([]byte, error)

Decrypt decrypts a message using the Session. Returns the the plain-text on success. Returns error on failure. If the base64 couldn't be decoded then the error will be "INVALID_BASE64". If the message is for an unsupported version of the protocol then the error will be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then the error will be BAD_MESSAGE_FORMAT". If the MAC on the message was invalid then the error will be "BAD_MESSAGE_MAC".

func (*Session) Describe

func (s *Session) Describe() string

Describe generates a string describing the internal state of an olm session for debugging and logging purposes.

func (*Session) Encrypt

func (s *Session) Encrypt(plaintext []byte) (id.OlmMsgType, []byte, error)

Encrypt encrypts a message using the Session. Returns the encrypted message as base64.

func (*Session) EncryptMsgType

func (s *Session) EncryptMsgType() id.OlmMsgType

EncryptMsgType returns the type of the next message that Encrypt will return. Returns MsgTypePreKey if the message will be a PRE_KEY message. Returns MsgTypeMsg if the message will be a normal message. Returns error on failure.

func (*Session) GobDecode

func (s *Session) GobDecode(rawPickled []byte) error

Deprecated

func (*Session) GobEncode

func (s *Session) GobEncode() ([]byte, error)

Deprecated

func (*Session) HasReceivedMessage

func (s *Session) HasReceivedMessage() bool

HasReceivedMessage returns true if this session has received any message.

func (*Session) ID

func (s *Session) ID() id.SessionID

Id returns an identifier for this Session. Will be the same for both ends of the conversation.

func (*Session) MarshalJSON

func (s *Session) MarshalJSON() ([]byte, error)

Deprecated

func (*Session) MatchesInboundSession

func (s *Session) MatchesInboundSession(oneTimeKeyMsg string) (bool, error)

MatchesInboundSession checks if the PRE_KEY message is for this in-bound Session. This can happen if multiple messages are sent to this Account before this Account sends a message in reply. Returns true if the session matches. Returns false if the session does not match. Returns error on failure. If the base64 couldn't be decoded then the error will be "INVALID_BASE64". If the message was for an unsupported protocol version then the error will be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then the error will be "BAD_MESSAGE_FORMAT".

func (*Session) MatchesInboundSessionFrom

func (s *Session) MatchesInboundSessionFrom(theirIdentityKey, oneTimeKeyMsg string) (bool, error)

MatchesInboundSessionFrom checks if the PRE_KEY message is for this in-bound Session. This can happen if multiple messages are sent to this Account before this Account sends a message in reply. Returns true if the session matches. Returns false if the session does not match. Returns error on failure. If the base64 couldn't be decoded then the error will be "INVALID_BASE64". If the message was for an unsupported protocol version then the error will be "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then the error will be "BAD_MESSAGE_FORMAT".

func (*Session) Pickle

func (s *Session) Pickle(key []byte) ([]byte, error)

Pickle returns a Session as a base64 string. Encrypts the Session using the supplied key.

func (*Session) UnmarshalJSON

func (s *Session) UnmarshalJSON(data []byte) error

Deprecated

func (*Session) Unpickle

func (s *Session) Unpickle(pickled, key []byte) error

Unpickle unpickles the base64-encoded Olm session decrypting it with the provided key. This function mutates the input pickled data slice.

Jump to

Keyboard shortcuts

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