fingerprints

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 10 Imported by: 0

README

Fingerprints GoDoc Status

Fingerprints is a user detection library intended to aid in finding spam accounts

Usage

New
func ExampleNew() {
	var err error
	if testController, err = New("./data"); err != nil {
		log.Fatal(err)
	}
}
Controller.New
func ExampleController_New() {
	var (
		i   Identifiers
		err error
	)

	i.IPAddress = "64.233.191.255"
	i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
	i.AcceptLanguage = "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"

	if err = testController.New(context.Background(), "user_0", i); err != nil {
		log.Fatal(err)
	}
}
Controller.GetByIP
func ExampleController_GetByIP() {
	var (
		es  []*Entry
		err error
	)
	if es, err = testController.GetByIP("[IP Address]"); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Matching entries", es)
}
Controller.GetByUserAgent
func ExampleController_GetByUserAgent() {
	var (
		es  []*Entry
		err error
	)
	if es, err = testController.GetByUserAgent("[User Agent]"); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Matching entries", es)
}
Controller.GetMatches
func ExampleController_GetMatches() {
	var (
		i   Identifiers
		es  []*Entry
		err error
	)

	i.IPAddress = "64.233.191.255"
	i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
	i.AcceptLanguage = "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"

	if es, err = testController.GetMatches(i); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Matching entries", es)
}
Controller.GetMatches (ip only)
func ExampleController_GetMatches_ip_only() {
	var (
		i   Identifiers
		es  []*Entry
		err error
	)

	i.IPAddress = "64.233.191.255"

	if es, err = testController.GetMatches(i); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Matching entries", es)
}
Controller.GetMatches (user agent only)
func ExampleController_GetMatches_user_agent_only() {
	var (
		i   Identifiers
		es  []*Entry
		err error
	)

	i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"

	if es, err = testController.GetMatches(i); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Matching entries", es)
}
Controller.GetDuplicates
func ExampleController_GetDuplicates() {
	var (
		dups map[string]stringset.Map
		err  error
	)
	if dups, err = testController.GetDuplicates(); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Duplicates", dups)
}

Documentation

Index

Examples

Constants

View Source
const (
	RelationshipUsers           = "users"
	RelationshipIPAddresses     = "ipAddresses"
	RelationshipUserAgents      = "userAgents"
	RelationshipAcceptLanguages = "acceptLanguages"
	RelationshipSignatures      = "signatures"
)

Relationship key const block

View Source
const (
	// ErrEmptyUserID is returned when the User ID for an Entry is empty
	ErrEmptyUserID = errors.Error("invalid user ID, cannot be empty")
	// ErrEmptyIPAddress is returned when the IP address for an Entry is empty
	ErrEmptyIPAddress = errors.Error("invalid IP address, cannot be empty")
	// ErrEmptyUserAgent is returned when the User Agent for an Entry is empty
	ErrEmptyUserAgent = errors.Error("invalid user agent, cannot be empty")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller represents a management layer to facilitate the retrieval and modification of Entries

func New

func New(dir string) (cc *Controller, err error)

New will return a new instance of the Controller

Example
var err error
if testController, err = New("./data"); err != nil {
	log.Fatal(err)
}

func (*Controller) Close

func (c *Controller) Close() (err error)

Close will close the controller and it's underlying dependencies

func (*Controller) Delete

func (c *Controller) Delete(ctx context.Context, entryID string) (removed *Entry, err error)

Delete will remove an Entry for a given user

func (*Controller) ForEach

func (c *Controller) ForEach(fn func(*Entry) error, opts *mojura.IteratingOpts) (err error)

ForEach will iterate through all Entries Note: The error constant mojura.Break can returned by the iterating func to end the iteration early

func (*Controller) Get

func (c *Controller) Get(entryID string) (entry *Entry, err error)

Get will retrieve an Entry which has the same ID as the provided entryID

func (*Controller) GetByIP

func (c *Controller) GetByIP(ipAddress string) (es []*Entry, err error)

GetByIP will retrieve all Entries associated with given IP address

Example
var (
	es  []*Entry
	err error
)
if es, err = testController.GetByIP("[IP Address]"); err != nil {
	log.Fatal(err)
}

fmt.Println("Matching entries", es)

func (*Controller) GetByUser

func (c *Controller) GetByUser(userID string) (es []*Entry, err error)

GetByUser will retrieve all Entries associated with given user

func (*Controller) GetByUserAgent

func (c *Controller) GetByUserAgent(userAgent string) (es []*Entry, err error)

GetByUserAgent will retrieve all Entries associated with given user agent

Example
var (
	es  []*Entry
	err error
)
if es, err = testController.GetByUserAgent("[User Agent]"); err != nil {
	log.Fatal(err)
}

fmt.Println("Matching entries", es)

func (*Controller) GetDuplicates

func (c *Controller) GetDuplicates() (dups map[string]stringset.Map, err error)

GetDuplicates will get all exact signature duplicates

Example
var (
	dups map[string]stringset.Map
	err  error
)
if dups, err = testController.GetDuplicates(); err != nil {
	log.Fatal(err)
}

fmt.Println("Duplicates", dups)

func (*Controller) GetMatches

func (c *Controller) GetMatches(i Identifiers) (es []*Entry, err error)

GetMatches will retrieve all Entries associated with given user agent and ip pair

Example
var (
	i   Identifiers
	es  []*Entry
	err error
)

i.IPAddress = "64.233.191.255"
i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
i.AcceptLanguage = "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"

if es, err = testController.GetMatches(i); err != nil {
	log.Fatal(err)
}

fmt.Println("Matching entries", es)
Example (Ip_only)
var (
	i   Identifiers
	es  []*Entry
	err error
)

i.IPAddress = "64.233.191.255"

if es, err = testController.GetMatches(i); err != nil {
	log.Fatal(err)
}

fmt.Println("Matching entries", es)
Example (User_agent_only)
var (
	i   Identifiers
	es  []*Entry
	err error
)

i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"

if es, err = testController.GetMatches(i); err != nil {
	log.Fatal(err)
}

fmt.Println("Matching entries", es)

func (*Controller) New

func (c *Controller) New(ctx context.Context, userID string, i Identifiers) (err error)

New will insert a new Entry to the back-end

Example
var (
	i   Identifiers
	err error
)

i.IPAddress = "64.233.191.255"
i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
i.AcceptLanguage = "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"

if err = testController.New(context.Background(), "user_0", i); err != nil {
	log.Fatal(err)
}

func (*Controller) NewFromHTTPRequst

func (c *Controller) NewFromHTTPRequst(ctx context.Context, userID string, req *http.Request) (err error)

NewFromHTTPRequst will create and insert a new entry from a given http request

type Entry

type Entry struct {
	// Include mojura.Entry to auto-populate fields/methods needed to match the
	mojura.Entry

	// UserID which Entry is related to
	UserID string `json:"userID"`
	// Include identifiers
	Identifiers
}

Entry represents a stored entry within the Controller

func (*Entry) GetRelationships

func (e *Entry) GetRelationships() (r mojura.Relationships)

GetRelationships will return the relationship IDs associated with the Entry

func (*Entry) Signature

func (e *Entry) Signature() string

Signature will return the signature of the entry

func (*Entry) Validate

func (e *Entry) Validate() (err error)

Validate will ensure an Entry is valid

type Hash

type Hash [32]byte

Hash represents a hashed value

func MakeHash

func MakeHash(strs ...string) (h Hash)

MakeHash will generate a new hashed value from an inbound string value

func NewHash

func NewHash(strs ...string) *Hash

NewHash will generate a new hashed value from an inbound string value and return a pointer to the resulting HAsh

func (*Hash) String

func (h *Hash) String() string

String returns a hex encoded string representation of the hashed value

type Identifiers

type Identifiers struct {
	// IPAddress is the IP address of the user
	IPAddress string `json:"ipAddress"`
	// UserAgent is the user agent of the user
	UserAgent string `json:"userAgent"`
	// AcceptLanguage is the acceptLanguage value for the user
	AcceptLanguage string `json:"acceptLanguage"`
}

Identifiers are the identifiers used for fingerprinting

Jump to

Keyboard shortcuts

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