message

package
v0.0.0-...-7271f6c Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2015 License: MIT Imports: 17 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToServer

func ConnectToServer(remote string) (net.Conn, error)

ConnectToServer is a convenience method that attempts to dial a tcp connection to a server specified by a string.

func SignAndSend

func SignAndSend(m Message, from *identity.Identity, to *identity.Address) error

SignAndSend will take a message, a from identity, and a to address, and send it to the address (so long as to already contains key information).

func SignAndSendToConnection

func SignAndSendToConnection(m Message, from *identity.Identity, to *identity.Address, conn net.Conn) error

SignAndSendToConnection performs exactly the same function as SignAndSend, but it can utilize an already open connection. Useful for responding to messages.

Types

type Component

type Component struct {
	Name string
	Data []byte
}

Component is a basic unit in an AirDispatch message. It has a name, generally a string akin to Apple's bundle ids.

E.G. if I am creating an AirDispatch application at http://airdispat.ch/notes I may have a data type called "ch.airdispat.notes.title".

func CreateComponent

func CreateComponent(name string, data []byte) Component

CreateComponent will return a new component given a name and data.

func CreateStringComponent

func CreateStringComponent(name string, data string) Component

CreateStringComponent will return a new component given a name and a UTF-8 string.

func (Component) Key

func (c Component) Key() string

Key will return the name of the component.

func (Component) String

func (c Component) String() string

String will return the bytes of the component interpreted as UTF-8.

func (Component) Value

func (c Component) Value() []byte

Value will return the bytes of the component.

type ComponentList

type ComponentList map[string]Component

ComponentList maps keys (strings) to components.

func (ComponentList) AddComponent

func (c ComponentList) AddComponent(comp Component)

AddComponent will add a new component object into the list.

func (ComponentList) GetComponent

func (c ComponentList) GetComponent(name string) []byte

GetComponent will return the []byte associated with a component name.

func (ComponentList) GetStringComponent

func (c ComponentList) GetStringComponent(name string) string

GetStringComponent will return the []byte associated with a component name interpreted as UTF-8.

func (ComponentList) HasComponent

func (c ComponentList) HasComponent(name string) bool

HasComponent will return whether a Mail object contains a component.

func (ComponentList) ToArray

func (c ComponentList) ToArray() []Component

ToArray will return the ComponentList as an array of components.

type DataMessage

type DataMessage struct {
	Hash     []byte
	Length   uint64
	Key      []byte
	DataType string
	Name     string
	Filename string
	// contains filtered or unexported fields
}

DataMessage allows transfer of arbitrarily large bytestreams.

func CreateDataMessage

func CreateDataMessage(hash []byte, length uint64, typ, name, filename string, r io.ReadCloser, h Header) (*DataMessage, io.ReadCloser, error)

func CreateDataMessageFromBytes

func CreateDataMessageFromBytes(by []byte, h Header) (*DataMessage, error)

CreateMailFromBytes will unmarshall a mail message given its bytes and header.

func (*DataMessage) DecryptReader

func (m *DataMessage) DecryptReader(r io.Reader) (io.Reader, error)

func (*DataMessage) Header

func (m *DataMessage) Header() Header

func (*DataMessage) ToBytes

func (m *DataMessage) ToBytes() []byte

ToBytes will marshal a mail message to its component bytes.

func (*DataMessage) TrueLength

func (m *DataMessage) TrueLength() uint64

func (*DataMessage) Type

func (m *DataMessage) Type() string

func (*DataMessage) VerifyPayload

func (m *DataMessage) VerifyPayload() bool

type EncryptedMessage

type EncryptedMessage struct {
	Data   []byte
	Header map[string]EncryptionHeader
	// contains filtered or unexported fields
}

EncryptedMessage represents an AirDispatch message encrypted for one or many recipients.

func CreateEncryptedMessageFromBytes

func CreateEncryptedMessageFromBytes(theBytes []byte) (*EncryptedMessage, error)

CreateEncryptedMessageFromBytes will take a series of bytes (usually read read from a connection) and Unmarshal them into the EncryptedMessage struct.

func ReadMessageFromConnection

func ReadMessageFromConnection(conn net.Conn) (*EncryptedMessage, error)

ReadMessageFromConnection will return a read EncryptedMessage off a specified net.Conn.

func (*EncryptedMessage) AddRecipient

func (e *EncryptedMessage) AddRecipient(addr *identity.Address) error

AddRecipient will take an *identity.Address and add information for it to decrypt the message.

func (*EncryptedMessage) Decrypt

Decrypt will use an *identity.Identity to decrypt the EncryptedMessage into a SignedMessage.

func (*EncryptedMessage) Reconstruct

func (e *EncryptedMessage) Reconstruct(receiver *identity.Identity, ts bool) ([]byte, string, Header, error)

Reconstruct will take an change an encrypted message into a message blob Message Type, Header, and Error by Decrypting with the receiver's identity, verifying the signed message, and reconstructing the signed message (optionally with timestamp support).

func (*EncryptedMessage) Send

func (e *EncryptedMessage) Send() error

Send will connect to each recipient's server and send the message to them.

func (*EncryptedMessage) SendMessageToConnection

func (e *EncryptedMessage) SendMessageToConnection(conn net.Conn) error

SendMessageToConnection will send an encryptedMessage to a connection.

func (*EncryptedMessage) ToBytes

func (e *EncryptedMessage) ToBytes() ([]byte, error)

ToBytes will marshal an EncryptedMessage to an array of bytes suitable for sending on a wire.

func (*EncryptedMessage) UnencryptedMessage

func (e *EncryptedMessage) UnencryptedMessage() (*SignedMessage, error)

UnencryptedMessage will downgrade an EncryptedMessage into a SignedMessage if you know that the message is not encrypted.

type EncryptionHeader

type EncryptionHeader struct {
	EncryptionKey  []byte
	EncryptionType []byte
	To             *identity.Address
}

EncryptionHeader holds the information necessary for a recipient to decrypt the message.

type Header struct {
	From      *identity.Address
	To        []*identity.Address
	Timestamp int64
	// Location Options
	EncryptionKey []byte
	Alias         string
}

Header is a message header that is sent across the wire signed and encrypted.

Each public field is an object that is important to be protected.

func CreateHeader

func CreateHeader(from *identity.Address, to ...*identity.Address) Header

CreateHeader will return a basic header for a from address and a to address.

func SendMessageAndReceive

func SendMessageAndReceive(m Message, sender *identity.Identity, addr *identity.Address) ([]byte, string, Header, error)

SendMessageAndReceive does exactly what you think:

- Signs, Encrypts, and sends a message to a connection - Receives, Decrypts, Verifies, and Reconstructs a message from a connection (without timestamp support)

func SendMessageAndReceiveWithTimestamp

func SendMessageAndReceiveWithTimestamp(m Message, sender *identity.Identity, addr *identity.Address) ([]byte, string, Header, error)

SendMessageAndReceiveWithTimestamp does exactly the same as SendMessageAndReceive but includes timestamp support.

type Mail

type Mail struct {
	Name       string
	Components ComponentList
	// contains filtered or unexported fields
}

Mail is the basic form of a user-visible AirDispatch message.

It contains a list of components that effectively serve as a key-value dictionary of string -> []byte. Most of the time, the []byte can be interpreted as a UTF-8 string.

func CreateMail

func CreateMail(from *identity.Address, ts time.Time, name string, to ...*identity.Address) *Mail

CreateMail will return a new Mail object with the correct header, ready for adding components.

func CreateMailFromBytes

func CreateMailFromBytes(by []byte, h Header) (*Mail, error)

CreateMailFromBytes will unmarshall a mail message given its bytes and header.

func (*Mail) Header

func (m *Mail) Header() Header

Header just returns the stored header with the message.

func (*Mail) ToBytes

func (m *Mail) ToBytes() []byte

ToBytes will marshal a mail message to its component bytes.

func (*Mail) Type

func (m *Mail) Type() string

Type is used to satisfy the (message.Message) interface. Mail objects have type wire.MailCode (or "MAI").

type Message

type Message interface {
	Header() Header
	Type() string
	ToBytes() []byte
}

Message is an interface that allows something to be sent on the AirDispatch wire. It requires a message that knows how to marshal itself to bytes (ToBytes()), retrieve a header (Header()), and return a message type (Type()).

type SignedMessage

type SignedMessage struct {
	Data        []byte
	Signature   []*wire.Signature
	SigningFunc []byte
	// contains filtered or unexported fields
}

SignedMessage represents a chunk of data that has been signed by a user of AirDispatch.

func SignMessage

func SignMessage(m Message, id *identity.Identity) (*SignedMessage, error)

SignMessage will sign an object that implements the message interface with an id and return the corresponding SignedMessage.

func (*SignedMessage) AddSignature

func (s *SignedMessage) AddSignature(id *identity.Identity) error

AddSignature will add a new signature of the data by id onto the message. This is useful if you need a SignedMessage to be signed by multiple parties.

func (*SignedMessage) Encrypt

func (s *SignedMessage) Encrypt(addr string, router routing.Router) (*EncryptedMessage, error)

Encrypt will take an address string and a router, and encrypt the message with the key received. This is generally not used, as the application should lookup the key itself based on the routing.LookupType needed.

func (*SignedMessage) EncryptWithKey

func (s *SignedMessage) EncryptWithKey(addr *identity.Address) (*EncryptedMessage, error)

EncryptWithKey will take an *identity.Address that already has a key associated with it and encrypt the SignedMessage with it.

func (*SignedMessage) ReconstructMessage

func (s *SignedMessage) ReconstructMessage() (data []byte, messageType string, header Header, err error)

ReconstructMessage will take the signed chunk of data and return the data, the messageType, the header on the data, and any errors.

Additionally, it will ensure that the Header.From field matches one of the signatures verified during Verify().

func (*SignedMessage) ReconstructMessageWithTimestamp

func (s *SignedMessage) ReconstructMessageWithTimestamp() (data []byte, messageType string, header Header, err error)

ReconstructMessageWithTimestamp will do the same thing as ReconstructMessage but it will ensure that the timestamp is within the last five minutes.

func (*SignedMessage) UnencryptedMessage

func (s *SignedMessage) UnencryptedMessage(addr *identity.Address) (*EncryptedMessage, error)

UnencryptedMessage will take a signed message and an address and turn it into an "EncryptedMessage" to send on the wire without actually encrypting the data.

func (*SignedMessage) Verify

func (s *SignedMessage) Verify() bool

Verify that a signed message is genuine.

Unwinds the R and S values of the ECDSA keypair from the Airdispatch Signature then passes them to the verifyPayload function.

Additionally, it will save which addresses had signatures that were verified to match with Header{} verification later.

Jump to

Keyboard shortcuts

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