try a little harder to recover from httpsig failures

This commit is contained in:
Ted Unangst 2019-11-25 15:54:29 -05:00
parent c9aba7ecba
commit d167f26418
3 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,8 @@ changelog
-- next -- next
+ Try a little harder to recover from httpsig failures.
+ Add cite tag for block quote attributions. + Add cite tag for block quote attributions.
+ @media print styles. + @media print styles.

7
fun.go
View File

@ -28,6 +28,7 @@ import (
"os" "os"
"regexp" "regexp"
"strings" "strings"
"time"
"golang.org/x/net/html" "golang.org/x/net/html"
"humungus.tedunangst.com/r/webs/cache" "humungus.tedunangst.com/r/webs/cache"
@ -613,6 +614,12 @@ func zaggy(keyname string) *rsa.PublicKey {
return key return key
} }
func savingthrow(keyname string) {
when := time.Now().UTC().Sub(30 * time.Minute).Format(dbtimeformat)
stmtDeleteXonker.Exec(keyname, "pubkey", when)
zaggies.Clear(keyname)
}
func keymatch(keyname string, actor string) string { func keymatch(keyname string, actor string) string {
hash := strings.IndexByte(keyname, '#') hash := strings.IndexByte(keyname, '#')
if hash == -1 { if hash == -1 {

8
web.go
View File

@ -330,6 +330,10 @@ func inbox(w http.ResponseWriter, r *http.Request) {
} }
keyname, err := httpsig.VerifyRequest(r, payload, zaggy) keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
if err != nil && keyname != "" {
savingthrow(keyname)
keyname, err = httpsig.VerifyRequest(r, payload, zaggy)
}
if err != nil { if err != nil {
log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For")) log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For"))
if keyname != "" { if keyname != "" {
@ -460,6 +464,10 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
return return
} }
keyname, err := httpsig.VerifyRequest(r, payload, zaggy) keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
if err != nil && keyname != "" {
savingthrow(keyname)
keyname, err = httpsig.VerifyRequest(r, payload, zaggy)
}
if err != nil { if err != nil {
log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For")) log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For"))
if keyname != "" { if keyname != "" {