gtls

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 5 Imported by: 10

README

gtls

Example of use
grpc server
func main() {
	// one-way authentication (server-side authentication)
	//credentials, err := gtls.GetServerTLSCredentials(certfile.Path("/one-way/server.crt"), certfile.Path("/one-way/server.key"))

	// two-way authentication
	credentials, err := gtls.GetServerTLSCredentialsByCA(
		certfile.Path("two-way/ca.pem"),
		certfile.Path("two-way/server/server.pem"),
		certfile.Path("two-way/server/server.key"),
	)
	if err != nil {
		panic(err)
	}

	// interceptor
	opts := []grpc.ServerOption{
		grpc.Creds(credentials),
	}

	server := grpc.NewServer(opts...)

	// ......
}

grpc client
func main() {
	// one-way authentication
	//credentials, err := gtls.GetClientTLSCredentials("localhost", certfile.Path("/one-way/server.crt"))

	// two-way authentication
	credentials, err := gtls.GetClientTLSCredentialsByCA(
		"localhost",
		certfile.Path("two-way/ca.pem"),
		certfile.Path("two-way/client/client.pem"),
		certfile.Path("two-way/client/client.key"),
	)
	if err != nil {
		panic(err)
	}

	conn, err := grpc.Dial("127.0.0.1:8080", grpc.WithTransportCredentials(credentials))
	if err != nil {
		panic(err)
	}

	// ......
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClientTLSCredentials

func GetClientTLSCredentials(serverName string, certFile string) (credentials.TransportCredentials, error)

GetClientTLSCredentials TLS encryption

func GetClientTLSCredentialsByCA

func GetClientTLSCredentialsByCA(serverName string, caFile string, certFile string, keyFile string) (credentials.TransportCredentials, error)

GetClientTLSCredentialsByCA two-way authentication via CA-issued root certificate

func GetServerTLSCredentials

func GetServerTLSCredentials(certFile string, keyFile string) (credentials.TransportCredentials, error)

GetServerTLSCredentials server-side authentication

func GetServerTLSCredentialsByCA

func GetServerTLSCredentialsByCA(caFile string, certFile string, keyFile string) (credentials.TransportCredentials, error)

GetServerTLSCredentialsByCA two-way authentication via CA-issued root certificate

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL