func (m *x509Manager) GenCert(config Config, claim Claim, c Cert) error {
	if err := checkName(c.Name); err != nil {
		return err
	}
	config.Serial++
	length := config.Length
	startTime := time.Now()
	endTime := startTime.AddDate(0, 0, config.Days)
	publicKey, privateKey, err := genKeyPair(length)
	if err != nil {
		return err
	}
	subjectKeyID, err := computeSubjectKeyID(publicKey)
	if err != nil {
		return err
	}
	cert := &x509.Certificate{
		SerialNumber: big.NewInt(config.Serial),
		NotBefore: startTime,
		NotAfter:  endTime,
		Subject: pkix.Name{
			CommonName:         claim.CommonName,
			Country:            claim.Country,
			Province:           claim.Province,
			Locality:           claim.Locality,
			Organization:       claim.Organization,
			OrganizationalUnit: claim.OrganizationalUnit,
			StreetAddress:      claim.StreetAddress,
			PostalCode:         claim.PostalCode,
		},
		DNSNames:       claim.DNSName,
		IPAddresses:    claim.IPAddress,
		EmailAddresses: claim.EmailAddress,
		BasicConstraintsValid: true,
		IsCA: true,
		SubjectKeyId:   subjectKeyID,
		AuthorityKeyId: subjectKeyID,
		KeyUsage:    x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign | x509.KeyUsageCRLSign,
		ExtKeyUsage: []x509.ExtKeyUsage{},
	}
	certData, err := x509.CreateCertificate(rand.Reader, cert, cert, publicKey, privateKey)
	if err != nil {
		return err
	}
	err = writePrivateKey(privateKey, config.Password, c.KeyPath())
	if err != nil {
		return err
	}
	err = writePemFile(pemTypeCert, certData, c.CertPath())
	if err != nil {
		return err
	}
	return nil
}
GenCert generates a new certificate
package pki
import (
	"crypto/rand"
	"crypto/x509"
	"crypto/x509/pkix"
	"errors"
	"math/big"
	"path/filepath"
	"time"
)
type (
	Manager interface {
		GenCert(Config, Claim, Cert) error
		GenCSR(Config, Claim, Cert) error
		SignCSR(Config, Cert, Config, Cert, TrustFunc) error
		VerifyCert(Cert, Cert, string) error
	}
	x509Manager struct{}
)
func NewX509Manager() Manager {
	return &x509Manager{}
}
func checkName(name string) error {
	if name == "" {
		return errors.New("Name is not set")
	}
	pattern := "./*/" + name + ".*"
	files, _ := filepath.Glob(pattern)  
	if len(files) > 0 {
		return errors.New(name + " already exists")
	}
	return nil
}