Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.vscode
*.exe
adrian.yaml
adrian
adrian
*.pem
access.log
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ global:

# Port number Adrian responds to
port: 80


# HTTPS support
https:
# Enable automatic TLS certificate generation using LetEncrypt
auto: false
# HTTPS port number Adrian responds to
port: 4443
# TLS Certificate file (if not using LetsEncrypt)
cert: "cert.pem"
# TLS Key file (if not using LetsEncrypt)
key: "key.pem"

# Adrian will only allow fonts to be used on these URLs (CORS functionality)
domains:
- example.com
Expand All @@ -63,6 +74,26 @@ global:

The TCP/IP port Adrian will listen to. Defaults to port 80.

##### https:

IF HTTPS support is desired, configure it here.

###### auto: <boolean>

Enable automatic TLS certificate generation using LetEncrypt

###### port: <integer>

The TCP/IP port Adrian will listen to for HTTPS. Defaults to port 443.

###### cert: <string>

Path/Filename of a TLS certificate file to use.

###### key: <string>

Path/Filename of a TLS key file to use.

##### domains

A whitelist of domains allowed to use fonts hosted by this instance
Expand Down
33 changes: 33 additions & 0 deletions adrian.https.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
global:

# Port number Adrian responds to
port: 80

# HTTPS support
https:
# Enable automatic TLS certificate generation using LetEncrypt
auto: false
# HTTPS port number Adrian responds to
port: 4443
# TLS Certificate file (if not using LetsEncrypt)
cert: "cert.pem"
# TLS Key file (if not using LetsEncrypt)
key: "key.pem"

# Adrian will only allow fonts to be used on these URLs (CORS functionality)
domains:
- example.com

# Directories where Adrian should look for fonts
directories:
- /usr/share/fonts

# If true, replace font filenames with hashes so they can't be guessed as easily
obfuscate filenames: false

# Used to set the cache-control header in responses
cache-control lifetime: 2628000

# Paths for writing logs to disk
logs:
access: "/var/log/adrian/access.log"
1 change: 1 addition & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"

"github.com/VictoriaMetrics/fastcache"
"github.com/labstack/echo"
)
Expand Down
8 changes: 7 additions & 1 deletion config/main.go → config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package main

import (
"fmt"
Expand All @@ -13,6 +13,12 @@ type Config struct {
Global struct {
Debug bool
Port uint16
HTTPS struct {
Auto bool
Port uint16
Cert string
Key string
}
Domains []string
AllowedOrigins []string
Directories []string
Expand Down
2 changes: 1 addition & 1 deletion fonts/css.go → css.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fonts
package main

import (
"fmt"
Expand Down
32 changes: 20 additions & 12 deletions fonts/main.go → fonts.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package fonts
package main

import (
"crypto/md5" // #nosec
"crypto/sha256"
"crypto/md5"
"encoding/hex"
"errors"
"io"
"log"
"os"
"io"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/ConradIrwin/font/sfnt"
adrianConfig "github.com/dana-ross/adrian/config"
)

// FontFileData describes a font (format) belonging to a font family
Expand Down Expand Up @@ -55,14 +55,14 @@ var fonts = make(map[string]FontData)
var uniqueIDXref = make(map[string]*FontVariant)

// LoadFont loads a font into memory
func LoadFont(filePath string, config adrianConfig.Config) {
func LoadFont(filePath string, config Config) {

fontFormat := GetCanonicalExtension(filePath)
if _, ok := supportedFormats[fontFormat]; !ok {
return
}

file, err := os.Open(filePath)
file, err := os.Open(filepath.Clean(filePath))
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -156,25 +156,33 @@ func GetFontVariantByUniqueID(uniqueID string) (fontVariant *FontVariant, err er
}

// calcUniqueID generates a unique ID for a font, optionally obfuscating it
func calcUniqueID(fontVariant FontVariant, config adrianConfig.Config) string {
func calcUniqueID(fontVariant FontVariant, config Config) string {
if config.Global.ObfuscateFilenames {
hash := sha256.New()
hash.Write([]byte(fontVariant.Name))
_, err := hash.Write([]byte(fontVariant.Name))
if err != nil {
log.Fatal(err)
}
return hex.EncodeToString(hash.Sum(nil))
}

return fontVariant.Name
}

// calcFileMD5 calculates the MD5 hash of a file
func calcFileMD5(filepath string) string {
file, err := os.Open(filepath)
func calcFileMD5(filePath string) string {
file, err := os.Open(filepath.Clean(filePath))
if err != nil {
log.Fatal(err)
}
defer file.Close()
defer func() {
err := file.Close()
if err != nil {
log.Printf("error closing the font file: %s", err)
}
}()

hash := md5.New()
hash := md5.New() // #nosec
if _, err := io.Copy(hash, file); err != nil {
log.Fatal(err)
}
Expand Down
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/dana-ross/adrian

go 1.15

require (
dmitri.shuralyov.com/font/woff2 v0.0.0-20180220214647-957792cbbdab // indirect
github.com/ConradIrwin/font v0.0.0-20190603172541-e12dbea4cf12
github.com/VictoriaMetrics/fastcache v1.5.7
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/yaml.v2 v2.4.0
)
66 changes: 66 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
dmitri.shuralyov.com/font/woff2 v0.0.0-20180220214647-957792cbbdab h1:Ew70NL+wL6v9looOiJJthlqA41VzoJS+q9AyjHJe6/g=
dmitri.shuralyov.com/font/woff2 v0.0.0-20180220214647-957792cbbdab/go.mod h1:FvHgTMJanm43G7B3MVSjS/jim5ytVqAJNAOpRhnuHJc=
github.com/ConradIrwin/font v0.0.0-20190603172541-e12dbea4cf12 h1:p6Fbemw7MLL8GECFdqBnGqrY6tfeNEECS1Gckyt6JJg=
github.com/ConradIrwin/font v0.0.0-20190603172541-e12dbea4cf12/go.mod h1:RfqDRypmK6cOLNPzccgIJ999A/yzpd0iGh6xazqpWrY=
github.com/VictoriaMetrics/fastcache v1.5.7 h1:4y6y0G8PRzszQUYIQHHssv/jgPHAb5qQuuDNdCbyAgw=
github.com/VictoriaMetrics/fastcache v1.5.7/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/dana-ross/adrian v2.2.3+incompatible h1:YG+5tPqxv+wm5eKP/EUB3j/uAiQNN2MOj7pslJ0Vdew=
github.com/dana-ross/adrian v2.2.3+incompatible/go.mod h1:HTa8Oe+abOIs4hN23Ip/Z4teliifcBEca5D68Z5swEs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/labstack/echo v1.4.4 h1:1bEiBNeGSUKxcPDGfZ/7IgdhJJZx8wV/pICJh4W2NJI=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Loading