cert

package
v0.0.0-...-88a629f Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetReceiverTLSConfig

func GetReceiverTLSConfig(cert *SelfSignedCert) (*tls.Config, error)

GetReceiverTLSConfig builds a tls.Config object for the receiver to use when establishing a TLS connection with the sender. It adds the receiver's public/ private key pair to the config's list of certificates.

func GetSenderTLSConfig

func GetSenderTLSConfig(certPEM []byte) *tls.Config

GetSenderTLSConfig builds a tls.Config object for the sender to use when establishing a TLS connection with the receiver. It adds the public key of the certificate authority that the receiver created to the config's collection of trusted certificate authorities.

func ReceiveFromReceiver

func ReceiveFromReceiver(addr _net.Addr, timeoutDuration uint) ([]byte, error)

ReceiveFromReceiver gets a TLS certificate from the receiver at the provided address through a TCP connection.

timeoutDuration is in seconds.

func SendToSender

func SendToSender(
	certificate *SelfSignedCert,
	port string,
	timeoutDuration uint,
) error

SendToSender establishes a TCP connection with the sender and sends a TLS certificate.

timeoutDuration is in seconds.

Types

type SelfSignedCert

type SelfSignedCert struct {
	// The certificate as PEM-encoded bytes.
	Bytes []byte

	// The private key as PEM-encoded bytes.
	SK []byte
}

SelfSignedCert stores an x509 certificate's pieces (the certificate itself as well as a private key) as PEM-encoded bytes.

func GenerateSelfSignedCert

func GenerateSelfSignedCert(ip net.IP) (*SelfSignedCert, error)

GenerateSelfSignedCert creates a self-signed x509 certificate to be used when establishing a TLS connection with the sender. The created certificate is valid for the device with the provided IPv4 address.

It generates a public/private key pair, uses those keys to build an x509 certificate, self-signs that certificate so the sender will trust it, and PEM-encodes that certificate and private key.

Inspired by https://golang.org/src/crypto/tls/generate_cert.go

Jump to

Keyboard shortcuts

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