server

package
v0.0.0-...-db591cf Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

package cache implements a really primitive cache that associates expiring values with string keys. This cache never clears itself out.

Package keyman provides convenience APIs around Go's built-in crypto APIs.

Index

Constants

View Source
const (
	PEM_HEADER_PRIVATE_KEY = "RSA PRIVATE KEY"
	PEM_HEADER_PUBLIC_KEY  = "RSA PRIVATE KEY"
	PEM_HEADER_CERTIFICATE = "CERTIFICATE"
)
View Source
const (
	Version   = "1.1"
	ONE_DAY   = 24 * time.Hour
	TWO_WEEKS = ONE_DAY * 14
	ONE_MONTH = 1
	ONE_YEAR  = 1
)

Variables

This section is empty.

Functions

func MyCopy

func MyCopy(src io.Reader, dst io.Writer, ch chan<- error)

func ParseReq

func ParseReq(b []byte) (*http.Request, error)

func PoolContainingCerts

func PoolContainingCerts(certs ...string) (*x509.CertPool, error)

PoolContainingCerts constructs a CertPool containing all of the given certs (PEM encoded).

func Start

func Start(conf *config.Cfg, tlsConfig *config.TlsConfig, wg *sync.WaitGroup)

func Transport

func Transport(conn1, conn2 net.Conn) (err error)

两个io口的连接

Types

type Cache

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

Cache is a cache for binary data

func NewCache

func NewCache() *Cache

NewCache creates a new Cache

func (*Cache) Get

func (cache *Cache) Get(key string) (val interface{}, found bool)

Get returns the currently cached value for the given key, as long as it hasn't expired. If the key was never set, or has expired, found will be false.

func (*Cache) Set

func (cache *Cache) Set(key string, data interface{}, ttl time.Duration)

Set sets a value in the cache with an expiration of now + ttl.

type Certificate

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

Certificate is a convenience wrapper for x509.Certificate

func LoadCertificateFromFile

func LoadCertificateFromFile(filename string) (*Certificate, error)

LoadCertificateFromFile loads a Certificate from a PEM-encoded file

func LoadCertificateFromPEMBytes

func LoadCertificateFromPEMBytes(pemBytes []byte) (*Certificate, error)

LoadCertificateFromPEMBytes loads a Certificate from a byte array in PEM format

func LoadCertificateFromX509

func LoadCertificateFromX509(cert *x509.Certificate) (*Certificate, error)

LoadCertificateFromX509 loads a Certificate from an x509.Certificate

func (*Certificate) ExpiresBefore

func (cert *Certificate) ExpiresBefore(time time.Time) bool

func (*Certificate) PEMEncoded

func (cert *Certificate) PEMEncoded() (pemBytes []byte)

PEMEncoded encodes the Certificate in PEM

func (*Certificate) PoolContainingCert

func (cert *Certificate) PoolContainingCert() *x509.CertPool

PoolContainingCert creates a pool containing this cert.

func (*Certificate) WriteToDERFile

func (cert *Certificate) WriteToDERFile(filename string) (err error)

WriteToDERFile writes the DER-encoded Certificate to a file.

func (*Certificate) WriteToFile

func (cert *Certificate) WriteToFile(filename string) (err error)

WriteToFile writes the PEM-encoded Certificate to a file.

func (*Certificate) WriteToTempFile

func (cert *Certificate) WriteToTempFile() (name string, err error)

func (*Certificate) X509

func (cert *Certificate) X509() *x509.Certificate

X509 returns the x509 certificate underlying this Certificate

type HandlerWrapper

type HandlerWrapper struct {
	MyConfig *config.Cfg
	// contains filtered or unexported fields
}

func InitConfig

func InitConfig(conf *config.Cfg, tlsConfig *config.TlsConfig) (*HandlerWrapper, error)

func (*HandlerWrapper) DumpHTTPAndHTTPs

func (hw *HandlerWrapper) DumpHTTPAndHTTPs(resp http.ResponseWriter, req *http.Request)

func (*HandlerWrapper) FakeCertForName

func (hw *HandlerWrapper) FakeCertForName(name string) (cert *tls.Certificate, err error)

func (*HandlerWrapper) Forward

func (hw *HandlerWrapper) Forward(resp http.ResponseWriter, req *http.Request, raddr string)

func (*HandlerWrapper) GenerateCertForClient

func (hw *HandlerWrapper) GenerateCertForClient() (err error)

func (*HandlerWrapper) InterceptHTTPs

func (hw *HandlerWrapper) InterceptHTTPs(resp http.ResponseWriter, req *http.Request)

func (*HandlerWrapper) ServeHTTP

func (hw *HandlerWrapper) ServeHTTP(resp http.ResponseWriter, req *http.Request)

type PrivateKey

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

PrivateKey is a convenience wrapper for rsa.PrivateKey

func GeneratePK

func GeneratePK(bits int) (key *PrivateKey, err error)

GeneratePK generates a PrivateKey with a specified size in bits.

func LoadPKFromFile

func LoadPKFromFile(filename string) (key *PrivateKey, err error)

LoadPKFromFile loads a PEM-encoded PrivateKey from a file

func (*PrivateKey) Certificate

func (key *PrivateKey) Certificate(template *x509.Certificate, issuer *Certificate) (*Certificate, error)

Certificate() generates a certificate for the Public Key of the given PrivateKey based on the given template and signed by the given issuer. If issuer is nil, the generated certificate is self-signed.

func (*PrivateKey) CertificateForKey

func (key *PrivateKey) CertificateForKey(template *x509.Certificate, issuer *Certificate, publicKey interface{}) (*Certificate, error)

CertificateForKey() generates a certificate for the given Public Key based on the given template and signed by the given issuer. If issuer is nil, the generated certificate is self-signed.

func (*PrivateKey) PEMEncoded

func (key *PrivateKey) PEMEncoded() (pemBytes []byte)

PEMEncoded encodes the PrivateKey in PEM

func (*PrivateKey) TLSCertificateFor

func (key *PrivateKey) TLSCertificateFor(
	organization string,
	name string,
	validUntil time.Time,
	isCA bool,
	issuer *Certificate) (cert *Certificate, err error)

TLSCertificateFor generates a certificate useful for TLS use based on the given parameters. These certs are usable for key encipherment and digital signatures.

organization: the org name for the cert.
name:         used as the common name for the cert.  If name is an IP
              address, it is also added as an IP SAN.
validUntil:   time at which certificate expires
isCA:         whether or not this cert is a CA
issuer:       the certificate which is issuing the new cert.  If nil, the
              new cert will be a self-signed CA certificate.

func (*PrivateKey) WriteToFile

func (key *PrivateKey) WriteToFile(filename string) (err error)

WriteToFile writes the PEM-encoded PrivateKey to the given file

Jump to

Keyboard shortcuts

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