update styles and add home page
This commit is contained in:
127
pkg/graceful/with-interrupt.go
Normal file
127
pkg/graceful/with-interrupt.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package graceful
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
func WithInterupt(ctx context.Context) context.Context {
|
||||
log := log.Ctx(ctx)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
// Listen for Interrupt signals
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
go func() {
|
||||
defer signal.Stop(c)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-c:
|
||||
cancel()
|
||||
log.Warn().Msg("Shutting down! interrupt received")
|
||||
return
|
||||
case <-ctx.Done():
|
||||
log.Warn().Msg("Shutting down! context cancelled")
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
type contextKey struct{ string }
|
||||
|
||||
var wgKey = contextKey{"waitgroup"}
|
||||
|
||||
type wgContext struct {
|
||||
wg sync.WaitGroup
|
||||
err error
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (wg *wgContext) String() string {
|
||||
return fmt.Sprintf("WaitGroup[%v %v]", wg.err, wg.ctx)
|
||||
}
|
||||
|
||||
type WG interface {
|
||||
Wait(time.Duration) error
|
||||
Go(func() error)
|
||||
}
|
||||
|
||||
func WithWaitGroup(ctx context.Context) (context.Context, WG) {
|
||||
if wg := WaitGroup(ctx); wg != nil {
|
||||
return ctx, wg
|
||||
}
|
||||
wg := &wgContext{ctx: ctx}
|
||||
return context.WithValue(ctx, wgKey, wg), wg
|
||||
}
|
||||
|
||||
func WaitGroup(ctx context.Context) *wgContext {
|
||||
if wg, ok := ctx.Value(wgKey).(*wgContext); ok {
|
||||
return wg
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wg *wgContext) Go(fn func() error) {
|
||||
if wg == nil {
|
||||
panic("nil wait group")
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
err := fn()
|
||||
wg.err = multierr.Append(wg.err, err)
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
func (wg *wgContext) Add(n int) {
|
||||
wg.wg.Add(n)
|
||||
}
|
||||
|
||||
func (wg *wgContext) Done() {
|
||||
wg.wg.Done()
|
||||
}
|
||||
|
||||
func (wg *wgContext) Wait(gracetime time.Duration) error {
|
||||
if wg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
log := log.Ctx(wg.ctx)
|
||||
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
wg.wg.Wait()
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
<-wg.ctx.Done()
|
||||
wg.err = multierr.Append(wg.err, wg.ctx.Err())
|
||||
|
||||
log.Debug().Msg("shutdown begin")
|
||||
timer := time.NewTimer(gracetime)
|
||||
|
||||
select {
|
||||
case <-ch:
|
||||
case <-timer.C:
|
||||
wg.err = multierr.Append(wg.err, ErrExpiredGrace)
|
||||
}
|
||||
log.Debug().Msg("shutdown complete")
|
||||
|
||||
return wg.err
|
||||
}
|
||||
|
||||
var ErrExpiredGrace = errors.New("grace time expired")
|
||||
32
pkg/keyproofs/routes-dns.go
Normal file
32
pkg/keyproofs/routes-dns.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package keyproofs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
type dnsApp struct {
|
||||
resolver *net.Resolver
|
||||
}
|
||||
|
||||
func NewDNSApp(ctx context.Context) *dnsApp {
|
||||
return &dnsApp{resolver: net.DefaultResolver}
|
||||
}
|
||||
func (app *dnsApp) getDNS(w http.ResponseWriter, r *http.Request) {
|
||||
domain := chi.URLParam(r, "domain")
|
||||
|
||||
res, err := app.resolver.LookupTXT(r.Context(), domain)
|
||||
if err != nil {
|
||||
writeText(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
writeText(w, 200, strings.Join(res, "\n"))
|
||||
}
|
||||
func (app *dnsApp) Routes(r *chi.Mux) {
|
||||
r.MethodFunc("GET", "/dns/{domain}", app.getDNS)
|
||||
}
|
||||
@@ -4,18 +4,15 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
zlog "github.com/rs/zerolog/log"
|
||||
"github.com/russross/blackfriday"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"gosrc.io/xmpp"
|
||||
|
||||
"github.com/sour-is/keyproofs/pkg/cache"
|
||||
"github.com/sour-is/keyproofs/pkg/config"
|
||||
@@ -23,32 +20,7 @@ import (
|
||||
)
|
||||
|
||||
var expireAfter = 20 * time.Minute
|
||||
|
||||
func New(ctx context.Context, c cache.Cacher) (*identity, error) {
|
||||
log := zlog.Ctx(ctx)
|
||||
|
||||
var ok bool
|
||||
var xmppConfig *xmpp.Config
|
||||
if xmppConfig, ok = config.FromContext(ctx).Get("xmpp-config").(*xmpp.Config); !ok {
|
||||
log.Error().Msg("no xmpp-config")
|
||||
|
||||
return nil, fmt.Errorf("no xmpp config")
|
||||
}
|
||||
|
||||
conn, err := NewXMPP(ctx, xmppConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tasker := promise.NewRunner(ctx, promise.Timeout(30*time.Second), promise.WithCache(c, expireAfter))
|
||||
i := &identity{
|
||||
cache: c,
|
||||
tasker: tasker,
|
||||
conn: conn,
|
||||
}
|
||||
|
||||
return i, nil
|
||||
}
|
||||
var runnerTimeout = 30 * time.Second
|
||||
|
||||
// 1x1 gif pixel
|
||||
var pixl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
|
||||
@@ -61,30 +33,32 @@ var defaultStyle = &Style{
|
||||
Palette: getPalette("#93CCEA"),
|
||||
}
|
||||
|
||||
type identity struct {
|
||||
type keyproofApp struct {
|
||||
cache cache.Cacher
|
||||
tasker promise.Tasker
|
||||
conn *connection
|
||||
}
|
||||
|
||||
func (s *identity) Routes(r *chi.Mux) {
|
||||
r.Use(secHeaders)
|
||||
r.MethodFunc("GET", "/id/{id}", s.get)
|
||||
r.MethodFunc("GET", "/dns/{domain}", s.getDNS)
|
||||
r.MethodFunc("GET", "/vcard/{jid}", s.getVCard)
|
||||
r.MethodFunc("GET", "/qr", s.getQR)
|
||||
func NewKeyProofApp(ctx context.Context, c cache.Cacher) *keyproofApp {
|
||||
return &keyproofApp{
|
||||
cache: c,
|
||||
tasker: promise.NewRunner(
|
||||
ctx,
|
||||
promise.Timeout(runnerTimeout),
|
||||
promise.WithCache(c, expireAfter),
|
||||
),
|
||||
}
|
||||
}
|
||||
func (app *keyproofApp) Routes(r *chi.Mux) {
|
||||
r.MethodFunc("GET", "/", app.getHome)
|
||||
r.MethodFunc("GET", "/id/{id}", app.getProofs)
|
||||
r.MethodFunc("GET", "/qr", app.getQR)
|
||||
r.MethodFunc("GET", "/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.WriteHeader(200)
|
||||
_, _ = w.Write(keypng)
|
||||
})
|
||||
}
|
||||
|
||||
func fmtKey(key promise.Key) string {
|
||||
return fmt.Sprintf("%T", key.Key())
|
||||
}
|
||||
|
||||
func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
func (app *keyproofApp) getProofs(w http.ResponseWriter, r *http.Request) {
|
||||
log := zlog.Ctx(r.Context())
|
||||
cfg := config.FromContext(r.Context())
|
||||
|
||||
@@ -96,7 +70,7 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
defer cancel()
|
||||
|
||||
// Run tasks to resolve entity, style, and proofs.
|
||||
task := s.tasker.Run(EntityKey(id), func(q promise.Q) {
|
||||
task := app.tasker.Run(EntityKey(id), func(q promise.Q) {
|
||||
ctx := q.Context()
|
||||
log := zlog.Ctx(ctx).With().Interface(fmtKey(q), q.Key()).Logger()
|
||||
|
||||
@@ -128,7 +102,7 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
key := q.Key().(StyleKey)
|
||||
|
||||
log.Debug().Msg("start task")
|
||||
style, err := s.getStyle(ctx, string(key))
|
||||
style, err := getStyle(ctx, string(key))
|
||||
if err != nil {
|
||||
q.Reject(err)
|
||||
return
|
||||
@@ -137,7 +111,6 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug().Msg("Resolving Style")
|
||||
q.Resolve(style)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
task.After(func(q promise.ResultQ) {
|
||||
@@ -175,7 +148,6 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
page := page{Style: defaultStyle}
|
||||
page.AppName = fmt.Sprintf("%s v%s", cfg.GetString("app-name"), cfg.GetString("app-version"))
|
||||
|
||||
|
||||
// Wait for either entity to resolve or timeout
|
||||
select {
|
||||
case <-task.Await():
|
||||
@@ -189,7 +161,7 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
case <-ctx.Done():
|
||||
log.Print("Deadline Timeout")
|
||||
if e, ok := s.cache.Get(EntityKey(id)); ok {
|
||||
if e, ok := app.cache.Get(EntityKey(id)); ok {
|
||||
page.Entity = e.Value().(*Entity)
|
||||
}
|
||||
}
|
||||
@@ -198,7 +170,7 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
if page.Entity != nil {
|
||||
var gotStyle, gotProofs bool
|
||||
|
||||
if s, ok := s.cache.Get(StyleKey(page.Entity.Primary.Address)); ok {
|
||||
if s, ok := app.cache.Get(StyleKey(page.Entity.Primary.Address)); ok {
|
||||
page.Style = s.Value().(*Style)
|
||||
gotStyle = true
|
||||
}
|
||||
@@ -210,7 +182,7 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
for i := range page.Entity.Proofs {
|
||||
p := page.Entity.Proofs[i]
|
||||
|
||||
if s, ok := s.cache.Get(ProofKey(p)); ok {
|
||||
if s, ok := app.cache.Get(ProofKey(p)); ok {
|
||||
log.Debug().Str("uri", p).Msg("Proof from cache")
|
||||
proofs[p] = s.Value().(*Proof)
|
||||
} else {
|
||||
@@ -226,31 +198,62 @@ func (s *identity) get(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Template and display.
|
||||
t, err := template.New("identity").Parse(pageTPL)
|
||||
var err error
|
||||
t := template.New("page")
|
||||
t, err = t.Parse(pageTPL)
|
||||
if err != nil {
|
||||
WriteText(w, 500, err.Error())
|
||||
writeText(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
t, err = t.Parse(proofTPL)
|
||||
if err != nil {
|
||||
writeText(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Execute(w, page)
|
||||
if err != nil {
|
||||
WriteText(w, 500, err.Error())
|
||||
writeText(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
func (app *keyproofApp) getHome(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
cfg := config.FromContext(ctx)
|
||||
|
||||
func (s *identity) getDNS(w http.ResponseWriter, r *http.Request) {
|
||||
domain := chi.URLParam(r, "domain")
|
||||
baseURL := cfg.GetString("base-url")
|
||||
if id := r.URL.Query().Get("id"); id != "" {
|
||||
http.Redirect(w, r, fmt.Sprintf("%s/id/%s", baseURL, id), http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := net.DefaultResolver.LookupTXT(r.Context(), domain)
|
||||
page := page{Style: defaultStyle, IsComplete: true, Markdown: homeMKDN}
|
||||
page.AppName = fmt.Sprintf("%s v%s", cfg.GetString("app-name"), cfg.GetString("app-version"))
|
||||
|
||||
// Template and display.
|
||||
var err error
|
||||
t := template.New("page")
|
||||
t = t.Funcs(template.FuncMap{"markDown": markDowner})
|
||||
t, err = t.Parse(pageTPL)
|
||||
if err != nil {
|
||||
WriteText(w, 400, err.Error())
|
||||
writeText(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
WriteText(w, 200, strings.Join(res, "\n"))
|
||||
}
|
||||
t, err = t.Parse(homeTPL)
|
||||
if err != nil {
|
||||
writeText(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
func (s *identity) getQR(w http.ResponseWriter, r *http.Request) {
|
||||
err = t.Execute(w, page)
|
||||
if err != nil {
|
||||
writeText(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
func (app *keyproofApp) getQR(w http.ResponseWriter, r *http.Request) {
|
||||
log := zlog.Ctx(r.Context())
|
||||
|
||||
content := r.URL.Query().Get("c")
|
||||
@@ -280,7 +283,7 @@ func (s *identity) getQR(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
png, err := qrcode.Encode(content, quality, size)
|
||||
if err != nil {
|
||||
WriteText(w, 400, err.Error())
|
||||
writeText(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -290,38 +293,18 @@ func (s *identity) getQR(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write(png)
|
||||
}
|
||||
|
||||
func (s *identity) getVCard(w http.ResponseWriter, r *http.Request) {
|
||||
jid := chi.URLParam(r, "jid")
|
||||
if _, err := mail.ParseAddress(jid); err != nil {
|
||||
fmt.Fprint(w, err)
|
||||
w.WriteHeader(400)
|
||||
}
|
||||
|
||||
vcard, err := s.conn.GetXMPPVCard(r.Context(), jid)
|
||||
if err != nil {
|
||||
fmt.Fprint(w, err)
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/xml")
|
||||
w.WriteHeader(200)
|
||||
fmt.Fprint(w, vcard)
|
||||
}
|
||||
|
||||
func secHeaders(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-XSS-Protection", "1; mode=block")
|
||||
w.Header().Set("X-Frame-Options", "DENY")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
func markDowner(args ...interface{}) template.HTML {
|
||||
s := blackfriday.MarkdownCommon([]byte(fmt.Sprintf("%s", args...)))
|
||||
return template.HTML(s)
|
||||
}
|
||||
|
||||
// WriteText writes plain text
|
||||
func WriteText(w http.ResponseWriter, code int, o string) {
|
||||
func writeText(w http.ResponseWriter, code int, o string) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(code)
|
||||
_, _ = w.Write([]byte(o))
|
||||
}
|
||||
|
||||
func fmtKey(key promise.Key) string {
|
||||
return fmt.Sprintf("%T", key.Key())
|
||||
}
|
||||
56
pkg/keyproofs/routes-vcard.go
Normal file
56
pkg/keyproofs/routes-vcard.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package keyproofs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
zlog "github.com/rs/zerolog/log"
|
||||
"github.com/sour-is/keyproofs/pkg/config"
|
||||
"gosrc.io/xmpp"
|
||||
)
|
||||
|
||||
type vcardApp struct {
|
||||
conn *connection
|
||||
}
|
||||
|
||||
func NewVCardApp(ctx context.Context) (*vcardApp, error) {
|
||||
log := zlog.Ctx(ctx)
|
||||
|
||||
var ok bool
|
||||
var xmppConfig *xmpp.Config
|
||||
if xmppConfig, ok = config.FromContext(ctx).Get("xmpp-config").(*xmpp.Config); !ok {
|
||||
log.Error().Msg("no xmpp-config")
|
||||
|
||||
return nil, fmt.Errorf("no xmpp config")
|
||||
}
|
||||
|
||||
conn, err := NewXMPP(ctx, xmppConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &vcardApp{conn: conn}, nil
|
||||
}
|
||||
func (app *vcardApp) Routes(r *chi.Mux) {
|
||||
r.MethodFunc("GET", "/vcard/{jid}", app.getVCard)
|
||||
}
|
||||
func (app *vcardApp) getVCard(w http.ResponseWriter, r *http.Request) {
|
||||
jid := chi.URLParam(r, "jid")
|
||||
if _, err := mail.ParseAddress(jid); err != nil {
|
||||
fmt.Fprint(w, err)
|
||||
w.WriteHeader(400)
|
||||
}
|
||||
|
||||
vcard, err := app.conn.GetXMPPVCard(r.Context(), jid)
|
||||
if err != nil {
|
||||
fmt.Fprint(w, err)
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/xml")
|
||||
w.WriteHeader(200)
|
||||
fmt.Fprint(w, vcard)
|
||||
}
|
||||
@@ -25,7 +25,7 @@ type Style struct {
|
||||
Palette []string
|
||||
}
|
||||
|
||||
func (s *identity) getStyle(ctx context.Context, email string) (*Style, error) {
|
||||
func getStyle(ctx context.Context, email string) (*Style, error) {
|
||||
log := log.Ctx(ctx)
|
||||
|
||||
avatarHost, styleHost, err := styleSRV(ctx, email)
|
||||
|
||||
@@ -2,10 +2,11 @@ package keyproofs
|
||||
|
||||
type page struct {
|
||||
AppName string
|
||||
Entity *Entity
|
||||
Style *Style
|
||||
Proofs *Proofs
|
||||
Entity *Entity
|
||||
Style *Style
|
||||
Proofs *Proofs
|
||||
|
||||
Markdown string
|
||||
HasProofs bool
|
||||
IsComplete bool
|
||||
Err error
|
||||
@@ -15,7 +16,6 @@ var pageTPL = `
|
||||
<html>
|
||||
<head>
|
||||
{{if not .IsComplete}}<meta http-equiv="refresh" content="1">{{end}}
|
||||
<script src="https://pagecdn.io/lib/font-awesome/5.14.0/js/fontawesome.min.js" crossorigin="anonymous" integrity="sha256-dNZKI9qQEpJG03MLdR2Rg9Dva1o+50fN3zmlDP+3I+Y="></script>
|
||||
|
||||
<link href="https://pagecdn.io/lib/bootstrap/4.5.1/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" integrity="sha256-VoFZSlmyTXsegReQCNmbXrS4hBBUl/cexZvPmPWoJsY=" >
|
||||
<link href="https://pagecdn.io/lib/font-awesome/5.14.0/css/fontawesome.min.css" rel="stylesheet" crossorigin="anonymous" integrity="sha256-7YMlwkILTJEm0TSengNDszUuNSeZu4KTN3z7XrhUQvc=" >
|
||||
@@ -25,6 +25,10 @@ var pageTPL = `
|
||||
|
||||
{{ with .Style }}
|
||||
<style>
|
||||
@font-face { font-family: "Font Awesome 5 Free"; font-weight: 900; src: url(https://pagecdn.io/lib/font-awesome/5.14.0/webfonts/fa-solid-900.woff2); }
|
||||
@font-face { font-family: "Font Awesome 5 Free"; font-weight: 400; src: url(https://pagecdn.io/lib/font-awesome/5.14.0/webfonts/fa-regular-400.woff2); }
|
||||
@font-face { font-family: "Font Awesome 5 Brands"; src: url(https://pagecdn.io/lib/font-awesome/5.14.0/webfonts/fa-brands-400.woff2); }
|
||||
|
||||
{{range $i, $val := .Palette}}.fg-color-{{$i}} { color: {{$val}}; }
|
||||
{{end}}
|
||||
|
||||
@@ -46,27 +50,26 @@ var pageTPL = `
|
||||
.shade { background-color: {{index .Palette 3}}80; border-radius: .25rem;}
|
||||
.lead { padding:0; margin:0; }
|
||||
|
||||
@media only screen and (max-width: 991px) {
|
||||
.jumbotron h1 { font-size: 2rem; }
|
||||
.jumbotron .lead { font-size: 1.0rem; }
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 768px) {
|
||||
.center-xs { text-align: center; width: 100% }
|
||||
.center-sm { text-align: center; width: 100% }
|
||||
.center-md { text-align: center; width: 100% }
|
||||
h1, h2, h3, h4, h5, h6, .lead { font-size: 75% }
|
||||
}
|
||||
.center-xs { text-align: center; width: 100% }
|
||||
.center-sm { text-align: center; width: 100% }
|
||||
.center-md { text-align: center; width: 100% }
|
||||
.jumbotron h1 { font-size: 2rem; }
|
||||
.jumbotron .lead { font-size: 1.0rem; }
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 576px) {
|
||||
.center-xs { text-align: center; width: 100% }
|
||||
.center-sm { text-align: center; width: 100% }
|
||||
.center-md { text-align: center; width: 100% }
|
||||
h1, h2, h3, h4, h5, h6, .lead { font-size: 75% }
|
||||
.jumbotron .lead { font-size: 0.8rem; }
|
||||
body { font-size: 0.8rem; }
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 0) {
|
||||
.center-xs { text-align: center; width: 100% }
|
||||
.center-sm { text-align: center; width: 100% }
|
||||
.center-md { text-align: center; width: 100% }
|
||||
h1, h2, h3, h4, h5, h6, .lead { font-size: 60% }
|
||||
}
|
||||
|
||||
</style>
|
||||
{{end}}
|
||||
</head>
|
||||
@@ -74,110 +77,178 @@ var pageTPL = `
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div class="col-md">
|
||||
<h1 class="display-8 fg-color-8">Something went wrong...</h1>
|
||||
<pre class="fg-color-11">{{.}}</pre>
|
||||
</div>
|
||||
{{else}}
|
||||
{{ with .Style }}
|
||||
<div class="col-xs center-md">
|
||||
<img src="{{.Avatar}}" class="img-thumbnail" alt="avatar" style="width:88px; height:88px">
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
{{with .Entity}}
|
||||
<div class="col-md center-md">
|
||||
<h1 class="display-8 fg-color-8">{{.Primary.Name}}</h1>
|
||||
<p class="lead fg-color-11"><i class="fas fa-fingerprint"></i> {{.Fingerprint}}</p>
|
||||
</div>
|
||||
<div class="col-xs center-md">
|
||||
<img src="/qr?s=-2&c=OPENPGP4FPR%3A{{.Fingerprint}}" class="img-thumbnail" alt="qrcode" style="width:88px; height:88px">
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="col-md">
|
||||
<h1 class="display-8 fg-color-8">Loading...</h1>
|
||||
<p class="lead fg-color-11">Reading key from remote service.</p>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
{{ with .Entity }}
|
||||
<div class="card">
|
||||
<div class="card-header">Contact</div>
|
||||
<div class="list-group list-group-flush">
|
||||
{{with .Primary}}<a href="mailto:{{.Address}}" class="list-group-item list-group-item-action"><i class="fas fa-envelope"></i> <b>{{.Name}} <{{.Address}}></b> <span class="badge badge-secondary">Primary</span></a>{{end}}
|
||||
{{range .Emails}}<a href="mailto:{{.Address}}" class="list-group-item list-group-item-action"><i class="far fa-envelope"></i> {{.Name}} <{{.Address}}></a>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
{{end}}
|
||||
|
||||
{{if .HasProofs}}
|
||||
{{with .Proofs}}
|
||||
<div class="card">
|
||||
<div class="card-header">Proofs</div>
|
||||
<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>
|
||||
{{.Name}}
|
||||
</a>
|
||||
|
||||
{{if eq .Status 0}}
|
||||
<a class="text-muted" href="{{.Verify}}"> <i class="fas fa-ellipsis-h"> Checking</i></a>
|
||||
{{else if eq .Status 1}}
|
||||
<a class="text-warning" href="{{.Verify}}"> <i class="fas fa-exclamation-triangle"></i> Error</a>
|
||||
{{else if eq .Status 2}}
|
||||
<a class="text-danger" href="{{.Verify}}"> <i class="far fa-times-circle"></i> Invalid</a>
|
||||
{{else if eq .Status 3}}
|
||||
<a class="text-success" href="{{.Verify}}"> <i class="far fa-check-square"></i> Verified</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div>
|
||||
{{if eq .Service "xmpp"}}
|
||||
<img src="/qr?s=-2&c={{.Link}}" alt="qrcode" style="width:88px; height:88px">
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
<br/>
|
||||
{{else}}
|
||||
<div class="card">
|
||||
<div class="card-header">Proofs</div>
|
||||
<div class="card-body">Loading...</div>
|
||||
</div>
|
||||
<br/>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{template "content" .}}
|
||||
|
||||
<div class="card-footer text-muted text-center">
|
||||
{{.AppName}} | © 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> | © 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>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
var homeTPL = `
|
||||
{{define "content"}}
|
||||
<div class="jumbotron heading">
|
||||
<div class="container">
|
||||
<div class="row shade">
|
||||
<div class="col-md">
|
||||
<h1 class="display-8 fg-color-8">Key Proofs</h1>
|
||||
<p class="lead fg-color-11">Verify social identitys using OpenPGP</p>
|
||||
</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">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" type="submit" id="button-addon">GO</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container"> {{.Markdown | markDown}} </div>
|
||||
{{end}}
|
||||
`
|
||||
|
||||
var proofTPL = `
|
||||
{{define "content"}}
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div class="col-md">
|
||||
<h1 class="display-8 fg-color-8">Something went wrong...</h1>
|
||||
<pre class="fg-color-11">{{.}}</pre>
|
||||
</div>
|
||||
{{else}}
|
||||
{{ with .Style }}
|
||||
<div class="col-xs center-md">
|
||||
<img src="{{.Avatar}}" class="img-thumbnail" alt="avatar" style="width:88px; height:88px">
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
{{with .Entity}}
|
||||
<div class="col-md center-md">
|
||||
<h1 class="display-8 fg-color-8">{{.Primary.Name}}</h1>
|
||||
<p class="lead fg-color-11"><i class="fas fa-fingerprint"></i> {{.Fingerprint}}</p>
|
||||
</div>
|
||||
<div class="col-xs center-md">
|
||||
<img src="/qr?s=-2&c=OPENPGP4FPR%3A{{.Fingerprint}}" class="img-thumbnail" alt="qrcode" style="width:88px; height:88px">
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="col-md">
|
||||
<h1 class="display-8 fg-color-8">Loading...</h1>
|
||||
<p class="lead fg-color-11">Reading key from remote service.</p>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
{{ with .Entity }}
|
||||
<div class="card">
|
||||
<div class="card-header">Contact</div>
|
||||
<div class="list-group list-group-flush">
|
||||
{{with .Primary}}<a href="mailto:{{.Address}}" class="list-group-item list-group-item-action"><i class="fas fa-envelope"></i> <b>{{.Name}} <{{.Address}}></b> <span class="badge badge-secondary">Primary</span></a>{{end}}
|
||||
{{range .Emails}}<a href="mailto:{{.Address}}" class="list-group-item list-group-item-action"><i class="far fa-envelope"></i> {{.Name}} <{{.Address}}></a>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
{{end}}
|
||||
|
||||
{{if .HasProofs}}
|
||||
{{with .Proofs}}
|
||||
<div class="card">
|
||||
<div class="card-header">Proofs</div>
|
||||
<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>
|
||||
{{.Name}}
|
||||
</a>
|
||||
|
||||
{{if eq .Status 0}}
|
||||
<a class="text-muted" href="{{.Verify}}"> <i class="fas fa-ellipsis-h"> Checking</i></a>
|
||||
{{else if eq .Status 1}}
|
||||
<a class="text-warning" href="{{.Verify}}"> <i class="fas fa-exclamation-triangle"></i> Error</a>
|
||||
{{else if eq .Status 2}}
|
||||
<a class="text-danger" href="{{.Verify}}"> <i class="far fa-times-circle"></i> Invalid</a>
|
||||
{{else if eq .Status 3}}
|
||||
<a class="text-success" href="{{.Verify}}"> <i class="far fa-check-square"></i> Verified</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div>
|
||||
{{if eq .Service "xmpp"}}
|
||||
<img src="/qr?s=-2&c={{.Link}}" alt="qrcode" style="width:88px; height:88px">
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
<br/>
|
||||
{{else}}
|
||||
<div class="card">
|
||||
<div class="card-header">Proofs</div>
|
||||
<div class="card-body">Loading...</div>
|
||||
</div>
|
||||
<br/>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
`
|
||||
|
||||
var homeMKDN = `
|
||||
## About Keyproofs
|
||||
|
||||
KeyProofs is a server side version of Keyoxide. There is no JavaScript executed on this page and resourcesKeys are looked up via [Web key directory](https://datatracker.ietf.org/doc/draft-koch-openpgp-webkey-service/)
|
||||
or from <https://keys.openpgp.org/>.
|
||||
|
||||
|
||||
### Decentralized online identity proofs
|
||||
|
||||
- You decide which accounts are linked together
|
||||
- You decide where this data is stored
|
||||
- KeyProofs does not store your identity data on its servers
|
||||
- KeyProofs merely verifies the identity proofs and displays them
|
||||
|
||||
### Empowering the internet citizen
|
||||
|
||||
- A verified identity proof proves ownership of an account and builds trust
|
||||
- No bad actor can impersonate you as long as your accounts aren't compromised
|
||||
- Your online identity data is safe from greedy internet corporations
|
||||
|
||||
### User-centric platform
|
||||
|
||||
- KeyProofs generates QR codes that integrate with OpenKeychain and Conversations
|
||||
- KeyProofs fetches the key wherever the user decides to store it
|
||||
- KeyProofs is self-hostable, meaning you could put it on any server you trust
|
||||
|
||||
### Secure and privacy-friendly
|
||||
|
||||
- KeyProofs doesn't want your personal data, track you or show you ads
|
||||
- KeyProofs relies on OpenPGP, a widely used public-key cryptography standard (RFC-4880)
|
||||
- Cryptographic operations are performed on server.
|
||||
`
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/sour-is/keyproofs/pkg/graceful"
|
||||
"gosrc.io/xmpp"
|
||||
"gosrc.io/xmpp/stanza"
|
||||
)
|
||||
@@ -40,28 +41,34 @@ func init() {
|
||||
}
|
||||
|
||||
type connection struct {
|
||||
client *xmpp.Client
|
||||
client xmpp.StreamClient
|
||||
}
|
||||
|
||||
func NewXMPP(ctx context.Context, config *xmpp.Config) (*connection, error) {
|
||||
log := log.Ctx(ctx)
|
||||
wg := graceful.WaitGroup(ctx)
|
||||
|
||||
router := xmpp.NewRouter()
|
||||
conn := &connection{}
|
||||
|
||||
var err error
|
||||
conn.client, err = xmpp.NewClient(config, router, func(err error) { log.Error().Err(err).Send() })
|
||||
cl, err := xmpp.NewClient(config, router, func(err error) { log.Error().Err(err).Send() })
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sc := xmpp.NewStreamManager(cl, func(c xmpp.Sender) { log.Info().Msg("XMPP Client connected.") })
|
||||
|
||||
wg.Go(func() error {
|
||||
log.Debug().Msg("starting XMPP")
|
||||
return sc.Run()
|
||||
})
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err := conn.client.Disconnect()
|
||||
log.Error().Err(err).Send()
|
||||
sc.Stop()
|
||||
log.Info().Msg("XMPP Client shutdown.")
|
||||
}()
|
||||
|
||||
err = conn.client.Connect()
|
||||
|
||||
conn.client = cl
|
||||
return conn, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user