func GetCertificate(destDir string, hostIP string) (string, string, error) {
	if isExisting(destDir) {
		err := printFingerprint(path.Join(destDir, "cert.pem"))
		if err != nil {
			return "", "", err
		}
		return path.Join(destDir, "cert.pem"), path.Join(destDir, "key.pem"), nil
	}
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return "", "", fmt.Errorf("Failed to generate private key: %v", err)
	}

	template, err := createTemplate(hostIP)
	if err != nil {
		return "", "", err
	}

	derBytes, err := generateCertificate(template, priv)
	if err != nil {
		return "", "", err
	}
	err = writeCertificate(derBytes, destDir)
	if err != nil {
		return "", "", err
	}

	err = writePrivateKey(priv, destDir)
	if err != nil {
		return "", "", err
	}

	log.Print("Successfully generated certificate. Send the Fingerprint to your clients.\n")
	printFingerprint(path.Join(destDir, "cert.pem"))
	return path.Join(destDir, "cert.pem"), path.Join(destDir, "key.pem"), nil
}
// GetCertificate generates a new self signed certificate in destDir
GetCertificate generates a new self signed certificate in destDir
// GetCertificate generates a new self signed certificate in destDir
func GetCertificate(destDir string, hostIP string) (string, string, error) {
	if isExisting(destDir) {
		err := printFingerprint(path.Join(destDir, "cert.pem"))
		if err != nil {
			return "", "", err
		}
		return path.Join(destDir, "cert.pem"), path.Join(destDir, "key.pem"), nil
	}
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return "", "", fmt.Errorf("Failed to generate private key: %v", err)
	}
	template, err := createTemplate(hostIP)
	if err != nil {
		return "", "", err
	}
	derBytes, err := generateCertificate(template, priv)
	if err != nil {
		return "", "", err
	}
	err = writeCertificate(derBytes, destDir)
	if err != nil {
		return "", "", err
	}
	err = writePrivateKey(priv, destDir)
	if err != nil {
		return "", "", err
	}
	log.Print("Successfully generated certificate. Send the Fingerprint to your clients.\n")
	printFingerprint(path.Join(destDir, "cert.pem"))
	return path.Join(destDir, "cert.pem"), path.Join(destDir, "key.pem"), nil
}
func GetCertificate ( destDir string , hostIP string ) ( string , string , error ) { if isExisting ( destDir ) { err := printFingerprint ( path . Join ( destDir , " " ) ) if err != nil { return " " , " " , err } return path . Join ( destDir , " " ) , path . Join ( destDir , " " ) , nil } priv , err := rsa . GenerateKey ( rand . Reader , 2048 ) if err != nil { return " " , " " , fmt . Errorf ( " " , err ) } template , err := createTemplate ( hostIP ) if err != nil { return " " , " " , err } derBytes , err := generateCertificate ( template , priv ) if err != nil { return " " , " " , err } err = writeCertificate ( derBytes , destDir ) if err != nil { return " " , " " , err } err = writePrivateKey ( priv , destDir ) if err != nil { return " " , " " , err } log . Print ( " \n " ) printFingerprint ( path . Join ( destDir , " " ) ) return path . Join ( destDir , " " ) , path . Join ( destDir , " " ) , nil }
GetCertificate generates a new self signed certificate in destDir
GetCertificate generates a new self signed certificate in destDir