Documentation
¶
Overview ¶
util loads a Configuration from a configuration file called 'config.yml' in a specified directory. The intended usage is for the user to setup a 'development' directory and a 'production' directory containing necessary configuration info.
The configuration uses the YAML format.
This code follows the singleton pattern, so that there is one Config variable that is used globally. The sync.Once library ensures that the variable is configured only once. We follow the pattern shown here: https://golangbyexample.com/singleton-design-pattern-go/
util was initially part of the certs package, unfortunately since these functions are needed by the config package, they must be placed here to avoid circular dependencies.
This package holds the various functions useful for basic, frequently called utilities. For example, converting PEM strings to x509 objects, etc.
Index ¶
- func ConfigInit(configDir string)
- func LogTest()
- func PackCertificateToPemBytes(cert *x509.Certificate) []byte
- func PackPrivateKeyToPemBytes(privKey *rsa.PrivateKey) []byte
- func PackPublicKeyToPemBytes(pubKey *rsa.PublicKey) []byte
- func SetUpLogger(level int, path string)
- func UnpackCSRFromBytes(csrData []byte) (*x509.CertificateRequest, error)
- func UnpackCSRFromPemString(csrPemString string) (*x509.CertificateRequest, error)
- func UnpackCertFromBytes(certData []byte) (*x509.Certificate, error)
- func UnpackCertFromPemString(cert string) (*x509.Certificate, error)
- func UnpackPrivateKeyFromBytes(privateKeyBytes []byte) (*rsa.PrivateKey, error)
- func UnpackPrivateKeyFromPemString(privateKeyPemString string) (*rsa.PrivateKey, error)
- func UnpackPublicKeyFromBytes(publicKeyBytes []byte) (*rsa.PublicKey, error)
- func UnpackPublicKeyFromPemString(publicKeyPemString string) (*rsa.PublicKey, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigInit ¶
func ConfigInit(configDir string)
ConfigInit is called early into the runtime of a program. This function initializes the config singleton and reads in all of the referenced files. After this function returns, Get() may be called to retrieve a copy of a pointer to the singleton.
func PackCertificateToPemBytes ¶
func PackCertificateToPemBytes(cert *x509.Certificate) []byte
PackCertificateToPemBytes takes an x.509.Certificate object and returns it as a ASN.1 DER formatted byte array.
func PackPrivateKeyToPemBytes ¶
func PackPrivateKeyToPemBytes(privKey *rsa.PrivateKey) []byte
PackPrivateKeyToPemBytes takes a pointer to an rsa.PrivateKey object and returns a byte array of that object with PKCS#1, ASN.1 DER formatting.
func PackPublicKeyToPemBytes ¶
PackPublicKeyToPemBytes takes a pointer to an rsa.PublicKey object and returns a byte array of that object with PKCS#1, ASN.1 DER formatting.
func SetUpLogger ¶
func UnpackCSRFromBytes ¶
func UnpackCSRFromBytes(csrData []byte) (*x509.CertificateRequest, error)
UnpackCSRFromBytes takes a CSR in a byte array formatted with either PEM or ASN.1 DER and formats it into an x509.CertificateRequest object.
func UnpackCSRFromPemString ¶
func UnpackCSRFromPemString(csrPemString string) (*x509.CertificateRequest, error)
UnpackCSRFromPemString takes a PEM formatted x509 Certificate Signing Request and returns a x509.CertificateRequest object from the given data.
func UnpackCertFromBytes ¶
func UnpackCertFromBytes(certData []byte) (*x509.Certificate, error)
UnpackCertFromBytes takes an x509 Certificate in a byte array formatted with either PEM or ASN.1 DER and formats it into an x509.Certificate object.
func UnpackCertFromPemString ¶
func UnpackCertFromPemString(cert string) (*x509.Certificate, error)
UnpackCertFromPemString takes a PEM formatted x509 Certificate and returns an x509.Certificate object from the given data.
func UnpackPrivateKeyFromBytes ¶
func UnpackPrivateKeyFromBytes(privateKeyBytes []byte) (*rsa.PrivateKey, error)
UnpackPrivateKeyFromBytes takes a PKCS#1 Private Key in a byte array formatted with either PEM or ASN.1 DER and formats it into an rsa.PrivateKey object and returns a pointer to that object.
func UnpackPrivateKeyFromPemString ¶
func UnpackPrivateKeyFromPemString(privateKeyPemString string) (*rsa.PrivateKey, error)
UnpackPrivateKeyFromPemString takes a PEM formatted PKCS#1 Private Key and returns a pointer to a rsa.PrivateKey object from the given data.
func UnpackPublicKeyFromBytes ¶
UnpackPublicKeyFromBytes takes a PKCS#1 Public Key in a byte array formatted with either PEM or ASN.1 DER and formats it into an rsa.PublicKey object and returns a pointer to that object.
Types ¶
type Config ¶
type Config struct { Name string `yaml:"name"` // name of the configuration, such as 'development' or 'production' Host string `yaml:"host"` Port int `yaml:"port"` Base string `yaml:"-"` DbConfig string `yaml:"database config"` RPDisplayName string `yaml:"RP display name"` RPID string `yaml:"RP ID"` RPOrigin string `yaml:"RP origin"` PublicKeyFile string `yaml:"public key"` // public key file path PrivateKeyFile string `yaml:"private key"` // private key file path RootCertificateFile string `yaml:"root certificate"` // location of the root certificate PublicKey *rsa.PublicKey `yaml:"-"` // public key PrivateKey *rsa.PrivateKey `yaml:"-"` // private key RootCertificate *x509.Certificate `yaml:"-"` // root certificate }
A Config is a singleton which reads in and stores the configuration file(s) needed to run the CA