@@ -36,30 +36,23 @@ ENDMACRO()
36
36
37
37
# Get CPE ID ( https://en.wikipedia.org/wiki/Common_Platform_Enumeration )
38
38
# for given project name and version
39
- # Only "known" CPEs are handled here, e.g currently no CPE for rocksdb
39
+ # CPE prefix are stored with other auxilliary info in the 3rdparty_info.cmake
40
+ # file
40
41
FUNCTION (SBOM_GET_CPE name version var)
41
- SET (cpe_prefix_map
42
- "zlib" "zlib:zlib"
43
- "mariadb-connector-c" "mariadb:connector\\\\ /c"
44
- "wolfssl" "wolfssl:wolfssl"
45
- "minizip" "zlib:zlib"
46
- "pcre2" "pcre:pcre2"
47
- "fmt" "fmt:fmt"
48
- "boost" "boost:boost"
49
- "thrift" "apache:thrift"
50
- )
51
- LIST (FIND cpe_prefix_map "${name} " idx_cpe_mapping)
52
- # Version needs to have at least one dot character in it.
53
- # Otherwise, we assume it is a git hash, and do not generate CPE
54
- STRING (FIND "${version} " "." idx_version_dot)
55
- IF ((idx_cpe_mapping GREATER -1) AND (idx_version_dot GREATER -1))
56
- MATH (EXPR next_idx "${idx_cpe_mapping} +1" )
57
- LIST (GET cpe_prefix_map ${next_idx} cpe_name_and_vendor)
58
- STRING (REGEX REPLACE "[^0-9\\ .]" "" cleaned_version "${version} " )
59
- SET (${var} "cpe:2.3:a:${cpe_name_and_vendor} :${cleaned_version} :*:*:*:*:*:*:*" PARENT_SCOPE)
60
- ELSE ()
61
- SET (${var} "" PARENT_SCOPE)
42
+ SET (${var} "" PARENT_SCOPE)
43
+ STRING (FIND "${version} " "." dot_idx)
44
+ IF (${dot_idx} EQUAL -1)
45
+ # Version does not have dot inside.
46
+ # mostly likely it is just a git hash
47
+ RETURN ()
48
+ ENDIF ()
49
+ SET (cpe_name_and_vendor "${${repo_name_lower} .cpe-prefix}" )
50
+ IF (NOT cpe_name_and_vendor)
51
+ RETURN ()
62
52
ENDIF ()
53
+
54
+ STRING (REGEX REPLACE "[^0-9\\ .]" "" cleaned_version "${version} " )
55
+ SET (${var} "cpe:2.3:a:${cpe_name_and_vendor} :${cleaned_version} :*:*:*:*:*:*:*" PARENT_SCOPE)
63
56
ENDFUNCTION ()
64
57
65
58
# Add dependency on CMake ExternalProject.
@@ -97,8 +90,8 @@ ENDMACRO()
97
90
# Perhaps it can always be "MariaDB", but security team recommendation is different
98
91
# more towards "author"
99
92
FUNCTION (sbom_get_supplier repo_name repo_user varname)
100
- IF ("${repo_name_SUPPLIER } " )
101
- SET (${varname} "${repo_name_SUPPLIER } " PARENT_SCOPE)
93
+ IF ("${${repo_name} _SUPPLIER }" )
94
+ SET (${varname} "${${repo_name} _SUPPLIER }" PARENT_SCOPE)
102
95
ELSEIF (repo_name MATCHES "zlib|minizip" )
103
96
# stuff that is checked into out repos
104
97
SET (${varname} "MariaDB" PARENT_SCOPE)
@@ -230,6 +223,7 @@ FUNCTION(GENERATE_SBOM)
230
223
\" ref\" : \" ${CPACK_PACKAGE_NAME} \" ,
231
224
\" dependsOn\" : [" )
232
225
226
+ INCLUDE (3rdparty_info)
233
227
SET (first ON )
234
228
FOREACH (dep ${ALL_THIRD_PARTY} )
235
229
# Extract the part after the last "/" from URL
@@ -277,6 +271,14 @@ FUNCTION(GENERATE_SBOM)
277
271
IF (cpe)
278
272
SET (cpe "\n \" cpe\" : \" ${cpe} \" ," )
279
273
ENDIF ()
274
+ SET (license "${${repo_name_lower} .license}" )
275
+ IF (NOT license)
276
+ MESSAGE (FATAL_ERROR "no license for 3rd party dependency ${repo_name_lower} ." )
277
+ ENDIF ()
278
+ SET (copyright "${${repo_name_lower} .copyright}" )
279
+ IF (NOT copyright)
280
+ SET (copyright NOASSERTION)
281
+ ENDIF ()
280
282
STRING (APPEND sbom_components "
281
283
{
282
284
\" bom-ref\" : \" ${bom_ref} \" ,
@@ -286,7 +288,15 @@ FUNCTION(GENERATE_SBOM)
286
288
\" purl\" : \" ${purl} \" ,${cpe}
287
289
\" supplier\" : {
288
290
\" name\" : \" ${supplier} \"
289
- }
291
+ },
292
+ \" licenses\" : [
293
+ {
294
+ \" license\" : {
295
+ \" id\" : \" ${license} \"
296
+ }
297
+ }
298
+ ],
299
+ \" copyright\" : \" ${copyright} \"
290
300
}" )
291
301
STRING (APPEND sbom_dependencies "
292
302
\" ${bom_ref} \" " )
@@ -302,5 +312,6 @@ FUNCTION(GENERATE_SBOM)
302
312
IF (NOT DEFINED CPACK_PACKAGE_VERSION)
303
313
SET (CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR} .${CPACK_PACKAGE_VERSION_MINOR} .${CPACK_PACKAGE_VERSION_PATCH} " )
304
314
ENDIF ()
315
+ STRING (TIMESTAMP CURRENT_YEAR "%Y" )
305
316
configure_file (${CMAKE_CURRENT_LIST_DIR} /cmake/sbom.json.in ${CMAKE_BINARY_DIR} /sbom.json)
306
317
ENDFUNCTION ()
0 commit comments