yap

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2017 License: Apache-2.0 Imports: 34 Imported by: 1

README

[WIP] Yap - Yet Another Proxy powered by Golang

Linux Build Status Go Report Card Apache License Version 2.0

Yap is a HTTP1.1/HTTP2 proxy which forked and refactored from branch vps of Goproxy

Usage

First of all, download the latest Yap program from Release page according to your os and arch.

Prepare for Server
  • A domain: example.org
  • Certificate for the domain: example.org.cer
  • Key of the certificate for the domain: example.org.key
Create a config file yap.toml
[default]
reject_nil_sni = false

[[http2]]
listen = ":443"
# server name for http2 proxy
server_name = ["example.org"]
# cert file
cert_file = "example.org.cer"
# key file
key_file = "example.org.key"

[http]
listen = ":8088"
Start Yap Server
./yap yap.toml
Use Yap
1. Use HTTP2 Proxy in Chrome or Firefox

Create a new pac proxy configuration for you browser and setting:

function FindProxyForURL(url, host) {
  return "HTTPS example.org:443";
}
2. Use Yap in Proxy Chain
[http]
listen = "localhost:8088"
upstream_proxy = "https://example.org:443"
./yap yap.toml

Config HTTP Proxy localhost:8088 for you application.

Enjoy you life

Configuration

Yap supports multiple format configuration file such as toml, yaml and so on.

Section - default

TBD

Section - http2

http2 section contains a list for HTTP2 proxy.

  • network - optional

    The network must be a stream-oriented network:

    "tcp", "tcp4", "tcp6", "unix" or "unixpacket".

    Currently, only support tcp, tcp4, tcp6.

  • listen

    The syntax of listen is "host:port", e.g. ":443"

  • server_name

    The server name for http2 proxy, should be a list, such as ["example.org", "yap.example.org"]

  • proxy_fallback - optional

    The fallback URL for non-proxy request

  • pem - optional

    The pem file location for key pair contains cert and key, if pem is setting, the cert_file and key_file will be not used.

  • cert_file - optional

    The certificate file location

  • key_file - optional

    The key file location

  • upstream_proxy - optional

    The upstream proxy URL, used for proxy chain.

  • proxy_auth_method - optional

    The proxy authenticate method, currently contains two option: "pam", "htpasswd".

    Leave it blank for disable proxy authenticate

  • proxy_auth_htpasswd_path - optional

    The htpasswd file location.

    Only used when proxy_auth_method is set to htpasswd.

Section - http
  • network - optional

    The network must be a stream-oriented network:

    "tcp", "tcp4", "tcp6", "unix" or "unixpacket".

    Currently, only support tcp, tcp4, tcp6.

  • listen

    The syntax of listen is "host:port", e.g. ":443"

  • upstream_proxy - optional

    The upstream proxy URL, used for proxy chain.

  • proxy_auth_method - optional

    The proxy authenticate method, currently contains two option: "pam", "htpasswd".

    Leave it blank for disable proxy authenticate

  • proxy_auth_htpasswd_path - optional

    The htpasswd file location.

    Only used when proxy_auth_method is set to htpasswd.

Use Yap in Docker

Quick start:

docker run -d \
    -v /path/to/yap.toml:/yap.toml \
    -v /path/to/example.cert:/example.cert \
    -v /path/to/example.key:/example.key \
    -v /path/to/htpasswd:/htpasswd \
    -p 443:443 \
    -p 8088:8088 \
    yaproxy/yap

You can find more details from Yap in Docker hub.

Contributing

Contributions are welcome.

Copyright 2013-2017 Yaproxy

This software is licensed under the terms of the Apache License Version 2. See the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main()

Main loads config and start Yap

Types

type Authenticator

type Authenticator interface {
	Authenticate(username, password string) error
}

type CertManager

type CertManager struct {
	RejectNilSni bool
	// contains filtered or unexported fields
}

func (*CertManager) Add

func (cm *CertManager) Add(host string, certfile, keyfile string, pem string, cafile, capem string) error

func (*CertManager) GetCertificate

func (cm *CertManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

func (*CertManager) GetConfigForClient

func (cm *CertManager) GetConfigForClient(hello *tls.ClientHelloInfo) (*tls.Config, error)

func (*CertManager) HostPolicy

func (cm *CertManager) HostPolicy(_ context.Context, host string) error

type Config

type Config struct {
	Default struct {
		LogLevel     int
		DaemonStderr string
		RejectNilSni bool
	}
	HTTP2 []struct {
		Network string
		Listen  string

		ServerName []string

		KeyFile  string
		CertFile string
		PEM      string

		ClientAuthFile string
		ClientAuthPem  string

		UpstreamProxy string

		ProxyFallback         string
		DisableProxy          bool
		ProxyAuthMethod       string
		ProxyAuthHtpasswdPath string
	}
	HTTP struct {
		Network string
		Listen  string

		UpstreamProxy string

		ProxyAuthMethod       string
		ProxyAuthHtpasswdPath string
	}
}

Config contains the configuration for Yap

type FlushWriter

type FlushWriter struct {
	// contains filtered or unexported fields
}

FlushWriter is a wrapper for io.Writer. When call the Write method, FlushWriter will try to call Flush after call Write for the io.Writer

func (FlushWriter) Write

func (fw FlushWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

type HTTP2Handler

type HTTP2Handler struct {
	ServerNames  []string
	Fallback     *url.URL
	DisableProxy bool
	Dial         func(network, address string) (net.Conn, error)
	*http.Transport
	Authenticator
}

HTTP2Handler serves as a HTTP2 proxy

func (*HTTP2Handler) ProxyAuthorizationRequired

func (h *HTTP2Handler) ProxyAuthorizationRequired(rw http.ResponseWriter, req *http.Request)

ProxyAuthorizationRequired returns Proxy-Authenticate to the client

func (*HTTP2Handler) ServeHTTP

func (h *HTTP2Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler interface

type HTTPHandler

type HTTPHandler struct {
	Dial func(network, address string) (net.Conn, error)
	*http.Transport
	Authenticator
}

HTTPHandler serves as a HTTP proxy

func (*HTTPHandler) ProxyAuthorizationRequired

func (h *HTTPHandler) ProxyAuthorizationRequired(rw http.ResponseWriter, req *http.Request)

ProxyAuthorizationRequired returns Proxy-Authenticate to the client

func (*HTTPHandler) ServeHTTP

func (h *HTTPHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler interface

type HtpasswdFileAuth

type HtpasswdFileAuth struct {
	CacheSize uint
	FilePath  string
	// contains filtered or unexported fields
}

func (*HtpasswdFileAuth) Authenticate

func (h *HtpasswdFileAuth) Authenticate(username, password string) error

type MultiSNHandler

type MultiSNHandler struct {
	ServerNames []string
	Handlers    map[string]http.Handler
}

MultiSNHandler contains multiple server name and their handler

func (*MultiSNHandler) ServeHTTP

func (h *MultiSNHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler interface

type SimplePAM

type SimplePAM struct {
	CacheSize uint
	// contains filtered or unexported fields
}

func (*SimplePAM) Authenticate

func (p *SimplePAM) Authenticate(username, password string) error

type TCPListener

type TCPListener struct {
	*net.TCPListener
}

TCPListener customize net.TCPListener for Yap

func (TCPListener) Accept

func (ln TCPListener) Accept() (c net.Conn, err error)

Accept implements Accept interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL