Browse Source

Respect OTP length key from configuration, set default to 12

Ettore Di Giacinto 4 years ago
parent
commit
139c93d42a
3 changed files with 7 additions and 2 deletions
  1. 5 1
      pkg/discovery/dht.go
  2. 1 1
      pkg/edgevpn/connection.go
  3. 1 0
      pkg/edgevpn/edgevpn.go

+ 5 - 1
pkg/discovery/dht.go

@@ -38,7 +38,7 @@ func (d *DHT) Option(ctx context.Context) func(c *libp2p.Config) error {
 }
 func (d *DHT) Rendezvous() string {
 	if d.OTPKey != "" {
-		totp := gotp.NewTOTP(d.OTPKey, 6, d.OTPInterval, nil)
+		totp := gotp.NewTOTP(d.OTPKey, d.KeyLength, d.OTPInterval, nil)
 
 		//totp := gotp.NewDefaultTOTP(d.OTPKey)
 		rv := totp.Now()
@@ -65,6 +65,10 @@ func (d *DHT) startDHT(ctx context.Context, h host.Host) (*dht.IpfsDHT, error) {
 }
 
 func (d *DHT) Run(c *zap.Logger, ctx context.Context, host host.Host) error {
+	if d.KeyLength == 0 {
+		d.KeyLength = 12
+	}
+
 	d.console = c
 	if len(d.BootstrapPeers) == 0 {
 		d.BootstrapPeers = dht.DefaultBootstrapPeers

+ 1 - 1
pkg/edgevpn/connection.go

@@ -87,7 +87,7 @@ func (e *EdgeVPN) genHost(ctx context.Context) (host.Host, error) {
 }
 
 func (e *EdgeVPN) sealkey() string {
-	return gotp.NewTOTP(e.config.ExchangeKey, 6, e.config.SealKeyInterval, nil).Now()
+	return gotp.NewTOTP(e.config.ExchangeKey, e.config.SealKeyLength, e.config.SealKeyInterval, nil).Now()
 }
 
 func (e *EdgeVPN) handleEvents(ctx context.Context) {

+ 1 - 0
pkg/edgevpn/edgevpn.go

@@ -35,6 +35,7 @@ func New(p ...Option) *EdgeVPN {
 		StreamHandlers:           make(map[protocol.ID]StreamHandler),
 		LedgerAnnounceTime:       5 * time.Second,
 		LedgerSyncronizationTime: 5 * time.Second,
+		SealKeyLength:            12,
 	}
 	c.Apply(p...)