migrate to consolidated types. (#30)
This commit is contained in:
parent
173abf7218
commit
c37e733d40
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue