Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05df6253db | ||
|
|
b294d4fdc8
|
||
|
|
90bba0e527
|
2
Makefile
2
Makefile
@@ -14,7 +14,7 @@ version:
|
|||||||
@echo $(VERSION)
|
@echo $(VERSION)
|
||||||
tag:
|
tag:
|
||||||
git tag -a v$(VERSION) -m "Version: $(VERSION)"
|
git tag -a v$(VERSION) -m "Version: $(VERSION)"
|
||||||
git push --tag
|
git push --follow-tags
|
||||||
release:
|
release:
|
||||||
@make tag BUMP=patch
|
@make tag BUMP=patch
|
||||||
run:
|
run:
|
||||||
|
|||||||
@@ -146,24 +146,21 @@ func ReadKey(r io.Reader, useArmored bool) (e *Entity, err error) {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
var w io.Writer = &buf
|
var w io.Writer = &buf
|
||||||
|
|
||||||
e = &Entity{}
|
e = &Entity{}
|
||||||
|
|
||||||
|
defer func(){ if e != nil { e.ArmorText = buf.String() }}()
|
||||||
|
|
||||||
|
|
||||||
if !useArmored {
|
if !useArmored {
|
||||||
var aw io.WriteCloser
|
var aw io.WriteCloser
|
||||||
aw, err = armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", nil)
|
aw, err = armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return e, fmt.Errorf("Read key: %w", err)
|
return e, fmt.Errorf("Read key: %w", err)
|
||||||
}
|
}
|
||||||
defer aw.Close()
|
defer aw.Close()
|
||||||
|
|
||||||
w = aw
|
w = aw
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
if e != nil {
|
|
||||||
e.ArmorText = buf.String()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
r = io.TeeReader(r, w)
|
r = io.TeeReader(r, w)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package keyproofs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -205,6 +206,17 @@ func NewProof(ctx context.Context, uri, fingerprint string) ProofResolver {
|
|||||||
return &httpResolve{p, url, nil}
|
return &httpResolve{p, url, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case strings.Contains(p.URI.Path, "/conv/"), strings.Contains(p.URI.Path, "/twt/"):
|
||||||
|
if sp := strings.SplitN(p.URI.Path, "/", 3); len(sp) == 3 {
|
||||||
|
p.Icon = "fas fa-comment-alt"
|
||||||
|
p.Service = "Twtxt"
|
||||||
|
p.Name = fmt.Sprintf("...@%s", p.URI.Host)
|
||||||
|
p.Link = fmt.Sprintf("https://%s", p.URI.Host)
|
||||||
|
|
||||||
|
url := fmt.Sprintf("https://%s/api/v1/conv", p.URI.Host)
|
||||||
|
return &twtxtResolve{p, url, sp[2], nil}
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if sp := strings.SplitN(p.URI.Path, "/", 3); len(sp) > 1 {
|
if sp := strings.SplitN(p.URI.Path, "/", 3); len(sp) > 1 {
|
||||||
p.Icon = "fas fa-project-diagram"
|
p.Icon = "fas fa-project-diagram"
|
||||||
@@ -294,8 +306,8 @@ func (r *gitlabResolve) Resolve(ctx context.Context) error {
|
|||||||
|
|
||||||
return ErrNoFingerprint
|
return ErrNoFingerprint
|
||||||
}
|
}
|
||||||
func (p *gitlabResolve) Proof() *Proof {
|
func (r *gitlabResolve) Proof() *Proof {
|
||||||
return &p.proof
|
return &r.proof
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proof) Resolve(ctx context.Context) error {
|
func (p *Proof) Resolve(ctx context.Context) error {
|
||||||
@@ -305,6 +317,44 @@ func (p *Proof) Proof() *Proof {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type twtxtResolve struct {
|
||||||
|
proof Proof `json:"-"`
|
||||||
|
url string `json:"-"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
headers map[string]string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *twtxtResolve) Resolve(ctx context.Context) error {
|
||||||
|
t.proof.Status = ProofInvalid
|
||||||
|
|
||||||
|
twt := struct {
|
||||||
|
Twts []struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
Twter struct{ Nick string }
|
||||||
|
} `json:"twts"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
if err := postJSON(ctx, t.url, nil, t, &twt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(twt.Twts) > 0 {
|
||||||
|
nick := twt.Twts[0].Twter.Nick
|
||||||
|
t.proof.Name = fmt.Sprintf("%s@%s", nick, t.proof.URI.Host)
|
||||||
|
t.proof.Link += "/user/" + nick
|
||||||
|
|
||||||
|
ck := fmt.Sprintf("[Verifying my OpenPGP key: openpgp4fpr:%s]", t.proof.Fingerprint)
|
||||||
|
if strings.Contains(twt.Twts[0].Text, ck) {
|
||||||
|
t.proof.Status = ProofVerified
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ErrNoFingerprint
|
||||||
|
}
|
||||||
|
func (t *twtxtResolve) Proof() *Proof {
|
||||||
|
return &t.proof
|
||||||
|
}
|
||||||
|
|
||||||
func checkHTTP(ctx context.Context, uri, fingerprint string, hdr map[string]string) error {
|
func checkHTTP(ctx context.Context, uri, fingerprint string, hdr map[string]string) error {
|
||||||
log := log.Ctx(ctx)
|
log := log.Ctx(ctx)
|
||||||
|
|
||||||
@@ -370,3 +420,36 @@ func httpJSON(ctx context.Context, uri string, hdr map[string]string, dst interf
|
|||||||
|
|
||||||
return json.NewDecoder(res.Body).Decode(dst)
|
return json.NewDecoder(res.Body).Decode(dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postJSON(ctx context.Context, uri string, hdr map[string]string, payload, dst interface{}) error {
|
||||||
|
log := log.Ctx(ctx)
|
||||||
|
|
||||||
|
log.Info().Str("URI", uri).Msg("postJSON")
|
||||||
|
|
||||||
|
body, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Send()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
buf := bytes.NewBuffer(body)
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "POST", uri, buf)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Send()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
for k, v := range hdr {
|
||||||
|
req.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
return json.NewDecoder(res.Body).Decode(dst)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user