Fix #41 #45

Merged
bmartin5692 merged 4 commits from fix-#41 into master 2019-06-10 20:12:56 +02:00
2 changed files with 65 additions and 23 deletions
Showing only changes of commit 990a93e583 - Show all commits

View file

@ -1,7 +1,6 @@
package main
import (
"fmt"
"bufio"
"crypto/rand"
"crypto/rsa"
@ -10,25 +9,25 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"flag"
"fmt"
"log"
"math/big"
"net"
"os"
"time"
"flag"
"path/filepath"
"time"
)
var InBumperSan string
var OutCertDirectory string
var inBumperSan string
var outCertDirectory string
func main() {
func setFlags() {
exePath, _ := os.Executable()
currentDir, _ := os.Getwd()
//certPath will be current working directory by default
//certPath will be current working directory by defaultß
certPath, err := filepath.Abs(currentDir)
if err != nil {
log.Printf("Error: %v", err)
@ -40,17 +39,20 @@ func main() {
log.Printf("Error: %v", err)
}
var inBumperSan string
var outCertDirectory string
flag.StringVar(&inBumperSan, "inSAN", sanPath, "Input file containing a list of Subject Alternate Names (line separated)")
flag.StringVar(&outCertDirectory, "out", certPath, "Directory to output certificates to")
flag.StringVar(&InBumperSan, "inSAN", sanPath, "Input file containing a list of Subject Alternate Names (line separated)")
flag.StringVar(&OutCertDirectory, "out", certPath, "Directory to output certificates to")
flag.Parse()
}
func main() {
setFlags()
fmt.Printf("-------- Create_Certs --------\n")
//get absolute path
outCertDirectory, _ = filepath.Abs(outCertDirectory)
outCertDirectory, _ := filepath.Abs(OutCertDirectory)
dexists, isdfile := pathExistsType(outCertDirectory)
if !dexists {
log.Fatalf("Certs directory doesn't exist: %v", outCertDirectory)
@ -60,7 +62,7 @@ func main() {
}
//get absolute path
inBumperSan, _ = filepath.Abs(inBumperSan)
inBumperSan, _ := filepath.Abs(InBumperSan)
bexists, isbfile := pathExistsType(inBumperSan)
if !bexists {
log.Printf("Bumper SAN doesn't exist, certificate won't contain Subject Alternate Names: %v\n", inBumperSan)
@ -108,7 +110,6 @@ func make_CA(outCertDirectory string) {
log.Fatalf("Create ca failed: %v", err)
}
// Public key
certOut, err := os.Create(filepath.Join(outCertDirectory, "ca.crt"))
if err != nil {

View file

@ -0,0 +1,41 @@
package main
import (
"flag"
"os"
"testing"
)
func TestArgs(t *testing.T) {
orArgs := os.Args
flag.CommandLine = flag.NewFlagSet(orArgs[0], flag.ContinueOnError)
os.Args = []string{"cmd", "-inSAN", "123"}
setFlags()
if InBumperSan != "123" {
t.Error("InBumperSan not set by arg")
}
flag.CommandLine = flag.NewFlagSet(orArgs[0], flag.ContinueOnError)
os.Args = []string{"cmd", "-out", "456"}
setFlags()
if OutCertDirectory != "456" {
t.Error("Out path not set by arg")
}
flag.CommandLine = flag.NewFlagSet(orArgs[0], flag.ContinueOnError)
os.Args = []string{"cmd", "-inSAN", "san1", "-out", "out2"}
setFlags()
if InBumperSan != "san1" {
t.Error("InBumperSan not set by arg")
}
if OutCertDirectory != "out2" {
t.Error("Out path not set by arg")
}
os.Args = orArgs
}