-
Notifications
You must be signed in to change notification settings - Fork 0
/
ca.go
90 lines (72 loc) · 1.79 KB
/
ca.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package ejbca
import (
"encoding/json"
"fmt"
"log"
)
func (c *RESTClient) GetEJBCACAList() (*CAInfo, error) {
log.Println("[INFO] Getting EJBCA CA list")
requestConfig := &request{
Method: "GET",
Endpoint: "v1/ca",
}
resp, err := c.sendRESTRequest(requestConfig)
if err != nil {
return nil, err
}
jsonResp := &CAInfo{}
err = json.NewDecoder(resp.Body).Decode(&jsonResp)
if err != nil {
return nil, err
}
return jsonResp, nil
}
// GetCACertificatePEM Deprecated
func (c *RESTClient) GetCACertificatePEM(subjectDn string) error {
log.Printf("[INFO] Downloading CA certificate with subject DN %s", subjectDn)
endpoint := fmt.Sprintf("v1/ca/%s/certificate/download", subjectDn)
requestConfig := &request{
Method: "GET",
Endpoint: endpoint,
}
_, err := c.sendRESTRequest(requestConfig)
if err != nil {
return err
}
return nil
}
func (c *RESTClient) GetCRLByIssuerDn(issuerDn string) (*LatestCRL, error) {
log.Printf("[INFO] Retreiving CRL from CA with issuer DN %s", issuerDn)
endpoint := fmt.Sprintf("v1/ca/%s/getLatestCrl", issuerDn)
requestConfig := &request{
Method: "GET",
Endpoint: endpoint,
}
resp, err := c.sendRESTRequest(requestConfig)
if err != nil {
return nil, err
}
jsonResp := &LatestCRL{}
err = json.NewDecoder(resp.Body).Decode(&jsonResp)
if err != nil {
return nil, err
}
return jsonResp, nil
}
func (c *RESTClient) GetV1CAStatus() (*V1CARestResourceStatus, error) {
log.Println("[INFO] Getting EJBCA V1 CA Endpoint Status")
requestConfig := &request{
Method: "GET",
Endpoint: "v1/ca/status",
}
resp, err := c.sendRESTRequest(requestConfig)
if err != nil {
return nil, err
}
jsonResp := &V1CARestResourceStatus{}
err = json.NewDecoder(resp.Body).Decode(&jsonResp)
if err != nil {
return nil, err
}
return jsonResp, nil
}