encryption

package
v0.176.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MPL-2.0, MPL-2.0 Imports: 29 Imported by: 0

README

protocol/encryption package

Hash ratchet encryption

encryptor.GenerateHashRatchetKey() generates a hash ratchet key and stores it in in the DB. There, 2 new tables are created: hash_ratchet_encryption and hash_ratchet_encryption_cache. Each hash ratchet key is uniquely identified by the (groupId, keyId) pair, where keyId is derived from a clock value.

protocol.BuildHashRatchetKeyExchangeMessage builds an 1-on-1 message containing the hash ratchet key, given it's ID.

protocol.BuildHashRatchetMessage builds a hash ratchet message with arbitrary payload, given groupId. It will use the latest hash ratchet key available. encryptor.encryptWithHR encrypts the payload using Hash Ratchet algorithms. Intermediate hashes are stored in hash_ratchet_encryption_cache table.

protocol.HandleMessage uses encryptor.decryptWithHR fn for decryption.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDeviceNotFound = errors.New("device not found")
	// ErrNotPairedDevice means that we received a message signed with our public key
	// but from a device that has not been paired.
	// This should not happen because the protocol forbids sending a message to
	// non-paired devices, however, in theory it is possible to receive such a message.
	ErrNotPairedDevice            = errors.New("received a message from not paired device")
	ErrHashRatchetSeqNoTooHigh    = errors.New("Hash ratchet seq no is too high")
	ErrHashRatchetGroupIDNotFound = errors.New("Hash ratchet group id not found")
	ErrNoEncryptionKey            = errors.New("no encryption key found for the community")
)
View Source
var (
	// ErrNoPayload means that there was no payload found in the received protocol message.
	ErrNoPayload    = errors.New("no payload")
	ErrNoRatchetKey = errors.New("no ratchet key for given keyID")
)
View Source
var File_protocol_message_proto protoreflect.FileDescriptor

Functions

func ExtractIdentity

func ExtractIdentity(bundle *Bundle) (*ecdsa.PublicKey, error)

ExtractIdentity extracts the identity key from a given bundle

func GetCurrentTime added in v0.162.9

func GetCurrentTime() uint64

GetCurrentTime64 returns the current unix time in milliseconds

func PerformActiveDH

func PerformActiveDH(publicKey *ecdsa.PublicKey) ([]byte, *ecdsa.PublicKey, error)

PerformActiveDH performs a Diffie-Hellman exchange using a public key and a generated ephemeral key. Returns the key resulting from the DH exchange as well as the ephemeral public key.

func PerformActiveX3DH

func PerformActiveX3DH(identity []byte, signedPreKey []byte, prv *ecdsa.PrivateKey) ([]byte, *ecdsa.PublicKey, error)

PerformActiveX3DH takes someone else's bundle and calculates shared secret. Returns the shared secret and the ephemeral key used.

func PerformDH

func PerformDH(privateKey *ecies.PrivateKey, publicKey *ecies.PublicKey) ([]byte, error)

PerformDH generates a shared key given a private and a public key

func PerformPassiveX3DH

func PerformPassiveX3DH(theirIdentityKey *ecdsa.PublicKey, mySignedPreKey *ecdsa.PrivateKey, theirEphemeralKey *ecdsa.PublicKey, myPrivateKey *ecdsa.PrivateKey) ([]byte, error)

PerformPassiveX3DH handles the part of the protocol where our interlocutor used our bundle, with ID of the signedPreKey, we loaded our identity key and the correct signedPreKey and we perform X3DH

func SignBundle

func SignBundle(identity *ecdsa.PrivateKey, bundleContainer *BundleContainer) error

SignBundle signs the bundle and refreshes the timestamps

func VerifyBundle

func VerifyBundle(bundle *Bundle) error

VerifyBundle checks that a bundle is valid

Types

type Bundle

type Bundle struct {

	// Identity key
	Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"`
	// Installation id
	SignedPreKeys map[string]*SignedPreKey `` /* 190-byte string literal not displayed */
	// Prekey signature
	Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"`
	// When the bundle was created locally
	Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

X3DH prekey bundle

func (*Bundle) Descriptor deprecated

func (*Bundle) Descriptor() ([]byte, []int)

Deprecated: Use Bundle.ProtoReflect.Descriptor instead.

func (*Bundle) GetIdentity

func (x *Bundle) GetIdentity() []byte

func (*Bundle) GetSignature

func (x *Bundle) GetSignature() []byte

func (*Bundle) GetSignedPreKeys

func (x *Bundle) GetSignedPreKeys() map[string]*SignedPreKey

func (*Bundle) GetTimestamp

func (x *Bundle) GetTimestamp() int64

func (*Bundle) ProtoMessage

func (*Bundle) ProtoMessage()

func (*Bundle) ProtoReflect added in v0.163.14

func (x *Bundle) ProtoReflect() protoreflect.Message

func (*Bundle) Reset

func (x *Bundle) Reset()

func (*Bundle) String

func (x *Bundle) String() string

type BundleContainer

type BundleContainer struct {

	// X3DH prekey bundle
	Bundle *Bundle `protobuf:"bytes,1,opt,name=bundle,proto3" json:"bundle,omitempty"`
	// Private signed prekey
	PrivateSignedPreKey []byte `protobuf:"bytes,2,opt,name=private_signed_pre_key,json=privateSignedPreKey,proto3" json:"private_signed_pre_key,omitempty"`
	// contains filtered or unexported fields
}

func NewBundleContainer

func NewBundleContainer(identity *ecdsa.PrivateKey, installationID string) (*BundleContainer, error)

NewBundleContainer creates a new BundleContainer from an identity private key

func (*BundleContainer) Descriptor deprecated

func (*BundleContainer) Descriptor() ([]byte, []int)

Deprecated: Use BundleContainer.ProtoReflect.Descriptor instead.

func (*BundleContainer) GetBundle

func (x *BundleContainer) GetBundle() *Bundle

func (*BundleContainer) GetPrivateSignedPreKey

func (x *BundleContainer) GetPrivateSignedPreKey() []byte

func (*BundleContainer) ProtoMessage

func (*BundleContainer) ProtoMessage()

func (*BundleContainer) ProtoReflect added in v0.163.14

func (x *BundleContainer) ProtoReflect() protoreflect.Message

func (*BundleContainer) Reset

func (x *BundleContainer) Reset()

func (*BundleContainer) String

func (x *BundleContainer) String() string

type DHHeader

type DHHeader struct {

	// Compressed ephemeral public key
	Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	// contains filtered or unexported fields
}

func (*DHHeader) Descriptor deprecated

func (*DHHeader) Descriptor() ([]byte, []int)

Deprecated: Use DHHeader.ProtoReflect.Descriptor instead.

func (*DHHeader) GetKey

func (x *DHHeader) GetKey() []byte

func (*DHHeader) ProtoMessage

func (*DHHeader) ProtoMessage()

func (*DHHeader) ProtoReflect added in v0.163.14

func (x *DHHeader) ProtoReflect() protoreflect.Message

func (*DHHeader) Reset

func (x *DHHeader) Reset()

func (*DHHeader) String

func (x *DHHeader) String() string

type DRHeader

type DRHeader struct {

	// Current ratchet public key
	Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	// Number of the message in the sending chain
	N uint32 `protobuf:"varint,2,opt,name=n,proto3" json:"n,omitempty"`
	// Length of the previous sending chain
	Pn uint32 `protobuf:"varint,3,opt,name=pn,proto3" json:"pn,omitempty"`
	// Bundle ID
	Id []byte `protobuf:"bytes,4,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

func (*DRHeader) Descriptor deprecated

func (*DRHeader) Descriptor() ([]byte, []int)

Deprecated: Use DRHeader.ProtoReflect.Descriptor instead.

func (*DRHeader) GetId

func (x *DRHeader) GetId() []byte

func (*DRHeader) GetKey

func (x *DRHeader) GetKey() []byte

func (*DRHeader) GetN

func (x *DRHeader) GetN() uint32

func (*DRHeader) GetPn

func (x *DRHeader) GetPn() uint32

func (*DRHeader) ProtoMessage

func (*DRHeader) ProtoMessage()

func (*DRHeader) ProtoReflect added in v0.163.14

func (x *DRHeader) ProtoReflect() protoreflect.Message

func (*DRHeader) Reset

func (x *DRHeader) Reset()

func (*DRHeader) String

func (x *DRHeader) String() string

type DecryptMessageResponse added in v0.59.0

type DecryptMessageResponse struct {
	DecryptedMessage []byte
	Installations    []*multidevice.Installation
	SharedSecrets    []*sharedsecret.Secret
	HashRatchetInfo  []*HashRatchetInfo
}

type EncryptedMessageProtocol added in v0.91.12

type EncryptedMessageProtocol struct {
	X3DHHeader *X3DHHeader `protobuf:"bytes,1,opt,name=X3DH_header,json=X3DHHeader,proto3" json:"X3DH_header,omitempty"`
	DRHeader   *DRHeader   `protobuf:"bytes,2,opt,name=DR_header,json=DRHeader,proto3" json:"DR_header,omitempty"`
	DHHeader   *DHHeader   `protobuf:"bytes,101,opt,name=DH_header,json=DHHeader,proto3" json:"DH_header,omitempty"`
	HRHeader   *HRHeader   `protobuf:"bytes,102,opt,name=HR_header,json=HRHeader,proto3" json:"HR_header,omitempty"`
	// Encrypted payload
	Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
	// contains filtered or unexported fields
}

Direct message value

func (*EncryptedMessageProtocol) Descriptor deprecated added in v0.91.12

func (*EncryptedMessageProtocol) Descriptor() ([]byte, []int)

Deprecated: Use EncryptedMessageProtocol.ProtoReflect.Descriptor instead.

func (*EncryptedMessageProtocol) GetDHHeader added in v0.91.12

func (x *EncryptedMessageProtocol) GetDHHeader() *DHHeader

func (*EncryptedMessageProtocol) GetDRHeader added in v0.91.12

func (x *EncryptedMessageProtocol) GetDRHeader() *DRHeader

func (*EncryptedMessageProtocol) GetHRHeader added in v0.91.12

func (x *EncryptedMessageProtocol) GetHRHeader() *HRHeader

func (*EncryptedMessageProtocol) GetPayload added in v0.91.12

func (x *EncryptedMessageProtocol) GetPayload() []byte

func (*EncryptedMessageProtocol) GetX3DHHeader added in v0.91.12

func (x *EncryptedMessageProtocol) GetX3DHHeader() *X3DHHeader

func (*EncryptedMessageProtocol) ProtoMessage added in v0.91.12

func (*EncryptedMessageProtocol) ProtoMessage()

func (*EncryptedMessageProtocol) ProtoReflect added in v0.163.14

func (x *EncryptedMessageProtocol) ProtoReflect() protoreflect.Message

func (*EncryptedMessageProtocol) Reset added in v0.91.12

func (x *EncryptedMessageProtocol) Reset()

func (*EncryptedMessageProtocol) String added in v0.91.12

func (x *EncryptedMessageProtocol) String() string

type HRCache added in v0.91.12

type HRCache struct {
	GroupID         []byte
	KeyID           []byte
	DeprecatedKeyID uint32
	Key             []byte
	Hash            []byte
	SeqNo           uint32
}

type HRHeader added in v0.91.12

type HRHeader struct {

	// deprecated group key ID
	DeprecatedKeyId uint32 `protobuf:"varint,1,opt,name=deprecated_key_id,json=deprecatedKeyId,proto3" json:"deprecated_key_id,omitempty"`
	// group message number for this key_id
	SeqNo uint32 `protobuf:"varint,2,opt,name=seq_no,json=seqNo,proto3" json:"seq_no,omitempty"`
	// group ID
	GroupId []byte `protobuf:"bytes,3,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"`
	// group key ID
	KeyId []byte  `protobuf:"bytes,4,opt,name=key_id,json=keyId,proto3" json:"key_id,omitempty"`
	Keys  *HRKeys `protobuf:"bytes,5,opt,name=keys,proto3" json:"keys,omitempty"`
	// contains filtered or unexported fields
}

Hash Ratchet Header

func (*HRHeader) Descriptor deprecated added in v0.91.12

func (*HRHeader) Descriptor() ([]byte, []int)

Deprecated: Use HRHeader.ProtoReflect.Descriptor instead.

func (*HRHeader) GetDeprecatedKeyId added in v0.171.5

func (x *HRHeader) GetDeprecatedKeyId() uint32

func (*HRHeader) GetGroupId added in v0.91.12

func (x *HRHeader) GetGroupId() []byte

func (*HRHeader) GetKeyId added in v0.91.12

func (x *HRHeader) GetKeyId() []byte

func (*HRHeader) GetKeys added in v0.174.0

func (x *HRHeader) GetKeys() *HRKeys

func (*HRHeader) GetSeqNo added in v0.91.12

func (x *HRHeader) GetSeqNo() uint32

func (*HRHeader) ProtoMessage added in v0.91.12

func (*HRHeader) ProtoMessage()

func (*HRHeader) ProtoReflect added in v0.163.14

func (x *HRHeader) ProtoReflect() protoreflect.Message

func (*HRHeader) Reset added in v0.91.12

func (x *HRHeader) Reset()

func (*HRHeader) String added in v0.91.12

func (x *HRHeader) String() string

type HRKey added in v0.111.7

type HRKey struct {
	DeprecatedKeyId uint32 `protobuf:"varint,1,opt,name=deprecated_key_id,json=deprecatedKeyId,proto3" json:"deprecated_key_id,omitempty"`
	Key             []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
	Timestamp       uint64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

func (*HRKey) Descriptor deprecated added in v0.111.7

func (*HRKey) Descriptor() ([]byte, []int)

Deprecated: Use HRKey.ProtoReflect.Descriptor instead.

func (*HRKey) GetDeprecatedKeyId added in v0.171.5

func (x *HRKey) GetDeprecatedKeyId() uint32

func (*HRKey) GetKey added in v0.111.7

func (x *HRKey) GetKey() []byte

func (*HRKey) GetTimestamp added in v0.171.5

func (x *HRKey) GetTimestamp() uint64

func (*HRKey) ProtoMessage added in v0.111.7

func (*HRKey) ProtoMessage()

func (*HRKey) ProtoReflect added in v0.163.14

func (x *HRKey) ProtoReflect() protoreflect.Message

func (*HRKey) Reset added in v0.111.7

func (x *HRKey) Reset()

func (*HRKey) String added in v0.111.7

func (x *HRKey) String() string

type HRKeys added in v0.111.7

type HRKeys struct {
	Keys       []*HRKey    `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"`
	RekeyGroup *RekeyGroup `protobuf:"bytes,2,opt,name=rekey_group,json=rekeyGroup,proto3" json:"rekey_group,omitempty"`
	// contains filtered or unexported fields
}

func (*HRKeys) Descriptor deprecated added in v0.111.7

func (*HRKeys) Descriptor() ([]byte, []int)

Deprecated: Use HRKeys.ProtoReflect.Descriptor instead.

func (*HRKeys) GetKeys added in v0.111.7

func (x *HRKeys) GetKeys() []*HRKey

func (*HRKeys) GetRekeyGroup added in v0.171.5

func (x *HRKeys) GetRekeyGroup() *RekeyGroup

func (*HRKeys) ProtoMessage added in v0.111.7

func (*HRKeys) ProtoMessage()

func (*HRKeys) ProtoReflect added in v0.163.14

func (x *HRKeys) ProtoReflect() protoreflect.Message

func (*HRKeys) Reset added in v0.111.7

func (x *HRKeys) Reset()

func (*HRKeys) String added in v0.111.7

func (x *HRKeys) String() string

type HashRatchetInfo added in v0.111.7

type HashRatchetInfo struct {
	GroupID []byte
	KeyID   []byte
}

type HashRatchetKeyCompatibility added in v0.171.5

type HashRatchetKeyCompatibility struct {
	GroupID []byte

	Timestamp uint64
	Key       []byte
	// contains filtered or unexported fields
}

func (*HashRatchetKeyCompatibility) DeprecatedKeyID added in v0.171.5

func (h *HashRatchetKeyCompatibility) DeprecatedKeyID() uint32

func (*HashRatchetKeyCompatibility) GenerateNext added in v0.171.5

func (*HashRatchetKeyCompatibility) GetKeyID added in v0.171.5

func (h *HashRatchetKeyCompatibility) GetKeyID() ([]byte, error)

func (*HashRatchetKeyCompatibility) IsOldFormat added in v0.171.5

func (h *HashRatchetKeyCompatibility) IsOldFormat() bool

type PartitionTopicMode

type PartitionTopicMode int
const (
	PartitionTopicNoSupport PartitionTopicMode = iota
	PartitionTopicV1
)

type Protocol

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

func New

func New(
	db *sql.DB,
	installationID string,
	logger *zap.Logger,
) *Protocol

New creates a new ProtocolService instance

func NewWithEncryptorConfig

func NewWithEncryptorConfig(
	db *sql.DB,
	installationID string,
	encryptorConfig encryptorConfig,
	logger *zap.Logger,
) *Protocol

DB and migrations are shared between encryption package and its sub-packages.

func (*Protocol) BuildBundleAdvertiseMessage

func (p *Protocol) BuildBundleAdvertiseMessage(myIdentityKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey) (*ProtocolMessageSpec, error)

func (*Protocol) BuildDHMessage

func (p *Protocol) BuildDHMessage(myIdentityKey *ecdsa.PrivateKey, destination *ecdsa.PublicKey, payload []byte) (*ProtocolMessageSpec, error)

BuildDHMessage builds a message with DH encryption so that it can be decrypted by any other device.

func (*Protocol) BuildEncryptedMessage added in v0.91.12

func (p *Protocol) BuildEncryptedMessage(myIdentityKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, payload []byte) (*ProtocolMessageSpec, error)

BuildEncryptedMessage returns a 1:1 chat message and optionally a negotiated topic given the user identity private key, the recipient's public key, and a payload

func (*Protocol) BuildHashRatchetKeyExchangeMessage added in v0.91.12

func (p *Protocol) BuildHashRatchetKeyExchangeMessage(myIdentityKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, groupID []byte, ratchets []*HashRatchetKeyCompatibility) (*ProtocolMessageSpec, error)

BuildHashRatchetKeyExchangeMessage builds a 1:1 message containing newly generated hash ratchet key

func (*Protocol) BuildHashRatchetKeyExchangeMessageWithPayload added in v0.174.0

func (p *Protocol) BuildHashRatchetKeyExchangeMessageWithPayload(myIdentityKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, groupID []byte, ratchets []*HashRatchetKeyCompatibility, payload []byte) (*ProtocolMessageSpec, error)

func (*Protocol) BuildHashRatchetMessage added in v0.91.12

func (p *Protocol) BuildHashRatchetMessage(groupID []byte, payload []byte) (*ProtocolMessageSpec, error)

BuildHashRatchetMessage returns a hash ratchet chat message

func (*Protocol) BuildHashRatchetReKeyGroupMessage added in v0.171.5

func (p *Protocol) BuildHashRatchetReKeyGroupMessage(myIdentityKey *ecdsa.PrivateKey, recipients []*ecdsa.PublicKey, groupID []byte, payload []byte, ratchet *HashRatchetKeyCompatibility) (*ProtocolMessageSpec, error)

BuildHashRatchetRekeyGroup builds a public message with the new key

func (*Protocol) BuildPublicMessage

func (p *Protocol) BuildPublicMessage(myIdentityKey *ecdsa.PrivateKey, payload []byte) (*ProtocolMessageSpec, error)

BuildPublicMessage marshals a public chat message given the user identity private key and a payload

func (*Protocol) ConfirmBundleAdvertisement

func (p *Protocol) ConfirmBundleAdvertisement(publicKey *ecdsa.PublicKey, time int64)

func (*Protocol) ConfirmMessageProcessed

func (p *Protocol) ConfirmMessageProcessed(messageID []byte) error

ConfirmMessageProcessed confirms and deletes message keys for the given messages

func (*Protocol) DecryptWithHashRatchet added in v0.171.39

func (p *Protocol) DecryptWithHashRatchet(keyID []byte, seqNo uint32, payload []byte) ([]byte, error)

func (*Protocol) DisableInstallation

func (p *Protocol) DisableInstallation(myIdentityKey *ecdsa.PublicKey, installationID string) error

DisableInstallation disables an installation for multi-device sync.

func (*Protocol) EnableInstallation

func (p *Protocol) EnableInstallation(myIdentityKey *ecdsa.PublicKey, installationID string) error

EnableInstallation enables an installation for multi-device sync.

func (*Protocol) EncryptWithHashRatchet added in v0.171.39

func (p *Protocol) EncryptWithHashRatchet(groupID []byte, payload []byte) ([]byte, *HashRatchetKeyCompatibility, uint32, error)

func (*Protocol) GenerateHashRatchetKey added in v0.102.2

func (p *Protocol) GenerateHashRatchetKey(groupID []byte) (*HashRatchetKeyCompatibility, error)

func (*Protocol) GetAllHRKeys added in v0.176.1

func (p *Protocol) GetAllHRKeys(groupID []byte) (*HRKeys, error)

func (*Protocol) GetAllHRKeysMarshaledV1 deprecated added in v0.176.1

func (p *Protocol) GetAllHRKeysMarshaledV1(groupID []byte) ([]byte, error)

Deprecated: This function is deprecated as it does not marshal groupID. Kept for backward compatibility.

func (*Protocol) GetAllHRKeysMarshaledV2 added in v0.176.1

func (p *Protocol) GetAllHRKeysMarshaledV2(groupID []byte) ([]byte, error)

func (*Protocol) GetBundle

func (p *Protocol) GetBundle(myIdentityKey *ecdsa.PrivateKey) (*Bundle, error)

GetBundle retrieves or creates a X3DH bundle, given a private identity key.

func (*Protocol) GetCurrentKeyForGroup added in v0.102.2

func (p *Protocol) GetCurrentKeyForGroup(groupID []byte) (*HashRatchetKeyCompatibility, error)

func (*Protocol) GetHRKeys added in v0.176.1

func (p *Protocol) GetHRKeys(ratchets []*HashRatchetKeyCompatibility) *HRKeys

func (*Protocol) GetKeyExMessageSpecs added in v0.102.2

func (p *Protocol) GetKeyExMessageSpecs(groupID []byte, identity *ecdsa.PrivateKey, recipients []*ecdsa.PublicKey, forceRekey bool) ([]*ProtocolMessageSpec, error)

func (*Protocol) GetKeysForGroup added in v0.171.5

func (p *Protocol) GetKeysForGroup(groupID []byte) ([]*HashRatchetKeyCompatibility, error)

GetKeyIDsForGroup returns a slice of key IDs belonging to a given group ID

func (*Protocol) GetMultiDevice added in v0.134.0

func (p *Protocol) GetMultiDevice() *multidevice.Multidevice

func (*Protocol) GetOurActiveInstallations

func (p *Protocol) GetOurActiveInstallations(myIdentityKey *ecdsa.PublicKey) ([]*multidevice.Installation, error)

GetOurActiveInstallations returns all the active installations available given an identity

func (*Protocol) GetOurInstallations

func (p *Protocol) GetOurInstallations(myIdentityKey *ecdsa.PublicKey) ([]*multidevice.Installation, error)

GetOurInstallations returns all the installations available given an identity

func (*Protocol) GetPublicBundle

func (p *Protocol) GetPublicBundle(theirIdentityKey *ecdsa.PublicKey) (*Bundle, error)

GetPublicBundle retrieves a public bundle given an identity

func (*Protocol) HandleHashRatchetHeadersPayload added in v0.176.1

func (p *Protocol) HandleHashRatchetHeadersPayload(encodedHeaders [][]byte) error

func (*Protocol) HandleHashRatchetKeys added in v0.114.4

func (p *Protocol) HandleHashRatchetKeys(groupID []byte, keys *HRKeys, myIdentityKey *ecdsa.PrivateKey, theirIdentityKey *ecdsa.PublicKey) ([]*HashRatchetInfo, error)

func (*Protocol) HandleHashRatchetKeysPayload added in v0.174.0

func (p *Protocol) HandleHashRatchetKeysPayload(groupID, encodedKeys []byte, myIdentityKey *ecdsa.PrivateKey, theirIdentityKey *ecdsa.PublicKey) ([]*HashRatchetInfo, error)

func (*Protocol) HandleMessage

func (p *Protocol) HandleMessage(
	myIdentityKey *ecdsa.PrivateKey,
	theirPublicKey *ecdsa.PublicKey,
	protocolMessage *ProtocolMessage,
	messageID []byte,
) (*DecryptMessageResponse, error)

HandleMessage unmarshals a message and processes it, decrypting it if it is a 1:1 message.

func (*Protocol) ProcessPublicBundle

func (p *Protocol) ProcessPublicBundle(myIdentityKey *ecdsa.PrivateKey, bundle *Bundle) ([]*multidevice.Installation, error)

ProcessPublicBundle processes a received X3DH bundle.

func (*Protocol) SetInstallationMetadata

func (p *Protocol) SetInstallationMetadata(myIdentityKey *ecdsa.PublicKey, installationID string, data *multidevice.InstallationMetadata) error

SetInstallationMetadata sets the metadata for our own installation

func (*Protocol) SetInstallationName added in v0.138.8

func (p *Protocol) SetInstallationName(myIdentityKey *ecdsa.PublicKey, installationID string, name string) error

SetInstallationName sets the metadata for our own installation

func (*Protocol) ShouldAdvertiseBundle

func (p *Protocol) ShouldAdvertiseBundle(publicKey *ecdsa.PublicKey, time int64) (bool, error)

func (*Protocol) Start

func (p *Protocol) Start(myIdentity *ecdsa.PrivateKey) (*Subscriptions, error)

func (*Protocol) Stop added in v0.59.0

func (p *Protocol) Stop() error

type ProtocolMessage

type ProtocolMessage struct {

	// The device id of the sender
	InstallationId string `protobuf:"bytes,2,opt,name=installation_id,json=installationId,proto3" json:"installation_id,omitempty"`
	// List of bundles
	Bundles []*Bundle `protobuf:"bytes,3,rep,name=bundles,proto3" json:"bundles,omitempty"`
	// One to one message, encrypted, indexed by installation_id
	// TODO map here is redundant in case of community messages
	EncryptedMessage map[string]*EncryptedMessageProtocol `` /* 199-byte string literal not displayed */
	// Public chats, not encrypted
	PublicMessage []byte `protobuf:"bytes,102,opt,name=public_message,json=publicMessage,proto3" json:"public_message,omitempty"`
	// contains filtered or unexported fields
}

Top-level protocol message

func (*ProtocolMessage) Descriptor deprecated

func (*ProtocolMessage) Descriptor() ([]byte, []int)

Deprecated: Use ProtocolMessage.ProtoReflect.Descriptor instead.

func (*ProtocolMessage) GetBundles

func (x *ProtocolMessage) GetBundles() []*Bundle

func (*ProtocolMessage) GetEncryptedMessage added in v0.91.12

func (x *ProtocolMessage) GetEncryptedMessage() map[string]*EncryptedMessageProtocol

func (*ProtocolMessage) GetInstallationId

func (x *ProtocolMessage) GetInstallationId() string

func (*ProtocolMessage) GetPublicMessage

func (x *ProtocolMessage) GetPublicMessage() []byte

func (*ProtocolMessage) ProtoMessage

func (*ProtocolMessage) ProtoMessage()

func (*ProtocolMessage) ProtoReflect added in v0.163.14

func (x *ProtocolMessage) ProtoReflect() protoreflect.Message

func (*ProtocolMessage) Reset

func (x *ProtocolMessage) Reset()

func (*ProtocolMessage) String

func (x *ProtocolMessage) String() string

type ProtocolMessageSpec

type ProtocolMessageSpec struct {
	Message *ProtocolMessage
	// Installations is the targeted devices
	Installations []*multidevice.Installation
	// SharedSecret is a shared secret established among the installations
	SharedSecret *sharedsecret.Secret
	// AgreedSecret indicates whether the shared secret has been agreed
	AgreedSecret bool
	// Public means that the spec contains a public wrapped message
	Public bool
}

func (*ProtocolMessageSpec) MinVersion

func (p *ProtocolMessageSpec) MinVersion() uint32

func (*ProtocolMessageSpec) PartitionedTopicMode

func (p *ProtocolMessageSpec) PartitionedTopicMode() PartitionTopicMode

type RatchetInfo

type RatchetInfo struct {
	ID             []byte
	Sk             []byte
	PrivateKey     []byte
	PublicKey      []byte
	Identity       []byte
	BundleID       []byte
	EphemeralKey   []byte
	InstallationID string
}

RatchetInfo holds the current ratchet state.

type RekeyGroup added in v0.171.5

type RekeyGroup struct {
	Timestamp uint64            `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Keys      map[uint32][]byte `` /* 150-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*RekeyGroup) Descriptor deprecated added in v0.171.5

func (*RekeyGroup) Descriptor() ([]byte, []int)

Deprecated: Use RekeyGroup.ProtoReflect.Descriptor instead.

func (*RekeyGroup) GetKeys added in v0.171.5

func (x *RekeyGroup) GetKeys() map[uint32][]byte

func (*RekeyGroup) GetTimestamp added in v0.171.5

func (x *RekeyGroup) GetTimestamp() uint64

func (*RekeyGroup) ProtoMessage added in v0.171.5

func (*RekeyGroup) ProtoMessage()

func (*RekeyGroup) ProtoReflect added in v0.171.5

func (x *RekeyGroup) ProtoReflect() protoreflect.Message

func (*RekeyGroup) Reset added in v0.171.5

func (x *RekeyGroup) Reset()

func (*RekeyGroup) String added in v0.171.5

func (x *RekeyGroup) String() string

type SignedPreKey

type SignedPreKey struct {
	SignedPreKey    []byte `protobuf:"bytes,1,opt,name=signed_pre_key,json=signedPreKey,proto3" json:"signed_pre_key,omitempty"`
	Version         uint32 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
	ProtocolVersion uint32 `protobuf:"varint,3,opt,name=protocol_version,json=protocolVersion,proto3" json:"protocol_version,omitempty"`
	// contains filtered or unexported fields
}

func (*SignedPreKey) Descriptor deprecated

func (*SignedPreKey) Descriptor() ([]byte, []int)

Deprecated: Use SignedPreKey.ProtoReflect.Descriptor instead.

func (*SignedPreKey) GetProtocolVersion

func (x *SignedPreKey) GetProtocolVersion() uint32

func (*SignedPreKey) GetSignedPreKey

func (x *SignedPreKey) GetSignedPreKey() []byte

func (*SignedPreKey) GetVersion

func (x *SignedPreKey) GetVersion() uint32

func (*SignedPreKey) ProtoMessage

func (*SignedPreKey) ProtoMessage()

func (*SignedPreKey) ProtoReflect added in v0.163.14

func (x *SignedPreKey) ProtoReflect() protoreflect.Message

func (*SignedPreKey) Reset

func (x *SignedPreKey) Reset()

func (*SignedPreKey) String

func (x *SignedPreKey) String() string

type Subscriptions added in v0.59.0

type Subscriptions struct {
	SharedSecrets   []*sharedsecret.Secret
	SendContactCode <-chan struct{}
	Quit            chan struct{}
}

type X3DHHeader

type X3DHHeader struct {

	// Ephemeral key used
	Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	// Used bundle's signed prekey
	Id []byte `protobuf:"bytes,4,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

func (*X3DHHeader) Descriptor deprecated

func (*X3DHHeader) Descriptor() ([]byte, []int)

Deprecated: Use X3DHHeader.ProtoReflect.Descriptor instead.

func (*X3DHHeader) GetId

func (x *X3DHHeader) GetId() []byte

func (*X3DHHeader) GetKey

func (x *X3DHHeader) GetKey() []byte

func (*X3DHHeader) ProtoMessage

func (*X3DHHeader) ProtoMessage()

func (*X3DHHeader) ProtoReflect added in v0.163.14

func (x *X3DHHeader) ProtoReflect() protoreflect.Message

func (*X3DHHeader) Reset

func (x *X3DHHeader) Reset()

func (*X3DHHeader) String

func (x *X3DHHeader) String() string

Directories

Path Synopsis
github.com

Jump to

Keyboard shortcuts

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