Browse Source

accept a PSK in the transport constructor (and reject it)

pull/1424/head
Marten Seemann 5 years ago
committed by Steven Allen
parent
commit
eea1dd74b5
  1. 22
      p2p/transport/quic/conn_test.go
  2. 2
      p2p/transport/quic/listener_test.go
  3. 11
      p2p/transport/quic/transport.go

22
p2p/transport/quic/conn_test.go

@ -62,12 +62,12 @@ var _ = Describe("Connection", func() {
})
It("handshakes on IPv4", func() {
serverTransport, err := NewTransport(serverKey)
serverTransport, err := NewTransport(serverKey, nil)
Expect(err).ToNot(HaveOccurred())
ln := runServer(serverTransport, "/ip4/127.0.0.1/udp/0/quic")
defer ln.Close()
clientTransport, err := NewTransport(clientKey)
clientTransport, err := NewTransport(clientKey, nil)
Expect(err).ToNot(HaveOccurred())
conn, err := clientTransport.Dial(context.Background(), ln.Multiaddr(), serverID)
Expect(err).ToNot(HaveOccurred())
@ -86,12 +86,12 @@ var _ = Describe("Connection", func() {
})
It("handshakes on IPv6", func() {
serverTransport, err := NewTransport(serverKey)
serverTransport, err := NewTransport(serverKey, nil)
Expect(err).ToNot(HaveOccurred())
ln := runServer(serverTransport, "/ip6/::1/udp/0/quic")
defer ln.Close()
clientTransport, err := NewTransport(clientKey)
clientTransport, err := NewTransport(clientKey, nil)
Expect(err).ToNot(HaveOccurred())
conn, err := clientTransport.Dial(context.Background(), ln.Multiaddr(), serverID)
Expect(err).ToNot(HaveOccurred())
@ -110,12 +110,12 @@ var _ = Describe("Connection", func() {
})
It("opens and accepts streams", func() {
serverTransport, err := NewTransport(serverKey)
serverTransport, err := NewTransport(serverKey, nil)
Expect(err).ToNot(HaveOccurred())
ln := runServer(serverTransport, "/ip4/127.0.0.1/udp/0/quic")
defer ln.Close()
clientTransport, err := NewTransport(clientKey)
clientTransport, err := NewTransport(clientKey, nil)
Expect(err).ToNot(HaveOccurred())
conn, err := clientTransport.Dial(context.Background(), ln.Multiaddr(), serverID)
Expect(err).ToNot(HaveOccurred())
@ -139,11 +139,11 @@ var _ = Describe("Connection", func() {
It("fails if the peer ID doesn't match", func() {
thirdPartyID, _ := createPeer()
serverTransport, err := NewTransport(serverKey)
serverTransport, err := NewTransport(serverKey, nil)
Expect(err).ToNot(HaveOccurred())
ln := runServer(serverTransport, "/ip4/127.0.0.1/udp/0/quic")
clientTransport, err := NewTransport(clientKey)
clientTransport, err := NewTransport(clientKey, nil)
Expect(err).ToNot(HaveOccurred())
// dial, but expect the wrong peer ID
_, err = clientTransport.Dial(context.Background(), ln.Multiaddr(), thirdPartyID)
@ -164,10 +164,10 @@ var _ = Describe("Connection", func() {
It("dials to two servers at the same time", func() {
serverID2, serverKey2 := createPeer()
serverTransport, err := NewTransport(serverKey)
serverTransport, err := NewTransport(serverKey, nil)
Expect(err).ToNot(HaveOccurred())
ln1 := runServer(serverTransport, "/ip4/127.0.0.1/udp/0/quic")
serverTransport2, err := NewTransport(serverKey2)
serverTransport2, err := NewTransport(serverKey2, nil)
defer ln1.Close()
Expect(err).ToNot(HaveOccurred())
ln2 := runServer(serverTransport2, "/ip4/127.0.0.1/udp/0/quic")
@ -194,7 +194,7 @@ var _ = Describe("Connection", func() {
}
}()
clientTransport, err := NewTransport(clientKey)
clientTransport, err := NewTransport(clientKey, nil)
Expect(err).ToNot(HaveOccurred())
c1, err := clientTransport.Dial(context.Background(), ln1.Multiaddr(), serverID)
Expect(err).ToNot(HaveOccurred())

2
p2p/transport/quic/listener_test.go

@ -23,7 +23,7 @@ var _ = Describe("Listener", func() {
Expect(err).ToNot(HaveOccurred())
key, err := ic.UnmarshalRsaPrivateKey(x509.MarshalPKCS1PrivateKey(rsaKey))
Expect(err).ToNot(HaveOccurred())
t, err = NewTransport(key)
t, err = NewTransport(key, nil)
Expect(err).ToNot(HaveOccurred())
})

11
p2p/transport/quic/transport.go

@ -5,17 +5,20 @@ import (
"errors"
"net"
logging "github.com/ipfs/go-log"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/pnet"
tpt "github.com/libp2p/go-libp2p-core/transport"
p2ptls "github.com/libp2p/go-libp2p-tls"
quic "github.com/lucas-clemente/quic-go"
ma "github.com/multiformats/go-multiaddr"
mafmt "github.com/multiformats/go-multiaddr-fmt"
manet "github.com/multiformats/go-multiaddr-net"
)
var log = logging.Logger("quic-transport")
var quicConfig = &quic.Config{
MaxIncomingStreams: 1000,
MaxIncomingUniStreams: -1, // disable unidirectional streams
@ -86,7 +89,11 @@ type transport struct {
var _ tpt.Transport = &transport{}
// NewTransport creates a new QUIC transport
func NewTransport(key ic.PrivKey) (tpt.Transport, error) {
func NewTransport(key ic.PrivKey, psk pnet.PSK) (tpt.Transport, error) {
if len(psk) > 0 {
log.Error("QUIC doesn't support private networks yet.")
return nil, errors.New("QUIC doesn't support private networks yet")
}
localPeer, err := peer.IDFromPrivateKey(key)
if err != nil {
return nil, err

Loading…
Cancel
Save