gtls

package
v1.5.15 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 5 Imported by: 10

README

gtls

gtls provides grpc secure connectivity, supporting both server-only authentication and client-server authentication.

Example of use
grpc server
import "github.com/zhufuyi/sponge/pkg/grpc/gtls"

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
import "github.com/zhufuyi/sponge/pkg/grpc/gtls"

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

Overview

Package gtls provides grpc secure connectivity, supporting both server-only authentication and client-server authentication.

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
Package certfile is used to locate the certificate file.
Package certfile is used to locate the certificate file.

Jump to

Keyboard shortcuts

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