-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathexample_test.go
64 lines (52 loc) · 1.53 KB
/
example_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package goca_test
import (
"fmt"
"log"
"os"
"github.com/kairoaraujo/goca/v2"
)
func Example_minimal() {
// Define the GOCAPTH (Default is current dir)
os.Setenv("CAPATH", "/opt/GoCA/CA")
// RootCAIdentity for creation
rootCAIdentity := goca.Identity{
Organization: "GO CA Root Company Inc.",
OrganizationalUnit: "Certificates Management",
Country: "NL",
Locality: "Noord-Brabant",
Province: "Veldhoven",
Intermediate: false,
}
// Create the New Root CA or loads existent from disk ($CAPATH)
RootCA, err := goca.New("mycompany.com", rootCAIdentity)
if err != nil {
// Loads in case it exists
fmt.Println("Loading CA")
RootCA, err = goca.Load("gocaroot.nl")
if err != nil {
log.Fatal(err)
}
// Check the CA status and shows the CA Certificate
fmt.Println(RootCA.Status())
fmt.Println(RootCA.GetCertificate())
} else {
log.Fatal(err)
}
// Issue certificate for example intranet server
intranetIdentity := goca.Identity{
Organization: "Intranet Company Inc.",
OrganizationalUnit: "Global Intranet",
Country: "NL",
Locality: "Noord-Brabant",
Province: "Veldhoven",
Intermediate: false,
DNSNames: []string{"w3.intranet.example.com", "www.intranet.example.com"},
}
intranetCert, err := RootCA.IssueCertificate("intranet.example.com", intranetIdentity)
if err != nil {
log.Fatal(err)
}
fmt.Println(intranetCert.GetCertificate())
// Shows all CA Certificates
fmt.Println(RootCA.ListCertificates())
}