Skip to content

Commit

Permalink
fix config.json problem and bring TLSHeaderLength config back
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Aug 10, 2023
1 parent c4f7d3c commit 7ebf968
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
65 changes: 37 additions & 28 deletions bepass/cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,59 @@ package main

import (
"bepass/cmd/core"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"log"
)

func loadConfig() (*core.Config, error) {
viper.SetConfigName("config")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
return nil, err
var configPath string

func loadConfig() {
if configPath != "" {
viper.SetConfigFile(configPath)
} else {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.SetConfigType("json")
}
viper.AutomaticEnv()

var config core.Config
if err := viper.Unmarshal(&config); err != nil {
return nil, err
err := viper.ReadInConfig()
if err != nil {
log.Fatal(err)
}
}

return &config, nil
func init() {
cobra.OnInitialize(loadConfig)
}

func main() {
var configPath string

config, err := loadConfig()
if err != nil {
panic(err)
}

rootCmd := &cobra.Command{
Use: "cli",
Short: "cli is a socks5 proxy server",
RunE: func(cmd *cobra.Command, args []string) error {
return core.RunServer(config, true)
Use: "Bepass",
Short: "Bepass is an Anti DPI and anti censorship proxy solution",
Run: func(cmd *cobra.Command, args []string) {
config := &core.Config{}
err := viper.Unmarshal(&config)
if err != nil {
log.Fatal(err)
}
err = core.RunServer(config, true)
if err != nil {
log.Fatal(err)
}
},
}

rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./config.json", "Path to configuration file")
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
viper.SetEnvPrefix("cli")
viper.AutomaticEnv()
err := viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
if err != nil {
log.Fatal(err)
}
viper.SetEnvPrefix("Bepass")

if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
err = rootCmd.Execute()
if err != nil {
log.Fatal(err)
}
}
1 change: 1 addition & 0 deletions bepass/cmd/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func RunServer(config *Config, captureCTRLC bool) error {
BeforeSniLength: config.SniChunksLength,
AfterSniLength: config.ChunksLengthAfterSni,
Delay: config.DelayBetweenChunks,
TLSHeaderLength: config.TLSHeaderLength,
}

workerConfig := server.WorkerConfig{
Expand Down
3 changes: 2 additions & 1 deletion bepass/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// ChunkConfig Constants for chunk lengths and delays.
type ChunkConfig struct {
TLSHeaderLength int
BeforeSniLength [2]int
AfterSniLength [2]int
Delay [2]int
Expand Down Expand Up @@ -177,7 +178,7 @@ func (s *Server) getSNBlock(data []byte) ([]byte, error) {
// getExtensionBlock finds the extension block given a raw TLS Client Hello.
func (s *Server) getExtensionBlock(data []byte) ([]byte, error) {
dataLen := len(data)
index := 5 + 38
index := s.ChunkConfig.TLSHeaderLength + 38

if dataLen <= index+1 {
return nil, fmt.Errorf("not enough bits to be a Client Hello")
Expand Down

0 comments on commit 7ebf968

Please sign in to comment.