forked from danikarik/ncanode-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
x509_info.go
132 lines (114 loc) · 3.72 KB
/
x509_info.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package ncanode
// KeyUsage is an alias of digital key type.
type KeyUsage string
// List of values KeyUsage can take.
const (
KeyUsageAuth KeyUsage = "AUTH"
KeyUsageSign KeyUsage = "SIGN"
KeyUsageUnknown KeyUsage = "UNKNOWN"
)
// Gender is an alias of person gender.
type Gender string
// List of values Gender can take.
const (
GenderMale Gender = "MALE"
GenderFemale Gender = "FEMALE"
)
// Subject holds person or organization data.
type Subject struct {
LastName string `json:"lastName,omitempty"`
Country string `json:"country,omitempty"`
CommonName string `json:"commonName,omitempty"`
Gender Gender `json:"gender,omitempty"`
Surname string `json:"surname,omitempty"`
Locality string `json:"locality,omitempty"`
DN string `json:"dn,omitempty"`
State string `json:"state,omitempty"`
BirthDate string `json:"birthDate,omitempty"`
IIN string `json:"iin,omitempty"`
BIN string `json:"bin,omitempty"`
Organization string `json:"organization,omitempty"`
Email string `json:"email,omitempty"`
}
// KeyUser is an alias of user type.
type KeyUser string
// List of values KeyUser can take.
const (
KeyUserIndividual KeyUser = "INDIVIDUAL"
KeyUserOrganization KeyUser = "ORGANIZATION"
KeyUserCEO KeyUser = "CEO"
KeyUserCanSign KeyUser = "CAN_SIGN"
KeyUserCanSignFinancial KeyUser = "CAN_SIGN_FINANCIAL"
KeyUserHR KeyUser = "HR"
KeyUserEmployee KeyUser = "EMPLOYEE"
KeyUserNCAPrivileges KeyUser = "NCA_PRIVILEGES"
KeyUserNCAAdmin KeyUser = "NCA_ADMIN"
KeyUserNCAManager KeyUser = "NCA_MANAGER"
KeyUserNCAOperator KeyUser = "NCA_OPERATOR"
)
// Status is an alias of revocation status.
type Status string
// List of values Status can take.
const (
StatusUnknown Status = "UNKNOWN"
StatusActive Status = "ACTIVE"
StatusRevoked Status = "REVOKED"
)
// Revocation holds data of revoked certificate.
type Revocation struct {
Reason interface{} `json:"revokationReason"`
Time Time `json:"revokationTime"`
RevokedBy string `json:"revokedBy,omitempty"`
Status Status `json:"status"`
}
// IsActive checks whether Revocation is active or not.
func (r *Revocation) IsActive() bool { return r.Status == StatusActive }
// Cert holds data of certificate.
type Cert struct {
Valid bool `json:"valid"`
NotAfter Time `json:"notAfter"`
NotBefore Time `json:"notBefore"`
Chain []Cert `json:"chain"`
KeyUsage KeyUsage `json:"keyUsage"`
SerialNumber string `json:"serialNumber"`
Subject Subject `json:"subject"`
SignAlg string `json:"signAlg"`
Sign string `json:"sign"`
PublicKey string `json:"publicKey"`
Issuer Subject `json:"issuer"`
KeyUser []KeyUser `json:"keyUser"`
OCSP *Revocation `json:"ocsp"`
CRL *Revocation `json:"crl"`
}
// X509Response describes json response from X509Info.
type X509Response struct {
apiResponse
Result Cert `json:"result"`
}
type x509Request struct {
Cert string `json:"cert"`
VerifyOCSP bool `json:"verifyOcsp"`
VerifyCRL bool `json:"verifyCrl"`
}
// X509Info returns certifacate info.
//
// See https://ncanode.kz/docs.php?go=68c0077b854fcdb23c567751b1329be3a34447c0
func (c *Client) X509Info(cert string, verifyOCSP, verifyCRL bool) (*X509Response, error) {
if cert == "" {
return nil, ErrInvalidRequestBody
}
body := apiRequest{
Version: c.version,
Method: "X509.info",
Params: x509Request{
Cert: cert,
VerifyOCSP: verifyOCSP,
VerifyCRL: verifyCRL,
},
}
var reply X509Response
if err := c.call(body, &reply); err != nil {
return nil, err
}
return &reply, nil
}