application

package
v0.0.0-...-9b381e1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package application contains the server-side application code.

Package application contains the server-side application code.

Package application contains the server-side application code.

Package application contains the server-side application code.

Package application contains the server-side application code.

Package application contains the server-side application code.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRecords defines an error message for when the DNS server returned nothing
	ErrNoRecords = errors.New("This server has no records for the type you specified")

	// ErrBadRecordType defines an erros message for when the user doesn't specify a valid DNS Record Type
	ErrBadRecordType = errors.New("You have specified a record type that does not exist")
)
View Source
var (
	// ErrInvalidDomain is the error message that specifies an invalid input domain
	ErrInvalidDomain = errors.New("You have sent an invalid domain. Please check your input")

	// ErrInvalidRecord is the error message that specifies that an invalid DNS record type was used
	ErrInvalidRecord = errors.New("You have specified an invalid DNS record type. Please check your input")

	// ErrInvalidHost is the error message that specified that an invalid host was set in the Origin Header
	ErrInvalidHost = errors.New("You have made your request from an unknown Origin")

	// ErrMissingOriginHeader is the error message that specified that an empty/missing origin header was sent
	ErrMissingOriginHeader = errors.New("Missing 'Origin' HTTP header")
)
View Source
var RecordTypes = map[string]uint16{
	"a":     dns.TypeA,
	"aaaa":  dns.TypeAAAA,
	"mx":    dns.TypeMX,
	"cname": dns.TypeCNAME,
	"srv":   dns.TypeSRV,
	"soa":   dns.TypeSOA,
	"txt":   dns.TypeTXT,
	"ptr":   dns.TypePTR,
	"ns":    dns.TypeNS,
	"caa":   dns.TypeCAA,
}

RecordTypes stores all the DNS record types supported by the application and maps them to their equivalent in the DNS library

Functions

func CheckOrigin

func CheckOrigin(req *http.Request) bool

CheckOrigin takes the original not-upgraded HTTP request and validates the origin header. It was created mostly as convinience to avoid having inline functions in the struct declaration.

func DisplayRecaptcha

func DisplayRecaptcha(req *http.Request) bool

DisplayRecaptcha verifies if the request contains a valid application reCAPTCHA cookie TODO Make this work with ReadCookie in the middleware

func GetRecordType

func GetRecordType(record string) uint16

GetRecordType obtains the equivalent value from the DNS library by passing a string with the record name. The record name passed as parameter is normalized before trying to get it from RecordTypes.

func Init

func Init(mux *http.ServeMux, dnsinfo *publicdns.PublicDNS, configuration Configuration)

Init is the entrypoint of the application. It loads the configuration file and sets-up the routes TODO Write documentation on how to generate the keys and the need to encode them to Base64 TODO Check for error returned by the decoding of Base64 strings

func IsRecordValid

func IsRecordValid(record string) bool

IsRecordValid checks if the record type passed as parameter is in the RecordTypes list The record name passed as parameter is normalized before trying to get it from RecordTypes.

func ValidateOrigin

func ValidateOrigin(origin string) (bool, error)

ValidateOrigin validates the origin header sent by the browser/client that is using the application TODO Make the valid origin host (or hosts) configurable in the configuration file FIXME This function does not please me yet. Validate the URL more thoroughly (although it can be faked so might not matter)

Types

type Configuration

type Configuration struct {
	Cookie       CookieConfiguration `json:"cookie"`
	Recaptcha    Recaptcha           `json:"recaptcha"`
	Countries    []interface{}       `json:"countries"`
	CacheUntil   string              `json:"cache_until"`
	RemoteSource string              `json:"remote_source"`
	Servers      []*publicdns.Nameserver
}

Configuration holds the application configuration settings. Configuration files should be created in the conf folder.

func LoadConfiguration

func LoadConfiguration(path string) (Configuration, error)

LoadConfiguration loads a configuration file from the specified path. It will return the configuration in the JSON file or an error with details if the operation fails (e.g. file does not exist, invalid JSON)

type CookieConfiguration

type CookieConfiguration struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	HashKey  string `json:"hashkey"`
	BlockKey string `json:"blockkey"`
	Domain   string `json:"domain"`
	Secure   bool   `json:"secure"`
}

CookieConfiguration holds the application configuration regarding the secure cookie

type DNSQuery

type DNSQuery struct {
	Servers []*publicdns.Nameserver
}

DNSQuery allows us to query multiple DNS servers at the same time. It currently supports Sync and Async requests.

func (*DNSQuery) QueryAll

func (d *DNSQuery) QueryAll(domain string, record string) []Response

QueryAll queries all the servers passed in the constructor, synchronously and returns an array of Response objects-

func (*DNSQuery) QueryAllAsync

func (d *DNSQuery) QueryAllAsync(domain string, record string) <-chan Response

QueryAllAsync queries all the servers passed in the constructor asynchronously and returns the Response object via a channel.

Sample Usage:

c := query.QueryAllAsync(websocketreq.Domain, websocketreq.RecordType)
for _, _ = range servers {
  log.Println(<-c)
}

type DNSRecord

type DNSRecord struct {
	Type string
	Data []dns.RR
}

DNSRecord stores the records returned from querying a single DNS Server. It also stores the record type for the frontend.

type IndexRequestHandler

type IndexRequestHandler struct {
	// Configuration contains the app configuration. In this context only the server list is used.
	Configuration Configuration
}

IndexRequestHandler handles the requests to present the main url of the application

func (IndexRequestHandler) ServeHTTP

func (i IndexRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles the request made to the homepage of the app. It will only serve the required files to start the RectJS app as well as some important configuration.

type IndexTemplateParams

type IndexTemplateParams struct {
	Title         string
	PublicKey     string
	ShowRecaptcha bool
}

IndexTemplateParams holds various values to be passed to the main template

type QueryRequestHandler

type QueryRequestHandler struct {
	// Configuration contains the app configuration. In this context only the server list is used.
	Configuration Configuration

	// DNSInfo contains a reference to the Public DNS Info package that allows us to query the database for servers.
	DNSInfo *publicdns.PublicDNS
}

QueryRequestHandler handles the requests made through the WebSocket.

func (QueryRequestHandler) ServeHTTP

func (q QueryRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles the request made by the user through the WebSocket. It will upgrade the connection from HTTP to WebSocket, read the request variables, validate them and perform the queries to the list of DNS servers in the configuration file.

type Recaptcha

type Recaptcha struct {
	PublicKey  string `json:"publickey"`
	PrivateKey string `json:"privatekey"`
}

Recaptcha holds the Google reCAPTCHA settings mainly the public and private keys.

type RecaptchaMiddleware

type RecaptchaMiddleware struct {
	// Configuration holds the application configuration. In this context only the reCAPTCHA configuration is used
	Configuration Configuration

	// SecureCookie holds the instance that will be used to encode and decode a cookie's value
	SecureCookie *securecookie.SecureCookie
}

RecaptchaMiddleware will allow us to chain the reCAPTCHA validation into the request processing

func (*RecaptchaMiddleware) Middleware

func (m *RecaptchaMiddleware) Middleware(next http.Handler) http.Handler

Middleware will perform the validation of reCAPTCHA challenge that the user should solve before passing control to the actual function that processes the full request and returns the result. TODO Improve the SecureCookie handling

type Response

type Response struct {
	Server   *publicdns.Nameserver
	Duration string
	Message  string
	Records  DNSRecord
}

Response is the standard response struct after a successful DNS Query. It contains all the information about the server that was used in the query, the records returned, the duration and also an optional message which is usually an error message.

func Query

func Query(domain string, record string, server *publicdns.Nameserver) Response

Query uses rawQuery obtain the raw data but returns a Response struct ready to send to the frontend. This func will only query a single server! To query multiple servers use QueryAllAsync or QueryAll

type ResponseError

type ResponseError struct {
	Error string
}

ResponseError is the default structure for responses to the client that only contain an error message

type SecureRecaptchaCookie

type SecureRecaptchaCookie struct {
	*http.Cookie
	SecureCookie *securecookie.SecureCookie
}

SecureRecaptchaCookie is an extension of the regular http.Cookie struct with value encoding capabilities

func NewSecureRecaptchaCookie

func NewSecureRecaptchaCookie(name string, cookie *http.Cookie, config *securecookie.SecureCookie) *SecureRecaptchaCookie

NewSecureRecaptchaCookie creates a SecureCookie instance based on a request cookie. If the cookie already exists its value is set in the SecureRecaptchaCookie struct otherwise it gets an empty value (which will fail verification)

func (*SecureRecaptchaCookie) Encode

func (cookie *SecureRecaptchaCookie) Encode(value string) string

Encode the value passed as a parameter with the keys present in SecureCookie and returns it

func (*SecureRecaptchaCookie) IsValid

func (cookie *SecureRecaptchaCookie) IsValid(original string) bool

IsValid validates the current cookie value (after decoding it) against an expected original value

type WebsocketRequest

type WebsocketRequest struct {
	Domain     string        `json:"domain"`
	RecordType string        `json:"type"`
	Countries  []interface{} `json:"countries"`
}

WebsocketRequest is the structure that holds the values passed as JSON from the frontend app through the WebSocket

func (*WebsocketRequest) Validate

func (r *WebsocketRequest) Validate() error

Validate performs the validation of the client-side values sent through the WebSocket

Jump to

Keyboard shortcuts

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