certinel

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2017 License: BSD-3-Clause Imports: 2 Imported by: 1

README

certinel Travis CI GoDoc

Certinel is a Go library that makes it even easier to implement zero-hit TLS certificate changes by watching for certificate changes for you. The methods required by tls.Config are already implemented for you.

Right now there's support for listening to file system events on Linux, BSDs, and Windows using the fsnotify library.

Usage

Create the certinel instance, start it with Watch, then pass the GetCertificate method to your tls.Config instance.

package main

import (
	"crypto/tls"
	"log"
	"net/http"

	"github.com/cloudflare/certinel"
	"github.com/cloudflare/certinel/fswatcher"
)

func main() {
	watcher, err := fswatcher.New("/etc/ssl/app.pem", "/etc/ssl/app.key")
	if err != nil {
		log.Fatalf("fatal: unable to read server certificate. err='%s'", err)
	}
	sentinel := certinel.New(watcher, func(err error) {
		log.Printf("error: certinel was unable to reload the certificate. err='%s'", err)
	})

	sentinel.Watch()

	server := http.Server{
		Addr: ":8000",
		TLSConfig: &tls.Config{
			GetCertificate: sentinel.GetCertificate,
		},
	}
	
	server.ListenAndServeTLS("", "")
}

On Go 1.8+, GetClientCertificate is also implemented to support rotating the client certificate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Certinel

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

Certinel is a container for zero-hit tls.Certificate changes, by receiving new certificates from sentries and presenting the functions expected by Go's tls.Config{}. Reading certificates from a Certinel instance is safe across multiple goroutines.

func New

func New(w Watcher, errBack func(error)) *Certinel

New creates a Certinel that watches for changes with the provided Watcher.

func (*Certinel) Close

func (c *Certinel) Close() error

Close calls Close on the held Watcher instance. After closing it is no longer safe to use this Certinel instance.

func (*Certinel) GetCertificate

func (c *Certinel) GetCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate returns the current tls.Certificate instance. The function can be passed as the GetCertificate member in a tls.Config object. It is safe to call across multiple goroutines.

func (*Certinel) GetClientCertificate

func (c *Certinel) GetClientCertificate(certificateRequest *tls.CertificateRequestInfo) (*tls.Certificate, error)

GetClientCertificate returns the current tls.Certificate instance. The function can be passed as the GetClientCertificate member in a tls.Config object. It is safe to call across multiple goroutines.

func (*Certinel) Watch

func (c *Certinel) Watch()

Watch setups the Certinel's channel handles and calls Watch on the held Watcher instance.

type Watcher

type Watcher interface {
	Watch() (<-chan tls.Certificate, <-chan error)
	Close() error
}

Watchers provide a way to construct (and close!) channels that bind a Certinel to a changing certificate.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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