Пример #1
0
func (lk LocalkubeServer) GenerateCerts() error {
	if !lk.shouldGenerateCACerts() {
		fmt.Println("Using these existing CA certs: ", lk.GetCAPublicKeyCertPath(), lk.GetCAPrivateKeyCertPath())
	} else {
		fmt.Println("Creating CA cert")
		if err := util.GenerateCACert(lk.GetCAPublicKeyCertPath(), lk.GetCAPrivateKeyCertPath()); err != nil {
			fmt.Println("Failed to create CA certs: ", err)
			return err
		}
	}

	ips, err := lk.getAllIPs()
	if err != nil {
		return err
	}

	if !lk.shouldGenerateCerts(ips) {
		fmt.Println("Using these existing certs: ", lk.GetPublicKeyCertPath(), lk.GetPrivateKeyCertPath())
		return nil
	}
	fmt.Println("Creating cert with IPs: ", ips)

	if err := util.GenerateSignedCert(lk.GetPublicKeyCertPath(), lk.GetPrivateKeyCertPath(), ips, util.GetAlternateDNS(lk.DNSDomain), lk.GetCAPublicKeyCertPath(), lk.GetCAPrivateKeyCertPath()); err != nil {
		fmt.Println("Failed to create certs: ", err)
		return err
	}

	return nil
}
Пример #2
0
func GenerateCerts(caCert, caKey, pub, priv string, ip net.IP) error {
	if !(util.CanReadFile(caCert) && util.CanReadFile(caKey)) {
		if err := util.GenerateCACert(caCert, caKey); err != nil {
			return err
		}
	}

	ips := []net.IP{ip, internalIP}
	if err := util.GenerateSignedCert(pub, priv, ips, util.GetAlternateDNS(util.DefaultDNSDomain), caCert, caKey); err != nil {
		return err
	}
	return nil
}