@cryptotaxi247 / kubo / commits / e37fefdfd

daemon option to optionally disable secio

This commit adds an option to turn off all encryption. This is a mode used for tests, debugging, achieving protocol implementation interop, learning about how the protocol works (nc ftw), and worst case networks which _demand_ to be able to snoop on all the traffic. (sadly, there are some private intranets like this...). (We should consider at least _signing_ all this traffic.) Because of the severity of this sort of thing, this is an all-or-nothing deal. Either encryption is ON or OFF _fully_. This way, partially unencrypted nodes cannot be accidentally left running without the user's understanding. Nodes without encrypted connections will simply not be able to speak to any of the global bootstrap nodes, or anybody in the public network. License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>

Juan Batiz-Benet committed Jun 19, 2015 at 03:05 UTC e37fefdfd305d96106c177e9d4ba2f3c899c9d62
4 files changed +25 -6
cmd/ipfs/daemon.go
+15 -4
@@ -19,6 +19,7 @@ import (
19 commands "github.com/ipfs/go-ipfs/core/commands"
20 corehttp "github.com/ipfs/go-ipfs/core/corehttp"
21 "github.com/ipfs/go-ipfs/core/corerouting"
22 + conn "github.com/ipfs/go-ipfs/p2p/net/conn"
23 peer "github.com/ipfs/go-ipfs/p2p/peer"
24 fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
25 util "github.com/ipfs/go-ipfs/util"
@@ -32,7 +33,8 @@ const (
33 writableKwd = "writable"
34 ipfsMountKwd = "mount-ipfs"
35 ipnsMountKwd = "mount-ipns"
35 - unrestrictedApiAccess = "unrestricted-api"
36 + unrestrictedApiAccessKwd = "unrestricted-api"
37 + unencryptTransportKwd = "disable-transport-encryption"
38 // apiAddrKwd = "address-api"
39 // swarmAddrKwd = "address-swarm"
40 )
@@ -76,7 +78,8 @@ the port as you would other services or database (firewall, authenticated proxy,
78 cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
79 cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"),
80 cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"),
79 - cmds.BoolOption(unrestrictedApiAccess, "Allow API access to unlisted hashes"),
81 + cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes"),
82 + cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"),
83
84 // TODO: add way to override addresses. tricky part: updating the config if also --init.
85 // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
@@ -110,6 +113,14 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
113 }
114 }()
115
116 + // check transport encryption flag.
117 + unencrypted, _, _ := req.Option(unencryptTransportKwd).Bool()
118 + if unencrypted {
119 + log.Warningf(`Running with --%s: All connections are UNENCRYPTED.
120 + You will not be able to connect to regular encrypted networks.`, unencryptTransportKwd)
121 + conn.EncryptConnections = false
122 + }
123 +
124 // first, whether user has provided the initialization flag. we may be
125 // running in an uninitialized state.
126 initialize, _, err := req.Option(initOptionKwd).Bool()
@@ -259,9 +270,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
270 apiMaddr = apiLis.Multiaddr()
271 fmt.Printf("API server listening on %s\n", apiMaddr)
272
262 - unrestricted, _, err := req.Option(unrestrictedApiAccess).Bool()
273 + unrestricted, _, err := req.Option(unrestrictedApiAccessKwd).Bool()
274 if err != nil {
264 - return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccess, err), nil
275 + return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
276 }
277
278 apiGw := corehttp.NewGateway(corehttp.GatewayConfig{
p2p/net/conn/dial.go
+1 -1
@@ -60,7 +60,7 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) (
60 return
61 }
62
63 - if d.PrivateKey == nil {
63 + if d.PrivateKey == nil || EncryptConnections == false {
64 log.Warning("dialer %s dialing INSECURELY %s at %s!", d, remote, raddr)
65 connOut = c
66 return
p2p/net/conn/interface.go
+8
@@ -93,3 +93,11 @@ type Listener interface {
93 // Any blocked Accept operations will be unblocked and return errors.
94 Close() error
95 }
96 +
97 +// EncryptConnections is a global parameter because it should either be
98 +// enabled or _completely disabled_. I.e. a node should only be able to talk
99 +// to proper (encrypted) networks if it is encrypting all its transports.
100 +// Running a node with disabled transport encryption is useful to debug the
101 +// protocols, achieve implementation interop, or for private networks which
102 +// -- for whatever reason -- _must_ run unencrypted.
103 +var EncryptConnections = true
p2p/net/conn/listen.go
+1 -1
@@ -107,7 +107,7 @@ func (l *listener) Accept() (net.Conn, error) {
107 return nil, err
108 }
109
110 - if l.privk == nil {
110 + if l.privk == nil || EncryptConnections == false {
111 log.Warning("listener %s listening INSECURELY!", l)
112 return c, nil
113 }