|
@@ -5,8 +5,8 @@ import (
|
|
"github.com/SongZihuan/MyCA/src/cert"
|
|
"github.com/SongZihuan/MyCA/src/cert"
|
|
"github.com/SongZihuan/MyCA/src/ica"
|
|
"github.com/SongZihuan/MyCA/src/ica"
|
|
"github.com/SongZihuan/MyCA/src/rootca"
|
|
"github.com/SongZihuan/MyCA/src/rootca"
|
|
|
|
+ "github.com/SongZihuan/MyCA/src/sysinfo"
|
|
"github.com/SongZihuan/MyCA/src/utils"
|
|
"github.com/SongZihuan/MyCA/src/utils"
|
|
- "math/big"
|
|
|
|
"net"
|
|
"net"
|
|
"net/mail"
|
|
"net/mail"
|
|
"net/url"
|
|
"net/url"
|
|
@@ -67,54 +67,116 @@ func CreateRCA() {
|
|
notBefore := time.Now()
|
|
notBefore := time.Now()
|
|
notAfter := notBefore.Add(validity)
|
|
notAfter := notBefore.Add(validity)
|
|
|
|
|
|
- caCert, key, err := rootca.CreateRCA(cryptoType, keyLength, org, cn, notBefore, notAfter)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("Error:", err)
|
|
|
|
- return
|
|
|
|
|
|
+ ocspURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your OCSP Server URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ocspURLs = append(ocspURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ issurURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your Issuing Certificate URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ issurURLs = append(issurURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ crlURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your CRL Distribution Points (URL) [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ crlURLs = append(crlURLs, u.String())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- dirPath := path.Join(home, "rca", fmt.Sprintf("%s-%s", caCert.Subject.Organization[0], caCert.Subject.CommonName))
|
|
|
|
|
|
+ fmt.Printf("Set a password for private key [empty is no password]: ")
|
|
|
|
+ password := ReadPassword()
|
|
|
|
+
|
|
|
|
+ org, cn = sysinfo.CreateCASubject(org, cn)
|
|
|
|
+
|
|
|
|
+ dirPath := path.Join(home, "rca", fmt.Sprintf("%s-%s", org, cn))
|
|
|
|
+ infoFile := path.Join(dirPath, "rca-info.gob")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain2Path := path.Join(dirPath, "fullchain.cer")
|
|
fullchain2Path := path.Join(dirPath, "fullchain.cer")
|
|
- serialNumberPath := path.Join(dirPath, "serial.num")
|
|
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
|
|
|
|
- if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
|
|
- fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYesMust() {
|
|
|
|
|
|
+ if utils.IsExists(dirPath) {
|
|
|
|
+ fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultNoPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Printf("Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultYesPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Set a password for private key: ")
|
|
|
|
- password := ReadPassword()
|
|
|
|
|
|
+ err := os.MkdirAll(dirPath, 0600)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- err = os.MkdirAll(dirPath, 0600)
|
|
|
|
|
|
+ caCert, key, rcaInfo, err := rootca.CreateRCA(infoFile, cryptoType, keyLength, org, cn, ocspURLs, issurURLs, crlURLs, notBefore, notAfter)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SaveCertificate(caCert, []byte{}, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
|
|
+ err = rcaInfo.SaveRCAInfo()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SavePrivateKey(key, password, keyPath)
|
|
|
|
|
|
+ err = utils.SaveCertificate(caCert, []byte{}, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.WriteBigIntToFile(serialNumberPath, big.NewInt(0))
|
|
|
|
|
|
+ err = utils.SavePrivateKey(key, password, keyPath)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
@@ -124,7 +186,7 @@ func CreateRCA() {
|
|
}
|
|
}
|
|
|
|
|
|
func CreateICAFromRCA() {
|
|
func CreateICAFromRCA() {
|
|
- rcaCert, rcaKey, rcaFullchain, rcaSerialNumber, err := LoadRCA()
|
|
|
|
|
|
+ rcaCert, rcaKey, rcaFullchain, rcaInfo, err := LoadRCA()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err.Error())
|
|
fmt.Println("Error:", err.Error())
|
|
return
|
|
return
|
|
@@ -167,66 +229,122 @@ func CreateICAFromRCA() {
|
|
fmt.Printf("Common Name: ")
|
|
fmt.Printf("Common Name: ")
|
|
cn := ReadString()
|
|
cn := ReadString()
|
|
|
|
|
|
|
|
+ org, cn = sysinfo.CreateCASubject(org, cn)
|
|
|
|
+
|
|
fmt.Printf("Validity: ")
|
|
fmt.Printf("Validity: ")
|
|
validity := ReadTimeDuration(time.Hour * 24 * 365 * 5)
|
|
validity := ReadTimeDuration(time.Hour * 24 * 365 * 5)
|
|
|
|
|
|
notBefore := time.Now()
|
|
notBefore := time.Now()
|
|
notAfter := notBefore.Add(validity)
|
|
notAfter := notBefore.Add(validity)
|
|
|
|
|
|
- caCert, key, err := ica.CreateICA(cryptoType, keyLength, org, cn, notBefore, notAfter, rcaSerialNumber, rcaCert, rcaKey)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("Error:", err)
|
|
|
|
- return
|
|
|
|
|
|
+ selfOcspURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your OCSP Server URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ selfOcspURLs = append(selfOcspURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ selfIssurURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your Issuing Certificate URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ selfIssurURLs = append(selfIssurURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ crlURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your CRL Distribution Points (URL) [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ crlURLs = append(crlURLs, u.String())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- dirPath := path.Join(home, "ica", fmt.Sprintf("%s-%s", caCert.Subject.Organization[0], caCert.Subject.CommonName))
|
|
|
|
|
|
+ fmt.Printf("Set a password for private key: ")
|
|
|
|
+ password := ReadPassword()
|
|
|
|
+
|
|
|
|
+ dirPath := path.Join(home, "ica", fmt.Sprintf("%s-%s", org, cn))
|
|
|
|
+ infoFile := path.Join(dirPath, "rca-info.gob")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain2Path := path.Join(dirPath, "fullchain.cer")
|
|
fullchain2Path := path.Join(dirPath, "fullchain.cer")
|
|
- serialNumberPath := path.Join(dirPath, "serial.num")
|
|
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
|
|
|
|
- if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
|
|
- fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYesMust() {
|
|
|
|
|
|
+ if utils.IsExists(dirPath) {
|
|
|
|
+ fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultNoPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Printf("Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultYesPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Set a password for private key: ")
|
|
|
|
- password := ReadPassword()
|
|
|
|
-
|
|
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SaveCertificate(caCert, rcaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
|
|
+ caCert, key, icaInfo, err := ica.CreateICA(infoFile, rcaInfo, cryptoType, keyLength, org, cn, selfOcspURLs, selfIssurURLs, crlURLs, notBefore, notAfter, rcaCert, rcaKey)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SavePrivateKey(key, password, keyPath)
|
|
|
|
|
|
+ err = icaInfo.SaveICAInfo()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.WriteBigIntToFile(serialNumberPath, big.NewInt(0))
|
|
|
|
|
|
+ err = utils.SaveCertificate(caCert, rcaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = rcaSerialNumber.Save()
|
|
|
|
|
|
+ err = utils.SavePrivateKey(key, password, keyPath)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
@@ -236,7 +354,7 @@ func CreateICAFromRCA() {
|
|
}
|
|
}
|
|
|
|
|
|
func CreateICAFromICA() {
|
|
func CreateICAFromICA() {
|
|
- icaCert, icaKey, icaFullchain, icaSerialNumber, err := LoadICA()
|
|
|
|
|
|
+ icaCert, icaKey, icaFullchain, icaInfo, err := LoadICA()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err.Error())
|
|
fmt.Println("Error:", err.Error())
|
|
return
|
|
return
|
|
@@ -279,66 +397,122 @@ func CreateICAFromICA() {
|
|
fmt.Printf("Common Name: ")
|
|
fmt.Printf("Common Name: ")
|
|
cn := ReadString()
|
|
cn := ReadString()
|
|
|
|
|
|
|
|
+ org, cn = sysinfo.CreateCASubject(org, cn)
|
|
|
|
+
|
|
fmt.Printf("Validity: ")
|
|
fmt.Printf("Validity: ")
|
|
validity := ReadTimeDuration(time.Hour * 24 * 365 * 5)
|
|
validity := ReadTimeDuration(time.Hour * 24 * 365 * 5)
|
|
|
|
|
|
- notBefore := time.Now()
|
|
|
|
- notAfter := notBefore.Add(validity)
|
|
|
|
|
|
+ ocspURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your OCSP Server URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
|
|
- caCert, key, err := ica.CreateICA(cryptoType, keyLength, org, cn, notBefore, notAfter, icaSerialNumber, icaCert, icaKey)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("Error:", err)
|
|
|
|
- return
|
|
|
|
|
|
+ ocspURLs = append(ocspURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ issurURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your Issuing Certificate URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ issurURLs = append(issurURLs, u.String())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- dirPath := path.Join(home, "ica", fmt.Sprintf("%s-%s", caCert.Subject.Organization[0], caCert.Subject.CommonName))
|
|
|
|
|
|
+ crlURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your CRL Distribution Points (URL) [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ crlURLs = append(crlURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Printf("Set a password for private key: ")
|
|
|
|
+ password := ReadPassword()
|
|
|
|
+
|
|
|
|
+ notBefore := time.Now()
|
|
|
|
+ notAfter := notBefore.Add(validity)
|
|
|
|
+
|
|
|
|
+ dirPath := path.Join(home, "ica", fmt.Sprintf("%s-%s", org, cn))
|
|
|
|
+ infoFile := path.Join(dirPath, "ica-info.gob")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain2Path := path.Join(dirPath, "fullchain.cer")
|
|
fullchain2Path := path.Join(dirPath, "fullchain.cer")
|
|
- serialNumberPath := path.Join(dirPath, "serial.num")
|
|
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
|
|
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
- fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYesMust() {
|
|
|
|
|
|
+ fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultNoPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Printf("Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultYesPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Set a password for private key: ")
|
|
|
|
- password := ReadPassword()
|
|
|
|
-
|
|
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SaveCertificate(caCert, icaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
|
|
+ caCert, key, newIcaInfo, err := ica.CreateICA(infoFile, icaInfo, cryptoType, keyLength, org, cn, ocspURLs, issurURLs, crlURLs, notBefore, notAfter, icaCert, icaKey)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SavePrivateKey(key, password, keyPath)
|
|
|
|
|
|
+ err = newIcaInfo.SaveICAInfo()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.WriteBigIntToFile(serialNumberPath, big.NewInt(0))
|
|
|
|
|
|
+ err = utils.SaveCertificate(caCert, icaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = icaSerialNumber.Save()
|
|
|
|
|
|
+ err = utils.SavePrivateKey(key, password, keyPath)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
@@ -348,7 +522,7 @@ func CreateICAFromICA() {
|
|
}
|
|
}
|
|
|
|
|
|
func CreateUserCertFromRCA() {
|
|
func CreateUserCertFromRCA() {
|
|
- rcaCert, rcaKey, rcaFullchain, rcaSerialNumber, err := LoadRCA()
|
|
|
|
|
|
+ rcaCert, rcaKey, rcaFullchain, rcaInfo, err := LoadRCA()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err.Error())
|
|
fmt.Println("Error:", err.Error())
|
|
return
|
|
return
|
|
@@ -427,12 +601,12 @@ func CreateUserCertFromRCA() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Now we need to add your email (if you have), do you want to check it from DNS? [yes/no]")
|
|
|
|
- checkEmail := ReadYes()
|
|
|
|
|
|
+ fmt.Printf("Now we need to add your email (if you have), do you want to check it from DNS? ")
|
|
|
|
+ checkEmail := ReadBoolDefaultYesPrint()
|
|
StillAddEmail := true
|
|
StillAddEmail := true
|
|
if checkEmail {
|
|
if checkEmail {
|
|
- fmt.Printf("Now we will check the email when you add it, do you want to still add it when dns check failed? [yes/no]")
|
|
|
|
- StillAddEmail = ReadYes()
|
|
|
|
|
|
+ fmt.Printf("Now we will check the email when you add it, do you want to still add it when dns check failed? ")
|
|
|
|
+ StillAddEmail = ReadBoolDefaultYesPrint()
|
|
}
|
|
}
|
|
|
|
|
|
emails := make([]string, 0, 10)
|
|
emails := make([]string, 0, 10)
|
|
@@ -517,10 +691,10 @@ func CreateUserCertFromRCA() {
|
|
ipsR = append(ipsR, ipsN...)
|
|
ipsR = append(ipsR, ipsN...)
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Add the domain in cert? [yes/no]")
|
|
|
|
- if ReadYes() {
|
|
|
|
- fmt.Printf("Add the all of the domain (include which the resolve failed) in cert? [yes/no]")
|
|
|
|
- if ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Add the domain in cert? ")
|
|
|
|
+ if ReadBoolDefaultYesPrint() {
|
|
|
|
+ fmt.Printf("Add the all of the domain (include which the resolve failed) in cert? ")
|
|
|
|
+ if ReadBoolDefaultYesPrint() {
|
|
domains = append(domains, domainsR...)
|
|
domains = append(domains, domainsR...)
|
|
} else {
|
|
} else {
|
|
domains = append(domains, domainsRS...)
|
|
domains = append(domains, domainsRS...)
|
|
@@ -529,13 +703,13 @@ func CreateUserCertFromRCA() {
|
|
|
|
|
|
ips = append(ips, ipsR...)
|
|
ips = append(ips, ipsR...)
|
|
|
|
|
|
- userCert, key, err := cert.CreateCert(cryptoType, keyLength, org, cn, domains, ips, emails, urls, notBefore, notAfter, rcaSerialNumber, rcaCert, rcaKey)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("Error:", err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ org, cn = sysinfo.CreateCASubjectLong(org, cn, domains, ips, emails, urls)
|
|
|
|
|
|
- dirPath := path.Join(home, "cert", fmt.Sprintf("%s-%s-%s-%s", userCert.Subject.Organization[0], rcaCert.Subject.CommonName, userCert.Subject.CommonName, userCert.NotBefore.Format("2006-01-02-15-04-05")))
|
|
|
|
|
|
+ fmt.Printf("Set a password for private key: ")
|
|
|
|
+ password := ReadPassword()
|
|
|
|
+
|
|
|
|
+ dirPath := path.Join(home, "cert", fmt.Sprintf("%s-%s-%s-%s-%s", rcaCert.Subject.Organization[0], rcaCert.Subject.CommonName, org, cn, notBefore.Format("2006-01-02-15-04-05")))
|
|
|
|
+ infoPath := path.Join(dirPath, "cert-info.gob")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
@@ -543,39 +717,42 @@ func CreateUserCertFromRCA() {
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
|
|
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
- fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYesMust() {
|
|
|
|
|
|
+ fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultNoPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Printf("Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultYesPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Set a password for private key: ")
|
|
|
|
- password := ReadPassword()
|
|
|
|
-
|
|
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SaveCertificate(userCert, rcaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
|
|
+ userCert, key, certInfo, err := cert.CreateCert(infoPath, rcaInfo, cryptoType, keyLength, org, cn, domains, ips, emails, urls, notBefore, notAfter, rcaCert, rcaKey)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SavePrivateKey(key, password, keyPath)
|
|
|
|
|
|
+ err = certInfo.SaveCertInfo()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = rcaSerialNumber.Save()
|
|
|
|
|
|
+ err = utils.SaveCertificate(userCert, rcaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = utils.SavePrivateKey(key, password, keyPath)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
@@ -585,7 +762,7 @@ func CreateUserCertFromRCA() {
|
|
}
|
|
}
|
|
|
|
|
|
func CreateUserCertFromICA() {
|
|
func CreateUserCertFromICA() {
|
|
- icaCert, icaKey, icaFullchain, icaSerialNumber, err := LoadICA()
|
|
|
|
|
|
+ icaCert, icaKey, icaFullchain, icaInfo, err := LoadICA()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err.Error())
|
|
fmt.Println("Error:", err.Error())
|
|
return
|
|
return
|
|
@@ -661,12 +838,12 @@ func CreateUserCertFromICA() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Now we need to add your email (if you have), do you want to check it from DNS? [yes/no]")
|
|
|
|
- checkEmail := ReadYes()
|
|
|
|
|
|
+ fmt.Printf("Now we need to add your email (if you have), do you want to check it from DNS? ")
|
|
|
|
+ checkEmail := ReadBoolDefaultYesPrint()
|
|
StillAddEmail := true
|
|
StillAddEmail := true
|
|
if checkEmail {
|
|
if checkEmail {
|
|
- fmt.Printf("Now we will check the email when you add it, do you want to still add it when dns check failed? [yes/no]")
|
|
|
|
- StillAddEmail = ReadYes()
|
|
|
|
|
|
+ fmt.Printf("Now we will check the email when you add it, do you want to still add it when dns check failed? ")
|
|
|
|
+ StillAddEmail = ReadBoolDefaultYesPrint()
|
|
}
|
|
}
|
|
|
|
|
|
emails := make([]string, 0, 10)
|
|
emails := make([]string, 0, 10)
|
|
@@ -751,10 +928,10 @@ func CreateUserCertFromICA() {
|
|
ipsR = append(ipsR, ipsN...)
|
|
ipsR = append(ipsR, ipsN...)
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Add the domain in cert? [yes/no]")
|
|
|
|
- if ReadYes() {
|
|
|
|
- fmt.Printf("Add the all of the domain (include which the resolve failed) in cert? [yes/no]")
|
|
|
|
- if ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Add the domain in cert? ")
|
|
|
|
+ if ReadBoolDefaultYesPrint() {
|
|
|
|
+ fmt.Printf("Add the all of the domain (include which the resolve failed) in cert? ")
|
|
|
|
+ if ReadBoolDefaultYesPrint() {
|
|
domains = append(domains, domainsR...)
|
|
domains = append(domains, domainsR...)
|
|
} else {
|
|
} else {
|
|
domains = append(domains, domainsRS...)
|
|
domains = append(domains, domainsRS...)
|
|
@@ -763,13 +940,13 @@ func CreateUserCertFromICA() {
|
|
|
|
|
|
ips = append(ips, ipsR...)
|
|
ips = append(ips, ipsR...)
|
|
|
|
|
|
- userCert, key, err := cert.CreateCert(cryptoType, keyLength, org, cn, domains, ips, emails, urls, notBefore, notAfter, icaSerialNumber, icaCert, icaKey)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("Error:", err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ org, cn = sysinfo.CreateCASubjectLong(org, cn, domains, ips, emails, urls)
|
|
|
|
+
|
|
|
|
+ fmt.Printf("Set a password for private key: ")
|
|
|
|
+ password := ReadPassword()
|
|
|
|
|
|
- dirPath := path.Join(home, "cert", fmt.Sprintf("%s-%s-%s-%s", userCert.Subject.Organization[0], icaCert.Subject.CommonName, userCert.Subject.CommonName, userCert.NotBefore.Format("2006-01-02-15-04-05")))
|
|
|
|
|
|
+ dirPath := path.Join(home, "cert", fmt.Sprintf("%s-%s-%s-%s-%s", icaCert.Subject.Organization[0], icaCert.Subject.CommonName, org, cn, notBefore.Format("2006-01-02-15-04-05")))
|
|
|
|
+ infoPath := path.Join(dirPath, "cert-info.gob")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
@@ -777,39 +954,42 @@ func CreateUserCertFromICA() {
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
|
|
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
- fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYesMust() {
|
|
|
|
|
|
+ fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultNoPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Printf("Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultYesPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Set a password for private key: ")
|
|
|
|
- password := ReadPassword()
|
|
|
|
-
|
|
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
err = os.MkdirAll(dirPath, 0600)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SaveCertificate(userCert, icaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
|
|
+ userCert, key, certInfo, err := cert.CreateCert(infoPath, icaInfo, cryptoType, keyLength, org, cn, domains, ips, emails, urls, notBefore, notAfter, icaCert, icaKey)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = utils.SavePrivateKey(key, password, keyPath)
|
|
|
|
|
|
+ err = certInfo.SaveCertInfo()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- err = icaSerialNumber.Save()
|
|
|
|
|
|
+ err = utils.SaveCertificate(userCert, icaFullchain, cert1Path, cert2Path, fullchain1Path, fullchain2Path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = utils.SavePrivateKey(key, password, keyPath)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|
|
@@ -892,12 +1072,12 @@ func CreateUserCertSelf() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Now we need to add your email (if you have), do you want to check it from DNS? [yes/no]")
|
|
|
|
- checkEmail := ReadYes()
|
|
|
|
|
|
+ fmt.Printf("Now we need to add your email (if you have), do you want to check it from DNS? ")
|
|
|
|
+ checkEmail := ReadBoolDefaultYesPrint()
|
|
StillAddEmail := true
|
|
StillAddEmail := true
|
|
if checkEmail {
|
|
if checkEmail {
|
|
- fmt.Printf("Now we will check the email when you add it, do you want to still add it when dns check failed? [yes/no]")
|
|
|
|
- StillAddEmail = ReadYes()
|
|
|
|
|
|
+ fmt.Printf("Now we will check the email when you add it, do you want to still add it when dns check failed? ")
|
|
|
|
+ StillAddEmail = ReadBoolDefaultYesPrint()
|
|
}
|
|
}
|
|
|
|
|
|
emails := make([]string, 0, 10)
|
|
emails := make([]string, 0, 10)
|
|
@@ -982,10 +1162,10 @@ func CreateUserCertSelf() {
|
|
ipsR = append(ipsR, ipsN...)
|
|
ipsR = append(ipsR, ipsN...)
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Add the domain in cert? [yes/no]")
|
|
|
|
- if ReadYes() {
|
|
|
|
- fmt.Printf("Add the all of the domain (include which the resolve failed) in cert? [yes/no]")
|
|
|
|
- if ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Add the domain in cert? ")
|
|
|
|
+ if ReadBoolDefaultYesPrint() {
|
|
|
|
+ fmt.Printf("Add the all of the domain (include which the resolve failed) in cert? ")
|
|
|
|
+ if ReadBoolDefaultYesPrint() {
|
|
domains = append(domains, domainsR...)
|
|
domains = append(domains, domainsR...)
|
|
} else {
|
|
} else {
|
|
domains = append(domains, domainsRS...)
|
|
domains = append(domains, domainsRS...)
|
|
@@ -994,13 +1174,73 @@ func CreateUserCertSelf() {
|
|
|
|
|
|
ips = append(ips, ipsR...)
|
|
ips = append(ips, ipsR...)
|
|
|
|
|
|
- userCert, key, err := cert.CreateSelfCert(cryptoType, keyLength, org, cn, domains, ips, emails, urls, notBefore, notAfter)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("Error:", err)
|
|
|
|
- return
|
|
|
|
|
|
+ org, cn = sysinfo.CreateCASubjectLong(org, cn, domains, ips, emails, urls)
|
|
|
|
+
|
|
|
|
+ ocspURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your OCSP Server URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ocspURLs = append(ocspURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ issurURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your Issuing Certificate URL [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ issurURLs = append(issurURLs, u.String())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- dirPath := path.Join(home, "cert", fmt.Sprintf("Self-%s-%s-%s-%s", userCert.Subject.Organization[0], userCert.Subject.CommonName, userCert.Subject.CommonName, userCert.NotBefore.Format("2006-01-02-15-04-05")))
|
|
|
|
|
|
+ crlURLs := make([]string, 0, 10)
|
|
|
|
+ for {
|
|
|
|
+ fmt.Printf("Enter your CRL Distribution Points (URL) [empty to stop]: ")
|
|
|
|
+ res := ReadString()
|
|
|
|
+ if res == "" {
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ u, err := url.Parse(res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Error: not a valid URL (%s)\n", err.Error())
|
|
|
|
+ break
|
|
|
|
+ } else if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
+ fmt.Println("Error: not a valid HTTP/HTTPS URL")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ crlURLs = append(crlURLs, u.String())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Printf("Set a password for private key: ")
|
|
|
|
+ password := ReadPassword()
|
|
|
|
+
|
|
|
|
+ dirPath := path.Join(home, "cert", fmt.Sprintf("Self-%s-%s-%s", cn, org, notBefore.Format("2006-01-02-15-04-05")))
|
|
|
|
+ infoPath := path.Join(dirPath, "cert-info.gob")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert1Path := path.Join(dirPath, "cert.pem")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
cert2Path := path.Join(dirPath, "cert.cer")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
fullchain1Path := path.Join(dirPath, "fullchain.pem")
|
|
@@ -1008,21 +1248,30 @@ func CreateUserCertSelf() {
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
keyPath := path.Join(dirPath, "key.pem")
|
|
|
|
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
if utils.IsExists(cert1Path) || utils.IsExists(cert2Path) || utils.IsExists(fullchain1Path) || utils.IsExists(fullchain2Path) || utils.IsExists(keyPath) {
|
|
- fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYesMust() {
|
|
|
|
|
|
+ fmt.Printf("There is a duplicate file, it will be overwritten. Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultNoPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- fmt.Printf("Do you confirm to save the certificate? [yes/no] ")
|
|
|
|
- if !ReadYes() {
|
|
|
|
|
|
+ fmt.Printf("Do you confirm to save the certificate?")
|
|
|
|
+ if !ReadBoolDefaultYesPrint() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Set a password for private key: ")
|
|
|
|
- password := ReadPassword()
|
|
|
|
|
|
+ err := os.MkdirAll(dirPath, 0600)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- err = os.MkdirAll(dirPath, 0600)
|
|
|
|
|
|
+ userCert, key, certInfo, err := cert.CreateSelfCert(infoPath, cryptoType, keyLength, org, cn, domains, ips, emails, urls, ocspURLs, issurURLs, crlURLs, notBefore, notAfter)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = certInfo.SaveSelfCert()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
fmt.Println("Error:", err)
|
|
return
|
|
return
|