certs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 8 Imported by: 1

Documentation

Overview

Package certs defines a certificate store that will provide primitives to store and get certificates for a given address.

It also provide a primitive to fetch a certificate from a known address using the hash as integrity validation.

Documentation Last Review: 07.10.2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertChain

type CertChain []byte

CertChain represents a list of x509 certificates formatted as ASN.1 DER data. The certificates must be concatenated with no intermediate padding. Can be parsed with `x509.LoadCertificates`.

type Dialable

type Dialable interface {
	mino.Address

	GetDialAddress() string
}

Dialable is an extension of the mino.Address interface to get a network address that can be used to dial the distant server.

type DiskStore

type DiskStore struct {
	*InMemoryStore
	// contains filtered or unexported fields
}

DiskStore is a persistent implementation of a certificate storage. It uses internally an in-memory store to cache the certificates.

- implements certs.Storage

func NewDiskStore

func NewDiskStore(db kv.DB, fac mino.AddressFactory) *DiskStore

NewDiskStore returns a new empty disk store. If certificates are stored in the database, they will be loaded on demand.

func (*DiskStore) Delete

func (s *DiskStore) Delete(addr mino.Address) error

Delete implements certs.Storage. It deletes the certificate from the disk and the cache.

func (*DiskStore) Load

func (s *DiskStore) Load(addr mino.Address) (CertChain, error)

Load implements certs.Storage. It first tries to read the certificate from the cache, then from the disk. It returns nil if not found in both.

func (*DiskStore) Range

func (s *DiskStore) Range(fn func(mino.Address, CertChain) bool) error

Range implements certs.Storage. It iterates over each certificate present in the disk.

func (*DiskStore) Store

func (s *DiskStore) Store(addr mino.Address, chain CertChain) error

Store implements certs.Storage. It stores the certificate in the disk and in the cache.

type InMemoryStore

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

InMemoryStore is a certificate store that keeps the certificates in memory only, which means it does not persist.

- implements certs.Storage

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore creates a new empty certificate store.

func (*InMemoryStore) Delete

func (s *InMemoryStore) Delete(addr mino.Address) error

Delete implements certs.Storage. It deletes the certificate associated to the address if any, otherwise it does nothing.

func (*InMemoryStore) Fetch

func (s *InMemoryStore) Fetch(addr Dialable, hash []byte) error

Fetch implements certs.Storage. It tries to open a TLS connection to the address only to get the certificate from the distant peer. The connection is dropped right after the certificate is read and stored.

func (*InMemoryStore) Hash

func (s *InMemoryStore) Hash(chain CertChain) ([]byte, error)

Hash implements certs.Storage. It returns the unique digest for the certificate.

func (*InMemoryStore) Load

func (s *InMemoryStore) Load(addr mino.Address) (CertChain, error)

Load implements certs.Storage. It looks for the certificate associated to the address. If it does not exist, it will return nil.

func (*InMemoryStore) Range

func (s *InMemoryStore) Range(fn func(addr mino.Address, chain CertChain) bool) error

Range implements certs.Storage. It iterates over all the certificates stored as long as the callback return true.

func (*InMemoryStore) Store

func (s *InMemoryStore) Store(addr mino.Address, chain CertChain) error

Store implements certs.Storage. It stores the certificate with the address as the key.

type Storage

type Storage interface {
	// Store stores the certificate with the address as the key.
	Store(mino.Address, CertChain) error

	// Load returns the certificate associated with the address if any.
	Load(mino.Address) (CertChain, error)

	// Delete removes all the certificates associated with the address.
	Delete(mino.Address) error

	// Range iterates over the certificates held by the store. If the callback
	// returns false, range stops the iteration.
	Range(func(addr mino.Address, cert CertChain) bool) error

	// Fetch calls the address to fetch its certificate and verifies the
	// integrity with the given digest.
	Fetch(Dialable, []byte) error

	// Hash generates the digest of a certificate.
	Hash(CertChain) ([]byte, error)
}

Storage is an interface to manage the certificates of a server.

Jump to

Keyboard shortcuts

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