all repos — honk @ a8621800cf495b55e32423e3c93df2f4d88e958c

my fork of honk

big resigh. need to resign after redirect.
Ted Unangst tedu@tedunangst.com
Tue, 29 Aug 2023 00:18:14 -0400
commit

a8621800cf495b55e32423e3c93df2f4d88e958c

parent

9943d358f37564e962837374e0a70f28667ca1b5

2 files changed, 23 insertions(+), 19 deletions(-)

jump to
M activity.goactivity.go

@@ -59,12 +59,14 @@ }

return false } -var develClient = &http.Client{ - Transport: &http.Transport{ +var honkClient = http.Client{} + +func gogglesDoNothing() { + honkClient.Transport = &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, - }, + } } func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) error {

@@ -72,10 +74,6 @@ return PostMsg(keyname, key, url, j.ToBytes())

} func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) error { - client := http.DefaultClient - if develMode { - client = develClient - } req, err := http.NewRequest("POST", url, bytes.NewReader(msg)) if err != nil { return err

@@ -86,7 +84,7 @@ httpsig.SignRequest(keyname, key, req, msg)

ctx, cancel := context.WithTimeout(context.Background(), 2*slowTimeout*time.Second) defer cancel() req = req.WithContext(ctx) - resp, err := client.Do(req) + resp, err := honkClient.Do(req) if err != nil { return err }

@@ -130,13 +128,10 @@ }

var flightdeck = gate.NewSerializer() -var signGets = true - func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk, error) { if rejectorigin(userid, url, false) { return nil, fmt.Errorf("rejected origin: %s", url) } - client := http.DefaultClient sign := func(req *http.Request) error { var ki *KeyInfo ok := ziggies.Get(userid, &ki)

@@ -146,9 +141,18 @@ }

return nil } if develMode { - client = develClient sign = nil } + client := honkClient + client.CheckRedirect = func(req *http.Request, via []*http.Request) error { + if len(via) >= 5 { + return fmt.Errorf("stopped after 5 redirects") + } + if sign != nil { + sign(req) + } + return nil + } fn := func() (interface{}, error) { at := theonetruename if strings.Contains(url, ".well-known/webfinger?resource") {

@@ -158,7 +162,7 @@ j, err := junk.Get(url, junk.GetArgs{

Accept: at, Agent: "honksnonk/5.0; " + serverName, Timeout: timeout, - Client: client, + Client: &client, Fixup: sign, }) return j, err

@@ -173,10 +177,6 @@ return j, nil

} func fetchsome(url string) ([]byte, error) { - client := http.DefaultClient - if develMode { - client = develClient - } req, err := http.NewRequest("GET", url, nil) if err != nil { ilog.Printf("error fetching %s: %s", url, err)

@@ -186,7 +186,7 @@ req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) defer cancel() req = req.WithContext(ctx) - resp, err := client.Do(req) + resp, err := honkClient.Do(req) if err != nil { ilog.Printf("error fetching %s: %s", url, err) return nil, err
M main.gomain.go

@@ -115,12 +115,16 @@ serverPrefix = fmt.Sprintf("https://%s/", serverName)

getconfig("usersep", &userSep) getconfig("honksep", &honkSep) getconfig("devel", &develMode) + if develMode { + gogglesDoNothing() + } getconfig("fasttimeout", &fastTimeout) getconfig("slowtimeout", &slowTimeout) getconfig("honkwindow", &honkwindow) honkwindow *= 24 * time.Hour - getconfig("signgets", &signGets) + prepareStatements(db) + switch cmd { case "admin": adminscreen()