Cleanup
This commit is contained in:
parent
425987f350
commit
f241ebb750
|
@ -77,30 +77,7 @@ func generateCA() {
|
||||||
log.Fatalf("Error happened creating certificate: %v\n", err)
|
log.Fatalf("Error happened creating certificate: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
log.Printf("Generating %v/.config/cert400/ca.key...\n", home)
|
||||||
//fmt.Printf("Checking %v/.config/\n", home)
|
|
||||||
// _, err = os.Stat(home + "/.config")
|
|
||||||
// if err != nil {
|
|
||||||
// if os.IsNotExist(err) {
|
|
||||||
// fmt.Printf("$HOME/.config doesn't exist, creating...\n")
|
|
||||||
// os.Mkdir(home+"/.config", 0700)
|
|
||||||
// } else {
|
|
||||||
// log.Fatalf("Error happened accessing .config: %v", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//fmt.Printf("Checking %v/.config/cert400\n", home)
|
|
||||||
// _, err = os.Stat(home + "/.config/cert400")
|
|
||||||
// if err != nil {
|
|
||||||
// if os.IsNotExist(err) {
|
|
||||||
// fmt.Printf("$HOME/.config/cert400 doesn't exist, creating...\n")
|
|
||||||
// os.Mkdir(home+"/.config/cert400", 0700)
|
|
||||||
// } else {
|
|
||||||
// log.Fatalf("Error happened accessing cert400: %v\n", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fmt.Printf("Generating %v/.config/cert400/ca.key...\n", home)
|
|
||||||
// TODO: Check if keys already exist and warn the user about it
|
// TODO: Check if keys already exist and warn the user about it
|
||||||
key, err := os.OpenFile(home+"/.config/cert400/ca.key", os.O_WRONLY|os.O_CREATE, 0600)
|
key, err := os.OpenFile(home+"/.config/cert400/ca.key", os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -108,7 +85,7 @@ func generateCA() {
|
||||||
}
|
}
|
||||||
defer key.Close()
|
defer key.Close()
|
||||||
|
|
||||||
fmt.Printf("Generating %v/.config/cert400/ca.cert...\n", home)
|
log.Printf("Generating %v/.config/cert400/ca.cert...\n", home)
|
||||||
cert, err := os.OpenFile(home+"/.config/cert400/ca.crt", os.O_WRONLY|os.O_CREATE, 0600)
|
cert, err := os.OpenFile(home+"/.config/cert400/ca.crt", os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error happened opening file: %v\n", err)
|
log.Fatalf("Error happened opening file: %v\n", err)
|
||||||
|
@ -210,7 +187,7 @@ func generateCert(serNumber int, clientOrg string, clientCountry string,
|
||||||
Bytes: x509.MarshalPKCS1PrivateKey(certPrivKey),
|
Bytes: x509.MarshalPKCS1PrivateKey(certPrivKey),
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Printf("Generating %v/.config/cert400/clientCertificates/"+clientDomain+".key...\n", home)
|
log.Printf("Generating %v/.config/cert400/clientCertificates/"+clientDomain+".key...\n", home)
|
||||||
clientkey, err := os.OpenFile(home+"/.config/cert400/clientCertificates/"+clientDomain+".key", os.O_WRONLY|os.O_CREATE, 0600)
|
clientkey, err := os.OpenFile(home+"/.config/cert400/clientCertificates/"+clientDomain+".key", os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Error happened opening file: %v\n", err)
|
e := fmt.Errorf("Error happened opening file: %v\n", err)
|
||||||
|
@ -218,7 +195,7 @@ func generateCert(serNumber int, clientOrg string, clientCountry string,
|
||||||
}
|
}
|
||||||
defer clientkey.Close()
|
defer clientkey.Close()
|
||||||
|
|
||||||
fmt.Printf("Generating %v/.config/cert400/clientCertificates/"+clientDomain+".crt...\n", home)
|
log.Printf("Generating %v/.config/cert400/clientCertificates/"+clientDomain+".crt...\n", home)
|
||||||
clientcert, err := os.OpenFile(home+"/.config/cert400/clientCertificates/"+clientDomain+".crt", os.O_WRONLY|os.O_CREATE, 0600)
|
clientcert, err := os.OpenFile(home+"/.config/cert400/clientCertificates/"+clientDomain+".crt", os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Error happened opening file: %v\n", err)
|
e := fmt.Errorf("Error happened opening file: %v\n", err)
|
||||||
|
|
|
@ -74,6 +74,7 @@ func defaultHTML() {
|
||||||
|
|
||||||
func server() {
|
func server() {
|
||||||
defaultHTML()
|
defaultHTML()
|
||||||
|
log.SetPrefix("[CERT400] ")
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,7 +88,6 @@ func server() {
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html")
|
LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html")
|
||||||
|
|
||||||
//r.Static("/css", "./cmd/templates/css")
|
|
||||||
r.StaticFileFS("/css/style.css", "./templates/css/style.css", http.FS(templateFolder))
|
r.StaticFileFS("/css/style.css", "./templates/css/style.css", http.FS(templateFolder))
|
||||||
r.StaticFileFS("/favicon.ico", "./templates/ico/favicon.ico", http.FS(templateFolder))
|
r.StaticFileFS("/favicon.ico", "./templates/ico/favicon.ico", http.FS(templateFolder))
|
||||||
r.StaticFileFS("/favicon-32x32.png", "./templates/ico/favicon-32x32.png", http.FS(templateFolder))
|
r.StaticFileFS("/favicon-32x32.png", "./templates/ico/favicon-32x32.png", http.FS(templateFolder))
|
||||||
|
@ -161,7 +161,7 @@ func getDomainRequest(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
DNSName, _ := c.GetPostForm("formDNS")
|
DNSName, _ := c.GetPostForm("formDNS")
|
||||||
certDownload, keyDownload, err := generateCert(serNumInt, Org,
|
_, _, err = generateCert(serNumInt, Org,
|
||||||
Country, Province, Locality, StreetAddr,
|
Country, Province, Locality, StreetAddr,
|
||||||
PostCode, DNSName, ExpiryTimeInt, BitSizeInt)
|
PostCode, DNSName, ExpiryTimeInt, BitSizeInt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -180,9 +180,6 @@ func getDomainRequest(c *gin.Context) {
|
||||||
</b>
|
</b>
|
||||||
`, DNSName, DNSName)
|
`, DNSName, DNSName)
|
||||||
c.String(http.StatusOK, result)
|
c.String(http.StatusOK, result)
|
||||||
//c.File(keyDownload)
|
|
||||||
|
|
||||||
fmt.Println(certDownload, keyDownload)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,5 +192,4 @@ func returnCerts(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.FileAttachment(base+"/.config/cert400/clientCertificates/"+domain, domain)
|
c.FileAttachment(base+"/.config/cert400/clientCertificates/"+domain, domain)
|
||||||
//c.File(base + "/.config/cert400/clientCertificates/" + domain + ".key")
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue