add support for ed25519 httpsig keys

This commit is contained in:
Ted Unangst 2020-01-19 03:44:38 -05:00
parent 7e2a8c0457
commit d6e1690192
5 changed files with 20 additions and 18 deletions

View File

@ -17,7 +17,6 @@ package main
import ( import (
"bytes" "bytes"
"crypto/rsa"
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
@ -58,11 +57,11 @@ func friendorfoe(ct string) bool {
return false 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()) 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 client := http.DefaultClient
req, err := http.NewRequest("POST", url, bytes.NewReader(msg)) req, err := http.NewRequest("POST", url, bytes.NewReader(msg))
if err != nil { if err != nil {

16
fun.go
View File

@ -17,7 +17,6 @@ package main
import ( import (
"crypto/rand" "crypto/rand"
"crypto/rsa"
"crypto/sha512" "crypto/sha512"
"fmt" "fmt"
"html/template" "html/template"
@ -594,10 +593,11 @@ func ziggy(userid int64) *KeyInfo {
return ki 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 var data string
row := stmtGetXonker.QueryRow(keyname, "pubkey") row := stmtGetXonker.QueryRow(keyname, "pubkey")
err := row.Scan(&data) err := row.Scan(&data)
var key httpsig.PublicKey
if err != nil { if err != nil {
log.Printf("hitting the webs for missing pubkey: %s", keyname) log.Printf("hitting the webs for missing pubkey: %s", keyname)
j, err := GetJunk(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) log.Printf("error getting %s pubkey: %s", keyname, err)
when := time.Now().UTC().Format(dbtimeformat) when := time.Now().UTC().Format(dbtimeformat)
stmtSaveXonker.Exec(keyname, "failed", "pubkey", when) stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
return nil, true return key, true
} }
allinjest(originate(keyname), j) allinjest(originate(keyname), j)
row = stmtGetXonker.QueryRow(keyname, "pubkey") 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") log.Printf("key not found after ingesting")
when := time.Now().UTC().Format(dbtimeformat) when := time.Now().UTC().Format(dbtimeformat)
stmtSaveXonker.Exec(keyname, "failed", "pubkey", when) 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 { if err != nil {
log.Printf("error decoding %s pubkey: %s", keyname, err) log.Printf("error decoding %s pubkey: %s", keyname, err)
return nil, true return key, true
} }
return key, true return key, true
}, Limit: 512}) }, Limit: 512})
func zaggy(keyname string) *rsa.PublicKey { func zaggy(keyname string) httpsig.PublicKey {
var key *rsa.PublicKey var key httpsig.PublicKey
zaggies.Get(keyname, &key) zaggies.Get(keyname, &key)
return key return key
} }

2
go.mod
View File

@ -7,7 +7,7 @@ require (
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 golang.org/x/net v0.0.0-20190620200207-3b0461eec859
humungus.tedunangst.com/r/go-sqlite3 v1.1.3 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 go 1.11

2
go.sum
View File

@ -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/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 h1:xDgtESuVljephZA4GfcycwiOwJeeJYUIQbStFHceN1Y=
humungus.tedunangst.com/r/webs v0.6.31/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= 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=

View File

@ -16,7 +16,6 @@
package main package main
import ( import (
"crypto/rsa"
"flag" "flag"
"fmt" "fmt"
"html/template" "html/template"
@ -26,6 +25,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"humungus.tedunangst.com/r/webs/httpsig"
) )
var softwareVersion = "develop" var softwareVersion = "develop"
@ -42,7 +43,7 @@ type WhatAbout struct {
Key string Key string
URL string URL string
Options UserOptions Options UserOptions
SecKey *rsa.PrivateKey SecKey httpsig.PrivateKey
} }
type UserOptions struct { type UserOptions struct {
@ -54,7 +55,7 @@ type UserOptions struct {
type KeyInfo struct { type KeyInfo struct {
keyname string keyname string
seckey *rsa.PrivateKey seckey httpsig.PrivateKey
} }
const serverUID int64 = -2 const serverUID int64 = -2