protohush

package
v0.0.0-...-2c4dd60 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolName = "protohush"

Variables

View Source
var (
	ErrInvalidSignature = errors.New("invalid signature")
	ErrInvalidDHPubkey  = errors.New("invalid DH pubkey")
	ErrEpochTooLow      = errors.New("epoch too low")
)
View Source
var (
	ErrRecipientIsSelf = errors.New("recipient is self")
)
View Source
var GenerateSharedKey = pb.GenerateSharedKey
View Source
var IndividualMessageFromDoubleRatchetMessage = pb.IndividualMessageFromDoubleRatchetMessage

Functions

func NewDecryptIncomingGroupMessagesTask

func NewDecryptIncomingGroupMessagesTask(
	interval time.Duration,
	hushProto *hushProtocol,
) *decryptIncomingGroupMessagesTask

func NewDecryptIncomingIndividualMessagesTask

func NewDecryptIncomingIndividualMessagesTask(
	interval time.Duration,
	hushProto *hushProtocol,
) *decryptIncomingIndividualMessagesTask

func NewExchangeDHPubkeysTask

func NewExchangeDHPubkeysTask(
	interval time.Duration,
	hushProto *hushProtocol,
) *exchangeDHPubkeysTask

func NewHushProtocol

func NewHushProtocol(
	transports []swarm.Transport,
	store Store,
	keyStore identity.KeyStore,
	peerStore swarm.PeerStore,
) *hushProtocol

func NewStore

func NewStore(db *state.DBTree) *store

Types

type BaseHushTransport

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

func (*BaseHushTransport) HandleIncomingDHPubkeyAttestations

func (t *BaseHushTransport) HandleIncomingDHPubkeyAttestations(ctx context.Context, attestations []DHPubkeyAttestation, peerConn HushPeerConn)

func (*BaseHushTransport) HandleIncomingGroupMessage

func (t *BaseHushTransport) HandleIncomingGroupMessage(ctx context.Context, msg GroupMessage, peerConn HushPeerConn)

func (*BaseHushTransport) HandleIncomingIndividualMessage

func (t *BaseHushTransport) HandleIncomingIndividualMessage(ctx context.Context, msg IndividualMessage, peerConn HushPeerConn)

func (*BaseHushTransport) HandleIncomingIndividualSessionProposal

func (t *BaseHushTransport) HandleIncomingIndividualSessionProposal(ctx context.Context, encryptedProposal []byte, alice HushPeerConn)

func (*BaseHushTransport) HandleIncomingIndividualSessionResponse

func (t *BaseHushTransport) HandleIncomingIndividualSessionResponse(ctx context.Context, approval IndividualSessionResponse, bob HushPeerConn)

func (*BaseHushTransport) OnIncomingDHPubkeyAttestations

func (t *BaseHushTransport) OnIncomingDHPubkeyAttestations(handler IncomingDHPubkeyAttestationsCallback)

func (*BaseHushTransport) OnIncomingGroupMessage

func (t *BaseHushTransport) OnIncomingGroupMessage(handler IncomingGroupMessageCallback)

func (*BaseHushTransport) OnIncomingIndividualMessage

func (t *BaseHushTransport) OnIncomingIndividualMessage(handler IncomingIndividualMessageCallback)

func (*BaseHushTransport) OnIncomingIndividualSessionProposal

func (t *BaseHushTransport) OnIncomingIndividualSessionProposal(handler IncomingIndividualSessionProposalCallback)

func (*BaseHushTransport) OnIncomingIndividualSessionResponse

func (t *BaseHushTransport) OnIncomingIndividualSessionResponse(handler IncomingIndividualSessionResponseCallback)

type DHPair

type DHPair = pb.DHPair

type DHPubkeyAttestation

type DHPubkeyAttestation = pb.DHPubkeyAttestation

type EncryptedIndividualSessionProposal

type EncryptedIndividualSessionProposal struct {
	AliceAddr         types.Address `tree:"aliceAddr"`
	EncryptedProposal []byte        `tree:"encryptedProposal"`
}

func (EncryptedIndividualSessionProposal) Hash

type GroupMessage

type GroupMessage = pb.GroupMessage

type GroupSessionID = pb.GroupSessionID type GroupSessionProposal = pb.GroupSessionProposal

type GroupMessageDecryptedCallback

type GroupMessageDecryptedCallback func(sender types.Address, plaintext []byte, msg GroupMessage)

type GroupMessageEncryptedCallback

type GroupMessageEncryptedCallback func(msg GroupMessage)

type GroupMessageIntent

type GroupMessageIntent struct {
	SessionType string          `tree:"sessionType"`
	ID          string          `tree:"id"`
	Recipients  []types.Address `tree:"recipients"`
	Plaintext   []byte          `tree:"plaintext"`
}

type GroupMessage_EncryptionKey

type GroupMessage_EncryptionKey = pb.GroupMessage_EncryptionKey

type HushPeerConn

type HushPeerConn interface {
	swarm.PeerConn
	SendDHPubkeyAttestations(ctx context.Context, attestations []DHPubkeyAttestation) error
	ProposeIndividualSession(ctx context.Context, encryptedProposal []byte) error
	RespondToIndividualSession(ctx context.Context, approval IndividualSessionResponse) error
	SendHushIndividualMessage(ctx context.Context, msg IndividualMessage) error
	SendHushGroupMessage(ctx context.Context, msg GroupMessage) error
}

type HushProtocol

type HushProtocol interface {
	process.Interface

	EnsureIndividualSession(ctx context.Context, sessionType string, recipient types.Address) (IndividualSessionProposal, bool, error)
	ProposeIndividualSession(ctx context.Context, sessionType string, recipient types.Address, epoch uint64) (IndividualSessionProposal, error)
	ProposeNextIndividualSession(ctx context.Context, sessionType string, recipient types.Address) (IndividualSessionProposal, error)

	EncryptIndividualMessage(sessionType string, recipient types.Address, plaintext []byte) error
	OnIndividualMessageDecrypted(sessionType string, handler IndividualMessageDecryptedCallback)

	EncryptGroupMessage(sessionType, messageID string, recipients []types.Address, plaintext []byte) error
	DecryptGroupMessage(msg GroupMessage) error
	OnGroupMessageEncrypted(sessionType string, handler GroupMessageEncryptedCallback)
	OnGroupMessageDecrypted(sessionType string, handler GroupMessageDecryptedCallback)
}

type HushTransport

type HushTransport interface {
	swarm.Transport
	OnIncomingDHPubkeyAttestations(handler IncomingDHPubkeyAttestationsCallback)
	OnIncomingIndividualSessionProposal(handler IncomingIndividualSessionProposalCallback)
	OnIncomingIndividualSessionResponse(handler IncomingIndividualSessionResponseCallback)
	OnIncomingIndividualMessage(handler IncomingIndividualMessageCallback)
	OnIncomingGroupMessage(handler IncomingGroupMessageCallback)
}

type IncomingDHPubkeyAttestationsCallback

type IncomingDHPubkeyAttestationsCallback func(ctx context.Context, attestations []DHPubkeyAttestation, peer HushPeerConn)

type IncomingGroupMessageCallback

type IncomingGroupMessageCallback func(ctx context.Context, msg GroupMessage, peer HushPeerConn)

type IncomingIndividualMessageCallback

type IncomingIndividualMessageCallback func(ctx context.Context, msg IndividualMessage, peer HushPeerConn)

type IncomingIndividualSessionProposalCallback

type IncomingIndividualSessionProposalCallback func(ctx context.Context, encryptedProposal []byte, alice HushPeerConn)

type IncomingIndividualSessionResponseCallback

type IncomingIndividualSessionResponseCallback func(ctx context.Context, approval IndividualSessionResponse, bob HushPeerConn)

type IndividualMessage

type IndividualMessage = pb.IndividualMessage

type IndividualMessageDecryptedCallback

type IndividualMessageDecryptedCallback func(sender types.Address, plaintext []byte, msg IndividualMessage)

type IndividualMessageHeader

type IndividualMessageHeader = pb.IndividualMessage_Header

type IndividualMessageIntent

type IndividualMessageIntent struct {
	ID          types.ID      `tree:"id"`
	SessionType string        `tree:"sessionType"`
	Recipient   types.Address `tree:"recipient"`
	Plaintext   []byte        `tree:"plaintext"`
}

type IndividualSessionID

type IndividualSessionID = pb.IndividualSessionID

type IndividualSessionProposal

type IndividualSessionProposal = pb.IndividualSessionProposal

type IndividualSessionResponse

type IndividualSessionResponse = pb.IndividualSessionResponse

type RatchetKeyStore

type RatchetKeyStore interface {
	doubleratchet.KeysStorage
}

type RatchetSessionStore

type RatchetSessionStore interface {
	doubleratchet.SessionStorage
}

type SharedKey

type SharedKey = pb.SharedKey

type Store

type Store interface {
	// Diffie-Hellman keys
	EnsureDHPair() (DHPair, error)
	DHPubkeyAttestations() ([]DHPubkeyAttestation, error)
	LatestDHPubkeyFor(addr types.Address) (DHPubkeyAttestation, error)
	SaveDHPubkeyAttestations(attestations []DHPubkeyAttestation) error

	// Individual session handshake protocol
	OutgoingIndividualSessionProposalHashes() (types.Set[types.Hash], error)
	OutgoingIndividualSessionProposalByHash(proposalHash types.Hash) (IndividualSessionProposal, error)
	OutgoingIndividualSessionProposalsForUsers(aliceAddr, bobAddr types.Address) ([]IndividualSessionProposal, error)
	OutgoingIndividualSessionProposalByUsersAndType(sessionType string, aliceAddr, bobAddr types.Address) (IndividualSessionProposal, error)
	SaveOutgoingIndividualSessionProposal(proposal IndividualSessionProposal) error
	DeleteOutgoingIndividualSessionProposal(sessionHash types.Hash) error

	IncomingIndividualSessionProposals() (map[types.Hash]EncryptedIndividualSessionProposal, error)
	IncomingIndividualSessionProposal(hash types.Hash) (EncryptedIndividualSessionProposal, error)
	SaveIncomingIndividualSessionProposal(proposal EncryptedIndividualSessionProposal) error
	DeleteIncomingIndividualSessionProposal(proposal EncryptedIndividualSessionProposal) error

	OutgoingIndividualSessionResponses() (map[types.Address]map[types.Hash]IndividualSessionResponse, error)
	OutgoingIndividualSessionResponsesForUser(aliceAddr types.Address) ([]IndividualSessionResponse, error)
	OutgoingIndividualSessionResponse(aliceAddr types.Address, proposalHash types.Hash) (IndividualSessionResponse, error)
	SaveOutgoingIndividualSessionResponse(sender types.Address, approval IndividualSessionResponse) error
	DeleteOutgoingIndividualSessionResponse(aliceAddr types.Address, proposalHash types.Hash) error

	// Established individual sessions
	LatestIndividualSessionWithUsers(sessionType string, aliceAddr, bobAddr types.Address) (IndividualSessionProposal, error)
	IndividualSessionByID(id IndividualSessionID) (IndividualSessionProposal, error)
	IndividualSessionIDBySessionHash(hash types.Hash) (IndividualSessionID, error)
	SaveApprovedIndividualSession(session IndividualSessionProposal) error

	// Individual messages
	OutgoingIndividualMessageIntents() ([]IndividualMessageIntent, error)
	OutgoingIndividualMessageIntentIDsForTypeAndRecipient(sessionType string, recipient types.Address) (types.Set[types.ID], error)
	OutgoingIndividualMessageIntent(sessionType string, recipient types.Address, id types.ID) (IndividualMessageIntent, error)
	SaveOutgoingIndividualMessageIntent(intent IndividualMessageIntent) error
	DeleteOutgoingIndividualMessageIntent(intent IndividualMessageIntent) error

	IncomingIndividualMessages() ([]IndividualMessage, error)
	SaveIncomingIndividualMessage(sender types.Address, msg IndividualMessage) error
	DeleteIncomingIndividualMessage(msg IndividualMessage) error

	// Group messages
	OutgoingGroupMessageSessionTypes() (types.Set[string], error)
	OutgoingGroupMessageIntentIDsForSessionType(sessionType string) (types.Set[string], error)
	OutgoingGroupMessageIntent(sessionType, id string) (GroupMessageIntent, error)
	SaveOutgoingGroupMessageIntent(intent GroupMessageIntent) error
	DeleteOutgoingGroupMessageIntent(sessionType, id string) error

	IncomingGroupMessages() ([]GroupMessage, error)
	SaveIncomingGroupMessage(sender types.Address, msg GroupMessage) error
	DeleteIncomingGroupMessage(msg GroupMessage) error

	// Double ratchet message keys + sessions
	RatchetSessionStore() RatchetSessionStore
	RatchetKeyStore() RatchetKeyStore

	DebugPrint()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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