protocol

package
v0.0.0-...-c3b93c4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package protocol provides address, group, and message structures that the Signal protocol uses for sending encrypted messages.

Index

Constants

View Source
const ADDRESS_SEPARATOR = "~"
View Source
const CurrentVersion = 3
View Source
const PREKEY_TYPE = 3
View Source
const SENDERKEY_DISTRIBUTION_TYPE = 5
View Source
const SENDERKEY_TYPE = 4
View Source
const UnsupportedVersion = 1
View Source
const WHISPER_TYPE = 2

Variables

This section is empty.

Functions

This section is empty.

Types

type CiphertextMessage

type CiphertextMessage interface {
	Serialize() []byte
	Type() uint32
}

type PreKeySignalMessage

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

PreKeySignalMessage is an encrypted Signal message that is designed to be used when building a session with someone for the first time.

func NewPreKeySignalMessage

func NewPreKeySignalMessage(version int, registrationID uint32, preKeyID *optional.Uint32, signedPreKeyID uint32,
	baseKey ecc.ECPublicKeyable, identityKey *identity.Key, message *SignalMessage, serializer PreKeySignalMessageSerializer,
	msgSerializer SignalMessageSerializer) (*PreKeySignalMessage, error)

NewPreKeySignalMessage will return a new PreKeySignalMessage object.

func NewPreKeySignalMessageFromBytes

func NewPreKeySignalMessageFromBytes(serialized []byte, serializer PreKeySignalMessageSerializer,
	msgSerializer SignalMessageSerializer) (*PreKeySignalMessage, error)

NewPreKeySignalMessageFromBytes will return a Signal Ciphertext message from the given bytes using the given serializer.

func NewPreKeySignalMessageFromStruct

func NewPreKeySignalMessageFromStruct(structure *PreKeySignalMessageStructure,
	serializer PreKeySignalMessageSerializer, msgSerializer SignalMessageSerializer) (*PreKeySignalMessage, error)

NewPreKeySignalMessageFromStruct will return a new PreKeySignalMessage from the given PreKeySignalMessageStructure.

func (*PreKeySignalMessage) BaseKey

func (*PreKeySignalMessage) IdentityKey

func (p *PreKeySignalMessage) IdentityKey() *identity.Key

func (*PreKeySignalMessage) MessageVersion

func (p *PreKeySignalMessage) MessageVersion() int

func (*PreKeySignalMessage) PreKeyID

func (p *PreKeySignalMessage) PreKeyID() *optional.Uint32

func (*PreKeySignalMessage) RegistrationID

func (p *PreKeySignalMessage) RegistrationID() uint32

func (*PreKeySignalMessage) Serialize

func (p *PreKeySignalMessage) Serialize() []byte

func (*PreKeySignalMessage) SignedPreKeyID

func (p *PreKeySignalMessage) SignedPreKeyID() uint32

func (*PreKeySignalMessage) Type

func (p *PreKeySignalMessage) Type() uint32

func (*PreKeySignalMessage) WhisperMessage

func (p *PreKeySignalMessage) WhisperMessage() *SignalMessage

type PreKeySignalMessageSerializer

type PreKeySignalMessageSerializer interface {
	Serialize(signalMessage *PreKeySignalMessageStructure) []byte
	Deserialize(serialized []byte) (*PreKeySignalMessageStructure, error)
}

PreKeySignalMessageSerializer is an interface for serializing and deserializing PreKeySignalMessages into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type PreKeySignalMessageStructure

type PreKeySignalMessageStructure struct {
	RegistrationID uint32
	PreKeyID       *optional.Uint32
	SignedPreKeyID uint32
	BaseKey        []byte
	IdentityKey    []byte
	Message        []byte
	Version        int
}

PreKeySignalMessageStructure is a serializable structure for PreKeySignalMessages.

type SenderKeyDistributionMessage

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

SenderKeyDistributionMessage is a structure for senderkey distribution messages.

func NewSenderKeyDistributionMessage

func NewSenderKeyDistributionMessage(id uint32, iteration uint32,
	chainKey []byte, signatureKey ecc.ECPublicKeyable,
	serializer SenderKeyDistributionMessageSerializer) *SenderKeyDistributionMessage

NewSenderKeyDistributionMessage returns a Signal Ciphertext message.

func NewSenderKeyDistributionMessageFromBytes

func NewSenderKeyDistributionMessageFromBytes(serialized []byte,
	serializer SenderKeyDistributionMessageSerializer) (*SenderKeyDistributionMessage, error)

NewSenderKeyDistributionMessageFromBytes will return a Signal Ciphertext message from the given bytes using the given serializer.

func NewSenderKeyDistributionMessageFromStruct

func NewSenderKeyDistributionMessageFromStruct(structure *SenderKeyDistributionMessageStructure,
	serializer SenderKeyDistributionMessageSerializer) (*SenderKeyDistributionMessage, error)

NewSenderKeyDistributionMessageFromStruct returns a Signal Ciphertext message from the given serializable structure.

func (*SenderKeyDistributionMessage) ChainKey

func (p *SenderKeyDistributionMessage) ChainKey() []byte

ChainKey will return the message's chain key in bytes.

func (*SenderKeyDistributionMessage) ID

ID will return the message's id.

func (*SenderKeyDistributionMessage) Iteration

func (p *SenderKeyDistributionMessage) Iteration() uint32

Iteration will return the message's iteration.

func (*SenderKeyDistributionMessage) Serialize

func (p *SenderKeyDistributionMessage) Serialize() []byte

Serialize will use the given serializer and return the message as bytes.

func (*SenderKeyDistributionMessage) SignatureKey

SignatureKey will return the message's signature public key

func (*SenderKeyDistributionMessage) Type

Type will return the message's type.

type SenderKeyDistributionMessageSerializer

type SenderKeyDistributionMessageSerializer interface {
	Serialize(signalMessage *SenderKeyDistributionMessageStructure) []byte
	Deserialize(serialized []byte) (*SenderKeyDistributionMessageStructure, error)
}

SenderKeyDistributionMessageSerializer is an interface for serializing and deserializing SenderKeyDistributionMessages into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type SenderKeyDistributionMessageStructure

type SenderKeyDistributionMessageStructure struct {
	ID         uint32
	Iteration  uint32
	ChainKey   []byte
	SigningKey []byte
	Version    uint32
}

SenderKeyDistributionMessageStructure is a serializeable structure for senderkey distribution messages.

type SenderKeyMessage

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

SenderKeyMessage is a structure for messages using senderkey groups.

func NewSenderKeyMessage

func NewSenderKeyMessage(keyID uint32, iteration uint32, ciphertext []byte,
	signatureKey ecc.ECPrivateKeyable, serializer SenderKeyMessageSerializer) *SenderKeyMessage

NewSenderKeyMessage returns a SenderKeyMessage.

func NewSenderKeyMessageFromBytes

func NewSenderKeyMessageFromBytes(serialized []byte,
	serializer SenderKeyMessageSerializer) (*SenderKeyMessage, error)

NewSenderKeyMessageFromBytes will return a Signal Ciphertext message from the given bytes using the given serializer.

func NewSenderKeyMessageFromStruct

func NewSenderKeyMessageFromStruct(structure *SenderKeyMessageStructure,
	serializer SenderKeyMessageSerializer) (*SenderKeyMessage, error)

NewSenderKeyMessageFromStruct returns a Signal Ciphertext message from the given serializable structure.

func (*SenderKeyMessage) Ciphertext

func (p *SenderKeyMessage) Ciphertext() []byte

Ciphertext returns the SenderKeyMessage encrypted ciphertext.

func (*SenderKeyMessage) Iteration

func (p *SenderKeyMessage) Iteration() uint32

Iteration returns the SenderKeyMessage iteration.

func (*SenderKeyMessage) KeyID

func (p *SenderKeyMessage) KeyID() uint32

KeyID returns the SenderKeyMessage key ID.

func (*SenderKeyMessage) Serialize

func (p *SenderKeyMessage) Serialize() []byte

Serialize will use the given serializer to return the message as bytes excluding the signature. This should be used for signing and verifying message signatures.

func (*SenderKeyMessage) Signature

func (p *SenderKeyMessage) Signature() [64]byte

Signature returns the SenderKeyMessage signature

func (*SenderKeyMessage) SignedSerialize

func (p *SenderKeyMessage) SignedSerialize() []byte

SignedSerialize will use the given serializer to return the message as bytes with the message signature included. This should be used when sending the message over the network.

func (*SenderKeyMessage) Type

func (p *SenderKeyMessage) Type() uint32

Type returns the sender key type.

func (*SenderKeyMessage) Version

func (p *SenderKeyMessage) Version() uint32

Version returns the Signal message version of the message.

type SenderKeyMessageSerializer

type SenderKeyMessageSerializer interface {
	Serialize(signalMessage *SenderKeyMessageStructure) []byte
	Deserialize(serialized []byte) (*SenderKeyMessageStructure, error)
}

SenderKeyMessageSerializer is an interface for serializing and deserializing SenderKeyMessages into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type SenderKeyMessageStructure

type SenderKeyMessageStructure struct {
	ID         uint32
	Iteration  uint32
	CipherText []byte
	Version    uint32
	Signature  []byte
}

SenderKeyMessageStructure is a serializeable structure for SenderKey messages.

type SenderKeyName

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

SenderKeyName is a structure for a group session address.

func NewSenderKeyName

func NewSenderKeyName(groupID string, sender *SignalAddress) *SenderKeyName

NewSenderKeyName returns a new SenderKeyName object.

func (*SenderKeyName) GroupID

func (n *SenderKeyName) GroupID() string

GroupID returns the sender key group id

func (*SenderKeyName) Sender

func (n *SenderKeyName) Sender() *SignalAddress

Sender returns the Signal address of sending user in the group.

type SignalAddress

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

SignalAddress is a combination of a name and a device ID.

func NewSignalAddress

func NewSignalAddress(name string, deviceID uint32) *SignalAddress

NewSignalAddress returns a new signal address.

func (*SignalAddress) DeviceID

func (s *SignalAddress) DeviceID() uint32

DeviceID returns the signal address's device ID.

func (*SignalAddress) Name

func (s *SignalAddress) Name() string

Name returns the signal address's name.

func (*SignalAddress) String

func (s *SignalAddress) String() string

String returns a string of both the address name and device id.

type SignalMessage

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

SignalMessage is a cipher message that contains a message encrypted with the Signal protocol.

func NewSignalMessage

func NewSignalMessage(messageVersion int, counter, previousCounter uint32, macKey []byte,
	senderRatchetKey ecc.ECPublicKeyable, ciphertext []byte, senderIdentityKey,
	receiverIdentityKey *identity.Key, serializer SignalMessageSerializer) (*SignalMessage, error)

NewSignalMessage returns a Signal Ciphertext message.

func NewSignalMessageFromBytes

func NewSignalMessageFromBytes(serialized []byte, serializer SignalMessageSerializer) (*SignalMessage, error)

NewSignalMessageFromBytes will return a Signal Ciphertext message from the given bytes using the given serializer.

func NewSignalMessageFromStruct

func NewSignalMessageFromStruct(structure *SignalMessageStructure, serializer SignalMessageSerializer) (*SignalMessage, error)

NewSignalMessageFromStruct returns a Signal Ciphertext message from the given serializable structure.

func (*SignalMessage) Body

func (s *SignalMessage) Body() []byte

Body will return the SignalMessage's ciphertext in bytes.

func (*SignalMessage) Counter

func (s *SignalMessage) Counter() uint32

Counter will return the SignalMessage counter.

func (*SignalMessage) MessageVersion

func (s *SignalMessage) MessageVersion() int

MessageVersion returns the message version this SignalMessage supports.

func (*SignalMessage) SenderRatchetKey

func (s *SignalMessage) SenderRatchetKey() ecc.ECPublicKeyable

SenderRatchetKey returns the SignalMessage's sender ratchet key. This key is used for ratcheting the chain forward to negotiate a new shared secret that cannot be derived from previous chains.

func (*SignalMessage) Serialize

func (s *SignalMessage) Serialize() []byte

Serialize will return the Signal Message as bytes.

func (*SignalMessage) Structure

func (s *SignalMessage) Structure() *SignalMessageStructure

Structure will return a serializeable structure of the Signal Message.

func (*SignalMessage) Type

func (s *SignalMessage) Type() uint32

Type will return the type of Signal Message this is.

func (*SignalMessage) VerifyMac

func (s *SignalMessage) VerifyMac(messageVersion int, senderIdentityKey,
	receiverIdentityKey *identity.Key, macKey []byte) error

VerifyMac will return an error if the message's message authentication code is invalid. This should be used on SignalMessages that have been constructed from a sent message.

type SignalMessageSerializer

type SignalMessageSerializer interface {
	Serialize(signalMessage *SignalMessageStructure) []byte
	Deserialize(serialized []byte) (*SignalMessageStructure, error)
}

SignalMessageSerializer is an interface for serializing and deserializing SignalMessages into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type SignalMessageStructure

type SignalMessageStructure struct {
	RatchetKey      []byte
	Counter         uint32
	PreviousCounter uint32
	CipherText      []byte
	Version         int
	Mac             []byte
}

SignalMessageStructure is a serializeable structure of a signal message object.

Jump to

Keyboard shortcuts

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