Documentation ¶
Overview ¶
Package testenv with managing certificates for testing
Package testenv for creating mosquitto testing environment This requires that the mosquitto broker is installed.
Package testenv with simulated services for authentication and directory
Index ¶
- Constants
- func CreateCA() (caCert *x509.Certificate, caKey *ecdsa.PrivateKey)
- func CreateTlsCert(cn string, ou string, isServer bool, clientKey *ecdsa.PrivateKey, ...) (tlscert *tls.Certificate)
- func CreateX509Cert(cn string, ou string, isServer bool, pubKey *ecdsa.PublicKey, ...) (cert *x509.Certificate, derBytes []byte, err error)
- func SaveCerts(testCerts *TestCerts, certFolder string)
- func StartMosquitto(testCerts *TestCerts, configFolder string) (mqCmd *exec.Cmd, err error)
- func StartServices(certs *TestCerts) *http.Server
- func StopMosquitto(cmd *exec.Cmd, tempFolder string)
- type TestCerts
Constants ¶
const ( MqttPortUnpw = 9883 MqttPortCert = 9884 MqttPortWS = 9885 )
MQTT ports for test environment in the 9xxx range
const OUDevice = "iotdevice"
const OUPlugin = "plugin"
FIXME: These OU names must match that in certsetup on the server side
const ServerAddress = "127.0.0.1"
Variables ¶
This section is empty.
Functions ¶
func CreateCA ¶
func CreateCA() (caCert *x509.Certificate, caKey *ecdsa.PrivateKey)
CreateCA generates the CA keys with certificate for testing not intended for production
func CreateTlsCert ¶
func CreateTlsCert(cn string, ou string, isServer bool, clientKey *ecdsa.PrivateKey, caCert *x509.Certificate, caKey *ecdsa.PrivateKey) (tlscert *tls.Certificate)
CreateTlsCert generates the certificate with keys, signed by the CA, valid for 127.0.0.1 intended for testing, not for production
cn is the certificate common name, usually the client ID or server hostname ou the organization isServer if set allow key usage of ServerAuth instead of ClientAuth clientKey is the client's private key for this certificate caCert and caKey is the signing CA
func CreateX509Cert ¶
func CreateX509Cert(cn string, ou string, isServer bool, pubKey *ecdsa.PublicKey, caCert *x509.Certificate, caKey *ecdsa.PrivateKey) (cert *x509.Certificate, derBytes []byte, err error)
CreateX509Cert generates a x509 certificate with keys, signed by the CA, valid for 127.0.0.1 intended for testing, not for production
cn is the certificate common name, usually the client ID or server hostname ou the organization isServer if set allow key usage of ServerAuth instead of ClientAuth pubKey is the owner public key for this certificate caCert and caKey is the signing CA
func SaveCerts ¶
SaveCerts saves the given CA and mosquitto server key and certificates as PEM files If the certFolder doesn't exist it will be created with permissions 700
func StartMosquitto ¶
StartMosquitto create a test environment with a mosquitto broker on localhost for the given home folder This:
- Set logging to info
- create the cert/config folder if it doesn't exist
- Saves the CA, server and client certificates in the cert/config folder
- Generates a mosquitto configuration in the cert/config folder
- Launches a mosquitto broker for testing.
mqCmd.Process.Kill() to end the mosquitto broker
testCerts are the certificates to use. configFolder to store certificates and configuration. Will be created if it doesn't exist.
Returns the mosquitto process, the temp folder for cleanup and error code in case of failure
func StartServices ¶
StartServices starts a TLS server and listens for auth and dir requests
func StopMosquitto ¶
StopMosquitto stops the mosquitto broker and cleans up the test environment
cmd is the command returned by StartMosquitto tempFolder is the folder returned by StartMosquitto. This will be deleted. Use "" to keep it
Types ¶
type TestCerts ¶
type TestCerts struct { CaCert *x509.Certificate CaKey *ecdsa.PrivateKey ServerKey *ecdsa.PrivateKey DeviceKey *ecdsa.PrivateKey PluginKey *ecdsa.PrivateKey ServerCert *tls.Certificate PluginCert *tls.Certificate DeviceCert *tls.Certificate }
TestCerts contain test certificates for CA, server and plugin (client)
func CreateCertBundle ¶
func CreateCertBundle() TestCerts
CreateCertBundle creates new certificates for CA, Server, Plugin and Thing Device testing The server cert is valid for localhost only
this returns the x509 and tls certificates