20 private $tagNamespace = CycloneDxSettings::DEFAULT_NAMESPACE;
23 private $specVersion = CycloneDxSettings::DEFAULT_VERSION;
30 $this->tagNamespace = $settings->getTagNamespace();
31 $this->specVersion = $settings->getSpecVersion();
34 public function getTagNamespace(): string
36 return $this->tagNamespace;
39 public function getSpecVersion(): string
41 return $this->specVersion;
48 private function supports(
string $version): bool
50 return version_compare($this->specVersion, $version,
'>=');
84 return $this->generateLicense($licenseData);
95 $author = [
'name' =>
'FOSSology Analyst'];
97 $author[
'bom-ref'] =
'person-fossology-analyst';
101 'bomFormat' =>
'CycloneDX',
102 '$schema' =>
'http://cyclonedx.org/schema/bom-' . $this->specVersion .
'.schema.json',
103 'specVersion' => $this->specVersion,
105 'serialNumber' =>
'urn:uuid:'. uuid_create(UUID_TYPE_TIME),
107 'timestamp' => date(
'c'),
109 'authors' => [$author],
110 'component' => $bomdata[
'maincomponent']
112 'components' => $bomdata[
'components']
116 if ($this->
supports(
'1.7') && !empty($bomdata[
'citations'])) {
117 $report[
'citations'] = $bomdata[
'citations'];
120 if (!empty($bomdata[
'externalReferences'])) {
121 $report[
'externalReferences'] = $bomdata[
'externalReferences'];
134 [
'name' =>
'FOSSology',
'bom-ref' =>
'tool-fossology'],
135 [
'name' =>
'FOSSology Scanners',
'bom-ref' =>
'tool-fossology-scanners']
138 return array_map(
function ($tool) use ($toolVersion) {
139 return [
'vendor' =>
'FOSSology',
'name' => $tool[
'name'],
'version' => $toolVersion];
143 foreach ($tools as $tool) {
144 $component = [
'type' =>
'application'];
146 $component[
'manufacturer'] = [
'name' =>
'FOSSology'];
148 $components[] = $component + [
149 'name' => $tool[
'name'],
150 'version' => $toolVersion,
151 'bom-ref' => $tool[
'bom-ref']
154 return [
'components' => $components];
166 'type' => $componentData[
'type'],
167 'name' => $componentData[
'name']
170 if (array_key_exists(
'version', $componentData) && !empty($componentData[
'version'])) {
171 $component[
'version'] = $componentData[
'version'];
174 if (array_key_exists(
'mimeType', $componentData) && !empty($componentData[
'mimeType'])) {
175 $component[
'mime-type'] = $componentData[
'mimeType'];
178 if (array_key_exists(
'bomref', $componentData) && !empty($componentData[
'bomref'])) {
179 $component[
'bom-ref'] = $componentData[
'bomref'];
186 if (array_key_exists(
'scope', $componentData) && !empty($componentData[
'scope'])) {
187 $component[
'scope'] = $componentData[
'scope'];
189 $component[
'scope'] =
'required';
192 if (array_key_exists(
'hashes', $componentData) && !empty($componentData[
'hashes'])) {
193 $component[
'hashes'] = $componentData[
'hashes'];
196 if (array_key_exists(
'licenses', $componentData) && !empty($componentData[
'licenses'])) {
197 $component[
'licenses'] = $componentData[
'licenses'];
200 if (array_key_exists(
'copyright', $componentData) && !empty($componentData[
'copyright'])) {
201 $component[
'copyright'] = $componentData[
'copyright'];
204 if (array_key_exists(
'purl', $componentData) && !empty($componentData[
'purl'])) {
205 $component[
'purl'] = $componentData[
'purl'];
208 if (array_key_exists(
'description', $componentData) && !empty($componentData[
'description'])) {
209 $component[
'description'] = $componentData[
'description'];
212 if (array_key_exists(
'externalReferences', $componentData) && !empty($componentData[
'externalReferences'])) {
213 $component[
'externalReferences'] = $componentData[
'externalReferences'];
217 if (array_key_exists(
'acknowledgements', $componentData) && !empty($componentData[
'acknowledgements'])) {
219 'name' => $this->tagNamespace .
'acknowledgement',
220 'value' => $componentData[
'acknowledgements']
223 if (array_key_exists(
'comments', $componentData) && !empty($componentData[
'comments'])) {
225 'name' => $this->tagNamespace .
'comment',
226 'value' => $componentData[
'comments']
229 if (!empty($properties)) {
230 $component[
'properties'] = $properties;
236 private function generateLicense(array $licenseData): array
241 unset($licenseData[
'bom-ref']);
244 unset($licenseData[
'acknowledgement']);
247 $isLicenseRef = !empty($licenseData[
'id']) &&
248 stripos($licenseData[
'id'], LicenseRef::SPDXREF_PREFIX) === 0;
251 if ($isLicenseRef && !$this->
supports(
'1.7')) {
252 $licenseData[
'name'] = $licenseData[
'id'];
253 unset($licenseData[
'id']);
254 } elseif ($isLicenseRef) {
255 $license[
'expression'] = $licenseData[
'id'];
256 if (array_key_exists(
'bom-ref', $licenseData) && !empty($licenseData[
'bom-ref'])) {
257 $license[
'bom-ref'] = $licenseData[
'bom-ref'];
259 if (array_key_exists(
'acknowledgement', $licenseData) && !empty($licenseData[
'acknowledgement'])) {
260 $license[
'acknowledgement'] = $licenseData[
'acknowledgement'];
265 if (array_key_exists(
'id', $licenseData) && !empty($licenseData[
'id'])) {
266 $license[
'license'][
'id'] = $licenseData[
'id'];
267 }
else if (array_key_exists(
'name', $licenseData) && !empty($licenseData[
'name'])) {
268 $license[
'license'][
'name'] = $licenseData[
'name'];
271 if (array_key_exists(
'bom-ref', $licenseData) && !empty($licenseData[
'bom-ref'])) {
272 $license[
'license'][
'bom-ref'] = $licenseData[
'bom-ref'];
275 if (array_key_exists(
'acknowledgement', $licenseData) && !empty($licenseData[
'acknowledgement'])) {
276 $license[
'license'][
'acknowledgement'] = $licenseData[
'acknowledgement'];
279 if (array_key_exists(
'url', $licenseData) && !empty($licenseData[
'url'])) {
280 $license[
'license'][
'url'] = $licenseData[
'url'];
283 if (array_key_exists(
'textContent', $licenseData) && !empty($licenseData[
'textContent'])) {
284 $license[
'license'][
'text'] = [
285 'content' => $licenseData[
'textContent'],
286 'contentType' => $licenseData[
'textContentType'],
287 'encoding' =>
'base64'
301 private function generateHash(
string $algorithm,
string $content): array
305 'content' => $content
createHash($algorithm, $content)
generateHash(string $algorithm, string $content)
createComponent(array $componentData)
createLicense(array $licenseData)
generateTools($toolVersion)
applySettings(CycloneDxSettings $settings)
supports(string $version)
generateComponent(array $componentData)
CycloneDX export settings of a user (defaults) or of an upload.
Namespace used by CycloneDX agent.