model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: MIT Imports: 18 Imported by: 9

Documentation

Index

Constants

View Source
const MaxGroupMessageLength = 1800

MaxGroupMessageLength is the maximum length of a message posted to a server group. TODO: Should this be per server?

View Source
const MessageBaseSize = 104

MessageBaseSize is a rough estimate of the base number of bytes the struct uses before strings are populated

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	GroupID        string
	SignedGroupID  []byte
	GroupKey       [32]byte
	GroupServer    string
	Timeline       Timeline `json:"-"`
	Accepted       bool
	Owner          string
	IsCompromised  bool
	InitialMessage []byte
	Attributes     map[string]string

	LocalID string
	State   string `json:"-"`
	// contains filtered or unexported fields
}

Group defines and encapsulates Cwtch's conception of group chat. Which are sessions tied to a server under a given group key. Each group has a set of Messages.

func NewGroup

func NewGroup(server string) (*Group, error)

NewGroup initializes a new group associated with a given CwtchServer

func (*Group) AddMessage

func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte) (*Message, bool)

AddMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline

func (*Group) AddSentMessage

func (g *Group) AddSentMessage(message *protocol.DecryptedGroupMessage, sig []byte) Message

AddSentMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline

func (*Group) Compromised

func (g *Group) Compromised()

Compromised should be called if we detect a a groupkey leak.

func (*Group) DecryptMessage

func (g *Group) DecryptMessage(ciphertext []byte) (bool, *protocol.DecryptedGroupMessage)

DecryptMessage takes a ciphertext and returns true and the decrypted message if the cipher text can be successfully decrypted,else false.

func (*Group) EncryptMessage

func (g *Group) EncryptMessage(message *protocol.DecryptedGroupMessage) ([]byte, error)

EncryptMessage takes a message and encrypts the message under the group key.

func (*Group) GetAttribute

func (g *Group) GetAttribute(name string) (value string, exists bool)

GetAttribute returns the value of a value set with SetAttribute. If no such value has been set exists is set to false.

func (*Group) GetInitialMessage

func (g *Group) GetInitialMessage() []byte

GetInitialMessage returns the first message of the group, if one was sent with the invite.

func (*Group) GetTimeline

func (g *Group) GetTimeline() (timeline []Message)

GetTimeline provides a safe copy of the timeline

func (*Group) Invite

func (g *Group) Invite(initialMessage []byte) ([]byte, error)

Invite generates a invitation that can be sent to a cwtch peer

func (*Group) SetAttribute

func (g *Group) SetAttribute(name string, value string)

SetAttribute allows applications to store arbitrary configuration info at the group level.

func (*Group) SignGroup

func (g *Group) SignGroup(signature []byte)

SignGroup adds a signature to the group.

type Message

type Message struct {
	Timestamp          time.Time
	Received           time.Time
	PeerID             string
	Message            string
	Signature          []byte
	PreviousMessageSig []byte
}

Message is a local representation of a given message sent over a group chat channel.

type Profile

type Profile struct {
	PublicProfile
	Contacts          map[string]*PublicProfile
	Ed25519PrivateKey ed25519.PrivateKey
	Groups            map[string]*Group
}

Profile encapsulates all the attributes necessary to be a Cwtch Peer.

func GenerateNewProfile

func GenerateNewProfile(name string) *Profile

GenerateNewProfile creates a new profile, with new encryption and signing keys, and a profile name.

func (*Profile) AcceptInvite

func (p *Profile) AcceptInvite(groupID string) (err error)

AcceptInvite accepts a group invite

func (*Profile) AddContact

func (p *Profile) AddContact(onion string, profile *PublicProfile)

AddContact allows direct manipulation of cwtch contacts

func (*Profile) AddGroup

func (p *Profile) AddGroup(group *Group)

AddGroup is a convenience method for adding a group to a profile.

func (*Profile) AttemptDecryption

func (p *Profile) AttemptDecryption(ciphertext []byte, signature []byte) (bool, string, *Message, bool)

AttemptDecryption takes a ciphertext and signature and attempts to decrypt it under known groups.

func (*Profile) BlockPeer

func (p *Profile) BlockPeer(onion string) (err error)

BlockPeer blocks a contact

func (*Profile) BlockedPeers

func (p *Profile) BlockedPeers() []string

BlockedPeers calculates a list of Peers who have been Blocked.

func (*Profile) DeleteContact

func (p *Profile) DeleteContact(onion string)

DeleteContact deletes a peer contact

func (*Profile) DeleteGroup

func (p *Profile) DeleteGroup(groupID string)

DeleteGroup deletes a group

func (*Profile) EncryptMessageToGroup

func (p *Profile) EncryptMessageToGroup(message string, groupID string) ([]byte, []byte, error)

EncryptMessageToGroup when given a message and a group, encrypts and signs the message under the group and profile

func (*Profile) GetContact

func (p *Profile) GetContact(onion string) (*PublicProfile, bool)

GetContact returns a contact if the profile has it

func (*Profile) GetContacts

func (p *Profile) GetContacts() []string

GetContacts returns an unordered list of contact onions associated with this profile.

func (*Profile) GetCopy

func (p *Profile) GetCopy(timeline bool) *Profile

GetCopy returns a full deep copy of the Profile struct and its members (timeline inclusion control by arg)

func (*Profile) GetCwtchIdentityPacket

func (p *Profile) GetCwtchIdentityPacket() (message []byte)

GetCwtchIdentityPacket returns the wire message for conveying this profiles identity.

func (*Profile) GetGroupByGroupID

func (p *Profile) GetGroupByGroupID(groupID string) (g *Group)

GetGroupByGroupID a pointer to a Group by the group Id, returns nil if no group found.

func (*Profile) GetGroups

func (p *Profile) GetGroups() []string

GetGroups returns an unordered list of group IDs associated with this profile.

func (*Profile) IsBlocked

func (p *Profile) IsBlocked(onion string) bool

IsBlocked returns true if the contact has been blocked, false otherwise

func (*Profile) ProcessInvite

func (p *Profile) ProcessInvite(gci *protocol.GroupChatInvite, peerHostname string)

ProcessInvite adds a new group invite to the profile.

func (*Profile) RejectInvite

func (p *Profile) RejectInvite(groupID string)

RejectInvite rejects and removes a group invite

func (*Profile) SignMessage

func (p *Profile) SignMessage(message string) []byte

SignMessage takes a given message and returns an Ed21159 signature

func (*Profile) StartGroup

func (p *Profile) StartGroup(server string) (groupID string, invite []byte, err error)

StartGroup when given a server, creates a new Group under this profile and returns the group id an a precomputed invite which can be sent on the wire.

func (*Profile) StartGroupWithMessage

func (p *Profile) StartGroupWithMessage(server string, initialMessage []byte) (groupID string, invite []byte, err error)

StartGroupWithMessage when given a server, and an initial message creates a new Group under this profile and returns the group id an a precomputed invite which can be sent on the wire.

func (*Profile) TrustPeer

func (p *Profile) TrustPeer(onion string) (err error)

TrustPeer sets a contact to trusted

func (*Profile) UnblockPeer

func (p *Profile) UnblockPeer(onion string) (err error)

UnblockPeer unblocks a contact

func (*Profile) VerifyGroupMessage

func (p *Profile) VerifyGroupMessage(onion string, groupID string, message string, timestamp int32, ciphertext []byte, signature []byte) bool

VerifyGroupMessage confirms the authenticity of a message given an onion, message and signature.

type PublicProfile

type PublicProfile struct {
	Name             string
	Ed25519PublicKey ed25519.PublicKey
	Trusted          bool
	Blocked          bool
	Onion            string
	Attributes       map[string]string
	//Timeline         Timeline `json:"-"` // TODO: cache recent messages for client
	LocalID string // used by storage engine
	State   string `json:"-"`
	// contains filtered or unexported fields
}

PublicProfile is a local copy of a CwtchIdentity

func (*PublicProfile) GetAttribute

func (p *PublicProfile) GetAttribute(name string) (value string, exists bool)

GetAttribute returns the value of a value set with SetCustomAttribute. If no such value has been set exists is set to false.

func (*PublicProfile) SetAttribute

func (p *PublicProfile) SetAttribute(name string, value string)

SetAttribute allows applications to store arbitrary configuration info at the profile level.

type Timeline

type Timeline struct {
	Messages      []Message
	SignedGroupID []byte
	// contains filtered or unexported fields
}

Timeline encapsulates a collection of ordered Messages, and a mechanism to access them in a threadsafe manner.

func (*Timeline) GetCopy

func (t *Timeline) GetCopy() *Timeline

GetCopy returns a duplicate of the Timeline

func (*Timeline) GetMessages

func (t *Timeline) GetMessages() []Message

GetMessages returns a copy of the entire timeline

func (*Timeline) Insert

func (t *Timeline) Insert(mi *Message) bool

Insert inserts a message into the timeline in a thread safe way.

func (*Timeline) Len

func (t *Timeline) Len() int

Len gets the length of the timeline

func (*Timeline) Less

func (t *Timeline) Less(i, j int) bool

Less checks 2 Messages (i and j) in the timeline and returns true if i occurred before j, else false

func (*Timeline) SetMessages

func (t *Timeline) SetMessages(messages []Message)

SetMessages sets the Messages of this timeline. Only to be used in loading/initialization

func (*Timeline) Sort

func (t *Timeline) Sort()

Sort sorts the timeline in a canonical order. TODO: There is almost definitely a more efficient way of doing things that involve not calling this method on every timeline load.

func (*Timeline) Swap

func (t *Timeline) Swap(i, j int)

Swap swaps 2 Messages on the timeline.

Jump to

Keyboard shortcuts

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