-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch enables TLS client authentication. The existing system cert pool configuration is merged into the new TLSCerts configuration. Change-Id: Ia9eacabf8a88f046028ca544b0ab6a99b65a5ea6 Signed-off-by: Emir Heidinger <[email protected]> Signed-off-by: Troy Ronda <[email protected]> Signed-off-by: Aleksandar Likic <[email protected]>
- Loading branch information
Showing
27 changed files
with
475 additions
and
209 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package comm | ||
|
||
import ( | ||
"crypto/tls" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/api/apiconfig" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/errors" | ||
) | ||
|
||
// TLSConfig returns the appropriate config for TLS including the root CAs, | ||
// certs for mutual TLS, and server host override | ||
func TLSConfig(certificate string, serverhostoverride string, config apiconfig.Config) (*tls.Config, error) { | ||
certPool, _ := config.TLSCACertPool("") | ||
|
||
if len(certificate) == 0 && (certPool == nil || len(certPool.Subjects()) == 0) { | ||
return nil, errors.New("certificate is required") | ||
} | ||
|
||
tlsCaCertPool, err := config.TLSCACertPool(certificate) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clientCerts, err := config.TLSClientCerts() | ||
if err != nil { | ||
return nil, errors.Errorf("Error loading cert/key pair for TLS client credentials: %v", err) | ||
} | ||
|
||
return &tls.Config{RootCAs: tlsCaCertPool, Certificates: clientCerts, ServerName: serverhostoverride}, nil | ||
} |
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
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
Oops, something went wrong.