2 Commits

Author SHA1 Message Date
Jon Lundy
616997fdc6 add libravatar/style endpoint 2020-11-28 15:11:49 -07:00
Jon Lundy
b56f27dcfb update template 2020-11-25 10:49:26 -07:00
7 changed files with 171 additions and 118 deletions

1
.gitignore vendored
View File

@@ -16,3 +16,4 @@
sour.is-keyproofs
.env
/pub

View File

@@ -1,5 +1,7 @@
# Rename to '.env' or pass required items to environment when running.
# Basic Configuration.
# REDDIT_APIKEY [REQUIRED]
# REDDIT_SECRET [REQUIRED]
# To prevent reddits low ratelimits for non-authenticated requests
@@ -26,6 +28,12 @@ HTTP_LISTEN=
BASE_URL=
# AVATAR_PATH [OPTIONAL]
# To set the path for avatar/bg/cover image directories to serve. (default: pub)
# Path should allow read/write to application. The folders will be generated automatically.
# Advanced Options. These are used to customize the application in non-standard deployments
# XMPP_URL [OPTIONAL]
# To set XMPP http url for VCard verification. (default: BASE_URL)
@@ -35,3 +43,20 @@ XMPP_URL=
# To set DNS http url for DNS verification. (default: BASE_URL)
XMPP_URL=
# Avatar app
# DISABLE_AVATAR [OPTIONAL]
# Disable the Avatar application. Set to any value other than "false"
# DNS app
# DISABLE_DNS [OPTIONAL]
# Disable the DNS application. Set to any value other than "false"
# Keyproofs app
# DISABLE_KEYPROOFS [OPTIONAL]
# Disable the KeyProofs application. Set to any value other than "false"
# XMPP VCard app
# DISABLE_VCARD [OPTIONAL]
# Disable the VCard application. Set to any value other than "false"
# If disabled the username/password are no longer required.

1
go.mod
View File

@@ -3,6 +3,7 @@ module github.com/sour-is/keyproofs
go 1.15
require (
github.com/fsnotify/fsnotify v1.4.7
github.com/go-chi/chi v4.1.2+incompatible
github.com/google/go-cmp v0.5.4 // indirect
github.com/hashicorp/golang-lru v0.5.4

1
go.sum
View File

@@ -138,6 +138,7 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190927073244-c990c680b611/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/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/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=

38
main.go
View File

@@ -86,38 +86,48 @@ func run(ctx context.Context) error {
Credential: xmpp.Password(os.Getenv("XMPP_PASSWORD")),
})
// configure cors middleware
corsMiddleware := cors.New(cors.Options{
AllowCredentials: true,
AllowedMethods: strings.Fields(env("CORS_METHODS", "GET")),
AllowedOrigins: strings.Fields(env("CORS_ORIGIN", "*")),
}).Handler
mux := chi.NewRouter()
mux.Use(
cfg.ApplyHTTP,
secHeaders,
corsMiddleware,
cors.New(cors.Options{
AllowCredentials: true,
AllowedMethods: strings.Fields(env("CORS_METHODS", "GET")),
AllowedOrigins: strings.Fields(env("CORS_ORIGIN", "*")),
}).Handler,
middleware.RequestID,
middleware.RealIP,
middleware.RequestLogger(&middleware.DefaultLogFormatter{Logger: accessLog(log.Info)}),
middleware.Recoverer,
)
if env("DISABLE_KEYPROOF", "false") == "false" {
// Create cache for promise engine
arc, _ := lru.NewARC(4096)
c := cache.New(arc)
keyproofs.NewKeyProofApp(ctx, c).Routes(mux)
}
keyproofApp := keyproofs.NewKeyProofApp(ctx, c)
dnsApp := keyproofs.NewDNSApp(ctx)
vcardApp, err := keyproofs.NewVCardApp(ctx)
if env("DISABLE_DNS", "false") == "false" {
keyproofs.NewDNSApp(ctx).Routes(mux)
}
if env("DISABLE_AVATAR", "false") == "false" {
avatarApp, err := keyproofs.NewAvatarApp(ctx, env("AVATAR_PATH", "pub"))
if err != nil {
return err
}
keyproofApp.Routes(mux)
dnsApp.Routes(mux)
avatarApp.Routes(mux)
}
if env("DISABLE_VCARD", "false") == "false" {
vcardApp, err := keyproofs.NewVCardApp(ctx)
if err != nil {
return err
}
vcardApp.Routes(mux)
}
log.Info().
Str("app", cfg.GetString("app-name")).
@@ -127,7 +137,7 @@ func run(ctx context.Context) error {
Str("listen", listen).
Msg("startup")
err = New(&http.Server{
err := New(&http.Server{
Addr: listen,
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,

View File

@@ -37,7 +37,6 @@ func getStyle(ctx context.Context, email string) (*Style, error) {
hash := md5.New()
email = strings.TrimSpace(strings.ToLower(email))
_, _ = hash.Write([]byte(email))
id := hash.Sum(nil)
style := &Style{}

View File

@@ -49,6 +49,7 @@ var pageTPL = `
}
.shade { background-color: {{index .Palette 3}}80; border-radius: .25rem;}
.lead { padding:0; margin:0; }
.scroll { height: 20em; overflow: scroll; }
@media only screen and (max-width: 991px) {
.jumbotron h1 { font-size: 2rem; }
@@ -80,7 +81,11 @@ var pageTPL = `
{{template "content" .}}
<div class="card-footer text-muted text-center">
<a href="/">{{.AppName}}</a> | &copy; 2020 Sour.is | <a href="/id/me@sour.is">About me</a> | <a href="https://github.com/sour-is/keyproofs">GitHub</a> | Inspired by <a href="https://keyoxide.org/">keyoxide</a>
<a href="/">{{.AppName}}</a>
| &copy; 2020 Sour.is
| <a href="/id/me@sour.is">About me</a>
| <a href="https://github.com/sour-is/keyproofs">GitHub</a>
| Inspired by <a href="https://keyoxide.org/">keyoxide</a>
</div>
</div>
</div>
@@ -99,12 +104,18 @@ var homeTPL = `
</div>
</div>
</div>
</div>
<br/>
<div class="card">
<div class="card-body">
<form method="GET" action="/">
<div class="input-group mb-3">
<input type="text" name="id" class="form-control" placeholder="Email or Fingerprint..." aria-label="Email or Fingerprint" aria-describedby="button-addon">
<input type="text"
name="id"
class="form-control"
placeholder="Email or Fingerprint..."
aria-label="Email or Fingerprint"
aria-describedby="button-addon" />
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit" id="button-addon">GO</button>
</div>
@@ -112,7 +123,6 @@ var homeTPL = `
</form>
</div>
</div>
</div>
<div class="container"> {{.Markdown | markDown}} </div>
{{end}}
`
@@ -122,7 +132,6 @@ var proofTPL = `
<div class="jumbotron heading">
<div class="container">
<div class="row shade">
{{ with .Err }}
<div class="col-xs center-md">
<i class="fas fa-exclamation-triangle fa-4x fg-color-11"></i>
@@ -139,7 +148,6 @@ var proofTPL = `
</div>
{{end}}
{{with .Entity}}
<div class="col-md center-md">
<h1 class="display-8 fg-color-8">{{.Primary.Name}}</h1>
@@ -154,14 +162,14 @@ var proofTPL = `
<p class="lead fg-color-11">Reading key from remote service.</p>
</div>
{{end}}
{{end}}
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-12 col-sm-12 col-xs-12">
{{ with .Entity }}
<div class="card">
<div class="card-header">Contact</div>
@@ -180,7 +188,6 @@ var proofTPL = `
<ul class="list-group list-group-flush">
{{range .}}
<li class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<div>
<a title="{{.Link}}" class="font-weight-bold" href="{{.Link}}">
<i title="{{.Service}}" class="{{.Icon}}"></i>
@@ -199,15 +206,15 @@ var proofTPL = `
</div>
<div>
{{if eq .Service "xmpp"}}
<br/>
<img src="/qr?s=-2&c={{.Link}}" alt="qrcode" style="width:88px; height:88px">
{{end}}
</div>
</div>
</li>
{{end}}
</ul>
</div>
<br/>
</div>
{{else}}
<div class="card">
<div class="card-header">Proofs</div>
@@ -216,6 +223,15 @@ var proofTPL = `
<br/>
{{end}}
{{end}}
<div class="col-lg-8 col-md-12 col-sm-12 col-xs-12">
<div class="card">
<div class="card-header">Public Key</div>
<div class="card-body scroll">
<pre><code>{{.Entity.ArmorText}}</code></pre>
</div>
</div>
</div>
</div>
</div>
{{end}}
`