From d6e1690192b9129e278be56cdcab73ae22e5aef7 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 19 Jan 2020 03:44:38 -0500 Subject: [PATCH] add support for ed25519 httpsig keys --- activity.go | 5 ++--- fun.go | 16 ++++++++-------- go.mod | 2 +- go.sum | 2 ++ honk.go | 13 +++++++------ 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/activity.go b/activity.go index c4ef906..6327222 100644 --- a/activity.go +++ b/activity.go @@ -17,7 +17,6 @@ package main import ( "bytes" - "crypto/rsa" "database/sql" "errors" "fmt" @@ -58,11 +57,11 @@ func friendorfoe(ct string) bool { return false } -func PostJunk(keyname string, key *rsa.PrivateKey, url string, j junk.Junk) error { +func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) error { return PostMsg(keyname, key, url, j.ToBytes()) } -func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error { +func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) error { client := http.DefaultClient req, err := http.NewRequest("POST", url, bytes.NewReader(msg)) if err != nil { diff --git a/fun.go b/fun.go index df275e2..1e18c08 100644 --- a/fun.go +++ b/fun.go @@ -17,7 +17,6 @@ package main import ( "crypto/rand" - "crypto/rsa" "crypto/sha512" "fmt" "html/template" @@ -594,10 +593,11 @@ func ziggy(userid int64) *KeyInfo { return ki } -var zaggies = cache.New(cache.Options{Filler: func(keyname string) (*rsa.PublicKey, bool) { +var zaggies = cache.New(cache.Options{Filler: func(keyname string) (httpsig.PublicKey, bool) { var data string row := stmtGetXonker.QueryRow(keyname, "pubkey") err := row.Scan(&data) + var key httpsig.PublicKey if err != nil { log.Printf("hitting the webs for missing pubkey: %s", keyname) j, err := GetJunk(keyname) @@ -605,7 +605,7 @@ var zaggies = cache.New(cache.Options{Filler: func(keyname string) (*rsa.PublicK log.Printf("error getting %s pubkey: %s", keyname, err) when := time.Now().UTC().Format(dbtimeformat) stmtSaveXonker.Exec(keyname, "failed", "pubkey", when) - return nil, true + return key, true } allinjest(originate(keyname), j) row = stmtGetXonker.QueryRow(keyname, "pubkey") @@ -614,19 +614,19 @@ var zaggies = cache.New(cache.Options{Filler: func(keyname string) (*rsa.PublicK log.Printf("key not found after ingesting") when := time.Now().UTC().Format(dbtimeformat) stmtSaveXonker.Exec(keyname, "failed", "pubkey", when) - return nil, true + return key, true } } - _, key, err := httpsig.DecodeKey(data) + _, key, err = httpsig.DecodeKey(data) if err != nil { log.Printf("error decoding %s pubkey: %s", keyname, err) - return nil, true + return key, true } return key, true }, Limit: 512}) -func zaggy(keyname string) *rsa.PublicKey { - var key *rsa.PublicKey +func zaggy(keyname string) httpsig.PublicKey { + var key httpsig.PublicKey zaggies.Get(keyname, &key) return key } diff --git a/go.mod b/go.mod index 2d45b6d..79d204a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.31 + humungus.tedunangst.com/r/webs v0.6.34 ) go 1.11 diff --git a/go.sum b/go.sum index 83c3182..afcaa73 100644 --- a/go.sum +++ b/go.sum @@ -25,3 +25,5 @@ humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9 humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= humungus.tedunangst.com/r/webs v0.6.31 h1:xDgtESuVljephZA4GfcycwiOwJeeJYUIQbStFHceN1Y= humungus.tedunangst.com/r/webs v0.6.31/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.34 h1:C9S5L310Z1H4H681f/e4zwqGJLR53XoCTwDoHAq7UVo= +humungus.tedunangst.com/r/webs v0.6.34/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= diff --git a/honk.go b/honk.go index 96f5bb5..86befa0 100644 --- a/honk.go +++ b/honk.go @@ -16,7 +16,6 @@ package main import ( - "crypto/rsa" "flag" "fmt" "html/template" @@ -26,6 +25,8 @@ import ( "strconv" "strings" "time" + + "humungus.tedunangst.com/r/webs/httpsig" ) var softwareVersion = "develop" @@ -42,19 +43,19 @@ type WhatAbout struct { Key string URL string Options UserOptions - SecKey *rsa.PrivateKey + SecKey httpsig.PrivateKey } type UserOptions struct { - SkinnyCSS bool `json:",omitempty"` + SkinnyCSS bool `json:",omitempty"` OmitImages bool `json:",omitempty"` - Avatar string `json:",omitempty"` - MapLink string `json:",omitempty"` + Avatar string `json:",omitempty"` + MapLink string `json:",omitempty"` } type KeyInfo struct { keyname string - seckey *rsa.PrivateKey + seckey httpsig.PrivateKey } const serverUID int64 = -2