Skip to content

Commit 56b4d9e

Browse files
authored
Merge pull request #337 from CycloneDX/next
Add support for v1.5
2 parents 5de8d19 + 319467b commit 56b4d9e

72 files changed

Lines changed: 2005 additions & 79 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage-report/
88
coverage.cobertura.xml
99
**/__snapshots__/__mismatch__/
1010
*.user
11+
.DS_Store

src/cyclonedx/Commands/Add/AddFilesCommand.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ namespace CycloneDX.Cli.Commands.Add
3434
{
3535
public static class AddFilesCommand
3636
{
37-
public static void Configure(Command rootCommand)
37+
public static void Configure(System.CommandLine.Command rootCommand)
3838
{
3939
Contract.Requires(rootCommand != null);
40-
var subCommand = new Command("files", "Add files to a BOM");
40+
var subCommand = new System.CommandLine.Command("files", "Add files to a BOM");
4141
subCommand.Add(new Option<string>("--input-file", "Input BOM filename."));
4242
subCommand.Add(new Option<bool>("--no-input", "Use this option to indicate that there is no input BOM."));
4343
subCommand.Add(new Option<string>("--output-file", "Output BOM filename, will write to stdout if no value provided."));
@@ -55,10 +55,9 @@ public static async Task<int> AddFiles(AddFilesCommandOptions options)
5555
Contract.Requires(options != null);
5656
var outputToConsole = string.IsNullOrEmpty(options.OutputFile);
5757

58-
var thisTool = new Tool
58+
var thisTool = new Component
5959
{
6060
Name = "CycloneDX CLI",
61-
Vendor = "CycloneDX",
6261
Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
6362
};
6463

@@ -68,9 +67,10 @@ public static async Task<int> AddFiles(AddFilesCommandOptions options)
6867
if (bom.SerialNumber is null) bom.SerialNumber = "urn:uuid:" + System.Guid.NewGuid().ToString();
6968
if (bom.Metadata is null) bom.Metadata = new Metadata();
7069
bom.Metadata.Timestamp = DateTime.UtcNow;
71-
if (bom.Metadata.Tools is null) bom.Metadata.Tools = new List<Tool>();
72-
if (!bom.Metadata.Tools.Exists(tool => tool.Name == thisTool.Name && tool.Version == thisTool.Version))
73-
bom.Metadata.Tools.Add(thisTool);
70+
if (bom.Metadata.Tools is null) bom.Metadata.Tools = new ToolChoices();
71+
if (bom.Metadata.Tools.Components is null) bom.Metadata.Tools.Components = new List<Component>();
72+
if (!bom.Metadata.Tools.Components.Exists(tool => tool.Name == thisTool.Name && tool.Version == thisTool.Version))
73+
bom.Metadata.Tools.Components.Add(thisTool);
7474

7575
if (options.OutputFormat == CycloneDXBomFormat.autodetect) options.OutputFormat = CliUtils.AutoDetectBomFormat(options.OutputFile);
7676
if (options.OutputFormat == CycloneDXBomFormat.autodetect)

src/cyclonedx/Commands/MergeCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class MergeCommand
3030
public static void Configure(RootCommand rootCommand)
3131
{
3232
Contract.Requires(rootCommand != null);
33-
var subCommand = new Command("merge", "Merge two or more BOMs");
33+
var subCommand = new System.CommandLine.Command("merge", "Merge two or more BOMs");
3434
subCommand.Add(new Option<List<string>>("--input-files", "Input BOM filenames (separate filenames with a space)."));
3535
subCommand.Add(new Option<string>("--output-file", "Output BOM filename, will write to stdout if no value provided."));
3636
subCommand.Add(new Option<CycloneDXBomFormat>("--input-format", "Specify input file format."));

src/cyclonedx/Commands/ValidateCommand.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static class ValidateCommand
3232
public static void Configure(RootCommand rootCommand)
3333
{
3434
Contract.Requires(rootCommand != null);
35-
var subCommand = new Command("validate", "Validate a BOM");
35+
var subCommand = new System.CommandLine.Command("validate", "Validate a BOM");
3636
subCommand.Add(new Option<string>("--input-file", "Input BOM filename, will read from stdin if no value provided."));
3737
subCommand.Add(new Option<ValidationBomFormat>("--input-format", "Specify input file format."));
3838
subCommand.Add(new Option<SpecificationVersion?>("--input-version", "Specify input file specification version (defaults to v1.4)"));
@@ -75,7 +75,11 @@ public static async Task<int> Validate(ValidateCommandOptions options)
7575
}
7676
else if (options.InputFormat == ValidationBomFormat.xml)
7777
{
78-
validationResult = Xml.Validator.Validate(inputBom, SpecificationVersion.v1_4);
78+
validationResult = Xml.Validator.Validate(inputBom, SpecificationVersion.v1_5);
79+
if (!validationResult.Valid)
80+
{
81+
validationResult = Xml.Validator.Validate(inputBom, SpecificationVersion.v1_4);
82+
}
7983
if (!validationResult.Valid)
8084
{
8185
validationResult = Xml.Validator.Validate(inputBom, SpecificationVersion.v1_3);
@@ -102,7 +106,11 @@ public static async Task<int> Validate(ValidateCommandOptions options)
102106
}
103107
else if (options.InputFormat == ValidationBomFormat.json)
104108
{
105-
validationResult = Json.Validator.Validate(inputBom, SpecificationVersion.v1_4);
109+
validationResult = Json.Validator.Validate(inputBom, SpecificationVersion.v1_5);
110+
if (!validationResult.Valid)
111+
{
112+
validationResult = Json.Validator.Validate(inputBom, SpecificationVersion.v1_4);
113+
}
106114
if (!validationResult.Valid)
107115
{
108116
validationResult = Json.Validator.Validate(inputBom, SpecificationVersion.v1_3);

src/cyclonedx/Serialization/CsvSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public static Bom Deserialize(string csv)
175175
TagId = csvReader.GetField("SwidTagId").NullIfWhiteSpace(),
176176
Name = csvReader.GetField("SwidName").NullIfWhiteSpace(),
177177
Version = csvReader.GetField("SwidVersion").NullIfWhiteSpace(),
178-
TagVersion = csvReader.GetField<int?>("SwidTagVersion"),
179-
Patch = csvReader.GetField<bool?>("SwidPatch"),
178+
TagVersion = csvReader.GetField<int?>("SwidTagVersion").GetValueOrDefault(),
179+
Patch = csvReader.GetField<bool?>("SwidPatch").GetValueOrDefault(),
180180
Text = new AttachedText
181181
{
182182
ContentType = csvReader.GetField("SwidTextContentType").NullIfWhiteSpace(),

src/cyclonedx/cyclonedx.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6-
<PublishTrimmed>true</PublishTrimmed>
6+
<!-- <PublishTrimmed>true</PublishTrimmed>-->
77
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
88
<RuntimeIdentifiers>linux-x64;linux-musl-x64;linux-arm;linux-arm64;win-x64;win-x86;win-arm;win-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
99
</PropertyGroup>
@@ -15,8 +15,8 @@
1515
<ItemGroup>
1616
<PackageReference Include="CoderPatros.AntPathMatching" Version="0.1.1" />
1717
<PackageReference Include="CsvHelper" Version="29.0.0" />
18-
<PackageReference Include="CycloneDX.Utils" Version="5.2.3" />
19-
<PackageReference Include="CycloneDX.Spdx.Interop" Version="5.2.3" />
18+
<PackageReference Include="CycloneDX.Utils" Version="6.0.0" />
19+
<PackageReference Include="CycloneDX.Spdx.Interop" Version="6.0.0" />
2020
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
2121
<PackageReference Include="System.Security.Cryptography.Xml" Version="6.0.1" />
2222
</ItemGroup>

tests/cyclonedx.tests/ConvertTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,21 @@ public class ConvertTests
6060
[InlineData("bom-1.4.xml", ConvertFormat.xml, "bom.xml", ConvertFormat.xml, null)]
6161
[InlineData("bom-1.4.xml", ConvertFormat.xml, "bom.xml", ConvertFormat.xml, SpecificationVersion.v1_4)]
6262

63+
[InlineData("bom-1.5.xml", ConvertFormat.autodetect, "bom.xml", ConvertFormat.autodetect, null)]
64+
[InlineData("bom-1.5.xml", ConvertFormat.xml, "bom.xml", ConvertFormat.autodetect, null)]
65+
[InlineData("bom-1.5.xml", ConvertFormat.xml, "bom.xml", ConvertFormat.xml, null)]
66+
[InlineData("bom-1.5.xml", ConvertFormat.xml, "bom.xml", ConvertFormat.xml, SpecificationVersion.v1_5)]
67+
6368
[InlineData("bom-1.4.json", ConvertFormat.autodetect, "bom.json", ConvertFormat.autodetect, null)]
6469
[InlineData("bom-1.4.json", ConvertFormat.json, "bom.json", ConvertFormat.autodetect, null)]
6570
[InlineData("bom-1.4.json", ConvertFormat.json, "bom.json", ConvertFormat.json, null)]
6671
[InlineData("bom-1.4.json", ConvertFormat.json, "bom.json", ConvertFormat.json, SpecificationVersion.v1_4)]
6772

73+
[InlineData("bom-1.5.json", ConvertFormat.autodetect, "bom.json", ConvertFormat.autodetect, null)]
74+
[InlineData("bom-1.5.json", ConvertFormat.json, "bom.json", ConvertFormat.autodetect, null)]
75+
[InlineData("bom-1.5.json", ConvertFormat.json, "bom.json", ConvertFormat.json, null)]
76+
[InlineData("bom-1.5.json", ConvertFormat.json, "bom.json", ConvertFormat.json, SpecificationVersion.v1_5)]
77+
6878
[InlineData("bom.csv", ConvertFormat.autodetect, "bom.csv", ConvertFormat.autodetect, null)]
6979
[InlineData("bom.csv", ConvertFormat.csv, "bom.csv", ConvertFormat.autodetect, null)]
7080
[InlineData("bom.csv", ConvertFormat.csv, "bom.csv", ConvertFormat.csv, null)]

tests/cyclonedx.tests/Resources/CsvSerializer/valid-component-types.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Application,,,,,,application-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
33
Library,,,,,,library-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
44
Framework,,,,,,framework-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
55
Container,,,,,,container-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
6-
OperationSystem,,,,,,operating-system-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
6+
Operating_System,,,,,,operating-system-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
77
Firmware,,,,,,firmware-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
88
Device,,,,,,device-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
99
File,,,,,,file-a,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"bomFormat": "CycloneDX",
3+
"specVersion": "1.5",
4+
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
5+
"version": 1,
6+
"metadata": {
7+
"timestamp": "2020-04-13T20:20:39+00:00",
8+
"tools": [
9+
{
10+
"vendor": "Awesome Vendor",
11+
"name": "Awesome Tool",
12+
"version": "9.1.2",
13+
"hashes": [
14+
{
15+
"alg": "SHA-1",
16+
"content": "25ed8e31b995bb927966616df2a42b979a2717f0"
17+
},
18+
{
19+
"alg": "SHA-256",
20+
"content": "a74f733635a19aefb1f73e5947cef59cd7440c6952ef0f03d09d974274cbd6df"
21+
}
22+
]
23+
}
24+
],
25+
"authors": [
26+
{
27+
"name": "Samantha Wright",
28+
"email": "samantha.wright@example.com",
29+
"phone": "800-555-1212"
30+
}
31+
],
32+
"component": {
33+
"type": "application",
34+
"author": "Acme Super Heros",
35+
"name": "Acme Application",
36+
"version": "9.1.1",
37+
"swid": {
38+
"tagId": "swidgen-242eb18a-503e-ca37-393b-cf156ef09691_9.1.1",
39+
"name": "Acme Application",
40+
"version": "9.1.1",
41+
"text": {
42+
"contentType": "text/xml",
43+
"encoding": "base64",
44+
"content": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxTb2Z0d2FyZUlkZW50aXR5IHhtbDpsYW5nPSJFTiIgbmFtZT0iQWNtZSBBcHBsaWNhdGlvbiIgdmVyc2lvbj0iOS4xLjEiIAogdmVyc2lvblNjaGVtZT0ibXVsdGlwYXJ0bnVtZXJpYyIgCiB0YWdJZD0ic3dpZGdlbi1iNTk1MWFjOS00MmMwLWYzODItM2YxZS1iYzdhMmE0NDk3Y2JfOS4xLjEiIAogeG1sbnM9Imh0dHA6Ly9zdGFuZGFyZHMuaXNvLm9yZy9pc28vMTk3NzAvLTIvMjAxNS9zY2hlbWEueHNkIj4gCiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiAKIHhzaTpzY2hlbWFMb2NhdGlvbj0iaHR0cDovL3N0YW5kYXJkcy5pc28ub3JnL2lzby8xOTc3MC8tMi8yMDE1LWN1cnJlbnQvc2NoZW1hLnhzZCBzY2hlbWEueHNkIiA+CiAgPE1ldGEgZ2VuZXJhdG9yPSJTV0lEIFRhZyBPbmxpbmUgR2VuZXJhdG9yIHYwLjEiIC8+IAogIDxFbnRpdHkgbmFtZT0iQWNtZSwgSW5jLiIgcmVnaWQ9ImV4YW1wbGUuY29tIiByb2xlPSJ0YWdDcmVhdG9yIiAvPiAKPC9Tb2Z0d2FyZUlkZW50aXR5Pg=="
45+
}
46+
}
47+
},
48+
"manufacture": {
49+
"name": "Acme, Inc.",
50+
"url": [
51+
"https://example.com"
52+
],
53+
"contact": [
54+
{
55+
"name": "Acme Professional Services",
56+
"email": "professional.services@example.com"
57+
}
58+
]
59+
},
60+
"supplier": {
61+
"name": "Acme, Inc.",
62+
"url": [
63+
"https://example.com"
64+
],
65+
"contact": [
66+
{
67+
"name": "Acme Distribution",
68+
"email": "distribution@example.com"
69+
}
70+
]
71+
}
72+
},
73+
"components": [
74+
{
75+
"bom-ref": "pkg:npm/acme/component@1.0.0",
76+
"type": "library",
77+
"publisher": "Acme Inc",
78+
"group": "com.acme",
79+
"name": "tomcat-catalina",
80+
"version": "9.0.14",
81+
"hashes": [
82+
{
83+
"alg": "MD5",
84+
"content": "3942447fac867ae5cdb3229b658f4d48"
85+
},
86+
{
87+
"alg": "SHA-1",
88+
"content": "e6b1000b94e835ffd37f4c6dcbdad43f4b48a02a"
89+
},
90+
{
91+
"alg": "SHA-256",
92+
"content": "f498a8ff2dd007e29c2074f5e4b01a9a01775c3ff3aeaf6906ea503bc5791b7b"
93+
},
94+
{
95+
"alg": "SHA-512",
96+
"content": "e8f33e424f3f4ed6db76a482fde1a5298970e442c531729119e37991884bdffab4f9426b7ee11fccd074eeda0634d71697d6f88a460dce0ac8d627a29f7d1282"
97+
}
98+
],
99+
"licenses": [
100+
{
101+
"license": {
102+
"id": "Apache-2.0",
103+
"text": {
104+
"contentType": "text/plain",
105+
"encoding": "base64",
106+
"content": "License text here"
107+
},
108+
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt"
109+
}
110+
}
111+
],
112+
"purl": "pkg:npm/acme/component@1.0.0",
113+
"pedigree": {
114+
"ancestors": [
115+
{
116+
"type": "library",
117+
"publisher": "Acme Inc",
118+
"group": "com.acme",
119+
"name": "tomcat-catalina",
120+
"version": "9.0.14"
121+
},
122+
{
123+
"type": "library",
124+
"publisher": "Acme Inc",
125+
"group": "com.acme",
126+
"name": "tomcat-catalina",
127+
"version": "9.0.14"
128+
}
129+
],
130+
"commits": [
131+
{
132+
"uid": "7638417db6d59f3c431d3e1f261cc637155684cd",
133+
"url": "https://location/to/7638417db6d59f3c431d3e1f261cc637155684cd",
134+
"author": {
135+
"timestamp": "2018-11-13T20:20:39+00:00",
136+
"name": "me",
137+
"email": "me@acme.org"
138+
}
139+
}
140+
]
141+
}
142+
},
143+
{
144+
"type": "library",
145+
"supplier": {
146+
"name": "Example, Inc.",
147+
"url": [
148+
"https://example.com",
149+
"https://example.net"
150+
],
151+
"contact": [
152+
{
153+
"name": "Example Support AMER Distribution",
154+
"email": "support@example.com",
155+
"phone": "800-555-1212"
156+
},
157+
{
158+
"name": "Example Support APAC",
159+
"email": "support@apac.example.com"
160+
}
161+
]
162+
},
163+
"author": "Example Super Heros",
164+
"group": "org.example",
165+
"name": "mylibrary",
166+
"version": "1.0.0"
167+
}
168+
],
169+
"dependencies": [
170+
{
171+
"ref": "pkg:npm/acme/component@1.0.0",
172+
"dependsOn": [
173+
"pkg:npm/acme/component@1.0.0"
174+
]
175+
}
176+
]
177+
}

tests/cyclonedx.tests/Resources/bom-1.5.xml

Lines changed: 181 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)