VERSION    uint32
	VER_STRING string
	DEBUG      bool
)

var (
	// socks5 exceptions
	INVALID_SOCKS5_HEADER  = exception.New(0xff, "Invalid socks5 header")
	INVALID_SOCKS5_REQUEST = exception.New(0x07, "Invalid socks5 request")
	GENERAL_FAILURE        = exception.New(0x01, "General failure")
	HOST_UNREACHABLE       = exception.New(0x04, "Host is unreachable")
)

var (
	// D5 exceptions
	INVALID_D5PARAMS     = exception.NewW("Invalid D5Params")
	D5SER_UNREACHABLE    = exception.NewW("D5Server is unreachable")
	VALIDATION_FAILED    = exception.NewW("Validation failed")
	NEGOTIATION_FAILED   = exception.NewW("Negotiation failed")
	DATATUN_SESSION      = exception.NewW("DT")
	INCONSISTENT_HASH    = exception.NewW("Inconsistent hash")
	INCOMPATIBLE_VERSION = exception.NewW("Incompatible version")
)

func ThrowErr(e interface{}) {
	if e != nil {
		panic(e)
	}
}

func ThrowIf(condition bool, e interface{}) {
示例#2
0
文件: config.go 项目: hangim/deblocus
	"regexp"
	"sort"
	"strconv"
	"strings"
)

const (
	SER_KEY_TYPE         = "deblocus/SERVER-PRIVATEKEY"
	USER_CREDENTIAL_TYPE = "deblocus/CLIENT-CREDENTIAL"
	WORD_d5p             = "D5P"
	WORD_provider        = "Provider"
	SIZE_UNIT            = "BKMG"
)

var (
	FILE_NOT_FOUND          = exception.NewW("File not found")
	FILE_EXISTS             = exception.NewW("File is already exists")
	INVALID_D5P_FRAGMENT    = exception.NewW("Invalid d5p fragment")
	INVALID_D5C_FILE        = exception.NewW("Invalid d5c file format")
	INVALID_D5S_FILE        = exception.NewW("Invalid d5s file format")
	UNRECOGNIZED_SYMBOLS    = exception.NewW("Unrecognized symbols")
	UNRECOGNIZED_DIRECTIVES = exception.NewW("Unrecognized directives")
	LOCAL_BIND_ERROR        = exception.NewW("Local bind error")
	CONF_MISS               = exception.NewW("Missed config")
	CONF_ERROR              = exception.NewW("Error config")
)

// client
type D5ClientConf struct {
	Listen     string `importable:":9009"`
	Verbose    int    `importable:"1"`
package auth

import (
	"bufio"
	"github.com/spance/deblocus/exception"
	"os"
	"strings"
)

var (
	NO_SUCH_USER          = exception.NewW("No such user")
	AUTH_FAILED           = exception.NewW("Auth failed")
	UNIMPLEMENTED_AUTHSYS = exception.NewW("Unimplemented authsys")
	INVALID_AUTH_CONF     = exception.NewW("Invalid Auth config")
	INVALID_AUTH_PARAMS   = exception.NewW("Invalid Auth params")
)

type AuthSys interface {
	Authenticate(input []byte) (bool, error)
	AddUser(user *User) error
	UserInfo(user string) (*User, error)
}

type User struct {
	Name string
	Pass string
}

func GetAuthSysImpl(proto string) (AuthSys, error) {
	if strings.HasPrefix(proto, "file://") {
		return NewFileAuthSys(proto[7:])
import (
	"crypto/aes"
	"crypto/cipher"
	"crypto/md5"
	"crypto/rand"
	"crypto/rc4"
	"crypto/rsa"
	"crypto/sha1"
	"encoding/binary"
	"github.com/monnand/dhkx"
	"github.com/spance/deblocus/exception"
)

var (
	UNSUPPORTED_CIPHER = exception.NewW("Unsupported cipher")
)

type cipherBuilder func(k, iv []byte) *Cipher

type cipherDecr struct {
	keyLen  int
	builder cipherBuilder
}

var availableCiphers = map[string]*cipherDecr{
	"RC4":       &cipherDecr{16, newRC4},
	"AES128CFB": &cipherDecr{16, newAES_CFB},
	"AES256CFB": &cipherDecr{32, newAES_CFB},
}