1
2
3 package x509limbo
4
5 import "encoding/json"
6 import "errors"
7 import "fmt"
8 import "reflect"
9 import "regexp"
10 import "time"
11
12 type ExpectedResult string
13
14 const ExpectedResultFAILURE ExpectedResult = "FAILURE"
15 const ExpectedResultSUCCESS ExpectedResult = "SUCCESS"
16
17 var enumValues_ExpectedResult = []interface{}{
18 "SUCCESS",
19 "FAILURE",
20 }
21
22
23 func (j *ExpectedResult) UnmarshalJSON(value []byte) error {
24 var v string
25 if err := json.Unmarshal(value, &v); err != nil {
26 return err
27 }
28 var ok bool
29 for _, expected := range enumValues_ExpectedResult {
30 if reflect.DeepEqual(v, expected) {
31 ok = true
32 break
33 }
34 }
35 if !ok {
36 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_ExpectedResult, v)
37 }
38 *j = ExpectedResult(v)
39 return nil
40 }
41
42 type Feature string
43
44 const FeatureDenialOfService Feature = "denial-of-service"
45 const FeatureHasCertPolicies Feature = "has-cert-policies"
46 const FeatureHasCrl Feature = "has-crl"
47 const FeatureHasMldsa Feature = "has-mldsa"
48 const FeatureHasPolicyConstraints Feature = "has-policy-constraints"
49 const FeatureMaxChainDepth Feature = "max-chain-depth"
50 const FeatureNameConstraintDn Feature = "name-constraint-dn"
51 const FeatureNoCertPolicies Feature = "no-cert-policies"
52 const FeaturePedanticPublicSuffixWildcard Feature = "pedantic-public-suffix-wildcard"
53 const FeaturePedanticRfc5280 Feature = "pedantic-rfc5280"
54 const FeaturePedanticSerialNumber Feature = "pedantic-serial-number"
55 const FeaturePedanticWebpkiEku Feature = "pedantic-webpki-eku"
56 const FeaturePedanticWebpkiSubscriberKey Feature = "pedantic-webpki-subscriber-key"
57 const FeatureRfc5280IncompatibleWithWebpki Feature = "rfc5280-incompatible-with-webpki"
58
59 var enumValues_Feature = []interface{}{
60 "has-policy-constraints",
61 "has-cert-policies",
62 "no-cert-policies",
63 "pedantic-public-suffix-wildcard",
64 "name-constraint-dn",
65 "pedantic-webpki-subscriber-key",
66 "pedantic-webpki-eku",
67 "pedantic-serial-number",
68 "max-chain-depth",
69 "pedantic-rfc5280",
70 "rfc5280-incompatible-with-webpki",
71 "denial-of-service",
72 "has-crl",
73 "has-mldsa",
74 }
75
76
77 func (j *Feature) UnmarshalJSON(value []byte) error {
78 var v string
79 if err := json.Unmarshal(value, &v); err != nil {
80 return err
81 }
82 var ok bool
83 for _, expected := range enumValues_Feature {
84 if reflect.DeepEqual(v, expected) {
85 ok = true
86 break
87 }
88 }
89 if !ok {
90 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_Feature, v)
91 }
92 *j = Feature(v)
93 return nil
94 }
95
96 type Importance string
97
98 const ImportanceCritical Importance = "critical"
99 const ImportanceHigh Importance = "high"
100 const ImportanceLow Importance = "low"
101 const ImportanceMedium Importance = "medium"
102 const ImportanceUndetermined Importance = "undetermined"
103
104 var enumValues_Importance = []interface{}{
105 "undetermined",
106 "low",
107 "medium",
108 "high",
109 "critical",
110 }
111
112
113 func (j *Importance) UnmarshalJSON(value []byte) error {
114 var v string
115 if err := json.Unmarshal(value, &v); err != nil {
116 return err
117 }
118 var ok bool
119 for _, expected := range enumValues_Importance {
120 if reflect.DeepEqual(v, expected) {
121 ok = true
122 break
123 }
124 }
125 if !ok {
126 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_Importance, v)
127 }
128 *j = Importance(v)
129 return nil
130 }
131
132 type KeyUsage string
133
134 const KeyUsageCRLSign KeyUsage = "cRLSign"
135 const KeyUsageContentCommitment KeyUsage = "contentCommitment"
136 const KeyUsageDataEncipherment KeyUsage = "dataEncipherment"
137 const KeyUsageDecipherOnly KeyUsage = "decipherOnly"
138 const KeyUsageDigitalSignature KeyUsage = "digitalSignature"
139 const KeyUsageEncipherOnly KeyUsage = "encipherOnly"
140 const KeyUsageKeyAgreement KeyUsage = "keyAgreement"
141 const KeyUsageKeyCertSign KeyUsage = "keyCertSign"
142 const KeyUsageKeyEncipherment KeyUsage = "keyEncipherment"
143
144 var enumValues_KeyUsage = []interface{}{
145 "digitalSignature",
146 "contentCommitment",
147 "keyEncipherment",
148 "dataEncipherment",
149 "keyAgreement",
150 "keyCertSign",
151 "cRLSign",
152 "encipherOnly",
153 "decipherOnly",
154 }
155
156
157 func (j *KeyUsage) UnmarshalJSON(value []byte) error {
158 var v string
159 if err := json.Unmarshal(value, &v); err != nil {
160 return err
161 }
162 var ok bool
163 for _, expected := range enumValues_KeyUsage {
164 if reflect.DeepEqual(v, expected) {
165 ok = true
166 break
167 }
168 }
169 if !ok {
170 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_KeyUsage, v)
171 }
172 *j = KeyUsage(v)
173 return nil
174 }
175
176 type KnownEKUs string
177
178 const KnownEKUsAnyExtendedKeyUsage KnownEKUs = "anyExtendedKeyUsage"
179 const KnownEKUsClientAuth KnownEKUs = "clientAuth"
180 const KnownEKUsCodeSigning KnownEKUs = "codeSigning"
181 const KnownEKUsEmailProtection KnownEKUs = "emailProtection"
182 const KnownEKUsOCSPSigning KnownEKUs = "OCSPSigning"
183 const KnownEKUsServerAuth KnownEKUs = "serverAuth"
184 const KnownEKUsTimeStamping KnownEKUs = "timeStamping"
185
186 var enumValues_KnownEKUs = []interface{}{
187 "anyExtendedKeyUsage",
188 "serverAuth",
189 "clientAuth",
190 "codeSigning",
191 "emailProtection",
192 "timeStamping",
193 "OCSPSigning",
194 }
195
196
197 func (j *KnownEKUs) UnmarshalJSON(value []byte) error {
198 var v string
199 if err := json.Unmarshal(value, &v); err != nil {
200 return err
201 }
202 var ok bool
203 for _, expected := range enumValues_KnownEKUs {
204 if reflect.DeepEqual(v, expected) {
205 ok = true
206 break
207 }
208 }
209 if !ok {
210 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_KnownEKUs, v)
211 }
212 *j = KnownEKUs(v)
213 return nil
214 }
215
216
217 type Limbo struct {
218
219 Testcases []Testcase `json:"testcases"`
220
221
222 Version int `json:"version"`
223 }
224
225
226 func (j *Limbo) UnmarshalJSON(value []byte) error {
227 var raw map[string]interface{}
228 if err := json.Unmarshal(value, &raw); err != nil {
229 return err
230 }
231 if _, ok := raw["testcases"]; raw != nil && !ok {
232 return fmt.Errorf("field testcases in Limbo: required")
233 }
234 if _, ok := raw["version"]; raw != nil && !ok {
235 return fmt.Errorf("field version in Limbo: required")
236 }
237 type Plain Limbo
238 var plain Plain
239 if err := json.Unmarshal(value, &plain); err != nil {
240 return err
241 }
242 if plain.Version != 1 {
243 return fmt.Errorf("field %s: must be equal to %v", "version", 1)
244 }
245 *j = Limbo(plain)
246 return nil
247 }
248
249 type PeerKind string
250
251 const PeerKindDNS PeerKind = "DNS"
252 const PeerKindIP PeerKind = "IP"
253 const PeerKindRFC822 PeerKind = "RFC822"
254
255 var enumValues_PeerKind = []interface{}{
256 "RFC822",
257 "DNS",
258 "IP",
259 }
260
261
262 func (j *PeerKind) UnmarshalJSON(value []byte) error {
263 var v string
264 if err := json.Unmarshal(value, &v); err != nil {
265 return err
266 }
267 var ok bool
268 for _, expected := range enumValues_PeerKind {
269 if reflect.DeepEqual(v, expected) {
270 ok = true
271 break
272 }
273 }
274 if !ok {
275 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_PeerKind, v)
276 }
277 *j = PeerKind(v)
278 return nil
279 }
280
281
282 type PeerName struct {
283
284 Kind PeerKind `json:"kind"`
285
286
287 Value string `json:"value"`
288 }
289
290
291 func (j *PeerName) UnmarshalJSON(value []byte) error {
292 var raw map[string]interface{}
293 if err := json.Unmarshal(value, &raw); err != nil {
294 return err
295 }
296 if _, ok := raw["kind"]; raw != nil && !ok {
297 return fmt.Errorf("field kind in PeerName: required")
298 }
299 if _, ok := raw["value"]; raw != nil && !ok {
300 return fmt.Errorf("field value in PeerName: required")
301 }
302 type Plain PeerName
303 var plain Plain
304 if err := json.Unmarshal(value, &plain); err != nil {
305 return err
306 }
307 *j = PeerName(plain)
308 return nil
309 }
310
311 type SignatureAlgorithm string
312
313 const SignatureAlgorithmDSAWITHSHA1 SignatureAlgorithm = "DSA_WITH_SHA1"
314 const SignatureAlgorithmDSAWITHSHA224 SignatureAlgorithm = "DSA_WITH_SHA224"
315 const SignatureAlgorithmDSAWITHSHA256 SignatureAlgorithm = "DSA_WITH_SHA256"
316 const SignatureAlgorithmDSAWITHSHA384 SignatureAlgorithm = "DSA_WITH_SHA384"
317 const SignatureAlgorithmDSAWITHSHA512 SignatureAlgorithm = "DSA_WITH_SHA512"
318 const SignatureAlgorithmECDSAWITHSHA1 SignatureAlgorithm = "ECDSA_WITH_SHA1"
319 const SignatureAlgorithmECDSAWITHSHA224 SignatureAlgorithm = "ECDSA_WITH_SHA224"
320 const SignatureAlgorithmECDSAWITHSHA256 SignatureAlgorithm = "ECDSA_WITH_SHA256"
321 const SignatureAlgorithmECDSAWITHSHA3224 SignatureAlgorithm = "ECDSA_WITH_SHA3_224"
322 const SignatureAlgorithmECDSAWITHSHA3256 SignatureAlgorithm = "ECDSA_WITH_SHA3_256"
323 const SignatureAlgorithmECDSAWITHSHA3384 SignatureAlgorithm = "ECDSA_WITH_SHA3_384"
324 const SignatureAlgorithmECDSAWITHSHA3512 SignatureAlgorithm = "ECDSA_WITH_SHA3_512"
325 const SignatureAlgorithmECDSAWITHSHA384 SignatureAlgorithm = "ECDSA_WITH_SHA384"
326 const SignatureAlgorithmECDSAWITHSHA512 SignatureAlgorithm = "ECDSA_WITH_SHA512"
327 const SignatureAlgorithmED25519 SignatureAlgorithm = "ED25519"
328 const SignatureAlgorithmED448 SignatureAlgorithm = "ED448"
329 const SignatureAlgorithmGOSTR34102012WITH34112012256 SignatureAlgorithm = "GOSTR3410_2012_WITH_3411_2012_256"
330 const SignatureAlgorithmGOSTR34102012WITH34112012512 SignatureAlgorithm = "GOSTR3410_2012_WITH_3411_2012_512"
331 const SignatureAlgorithmGOSTR341194WITH34102001 SignatureAlgorithm = "GOSTR3411_94_WITH_3410_2001"
332 const SignatureAlgorithmMLDSA44 SignatureAlgorithm = "ML_DSA_44"
333 const SignatureAlgorithmMLDSA65 SignatureAlgorithm = "ML_DSA_65"
334 const SignatureAlgorithmMLDSA87 SignatureAlgorithm = "ML_DSA_87"
335 const SignatureAlgorithmRSASSAPSS SignatureAlgorithm = "RSASSA_PSS"
336 const SignatureAlgorithmRSAWITHMD5 SignatureAlgorithm = "RSA_WITH_MD5"
337 const SignatureAlgorithmRSAWITHSHA1 SignatureAlgorithm = "RSA_WITH_SHA1"
338 const SignatureAlgorithmRSAWITHSHA224 SignatureAlgorithm = "RSA_WITH_SHA224"
339 const SignatureAlgorithmRSAWITHSHA256 SignatureAlgorithm = "RSA_WITH_SHA256"
340 const SignatureAlgorithmRSAWITHSHA3224 SignatureAlgorithm = "RSA_WITH_SHA3_224"
341 const SignatureAlgorithmRSAWITHSHA3256 SignatureAlgorithm = "RSA_WITH_SHA3_256"
342 const SignatureAlgorithmRSAWITHSHA3384 SignatureAlgorithm = "RSA_WITH_SHA3_384"
343 const SignatureAlgorithmRSAWITHSHA3512 SignatureAlgorithm = "RSA_WITH_SHA3_512"
344 const SignatureAlgorithmRSAWITHSHA384 SignatureAlgorithm = "RSA_WITH_SHA384"
345 const SignatureAlgorithmRSAWITHSHA512 SignatureAlgorithm = "RSA_WITH_SHA512"
346
347 var enumValues_SignatureAlgorithm = []interface{}{
348 "RSA_WITH_MD5",
349 "RSA_WITH_SHA1",
350 "RSA_WITH_SHA224",
351 "RSA_WITH_SHA256",
352 "RSA_WITH_SHA384",
353 "RSA_WITH_SHA512",
354 "RSA_WITH_SHA3_224",
355 "RSA_WITH_SHA3_256",
356 "RSA_WITH_SHA3_384",
357 "RSA_WITH_SHA3_512",
358 "RSASSA_PSS",
359 "ECDSA_WITH_SHA1",
360 "ECDSA_WITH_SHA224",
361 "ECDSA_WITH_SHA256",
362 "ECDSA_WITH_SHA384",
363 "ECDSA_WITH_SHA512",
364 "ECDSA_WITH_SHA3_224",
365 "ECDSA_WITH_SHA3_256",
366 "ECDSA_WITH_SHA3_384",
367 "ECDSA_WITH_SHA3_512",
368 "DSA_WITH_SHA1",
369 "DSA_WITH_SHA224",
370 "DSA_WITH_SHA256",
371 "DSA_WITH_SHA384",
372 "DSA_WITH_SHA512",
373 "ED25519",
374 "ED448",
375 "ML_DSA_44",
376 "ML_DSA_65",
377 "ML_DSA_87",
378 "GOSTR3411_94_WITH_3410_2001",
379 "GOSTR3410_2012_WITH_3411_2012_256",
380 "GOSTR3410_2012_WITH_3411_2012_512",
381 }
382
383
384 func (j *SignatureAlgorithm) UnmarshalJSON(value []byte) error {
385 var v string
386 if err := json.Unmarshal(value, &v); err != nil {
387 return err
388 }
389 var ok bool
390 for _, expected := range enumValues_SignatureAlgorithm {
391 if reflect.DeepEqual(v, expected) {
392 ok = true
393 break
394 }
395 }
396 if !ok {
397 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_SignatureAlgorithm, v)
398 }
399 *j = SignatureAlgorithm(v)
400 return nil
401 }
402
403
404 type Testcase struct {
405
406 ConflictsWith []string `json:"conflicts_with,omitempty,omitzero"`
407
408
409 Crls []string `json:"crls,omitempty,omitzero"`
410
411
412 Description string `json:"description"`
413
414
415 ExpectedPeerName *TestcaseExpectedPeerName `json:"expected_peer_name,omitempty,omitzero"`
416
417
418 ExpectedPeerNames []PeerName `json:"expected_peer_names"`
419
420
421 ExpectedResult ExpectedResult `json:"expected_result"`
422
423
424
425 ExtendedKeyUsage []KnownEKUs `json:"extended_key_usage"`
426
427
428
429
430
431
432 Features []Feature `json:"features,omitempty,omitzero"`
433
434
435 Id string `json:"id"`
436
437
438 Importance Importance `json:"importance,omitempty,omitzero"`
439
440
441 KeyUsage []KeyUsage `json:"key_usage"`
442
443
444 MaxChainDepth interface{} `json:"max_chain_depth,omitempty,omitzero"`
445
446
447 PeerCertificate string `json:"peer_certificate"`
448
449
450 PeerCertificateKey interface{} `json:"peer_certificate_key,omitempty,omitzero"`
451
452
453 SignatureAlgorithms []SignatureAlgorithm `json:"signature_algorithms"`
454
455
456 TrustedCerts []string `json:"trusted_certs"`
457
458
459 UntrustedIntermediates []string `json:"untrusted_intermediates"`
460
461
462 ValidationKind ValidationKind `json:"validation_kind"`
463
464
465 ValidationTime interface{} `json:"validation_time,omitempty,omitzero"`
466 }
467
468
469 type TestcaseExpectedPeerName struct {
470
471 Kind PeerKind `json:"kind"`
472
473
474 Value string `json:"value"`
475 }
476
477
478 func (j *TestcaseExpectedPeerName) UnmarshalJSON(value []byte) error {
479 var raw map[string]interface{}
480 if err := json.Unmarshal(value, &raw); err != nil {
481 return err
482 }
483 var testcaseExpectedPeerName_0 TestcaseExpectedPeerName_0
484 var errs []error
485 if err := testcaseExpectedPeerName_0.UnmarshalJSON(value); err != nil {
486 errs = append(errs, err)
487 }
488 if len(errs) == 1 {
489 return fmt.Errorf("all validators failed: %s", errors.Join(errs...))
490 }
491 type Plain TestcaseExpectedPeerName
492 var plain Plain
493 if err := json.Unmarshal(value, &plain); err != nil {
494 return err
495 }
496 *j = TestcaseExpectedPeerName(plain)
497 return nil
498 }
499
500 type TestcaseMaxChainDepth_0 *int
501
502 type TestcasePeerCertificateKey_0 *string
503
504 type TestcaseValidationTime_0 *time.Time
505
506
507 func (j *Testcase) UnmarshalJSON(value []byte) error {
508 var raw map[string]interface{}
509 if err := json.Unmarshal(value, &raw); err != nil {
510 return err
511 }
512 if _, ok := raw["description"]; raw != nil && !ok {
513 return fmt.Errorf("field description in Testcase: required")
514 }
515 if _, ok := raw["expected_peer_names"]; raw != nil && !ok {
516 return fmt.Errorf("field expected_peer_names in Testcase: required")
517 }
518 if _, ok := raw["expected_result"]; raw != nil && !ok {
519 return fmt.Errorf("field expected_result in Testcase: required")
520 }
521 if _, ok := raw["extended_key_usage"]; raw != nil && !ok {
522 return fmt.Errorf("field extended_key_usage in Testcase: required")
523 }
524 if _, ok := raw["id"]; raw != nil && !ok {
525 return fmt.Errorf("field id in Testcase: required")
526 }
527 if _, ok := raw["key_usage"]; raw != nil && !ok {
528 return fmt.Errorf("field key_usage in Testcase: required")
529 }
530 if _, ok := raw["peer_certificate"]; raw != nil && !ok {
531 return fmt.Errorf("field peer_certificate in Testcase: required")
532 }
533 if _, ok := raw["signature_algorithms"]; raw != nil && !ok {
534 return fmt.Errorf("field signature_algorithms in Testcase: required")
535 }
536 if _, ok := raw["trusted_certs"]; raw != nil && !ok {
537 return fmt.Errorf("field trusted_certs in Testcase: required")
538 }
539 if _, ok := raw["untrusted_intermediates"]; raw != nil && !ok {
540 return fmt.Errorf("field untrusted_intermediates in Testcase: required")
541 }
542 if _, ok := raw["validation_kind"]; raw != nil && !ok {
543 return fmt.Errorf("field validation_kind in Testcase: required")
544 }
545 type Plain Testcase
546 var plain Plain
547 if err := json.Unmarshal(value, &plain); err != nil {
548 return err
549 }
550 if v, ok := raw["conflicts_with"]; !ok || v == nil {
551 plain.ConflictsWith = []string{}
552 }
553 if v, ok := raw["crls"]; !ok || v == nil {
554 plain.Crls = []string{}
555 }
556 if v, ok := raw["features"]; !ok || v == nil {
557 plain.Features = []Feature{}
558 }
559 if matched, _ := regexp.MatchString(`^([A-Za-z][A-Za-z0-9-.]+::)*([A-Za-z][A-Za-z0-9-.]+)$`, string(plain.Id)); !matched {
560 return fmt.Errorf("field %s pattern match: must match %s", "Id", `^([A-Za-z][A-Za-z0-9-.]+::)*([A-Za-z][A-Za-z0-9-.]+)$`)
561 }
562 if v, ok := raw["importance"]; !ok || v == nil {
563 plain.Importance = "undetermined"
564 }
565 *j = Testcase(plain)
566 return nil
567 }
568
569 type ValidationKind string
570
571 const ValidationKindCLIENT ValidationKind = "CLIENT"
572 const ValidationKindSERVER ValidationKind = "SERVER"
573
574 var enumValues_ValidationKind = []interface{}{
575 "CLIENT",
576 "SERVER",
577 }
578
579
580 func (j *ValidationKind) UnmarshalJSON(value []byte) error {
581 var v string
582 if err := json.Unmarshal(value, &v); err != nil {
583 return err
584 }
585 var ok bool
586 for _, expected := range enumValues_ValidationKind {
587 if reflect.DeepEqual(v, expected) {
588 ok = true
589 break
590 }
591 }
592 if !ok {
593 return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_ValidationKind, v)
594 }
595 *j = ValidationKind(v)
596 return nil
597 }
598
599 type TestcaseExpectedPeerName_0 = PeerName
600
View as plain text