service

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultReplicationPort = 1001
View Source
const HandlerLabel = "handler"
View Source
const IdentityReplicationPush = "/_matrix/identity/replicate/v1/push"
View Source
const SIGNING_KEY_ALGORITHM = "ed25519"

Variables

View Source
var ErrMissingThreepid = models.NewError(
	models.ErrMissingParam,
	"missing threepids in request body",
)
View Source
var ErrNoMatchingSignature = errors.New("no matching signatures found")

ErrNoMatchingSignature is returned when there is no signatures for this server found in a signed association object.

View Source
var ErrNoSignature = errors.New("no signatures found")

ErrNoSignature is returned when there is no signatures field in a signed message object.

View Source
var ErrPublicKeyNotFound = models.NewError(
	models.ErrNotFound,
	"The public key was not found",
)

ErrPublicKeyNotFound shortcut for the error object returned when there is no public key found.

View Source
var ErrThreepidNotAList = models.NewError(
	models.ErrInvalidParam,
	"threepids must be a list",
)

Functions

func AddBinding

func AddBinding(coreContext *core.Ctx) func(context.Context, string, string, string) (signedjson.Message, error)

func AssociationFromMap

func AssociationFromMap(m map[string]interface{}) (*models.Association, error)

func Bind

func Bind(coreContext *core.Ctx, m Metric) echo.HandlerFunc

Bind returns a handler that binds third party id to matrix id. You can think of this in the following terms.

Say, you own an email address foo@example.com . The server running this handler is serving requests on bar.com. Now, you want to use bar.com for identification with people you want to chat with in the matrix multiverse.

So you tell bar.com that you are the owner of foo@example.com , bar.com will send you a verification email to make sure you are you, after verifying the email now bar.com knows who you are, so it gives you another id which is recognized by other applications running in the multiverse example @foo:bar.com.

You will become @foo:bar.com to the rest of the matrix multiverse and foo@example.com to bar.com only.

This handler takes care of the binding of foo@example.com => @foo:bar.com. Note that, verification of who you are is done by another handler, this just make sure this server remembers who you really are and assignment of your matrix id.

func BulkLookup

func BulkLookup(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func CORS

func CORS() middleware.CORSConfig

CORS configures echo middleware for identity service cors.

func EmailRequestCode

func EmailRequestCode(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func EphemeralIsValid

func EphemeralIsValid(coreContext *core.Ctx) echo.HandlerFunc

EphemeralIsValid checks if a short term public key is valid.

func GetEmailValidatedCode

func GetEmailValidatedCode(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func GetPublicKey

func GetPublicKey(coreContext *core.Ctx) echo.HandlerFunc

GetPublicKey uses key id to search for a stored public key pinned by this server.

func GetReplicationURLFromPeer

func GetReplicationURLFromPeer(cfg *config.Matrix, peer *models.Peer) string

GetReplicationURLFromPeer returns a url string for replication on peer.

func GetValidated3PID

func GetValidated3PID(coreContext *core.Ctx, mx Metric) echo.HandlerFunc

func GetVerifyKeyFromPeer

func GetVerifyKeyFromPeer(p *models.Peer) (*signedjson.Key, error)

GetVerifyKeyFromPeer returns the verification key for peer.

func InternalError

func InternalError(ctx echo.Context) error

InternalError renders json for internal server errors. We don't divulge reasons for internal errors

func LocalPusher

func LocalPusher(coreContext *core.Ctx) func(context.Context) error

func Lookup

func Lookup(coreContext *core.Ctx, m Metric) echo.HandlerFunc

Lookup gets a 3pid bound to a matrix user id.

func PostEmailValidatedCode

func PostEmailValidatedCode(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func PublicKeyIsValid

func PublicKeyIsValid(coreContext *core.Ctx) echo.HandlerFunc

PublicKeyIsValid checks if a public key is valid.

func PushToRemotePeer

func PushToRemotePeer(cfg *config.Matrix, peer *models.Peer, replica config.HTTPClient, as []Association) error

PushToRemotePeer pushes signed associations to a remote identity service peer.

replica is the client used for replication.

func RemoveBinding

func RemoveBinding(coreContext *core.Ctx) func(context.Context, *models.Association) error

func Replicate

func Replicate(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func RequestEmailToken

func RequestEmailToken(ctx context.Context, coreContext *core.Ctx, req *TokenRequest) (int64, error)

func RequestError

func RequestError(lg logger.Logger, req *http.Request, err error)

RequestError logs an error that occurred during request processing. Fields of interest are url Path and Method.

func Service

func Service(opts *core.Ctx, m Metric) *echo.Echo

func SessionWithToken

func SessionWithToken(ctx context.Context, coreContext *core.Ctx, sid int64, clientSecret, token string) error

func SignED25519

func SignED25519(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func Signer

func Signer(coreContext *core.Ctx) func(*models.Association) (signedjson.Message, error)

func StoreInvite

func StoreInvite(coreContext *core.Ctx, m Metric) echo.HandlerFunc

func Unbind

func Unbind(coreContext *core.Ctx, fedClient config.HTTPClient) echo.HandlerFunc

func VerifySignedAssociation

func VerifySignedAssociation(ctx context.Context, key *signedjson.Key, serverName string, msg signedjson.Message) error

func Version

func Version(ctx echo.Context) error

Types

type Association

type Association struct {
	OriginID          int64
	SignedAssociation signedjson.Message
}

Association defines association tuple that is shared during replication.

type Key

type Key struct {
	Key       string `json:"key"`
	ExpiredTS int64  `json:"expired_ts,omitempty"`
}

type Metric

type Metric interface {
	// CountError returns collector for error counts in an handler. By error counts
	// it means an occupance of if err!=nil expression in the handler body. This is
	// to allow high quality code as the API is already final and cover small
	// surface area.
	//
	// We hope to achieve 0 runtime errors for this service deployments.
	CountError(handler string) prometheus.Counter
}

type MetricApi

type MetricApi struct {
	ErrorCount *prometheus.CounterVec
	// contains filtered or unexported fields
}

func NewMetric

func NewMetric() MetricApi

func (MetricApi) CountError

func (m MetricApi) CountError(handler string) prometheus.Counter

type Payload

type Payload struct {
	SignedAssociations []Association `json:"sgAssocs,omitempty"`
}

type Peer

type Peer interface {
	PushUpdates(context.Context, []Association) error
}

Peer is an interface for replicating messages across matrix peers.

type PushFunc

type PushFunc func(context.Context, []Association) error

PushFunc defines a function that implements Peer interface.

func PushLocal

func PushLocal(coreContext *core.Ctx) PushFunc

PushLocal pushes associations within the same host/instance. This copies associations from local table to the global association table.

func (PushFunc) PushUpdates

func (pf PushFunc) PushUpdates(ctx context.Context, as []Association) error

PushUpdates wrapper for implementing Peer interface on pf.

type ServerKeys

type ServerKeys struct {
	Name          string                       `json:"server_name"`
	VerifyKeys    map[string]Key               `json:"verify_keys"`
	OldVerifyKeys map[string]Key               `json:"old_verify_keys"`
	Signatures    map[string]map[string]string `json:"signatures"`
	ValidUntil    int64                        `json:"valid_until_ts"`
}

ServerKeys is an object returned when asking for verification keys on a matrix server

type TokenRequest

type TokenRequest struct {
	Email        string
	ClientSecret string
	SendAttempt  int64
	NextLink     string
	IP           net.IP
}

type UnbindOption

type UnbindOption struct {
	Threepid *models.Association `json:"threepid,omitempty"`
	MatrixID string              `json:"mxid"`
}

Jump to

Keyboard shortcuts

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