Skip to content

Commit

Permalink
Sync fork (#3)
Browse files Browse the repository at this point in the history
* Update README (pufferffish#137)

* Fix broken sandboxing resulting in SIGABRT (pufferffish#136)

* Fix HTTP proxy authentication to support both preemptive and challenge-response auth (pufferffish#134)

* Bump version

---------

Co-authored-by: Niko <[email protected]>
Co-authored-by: Luiz Henrique Gomes Palácio <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2024
1 parent c57adbc commit fe2920a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/wireproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var default_config_paths = []string {
os.Getenv("HOME")+"/.config/wireproxy.conf",
}

var version = "1.0.8-dev"
var version = "1.0.11-dev"

func panicIfError(err error) {
if err != nil {
Expand Down
36 changes: 20 additions & 16 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ func (s *HTTPServer) authenticate(req *http.Request) (int, error) {
}

auth := req.Header.Get(proxyAuthHeaderKey)
if auth != "" {
enc := strings.TrimPrefix(auth, "Basic ")
str, err := base64.StdEncoding.DecodeString(enc)
if err != nil {
return http.StatusNotAcceptable, fmt.Errorf("decode username and password failed: %w", err)
}
pairs := bytes.SplitN(str, []byte(":"), 2)
if len(pairs) != 2 {
return http.StatusLengthRequired, fmt.Errorf("username and password format invalid")
}
if s.auth.Valid(string(pairs[0]), string(pairs[1])) {
return 0, nil
}
return http.StatusUnauthorized, fmt.Errorf("username and password not matching")
if auth == "" {
return http.StatusProxyAuthRequired, errors.New(http.StatusText(http.StatusProxyAuthRequired))
}

return http.StatusProxyAuthRequired, errors.New(http.StatusText(http.StatusProxyAuthRequired))
enc := strings.TrimPrefix(auth, "Basic ")
str, err := base64.StdEncoding.DecodeString(enc)
if err != nil {
return http.StatusNotAcceptable, fmt.Errorf("decode username and password failed: %w", err)
}
pairs := bytes.SplitN(str, []byte(":"), 2)
if len(pairs) != 2 {
return http.StatusLengthRequired, fmt.Errorf("username and password format invalid")
}
if s.auth.Valid(string(pairs[0]), string(pairs[1])) {
return 0, nil
}
return http.StatusUnauthorized, fmt.Errorf("username and password not matching")
}

func (s *HTTPServer) handleConn(req *http.Request, conn net.Conn) (peer net.Conn, err error) {
Expand Down Expand Up @@ -104,7 +104,11 @@ func (s *HTTPServer) serve(conn net.Conn) {

code, err := s.authenticate(req)
if err != nil {
_ = responseWith(req, code).Write(conn)
resp := responseWith(req, code)
if code == http.StatusProxyAuthRequired {
resp.Header.Set("Proxy-Authenticate", "Basic realm=\"Proxy\"")
}
_ = resp.Write(conn)
log.Println(err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion systemd/wireproxy.service
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK
RestrictNamespaces=true
RestrictRealtime=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=@system-service @sandbox

[Install]
WantedBy=multi-user.target

0 comments on commit fe2920a

Please sign in to comment.