-
Notifications
You must be signed in to change notification settings - Fork 73
🌱 OPRUN-4550: Replace generated mozilla_data.go with go:embed + runtime parsing #2634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,104 @@ | ||
| package tlsprofiles | ||
|
|
||
| // DO NOT EDIT, GENERATED BY hack/tools/update-tls-profiles.sh | ||
| // DATA SOURCE: https://ssl-config.mozilla.org/guidelines/latest.json | ||
| // DATA VERSION: 6 | ||
| // This file embeds the Mozilla SSL/TLS Configuration Guidelines JSON and parses | ||
| // it at init() time to populate the modern and intermediate TLS profiles. | ||
| // Run `make update-tls-profiles` to refresh mozilla_data.json from the upstream spec. | ||
|
|
||
| import ( | ||
| "crypto/tls" | ||
| _ "embed" | ||
| "encoding/json" | ||
| "fmt" | ||
| ) | ||
|
|
||
| var modernTLSProfile = tlsProfile{ | ||
| ciphers: cipherSlice{ | ||
| cipherNums: []uint16{ | ||
| tls.TLS_AES_128_GCM_SHA256, | ||
| tls.TLS_AES_256_GCM_SHA384, | ||
| tls.TLS_CHACHA20_POLY1305_SHA256, | ||
| }, | ||
| }, | ||
| curves: curveSlice{ | ||
| curveNums: []tls.CurveID{ | ||
| X25519MLKEM768, | ||
| X25519, | ||
| prime256v1, | ||
| secp384r1, | ||
| }, | ||
| }, | ||
| minTLSVersion: tls.VersionTLS13, | ||
| //go:embed mozilla_data.json | ||
| var mozillaDataJSON []byte | ||
|
|
||
| // skippedCiphers records cipher names from mozilla_data.json that are not | ||
| // supported by Go's crypto/tls and were omitted from the profiles. | ||
| var skippedCiphers []string | ||
|
|
||
| // skippedCurves records curve names from mozilla_data.json that are not | ||
| // supported by Go's crypto/tls and were omitted from the profiles. | ||
| var skippedCurves []string | ||
|
|
||
| var ( | ||
| modernTLSProfile tlsProfile | ||
| intermediateTLSProfile tlsProfile | ||
| ) | ||
|
|
||
| type mozillaConfiguration struct { | ||
| Ciphersuites []string `json:"ciphersuites"` | ||
| Ciphers struct { | ||
| IANA []string `json:"iana"` | ||
| } `json:"ciphers"` | ||
| TLSCurves []string `json:"tls_curves"` | ||
| TLSVersions []string `json:"tls_versions"` | ||
| } | ||
|
|
||
| type mozillaSpec struct { | ||
| Configurations map[string]mozillaConfiguration `json:"configurations"` | ||
| } | ||
|
|
||
| func init() { | ||
| var spec mozillaSpec | ||
| if err := json.Unmarshal(mozillaDataJSON, &spec); err != nil { | ||
| panic(fmt.Sprintf("tlsprofiles: failed to parse embedded mozilla_data.json: %v", err)) | ||
| } | ||
|
|
||
pedjak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for _, name := range []string{"modern", "intermediate"} { | ||
| cfg, ok := spec.Configurations[name] | ||
| if !ok { | ||
| panic(fmt.Sprintf("tlsprofiles: profile %q not found in embedded mozilla_data.json", name)) | ||
| } | ||
|
|
||
| p, ciphers, curves := parseProfile(name, cfg) | ||
| skippedCiphers = append(skippedCiphers, ciphers...) | ||
| skippedCurves = append(skippedCurves, curves...) | ||
|
|
||
| switch name { | ||
| case "modern": | ||
| modernTLSProfile = p | ||
| case "intermediate": | ||
| intermediateTLSProfile = p | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var intermediateTLSProfile = tlsProfile{ | ||
| ciphers: cipherSlice{ | ||
| cipherNums: []uint16{ | ||
| tls.TLS_AES_128_GCM_SHA256, | ||
| tls.TLS_AES_256_GCM_SHA384, | ||
| tls.TLS_CHACHA20_POLY1305_SHA256, | ||
| tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | ||
| tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | ||
| tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | ||
| tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | ||
| tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, | ||
| tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, | ||
| }, | ||
| }, | ||
| curves: curveSlice{ | ||
| curveNums: []tls.CurveID{ | ||
| X25519MLKEM768, | ||
| X25519, | ||
| prime256v1, | ||
| secp384r1, | ||
| }, | ||
| }, | ||
| minTLSVersion: tls.VersionTLS12, | ||
| func parseProfile(name string, cfg mozillaConfiguration) (tlsProfile, []string, []string) { | ||
| var skippedC, skippedK []string | ||
| var cipherNums []uint16 | ||
| for _, c := range append(cfg.Ciphersuites, cfg.Ciphers.IANA...) { | ||
| id := cipherSuiteId(c) | ||
| if id == 0 { | ||
| skippedC = append(skippedC, c) | ||
| continue | ||
| } | ||
| cipherNums = append(cipherNums, id) | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsupported ciphers are tracked in If Mozilla adds a new curve that Go does not yet support, this would silently weaken the profile. Consider adding a id := curveId(c)
if id == 0 {
skipped = append(skipped, "curve:"+c)
continue
}(Or a separate
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I noticed that too... it may not even be a curve that isn't support, but simply not mapped in our own functions. |
||
| var curveNums []tls.CurveID | ||
| for _, c := range cfg.TLSCurves { | ||
| id := curveId(c) | ||
| if id == 0 { | ||
| skippedK = append(skippedK, c) | ||
| continue | ||
| } | ||
| curveNums = append(curveNums, id) | ||
| } | ||
|
|
||
| if len(cfg.TLSVersions) == 0 { | ||
| panic(fmt.Sprintf("tlsprofiles: profile %q has no tls_versions in embedded mozilla_data.json", name)) | ||
| } | ||
|
|
||
| var version tlsVersion | ||
| if err := version.Set(cfg.TLSVersions[0]); err != nil { | ||
| panic(fmt.Sprintf("tlsprofiles: profile %q has unrecognized tls_versions[0] %q: %v", name, cfg.TLSVersions[0], err)) | ||
| } | ||
|
|
||
| return tlsProfile{ | ||
| ciphers: cipherSlice{cipherNums: cipherNums}, | ||
| curves: curveSlice{curveNums: curveNums}, | ||
| minTLSVersion: version, | ||
| }, skippedC, skippedK | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me here we drop the only usage of gojq, but we keep it still in bingo files (.bingo/gojq.mod, .bingo/Variables.mk, ...).
Should we drop it also from bingo?
Should be something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, if not used anywhere else, we should remove it from bingo files as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and rebased, please re-review @pedjak