From e37fefdfd305d96106c177e9d4ba2f3c899c9d62 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet <juan@benet.ai> Date: Fri, 19 Jun 2015 03:05:50 -0700 Subject: [PATCH] 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> --- cmd/ipfs/daemon.go | 19 +++++++++++++++---- p2p/net/conn/dial.go | 2 +- p2p/net/conn/interface.go | 8 ++++++++ p2p/net/conn/listen.go | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 977816854..a49282949 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -19,6 +19,7 @@ import ( commands "github.com/ipfs/go-ipfs/core/commands" corehttp "github.com/ipfs/go-ipfs/core/corehttp" "github.com/ipfs/go-ipfs/core/corerouting" + conn "github.com/ipfs/go-ipfs/p2p/net/conn" peer "github.com/ipfs/go-ipfs/p2p/peer" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" util "github.com/ipfs/go-ipfs/util" @@ -32,7 +33,8 @@ const ( writableKwd = "writable" ipfsMountKwd = "mount-ipfs" ipnsMountKwd = "mount-ipns" - unrestrictedApiAccess = "unrestricted-api" + unrestrictedApiAccessKwd = "unrestricted-api" + unencryptTransportKwd = "disable-transport-encryption" // apiAddrKwd = "address-api" // swarmAddrKwd = "address-swarm" ) @@ -76,7 +78,8 @@ the port as you would other services or database (firewall, authenticated proxy, cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"), cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"), cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"), - cmds.BoolOption(unrestrictedApiAccess, "Allow API access to unlisted hashes"), + cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes"), + cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"), // TODO: add way to override addresses. tricky part: updating the config if also --init. // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"), @@ -110,6 +113,14 @@ func daemonFunc(req cmds.Request, res cmds.Response) { } }() + // check transport encryption flag. + unencrypted, _, _ := req.Option(unencryptTransportKwd).Bool() + if unencrypted { + log.Warningf(`Running with --%s: All connections are UNENCRYPTED. + You will not be able to connect to regular encrypted networks.`, unencryptTransportKwd) + conn.EncryptConnections = false + } + // first, whether user has provided the initialization flag. we may be // running in an uninitialized state. initialize, _, err := req.Option(initOptionKwd).Bool() @@ -259,9 +270,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { apiMaddr = apiLis.Multiaddr() fmt.Printf("API server listening on %s\n", apiMaddr) - unrestricted, _, err := req.Option(unrestrictedApiAccess).Bool() + unrestricted, _, err := req.Option(unrestrictedApiAccessKwd).Bool() if err != nil { - return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccess, err), nil + return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil } apiGw := corehttp.NewGateway(corehttp.GatewayConfig{ diff --git a/p2p/net/conn/dial.go b/p2p/net/conn/dial.go index 43831c3ef..a9a1a7aaf 100644 --- a/p2p/net/conn/dial.go +++ b/p2p/net/conn/dial.go @@ -60,7 +60,7 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) ( return } - if d.PrivateKey == nil { + if d.PrivateKey == nil || EncryptConnections == false { log.Warning("dialer %s dialing INSECURELY %s at %s!", d, remote, raddr) connOut = c return diff --git a/p2p/net/conn/interface.go b/p2p/net/conn/interface.go index 3a61911af..820085930 100644 --- a/p2p/net/conn/interface.go +++ b/p2p/net/conn/interface.go @@ -93,3 +93,11 @@ type Listener interface { // Any blocked Accept operations will be unblocked and return errors. Close() error } + +// EncryptConnections is a global parameter because it should either be +// enabled or _completely disabled_. I.e. a node should only be able to talk +// to proper (encrypted) networks if it is encrypting all its transports. +// Running a node with disabled transport encryption is useful to debug the +// protocols, achieve implementation interop, or for private networks which +// -- for whatever reason -- _must_ run unencrypted. +var EncryptConnections = true diff --git a/p2p/net/conn/listen.go b/p2p/net/conn/listen.go index ea91e5a56..71b89d767 100644 --- a/p2p/net/conn/listen.go +++ b/p2p/net/conn/listen.go @@ -107,7 +107,7 @@ func (l *listener) Accept() (net.Conn, error) { return nil, err } - if l.privk == nil { + if l.privk == nil || EncryptConnections == false { log.Warning("listener %s listening INSECURELY!", l) return c, nil } -- GitLab