license

package
v5.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 13 Imported by: 0

README

License package

License Generation

package main

import (
	"fmt"
	"io/ioutil"
	"time"

	"github.com/myrteametrics/myrtea-sdk/v5/license"
)

func main() {
	data := license.NewMyrteaLicenseData("Myrtea Client", "Test Projet", "Myrtea",
		"myrtea@myrteametrics.com", 5*time.Second, "Myrtea Issuer")
	license, err := license.Generate(data, "license/testdata/license-signing-key.pem")
	if err != nil {
        fmt.Println(err)
        return
	}

	err = ioutil.WriteFile("myrtea-license.key", []byte(license), 0644)
	if err != nil {
        fmt.Println(err)
        return
    }
    // [...]
}

License Validation

package main

import (
	"fmt"

	"github.com/myrteametrics/myrtea-sdk/v5/license"
)

var publicKey = []byte(`
-----BEGIN PUBLIC KEY-----
MIICITANBgkqhk[...]
-----END PUBLIC KEY-----
`)

func main() {
	data, err := license.Verify("myrtea-license.key", publicKey)
	if err != nil {
        fmt.Println(err)
        return
	}
    fmt.Println(data)
    // [...]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(licenseData ILicenseData, privateKeyData []byte) (string, error)

Generate encrypt and sign a license with a private key

func ReadPrivateKeyContents

func ReadPrivateKeyContents(contents []byte) (*rsa.PrivateKey, error)

ReadPrivateKeyContents reads a PEM-encoded X.509 RSA private key and returns a rsa.PrivateKey that can be used in GenerateFromPayload to generate a license key from a payload.

func ReadPublicKeyContents

func ReadPublicKeyContents(contents []byte) (*rsa.PublicKey, error)

ReadPublicKeyContents reads a PEM-encoded X.509 RSA public key and returns a rsa.PublicKey that can be used in VerifyAndExtractPayload to verify a license key and extract the included payload.

Types

type ILicenseData

type ILicenseData interface {
	Validate() (bool, error)
}

ILicenseData is a top interface for any potential licensing data which must be validated

func Verify

func Verify(licenseContent []byte, publicKeyData []byte) (ILicenseData, error)

Verify reads, decrypts and checks validity of a license file

type MyrteaLicenseData

type MyrteaLicenseData struct {
	Serial       string
	Company      string
	Project      string
	ContactName  string
	ContactEmail string
	DateIssued   time.Time
	DateExpires  time.Time
	IssuedBy     string
}

MyrteaLicenseData is the default data structure for Myrtea licenses

func NewMyrteaLicenseData

func NewMyrteaLicenseData(company string, project string, contactName string, contactEmail string,
	duration time.Duration, issuedBy string) MyrteaLicenseData

NewMyrteaLicenseData returns a new filled MyrteaLicenseData object

func (MyrteaLicenseData) Validate

func (ld MyrteaLicenseData) Validate() (bool, error)

Validate checks if the license is valid. A Myrtea license is valid if : * It's not expired (DateExpires < Now)

Jump to

Keyboard shortcuts

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