Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeContainer(container *Container) ([]byte, error)
- func EncodeData(data *Data) ([]byte, error)
- type CertManager
- func (m *CertManager) CreateRoot(privKey *rsa.PrivateKey) (*x509.Certificate, error)
- func (m *CertManager) GetLocal() (*x509.Certificate, error)
- func (m *CertManager) Prepare(csr *x509.CertificateRequest, license *Data) *x509.Certificate
- func (m *CertManager) SetLocal(cert *x509.Certificate) error
- func (m *CertManager) Sign(csr *x509.Certificate, privKey interface{}) (*x509.Certificate, error)
- type Container
- func (c *Container) IsValid(rootCertificate *x509.Certificate) (bool, error)
- func (c *Container) License(privKey *rsa.PrivateKey, rootCert *x509.Certificate) (*Data, error)
- func (c *Container) SetLicense(data *Data, pubKey *rsa.PublicKey) error
- func (c *Container) Sign(privateKey *rsa.PrivateKey, algorithm string) error
- type Data
- type EncryptedPayload
- type KeyManager
- type Metadata
- type Product
- type Signature
- type Template
Constants ¶
const CertificateType = "LITHIUM CERTIFICATE"
CertificateType is used to armour the public certificates of the server chain which issued the license.
const EncryptedLicenseLabel = "Lithium License Encryption Key"
EncryptedLicenseLabel is used to identify a key which is used for symmetric cryptographic operations, and which has been protected by an asymmetric encryption layer.
const EncryptedPayloadKeyLabel = "Lithium Encrypted Payload Key"
EncryptedPayloadKeyLabel is responsible for identifying an asymmetrically encrypted key used to perform symmetric encryption/decryption for encrypted payload objects.
const LicenseKeyType = "LITHIUM LICENSE KEY"
LicenseKeyType is used to armour the Lithium license encryption key after it has been encrypted and encoded.
const LicenseType = "LITHIUM LICENSE"
LicenseType is used to armour the Lithium license data when encrypted and encoded.
const PrivateKeyType = "LITHIUM PRIVATE KEY"
PrivateKeyType is used to armour the machine's private key when PEM encoded and encrypted.
const PublicKeyType = "LITHIUM PUBLIC KEY"
PublicKeyType is used to armour the machine's public key when PEM encoded.
const SignatureType = "LITHIUM SIGNATURE"
SignatureType is used to armour the Lithium license data's signature data.
Variables ¶
var KeySize = 2048
KeySize is the size of the RSA key used for license encryption and decryption. 2048 is probably secure enough for any general use, however you can reduce this to 1024 or increase to 4096 to balance generation speed and security.
var PrivateKeyName = "machine"
PrivateKeyName is the name of the private key file. It may be changed if you wish to enable multiple side-by-side installations with different keys. This is usually not necessary.
var PublicKeyName = "machine.pub"
PublicKeyName is the name of your public key file. It may be changed if you wish to enable multiple side-by-side installations with different keys. This is usually not necessary.
Functions ¶
func EncodeContainer ¶
EncodeContainer will encode a license container into its binary format.
func EncodeData ¶
EncodeData is responsible for encoding a license Data structure into its binary form for transfer between nodes or further processing.
Types ¶
type CertManager ¶
CertManager is responsible for tracking the local node's certificates.
func NewCertManager ¶
func NewCertManager(prod *Product) *CertManager
NewCertManager is responsible for creating a new certificate manager instance. This instance will be responsible for creating, signing and persisting product certificates.
func (*CertManager) CreateRoot ¶
func (m *CertManager) CreateRoot(privKey *rsa.PrivateKey) (*x509.Certificate, error)
CreateRoot will create a new, self-signed, root certificate.
func (*CertManager) GetLocal ¶
func (m *CertManager) GetLocal() (*x509.Certificate, error)
GetLocal retrieves the certificate used to sign derivative licenses for the current server.
func (*CertManager) Prepare ¶
func (m *CertManager) Prepare(csr *x509.CertificateRequest, license *Data) *x509.Certificate
Prepare is responsible for preparing an x509 certificate to match a specific license's constraints.
func (*CertManager) SetLocal ¶
func (m *CertManager) SetLocal(cert *x509.Certificate) error
SetLocal will update the stored local certificate to match the certificate provided.
func (*CertManager) Sign ¶
func (m *CertManager) Sign(csr *x509.Certificate, privKey interface{}) (*x509.Certificate, error)
Sign is responsible for signing a provided certificate using the current product's certificate and private key. This then enables consumers of the resulting certificate to trace the authenticity of that certificate back to a single root certificate.
type Container ¶
type Container struct { Payload EncryptedPayload Signature *Signature Certificates []*x509.Certificate }
Container represents
func ParseContainer ¶
ParseContainer is responsible for parsing a license file into its structured representation.
func (*Container) IsValid ¶
func (c *Container) IsValid(rootCertificate *x509.Certificate) (bool, error)
IsValid is responsible for determining whether a container is valid by validating the signature of its data and the certification chain of that signature.
func (*Container) License ¶
func (c *Container) License(privKey *rsa.PrivateKey, rootCert *x509.Certificate) (*Data, error)
License will extract and decode the license data from the encrypted license block in this container.
func (*Container) SetLicense ¶
SetLicense will set the license data for this container. You will need to sign that data using your private key once you are finished. The public key you provide is used to ensure that the encryption key used to protect the license data is accessible by the intended client.
type Data ¶
Data represents the data of a license entry. Specifically, it includes the protocol specific metadata and the custom license payload data.
func DecodeData ¶
DecodeData is responsible for decoding a previously encoded, binary license data object, into its native format for further use.
type EncryptedPayload ¶
type EncryptedPayload struct { Data []byte `json:"data"` Key []byte `json:"key"` IV []byte `json:"iv"` Algorithm string `json:"algorithm"` }
EncryptedPayload represents an encrypted license definition. It is encrypted using AES256 making use of the IV and Key provided. The Key itself is encrypted using RSA.
func (*EncryptedPayload) Decrypt ¶
func (p *EncryptedPayload) Decrypt(data interface{}, privKey *rsa.PrivateKey) error
Decrypt will transform an encrypted payload into the data variable you specify. This assumes that your provided private key matches the public key used to encrypt the symmetric key for the encrypted payload.
func (*EncryptedPayload) Encrypt ¶
func (p *EncryptedPayload) Encrypt(data interface{}, pubKey *rsa.PublicKey) error
Encrypt will encrypt the provided data in a reversible manner. The data is first serialized using JSON, following which it is encrypted using a symmetric encryption algorithm, adopting a cryptographically random key and initialization vector. The vector is stored alongside the data, and the key is encrypted using an asymmetric algorithm and the provided public key. Only someone in posession of the corresponding private key will be able to decrypt the symmetric encryption key, and thereby decrypt the contents of the data.
type KeyManager ¶
KeyManager provides a set of tools for accessing your machine's local key. This is tied to your machine and allows you to decrypt your license packs.
func NewKeyManager ¶
func NewKeyManager(machineCode []byte) *KeyManager
NewKeyManager returns a new KeyManager for your local machine using the given machine code to encrypt and decrypt local machine keys.
func (*KeyManager) GetPrivateKey ¶
func (m *KeyManager) GetPrivateKey() (*rsa.PrivateKey, error)
GetPrivateKey retrieves the private key for your local machine. This is used to decrypt license packs and sign child license files for later verification.
func (*KeyManager) GetPublicKey ¶
func (m *KeyManager) GetPublicKey() (*rsa.PublicKey, error)
GetPublicKey retrieves the public key for your local machine. This is used by upstream servers to identify and encrypt keys for your machine.
func (*KeyManager) ResetKeypair ¶
func (m *KeyManager) ResetKeypair() error
ResetKeypair will generate a new keypair for this machine, replacing the existing keypair and invalidating any licenses which were created for it.
type Metadata ¶
type Metadata struct { ID string `json:"id"` ActivatesOn time.Time `json:"activates"` ExpiresOn time.Time `json:"expires"` Pack map[string]*Template `json:"pack,omitempty"` }
Metadata is the protocol specific metadata describing a license, including its unique identifier, valid date range and any child licenses it may issue.
type Product ¶
type Product struct { ID string `json:"id"` Name string `json:"name"` Organization string `json:"organization"` }
Product tracks a product which makes use of Lithium for licensing purposes.