obfs.go 909 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package obfs
  2. import (
  3. "errors"
  4. "fmt"
  5. "net"
  6. )
  7. var (
  8. errTLS12TicketAuthIncorrectMagicNumber = errors.New("tls1.2_ticket_auth incorrect magic number")
  9. errTLS12TicketAuthTooShortData = errors.New("tls1.2_ticket_auth too short data")
  10. errTLS12TicketAuthHMACError = errors.New("tls1.2_ticket_auth hmac verifying failed")
  11. )
  12. type authData struct {
  13. clientID [32]byte
  14. }
  15. type Obfs interface {
  16. StreamConn(net.Conn) net.Conn
  17. }
  18. type obfsCreator func(b *Base) Obfs
  19. var obfsList = make(map[string]struct {
  20. overhead int
  21. new obfsCreator
  22. })
  23. func register(name string, c obfsCreator, o int) {
  24. obfsList[name] = struct {
  25. overhead int
  26. new obfsCreator
  27. }{overhead: o, new: c}
  28. }
  29. func PickObfs(name string, b *Base) (Obfs, int, error) {
  30. if choice, ok := obfsList[name]; ok {
  31. return choice.new(b), choice.overhead, nil
  32. }
  33. return nil, 0, fmt.Errorf("Obfs %s not supported", name)
  34. }