Skip to content

Commit

Permalink
notify user if QPPCount/qpp-count is not a prime
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jul 15, 2024
1 parent a956bb3 commit 96ef4c9
Show file tree
Hide file tree
Showing 29 changed files with 2,607 additions and 10 deletions.
14 changes: 10 additions & 4 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"math/big"
"math/rand"
"net"
"net/http"
Expand All @@ -14,6 +15,7 @@ import (

"golang.org/x/crypto/pbkdf2"

"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/urfave/cli"
kcp "github.com/xtaci/kcp-go/v5"
Expand Down Expand Up @@ -183,8 +185,8 @@ func main() {
},
cli.IntFlag{
Name: "QPPCount",
Value: 64,
Usage: "the number of pads to use for QPP: The more pads you use, the more secure the encryption. Each pad requires 256 bytes.",
Value: 61,
Usage: "the prime number of pads to use for QPP: The more pads you use, the more secure the encryption. Each pad requires 256 bytes.",
},
cli.IntFlag{
Name: "conn",
Expand Down Expand Up @@ -425,12 +427,16 @@ func main() {
if config.QPP {
minSeedLength := qpp.QPPMinimumSeedLength(8)
if len(config.Key) < minSeedLength {
log.Printf("QPP Warning: 'key' has size of %d bytes, required %d bytes at least", len(config.Key), minSeedLength)
color.Red("QPP Warning: 'key' has size of %d bytes, required %d bytes at least", len(config.Key), minSeedLength)
}

minPads := qpp.QPPMinimumPads(8)
if config.QPPCount < minPads {
log.Printf("QPP Warning: QPPCount %d, required %d at least", config.QPPCount, minPads)
color.Red("QPP Warning: QPPCount %d, required %d at least", config.QPPCount, minPads)
}

if new(big.Int).GCD(nil, nil, big.NewInt(int64(config.QPPCount)), big.NewInt(8)).Int64() != 1 {
color.Red("QPP Warning: QPPCount %d, choose a prime number for security", config.QPPCount)
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"key": "PASSWORD",
"crypt": "aes-128",
"qpp":true,
"qpp-count":64,
"qpp-count":61,
"mode": "fast3",
"mtu": 1400,
"sndwnd": 128,
Expand Down
2 changes: 1 addition & 1 deletion examples/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"key": "PASSWORD",
"crypt": "aes-128",
"qpp":true,
"qpp-count":64,
"qpp-count":61,
"mode": "fast3",
"mtu": 1400,
"sndwnd": 2048,
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ require (
require (
github.com/coreos/go-iptables v0.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/klauspost/reedsolomon v1.12.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/templexxx/cpu v0.1.0 // indirect
github.com/templexxx/xorsimd v0.4.2 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -39,6 +41,11 @@ github.com/klauspost/reedsolomon v1.12.1 h1:NhWgum1efX1x58daOBGCFWcxtEhOhXKKl1HA
github.com/klauspost/reedsolomon v1.12.1/go.mod h1:nEi5Kjb6QqtbofI6s+cbG/j1da11c96IBYBSnVGtuBs=
github.com/klauspost/reedsolomon v1.12.2 h1:TC0hlL/tTRxiMNnqHCzKsY11E0fIIKGCoZ2vQoPKIEM=
github.com/klauspost/reedsolomon v1.12.2/go.mod h1:nEi5Kjb6QqtbofI6s+cbG/j1da11c96IBYBSnVGtuBs=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -134,7 +141,9 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
Expand Down
14 changes: 10 additions & 4 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"math/big"
"math/rand"
"net"
"net/http"
Expand All @@ -15,6 +16,7 @@ import (

"golang.org/x/crypto/pbkdf2"

"github.com/fatih/color"
"github.com/urfave/cli"
kcp "github.com/xtaci/kcp-go/v5"
"github.com/xtaci/kcptun/generic"
Expand Down Expand Up @@ -215,8 +217,8 @@ func main() {
},
cli.IntFlag{
Name: "QPPCount",
Value: 64,
Usage: "the number of pads to use for QPP: The more pads you use, the more secure the encryption. Each pad requires 256 bytes.",
Value: 61,
Usage: "the prime number of pads to use for QPP: The more pads you use, the more secure the encryption. Each pad requires 256 bytes.",
},

cli.StringFlag{
Expand Down Expand Up @@ -424,12 +426,16 @@ func main() {
if config.QPP {
minSeedLength := qpp.QPPMinimumSeedLength(8)
if len(config.Key) < minSeedLength {
log.Printf("QPP Warning: 'key' has size of %d bytes, required %d bytes at least", len(config.Key), minSeedLength)
color.Red("QPP Warning: 'key' has size of %d bytes, required %d bytes at least", len(config.Key), minSeedLength)
}

minPads := qpp.QPPMinimumPads(8)
if config.QPPCount < minPads {
log.Printf("QPP Warning: QPPCount %d, required %d at least", config.QPPCount, minPads)
color.Red("QPP Warning: QPPCount %d, required %d at least", config.QPPCount, minPads)
}

if new(big.Int).GCD(nil, nil, big.NewInt(int64(config.QPPCount)), big.NewInt(8)).Int64() != 1 {
color.Red("QPP Warning: QPPCount %d, choose a prime number for security", config.QPPCount)
}
}
// parameters check
Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/fatih/color/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

176 changes: 176 additions & 0 deletions vendor/github.com/fatih/color/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96ef4c9

Please sign in to comment.