Skip to content

Commit

Permalink
*fix tls in a situation that no cert meets sni
Browse files Browse the repository at this point in the history
*better api
  • Loading branch information
mrhaoxx committed Jul 18, 2023
1 parent 7c2a7e3 commit 6981849
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions auth/policybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (usr *user) checkpwd(passwd string) bool {

return false
}
func GenHash(data string) string {
hashed, _ := utils.HashPassword(data)
return hashed
}

func (l *policyBaseAuth) getPolicies(hos string) policygroup {
return l.policyBuf.Lookup(hos).([]*policy)
Expand Down
12 changes: 6 additions & 6 deletions http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ func (h *httpproxy) HandleHTTPInternal(ctx *HttpCtx) Ret {
var id string
if _host != nil {
id = _host.(*Httphost).Id
} else {
id = "nohit"
}

ctx.WriteString("hit: " + id + "\n")
ctx.WriteString("id: " + id + "\n")
return RequestEnd
}
func (*httpproxy) PathsInternal() utils.GroupRegexp {
Expand All @@ -48,9 +50,6 @@ func (*httpproxy) PathsInternal() utils.GroupRegexp {

var regexpforproxy = regexp2.MustCompile("^/proxy/trace$", 0)

// @RetVal *httpproxy proxier
//
//ng:generate def func NewHTTPProxier
func NewHTTPProxier() *httpproxy {
hpx := &httpproxy{
hosts: make([]*Httphost, 0),
Expand All @@ -59,11 +58,13 @@ func NewHTTPProxier() *httpproxy {
hpx.buf = utils.NewBufferedLookup(func(host string) interface{} {
for _, t := range hpx.hosts {
if t.ServerName.MatchString(host) {
// fmt.Println(t.ServerName.String(), host, "success")
return t
}
// fmt.Println(t.ServerName.String(), host, "failed")
}
return nil
})
})
return hpx
}

Expand Down Expand Up @@ -161,7 +162,6 @@ func (hpx *httpproxy) Insert(index int, id string, hosts []string, backend strin
FlushInterval: 0,
}
hpx.hosts = insert(hpx.hosts, index, &buf)
hpx.buf.Refresh()
return nil
}
func insert(a []*Httphost, index int, value *Httphost) []*Httphost {
Expand Down
2 changes: 1 addition & 1 deletion tls/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ func (mgr *tlsMgr) Handle(c *tcp.Connection) tcp.SerRet {
}
}
}
return tcp.Continue
return tcp.Close
}
22 changes: 18 additions & 4 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package ui
import (
_ "embed"
"encoding/json"
"fmt"
"io"
"io/fs"
stdhttp "net/http"
_ "net/http/pprof"
"os"
"runtime"
"strconv"
"strings"

auth "github.com/haoxingxing/OpenNG/auth"
http "github.com/haoxingxing/OpenNG/http"
utils "github.com/haoxingxing/OpenNG/utils"

Expand Down Expand Up @@ -68,10 +71,21 @@ func (*UI) HandleHTTP(ctx *http.HttpCtx) http.Ret {
ctx.Resp.Header().Set("Content-Type", "text/yaml; charset=utf-8")
ctx.Resp.Header().Set("Cache-Control", "no-cache")
ctx.Resp.Write(curcfg)
// case "/genhash":
// b, _ := io.ReadAll(ctx.Req.Body)
// hashed := auth.GenHash(string(b))
// ctx.Resp.Write([]byte(hashed))
case "/genhash":
b, _ := io.ReadAll(ctx.Req.Body)
hashed := auth.GenHash(string(b))
ctx.Resp.Write([]byte(hashed))
case "/sys":
var m runtime.MemStats
runtime.ReadMemStats(&m)
ctx.WriteString(fmt.Sprint("alloc: ", m.Alloc, "\n",
"totalalloc: ", m.TotalAlloc, "\n",
"sysmem: ", m.Sys, "\n",
"numgc: ", m.NumGC, "\n",
"goroutines: ", runtime.NumGoroutine(), "\n",
"cpus: ", runtime.NumCPU(), "\n",
"ccalls: ", runtime.NumCgoCall(), "\n",
))

case "/204":
ctx.Resp.WriteHeader(204)
Expand Down

0 comments on commit 6981849

Please sign in to comment.