enrollment

package
v0.2024.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package enrollment facilitates the binding of an Area Controller to a Building Controller. The Building Controller connects to the Area Controller, which implements the EnrollmentApi, and gives it metadata about the Smart Core network and a certificate.

This package only implements the communication between the Building Controller and the Area Controller. It does not interact with the database or user interfaces.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotEnrolled = errors.New("node is not enrolled")

Functions

func DeleteEnrollment

func DeleteEnrollment(dir string) error

func SaveEnrollment

func SaveEnrollment(dir string, enrollment Enrollment) (err error)

Types

type Enrollment

type Enrollment struct {
	RootDeviceName string `json:"root_device_name"`
	ManagerName    string `json:"manager_name"`
	ManagerAddress string `json:"manager_address"`
	LocalAddress   string `json:"local_address"`

	RootCA *x509.Certificate `json:"-"`
	Cert   tls.Certificate   `json:"-"`
}

func LoadEnrollment

func LoadEnrollment(dir string, keyPEM []byte) (Enrollment, error)

LoadEnrollment will load a previously saved Enrollment from a directory on disk. The directory should have the following structure:

<root>
  - enrollment.json - JSON-encoded Enrollment structure
  - root-ca.crt - Root CA for the enrollment, PEM-encoded X.509 certificate
  - cert.crt - Certificate chain for keyPEM, with the Root CA at the top of the chain

This node's private key must be passed in, in PEM-wrapped PKCS#1 or PKCS#8 format.

func (Enrollment) Equal

func (e Enrollment) Equal(other Enrollment) bool

func (Enrollment) IsZero

func (e Enrollment) IsZero() bool

type Server

type Server struct {
	gen.UnimplementedEnrollmentApiServer
	// contains filtered or unexported fields
}

func LoadOrCreateServer

func LoadOrCreateServer(dir string, keyPEM []byte, logger *zap.Logger) (*Server, error)

LoadOrCreateServer will try to load an enrollment from disk. If successful, a server in the enrolled state is returned. Otherwise, a server in the unenrolled state is returned and new enrollments will be saved in the provided directory.

func NewServer

func NewServer(dir string, keyPEM []byte, logger *zap.Logger) *Server

NewServer creates an enrollment server, without attempting to load an existing enrollment. The new server will be in an un-enrolled state. New enrollments will be saved in the provided directory.

func (*Server) AutoRenew

func (es *Server) AutoRenew(ctx context.Context) error

func (*Server) Certs

func (es *Server) Certs() (*tls.Certificate, []*x509.Certificate, error)

Certs implements pki.Source and provides a certificate source that provides the latest known enrollment certificate. If the certificate source is used while this Server has no enrollment, an error will be returned. This is therefore not suitable for use in enrollment mode - use a self-signed certificate source (with the enrollment private key) instead.

func (*Server) CreateEnrollment

func (es *Server) CreateEnrollment(ctx context.Context, request *gen.CreateEnrollmentRequest) (*gen.Enrollment, error)

func (*Server) DeleteEnrollment

func (es *Server) DeleteEnrollment(ctx context.Context, request *gen.DeleteEnrollmentRequest) (*gen.Enrollment, error)

func (*Server) Enrollment

func (es *Server) Enrollment() (enrollment Enrollment, ok bool)

func (*Server) Enrollments

func (es *Server) Enrollments(ctx context.Context) <-chan Enrollment

Enrollments returns a chan that emits whenever the enrollment status or properties for this server change.

func (*Server) GetEnrollment

func (es *Server) GetEnrollment(_ context.Context, _ *gen.GetEnrollmentRequest) (*gen.Enrollment, error)

func (*Server) ManagerAddress

func (es *Server) ManagerAddress(ctx context.Context) <-chan string

ManagerAddress returns a chan that emits the manager address whenever it changes. Cancel the given context to stop listening for changes.

func (*Server) RequestRenew

func (es *Server) RequestRenew(ctx context.Context) error

RequestRenew asks the hub to renew our certificate. Errors if this node is not enrolled with a hub.

func (*Server) TestEnrollment

func (*Server) UpdateEnrollment

func (es *Server) UpdateEnrollment(ctx context.Context, request *gen.UpdateEnrollmentRequest) (*gen.Enrollment, error)

func (*Server) Wait

func (es *Server) Wait(ctx context.Context) (enrollment Enrollment, done bool)

Jump to

Keyboard shortcuts

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