simpleacme

package module
v0.0.0-...-3cfc441 Latest Latest
Warning

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

Go to latest
Published: May 6, 2017 License: MIT Imports: 15 Imported by: 0

README

go-simpleacme

GoDoc MIT License

The golang.org/x/crypto/acme package enables Go applications to obtain TLS certificates. However, the package is quite complex and using it in an application requires lots of boilerplate code. This package provides a much simpler interface, while still utilizing golang.org/x/crypto/acme behind the scenes.

Basic Usage

The following example demonstrates basic usage of go-simpleacme:

import (
    "context"

    "github.com/nathan-osman/go-simpleacme"
)

ctx := context.TODO()

// Create the client - the key will be generated if it does not exist
c, err := simpleacme.New(ctx, "account.key")
if err != nil {
    // handle error
}

// Obtain a certificate for the list of domain names - the
// address is used for responding to challenges
domains := []string{"example.com", "example.org"}
if err := c.Create(ctx, "test.key", "test.crt", ":http", domains...); err != nil {
    // handle error
}

That's it! If everything went well, you will now have three new files in the current directory:

  • account.key the account key, which can be reused
  • test.key the private key for the certificate
  • test.crt the certificate bundle for the domain names

Advanced Usage

go-simpleacme also provides a certificate manager:

import (
    "context"

    "github.com/nathan-osman/go-simpleacme/manager"
)

ctx := context.TODO()

// Create a certificate manager that will store all keys
// and certificates in /etc/certs
m, err := simpleacme.New(ctx, ":http", "/etc/certs", nil)
if err != nil {
    // handle error
}
defer m.Close()

// Add a couple of domain names to the manager
m.Add(ctx, "example.com", "example.org")

The manager will automatically obtain TLS certificates for the two domain names (combining them into a single certificate to reduce ACME requests). When the certificates are about to expire, they will be automatically renewed.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("invalid key")
View Source
var ErrNoChallenges = errors.New("no suitable challenge found")
View Source
var ErrNoDomains = errors.New("no domain names provided")

Functions

This section is empty.

Types

type Client

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

Client facilitates the process of obtaining TLS certificates.

func New

func New(ctx context.Context, key string) (*Client, error)

New creates a new ACME client. If the key does not exist, a new one is generated and registered.

func (*Client) Create

func (c *Client) Create(ctx context.Context, key, cert, addr string, domains ...string) error

Create attempts to create a TLS certificate and private key for the specified domain names. The provided address is used for challenges.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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