Unverified Commit fb33e078 authored by aliiohs's avatar aliiohs Committed by GitHub

add tls test case (#45)

Co-authored-by: 's avataraliiohs <renzhiyuan@wecash.net>
parent 2c6d6463
...@@ -36,6 +36,7 @@ var ( ...@@ -36,6 +36,7 @@ var (
EventListener = &hello.MessageHandler{} EventListener = &hello.MessageHandler{}
) )
// InitialSession init session
func InitialSession(session getty.Session) (err error) { func InitialSession(session getty.Session) (err error) {
//session.SetCompressType(getty.CompressZip) //session.SetCompressType(getty.CompressZip)
_, ok := session.Conn().(*tls.Conn) _, ok := session.Conn().(*tls.Conn)
......
...@@ -27,10 +27,12 @@ import ( ...@@ -27,10 +27,12 @@ import (
perrors "github.com/pkg/errors" perrors "github.com/pkg/errors"
) )
// TlsConfigBuilder tls config builder interface
type TlsConfigBuilder interface { type TlsConfigBuilder interface {
BuildTlsConfig() (*tls.Config, error) BuildTlsConfig() (*tls.Config, error)
} }
// ServerTlsConfigBuilder impl TlsConfigBuilder for server
type ServerTlsConfigBuilder struct { type ServerTlsConfigBuilder struct {
ServerKeyCertChainPath string ServerKeyCertChainPath string
ServerPrivateKeyPath string ServerPrivateKeyPath string
...@@ -38,6 +40,7 @@ type ServerTlsConfigBuilder struct { ...@@ -38,6 +40,7 @@ type ServerTlsConfigBuilder struct {
ServerTrustCertCollectionPath string ServerTrustCertCollectionPath string
} }
// BuildTlsConfig impl TlsConfigBuilder method
func (s *ServerTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) { func (s *ServerTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) {
var ( var (
err error err error
...@@ -75,6 +78,7 @@ func (s *ServerTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) { ...@@ -75,6 +78,7 @@ func (s *ServerTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) {
return config, nil return config, nil
} }
// ClientTlsConfigBuilder impl TlsConfigBuilder for client
type ClientTlsConfigBuilder struct { type ClientTlsConfigBuilder struct {
ClientKeyCertChainPath string ClientKeyCertChainPath string
ClientPrivateKeyPath string ClientPrivateKeyPath string
...@@ -82,6 +86,7 @@ type ClientTlsConfigBuilder struct { ...@@ -82,6 +86,7 @@ type ClientTlsConfigBuilder struct {
ClientTrustCertCollectionPath string ClientTrustCertCollectionPath string
} }
// BuildTlsConfig impl TlsConfigBuilder method
func (c *ClientTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) { func (c *ClientTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(c.ClientTrustCertCollectionPath, c.ClientPrivateKeyPath) cert, err := tls.LoadX509KeyPair(c.ClientTrustCertCollectionPath, c.ClientPrivateKeyPath)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment