-
Notifications
You must be signed in to change notification settings - Fork 6
/
certificate.go
202 lines (182 loc) · 4.91 KB
/
certificate.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package types
import (
"bytes"
"crypto/elliptic"
"crypto/x509"
"encoding/pem"
"time"
"github.com/aws/aws-sdk-go-v2/service/acmpca/types"
)
var SubordinatePath string
type CertificateParameters struct {
Region string
CaArn string
AssumeRole bool
RoleArn string
Validity int
RootCa bool
}
type Extensions struct {
KeyUsage x509.KeyUsage
ExtendedKeyUsage []x509.ExtKeyUsage
TemplateArn string
}
type Algorithm struct {
Algorithm x509.PublicKeyAlgorithm
KeySize map[int]any
Signature map[string]bool
SigningAlgorithm map[x509.SignatureAlgorithm]bool
}
type SignatureAlgorithm struct {
Common x509.SignatureAlgorithm
PCA types.SigningAlgorithm
}
type SigningRequest struct {
CSR *bytes.Buffer
PrivateKey *pem.Block
}
type SignedCertificate struct {
CertificatePath string
IntermediateCertificateChainPath string
RootCertificateChainPath string
}
type CertificateMetadata struct {
SerialNumber string
CommonName string
SubjectAlternativeName []string
ExpirationDate time.Time
IssuedDate time.Time
CaSerialNumber string
CertificateAuthorityArn string
Revoked bool
RevokedBy string
RevokeDate time.Time
}
type CertificateRequest struct {
CommonName string
SubjectAlternateNames []string
DistinguishedName DistinguishedName
SigningAlgorithm x509.SignatureAlgorithm
PublicKeyAlgorithm x509.PublicKeyAlgorithm
KeySize int
Output Output
}
type Output struct {
CertificateSigningRequest string
Certificate string
CertificateChain string
PrivateKey string
}
type DistinguishedName struct {
Country []string
Province []string
Locality []string
Organization []string
OrganizationalUnit []string
}
type EC2InstanceMetadata struct {
InstanceIdentityDocument []byte `json:"instance_identity_document"`
InstanceIdentitySignature []byte `json:"instance_identity_signature"`
}
type CertificateAuthority struct {
Certificate *x509.Certificate
AsymmetricKey *AsymmetricKey
SerialNumber string
CertificateAuthorityArn string
}
type AsymmetricKey interface {
KeyPair() any
Sign(data []byte) ([]byte, error)
}
var ValidSignatures = map[string]SignatureAlgorithm{
"SHA256WITHECDSA": {
Common: x509.ECDSAWithSHA256,
PCA: types.SigningAlgorithmSha256withecdsa,
},
"SHA384WITHECDSA": {
Common: x509.ECDSAWithSHA384,
PCA: types.SigningAlgorithmSha384withecdsa,
},
"SHA512WITHECDSA": {
Common: x509.ECDSAWithSHA512,
PCA: types.SigningAlgorithmSha512withecdsa,
},
"SHA256WITHRSA": {
Common: x509.SHA256WithRSA,
PCA: types.SigningAlgorithmSha256withrsa,
},
"SHA384WITHRSA": {
Common: x509.SHA384WithRSA,
PCA: types.SigningAlgorithmSha384withrsa,
},
"SHA512WITHRSA": {
Common: x509.SHA512WithRSA,
PCA: types.SigningAlgorithmSha512withrsa,
},
// TODO: Support Probabilistic Element to the Signature Scheme [SHA256WithRSAPSS]
}
var PublicKeyAlgorithms = map[string]Algorithm{
"RSA": {
Algorithm: x509.RSA,
KeySize: map[int]any{
2048: true,
4096: true,
},
Signature: map[string]bool{
"SHA256WITHRSA": true,
"SHA384WITHRSA": true,
"SHA512WITHRSA": true,
},
SigningAlgorithm: map[x509.SignatureAlgorithm]bool{
x509.SHA256WithRSA: true,
x509.SHA384WithRSA: true,
x509.SHA512WithRSA: true,
},
},
"ECDSA": {
Algorithm: x509.ECDSA,
KeySize: map[int]any{
256: elliptic.P256(),
384: elliptic.P384(),
521: elliptic.P521(),
},
Signature: map[string]bool{
"SHA256WITHECDSA": true,
"SHA384WITHECDSA": true,
"SHA512WITHECDSA": true,
},
SigningAlgorithm: map[x509.SignatureAlgorithm]bool{
x509.ECDSAWithSHA256: true,
x509.ECDSAWithSHA384: true,
x509.ECDSAWithSHA512: true,
},
},
// TODO: Support Ed25519
"Ed25519": {
Algorithm: x509.Ed25519,
KeySize: map[int]any{
256: true,
},
},
}
var CertificateRequestExtension = map[string]Extensions{
"EndEntityClientAuthCertificate": {
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtendedKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
TemplateArn: "arn:aws:acm-pca:::template/EndEntityClientAuthCertificate/V1",
},
"EndEntityServerAuthCertificate": {
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtendedKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
TemplateArn: "arn:aws:acm-pca:::template/EndEntityServerAuthCertificate/V1",
},
"CodeSigningCertificate": {
KeyUsage: x509.KeyUsageDigitalSignature,
ExtendedKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageCodeSigning},
TemplateArn: "arn:aws:acm-pca:::template/CodeSigningCertificate/V1",
},
}
var ValidNodeAttestation = map[string]bool{
"None": false,
"AWS": true,
}