From dd9a52592c30b7bc004cf45244fbc211c947b9ee Mon Sep 17 00:00:00 2001 From: Semyon Andreev Date: Thu, 29 Oct 2026 14:22:07 +0300 Subject: [PATCH] scanner/plugins/opensslconf: record Groups (TLS 1.3 key-exchange groups) MinProtocol/MaxProtocol/CipherString/Options/CAfile/CApath/default_md were already extracted from openssl.cnf into CBOM properties, but Groups was not -- so a post-quantum or hybrid key exchange configured via this directive (e.g. X25519MLKEM768) never reached the CBOM. "Curves" is the legacy alias for the same directive, and OpenSSL matches directive names case-insensitively, so both spellings are matched case-insensitively here (Groups preferred when a config sets both in the same section). Section priority still takes precedence over name priority: a match in an earlier preferred section wins even when a later section has the otherwise-preferred name. Groups/Curves are recorded as a plain string property; they are not yet modelled as cryptographic-asset components or linked to the TLS protocol component, and case-insensitive matching covers only these two names. Both are left as follow-ups. Part of cbomkit-theia#212. Signed-off-by: Semyon Andreev Assisted-by: Claude Sonnet 5 --- scanner/plugins/opensslconf/opensslconf.go | 55 ++++++++++++++- .../plugins/opensslconf/opensslconf_test.go | 67 +++++++++++++++++++ testdata/openssl/dir/openssl.cnf | 1 + 3 files changed, 122 insertions(+), 1 deletion(-) diff --git a/scanner/plugins/opensslconf/opensslconf.go b/scanner/plugins/opensslconf/opensslconf.go index bc811a4..e536231 100644 --- a/scanner/plugins/opensslconf/opensslconf.go +++ b/scanner/plugins/opensslconf/opensslconf.go @@ -43,7 +43,7 @@ func NewOpenSSLConfPlugin() (plugins.Plugin, error) { return &Plugin{}, nil } func (*Plugin) GetName() string { return "OpenSSL Config Plugin" } func (*Plugin) GetExplanation() string { - return "Scans for OpenSSL configuration files (openssl.cnf) and adds selected TLS settings (Min/MaxProtocol, CipherString, Options, CAfile/CApath, default_md) to the CBOM as component properties." + return "Scans for OpenSSL configuration files (openssl.cnf) and adds selected TLS settings (Min/MaxProtocol, CipherString, Groups/Curves, Options, CAfile/CApath, default_md) to the CBOM as component properties. Groups/Curves are matched case-insensitively (Groups preferred when both are set in the same section); a match in an earlier preferred section wins over a later section even when the later section's directive name would otherwise be preferred." } func (*Plugin) GetType() plugins.PluginType { return plugins.PluginTypeAppend } @@ -343,9 +343,62 @@ func extractRelevantProperties(cfg map[string]map[string]string) []cdx.Property properties = append(properties, cdx.Property{Name: "theia:openssl:" + k, Value: v}) } } + // Groups (TLS 1.3 key-exchange groups, e.g. post-quantum/hybrid groups such + // as X25519MLKEM768) is read from the "Groups" directive, or from its + // legacy alias "Curves" -- OpenSSL itself matches directive names + // case-insensitively, so both names are matched case-insensitively here + // too, with "Groups" preferred when a config sets both in the same + // section. Section priority still takes precedence over name priority: + // a match in an earlier preferred section wins even when a later section + // has the otherwise-preferred name (see + // Test_parseOpenSSLConf_SectionPriorityOverNamePriority). + if v, ok := getFirstKeyCI(cfg, preferredSections, "Groups", "Curves"); ok && v != "" { + properties = append(properties, cdx.Property{Name: "theia:openssl:Groups", Value: v}) + } return properties } +// getFirstKeyCI is like getFirstKey but matches each of names case-insensitively, +// trying them in priority order (first name wins if multiple are present in the +// same section). Used for directives with a case-insensitive alias (Groups/Curves). +func getFirstKeyCI(cfg map[string]map[string]string, sections []string, names ...string) (string, bool) { + for _, s := range sections { + if sec, ok := cfg[s]; ok { + if v, ok2 := lookupKeyCI(sec, names); ok2 { + return v, true + } + } + } + secNames := make([]string, 0, len(cfg)) + for s := range cfg { + secNames = append(secNames, s) + } + sort.Strings(secNames) + for _, s := range secNames { + if v, ok := lookupKeyCI(cfg[s], names); ok { + return v, true + } + } + return "", false +} + +func lookupKeyCI(section map[string]string, names []string) (string, bool) { + for _, name := range names { + lname := strings.ToLower(name) + var matched []string + for k := range section { + if strings.ToLower(k) == lname { + matched = append(matched, k) + } + } + if len(matched) > 0 { + sort.Strings(matched) // deterministic if the same name appears with different casing + return section[matched[0]], true + } + } + return "", false +} + func getFirstKey(cfg map[string]map[string]string, sections []string, key string) (string, bool) { for _, s := range sections { if sec, ok := cfg[s]; ok { diff --git a/scanner/plugins/opensslconf/opensslconf_test.go b/scanner/plugins/opensslconf/opensslconf_test.go index c77af6d..7ff939f 100644 --- a/scanner/plugins/opensslconf/opensslconf_test.go +++ b/scanner/plugins/opensslconf/opensslconf_test.go @@ -34,6 +34,7 @@ func Test_parseOpenSSLConf_and_extractRelevantProperties(t *testing.T) { MinProtocol = TLSv1.2 MaxProtocol = TLSv1.3 CipherString = DEFAULT@SECLEVEL=2 +Groups = X25519MLKEM768:X25519:P-256 Options = ServerPreference,PrioritizeChaCha [ca_default] @@ -54,12 +55,77 @@ CApath=/etc/ssl/certs assert.Equal(t, "TLSv1.2", m["theia:openssl:MinProtocol"]) assert.Equal(t, "TLSv1.3", m["theia:openssl:MaxProtocol"]) assert.Equal(t, "DEFAULT@SECLEVEL=2", m["theia:openssl:CipherString"]) + assert.Equal(t, "X25519MLKEM768:X25519:P-256", m["theia:openssl:Groups"]) assert.Equal(t, "ServerPreference,PrioritizeChaCha", m["theia:openssl:Options"]) assert.Equal(t, "/etc/ssl/certs/ca-bundle.crt", m["theia:openssl:CAfile"]) assert.Equal(t, "/etc/ssl/certs", m["theia:openssl:CApath"]) assert.Equal(t, "sha256", m["theia:openssl:default_md"]) } +// Test_parseOpenSSLConf_CurvesAliasCaseInsensitive covers cbomkit-theia#212: +// "Curves" is the legacy alias for "Groups", and OpenSSL matches directive +// names case-insensitively, so a config using either spelling/casing must +// still surface the post-quantum/hybrid group on the CBOM. +func Test_parseOpenSSLConf_CurvesAliasCaseInsensitive(t *testing.T) { + content := ` +[system_default_sect] +curves = X25519MLKEM768 +` + cfg, err := parseOpenSSLConf(strings.NewReader(content)) + assert.NoError(t, err) + props := extractRelevantProperties(cfg) + + m := map[string]string{} + for _, p := range props { + m[p.Name] = p.Value + } + assert.Equal(t, "X25519MLKEM768", m["theia:openssl:Groups"]) +} + +// Test_parseOpenSSLConf_GroupsPreferredOverCurves: when both directives are +// present (e.g. a config written for both OpenSSL 1.1 and 3.x readers), +// "Groups" wins deterministically. +func Test_parseOpenSSLConf_GroupsPreferredOverCurves(t *testing.T) { + content := ` +[system_default_sect] +Groups = X25519MLKEM768 +Curves = P-256 +` + cfg, err := parseOpenSSLConf(strings.NewReader(content)) + assert.NoError(t, err) + props := extractRelevantProperties(cfg) + + m := map[string]string{} + for _, p := range props { + m[p.Name] = p.Value + } + assert.Equal(t, "X25519MLKEM768", m["theia:openssl:Groups"]) +} + +// Test_parseOpenSSLConf_SectionPriorityOverNamePriority: section order wins +// over name order across sections -- "Curves" in the earlier preferred +// section ("system_default_sect") is used even though "Groups" (the +// otherwise-preferred name) appears only in a later preferred section +// ("req"). +func Test_parseOpenSSLConf_SectionPriorityOverNamePriority(t *testing.T) { + content := ` +[system_default_sect] +Curves = X25519MLKEM768 + +[req] +Groups = P-256 +` + cfg, err := parseOpenSSLConf(strings.NewReader(content)) + assert.NoError(t, err) + props := extractRelevantProperties(cfg) + + m := map[string]string{} + for _, p := range props { + m[p.Name] = p.Value + } + assert.Equal(t, "X25519MLKEM768", m["theia:openssl:Groups"]) +} + func Test_UpdateBOM_adds_component(t *testing.T) { fs := filesystem.NewPlainFilesystem("../../../testdata/openssl/dir") bom := cdx.NewBOM() @@ -91,6 +157,7 @@ func Test_UpdateBOM_adds_component(t *testing.T) { assert.Equal(t, "TLSv1.2", props["theia:openssl:MinProtocol"]) assert.Equal(t, "TLSv1.3", props["theia:openssl:MaxProtocol"]) assert.Equal(t, "ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384", props["theia:openssl:CipherString"]) + assert.Equal(t, "X25519MLKEM768:X25519:P-256", props["theia:openssl:Groups"]) assert.Equal(t, "ServerPreference,PrioritizeChaCha", props["theia:openssl:Options"]) assert.Equal(t, "/etc/ssl/certs/ca-bundle.crt", props["theia:openssl:CAfile"]) assert.Equal(t, "/etc/ssl/certs", props["theia:openssl:CApath"]) diff --git a/testdata/openssl/dir/openssl.cnf b/testdata/openssl/dir/openssl.cnf index 52d2776..0491e25 100644 --- a/testdata/openssl/dir/openssl.cnf +++ b/testdata/openssl/dir/openssl.cnf @@ -14,6 +14,7 @@ MinProtocol = TLSv1.2 MaxProtocol = TLSv1.3 CipherString = ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384 Ciphersuites = TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256 +Groups = X25519MLKEM768:X25519:P-256 Options = ServerPreference,PrioritizeChaCha # Default CA section