afssl

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: Apache-2.0 Imports: 26 Imported by: 4

README

AFSSL

SSL Generator.

Install

go get github.com/aacfactory/afssl

Usage

Generate Self Signed SSL.

config := afssl.CertificateConfig{
    Country:            "CN",
    Province:           "Shanghai",
    City:               "Shanghai",
    Organization:       "AACFACTORY",
    OrganizationalUnit: "TECH",
    CommonName:         "AFSSL",
    IPs:                nil,
    Emails:             nil,
    DNSNames:           nil,
}
// ca
caPEM, caKeyPEM, caErr := afssl.GenerateCertificate(config, afssl.CA())
if caErr != nil {
    t.Error("ca", caErr)
    return
}
fmt.Println(string(caPEM))
fmt.Println(string(caKeyPEM))
// server
serverPEM, serverKeyPEM, serverErr := afssl.GenerateCertificate(config, afssl.WithParent(caPEM, caKeyPEM))
if serverErr != nil {
    t.Error("server", serverErr)
    return
}
fmt.Println(string(serverPEM))
fmt.Println(string(serverKeyPEM))
// client
clientPEM, clientKeyPEM, clientErr := afssl.GenerateCertificate(config, afssl.WithParent(caPEM, caKeyPEM))
if clientErr != nil {
    t.Error("client", clientErr)
    return
}
fmt.Println(string(clientPEM))
fmt.Println(string(clientKeyPEM))

Generate *tls.Config via ACME. More DNS providers is HERE . Support Automatic RENEW. Thanks to LEGO.

os.Setenv("ALICLOUD_ACCESS_KEY", "your aliyun access key")
os.Setenv("ALICLOUD_SECRET_KEY", "your aliyun sercet key")
acme, acmeErr := afssl.NewAcme("foo@bar.com", "alidns", []string{"*.foo.bar"})
if acmeErr != nil {
    t.Error(acmeErr)
    return
}
config, obtainErr := acme.Obtain()
if obtainErr != nil {
    t.Error(obtainErr)
    return
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCertificate added in v1.1.0

func GenerateCertificate(config CertificateConfig, opts ...GenerateCertificateOption) (certPEM []byte, keyPEM []byte, err error)

Types

type Acme added in v1.2.0

type Acme interface {
	Obtain() (config *tls.Config, err error)
	Close()
}

func NewAcme added in v1.2.0

func NewAcme(email string, dnsProvider string, domains []string, opts ...AcmeOption) (v Acme, err error)

type AcmeLogger added in v1.2.0

type AcmeLogger interface {
	Fatal(args ...interface{})
	Fatalln(args ...interface{})
	Fatalf(format string, args ...interface{})
	Print(args ...interface{})
	Println(args ...interface{})
	Printf(format string, args ...interface{})
}

type AcmeOption added in v1.2.0

type AcmeOption func(*AcmeOptions) error

func AcmeRequestCertificateTimeout added in v1.2.0

func AcmeRequestCertificateTimeout(v time.Duration) AcmeOption

func CustomizeAcmeLogger added in v1.2.0

func CustomizeAcmeLogger(v AcmeLogger) AcmeOption

type AcmeOptions added in v1.2.0

type AcmeOptions struct {
	RequestCertificateTimeout time.Duration
	Log                       AcmeLogger
}

type CertificateConfig added in v1.1.0

type CertificateConfig struct {
	Country            string
	Province           string
	City               string
	Organization       string
	OrganizationalUnit string
	CommonName         string
	IPs                []string
	Emails             []string
	DNSNames           []string
}

type GenerateCertificateOption added in v1.1.0

type GenerateCertificateOption func(*GenerateCertificateOptions) error

func CA added in v1.1.0

func WithExpirationDays added in v1.1.0

func WithExpirationDays(days int) GenerateCertificateOption

func WithParent added in v1.1.0

func WithParent(certPEM []byte, keyPEM []byte) GenerateCertificateOption

func WithSerialNumber added in v1.1.0

func WithSerialNumber(sn uint64) GenerateCertificateOption

type GenerateCertificateOptions added in v1.1.0

type GenerateCertificateOptions struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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