Skip to content

Commit

Permalink
migrate to consolidated types. (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed May 27, 2019
1 parent 173abf7 commit c37e733
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion p2p/security/tls/cmd/tlsdiag/client.go
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion p2p/security/tls/cmd/tlsdiag/key.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion p2p/security/tls/cmd/tlsdiag/server.go
Expand Up @@ -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"
)

Expand Down
8 changes: 4 additions & 4 deletions p2p/security/tls/conn.go
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions p2p/security/tls/crypto.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions p2p/security/tls/transport.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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.
Expand Down Expand Up @@ -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")
}
Expand Down
11 changes: 6 additions & 5 deletions p2p/security/tls/transport_test.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit c37e733

Please sign in to comment.