mirror of
https://gitgud.io/yats/cerberus.git
synced 2026-05-02 02:32:18 -04:00
Add challenge page parser util
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
|||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
const _TEST_HOST = "kiwifarms.jp"
|
const _TEST_HOST = "kiwifarms.st"
|
||||||
const _TEST_ONION = "kiwifarmsaaf4t2h7gc3dfc5ojhmqruw2nit3uejrpiagrxeuxiyxcyd.onion"
|
const _TEST_ONION = "kiwifarmsaaf4t2h7gc3dfc5ojhmqruw2nit3uejrpiagrxeuxiyxcyd.onion"
|
||||||
|
|
||||||
type errBadZeroCheck struct {
|
type errBadZeroCheck struct {
|
||||||
|
|||||||
18
http.go
18
http.go
@@ -70,6 +70,21 @@ func NewChallenge(ctx context.Context, hc http.Client, host string) (Challenge,
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseChallenge(r io.Reader, host string) (Challenge, error) {
|
||||||
|
u, err := parseHost(host)
|
||||||
|
if err != nil {
|
||||||
|
return Challenge{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err := parseTags(r)
|
||||||
|
if err != nil {
|
||||||
|
return Challenge{}, err
|
||||||
|
}
|
||||||
|
c.host = u
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Submit a Solution for a Challenge.
|
// Submit a Solution for a Challenge.
|
||||||
//
|
//
|
||||||
// If redirect is empty, "/" is used as a sensible default.
|
// If redirect is empty, "/" is used as a sensible default.
|
||||||
@@ -137,8 +152,7 @@ func postSolution(ctx context.Context, hc http.Client, s Solution) (*http.Respon
|
|||||||
// TODO: Additionally verify failure from response JSON. Maybe include resp body in err type.
|
// TODO: Additionally verify failure from response JSON. Maybe include resp body in err type.
|
||||||
// Rejected solution response: status=400 body={"success":false,"reason":"invalid_solution","action":"retry"}
|
// Rejected solution response: status=400 body={"success":false,"reason":"invalid_solution","action":"retry"}
|
||||||
if resp.StatusCode == 400 {
|
if resp.StatusCode == 400 {
|
||||||
defer resp.Body.Close()
|
return resp, &ErrInvalidSolution{s}
|
||||||
return nil, &ErrInvalidSolution{s}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user