mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 09:59:13 +08:00
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>
This commit is contained in:
@ -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{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user