-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gateway support for mutual TLS networks (#3235)
To support client authentication (mTLS), the gateway needs to pass the host peer’s client certificate when making connections to the other nodes in the network. If client authentication is not enabled, then these certs will be ignored. Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com> (cherry picked from commit 59835e6)
- Loading branch information
1 parent
602f4c6
commit c89ba60
Showing
5 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package gateway | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/hyperledger/fabric/common/crypto/tlsgen" | ||
"github.com/hyperledger/fabric/gossip/common" | ||
"github.com/hyperledger/fabric/internal/pkg/comm" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMutualTLS(t *testing.T) { | ||
ca, err := tlsgen.NewCA() | ||
require.NoError(t, err, "failed to create CA") | ||
|
||
serverPair, err := ca.NewServerCertKeyPair("127.0.0.1") | ||
require.NoError(t, err, "failed to create server key pair") | ||
|
||
clientPair, err := ca.NewClientCertKeyPair() | ||
require.NoError(t, err, "failed to create client key pair") | ||
|
||
rootTLSCert := ca.CertBytes() | ||
|
||
server, err := comm.NewGRPCServer("127.0.0.1:0", comm.ServerConfig{ | ||
SecOpts: comm.SecureOptions{ | ||
UseTLS: true, | ||
RequireClientCert: true, | ||
Certificate: serverPair.Cert, | ||
Key: serverPair.Key, | ||
ClientRootCAs: [][]byte{rootTLSCert}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
go server.Start() | ||
defer server.Stop() | ||
|
||
factory := &endpointFactory{ | ||
timeout: 10 * time.Second, | ||
clientCert: clientPair.Cert, | ||
clientKey: clientPair.Key, | ||
} | ||
|
||
endorser, err := factory.newEndorser(common.PKIidType{}, server.Address(), "msp1", [][]byte{rootTLSCert}) | ||
require.NoError(t, err, "failed to make mTLS connection to server") | ||
|
||
err = endorser.closeConnection() | ||
require.NoError(t, err, "failed to close connection") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters