-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkmip.go
280 lines (235 loc) · 9.11 KB
/
kmip.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package kmip
import (
"fmt"
"github.com/ovh/kmip-go/ttlv"
)
var (
V1_0 = ProtocolVersion{ProtocolVersionMajor: 1, ProtocolVersionMinor: 0}
V1_1 = ProtocolVersion{ProtocolVersionMajor: 1, ProtocolVersionMinor: 1}
V1_2 = ProtocolVersion{ProtocolVersionMajor: 1, ProtocolVersionMinor: 2}
V1_3 = ProtocolVersion{ProtocolVersionMajor: 1, ProtocolVersionMinor: 3}
V1_4 = ProtocolVersion{ProtocolVersionMajor: 1, ProtocolVersionMinor: 4}
V2_0 = ProtocolVersion{ProtocolVersionMajor: 2, ProtocolVersionMinor: 0}
V2_1 = ProtocolVersion{ProtocolVersionMajor: 2, ProtocolVersionMinor: 1}
V2_2 = ProtocolVersion{ProtocolVersionMajor: 2, ProtocolVersionMinor: 2}
)
type ProtocolVersion struct {
ProtocolVersionMajor int32
ProtocolVersionMinor int32
}
func (v ProtocolVersion) Major() int {
return int(v.ProtocolVersionMajor)
}
func (v ProtocolVersion) Minor() int {
return int(v.ProtocolVersionMinor)
}
func (pv ProtocolVersion) String() string {
return fmt.Sprintf("%d.%d", pv.ProtocolVersionMajor, pv.ProtocolVersionMinor)
}
type CredentialValue struct {
UserPassword *CredentialValueUserPassword
Device *CredentialValueDevice
Attestation *CredentialValueAttestation
}
func (cred *CredentialValue) TagEncodeTTLV(e *ttlv.Encoder, tag int) {
e.TagAny(tag, cred.UserPassword)
e.TagAny(tag, cred.Device)
e.TagAny(tag, cred.Attestation)
}
func (cred *CredentialValue) decode(d *ttlv.Decoder, tag int, cType CredentialType) error {
switch cType {
case CredentialTypeUsernameAndPassword:
return d.TagAny(tag, &cred.UserPassword)
case CredentialTypeDevice:
return d.TagAny(tag, &cred.Device)
case CredentialTypeAttestation:
return d.TagAny(tag, &cred.Attestation)
}
return fmt.Errorf("Unsupported credential type %X", cType)
}
type CredentialValueUserPassword struct {
Username string
Password string `ttlv:",omitempty"`
}
type CredentialValueDevice struct {
DeviceSerialNumber string `ttlv:",omitempty"`
Password string `ttlv:",omitempty"`
DeviceIdentifier string `ttlv:",omitempty"`
NetworkIdentifier string `ttlv:",omitempty"`
MachineIdentifier string `ttlv:",omitempty"`
MediaIdentifier string `ttlv:",omitempty"`
}
type CredentialValueAttestation struct {
Nonce Nonce
AttestationType AttestationType
AttestationMeasurement []byte `ttlv:",omitempty"`
AttestationAssertion []byte `ttlv:",omitempty"`
}
type Credential struct {
CredentialType CredentialType
CredentialValue CredentialValue
}
func (kb *Credential) TagDecodeTTLV(d *ttlv.Decoder, tag int) error {
return d.Struct(tag, func(d *ttlv.Decoder) error {
if err := d.Any(&kb.CredentialType); err != nil {
return err
}
return kb.CredentialValue.decode(d, TagCredentialValue, kb.CredentialType)
})
}
type Authentication struct {
Credential Credential
// Starting from KMIP 1.2, Credential can be repeated
AdditionalCredential []Credential `ttlv:",version=v1.2.."`
}
type RevocationReason struct {
RevocationReasonCode RevocationReasonCode `ttlv:",omitempty"`
RevocationMessage string `ttlv:",omitempty"`
}
type MessageExtension struct {
VendorIdentification string
CriticalityIndicator bool
VendorExtension ttlv.Struct
}
type CryptographicParameters struct {
BlockCipherMode BlockCipherMode `ttlv:",omitempty"`
PaddingMethod PaddingMethod `ttlv:",omitempty"`
HashingAlgorithm HashingAlgorithm `ttlv:",omitempty"`
KeyRoleType KeyRoleType `ttlv:",omitempty"`
DigitalSignatureAlgorithm DigitalSignatureAlgorithm `ttlv:",omitempty,version=v1.2.."`
CryptographicAlgorithm CryptographicAlgorithm `ttlv:",omitempty,version=v1.2.."`
RandomIV *bool `ttlv:",version=v1.2.."`
IVLength int32 `ttlv:",omitempty,version=v1.2.."`
TagLength int32 `ttlv:",omitempty,version=v1.2.."`
FixedFieldLength int32 `ttlv:",omitempty,version=v1.2.."`
InvocationFieldLength int32 `ttlv:",omitempty,version=v1.2.."`
CounterLength int32 `ttlv:",omitempty,version=v1.2.."`
InitialCounterValue *int32 `ttlv:",version=v1.2.."`
SaltLength *int32 `ttlv:",version=v1.4.."`
MaskGenerator MaskGenerator `ttlv:",omitempty,version=v1.4.."`
MaskGeneratorHashingAlgorithm HashingAlgorithm `ttlv:",omitempty,version=v1.4.."`
PSource []byte `ttlv:",omitempty,version=v1.4.."`
TrailerField *int32 `ttlv:",version=v1.4.."`
}
type CryptographicDomainParameters struct {
Qlength int32 `ttlv:",omitempty"`
RecommendedCurve RecommendedCurve `ttlv:",omitempty"`
}
type KeyWrappingSpecification struct {
WrappingMethod WrappingMethod
EncryptionKeyInformation *EncryptionKeyInformation
MACSignatureKeyInformation *MACSignatureKeyInformation
AttributeName []AttributeName
EncodingOption EncodingOption `ttlv:",omitempty,version=v1.1.."`
}
type Link struct {
LinkType LinkType `ttlv:",omitempty"`
LinkedObjectIdentifier string `ttlv:",omitempty"`
}
type Digest struct {
HashingAlgorithm HashingAlgorithm
DigestValue []byte
KeyFormatType KeyFormatType `ttlv:",omitempty,version=1.1.."`
}
// Deprecated: deprecated as of kmip 1.1.
type CertificateIdentifier struct {
Issuer string `ttlv:",omitempty"`
SerialNumber string `ttlv:",omitempty"`
}
// Deprecated: deprecated as of kmip 1.1.
type CertificateSubject struct {
CertificateSubjectDistinguishedName string `ttlv:",omitempty"`
CertificateSubjectAlternativeName []string
}
// Deprecated: deprecated as of kmip 1.1.
type CertificateIssuer struct {
CertificateIssuerDistinguishedName string `ttlv:",omitempty"`
CertificateIssuerAlternativeName []string
}
type ApplicationSpecificInformation struct {
ApplicationNamespace string `ttlv:",omitempty"`
ApplicationData string `ttlv:",omitempty"` //TODO: Optional since kmip 1.3, not before.
}
type UsageLimits struct {
UsageLimitsTotal int64
UsageLimitsCount *int64
UsageLimitsUnit UsageLimitsUnit `ttlv:",omitempty"`
}
func (ul UsageLimits) Equals(other *UsageLimits) bool {
return other != nil &&
other.UsageLimitsTotal == ul.UsageLimitsTotal &&
other.UsageLimitsUnit == ul.UsageLimitsUnit &&
(other.UsageLimitsCount == nil && ul.UsageLimitsCount == nil ||
*other.UsageLimitsCount == *ul.UsageLimitsCount)
}
// KMIP 1.1.
type ExtensionInformation struct {
ExtensionName string
ExtensionTag int32 `ttlv:",omitempty"`
ExtensionType int32 `ttlv:",omitempty"`
}
type X_509CertificateIdentifier struct {
IssuerDistinguishedName []byte `ttlv:",omitempty"`
CertificateSerialNumber []byte `ttlv:",omitempty"`
}
type X_509CertificateSubject struct {
SubjectDistinguishedName []byte `ttlv:",omitempty"`
SubjectAlternativeName [][]byte
}
type X_509CertificateIssuer struct {
IssuerDistinguishedName []byte `ttlv:",omitempty"`
IssuerAlternativeName [][]byte
}
// KMIP 1.2.
type Nonce struct {
NonceID []byte
NonceValue []byte
}
type AlternativeName struct {
AlternativeNameValue string `ttlv:",omitempty"`
AlternativeNameType AlternativeNameType `ttlv:",omitempty"`
}
type KeyValueLocation struct {
KeyValueLocationValue string `ttlv:",omitempty"`
KeyValueLocationType KeyValueLocationType `ttlv:",omitempty"`
}
// KMIP 1.3.
type RNGParameters struct {
RNGAlgorithm RNGAlgorithm `ttlv:",omitempty"`
CryptographicAlgorithm CryptographicAlgorithm `ttlv:",omitempty"`
CryptographicLength int32 `ttlv:",omitempty"`
HashingAlgorithm HashingAlgorithm `ttlv:",omitempty"`
DRBGAlgorithm DRBGAlgorithm `ttlv:",omitempty"`
RecommendedCurve RecommendedCurve `ttlv:",omitempty"`
FIPS186Variation FIPS186Variation `ttlv:",omitempty"`
PredictionResistance *bool
}
type ProfileInformation struct {
ProfileName ProfileName
ServerURI string `ttlv:",omitempty"`
ServerPort int32 `ttlv:",omitempty"`
}
type ValidationInformation struct {
ValidationAuthorityType ValidationAuthorityType
ValidationAuthorityCountry string `ttlv:",omitempty"`
ValidationAuthorityURI string `ttlv:",omitempty"`
ValidationVersionMajor int32
ValidationVersionMinor *int32
ValidationType ValidationType
ValidationLevel int32
ValidationCertificateIdentifier string `ttlv:",omitempty"`
ValidationCertificateURI string `ttlv:",omitempty"`
ValidationVendorURI string `ttlv:",omitempty"`
ValidationProfile []string
}
type CapabilityInformation struct {
StreamingCapability *bool
AsynchronousCapability *bool
AttestationCapability *bool
BatchUndoCapability *bool `ttlv:",version=v1.4.."`
BatchContinueCapability *bool `ttlv:",version=v1.4.."`
UnwrapMode UnwrapMode `ttlv:",omitempty"`
DestroyAction DestroyAction `ttlv:",omitempty"`
ShreddingAlgorithm ShreddingAlgorithm `ttlv:",omitempty"`
RNGMode RNGMode `ttlv:",omitempty"`
}