fully automatic onionv3 reseeds
This commit is contained in:
@@ -2,15 +2,18 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/MDrollette/i2p-tools/reseed"
|
"github.com/MDrollette/i2p-tools/reseed"
|
||||||
"github.com/cretz/bine/tor"
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/cretz/bine/tor"
|
||||||
|
"github.com/cretz/bine/torutil/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewReseedCommand() cli.Command {
|
func NewReseedCommand() cli.Command {
|
||||||
@@ -31,6 +34,15 @@ func NewReseedCommand() cli.Command {
|
|||||||
Name: "onion",
|
Name: "onion",
|
||||||
Usage: "Present an onionv3 address",
|
Usage: "Present an onionv3 address",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "singleOnion",
|
||||||
|
Usage: "Use a faster, but non-anonymous single-hop onion",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "onionKey",
|
||||||
|
Value: "onion.key",
|
||||||
|
Usage: "Specify a path to an ed25519 private key for onion",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "key",
|
Name: "key",
|
||||||
Usage: "Path to your su3 signing private key",
|
Usage: "Path to your su3 signing private key",
|
||||||
@@ -186,13 +198,49 @@ func reseedAction(c *cli.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Bool("onion") {
|
if c.Bool("onion") {
|
||||||
port, err := strconv.Atoi(c.String("port"))
|
port, err := strconv.Atoi(c.String("port"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err.Error())
|
log.Fatalln(err.Error())
|
||||||
}
|
}
|
||||||
log.Fatalln(server.ListenAndServeOnion(nil, &tor.ListenConf{LocalPort: port, RemotePorts: []int{80}}))
|
if _, err := os.Stat(c.String("onionKey")); err == nil {
|
||||||
}else if tlsHost != "" && tlsCert != "" && tlsKey != "" {
|
ok, err := ioutil.ReadFile(c.String("onionKey"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err.Error())
|
||||||
|
} else {
|
||||||
|
log.Fatalln(
|
||||||
|
server.ListenAndServeOnion(
|
||||||
|
nil,
|
||||||
|
&tor.ListenConf{
|
||||||
|
LocalPort: port,
|
||||||
|
Key: ed25519.PrivateKey(ok),
|
||||||
|
RemotePorts: []int{80},
|
||||||
|
Version3: true,
|
||||||
|
NonAnonymous: c.Bool("singleOnion"),
|
||||||
|
DiscardKey: false,
|
||||||
|
},
|
||||||
|
c.String("onionKey"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
log.Fatalln(
|
||||||
|
server.ListenAndServeOnion(
|
||||||
|
nil,
|
||||||
|
&tor.ListenConf{
|
||||||
|
LocalPort: port,
|
||||||
|
RemotePorts: []int{80},
|
||||||
|
Version3: true,
|
||||||
|
NonAnonymous: c.Bool("singleOnion"),
|
||||||
|
DiscardKey: false,
|
||||||
|
},
|
||||||
|
c.String("onionKey"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if tlsHost != "" && tlsCert != "" && tlsKey != "" {
|
||||||
log.Printf("HTTPS server started on %s\n", server.Addr)
|
log.Printf("HTTPS server started on %s\n", server.Addr)
|
||||||
log.Fatalln(server.ListenAndServeTLS(tlsCert, tlsKey))
|
log.Fatalln(server.ListenAndServeTLS(tlsCert, tlsKey))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cretz/bine/tor"
|
"github.com/cretz/bine/tor"
|
||||||
|
"github.com/cretz/bine/torutil/ed25519"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/justinas/alice"
|
"github.com/justinas/alice"
|
||||||
"gopkg.in/throttled/throttled.v2"
|
"gopkg.in/throttled/throttled.v2"
|
||||||
@@ -114,7 +116,7 @@ func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
|
|||||||
return srv.Serve(tlsListener)
|
return srv.Serve(tlsListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ListenAndServeOnion(startConf *tor.StartConf, listenConf *tor.ListenConf) error {
|
func (srv *Server) ListenAndServeOnion(startConf *tor.StartConf, listenConf *tor.ListenConf, onionKey string) error {
|
||||||
log.Println("Starting and registering onion service, please wait a couple of minutes...")
|
log.Println("Starting and registering onion service, please wait a couple of minutes...")
|
||||||
tor, err := tor.Start(nil, startConf)
|
tor, err := tor.Start(nil, startConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,6 +130,10 @@ func (srv *Server) ListenAndServeOnion(startConf *tor.StartConf, listenConf *tor
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = ioutil.WriteFile(onionKey, []byte(srv.OnionListener.Key.(ed25519.KeyPair).PrivateKey()), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
log.Printf("Onionv3 server started on http://%v.onion\n", srv.OnionListener.ID)
|
log.Printf("Onionv3 server started on http://%v.onion\n", srv.OnionListener.ID)
|
||||||
return srv.Serve(srv.OnionListener)
|
return srv.Serve(srv.OnionListener)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user