big resigh. need to resign after redirect.

This commit is contained in:
Ted Unangst 2023-08-29 00:18:14 -04:00
parent 7dc99cec9b
commit 8380a32139
2 changed files with 23 additions and 19 deletions

View File

@ -59,12 +59,14 @@ func friendorfoe(ct string) bool {
return false return false
} }
var develClient = &http.Client{ var honkClient = http.Client{}
Transport: &http.Transport{
func gogglesDoNothing() {
honkClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
}, },
}, }
} }
func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) error { func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) error {
@ -72,10 +74,6 @@ func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) e
} }
func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) error { 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)) req, err := http.NewRequest("POST", url, bytes.NewReader(msg))
if err != nil { if err != nil {
return err return err
@ -86,7 +84,7 @@ func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) err
ctx, cancel := context.WithTimeout(context.Background(), 2*slowTimeout*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 2*slowTimeout*time.Second)
defer cancel() defer cancel()
req = req.WithContext(ctx) req = req.WithContext(ctx)
resp, err := client.Do(req) resp, err := honkClient.Do(req)
if err != nil { if err != nil {
return err return err
} }
@ -130,13 +128,10 @@ func GetJunkHardMode(userid int64, url string) (junk.Junk, error) {
var flightdeck = gate.NewSerializer() var flightdeck = gate.NewSerializer()
var signGets = true
func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk, error) { func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk, error) {
if rejectorigin(userid, url, false) { if rejectorigin(userid, url, false) {
return nil, fmt.Errorf("rejected origin: %s", url) return nil, fmt.Errorf("rejected origin: %s", url)
} }
client := http.DefaultClient
sign := func(req *http.Request) error { sign := func(req *http.Request) error {
var ki *KeyInfo var ki *KeyInfo
ok := ziggies.Get(userid, &ki) ok := ziggies.Get(userid, &ki)
@ -146,9 +141,18 @@ func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk,
return nil return nil
} }
if develMode { if develMode {
client = develClient
sign = nil 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) { fn := func() (interface{}, error) {
at := theonetruename at := theonetruename
if strings.Contains(url, ".well-known/webfinger?resource") { if strings.Contains(url, ".well-known/webfinger?resource") {
@ -158,7 +162,7 @@ func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk,
Accept: at, Accept: at,
Agent: "honksnonk/5.0; " + serverName, Agent: "honksnonk/5.0; " + serverName,
Timeout: timeout, Timeout: timeout,
Client: client, Client: &client,
Fixup: sign, Fixup: sign,
}) })
return j, err return j, err
@ -173,10 +177,6 @@ func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk,
} }
func fetchsome(url string) ([]byte, error) { func fetchsome(url string) ([]byte, error) {
client := http.DefaultClient
if develMode {
client = develClient
}
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
ilog.Printf("error fetching %s: %s", url, err) ilog.Printf("error fetching %s: %s", url, err)
@ -186,7 +186,7 @@ func fetchsome(url string) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel() defer cancel()
req = req.WithContext(ctx) req = req.WithContext(ctx)
resp, err := client.Do(req) resp, err := honkClient.Do(req)
if err != nil { if err != nil {
ilog.Printf("error fetching %s: %s", url, err) ilog.Printf("error fetching %s: %s", url, err)
return nil, err return nil, err

View File

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