doubleratchet

package
v0.0.0-...-ddb1edc Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSession

func NewSession(sessionID string, expiry uint64) (secret, pubKey string, err error)

NewSession is used by the initiator of the encrypted session. This function takes no paramters and returns:

sessionID: A unique string that identified the session for later use secret: A shared secret to be shared with the other side

This function creates a session and stores its state in the SessionStore Following this operation the caller can imediately use Encrypt/Decrypt by providing the sessionID as identifier.

func NewSessionWithRemoteKey

func NewSessionWithRemoteKey(sessionID, secret, remotePubKey string, expiry uint64) error

NewSessionWithRemoteKey is used by the recepient side of the encrypted session. This function takes the following parameters:

secret: Shared secret that was agreed with the initiator side remotePubKey The initiator side public key.

This function creates a session and stores its state in the SessionStore Following this operation the caller can imediately use Encrypt/Decrypt by providing the sessionID as identifier.

func RatchetDecrypt

func RatchetDecrypt(sessionID, message string) (string, error)

RatchetDecrypt is used to decrypt a message providing a sessionID and a message to decrypt This function loads the session from the session store and use it to decrypt the message. This way the user is free of managing sessions state and only need to provide the sessionID.

func RatchetEncrypt

func RatchetEncrypt(sessionID, message string) (string, error)

RatchetEncrypt is used to encrypt a message providing a sessionID and a message to encrypt This function loads the session from the session store and use it to encrypt the message. This way the user is free of managing sessions state and only need to provide the sessionID.

func RatchetSessionSetInfo

func RatchetSessionSetInfo(sessionID, info string) error

RatchetSessionSetInfo checks if a session matches the sessionID and set its details.

func Start

func Start(dbpath string) error

Start starts the doubleratchet service and makes it ready for action

func Stop

func Stop() error

Stop stops the doubleratchet service and release not needed resources

Types

type BoltDBKeysStorage

type BoltDBKeysStorage struct{}

BoltDBKeysStorage is a structure that implements the KeysStorge interface. Keys are saved for skipped messages that may come later. It uses boltdb to save the keys.

func (*BoltDBKeysStorage) All

All returns all the keys

func (*BoltDBKeysStorage) Count

Count returns number of message keys stored under the specified key.

func (*BoltDBKeysStorage) DeleteMk

func (*BoltDBKeysStorage) DeleteMk(k doubleratchet.Key, msgNum uint) error

DeleteMk ensures there's no message key under the specified key and msgNum.

func (*BoltDBKeysStorage) DeleteOldMks

func (*BoltDBKeysStorage) DeleteOldMks(sessionID []byte, deleteUntilSeqKey uint) error

DeleteOldMks deletes old message keys for a session.

func (*BoltDBKeysStorage) Get

func (*BoltDBKeysStorage) Get(k doubleratchet.Key, msgNum uint) (mk doubleratchet.Key, ok bool, err error)

Get returns a message key by the given key and message number.

func (*BoltDBKeysStorage) Put

func (*BoltDBKeysStorage) Put(sessionID []byte, k doubleratchet.Key, msgNum uint, mk doubleratchet.Key, keySeqNum uint) error

Put saves the given mk under the specified key and msgNum.

func (*BoltDBKeysStorage) TruncateMks

func (*BoltDBKeysStorage) TruncateMks(sessionID []byte, maxKeys int) error

TruncateMks truncates the number of keys to maxKeys. We have short live sessions so currently we don't implemented that

type BoltDBSessionStorage

type BoltDBSessionStorage struct{}

BoltDBSessionStorage is a structure that implements the SessionStore interface. It uses boltdb to save sessions

func (*BoltDBSessionStorage) Load

Load session by id

func (*BoltDBSessionStorage) Save

func (s *BoltDBSessionStorage) Save(id []byte, state *doubleratchet.State) error

Save the session to the session store

type DHPair

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

DHPair is a key pair structure that implements the doubleratchet.DHPair interface

func (DHPair) PrivateKey

func (p DHPair) PrivateKey() doubleratchet.Key

PrivateKey is part of the doubleratchets.DHPair interaface

func (DHPair) PublicKey

func (p DHPair) PublicKey() doubleratchet.Key

PublicKey is part of the doubleratchets.DHPair interaface

type RatchetSessionDetails

type RatchetSessionDetails struct {
	SessionID string
	Initiated bool
	UserInfo  string
}

RatchetSessionDetails represents the info of existing session

func RatchetSessionInfo

func RatchetSessionInfo(sessionID string) *RatchetSessionDetails

RatchetSessionInfo checks if a session matches the sessionID and returns its details.

Jump to

Keyboard shortcuts

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