federation

package module
v0.0.0-...-34a32d4 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: GPL-3.0 Imports: 24 Imported by: 11

README

GangGo Federation Library

pipeline status coverage report Documentation testsuite

Federation library for golang to communicate with the diaspora protocol

Dependencies

For parsing hcard's the library requires a third party lib:

github.com/PuerkitoBio/goquery

Documentation

Overview

GangGo Federation Library Copyright (C) 2017-2018 Lukas Matt <lukas@zauberstuhl.de>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Package federation is a library to communicate between fediverse protocols

SENDING

To send a entity to a fediverse server we simply have to construct one with the protocol we want to use and hit send! :)

msg := federation.NewMessagePost(federation.DiasporaProtocol)
msg.SetAuthor(author)
msg.SetText(text)
msg.SetGuid(guid)
msg.SetPublic(public)
msg.SetCreatedAt(createdAt)
err = msg.Send(endpoint, privKey, pubKey)
if err != nil {
	[...]
}

RECEIVING

Diaspora

To receive and parser diaspora requests `federation.DiasporaParse` and `federation.DiasporaParseEncrypted` is used.

Diaspora has to main routes to receive entities: 1) /receive/public 2) /receive/private/:guid

If we receive something via 1) it will be in a xml format and can be parsed without encryption in the first place. If we receive a entity via 2) we have to decrypt the xml first. This is better described here: https://diaspora.github.io/diaspora_federation/federation/encryption.html

ActivityPub

[...]

After we succesfully parsed the request we will end up with a `Message` interface which includes the `MessageBase` and can be type casted to every entity message. Afterwards all information can be retrieved via abstraction methods e.g. entity.Author()

Index

Constants

View Source
const (
	CONTENT_TYPE_ENVELOPE = "application/magic-envelope+xml"
	CONTENT_TYPE_JSON     = "application/json"
	CONTENT_TYPE_JSONLD   = "application/ld+json"
	CONTENT_TYPE_TEXTHTML = "text/html"
	CONTENT_TYPE_XRDXML   = "application/xrd+xml"
	USER_AGENT            = "GangGo/v0 (Federation library)"
)
View Source
const (
	LOG_C_TUR    = "\033[0;36m"
	LOG_C_RED    = "\033[31m"
	LOG_C_YELLOW = "\033[33m"
	LOG_C_RESET  = "\033[0m"
)
View Source
const (
	HttpApHeader = "x-ap-object"

	// protocols
	DiasporaProtocol Protocol = 100 + iota
	ActivityPubProtocol

	// entity names
	Retraction    EntityType = "retraction"
	Profile       EntityType = "profile"
	StatusMessage EntityType = "status_message"
	Reshare       EntityType = "reshare"
	Comment       EntityType = "comment"
	Like          EntityType = "like"
	Contact       EntityType = "contact"
	Unknown       EntityType = "unknown"

	// webfinger
	WebFingerOstatus  = "http://ostatus.org/schema/1.0/subscribe"
	WebFingerHcard    = "http://microformats.org/profile/hcard"
	WebFingerDiaspora = "http://joindiaspora.com/seed_location"
	WebFingerSelf     = "self"

	// signatures
	SignatureDelimiter       = "."
	SignatureAuthorDelimiter = ";"
	SignatureHTTPDelimiter   = "\n"
)
View Source
const (
	XMLNS           = "https://joindiaspora.com/protocol"
	XMLNS_ME        = "http://salmon-protocol.org/ns/magic-env"
	APPLICATION_XML = "application/xml"
	BASE64_URL      = "base64url"
	RSA_SHA256      = "RSA-SHA256"
)

Diaspora

View Source
const (
	ACTIVITY_STREAMS        = "https://www.w3.org/ns/activitystreams"
	ACTIVITY_STREAMS_PUBLIC = ACTIVITY_STREAMS + "#Public"

	ActivityTypeUndo                  = "Undo"
	ActivityTypeFollow                = "Follow"
	ActivityTypeDelete                = "Delete"
	ActivityTypeAccept                = "Accept"
	ActivityTypeCreate                = "Create"
	ActivityTypeUpdate                = "Update"
	ActivityTypeLike                  = "Like"
	ActivityTypeNote                  = "Note"
	ActivityTypePerson                = "Person"
	ActivityTypeCollection            = "Collection"
	ActivityTypeOrderedCollection     = "OrderedCollection"
	ActivityTypeCollectionPage        = "CollectionPage"
	ActivityTypeOrderedCollectionPage = "OrderedCollectionPage"
)

ActivityPub

Variables

View Source
var (
	ERR_APU_MISSING_OBJT = errors.New("missing object attribute in request")
	ERR_APU_MISSING_TYPE = errors.New("missing type in request")
	ERR_APU_MISSING_ATTR = errors.New("missing attribute in body")

	ERR_INVALID_ENDPOINT = errors.New("endpoint is invalid")
	ERR_TYPE_CAST        = errors.New("cannot type cast")
	ERR_NOT_IMPLEMENTED  = errors.New("not implemented")
)

Functions

func DiasporaEncryptedMagicEnvelope

func DiasporaEncryptedMagicEnvelope(privKey *rsa.PrivateKey, pubKey *rsa.PublicKey, handle string, serializedXml []byte) (payload []byte, err error)

func DiasporaFetchOrder

func DiasporaFetchOrder(entity []byte) (string, error)

func DiasporaMagicEnvelope

func DiasporaMagicEnvelope(privKey *rsa.PrivateKey, handle string, plainXml []byte) (payload []byte, err error)

func DiasporaSortByOrder

func DiasporaSortByOrder(order string, entity []byte) (sorted []byte, err error)

func FetchHtml

func FetchHtml(method, url string, body io.Reader) (resp *http.Response, err error)

FetchHtml fetches from an url with optional body and content-type html

func FetchJson

func FetchJson(method, url string, body io.Reader, result interface{}) error

FetchJson fetches from an url with optional body and content-type json

func FetchXml

func FetchXml(method, url string, body io.Reader, result interface{}) error

FetchXml fetches from an url with optional body and content-type xml

func SetConfig

func SetConfig(userConfig Config)

func SetLogger

func SetLogger(writer LogWriter)

SetLogger sets the logger interface and makes it possible to include log output in your application logs

Types

type ActivityPubAccept

type ActivityPubAccept struct {
	ActivityPubContext
	Actor  string            `json:"actor"`
	Object ActivityPubFollow `json:"object"`
}

func (*ActivityPubAccept) Marshal

func (e *ActivityPubAccept) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*ActivityPubAccept) Unmarshal

func (e *ActivityPubAccept) Unmarshal(b []byte) error

type ActivityPubActor

type ActivityPubActor struct {
	ActivityPubContext
	Inbox     string `json:"inbox"`
	Outbox    string `json:"outbox"`
	Following string `json:"following"`
	Followers string `json:"followers"`

	PreferredUsername *string                    `json:"preferredUsername,omitempty"`
	Name              *string                    `json:"name,omitempty"`
	Summary           *string                    `json:"summary,omitempty"`
	Url               *string                    `json:"url,omitempty"`
	PublicKey         *ActivityPubActorPubKey    `json:"publicKey,omitempty"`
	Icon              *ActivityPubActorIcon      `json:"icon,omitempty"`
	Endpoints         *ActivityPubActorEndpoints `json:"endpoints,omitempty"`
}

type ActivityPubActorEndpoints

type ActivityPubActorEndpoints struct {
	SharedInbox string `json:"sharedInbox"`
}

type ActivityPubActorIcon

type ActivityPubActorIcon struct {
	Url string `json:"url"`
}

type ActivityPubActorPubKey

type ActivityPubActorPubKey struct {
	Id           string `json:"id"`
	Owner        string `json:"owner"`
	PublicKeyPem string `json:"publicKeyPem"`
}

type ActivityPubAttachment

type ActivityPubAttachment struct {
	Type      string `json:"type"`
	MediaType string `json:"mediaType"`
	Url       string `json:"url"`
}

type ActivityPubBase

type ActivityPubBase struct {
	Id   string `json:"id"`
	Type string `json:"type"`
}

type ActivityPubCollection

type ActivityPubCollection struct {
	ActivityPubContext
	TotalItems int     `json:"totalItems"`
	First      *string `json:"first,omitempty"`
}

type ActivityPubCollectionPage

type ActivityPubCollectionPage struct {
	ActivityPubContext
	TotalItems   int         `json:"totalItems"`
	Next         *string     `json:"next,omitempty"`
	PartOf       string      `json:"partOf"`
	Items        interface{} `json:"items,omitempty"`
	OrderedItems interface{} `json:"orderedItems,omitempty"`
}

type ActivityPubContext

type ActivityPubContext struct {
	Context []interface{} `json:"@context"`
	ActivityPubBase
}

type ActivityPubCreate

type ActivityPubCreate struct {
	ActivityPubContext `json:",omitempty"`
	Actor              string          `json:"actor"`
	Published          helpers.Time    `json:"published"`
	To                 []string        `json:"to"`
	Cc                 []string        `json:"cc"`
	Object             ActivityPubNote `json:"object"`
}

func (*ActivityPubCreate) Author

func (e *ActivityPubCreate) Author() string

func (*ActivityPubCreate) Marshal

func (e *ActivityPubCreate) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*ActivityPubCreate) Recipients

func (e *ActivityPubCreate) Recipients() []string

func (*ActivityPubCreate) Send

func (e *ActivityPubCreate) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*ActivityPubCreate) SetAuthor

func (e *ActivityPubCreate) SetAuthor(author string)

func (*ActivityPubCreate) SetRecipients

func (e *ActivityPubCreate) SetRecipients(recipients []string)

func (*ActivityPubCreate) Unmarshal

func (e *ActivityPubCreate) Unmarshal(b []byte) error

type ActivityPubCreateComment

type ActivityPubCreateComment struct {
	ActivityPubCreate
}

func (*ActivityPubCreateComment) CreatedAt

func (e *ActivityPubCreateComment) CreatedAt() helpers.Time

func (*ActivityPubCreateComment) Guid

func (e *ActivityPubCreateComment) Guid() string

func (*ActivityPubCreateComment) Parent

func (e *ActivityPubCreateComment) Parent() string

func (*ActivityPubCreateComment) SetAuthor

func (e *ActivityPubCreateComment) SetAuthor(author string)

func (*ActivityPubCreateComment) SetCreatedAt

func (e *ActivityPubCreateComment) SetCreatedAt(createdAt time.Time)

func (*ActivityPubCreateComment) SetGuid

func (e *ActivityPubCreateComment) SetGuid(guid string)

func (*ActivityPubCreateComment) SetParent

func (e *ActivityPubCreateComment) SetParent(guid string)

func (*ActivityPubCreateComment) SetSignature

func (e *ActivityPubCreateComment) SetSignature(priv *rsa.PrivateKey) error

func (*ActivityPubCreateComment) SetText

func (e *ActivityPubCreateComment) SetText(text string)

func (*ActivityPubCreateComment) Signature

func (e *ActivityPubCreateComment) Signature() string

func (*ActivityPubCreateComment) SignatureOrder

func (e *ActivityPubCreateComment) SignatureOrder() string

func (*ActivityPubCreateComment) Text

func (e *ActivityPubCreateComment) Text() string

func (*ActivityPubCreateComment) Type

type ActivityPubCreatePost

type ActivityPubCreatePost struct {
	ActivityPubCreate
}

func (*ActivityPubCreatePost) CreatedAt

func (e *ActivityPubCreatePost) CreatedAt() helpers.Time

func (*ActivityPubCreatePost) FilePaths

func (e *ActivityPubCreatePost) FilePaths() (files []string)

func (*ActivityPubCreatePost) Guid

func (e *ActivityPubCreatePost) Guid() string

func (*ActivityPubCreatePost) Provider

func (e *ActivityPubCreatePost) Provider() string

func (*ActivityPubCreatePost) Public

func (e *ActivityPubCreatePost) Public() bool

func (*ActivityPubCreatePost) SetAuthor

func (e *ActivityPubCreatePost) SetAuthor(author string)

func (*ActivityPubCreatePost) SetCreatedAt

func (e *ActivityPubCreatePost) SetCreatedAt(createdAt time.Time)

func (*ActivityPubCreatePost) SetGuid

func (e *ActivityPubCreatePost) SetGuid(guid string)

func (*ActivityPubCreatePost) SetProvider

func (e *ActivityPubCreatePost) SetProvider(provider string)

func (*ActivityPubCreatePost) SetPublic

func (e *ActivityPubCreatePost) SetPublic(public bool)

func (*ActivityPubCreatePost) SetText

func (e *ActivityPubCreatePost) SetText(text string)

func (*ActivityPubCreatePost) Text

func (e *ActivityPubCreatePost) Text() string

func (*ActivityPubCreatePost) Type

type ActivityPubFollow

type ActivityPubFollow struct {
	ActivityPubContext
	Actor     string `json:"actor"`
	Object    string `json:"object"`
	Following helpers.ReadOnlyBool
}

func (*ActivityPubFollow) Author

func (e *ActivityPubFollow) Author() string

func (*ActivityPubFollow) Marshal

func (e *ActivityPubFollow) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*ActivityPubFollow) Recipient

func (e *ActivityPubFollow) Recipient() string

func (*ActivityPubFollow) Send

func (e *ActivityPubFollow) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*ActivityPubFollow) SetAuthor

func (e *ActivityPubFollow) SetAuthor(author string)

func (*ActivityPubFollow) SetRecipient

func (e *ActivityPubFollow) SetRecipient(recipient string)

func (*ActivityPubFollow) SetSharing

func (e *ActivityPubFollow) SetSharing(sharing bool)

func (*ActivityPubFollow) Sharing

func (e *ActivityPubFollow) Sharing() bool

func (*ActivityPubFollow) Type

func (e *ActivityPubFollow) Type() MessageType

func (*ActivityPubFollow) Unmarshal

func (e *ActivityPubFollow) Unmarshal(b []byte) error

type ActivityPubLike

type ActivityPubLike struct {
	ActivityPubContext
	Actor  string `json:"actor"`
	Object string `json:"object"`
}

func (*ActivityPubLike) Author

func (e *ActivityPubLike) Author() string

func (*ActivityPubLike) Guid

func (e *ActivityPubLike) Guid() string

func (*ActivityPubLike) Marshal

func (e *ActivityPubLike) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*ActivityPubLike) Parent

func (e *ActivityPubLike) Parent() string

func (*ActivityPubLike) Positive

func (e *ActivityPubLike) Positive() bool

func (*ActivityPubLike) Send

func (e *ActivityPubLike) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*ActivityPubLike) SetAuthor

func (e *ActivityPubLike) SetAuthor(author string)

func (*ActivityPubLike) SetGuid

func (e *ActivityPubLike) SetGuid(guid string)

func (*ActivityPubLike) SetParent

func (e *ActivityPubLike) SetParent(guid string)

func (*ActivityPubLike) SetPositive

func (e *ActivityPubLike) SetPositive(positive bool)

func (*ActivityPubLike) SetSignature

func (e *ActivityPubLike) SetSignature(priv *rsa.PrivateKey) error

func (*ActivityPubLike) Signature

func (e *ActivityPubLike) Signature() string

func (*ActivityPubLike) SignatureOrder

func (e *ActivityPubLike) SignatureOrder() string

func (*ActivityPubLike) Type

func (e *ActivityPubLike) Type() MessageType

func (*ActivityPubLike) Unmarshal

func (e *ActivityPubLike) Unmarshal(b []byte) error

type ActivityPubMessage

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

func ActivityPubParse

func ActivityPubParse(r *http.Request) (m ActivityPubMessage, err error)

func (ActivityPubMessage) Entity

func (m ActivityPubMessage) Entity() MessageBase

func (ActivityPubMessage) Parse

func (m ActivityPubMessage) Parse(body []byte) (MessageBase, error)

func (ActivityPubMessage) Type

func (ActivityPubMessage) ValidSignature

func (m ActivityPubMessage) ValidSignature(pub *rsa.PublicKey) bool

type ActivityPubNote

type ActivityPubNote struct {
	ActivityPubBase `json:",omitempty"`
	Actor           string       `json:"actor,omitempty"`
	Summary         string       `json:"summary"`
	Content         string       `json:"content"`
	InReplyTo       string       `json:"inReplyTo"`
	Published       helpers.Time `json:"published"`
	Url             string       `json:"url"`
	AttributedTo    string       `json:"attributedTo"`
	// NOTE mastodon is not using it ??
	// see Public method for current implementation
	Sensitive  bool                    `json:"sensitive"`
	To         []string                `json:"to"`
	Cc         []string                `json:"cc"`
	Attachment []ActivityPubAttachment `json:"attachment,omitempty"`
	Tags       *ActivityPubNoteTags    `json:"tag,omitempty"`
}

type ActivityPubNoteTag

type ActivityPubNoteTag struct {
	Type string `json:"type"`
	Href string `json:"href"`
	Name string `json:"name"`
}

type ActivityPubNoteTags

type ActivityPubNoteTags []ActivityPubNoteTag

type ActivityPubRetract

type ActivityPubRetract struct {
	ActivityPubContext
	Actor  string                 `json:"actor"`
	Object map[string]interface{} `json:"object"`
}

func (*ActivityPubRetract) Author

func (e *ActivityPubRetract) Author() string

func (*ActivityPubRetract) Marshal

func (e *ActivityPubRetract) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*ActivityPubRetract) ParentGuid

func (e *ActivityPubRetract) ParentGuid() string

func (*ActivityPubRetract) ParentType

func (e *ActivityPubRetract) ParentType() EntityType

func (*ActivityPubRetract) Send

func (e *ActivityPubRetract) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*ActivityPubRetract) SetAuthor

func (e *ActivityPubRetract) SetAuthor(author string)

func (*ActivityPubRetract) SetParentGuid

func (e *ActivityPubRetract) SetParentGuid(guid string)

func (*ActivityPubRetract) SetParentType

func (e *ActivityPubRetract) SetParentType(entityType EntityType)

func (*ActivityPubRetract) Type

func (e *ActivityPubRetract) Type() MessageType

func (*ActivityPubRetract) Unmarshal

func (e *ActivityPubRetract) Unmarshal(b []byte) error

type ActivityPubUpdate

type ActivityPubUpdate struct {
	ActivityPubContext
	Actor  string           `json:"actor"`
	Object ActivityPubActor `json:"object"`
}

func (*ActivityPubUpdate) Author

func (actor *ActivityPubUpdate) Author() string

func (*ActivityPubUpdate) Bio

func (actor *ActivityPubUpdate) Bio() string

func (*ActivityPubUpdate) Birthday

func (actor *ActivityPubUpdate) Birthday() string

func (*ActivityPubUpdate) FirstName

func (actor *ActivityPubUpdate) FirstName() string

func (*ActivityPubUpdate) Gender

func (actor *ActivityPubUpdate) Gender() string

func (*ActivityPubUpdate) ImageUrl

func (actor *ActivityPubUpdate) ImageUrl() string

func (*ActivityPubUpdate) LastName

func (actor *ActivityPubUpdate) LastName() string

func (*ActivityPubUpdate) Location

func (actor *ActivityPubUpdate) Location() string

func (*ActivityPubUpdate) Marshal

func (actor *ActivityPubUpdate) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*ActivityPubUpdate) Nsfw

func (actor *ActivityPubUpdate) Nsfw() bool

func (*ActivityPubUpdate) Public

func (actor *ActivityPubUpdate) Public() bool

func (*ActivityPubUpdate) Send

func (actor *ActivityPubUpdate) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*ActivityPubUpdate) SetAuthor

func (actor *ActivityPubUpdate) SetAuthor(author string)

func (*ActivityPubUpdate) Type

func (actor *ActivityPubUpdate) Type() MessageType

func (*ActivityPubUpdate) Unmarshal

func (actor *ActivityPubUpdate) Unmarshal(b []byte) error

type Config

type Config struct {
	Host, ApiVersion           string
	GuidURLFormat, ApURLFormat string
	// contains filtered or unexported fields
}

func (*Config) Configure

func (c *Config) Configure()

func (*Config) GuidURLRegExp

func (c *Config) GuidURLRegExp() string

type DiasporaAes

type DiasporaAes struct {
	Key  string `json:"key,omitempty"`
	Iv   string `json:"iv,omitempty"`
	Data string `json:"-"`
}

func (DiasporaAes) Decrypt

func (a DiasporaAes) Decrypt() (ciphertext []byte, err error)

func (*DiasporaAes) Encrypt

func (a *DiasporaAes) Encrypt(data []byte) error

func (*DiasporaAes) Generate

func (a *DiasporaAes) Generate() error

type DiasporaAesWrapper

type DiasporaAesWrapper struct {
	AesKey        string `json:"aes_key"`
	MagicEnvelope string `json:"encrypted_magic_envelope"`
}

func (DiasporaAesWrapper) Decrypt

func (w DiasporaAesWrapper) Decrypt(privKey *rsa.PrivateKey) (entityXML []byte, err error)

type DiasporaComment

type DiasporaComment struct {
	XMLName               xml.Name     `xml:"comment"`
	EntityAuthor          string       `xml:"author"`
	EntityCreatedAt       helpers.Time `xml:"created_at"`
	EntityGuid            string       `xml:"guid"`
	EntityParentGuid      string       `xml:"parent_guid"`
	EntityText            string       `xml:"text"`
	EntityAuthorSignature string       `xml:"author_signature"`

	// store relayable signature order
	EntitySignatureOrder string `xml:"-"`
	// store original entity in case we relay it
	EntityRaw []byte `xml:"-"`
}

func (*DiasporaComment) Author

func (e *DiasporaComment) Author() string

func (*DiasporaComment) CreatedAt

func (e *DiasporaComment) CreatedAt() helpers.Time

func (*DiasporaComment) Guid

func (e *DiasporaComment) Guid() string

func (*DiasporaComment) Marshal

func (e *DiasporaComment) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) (payload []byte, err error)

func (*DiasporaComment) Parent

func (e *DiasporaComment) Parent() string

func (*DiasporaComment) Recipients

func (e *DiasporaComment) Recipients() []string

func (*DiasporaComment) Send

func (e *DiasporaComment) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaComment) SetAuthor

func (e *DiasporaComment) SetAuthor(author string)

func (*DiasporaComment) SetCreatedAt

func (e *DiasporaComment) SetCreatedAt(createdAt time.Time)

func (*DiasporaComment) SetGuid

func (e *DiasporaComment) SetGuid(guid string)

func (*DiasporaComment) SetParent

func (e *DiasporaComment) SetParent(guid string)

func (*DiasporaComment) SetRecipients

func (e *DiasporaComment) SetRecipients(recipients []string)

func (*DiasporaComment) SetSignature

func (e *DiasporaComment) SetSignature(priv *rsa.PrivateKey) error

func (*DiasporaComment) SetText

func (e *DiasporaComment) SetText(text string)

func (*DiasporaComment) Signature

func (e *DiasporaComment) Signature() string

func (*DiasporaComment) SignatureOrder

func (e *DiasporaComment) SignatureOrder() string

func (*DiasporaComment) Text

func (e *DiasporaComment) Text() string

func (*DiasporaComment) Type

func (e *DiasporaComment) Type() MessageType

func (*DiasporaComment) Unmarshal

func (e *DiasporaComment) Unmarshal(b []byte) error

type DiasporaContact

type DiasporaContact struct {
	XMLName         xml.Name `xml:"contact"`
	EntityAuthor    string   `xml:"author"`
	EntityRecipient string   `xml:"recipient"`
	EntityFollowing bool     `xml:"following"`
	EntitySharing   bool     `xml:"sharing"`
	EntityBlocking  bool     `xml:"blocking"`
}

func (*DiasporaContact) Author

func (e *DiasporaContact) Author() string

func (*DiasporaContact) Marshal

func (e *DiasporaContact) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*DiasporaContact) Recipient

func (e *DiasporaContact) Recipient() string

func (*DiasporaContact) Send

func (e *DiasporaContact) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaContact) SetAuthor

func (e *DiasporaContact) SetAuthor(author string)

func (*DiasporaContact) SetRecipient

func (e *DiasporaContact) SetRecipient(recipient string)

func (*DiasporaContact) SetSharing

func (e *DiasporaContact) SetSharing(sharing bool)

func (*DiasporaContact) Sharing

func (e *DiasporaContact) Sharing() bool

func (*DiasporaContact) Type

func (e *DiasporaContact) Type() MessageType

func (*DiasporaContact) Unmarshal

func (e *DiasporaContact) Unmarshal(b []byte) error

type DiasporaEntity

type DiasporaEntity struct {
	XMLName xml.Name
	// Use custom unmarshaler for xml fetch XMLName
	// and decide which entity to use
	Type           string      `xml:"-"`
	SignatureOrder string      `xml:"-"`
	Data           MessageBase `xml:"-"`
	DataRaw        []byte      `xml:"-"`
}

func (*DiasporaEntity) UnmarshalXML

func (e *DiasporaEntity) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type DiasporaEvent

type DiasporaEvent struct {
	Author      string            `xml:"author"`
	Guid        string            `xml:"guid"`
	Summary     string            `xml:"summary"`
	Start       helpers.Time      `xml:"start"`
	End         helpers.Time      `xml:"end"`
	AllDay      bool              `xml:"all_day"`
	Timezone    string            `xml:"timezone"`
	Description string            `xml:"description"`
	Location    *DiasporaLocation `xml:"location,omitempty"`
}

type DiasporaLike

type DiasporaLike struct {
	XMLName               xml.Name `xml:"like"`
	EntityPositive        bool     `xml:"positive"`
	EntityGuid            string   `xml:"guid"`
	EntityParentGuid      string   `xml:"parent_guid"`
	EntityParentType      string   `xml:"parent_type"`
	EntityAuthor          string   `xml:"author"`
	EntityAuthorSignature string   `xml:"author_signature"`

	// store relayable signature order
	EntitySignatureOrder string `xml:"-"`
	// store original entity in case we relay it
	EntityRaw []byte `xml:"-"`
}

func (*DiasporaLike) Author

func (e *DiasporaLike) Author() string

func (*DiasporaLike) Guid

func (e *DiasporaLike) Guid() string

func (*DiasporaLike) Marshal

func (e *DiasporaLike) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) (payload []byte, err error)

func (*DiasporaLike) Parent

func (e *DiasporaLike) Parent() string

func (*DiasporaLike) Positive

func (e *DiasporaLike) Positive() bool

func (*DiasporaLike) Send

func (e *DiasporaLike) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaLike) SetAuthor

func (e *DiasporaLike) SetAuthor(author string)

func (*DiasporaLike) SetGuid

func (e *DiasporaLike) SetGuid(guid string)

func (*DiasporaLike) SetParent

func (e *DiasporaLike) SetParent(guid string)

func (*DiasporaLike) SetPositive

func (e *DiasporaLike) SetPositive(positive bool)

func (*DiasporaLike) SetSignature

func (e *DiasporaLike) SetSignature(priv *rsa.PrivateKey) error

func (*DiasporaLike) Signature

func (e *DiasporaLike) Signature() string

func (*DiasporaLike) SignatureOrder

func (e *DiasporaLike) SignatureOrder() string

func (*DiasporaLike) Type

func (e *DiasporaLike) Type() MessageType

func (*DiasporaLike) Unmarshal

func (e *DiasporaLike) Unmarshal(b []byte) error

type DiasporaLocation

type DiasporaLocation struct {
	Address string `xml:"address"`
	Lat     string `xml:"lat"`
	Lng     string `xml:"lng"`
}

type DiasporaMessage

type DiasporaMessage struct {
	XMLName xml.Name `xml:"me:env"`
	Me      string   `xml:"me,attr"`
	Data    struct {
		XMLName xml.Name `xml:"me:data"`
		Type    string   `xml:"type,attr"`
		Data    string   `xml:",chardata"`
	}
	Encoding string `xml:"me:encoding"`
	Alg      string `xml:"me:alg"`
	Sig      struct {
		XMLName xml.Name `xml:"me:sig"`
		Sig     string   `xml:",chardata"`
		KeyId   string   `xml:"key_id,attr,omitempty"`
	}
	// contains filtered or unexported fields
}

func DiasporaParse

func DiasporaParse(raw []byte) (message DiasporaMessage, err error)

func DiasporaParseEncrypted

func DiasporaParseEncrypted(raw []byte, privKey *rsa.PrivateKey) (message DiasporaMessage, err error)

func (DiasporaMessage) Entity

func (m DiasporaMessage) Entity() MessageBase

func (*DiasporaMessage) Parse

func (message *DiasporaMessage) Parse() error

func (DiasporaMessage) Type

func (m DiasporaMessage) Type() MessageType

func (DiasporaMessage) ValidSignature

func (message DiasporaMessage) ValidSignature(pub *rsa.PublicKey) bool

type DiasporaPhoto

type DiasporaPhoto struct {
	Guid              string       `xml:"guid"`
	Author            string       `xml:"author"`
	Public            bool         `xml:"public"`
	CreatedAt         helpers.Time `xml:"created_at"`
	RemotePhotoPath   string       `xml:"remote_photo_path"`
	RemotePhotoName   string       `xml:"remote_photo_name"`
	Text              string       `xml:"text"`
	StatusMessageGuid string       `xml:"status_message_guid"`
	Height            int          `xml:"height"`
	Width             int          `xml:"width"`
}

type DiasporaPhotos

type DiasporaPhotos []DiasporaPhoto

type DiasporaPoll

type DiasporaPoll struct {
	Guid        string               `xml:"guid"`
	Question    string               `xml:"question"`
	PollAnswers []DiasporaPollAnswer `xml:"poll_answers"`
}

type DiasporaPollAnswer

type DiasporaPollAnswer struct {
	Guid   string `xml:"guid"`
	Answer string `xml:"answer"`
}

type DiasporaProfile

type DiasporaProfile struct {
	XMLName              xml.Name `xml:"profile"`
	EntityAuthor         string   `xml:"author"`
	EntityFirstName      string   `xml:"first_name"`
	EntityLastName       string   `xml:"last_name"`
	EntityImageUrl       string   `xml:"image_url"`
	EntityImageUrlMedium string   `xml:"image_url_medium"`
	EntityImageUrlSmall  string   `xml:"image_url_small"`
	EntityBirthday       string   `xml:"birthday"`
	EntityGender         string   `xml:"gender"`
	EntityBio            string   `xml:"bio"`
	EntityLocation       string   `xml:"location"`
	EntitySearchable     bool     `xml:"searchable"`
	EntityPublic         bool     `xml:"public"`
	EntityNsfw           bool     `xml:"nsfw"`
	EntityTagString      string   `xml:"tag_string"`
}

func (*DiasporaProfile) Author

func (e *DiasporaProfile) Author() string

func (*DiasporaProfile) Bio

func (e *DiasporaProfile) Bio() string

func (*DiasporaProfile) Birthday

func (e *DiasporaProfile) Birthday() string

func (*DiasporaProfile) FirstName

func (e *DiasporaProfile) FirstName() string

func (*DiasporaProfile) Gender

func (e *DiasporaProfile) Gender() string

func (*DiasporaProfile) ImageUrl

func (e *DiasporaProfile) ImageUrl() string

func (*DiasporaProfile) LastName

func (e *DiasporaProfile) LastName() string

func (*DiasporaProfile) Location

func (e *DiasporaProfile) Location() string

func (*DiasporaProfile) Marshal

func (e *DiasporaProfile) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*DiasporaProfile) Nsfw

func (e *DiasporaProfile) Nsfw() bool

func (*DiasporaProfile) Public

func (e *DiasporaProfile) Public() bool

func (*DiasporaProfile) Send

func (e *DiasporaProfile) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaProfile) SetAuthor

func (e *DiasporaProfile) SetAuthor(author string)

func (*DiasporaProfile) Type

func (e *DiasporaProfile) Type() MessageType

func (*DiasporaProfile) Unmarshal

func (e *DiasporaProfile) Unmarshal(b []byte) error

type DiasporaReshare

type DiasporaReshare struct {
	XMLName          xml.Name     `xml:"reshare"`
	EntityAuthor     string       `xml:"author"`
	EntityGuid       string       `xml:"guid"`
	EntityCreatedAt  helpers.Time `xml:"created_at"`
	EntityRootAuthor string       `xml:"root_author"`
	EntityRootGuid   string       `xml:"root_guid"`
}

func (*DiasporaReshare) Author

func (e *DiasporaReshare) Author() string

func (*DiasporaReshare) CreatedAt

func (e *DiasporaReshare) CreatedAt() helpers.Time

func (*DiasporaReshare) Guid

func (e *DiasporaReshare) Guid() string

func (*DiasporaReshare) Marshal

func (e *DiasporaReshare) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*DiasporaReshare) Parent

func (e *DiasporaReshare) Parent() string

func (*DiasporaReshare) ParentAuthor

func (e *DiasporaReshare) ParentAuthor() string

func (*DiasporaReshare) Send

func (e *DiasporaReshare) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaReshare) SetAuthor

func (e *DiasporaReshare) SetAuthor(author string)

func (*DiasporaReshare) SetCreatedAt

func (e *DiasporaReshare) SetCreatedAt(createdAt time.Time)

func (*DiasporaReshare) SetGuid

func (e *DiasporaReshare) SetGuid(guid string)

func (*DiasporaReshare) SetParent

func (e *DiasporaReshare) SetParent(guid string)

func (*DiasporaReshare) SetParentAuthor

func (e *DiasporaReshare) SetParentAuthor(author string)

func (*DiasporaReshare) Type

func (e *DiasporaReshare) Type() MessageType

func (*DiasporaReshare) Unmarshal

func (e *DiasporaReshare) Unmarshal(b []byte) error

type DiasporaRetraction

type DiasporaRetraction struct {
	XMLName          xml.Name `xml:"retraction"`
	EntityAuthor     string   `xml:"author"`
	EntityTargetGuid string   `xml:"target_guid"`
	EntityTargetType string   `xml:"target_type"`
}

func (*DiasporaRetraction) Author

func (e *DiasporaRetraction) Author() string

func (*DiasporaRetraction) Marshal

func (e *DiasporaRetraction) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*DiasporaRetraction) ParentGuid

func (e *DiasporaRetraction) ParentGuid() string

func (*DiasporaRetraction) ParentType

func (e *DiasporaRetraction) ParentType() EntityType

func (*DiasporaRetraction) Send

func (e *DiasporaRetraction) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaRetraction) SetAuthor

func (e *DiasporaRetraction) SetAuthor(author string)

func (*DiasporaRetraction) SetParentGuid

func (e *DiasporaRetraction) SetParentGuid(guid string)

func (*DiasporaRetraction) SetParentType

func (e *DiasporaRetraction) SetParentType(parentType EntityType)

func (*DiasporaRetraction) Type

func (e *DiasporaRetraction) Type() MessageType

func (*DiasporaRetraction) Unmarshal

func (e *DiasporaRetraction) Unmarshal(b []byte) error

type DiasporaStatusMessage

type DiasporaStatusMessage struct {
	XMLName            xml.Name          `xml:"status_message"`
	EntityAuthor       string            `xml:"author"`
	EntityGuid         string            `xml:"guid"`
	EntityCreatedAt    helpers.Time      `xml:"created_at"`
	EntityProviderName string            `xml:"provider_display_name"`
	EntityText         string            `xml:"text,omitempty"`
	EntityPhotos       *DiasporaPhotos   `xml:"photo,omitempty"`
	EntityLocation     *DiasporaLocation `xml:"location,omitempty"`
	EntityPoll         *DiasporaPoll     `xml:"poll,omitempty"`
	EntityPublic       bool              `xml:"public"`
	EntityEvent        *DiasporaEvent    `xml:"event,omitempty"`
}

func (*DiasporaStatusMessage) Author

func (e *DiasporaStatusMessage) Author() string

func (*DiasporaStatusMessage) CreatedAt

func (e *DiasporaStatusMessage) CreatedAt() helpers.Time

func (*DiasporaStatusMessage) FilePaths

func (e *DiasporaStatusMessage) FilePaths() (result []string)

func (*DiasporaStatusMessage) Guid

func (e *DiasporaStatusMessage) Guid() string

func (*DiasporaStatusMessage) Marshal

func (e *DiasporaStatusMessage) Marshal(priv *rsa.PrivateKey, pub *rsa.PublicKey) ([]byte, error)

func (*DiasporaStatusMessage) Provider

func (e *DiasporaStatusMessage) Provider() string

func (*DiasporaStatusMessage) Public

func (e *DiasporaStatusMessage) Public() bool

func (*DiasporaStatusMessage) Recipients

func (e *DiasporaStatusMessage) Recipients() []string

func (*DiasporaStatusMessage) Send

func (e *DiasporaStatusMessage) Send(inbox string, priv *rsa.PrivateKey, pub *rsa.PublicKey) error

func (*DiasporaStatusMessage) SetAuthor

func (e *DiasporaStatusMessage) SetAuthor(author string)

func (*DiasporaStatusMessage) SetCreatedAt

func (e *DiasporaStatusMessage) SetCreatedAt(createdAt time.Time)

func (*DiasporaStatusMessage) SetGuid

func (e *DiasporaStatusMessage) SetGuid(guid string)

func (*DiasporaStatusMessage) SetProvider

func (e *DiasporaStatusMessage) SetProvider(provider string)

func (*DiasporaStatusMessage) SetPublic

func (e *DiasporaStatusMessage) SetPublic(public bool)

func (*DiasporaStatusMessage) SetRecipients

func (e *DiasporaStatusMessage) SetRecipients(recipient []string)

func (*DiasporaStatusMessage) SetText

func (e *DiasporaStatusMessage) SetText(text string)

func (*DiasporaStatusMessage) Text

func (e *DiasporaStatusMessage) Text() string

func (*DiasporaStatusMessage) Type

func (*DiasporaStatusMessage) Unmarshal

func (e *DiasporaStatusMessage) Unmarshal(b []byte) error

type DiasporaXmlOrder

type DiasporaXmlOrder struct {
	XMLName xml.Name
	Order   []string               `xml:"-"`
	Lines   []DiasporaXmlOrderLine `xml:",any"`
}

func (DiasporaXmlOrder) Len

func (order DiasporaXmlOrder) Len() int

func (DiasporaXmlOrder) Less

func (order DiasporaXmlOrder) Less(i, j int) bool

func (DiasporaXmlOrder) Swap

func (order DiasporaXmlOrder) Swap(i, j int)

type DiasporaXmlOrderLine

type DiasporaXmlOrderLine struct {
	XMLName xml.Name
	Value   string `xml:",chardata"`
}

func (*DiasporaXmlOrderLine) UnmarshalXML

func (o *DiasporaXmlOrderLine) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type EntityType

type EntityType string

EntityType type specifies the different entities like comments or posts

type Hcard

type Hcard struct {
	Guid        string
	Nickname    string
	FullName    string
	Searchable  bool
	PublicKey   string
	FirstName   string
	LastName    string
	Url         string
	Photo       string
	PhotoMedium string
	PhotoSmall  string
}

Hcard is used by Diaspora to build and share user profiles

func (*Hcard) Fetch

func (h *Hcard) Fetch(endpoint string) error

Fetch will try parsing a html document after fetching it from a certain endpoint

type HttpClient

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

HttpClient struct can hold a private key and keyId for signing http headers this is required for ActivityPub communication

func (*HttpClient) New

func (c *HttpClient) New(id string, key *rsa.PrivateKey) *HttpClient

New can set private key and keyId for http header signing

func (HttpClient) Push

func (c HttpClient) Push(endpoint string, header http.Header, body io.Reader) error

Push can push a body with modified headers to a certain endpoint. If a private key is available it will also sign the http header. It will try https first and fallback to http if the first one fails!

type LogWriter

type LogWriter interface {
	Println(v ...interface{})
}

type Logger

type Logger struct {
	LogWriter

	Prefix string
}
var (
	// Log is the used logger for the federation library.
	// On default this is stdout but you can change it with SetLogger()
	Log Logger
)

func (Logger) Error

func (l Logger) Error(values ...interface{})

Error prints error messages and fatals

func (Logger) Info

func (l Logger) Info(values ...interface{})

Info prints information/debug messages

func (Logger) Warn

func (l Logger) Warn(values ...interface{})

Warn prints warnings

type Message

type Message interface {
	ValidSignature(*rsa.PublicKey) bool
	Type() MessageType
	Entity() MessageBase
}

Message is the main interface for handling requests. It will be returned by all [...]Parse(...) functions e.g. DiasporaParse() or ActivityPubParse()

type MessageBase

type MessageBase interface {
	Author() string
	SetAuthor(string)
	Unmarshal([]byte) error
	Type() MessageType
	Marshal(*rsa.PrivateKey, *rsa.PublicKey) ([]byte, error)
	Send(string, *rsa.PrivateKey, *rsa.PublicKey) error
}

MessageBase is the minimum what a entity has to support/implement

type MessageComment

type MessageComment interface {
	MessageRelayable
	Recipients() []string
	SetRecipients([]string)
	CreatedAt() helpers.Time
	SetCreatedAt(time.Time)
	Text() string
	SetText(string)
}

MessageComment represents a comment to a Post or Reshare it inherits MessageRelayable

func NewMessageComment

func NewMessageComment(proto Protocol) (MessageComment, error)

NewMessageComment will return a MessageComment interface depending on the specified Protocol

type MessageContact

type MessageContact interface {
	MessageBase
	Recipient() string
	SetRecipient(string)
	Sharing() bool
	SetSharing(bool)
}

MessageContact represents a state with another person it inherits MessageBase

func NewMessageContact

func NewMessageContact(proto Protocol) (MessageContact, error)

NewMessageContact will return a MessageContact interface depending on the specified Protocol

type MessageLike

type MessageLike interface {
	MessageRelayable
	Positive() bool
	SetPositive(bool)
}

MessageLike represents a like on a other entity e.g. a post it inherits MessageRelayable

func NewMessageLike

func NewMessageLike(proto Protocol) (MessageLike, error)

NewMessageLike will return a MessageLike interface depending on the specified Protocol

type MessagePost

type MessagePost interface {
	MessageBase
	Recipients() []string
	SetRecipients([]string)
	Guid() string
	SetGuid(string)
	CreatedAt() helpers.Time
	SetCreatedAt(time.Time)
	Provider() string
	SetProvider(string)
	Text() string
	SetText(string)
	Public() bool
	SetPublic(bool)
	FilePaths() []string
}

MessagePost represents a status message or post from a user it inherits MessageBase

func NewMessagePost

func NewMessagePost(proto Protocol) (MessagePost, error)

NewMessagePost will return a MessagePost interface depending on the specified Protocol

type MessageProfile

type MessageProfile interface {
	MessageBase
	FirstName() string
	LastName() string
	ImageUrl() string
	Birthday() string
	Gender() string
	Bio() string
	Location() string
	Public() bool
	Nsfw() bool
}

MessageProfile represents a user profile and inherits MessageBase

type MessageRelayable

type MessageRelayable interface {
	MessageBase
	Guid() string
	SetGuid(string)
	Parent() string
	SetParent(string)
	Signature() string
	SetSignature(*rsa.PrivateKey) error
	SignatureOrder() string
}

MessageRelayable represents a minimum required to relay child entities

type MessageReshare

type MessageReshare interface {
	MessageBase
	Guid() string
	SetGuid(string)
	Parent() string
	SetParent(string)
	ParentAuthor() string
	SetParentAuthor(string)
	CreatedAt() helpers.Time
	SetCreatedAt(time.Time)
}

MessageReshare represents a boost or reshare of a post or status message it also inherits MessageBase

func NewMessageReshare

func NewMessageReshare(proto Protocol) (MessageReshare, error)

NewMessageReshare will return a MessageReshare interface depending on the specified Protocol

type MessageRetract

type MessageRetract interface {
	MessageBase
	ParentGuid() string
	SetParentGuid(string)
	ParentType() EntityType
	SetParentType(EntityType)
}

func NewMessageRetract

func NewMessageRetract(proto Protocol) (MessageRetract, error)

NewMessageRetract will return a MessageRetract interface depending on the specified Protocol

type MessageType

type MessageType struct {
	Proto  Protocol
	Entity EntityType
}

MessageType defines what kind of message we are dealing with

type Protocol

type Protocol int

Protocol type specifies the kind of protocol e.g. Diaspora or ActivityPub

type WebFinger

type WebFinger struct {
	Host   string
	Handle string
	Data   WebfingerData
}

WebFinger will be used to discover users on different servers (see https://tools.ietf.org/html/rfc7033)

func (*WebFinger) Discovery

func (w *WebFinger) Discovery() error

Discovery will try fetching json data from a host. If that fails it will fallback to Diaspora XML webfinger

func (*WebFinger) Protocol

func (w *WebFinger) Protocol() Protocol

Protocol tries to identify a server by his webfinger profile

type WebfingerData

type WebfingerData struct {
	// xml
	XMLName xml.Name `xml:"XRD" json:"-"`
	Xmlns   string   `xml:"xmlns,attr" json:"-"`
	Alias   string   `xml:"Alias,omitempty" json:"-"`
	// json
	Aliases []string `json:"aliases" xml:"-"`

	Subject string              `json:"subject" xml:"Subject,omitempty"`
	Links   []WebfingerDataLink `json:"links" xml:"Link"`
}

WebfingerData holds and stores discovered webfinger profiles

type WebfingerDataLink struct {
	// xml
	XMLName xml.Name `xml:"Link" json:"-"`

	Rel      string `json:"rel" xml:"rel,attr"`
	Type     string `json:"type,omitempty" xml:"type,attr"`
	Href     string `json:"href,omitempty" xml:"href,attr,omitempty"`
	Template string `json:"template,omitempty" xml:"template,attr,omitempty"`
}

WebfingerDataLink holds and stores webfinger links

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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