├── vendor ├── github.com │ ├── elazarl │ │ └── goproxy │ │ │ ├── .gitignore │ │ │ ├── logger.go │ │ │ ├── go.mod │ │ │ ├── go.sum │ │ │ ├── all.bash │ │ │ ├── responses.go │ │ │ ├── LICENSE │ │ │ ├── counterecryptor.go │ │ │ ├── chunked.go │ │ │ ├── ca.pem │ │ │ ├── actions.go │ │ │ ├── signer.go │ │ │ ├── key.pem │ │ │ ├── ctx.go │ │ │ ├── websocket.go │ │ │ ├── doc.go │ │ │ ├── certs.go │ │ │ ├── proxy.go │ │ │ ├── README.md │ │ │ ├── dispatcher.go │ │ │ └── https.go │ └── BurntSushi │ │ └── toml │ │ ├── session.vim │ │ ├── .gitignore │ │ ├── COMPATIBLE │ │ ├── .travis.yml │ │ ├── Makefile │ │ ├── encoding_types_1.1.go │ │ ├── encoding_types.go │ │ ├── COPYING │ │ ├── doc.go │ │ ├── type_check.go │ │ ├── decode_meta.go │ │ ├── README.md │ │ ├── type_fields.go │ │ ├── decode.go │ │ ├── encode.go │ │ └── parse.go └── modules.txt ├── .gitignore ├── go.mod ├── microproxy.toml ├── .github └── workflows │ └── go.yml ├── basic_auth_test.go ├── conn.go ├── go.sum ├── LICENSE ├── basic_auth.go ├── proxy-digest-auth-test.py.bak ├── proxy-digest-auth-test.py ├── config_test.go ├── headers_test.go ├── digest_auth.go ├── log.go ├── README.md ├── config.go ├── auth.go ├── auth_test.go └── microproxy.go /vendor/github.com/elazarl/goproxy/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | *.swp 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | microproxy 2 | .tags* 3 | *.sublime* 4 | *.swp 5 | bin/ 6 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/session.vim: -------------------------------------------------------------------------------- 1 | au BufWritePost *.go silent!make tags > /dev/null 2>&1 2 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.gitignore: -------------------------------------------------------------------------------- 1 | TAGS 2 | tags 3 | .*.swp 4 | tomlcheck/tomlcheck 5 | toml.test 6 | -------------------------------------------------------------------------------- /vendor/github.com/elazarl/goproxy/logger.go: -------------------------------------------------------------------------------- 1 | package goproxy 2 | 3 | type Logger interface { 4 | Printf(format string, v ...interface{}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/elazarl/goproxy/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/elazarl/goproxy 2 | 3 | require github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 4 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COMPATIBLE: -------------------------------------------------------------------------------- 1 | Compatible with TOML version 2 | [v0.4.0](https://github.com/toml-lang/toml/blob/v0.4.0/versions/en/toml-v0.4.0.md) 3 | 4 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/thekvs/microproxy 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/BurntSushi/toml v0.3.1 7 | github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d 8 | ) 9 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/BurntSushi/toml v0.3.1 2 | ## explicit 3 | github.com/BurntSushi/toml 4 | # github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d 5 | ## explicit 6 | github.com/elazarl/goproxy 7 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.1 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | - 1.6 9 | - tip 10 | install: 11 | - go install ./... 12 | - go get github.com/BurntSushi/toml-test 13 | script: 14 | - export PATH="$PATH:$HOME/gopath/bin" 15 | - make test 16 | -------------------------------------------------------------------------------- /microproxy.toml: -------------------------------------------------------------------------------- 1 | listen="127.0.0.1:3129" 2 | access_log="/tmp/microproxy.access.log" 3 | activity_log="/tmp/microproxy.error.log" 4 | allowed_connect_ports=[443, 80] 5 | auth_file="auth.txt" 6 | auth_type="basic" 7 | auth_realm="proxy" 8 | forwarded_for_header="on" 9 | allowed_networks=["127.0.0.1/32"] 10 | add_headers=[ 11 | ["X-Test-Header1", "yes"], 12 | ["X-Test-Header2", "no"] 13 | ] 14 | -------------------------------------------------------------------------------- /vendor/github.com/elazarl/goproxy/go.sum: -------------------------------------------------------------------------------- 1 | github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM= 2 | github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= 3 | github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc= 4 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | go install ./... 3 | 4 | test: install 5 | go test -v 6 | toml-test toml-test-decoder 7 | toml-test -encoder toml-test-encoder 8 | 9 | fmt: 10 | gofmt -w *.go */*.go 11 | colcheck *.go */*.go 12 | 13 | tags: 14 | find ./ -name '*.go' -print0 | xargs -0 gotags > TAGS 15 | 16 | push: 17 | git push origin master 18 | git push github master 19 | 20 | -------------------------------------------------------------------------------- /vendor/github.com/elazarl/goproxy/all.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | go test || exit 4 | for action in $@; do go $action; done 5 | 6 | mkdir -p bin 7 | find regretable examples/* ext/* -maxdepth 0 -type d | while read d; do 8 | (cd $d 9 | go build -o ../../bin/$(basename $d) 10 | find *_test.go -maxdepth 0 2>/dev/null|while read f;do 11 | for action in $@; do go $action; done 12 | go test 13 | break 14 | done) 15 | done 16 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.17 20 | 21 | - name: Build 22 | run: go build -v ./... 23 | 24 | - name: Test 25 | run: go test -v ./... 26 | -------------------------------------------------------------------------------- /basic_auth_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | ) 7 | 8 | func TestBasicAuthFile(t *testing.T) { 9 | file := bytes.NewBuffer([]byte("testuser:asdf\n")) 10 | auth, err := newBasicAuth(file) 11 | if err != nil { 12 | t.Errorf("couldn't create basic auth structure") 13 | } 14 | 15 | if valid := auth.validate(&BasicAuthData{ 16 | user: "testuser", 17 | password: "asdf", 18 | }); !valid { 19 | t.Errorf("password validation failed") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/encoding_types_1.1.go: -------------------------------------------------------------------------------- 1 | // +build !go1.2 2 | 3 | package toml 4 | 5 | // These interfaces were introduced in Go 1.2, so we add them manually when 6 | // compiling for Go 1.1. 7 | 8 | // TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here 9 | // so that Go 1.1 can be supported. 10 | type TextMarshaler interface { 11 | MarshalText() (text []byte, err error) 12 | } 13 | 14 | // TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined 15 | // here so that Go 1.1 can be supported. 16 | type TextUnmarshaler interface { 17 | UnmarshalText(text []byte) error 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/encoding_types.go: -------------------------------------------------------------------------------- 1 | // +build go1.2 2 | 3 | package toml 4 | 5 | // In order to support Go 1.1, we define our own TextMarshaler and 6 | // TextUnmarshaler types. For Go 1.2+, we just alias them with the 7 | // standard library interfaces. 8 | 9 | import ( 10 | "encoding" 11 | ) 12 | 13 | // TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here 14 | // so that Go 1.1 can be supported. 15 | type TextMarshaler encoding.TextMarshaler 16 | 17 | // TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined 18 | // here so that Go 1.1 can be supported. 19 | type TextUnmarshaler encoding.TextUnmarshaler 20 | -------------------------------------------------------------------------------- /conn.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | const ( 9 | DefaultReadTimeout = 15 * time.Minute 10 | DefaultWriteTimeout = 15 * time.Minute 11 | ) 12 | 13 | type TimedConn struct { 14 | net.Conn 15 | readTimeout time.Duration 16 | writeTimeout time.Duration 17 | } 18 | 19 | func (c TimedConn) Read(b []byte) (int, error) { 20 | err := c.Conn.SetReadDeadline(time.Now().Add(c.readTimeout)) 21 | if err != nil { 22 | return 0, err 23 | } 24 | 25 | return c.Conn.Read(b) 26 | } 27 | 28 | func (c TimedConn) Write(b []byte) (int, error) { 29 | err := c.Conn.SetWriteDeadline(time.Now().Add(c.writeTimeout)) 30 | if err != nil { 31 | return 0, err 32 | } 33 | 34 | return c.Conn.Write(b) 35 | } 36 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d h1:rtM8HsT3NG37YPjz8sYSbUSdElP9lUsQENYzJDZDUBE= 4 | github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= 5 | github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM= 6 | github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= 7 | github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc= 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Konstantin Sorokin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COPYING: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 TOML authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package toml provides facilities for decoding and encoding TOML configuration 3 | files via reflection. There is also support for delaying decoding with 4 | the Primitive type, and querying the set of keys in a TOML document with the 5 | MetaData type. 6 | 7 | The specification implemented: https://github.com/toml-lang/toml 8 | 9 | The sub-command github.com/BurntSushi/toml/cmd/tomlv can be used to verify 10 | whether a file is a valid TOML document. It can also be used to print the 11 | type of each key in a TOML document. 12 | 13 | Testing 14 | 15 | There are two important types of tests used for this package. The first is 16 | contained inside '*_test.go' files and uses the standard Go unit testing 17 | framework. These tests are primarily devoted to holistically testing the 18 | decoder and encoder. 19 | 20 | The second type of testing is used to verify the implementation's adherence 21 | to the TOML specification. These tests have been factored into their own 22 | project: https://github.com/BurntSushi/toml-test 23 | 24 | The reason the tests are in a separate project is so that they can be used by 25 | any implementation of TOML. Namely, it is language agnostic. 26 | */ 27 | package toml 28 | -------------------------------------------------------------------------------- /basic_auth.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/csv" 5 | "errors" 6 | "io" 7 | "os" 8 | ) 9 | 10 | type BasicAuthData struct { 11 | user string 12 | password string 13 | } 14 | 15 | type basicAuth struct { 16 | users map[string]string 17 | } 18 | 19 | func newBasicAuthFromFile(path string) (*basicAuth, error) { 20 | r, err := os.Open(path) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | return newBasicAuth(r) 26 | } 27 | 28 | func newBasicAuth(file io.Reader) (*basicAuth, error) { 29 | csvReader := csv.NewReader(file) 30 | csvReader.Comma = ':' 31 | csvReader.Comment = '#' 32 | csvReader.TrimLeadingSpace = true 33 | 34 | records, err := csvReader.ReadAll() 35 | if err != nil { 36 | return nil, err 37 | } 38 | 39 | h := &basicAuth{users: make(map[string]string)} 40 | 41 | for _, record := range records { 42 | if len(record) != 2 { 43 | return nil, errors.New("invalid basic auth file format") 44 | } 45 | h.users[record[0]] = record[1] 46 | } 47 | 48 | if len(h.users) == 0 { 49 | return nil, errors.New("auth file contains no data") 50 | } 51 | 52 | return h, nil 53 | } 54 | 55 | func (h *basicAuth) validate(authData *BasicAuthData) bool { 56 | realPassword, exists := h.users[authData.user] 57 | if !exists || realPassword != authData.password { 58 | return false 59 | } 60 | 61 | return true 62 | } 63 | -------------------------------------------------------------------------------- /proxy-digest-auth-test.py.bak: -------------------------------------------------------------------------------- 1 | import sys 2 | import urllib2 3 | import argparse 4 | 5 | 6 | def parse_args(): 7 | parser = argparse.ArgumentParser() 8 | parser.add_argument("--proxy", type=str, metavar="PROXY", required=True, 9 | help="address of a proxy server") 10 | parser.add_argument("--user", type=str, metavar="USER", required=True, 11 | help="proxy user") 12 | parser.add_argument("--password", type=str, metavar="PASSWORD", required=True, 13 | help="proxt user's password") 14 | parser.add_argument("--url", type=str, metavar="URL", required=True, 15 | help="URL to access") 16 | 17 | args = parser.parse_args() 18 | 19 | return args 20 | 21 | 22 | def main(): 23 | args = parse_args() 24 | 25 | password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() 26 | password_manager.add_password(None, args.url, args.user, args.password) 27 | auth_handler = urllib2.ProxyDigestAuthHandler(password_manager) 28 | proxy_support = urllib2.ProxyHandler({"http": args.proxy}) 29 | opener = urllib2.build_opener(proxy_support, auth_handler) 30 | urllib2.install_opener(opener) 31 | handle = urllib2.urlopen(args.url) 32 | page = handle.read() 33 | 34 | print(page), 35 | 36 | 37 | if __name__ == '__main__': 38 | try: 39 | main() 40 | except Exception as exc: 41 | print(exc) 42 | sys.exit(-1) 43 | -------------------------------------------------------------------------------- /vendor/github.com/elazarl/goproxy/responses.go: -------------------------------------------------------------------------------- 1 | package goproxy 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "net/http" 7 | ) 8 | 9 | // Will generate a valid http response to the given request the response will have 10 | // the given contentType, and http status. 11 | // Typical usage, refuse to process requests to local addresses: 12 | // 13 | // proxy.OnRequest(IsLocalHost()).DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request,*http.Response) { 14 | // return nil,NewResponse(r,goproxy.ContentTypeHtml,http.StatusUnauthorized, 15 | // `