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 21e4d180..8b0fc46f 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 03897422..557a485c 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 0a895baf..290af13d 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 d5450b1c..cf32fa45 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 50c9d71a..917c65a6 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 8b3e132f..2dc4257a 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 82944560..94f2c215 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()