Add TLS Options
This commit is contained in:
@ -22,6 +22,6 @@ func (c *Conf) SetClientDest(label ...string) {
|
||||
if v, ok := c.Get("destination", label...); ok {
|
||||
c.ClientDest = v
|
||||
} else {
|
||||
c.ClientDest = v
|
||||
c.ClientDest = ""
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package i2ptunconf
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log"
|
||||
)
|
||||
|
||||
// GetPort443 takes an argument and a default. If the argument differs from the
|
||||
// default, the argument is always returned. If the argument and default are
|
||||
// the same and the key exists, the key is returned. If the key is absent, the
|
||||
@ -25,3 +30,80 @@ func (c *Conf) SetTargetPort443(label ...string) {
|
||||
c.TargetForPort443 = ""
|
||||
}
|
||||
}
|
||||
|
||||
// Get
|
||||
func (c *Conf) GetUseTLS(arg, def bool, label ...string) bool {
|
||||
if arg != def {
|
||||
return arg
|
||||
}
|
||||
if c.Config == nil {
|
||||
return arg
|
||||
}
|
||||
if x, o := c.GetBool("usetls", label...); o {
|
||||
return x
|
||||
}
|
||||
return arg
|
||||
}
|
||||
|
||||
// SetAllowZeroHopOut sets the config to allow zero-hop tunnels
|
||||
func (c *Conf) SetUseTLS(label ...string) {
|
||||
if v, ok := c.GetBool("usetls", label...); ok {
|
||||
c.UseTLS = v
|
||||
} else {
|
||||
c.UseTLS = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetTLSConfig
|
||||
func (c *Conf) GetTLSConfig(arg, def string, label ...string) string {
|
||||
if arg != def {
|
||||
return arg
|
||||
}
|
||||
if c.Config == nil {
|
||||
return arg
|
||||
}
|
||||
if x, o := c.Get("cert", label...); o {
|
||||
return x
|
||||
}
|
||||
return arg
|
||||
}
|
||||
|
||||
// SetClientDest sets the key name from the config file
|
||||
func (c *Conf) SetTLSConfig(label ...string) {
|
||||
if v, ok := c.Get("cert", label...); ok {
|
||||
c.Cert = v
|
||||
} else {
|
||||
c.Cert = ""
|
||||
}
|
||||
}
|
||||
|
||||
// GetTLSConfig
|
||||
func (c *Conf) GetTLSConfigPem(arg, def string, label ...string) string {
|
||||
if arg != def {
|
||||
return arg
|
||||
}
|
||||
if c.Config == nil {
|
||||
return arg
|
||||
}
|
||||
if x, o := c.Get("pem", label...); o {
|
||||
return x
|
||||
}
|
||||
return arg
|
||||
}
|
||||
|
||||
// SetClientDest sets the key name from the config file
|
||||
func (c *Conf) SetTLSConfigPem(label ...string) {
|
||||
if v, ok := c.Get("pem", label...); ok {
|
||||
c.Pem = v
|
||||
} else {
|
||||
c.Pem = ""
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Conf) TLSConfig() *tls.Config {
|
||||
cert, err := tls.LoadX509KeyPair(c.Cert, c.Pem)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return &tls.Config{Certificates: []tls.Certificate{cert}}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package i2ptunconf
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
// "crypto/tls"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@ -68,7 +68,9 @@ type Conf struct {
|
||||
UserName string `default:""`
|
||||
Password string `default:""`
|
||||
UseTLS bool `default:false`
|
||||
TLSConf *tls.Config
|
||||
Cert string `default:""`
|
||||
Pem string `default:""`
|
||||
//TLSConf *tls.Config
|
||||
LoadedKeys i2pkeys.I2PKeys
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
package samtunnelhandler
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DefaultCSS() string {
|
||||
return `.server {
|
||||
|
@ -361,7 +361,7 @@ func (f *SAMForwarder) Serve() error {
|
||||
log.Println("SAM Listener created,", f.Base32())
|
||||
log.Println("Human-readable hash:\n ", f.Base32Readable())
|
||||
if f.Conf.UseTLS {
|
||||
f.publishListen = tls.NewListener(publishListen, f.Conf.TLSConf)
|
||||
f.publishListen = tls.NewListener(publishListen, f.Conf.TLSConfig())
|
||||
} else {
|
||||
f.publishListen = publishListen
|
||||
}
|
||||
|
Reference in New Issue
Block a user