/
CertCheck.go
49 lines (44 loc) · 1.4 KB
/
CertCheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package functions
import (
"flag"
"fmt"
"os"
"time"
)
var (
host = flag.String("host", "", "Comma-separated hostnames and IPs to generate a certificate for")
validFrom = flag.String("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011")
validFor = flag.Duration("duration", 365*24*time.Hour, "Duration that certificate is valid for")
isCA = flag.Bool("ca", false, "whether this cert should be its own Certificate Authority")
rsaBits = flag.Int("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set")
ecdsaCurve = flag.String("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256 (recommended), P384, P521")
ed25519Key = flag.Bool("ed25519", false, "Generate an Ed25519 key")
)
func CertCheck() string {
certCheckOk := false
certDir := "/tmp/cert"
if _, err := os.Stat("/cert/key.pem"); err == nil {
fmt.Printf("/cert/key.pem exists\n")
certCheckOk = true
} else {
fmt.Printf("/cert/key.pem not exist\n")
certCheckOk = false
}
if certCheckOk == true {
if _, err := os.Stat("/cert/cert.pem"); err == nil {
fmt.Printf("/cert/cert.pem exists\n")
certCheckOk = true
} else {
fmt.Printf("/cert/cert.pem not exist\n")
certCheckOk = false
}
}
if certCheckOk == true {
certDir = "/cert"
} else {
fmt.Printf("Self certs will be used\n")
certDir = "/tmp/cert"
SslCertGenerate()
}
return certDir
}