func GenerateCSR() func(*cli.Context) error {
	return func(ctx *cli.Context) error {

		if _, err := os.Stat("key.pem"); !os.IsNotExist(err) {
			if !ctx.Bool("overwrite") {
				log.Fatalf("The file already exists. Won't overwrite unless --overwrite is specified.")
			}
		}

		subj := pkix.Name{
			CommonName: ctx.String("common-name"),
			Country:    []string{ctx.String("country")},
		}

		template := x509.CertificateRequest{
			Subject:            subj,
			DNSNames:           strings.Split(ctx.String("alternative-names"), ","),
			SignatureAlgorithm: x509.SHA256WithRSA,
		}

		keyBytes, err := createPrivateKey()
		if err != nil {
			log.Fatalf("Failed to generate private key: %v", err)
		}
		csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &template, keyBytes)

		if err != nil {
			log.Fatalf("Failed to create certificate request: %v", err)
		}

		certOut, err := os.Create("cert.csr")
		if err != nil {
			log.Fatalf("Failed to open cert.csr for writing: %v", err)
		}
		if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrBytes}); err != nil {
			log.Fatalf("Failed to write data to cert.pem: %v", err)
		}
		if err := certOut.Close(); err != nil {
			log.Fatalf("Error closing cert.csr: %v", err)
		}
		log.Print("wrote cert.csr\n")

		return nil
	}
}
// GenerateCSR creates a signing request and stores it in a file
GenerateCSR creates a signing request and stores it in a file
// GenerateCSR creates a signing request and stores it in a file
func GenerateCSR() func(*cli.Context) error {
	return func(ctx *cli.Context) error {
		if _, err := os.Stat("key.pem"); !os.IsNotExist(err) {
			if !ctx.Bool("overwrite") {
				log.Fatalf("The file already exists. Won't overwrite unless --overwrite is specified.")
			}
		}
		subj := pkix.Name{
			CommonName: ctx.String("common-name"),
			Country:    []string{ctx.String("country")},
		}
		template := x509.CertificateRequest{
			Subject:            subj,
			DNSNames:           strings.Split(ctx.String("alternative-names"), ","),
			SignatureAlgorithm: x509.SHA256WithRSA,
		}
		keyBytes, err := createPrivateKey()
		if err != nil {
			log.Fatalf("Failed to generate private key: %v", err)
		}
		csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &template, keyBytes)
		if err != nil {
			log.Fatalf("Failed to create certificate request: %v", err)
		}
		certOut, err := os.Create("cert.csr")
		if err != nil {
			log.Fatalf("Failed to open cert.csr for writing: %v", err)
		}
		if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrBytes}); err != nil {
			log.Fatalf("Failed to write data to cert.pem: %v", err)
		}
		if err := certOut.Close(); err != nil {
			log.Fatalf("Error closing cert.csr: %v", err)
		}
		log.Print("wrote cert.csr\n")
		return nil
	}
}
func GenerateCSR ( ) func ( * cli . Context ) error { return func ( ctx * cli . Context ) error { if _ , err := os . Stat ( " " ) ; ! os . IsNotExist ( err ) { if ! ctx . Bool ( " " ) { log . Fatalf ( " " ) } } subj := pkix . Name { CommonName : ctx . String ( " " ) , Country : [ ] string { ctx . String ( " " ) } , } template := x509 . CertificateRequest { Subject : subj , DNSNames : strings . Split ( ctx . String ( " " ) , " " ) , SignatureAlgorithm : x509 . SHA256WithRSA , } keyBytes , err := createPrivateKey ( ) if err != nil { log . Fatalf ( " " , err ) } csrBytes , err := x509 . CreateCertificateRequest ( rand . Reader , & template , keyBytes ) if err != nil { log . Fatalf ( " " , err ) } certOut , err := os . Create ( " " ) if err != nil { log . Fatalf ( " " , err ) } if err := pem . Encode ( certOut , & pem . Block { Type : " " , Bytes : csrBytes } ) ; err != nil { log . Fatalf ( " " , err ) } if err := certOut . Close ( ) ; err != nil { log . Fatalf ( " " , err ) } log . Print ( " \n " ) return nil } }
GenerateCSR creates a signing request and stores it in a file
GenerateCSR creates a signing request and stores it in a file