-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
16 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
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,35 @@ | ||
// Copyright (c) 2022 Meng Huang ([email protected]) | ||
// This package is licensed under a MIT license that can be found in the LICENSE file. | ||
|
||
package rpc | ||
|
||
import ( | ||
"crypto/tls" | ||
"github.com/hslam/socket" | ||
) | ||
|
||
// LoadTLSConfig returns a TLS config by loading the certificate file and the key file. | ||
func LoadTLSConfig(certFile, keyFile string) (*tls.Config, error) { | ||
return socket.LoadTLSConfig(certFile, keyFile) | ||
} | ||
|
||
// TLSConfig returns a TLS config by the certificate data and the key data. | ||
func TLSConfig(certPEM []byte, keyPEM []byte) *tls.Config { | ||
return socket.TLSConfig(certPEM, keyPEM) | ||
} | ||
|
||
// DefalutTLSConfig returns a default TLS config. | ||
func DefalutTLSConfig() *tls.Config { | ||
return socket.DefalutTLSConfig() | ||
} | ||
|
||
// SkipVerifyTLSConfig returns a insecure skip verify TLS config. | ||
func SkipVerifyTLSConfig() *tls.Config { | ||
return socket.SkipVerifyTLSConfig() | ||
} | ||
|
||
// DefaultKeyPEM represents the default private key data. | ||
var DefaultKeyPEM = socket.DefaultKeyPEM | ||
|
||
// DefaultCertPEM represents the default certificate data. | ||
var DefaultCertPEM = socket.DefaultCertPEM |
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,44 @@ | ||
// Copyright (c) 2022 Meng Huang ([email protected]) | ||
// This package is licensed under a MIT license that can be found in the LICENSE file. | ||
|
||
package rpc | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLoadTLSConfig(t *testing.T) { | ||
var certFileName = "tmpTestCertFile" | ||
var keyFileName = "tmpTestKeyFile" | ||
var err error | ||
_, err = LoadTLSConfig("", "") | ||
if err == nil { | ||
t.Error("should be no such file or directory") | ||
} | ||
certFile, _ := os.Create(certFileName) | ||
certFile.Write(DefaultCertPEM) | ||
certFile.Close() | ||
defer os.Remove(certFileName) | ||
_, err = LoadTLSConfig(certFileName, "") | ||
if err == nil { | ||
t.Error("should be no such file or directory") | ||
} | ||
keyFile, _ := os.Create(keyFileName) | ||
keyFile.Write(DefaultKeyPEM) | ||
keyFile.Close() | ||
defer os.Remove(keyFileName) | ||
_, err = LoadTLSConfig(certFileName, keyFileName) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestTLSConfig(t *testing.T) { | ||
defer func() { | ||
if err := recover(); err == nil { | ||
t.Error("should panic") | ||
} | ||
}() | ||
TLSConfig(DefaultCertPEM, []byte{}) | ||
} |