Browse Source
logging: Add canonical log for misbehaving peers (#1600)
* Add misbehaving log
* Add logging when security handshake or muxer fails
* Update go-libp2p-core
* Log at the security handshake level
* Remove misbehaving log from setup muxer
pull/1618/head
Marco Munizaga
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
11 additions and
4 deletions
-
go.mod
-
go.sum
-
p2p/security/noise/transport.go
-
p2p/security/tls/transport.go
|
|
@ -21,7 +21,7 @@ require ( |
|
|
|
github.com/libp2p/go-eventbus v0.2.1 |
|
|
|
github.com/libp2p/go-libp2p-asn-util v0.2.0 |
|
|
|
github.com/libp2p/go-libp2p-circuit v0.6.0 |
|
|
|
github.com/libp2p/go-libp2p-core v0.16.1 |
|
|
|
github.com/libp2p/go-libp2p-core v0.17.0 |
|
|
|
github.com/libp2p/go-libp2p-peerstore v0.7.0 |
|
|
|
github.com/libp2p/go-libp2p-resource-manager v0.3.0 |
|
|
|
github.com/libp2p/go-libp2p-testing v0.9.2 |
|
|
|
|
|
@ -411,8 +411,8 @@ github.com/libp2p/go-libp2p-core v0.6.0/go.mod h1:txwbVEhHEXikXn9gfC7/UDDw7rkxuX |
|
|
|
github.com/libp2p/go-libp2p-core v0.10.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg= |
|
|
|
github.com/libp2p/go-libp2p-core v0.12.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg= |
|
|
|
github.com/libp2p/go-libp2p-core v0.14.0/go.mod h1:tLasfcVdTXnixsLB0QYaT1syJOhsbrhG7q6pGrHtBg8= |
|
|
|
github.com/libp2p/go-libp2p-core v0.16.1 h1:bWoiEBqVkpJ13hbv/f69tHODp86t6mvc4fBN4DkK73M= |
|
|
|
github.com/libp2p/go-libp2p-core v0.16.1/go.mod h1:O3i/7y+LqUb0N+qhzXjBjjpchgptWAVMG1Voegk7b4c= |
|
|
|
github.com/libp2p/go-libp2p-core v0.17.0 h1:QGU8mlxHytwTc4pq/aVQX9VDoAPiCHxfe/oOSwF+YDg= |
|
|
|
github.com/libp2p/go-libp2p-core v0.17.0/go.mod h1:h/iAbFij28ASmI+tvXfjoipg1g2N33O4UN6LIb6QfoU= |
|
|
|
github.com/libp2p/go-libp2p-mplex v0.5.0/go.mod h1:eLImPJLkj3iG5t5lq68w3Vm5NAQ5BcKwrrb2VmOYb3M= |
|
|
|
github.com/libp2p/go-libp2p-peerstore v0.6.0/go.mod h1:DGEmKdXrcYpK9Jha3sS7MhqYdInxJy84bIPtSu65bKc= |
|
|
|
github.com/libp2p/go-libp2p-peerstore v0.7.0 h1:2iIUwok3vtmnWJTZeTeLgnBO6GbkXcwSRwgZHEKrQZs= |
|
|
|
|
|
@ -4,6 +4,7 @@ import ( |
|
|
|
"context" |
|
|
|
"net" |
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/canonicallog" |
|
|
|
"github.com/libp2p/go-libp2p-core/crypto" |
|
|
|
"github.com/libp2p/go-libp2p-core/peer" |
|
|
|
"github.com/libp2p/go-libp2p-core/sec" |
|
|
@ -38,7 +39,11 @@ func New(privkey crypto.PrivKey) (*Transport, error) { |
|
|
|
// SecureInbound runs the Noise handshake as the responder.
|
|
|
|
// If p is empty, connections from any peer are accepted.
|
|
|
|
func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error) { |
|
|
|
return newSecureSession(t, ctx, insecure, p, false) |
|
|
|
c, err := newSecureSession(t, ctx, insecure, p, false) |
|
|
|
if err != nil { |
|
|
|
canonicallog.LogMisbehavingPeerNetAddr(p, insecure.RemoteAddr(), "noise-security-handshake", err, "failed security handshake") |
|
|
|
} |
|
|
|
return c, err |
|
|
|
} |
|
|
|
|
|
|
|
// SecureOutbound runs the Noise handshake as the initiator.
|
|
|
|
|
|
@ -9,6 +9,7 @@ import ( |
|
|
|
"os" |
|
|
|
"runtime/debug" |
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/canonicallog" |
|
|
|
ci "github.com/libp2p/go-libp2p-core/crypto" |
|
|
|
"github.com/libp2p/go-libp2p-core/peer" |
|
|
|
"github.com/libp2p/go-libp2p-core/sec" |
|
|
@ -52,6 +53,7 @@ func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn, p peer |
|
|
|
config, keyCh := t.identity.ConfigForPeer(p) |
|
|
|
cs, err := t.handshake(ctx, tls.Server(insecure, config), keyCh) |
|
|
|
if err != nil { |
|
|
|
canonicallog.LogMisbehavingPeerNetAddr(p, insecure.RemoteAddr(), "tls-security-handshake", err, "failed security handshake") |
|
|
|
insecure.Close() |
|
|
|
} |
|
|
|
return cs, err |
|
|
|