func NewSelfSignedx509Certificate()

in pkg/internal/crypto/crypto_linux.go [40:77]


func NewSelfSignedx509Certificate() (*SelfSignedCertificateKey, error) {
	privateKey, err := rsa.GenerateKey(rand.Reader, 1024)

	if err != nil {
		return nil, extensionerrors.AddStackToError(err)
	}

	certSubject := pkix.Name{
		Country:            []string{COUNTRY},
		Locality:           []string{LOCALITY},
		Province:           []string{STATE},
		Organization:       []string{ORGANIZATION},
		OrganizationalUnit: []string{ORGANIZATIONAL_UNIT},
		CommonName:         COMMON_NAME,
		SerialNumber:       "666",
	}
	certTemplate := x509.Certificate{
		Subject:               certSubject,
		NotBefore:             time.Unix(0, 0),
		NotAfter:              time.Now().Add(time.Hour * 24 * 365 * 10), // 10 years from now
		KeyUsage:              x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
		ExtKeyUsage:           []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
		BasicConstraintsValid: true,
		SerialNumber:          big.NewInt(666),
	}

	certBytes, err := x509.CreateCertificate(rand.Reader, &certTemplate, &certTemplate, &privateKey.PublicKey, privateKey)
	if err != nil {
		return nil, extensionerrors.AddStackToError(err)
	}

	x509Cert, err := x509.ParseCertificate(certBytes)
	if err != nil {
		return nil, extensionerrors.AddStackToError(err)
	}

	return &SelfSignedCertificateKey{Cert: *x509Cert, PrivKey: *privateKey}, nil
}