Documentation ¶
Overview ¶
Package msg defines messages in Mute. Specification: https://github.com/mutecomm/mute/blob/master/doc/messages.md
Index ¶
Constants ¶
const ( StatusOK = 0 StatusReset = 1 StatusError = 2 )
Possible header status codes.
const AverageSessionSize = 1000
AverageSessionSize defines the average session size. That is, the number of keys used in a session before a new session is started. For every encrypted message there is the probability of 1/AverageSessionSize that it starts a new session.
const DefaultCiphersuite = "CURVE25519 XSALSA20 POLY1305"
DefaultCiphersuite is the default ciphersuite used for Mute messages.
const EncodedMsgSize = 65536 // 64KB
EncodedMsgSize is the size of a base64 encoded encrypted message.
const MaxContentLength = UnencodedMsgSize - preHeaderSize - encryptedHeaderSize - cryptoSetupSize - encryptedPacketSize - signatureSize - innerHeaderSize - hmacSize // 41691
MaxContentLength is the maximum length the content of a message can have.
const NumOfFutureKeys = 50
NumOfFutureKeys defines the default number of future message keys which are precomputed.
const SendTime = 172800 // 48h
SendTime defines how long key material can be used for sending.
const UnencodedMsgSize = EncodedMsgSize / 4 * 3 // 49152
UnencodedMsgSize is the size of unencoded encrypted message.
const Version = 1
Version is the current version number of Mute messages.
Variables ¶
var CleanupTime uint64
CleanupTime defines the time how long key material should be retained. Initialized via def.InitMute().
var ErrHMACsDiffer = errors.New("msg: HMACs differ")
ErrHMACsDiffer is raised when the HMACs differ.
var ErrInvalidSignature = errors.New("msg: signature invalid")
ErrInvalidSignature is raised when a signature verification failed.
var ErrNoPreHeaderKey = errors.New("msg: could not find key to decrypt pre-header")
ErrNoPreHeaderKey is raised when the key to decrypt the pre-header could not be found.
var ErrNotCryptoSetup = errors.New("msg: message doesn't have crypto setup header")
ErrNotCryptoSetup is raised when a message doesn't has a crypto setup header after the encrypted header.
var ErrNotData = errors.New("msg: expected inner data header")
ErrNotData is raised when an inner data header was expected.
var ErrNotEncryptedHeader = errors.New("msg: message doesn't have encrypted header")
ErrNotEncryptedHeader is raised when a message doesn't has an encrypted header after the pre-header.
var ErrNotEncryptedPacket = errors.New("msg: expected encrypted packet")
ErrNotEncryptedPacket is raised when an encrypted packet was expected.
var ErrNotHMACPacket = errors.New("msg: expected HMAC packet")
ErrNotHMACPacket is raised when an HMAC packet was expected.
var ErrNotPaddingPacket = errors.New("msg: expected padding packet")
ErrNotPaddingPacket is raised when a padding packet was expected.
var ErrNotPreHeader = errors.New("msg: message doesn't start with pre-header")
ErrNotPreHeader is raised when a message doesn't start with a pre-header.
var ErrNotSignaturePacket = errors.New("msg: expected signature packet")
ErrNotSignaturePacket is raised when a signature packet was expected.
var ErrReflection = errors.New("msg: reflection attack detected")
ErrReflection is raised when a possible reflection attack has been detected.
var ErrStatusError = errors.New("msg: StatusCode == StatusError")
ErrStatusError is raised when a decryption operation lead to a StatusCode StatusError.
var ErrWrongCount = errors.New("msg: wrong outer header count")
ErrWrongCount is raised when an outer header count is wrong.
var ErrWrongCryptoSetup = errors.New("msg: crypto setup header has the wrong length")
ErrWrongCryptoSetup is raised when a crypto setup header has the wrong length.
var ErrWrongSignatureLength = errors.New("msg: wrong signature length")
ErrWrongSignatureLength is raised when a signature has the wrong length.
Functions ¶
func Decrypt ¶
func Decrypt(args *DecryptArgs) (senderID, sig string, err error)
Decrypt decrypts a message with the argument given in args. The senderID is returned. If the message was signed and the signature could be verified successfully the base64 encoded signature is returned. If the message was signed and the signature could not be verfied an error is returned.
func Encrypt ¶
func Encrypt(args *EncryptArgs) (nymAddress string, err error)
Encrypt encrypts a message with the argument given in args and returns the nymAddress the message should be delivered to.
func ReadFirstOuterHeader ¶
ReadFirstOuterHeader reads the first outer header from the base64 decoder r and returns the version and the preHeader for further processing. This function is intended to be used outside the msg package to allow to check for incompatible message format changes down the line.
Types ¶
type DecryptArgs ¶
type DecryptArgs struct { Writer io.Writer // decrypted message is written here Identities []*uid.Message // list of recipient UID messages PreHeader []byte // preHeader read with ReadFirstOuterHeader() Reader io.Reader // data to decrypt is read here (not base64 encoded) NumOfKeys uint64 // number of generated sessions keys (default: NumOfFutureKeys) Rand io.Reader // random source KeyStore session.Store // for managing session keys }
DecryptArgs contains all arguments for a message decryption.
type EncryptArgs ¶
type EncryptArgs struct { Writer io.Writer // encrypted messagte is written here (base64 encoded) From *uid.Message // sender UID To *uid.Message // recipient UID NymAddress string // address to receive future messages at SenderLastKeychainHash string // last hash chain entry known to the sender PrivateSigKey *[64]byte // if this is s not nil the message is signed with the key Reader io.Reader // data to encrypt is read here (only for StatusCode == StatusOK) NumOfKeys uint64 // number of generated sessions keys (default: NumOfFutureKeys) AvgSessionSize uint // average session size (default: AverageSessionSize) Rand io.Reader // random source KeyStore session.Store // for managing session keys StatusCode StatusCode // status code of the encrypted message }
EncryptArgs contains all arguments for a message encryption.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mime implements the MIME encoding used for messages in Mute.
|
Package mime implements the MIME encoding used for messages in Mute. |
Package msgid contains helper functions for message ID generation and parsing.
|
Package msgid contains helper functions for message ID generation and parsing. |
Package padding contains helper functions to generate cheap paddings.
|
Package padding contains helper functions to generate cheap paddings. |
Package session defines session states and session stores in Mute.
|
Package session defines session states and session stores in Mute. |
memstore
Package memstore implements a key store in memory (for testing purposes).
|
Package memstore implements a key store in memory (for testing purposes). |