utils

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: BSD-3-Clause, MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InvalidPrivateKeyFileError is a library error, thrown when the given key file fials to load
	InvalidPrivateKeyFileError = Error("InvalidPrivateKeyFileError")

	// RicochetKeySize - tor onion services currently use rsa key sizes of 1024 bits
	RicochetKeySize = 1024
)
View Source
const (
	VersionNegotiationError  = Error("VersionNegotiationError")
	VersionNegotiationFailed = Error("VersionNegotiationFailed")

	RicochetConnectionClosed = Error("RicochetConnectionClosed")
	RicochetProtocolError    = Error("RicochetProtocolError")

	UnknownChannelTypeError      = Error("UnknownChannelTypeError")
	UnauthorizedChannelTypeError = Error("UnauthorizedChannelTypeError")
	UnexpectedChannelResultError = Error("UnexpectedChannelResultError")

	// Timeout Errors
	ActionTimedOutError = Error("ActionTimedOutError")
	PeerTimedOutError   = Error("PeerTimedOutError")

	// Authentication Errors
	ClientFailedToAuthenticateError     = Error("ClientFailedToAuthenticateError")
	ServerRejectedClientConnectionError = Error("ServerRejectedClientConnectionError")

	UnauthorizedActionError  = Error("UnauthorizedActionError")
	ChannelClosedByPeerError = Error("ChannelClosedByPeerError")

	// Channel Management Errors
	ServerAttemptedToOpenEvenNumberedChannelError = Error("ServerAttemptedToOpenEvenNumberedChannelError")
	ClientAttemptedToOpenOddNumberedChannelError  = Error("ClientAttemptedToOpenOddNumberedChannelError")
	ChannelIDIsAlreadyInUseError                  = Error("ChannelIDIsAlreadyInUseError")
	AttemptToOpenMoreThanOneSingletonChannelError = Error("AttemptToOpenMoreThanOneSingletonChannelError")

	// Library Use Errors
	OnionAddressGenerationError = Error("OnionAddressGenerationError")
	PrivateKeyNotSetError       = Error("PrivateKeyNotSet")

	// Connection Errors
	ConnectionClosedError = Error("ConnectionClosedError")
)

Defining Versions

View Source
const (
	// InvalidPacketLengthError is returned whenever ricochet receives a packet too small or too large to conform to the spec.
	InvalidPacketLengthError = Error("InvalidPacketLengthError")

	// InvalidChannelIDError channels must be between 0 and 65535
	InvalidChannelIDError = Error("InvalidChannelIDError")
)
View Source
const V3HostnameLength = 56

V3HostnameLength is the length of a Tor V3 Onion Address (without the .onion suffix)

Variables

This section is empty.

Functions

func CheckError

func CheckError(err error)

CheckError is a helper function for panicing on errors which we need to handle but should be very rare e.g. failures deserializing a protobuf object that should only happen if there was a bug in the underlying library.

func EDH

func EDH(privateKey ed25519.PrivateKey, remotePublicKey ed25519.PublicKey) [32]byte

EDH implements diffie hellman using curve25519 keys derived from ed25519 keys NOTE: This uses a 3rd party library extra25519 as the key conversion is not in the core golang lib as such this definitely needs further review.

func GeneratePrivateKeyV3

func GeneratePrivateKeyV3() (ed25519.PublicKey, ed25519.PrivateKey, error)

GeneratePrivateKeyV3 cryptographically creats a new ed25519 key pair.

func GetRandNumber

func GetRandNumber() *big.Int

GetRandNumber is a helper function which returns a random integer, this is currently mostly used to generate messageids

func GetTorHostname

func GetTorHostname(publicKeyBytes []byte) string

GetTorHostname takes a []byte contained a DER-encoded RSA public key and returns the first 16 bytes of the base32 encoded sha1 hash of the key. This is the onion hostname of the tor service represented by the public key.

func GetTorV3Hostname

func GetTorV3Hostname(pub ed25519.PublicKey) string

GetTorV3Hostname converts an ed25519 public key to a valid tor onion hostname

func IsValidHostname

func IsValidHostname(address string) bool

IsValidHostname returns true if the given address is a valid onion v3 address

func LoadPrivateKeyFromFile

func LoadPrivateKeyFromFile(filename string) (*rsa.PrivateKey, error)

LoadPrivateKeyFromFile loads a private key from a file...

func ParsePrivateKey

func ParsePrivateKey(pemData []byte) (*rsa.PrivateKey, error)

ParsePrivateKey Convert a private key string to a usable private key

func PrivateKeyToString

func PrivateKeyToString(privateKey *rsa.PrivateKey) string

PrivateKeyToString turns a private key into storable string

Types

type Error

type Error string

Error captures various common ricochet errors

func (Error) Error

func (e Error) Error() string

type MessageBuilder

type MessageBuilder struct {
}

MessageBuilder allows a client to construct specific data packets for the ricochet protocol.

func (*MessageBuilder) AckChatMessage

func (mb *MessageBuilder) AckChatMessage(messageID uint32, accepted bool) []byte

AckChatMessage constructs a chat message acknowledgement.

func (*MessageBuilder) AckOpenChannel

func (mb *MessageBuilder) AckOpenChannel(channelID int32) []byte

AckOpenChannel constructs a message to acknowledge a previous open channel operation.

func (*MessageBuilder) AuthResult

func (mb *MessageBuilder) AuthResult(accepted bool, isKnownContact bool) []byte

AuthResult constructs a response to a Proof

func (*MessageBuilder) AuthResult3DH

func (mb *MessageBuilder) AuthResult3DH(accepted bool, isKnownContact bool) []byte

AuthResult3DH constructs a response to a Proof

func (*MessageBuilder) ChatMessage

func (mb *MessageBuilder) ChatMessage(message string, messageID uint32, timeDelta int64) []byte

ChatMessage constructs a chat message with the given content.

func (*MessageBuilder) Confirm3EDHAuthChannel

func (mb *MessageBuilder) Confirm3EDHAuthChannel(channelID int32, pubkey [32]byte, ephemeralKey [32]byte) []byte

Confirm3EDHAuthChannel constructs a message to acknowledge a previous open channel operation.

func (*MessageBuilder) ConfirmAuthChannel

func (mb *MessageBuilder) ConfirmAuthChannel(channelID int32, serverCookie [16]byte) []byte

ConfirmAuthChannel constructs a message to acknowledge a previous open channel operation.

func (*MessageBuilder) EnableFeatures

func (mb *MessageBuilder) EnableFeatures(features []string) []byte

EnableFeatures ...

func (*MessageBuilder) FeaturesEnabled

func (mb *MessageBuilder) FeaturesEnabled(features []string) []byte

FeaturesEnabled ...

func (*MessageBuilder) KeepAlive

func (mb *MessageBuilder) KeepAlive(responseRequested bool) []byte

KeepAlive ...

func (*MessageBuilder) Open3EDHAuthenticationChannel

func (mb *MessageBuilder) Open3EDHAuthenticationChannel(channelID int32, pubkey [32]byte, ephemeralKey [32]byte) []byte

Open3EDHAuthenticationChannel constructs a message which will reuqest to open a channel for authentication on the given channelID, with the given cookie

func (*MessageBuilder) OpenAuthenticationChannel

func (mb *MessageBuilder) OpenAuthenticationChannel(channelID int32, clientCookie [16]byte) []byte

OpenAuthenticationChannel constructs a message which will reuqest to open a channel for authentication on the given channelID, with the given cookie

func (*MessageBuilder) OpenChannel

func (mb *MessageBuilder) OpenChannel(channelID int32, channelType string) []byte

OpenChannel contructs a message which will request to open a channel for chat on the given channelID.

func (*MessageBuilder) OpenContactRequestChannel

func (mb *MessageBuilder) OpenContactRequestChannel(channelID int32, nick string, message string) []byte

OpenContactRequestChannel contructs a message which will reuqest to open a channel for a contact request on the given channelID, with the given nick and message.

func (*MessageBuilder) Proof

func (mb *MessageBuilder) Proof(publicKeyBytes []byte, signatureBytes []byte) []byte

Proof constructs a proof message with the given public key and signature.

func (*MessageBuilder) Proof3DH

func (mb *MessageBuilder) Proof3DH(proofBytes []byte) []byte

Proof3DH constructs a proof message with the given public key and signature.

func (*MessageBuilder) RejectOpenChannel

func (mb *MessageBuilder) RejectOpenChannel(channelID int32, error string) []byte

RejectOpenChannel constructs a channel result message, stating the channel failed to open and a reason

func (*MessageBuilder) ReplyToContactRequest

func (mb *MessageBuilder) ReplyToContactRequest(channelID int32, status string) []byte

ReplyToContactRequest constructs a message to acknowledge a contact request

func (*MessageBuilder) ReplyToContactRequestOnResponse

func (mb *MessageBuilder) ReplyToContactRequestOnResponse(channelID int32, status string) []byte

ReplyToContactRequestOnResponse constructs a message to acknowledge contact request

type RicochetData

type RicochetData struct {
	Channel int32
	Data    []byte
}

RicochetData is a structure containing the raw data and the channel it the message originated on.

func (RicochetData) Equals

func (rd RicochetData) Equals(other RicochetData) bool

Equals compares a RicochetData object to another and returns true if contain the same data.

type RicochetNetwork

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

RicochetNetwork is a concrete implementation of the RicochetNetworkInterface

func (*RicochetNetwork) RecvRicochetPacket

func (rn *RicochetNetwork) RecvRicochetPacket(reader io.Reader) (RicochetData, error)

RecvRicochetPacket returns the next packet from reader as a RicochetData structure, or an error.

func (*RicochetNetwork) SendRicochetPacket

func (rn *RicochetNetwork) SendRicochetPacket(dst io.Writer, channel int32, data []byte) error

SendRicochetPacket places the data into a structure needed for the client to decode the packet and writes the packet to the network.

func (*RicochetNetwork) SetEncryptionKey

func (rn *RicochetNetwork) SetEncryptionKey(key [32]byte)

SetEncryptionKey sets the ephemeral encryption key for this session.

type RicochetNetworkInterface

type RicochetNetworkInterface interface {
	SendRicochetPacket(dst io.Writer, channel int32, data []byte) error
	RecvRicochetPacket(reader io.Reader) (RicochetData, error)
}

RicochetNetworkInterface abstract operations that interact with ricochet's packet layer.

Jump to

Keyboard shortcuts

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