Fix #41 #45
5 changed files with 23 additions and 8 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
|
@ -24,14 +25,21 @@ var outCertDirectory string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
certPath, err := filepath.Abs("../../certs")
|
exePath, _ := os.Executable()
|
||||||
|
currentDir, _ := os.Getwd()
|
||||||
|
|
||||||
|
//certPath will be current working directory by default
|
||||||
|
certPath, err := filepath.Abs(currentDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: %v", err)
|
log.Printf("Error: %v", err)
|
||||||
}
|
}
|
||||||
sanPath, err := filepath.Abs("../Bumper_SAN.txt")
|
|
||||||
|
//sanPath will be exe path /Bumper_SAN.txt by default
|
||||||
|
sanPath, err := filepath.Abs(filepath.Join(exePath,"..","/Bumper_SAN.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: %v", err)
|
log.Printf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var inBumperSan string
|
var inBumperSan string
|
||||||
var outCertDirectory string
|
var outCertDirectory string
|
||||||
flag.StringVar(&inBumperSan, "inSAN", sanPath, "Input file containing a list of Subject Alternate Names (line separated)")
|
flag.StringVar(&inBumperSan, "inSAN", sanPath, "Input file containing a list of Subject Alternate Names (line separated)")
|
||||||
|
|
@ -39,36 +47,42 @@ func main() {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
fmt.Printf("-------- Create_Certs --------\n")
|
||||||
|
|
||||||
//get absolute path
|
//get absolute path
|
||||||
outCertDirectory, _ = filepath.Abs(outCertDirectory)
|
outCertDirectory, _ = filepath.Abs(outCertDirectory)
|
||||||
dexists, isdfile := pathExistsType(outCertDirectory)
|
dexists, isdfile := pathExistsType(outCertDirectory)
|
||||||
if !dexists {
|
if !dexists {
|
||||||
log.Fatal("Certs directory doesn't exist")
|
log.Fatalf("Certs directory doesn't exist: %v", outCertDirectory)
|
||||||
}
|
}
|
||||||
if isdfile {
|
if isdfile {
|
||||||
log.Fatal("Certs directory is a file, not a directory")
|
log.Fatalf("Certs directory is a file, not a directory: %v", outCertDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//get absolute path
|
//get absolute path
|
||||||
inBumperSan, _ = filepath.Abs(inBumperSan)
|
inBumperSan, _ = filepath.Abs(inBumperSan)
|
||||||
bexists, isbfile := pathExistsType(inBumperSan)
|
bexists, isbfile := pathExistsType(inBumperSan)
|
||||||
if !bexists {
|
if !bexists {
|
||||||
log.Print("Bumper SAN doesn't exist, certificate won't contain Subject Alternate Names")
|
log.Printf("Bumper SAN doesn't exist, certificate won't contain Subject Alternate Names: %v\n", inBumperSan)
|
||||||
|
inBumperSan = ""
|
||||||
}
|
}
|
||||||
if bexists && !isbfile {
|
if bexists && !isbfile {
|
||||||
log.Print("Bumper SAN is a directory instead of file, certificate won't contain Subject Alternate Names")
|
log.Printf("Bumper SAN is a directory instead of file, certificate won't contain Subject Alternate Names: %v\n", inBumperSan)
|
||||||
|
inBumperSan = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("-------- Starting Certificate Creation --------\n")
|
||||||
|
fmt.Printf("Options: \n Output Directory: %v\n Input SAN List: %v\n", outCertDirectory, inBumperSan)
|
||||||
|
|
||||||
make_CA(outCertDirectory)
|
make_CA(outCertDirectory)
|
||||||
signCert(outCertDirectory, inBumperSan)
|
signCert(outCertDirectory, inBumperSan)
|
||||||
|
|
||||||
|
fmt.Printf("-------- Certificate Creation Complete --------\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func make_CA(outCertDirectory string) {
|
func make_CA(outCertDirectory string) {
|
||||||
|
|
||||||
|
fmt.Printf("-------- Creating CA Cert --------\n")
|
||||||
priv, _ := rsa.GenerateKey(rand.Reader, 2048)
|
priv, _ := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
pub := &priv.PublicKey
|
pub := &priv.PublicKey
|
||||||
|
|
||||||
|
|
@ -116,6 +130,7 @@ func make_CA(outCertDirectory string) {
|
||||||
|
|
||||||
func signCert(outCertDirectory string, inBumperSan string) {
|
func signCert(outCertDirectory string, inBumperSan string) {
|
||||||
|
|
||||||
|
fmt.Printf("-------- Creating Server Cert --------\n")
|
||||||
// Load CA
|
// Load CA
|
||||||
catls, err := tls.LoadX509KeyPair(filepath.Join(outCertDirectory,"ca.crt"), filepath.Join(outCertDirectory,"ca.key"))
|
catls, err := tls.LoadX509KeyPair(filepath.Join(outCertDirectory,"ca.crt"), filepath.Join(outCertDirectory,"ca.key"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue