From c37e733d403f0261be74d9fb8d9f8fc42368397e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Mon, 27 May 2019 12:00:30 +0100 Subject: [PATCH] migrate to consolidated types. (#30) --- p2p/security/tls/cmd/tlsdiag/client.go | 2 +- p2p/security/tls/cmd/tlsdiag/key.go | 2 +- p2p/security/tls/cmd/tlsdiag/server.go | 2 +- p2p/security/tls/conn.go | 8 ++++---- p2p/security/tls/crypto.go | 8 ++++---- p2p/security/tls/transport.go | 16 ++++++++-------- p2p/security/tls/transport_test.go | 11 ++++++----- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/p2p/security/tls/cmd/tlsdiag/client.go b/p2p/security/tls/cmd/tlsdiag/client.go index 21e4d18098..8b0fc46fb0 100644 --- a/p2p/security/tls/cmd/tlsdiag/client.go +++ b/p2p/security/tls/cmd/tlsdiag/client.go @@ -8,7 +8,7 @@ import ( "net" "time" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" libp2ptls "github.com/libp2p/go-libp2p-tls" ) diff --git a/p2p/security/tls/cmd/tlsdiag/key.go b/p2p/security/tls/cmd/tlsdiag/key.go index 038974225a..557a485c35 100644 --- a/p2p/security/tls/cmd/tlsdiag/key.go +++ b/p2p/security/tls/cmd/tlsdiag/key.go @@ -4,7 +4,7 @@ import ( "crypto/rand" "fmt" - ic "github.com/libp2p/go-libp2p-crypto" + ic "github.com/libp2p/go-libp2p-core/crypto" ) func generateKey(keyType string) (priv ic.PrivKey, err error) { diff --git a/p2p/security/tls/cmd/tlsdiag/server.go b/p2p/security/tls/cmd/tlsdiag/server.go index 0a895baf12..290af13d63 100644 --- a/p2p/security/tls/cmd/tlsdiag/server.go +++ b/p2p/security/tls/cmd/tlsdiag/server.go @@ -7,7 +7,7 @@ import ( "net" "time" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" libp2ptls "github.com/libp2p/go-libp2p-tls" ) diff --git a/p2p/security/tls/conn.go b/p2p/security/tls/conn.go index d5450b1c6d..cf32fa459d 100644 --- a/p2p/security/tls/conn.go +++ b/p2p/security/tls/conn.go @@ -3,9 +3,9 @@ package libp2ptls import ( "crypto/tls" - cs "github.com/libp2p/go-conn-security" - ci "github.com/libp2p/go-libp2p-crypto" - peer "github.com/libp2p/go-libp2p-peer" + ci "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/sec" ) type conn struct { @@ -18,7 +18,7 @@ type conn struct { remotePubKey ci.PubKey } -var _ cs.Conn = &conn{} +var _ sec.SecureConn = &conn{} func (c *conn) LocalPeer() peer.ID { return c.localPeer diff --git a/p2p/security/tls/crypto.go b/p2p/security/tls/crypto.go index 50c9d71a43..917c65a666 100644 --- a/p2p/security/tls/crypto.go +++ b/p2p/security/tls/crypto.go @@ -13,11 +13,11 @@ import ( "math/big" "time" + crypto "github.com/libp2p/go-libp2p-crypto" "golang.org/x/sys/cpu" - crypto "github.com/libp2p/go-libp2p-crypto" - ic "github.com/libp2p/go-libp2p-crypto" - peer "github.com/libp2p/go-libp2p-peer" + ic "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/peer" ) const certValidityPeriod = 100 * 365 * 24 * time.Hour // ~100 years @@ -133,7 +133,7 @@ func getRemotePubKey(chain []*x509.Certificate) (ic.PubKey, error) { if _, err := asn1.Unmarshal(keyExt.Value, &sk); err != nil { return nil, fmt.Errorf("unmarshalling signed certificate failed: %s", err) } - pubKey, err := crypto.UnmarshalPublicKey(sk.PubKey) + pubKey, err := ic.UnmarshalPublicKey(sk.PubKey) if err != nil { return nil, fmt.Errorf("unmarshalling public key failed: %s", err) } diff --git a/p2p/security/tls/transport.go b/p2p/security/tls/transport.go index 8b3e132f6b..2dc4257a3e 100644 --- a/p2p/security/tls/transport.go +++ b/p2p/security/tls/transport.go @@ -7,9 +7,9 @@ import ( "net" "os" - cs "github.com/libp2p/go-conn-security" - ci "github.com/libp2p/go-libp2p-crypto" - peer "github.com/libp2p/go-libp2p-peer" + ci "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/sec" ) // TLS 1.3 is opt-in in Go 1.12 @@ -48,10 +48,10 @@ func New(key ci.PrivKey) (*Transport, error) { return t, nil } -var _ cs.Transport = &Transport{} +var _ sec.SecureTransport = &Transport{} // SecureInbound runs the TLS handshake as a server. -func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn) (cs.Conn, error) { +func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn) (sec.SecureConn, error) { config, keyCh := t.identity.ConfigForAny() return t.handshake(ctx, tls.Server(insecure, config), keyCh) } @@ -63,7 +63,7 @@ func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn) (cs.Co // application data immediately afterwards. // If the handshake fails, the server will close the connection. The client will // notice this after 1 RTT when calling Read. -func (t *Transport) SecureOutbound(ctx context.Context, insecure net.Conn, p peer.ID) (cs.Conn, error) { +func (t *Transport) SecureOutbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error) { config, keyCh := t.identity.ConfigForPeer(p) return t.handshake(ctx, tls.Client(insecure, config), keyCh) } @@ -72,7 +72,7 @@ func (t *Transport) handshake( ctx context.Context, tlsConn *tls.Conn, keyCh <-chan ci.PubKey, -) (cs.Conn, error) { +) (sec.SecureConn, error) { // There's no way to pass a context to tls.Conn.Handshake(). // See https://github.com/golang/go/issues/18482. // Close the connection instead. @@ -117,7 +117,7 @@ func (t *Transport) handshake( return conn, nil } -func (t *Transport) setupConn(tlsConn *tls.Conn, remotePubKey ci.PubKey) (cs.Conn, error) { +func (t *Transport) setupConn(tlsConn *tls.Conn, remotePubKey ci.PubKey) (sec.SecureConn, error) { if remotePubKey == nil { return nil, errors.New("go-libp2p-tls BUG: expected remote pub key to be set") } diff --git a/p2p/security/tls/transport_test.go b/p2p/security/tls/transport_test.go index 82944560e4..94f2c215f0 100644 --- a/p2p/security/tls/transport_test.go +++ b/p2p/security/tls/transport_test.go @@ -20,9 +20,10 @@ import ( "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/types" - cs "github.com/libp2p/go-conn-security" - ci "github.com/libp2p/go-libp2p-crypto" - peer "github.com/libp2p/go-libp2p-peer" + ci "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/sec" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -94,7 +95,7 @@ var _ = Describe("Transport", func() { clientInsecureConn, serverInsecureConn := connect() - serverConnChan := make(chan cs.Conn) + serverConnChan := make(chan sec.SecureConn) go func() { defer GinkgoRecover() serverConn, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn) @@ -103,7 +104,7 @@ var _ = Describe("Transport", func() { }() clientConn, err := clientTransport.SecureOutbound(context.Background(), clientInsecureConn, serverID) Expect(err).ToNot(HaveOccurred()) - var serverConn cs.Conn + var serverConn sec.SecureConn Eventually(serverConnChan).Should(Receive(&serverConn)) defer clientConn.Close() defer serverConn.Close()