diff --git a/go.mod b/go.mod index 960aca3f1..7b246b797 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/sigstore/rekor v0.12.1-0.20220915152154-4bb6f441c1b2 github.com/sigstore/sigstore v1.4.4 github.com/vbatts/go-mtree v0.5.0 + golang.org/x/exp v0.0.0-20220823124025-807a23277127 gopkg.in/yaml.v3 v3.0.1 ) @@ -288,7 +289,6 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.23.0 // indirect - golang.org/x/exp v0.0.0-20220823124025-807a23277127 // indirect golang.org/x/oauth2 v0.0.0-20221006150949-b44042a4b9c1 // indirect golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 // indirect golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect diff --git a/schema/spdx-json/spdx-schema-2.2.json b/schema/spdx-json/spdx-schema-2.2.json index 8279648c9..805b11d0b 100644 --- a/schema/spdx-json/spdx-schema-2.2.json +++ b/schema/spdx-json/spdx-schema-2.2.json @@ -1,610 +1,740 @@ { "$schema" : "http://json-schema.org/draft-07/schema#", - "$id" : "http://spdx.org/rdf/terms", - "title" : "SPDX 2.2", + "$id" : "http://spdx.org/rdf/terms/2.3", + "title" : "SPDX 2.3", "type" : "object", "properties" : { - "Document" : { - "type" : "object", - "properties" : { - "revieweds" : { - "description" : "Reviewed", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "reviewer" : { - "description" : "The name and, optionally, contact information of the person who performed the review. Values of this property must conform to the agent and tool syntax.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "reviewDate" : { - "description" : "The date and time at which the SpdxDocument was reviewed. This value must be in UTC and have 'Z' as its timezone indicator.", - "type" : "string" - } - } - } - }, - "hasExtractedLicensingInfos" : { - "description" : "Indicates that a particular ExtractedLicensingInfo was defined in the subject SpdxDocument.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "seeAlsos" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "name" : { - "description" : "Identify name of this SpdxElement.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "licenseId" : { - "description" : "A human readable short form license identifier for a license. The license ID is iether on the standard license oist or the form \"LicenseRef-\"[idString] where [idString] is a unique string containing letters, numbers, \".\", \"-\" or \"+\".", - "type" : "string" - }, - "extractedText" : { - "description" : "Verbatim license or licensing notice text that was discovered.", - "type" : "string" - } - }, - "description" : "An ExtractedLicensingInfo represents a license or licensing notice that was found in the package. Any license text that is recognized as a license may be represented as a License rather than an ExtractedLicensingInfo." - } - }, - "name" : { - "description" : "Identify name of this SpdxElement.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "spdxVersion" : { - "description" : "Provide a reference number that can be used to understand how to parse and interpret the rest of the file. It will enable both future changes to the specification and to support backward compatibility. The version number consists of a major and minor version indicator. The major field will be incremented when incompatible changes between versions are made (one or more sections are created, modified or deleted). The minor field will be incremented when backwards compatible changes are made.", - "type" : "string" - }, - "annotations" : { - "description" : "Provide additional information about an SpdxElement.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "annotationDate" : { - "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "annotator" : { - "description" : "This field identifies the person, organization or tool that has commented on a file, package, or the entire document.", - "type" : "string" - }, - "annotationType" : { - "description" : "Type of the annotation.", - "type" : "string", - "enum" : [ "OTHER", "REVIEW" ] - } - }, - "description" : "An Annotation is a comment on an SpdxItem by an agent." - } - }, - "describesPackages" : { - "description" : "The describesPackage property relates an SpdxDocument to the package which it describes.", - "type" : "array", - "items" : { - "description" : "SPDX ID for Package. The describesPackage property relates an SpdxDocument to the package which it describes.", + "SPDXID" : { + "type" : "string", + "description" : "Uniquely identify any element in an SPDX document which may be referenced by other elements." + }, + "annotations" : { + "description" : "Provide additional information about an SpdxElement.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "annotationDate" : { + "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", + "type" : "string" + }, + "annotationType" : { + "description" : "Type of the annotation.", + "type" : "string", + "enum" : [ "OTHER", "REVIEW" ] + }, + "annotator" : { + "description" : "This field identifies the person, organization, or tool that has commented on a file, package, snippet, or the entire document.", + "type" : "string" + }, + "comment" : { "type" : "string" } }, - "dataLicense" : { - "description" : "License expression for dataLicense. Compliance with the SPDX specification includes populating the SPDX fields therein with data related to such fields (\"SPDX-Metadata\"). The SPDX specification contains numerous fields where an SPDX document creator may provide relevant explanatory text in SPDX-Metadata. Without opining on the lawfulness of \"database rights\" (in jurisdictions where applicable), such explanatory text is copyrightable subject matter in most Berne Convention countries. By using the SPDX specification, or any portion hereof, you hereby agree that any copyright rights (as determined by your jurisdiction) in any SPDX-Metadata, including without limitation explanatory text, shall be subject to the terms of the Creative Commons CC0 1.0 Universal license. For SPDX-Metadata not containing any copyright rights, you hereby agree and acknowledge that the SPDX-Metadata is provided to you \"as-is\" and without any representations or warranties of any kind concerning the SPDX-Metadata, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non-infringement, or the absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.", + "required" : [ "annotationDate", "annotationType", "annotator", "comment" ], + "additionalProperties" : false, + "description" : "An Annotation is a comment on an SpdxItem by an agent." + } + }, + "comment" : { + "type" : "string" + }, + "creationInfo" : { + "type" : "object", + "properties" : { + "comment" : { "type" : "string" }, - "externalDocumentRefs" : { - "description" : "Identify any external SPDX documents referenced within this SPDX document.", + "created" : { + "description" : "Identify when the SPDX document was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard.", + "type" : "string" + }, + "creators" : { + "description" : "Identify who (or what, in the case of a tool) created the SPDX document. If the SPDX document was created by an individual, indicate the person's name. If the SPDX document was created on behalf of a company or organization, indicate the entity name. If the SPDX document was created using a software tool, indicate the name and version for that tool. If multiple participants or tools were involved, use multiple instances of this field. Person name or organization name may be designated as “anonymous” if appropriate.", + "minItems" : 1, "type" : "array", "items" : { + "description" : "Identify who (or what, in the case of a tool) created the SPDX document. If the SPDX document was created by an individual, indicate the person's name. If the SPDX document was created on behalf of a company or organization, indicate the entity name. If the SPDX document was created using a software tool, indicate the name and version for that tool. If multiple participants or tools were involved, use multiple instances of this field. Person name or organization name may be designated as “anonymous” if appropriate.", + "type" : "string" + } + }, + "licenseListVersion" : { + "description" : "An optional field for creators of the SPDX file to provide the version of the SPDX License List used when the SPDX file was created.", + "type" : "string" + } + }, + "required" : [ "created", "creators" ], + "additionalProperties" : false, + "description" : "One instance is required for each SPDX file produced. It provides the necessary information for forward and backward compatibility for processing tools." + }, + "dataLicense" : { + "description" : "License expression for dataLicense. See SPDX Annex D for the license expression syntax. Compliance with the SPDX specification includes populating the SPDX fields therein with data related to such fields (\"SPDX-Metadata\"). The SPDX specification contains numerous fields where an SPDX document creator may provide relevant explanatory text in SPDX-Metadata. Without opining on the lawfulness of \"database rights\" (in jurisdictions where applicable), such explanatory text is copyrightable subject matter in most Berne Convention countries. By using the SPDX specification, or any portion hereof, you hereby agree that any copyright rights (as determined by your jurisdiction) in any SPDX-Metadata, including without limitation explanatory text, shall be subject to the terms of the Creative Commons CC0 1.0 Universal license. For SPDX-Metadata not containing any copyright rights, you hereby agree and acknowledge that the SPDX-Metadata is provided to you \"as-is\" and without any representations or warranties of any kind concerning the SPDX-Metadata, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non-infringement, or the absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.", + "type" : "string" + }, + "externalDocumentRefs" : { + "description" : "Identify any external SPDX documents referenced within this SPDX document.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "checksum" : { "type" : "object", "properties" : { - "externalDocumentId" : { - "description" : "externalDocumentId is a string containing letters, numbers, ., - and/or + which uniquely identifies an external document within this document.", - "type" : "string" + "algorithm" : { + "description" : "Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.", + "type" : "string", + "enum" : [ "SHA1", "BLAKE3", "SHA3-384", "SHA256", "SHA384", "BLAKE2b-512", "BLAKE2b-256", "SHA3-512", "MD2", "ADLER32", "MD4", "SHA3-256", "BLAKE2b-384", "SHA512", "MD6", "MD5", "SHA224" ] }, - "checksum" : { - "type" : "object", - "properties" : { - "algorithm" : { - "description" : "Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.", - "type" : "string", - "enum" : [ "SHA256", "SHA1", "SHA384", "MD2", "MD4", "SHA512", "MD6", "MD5", "SHA224" ] - }, - "checksumValue" : { - "description" : "The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.", - "type" : "string" - } - }, - "description" : "A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented." - }, - "spdxDocument" : { - "description" : "SPDX ID for SpdxDocument. A propoerty containing an SPDX document.", + "checksumValue" : { + "description" : "The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.", "type" : "string" } }, - "description" : "Information about an external SPDX document reference including the checksum. This allows for verification of the external references." + "required" : [ "algorithm", "checksumValue" ], + "additionalProperties" : false, + "description" : "A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented." + }, + "externalDocumentId" : { + "description" : "externalDocumentId is a string containing letters, numbers, ., - and/or + which uniquely identifies an external document within this document.", + "type" : "string" + }, + "spdxDocument" : { + "description" : "SPDX ID for SpdxDocument. A property containing an SPDX document.", + "type" : "string" } }, - "creationInfo" : { - "type" : "object", - "properties" : { - "comment" : { - "type" : "string" - }, - "created" : { - "description" : "Identify when the SPDX file was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard. This field is distinct from the fields in section 8, which involves the addition of information during a subsequent review.", - "type" : "string" - }, - "creators" : { - "description" : "Identify who (or what, in the case of a tool) created the SPDX file. If the SPDX file was created by an individual, indicate the person's name. If the SPDX file was created on behalf of a company or organization, indicate the entity name. If the SPDX file was created using a software tool, indicate the name and version for that tool. If multiple participants or tools were involved, use multiple instances of this field. Person name or organization name may be designated as “anonymous” if appropriate.", - "type" : "array", - "items" : { - "description" : "Identify who (or what, in the case of a tool) created the SPDX file. If the SPDX file was created by an individual, indicate the person's name. If the SPDX file was created on behalf of a company or organization, indicate the entity name. If the SPDX file was created using a software tool, indicate the name and version for that tool. If multiple participants or tools were involved, use multiple instances of this field. Person name or organization name may be designated as “anonymous” if appropriate.", - "type" : "string" + "required" : [ "checksum", "externalDocumentId", "spdxDocument" ], + "additionalProperties" : false, + "description" : "Information about an external SPDX document reference including the checksum. This allows for verification of the external references." + } + }, + "hasExtractedLicensingInfos" : { + "description" : "Indicates that a particular ExtractedLicensingInfo was defined in the subject SpdxDocument.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "comment" : { + "type" : "string" + }, + "crossRefs" : { + "description" : "Cross Reference Detail for a license SeeAlso URL", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "isLive" : { + "description" : "Indicate a URL is still a live accessible location on the public internet", + "type" : "boolean" + }, + "isValid" : { + "description" : "True if the URL is a valid well formed URL", + "type" : "boolean" + }, + "isWayBackLink" : { + "description" : "True if the License SeeAlso URL points to a Wayback archive", + "type" : "boolean" + }, + "match" : { + "description" : "Status of a License List SeeAlso URL reference if it refers to a website that matches the license text.", + "type" : "string" + }, + "order" : { + "description" : "The ordinal order of this element within a list", + "type" : "integer" + }, + "timestamp" : { + "description" : "Timestamp", + "type" : "string" + }, + "url" : { + "description" : "URL Reference", + "type" : "string" + } }, - "minItems" : 1 - }, - "licenseListVersion" : { - "description" : "An optional field for creators of the SPDX file to provide the version of the SPDX License List used when the SPDX file was created.", + "required" : [ "url" ], + "additionalProperties" : false, + "description" : "Cross reference details for the a URL reference" + } + }, + "extractedText" : { + "description" : "Provide a copy of the actual text of the license reference extracted from the package, file or snippet that is associated with the License Identifier to aid in future analysis.", + "type" : "string" + }, + "licenseId" : { + "description" : "A human readable short form license identifier for a license. The license ID is either on the standard license list or the form \"LicenseRef-[idString]\" where [idString] is a unique string containing letters, numbers, \".\" or \"-\". When used within a license expression, the license ID can optionally include a reference to an external document in the form \"DocumentRef-[docrefIdString]:LicenseRef-[idString]\" where docRefIdString is an ID for an external document reference.", + "type" : "string" + }, + "name" : { + "description" : "Identify name of this SpdxElement.", + "type" : "string" + }, + "seeAlsos" : { + "type" : "array", + "items" : { + "type" : "string" + } + } + }, + "required" : [ "extractedText", "licenseId" ], + "additionalProperties" : false, + "description" : "An ExtractedLicensingInfo represents a license or licensing notice that was found in a package, file or snippet. Any license text that is recognized as a license may be represented as a License rather than an ExtractedLicensingInfo." + } + }, + "name" : { + "description" : "Identify name of this SpdxElement.", + "type" : "string" + }, + "revieweds" : { + "description" : "Reviewed", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "comment" : { + "type" : "string" + }, + "reviewDate" : { + "description" : "The date and time at which the SpdxDocument was reviewed. This value must be in UTC and have 'Z' as its timezone indicator.", + "type" : "string" + }, + "reviewer" : { + "description" : "The name and, optionally, contact information of the person who performed the review. Values of this property must conform to the agent and tool syntax. The reviewer property is deprecated in favor of Annotation with an annotationType review.", + "type" : "string" + } + }, + "required" : [ "reviewDate" ], + "additionalProperties" : false, + "description" : "This class has been deprecated in favor of an Annotation with an Annotation type of review." + } + }, + "spdxVersion" : { + "description" : "Provide a reference number that can be used to understand how to parse and interpret the rest of the file. It will enable both future changes to the specification and to support backward compatibility. The version number consists of a major and minor version indicator. The major field will be incremented when incompatible changes between versions are made (one or more sections are created, modified or deleted). The minor field will be incremented when backwards compatible changes are made.", + "type" : "string" + }, + "documentNamespace" : { + "type" : "string", + "description" : "The URI provides an unambiguous mechanism for other SPDX documents to reference SPDX elements within this SPDX document." + }, + "documentDescribes" : { + "description" : "Packages, files and/or Snippets described by this SPDX document", + "type" : "array", + "items" : { + "type" : "string", + "description" : "SPDX ID for each Package, File, or Snippet." + } + }, + "packages" : { + "description" : "Packages referenced in the SPDX document", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "SPDXID" : { + "type" : "string", + "description" : "Uniquely identify any element in an SPDX document which may be referenced by other elements." + }, + "annotations" : { + "description" : "Provide additional information about an SpdxElement.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "annotationDate" : { + "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", + "type" : "string" + }, + "annotationType" : { + "description" : "Type of the annotation.", + "type" : "string", + "enum" : [ "OTHER", "REVIEW" ] + }, + "annotator" : { + "description" : "This field identifies the person, organization, or tool that has commented on a file, package, snippet, or the entire document.", + "type" : "string" + }, + "comment" : { + "type" : "string" + } + }, + "required" : [ "annotationDate", "annotationType", "annotator", "comment" ], + "additionalProperties" : false, + "description" : "An Annotation is a comment on an SpdxItem by an agent." + } + }, + "attributionTexts" : { + "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include the actual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", + "type" : "array", + "items" : { + "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include the actual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", "type" : "string" } }, - "description" : "One instance is required for each SPDX file produced. It provides the necessary information for forward and backward compatibility for processing tools." - }, - "packages" : { - "description" : "Packages referenced in the SPDX document", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "attributionTexts" : { - "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", - "type" : "array", - "items" : { - "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", - "type" : "string" - } - }, - "annotations" : { - "description" : "Provide additional information about an SpdxElement.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "annotationDate" : { - "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "annotator" : { - "description" : "This field identifies the person, organization or tool that has commented on a file, package, or the entire document.", - "type" : "string" - }, - "annotationType" : { - "description" : "Type of the annotation.", - "type" : "string", - "enum" : [ "OTHER", "REVIEW" ] - } - }, - "description" : "An Annotation is a comment on an SpdxItem by an agent." - } - }, - "supplier" : { - "description" : "The name and, optionally, contact information of the person or organization who was the immediate supplier of this package to the recipient. The supplier may be different than originator when the software has been repackaged. Values of this property must conform to the agent and tool syntax.", - "type" : "string" - }, - "homepage" : { - "type" : "string" - }, - "packageVerificationCode" : { - "type" : "object", - "properties" : { - "packageVerificationCodeValue" : { - "description" : "The actual package verification code as a hex encoded value.", - "type" : "string" - }, - "packageVerificationCodeExcludedFiles" : { - "description" : "A file that was excluded when calculating the package verification code. This is usually a file containing SPDX data regarding the package. If a package contains more than one SPDX file all SPDX files must be excluded from the package verification code. If this is not done it would be impossible to correctly calculate the verification codes in both files.", - "type" : "array", - "items" : { - "description" : "A file that was excluded when calculating the package verification code. This is usually a file containing SPDX data regarding the package. If a package contains more than one SPDX file all SPDX files must be excluded from the package verification code. If this is not done it would be impossible to correctly calculate the verification codes in both files.", - "type" : "string" - } - } - }, - "description" : "A manifest based verification code (the algorithm is defined in section 4.7 of the full specification) of the SPDX Item. This allows consumers of this data and/or database to determine if an SPDX item they have in hand is identical to the SPDX item from which the data was produced. This algorithm works even if the SPDX document is included in the SPDX item." - }, - "checksums" : { - "description" : "The checksum property provides a mechanism that can be used to verify that the contents of a File or Package have not changed.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "algorithm" : { - "description" : "Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.", - "type" : "string", - "enum" : [ "SHA256", "SHA1", "SHA384", "MD2", "MD4", "SHA512", "MD6", "MD5", "SHA224" ] - }, - "checksumValue" : { - "description" : "The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.", - "type" : "string" - } - }, - "description" : "A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented." - } - }, - "downloadLocation" : { - "description" : "The URI at which this package is available for download. Private (i.e., not publicly reachable) URIs are acceptable as values of this property. The values http://spdx.org/rdf/terms#none and http://spdx.org/rdf/terms#noassertion may be used to specify that the package is not downloadable or that no attempt was made to determine its download location, respectively.", - "type" : "string" - }, - "filesAnalyzed" : { - "description" : "Indicates whether the file content of this package has been available for or subjected to analysis when creating the SPDX document. If false indicates packages that represent metadata or URI references to a project, product, artifact, distribution or a component. If set to false, the package must not contain any files.", - "type" : "boolean" - }, - "externalRefs" : { - "description" : "An External Reference allows a Package to reference an external source of additional information, metadata, enumerations, asset identifiers, or downloadable content believed to be relevant to the Package.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "comment" : { - "type" : "string" - }, - "referenceCategory" : { - "description" : "Category for the external reference", - "type" : "string", - "enum" : [ "OTHER", "SECURITY", "PACKAGE_MANAGER" ] - }, - "referenceLocator" : { - "description" : "The unique string with no spaces necessary to access the package-specific information, metadata, or content within the target location. The format of the locator is subject to constraints defined by the .", - "type" : "string" - }, - "referenceType" : { - "description" : "Type of the external reference. These are definined in an appendix in the SPDX specification.", - "type" : "string" - } - }, - "description" : "An External Reference allows a Package to reference an external source of additional information, metadata, enumerations, asset identifiers, or downloadable content believed to be relevant to the Package." - } - }, - "licenseComments" : { - "description" : "The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.", - "type" : "string" - }, - "name" : { - "description" : "Identify name of this SpdxElement.", - "type" : "string" - }, - "hasFiles" : { - "description" : "Indicates that a particular file belongs to a package.", - "type" : "array", - "items" : { - "description" : "SPDX ID for File. Indicates that a particular file belongs to a package.", - "type" : "string" - } - }, - "comment" : { - "type" : "string" - }, - "summary" : { - "description" : "Provides a short description of the package.", - "type" : "string" - }, - "copyrightText" : { - "description" : "The text of copyright declarations recited in the Package or File.", - "type" : "string" - }, - "originator" : { - "description" : "The name and, optionally, contact information of the person or organization that originally created the package. Values of this property must conform to the agent and tool syntax.", - "type" : "string" - }, - "packageFileName" : { - "description" : "The base name of the package file name. For example, zlib-1.2.5.tar.gz.", - "type" : "string" - }, - "licenseInfoFromFiles" : { - "description" : "The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.", - "type" : "array", - "items" : { - "description" : "License expression for licenseInfoFromFiles. The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.", - "type" : "string" - } - }, - "versionInfo" : { - "description" : "Provides an indication of the version of the package that is described by this SpdxDocument.", - "type" : "string" - }, - "sourceInfo" : { - "description" : "Allows the producer(s) of the SPDX document to describe how the package was acquired and/or changed from the original source.", - "type" : "string" - }, - "description" : { - "description" : "Provides a detailed description of the package.", - "type" : "string" - } - } - } - }, - "files" : { - "description" : "Files referenced in the SPDX document", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "fileTypes" : { - "description" : "The type of the file.", - "type" : "array", - "items" : { - "description" : "The type of the file.", + "builtDate" : { + "description" : "This field provides a place for recording the actual date the package was built.", + "type" : "string" + }, + "checksums" : { + "description" : "The checksum property provides a mechanism that can be used to verify that the contents of a File or Package have not changed.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "algorithm" : { + "description" : "Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.", "type" : "string", - "enum" : [ "OTHER", "DOCUMENTATION", "IMAGE", "VIDEO", "ARCHIVE", "SPDX", "APPLICATION", "SOURCE", "BINARY", "TEXT", "AUDIO" ] - } - }, - "attributionTexts" : { - "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", - "type" : "array", - "items" : { - "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", - "type" : "string" - } - }, - "annotations" : { - "description" : "Provide additional information about an SpdxElement.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "annotationDate" : { - "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "annotator" : { - "description" : "This field identifies the person, organization or tool that has commented on a file, package, or the entire document.", - "type" : "string" - }, - "annotationType" : { - "description" : "Type of the annotation.", - "type" : "string", - "enum" : [ "OTHER", "REVIEW" ] - } - }, - "description" : "An Annotation is a comment on an SpdxItem by an agent." - } - }, - "checksums" : { - "description" : "The checksum property provides a mechanism that can be used to verify that the contents of a File or Package have not changed.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "algorithm" : { - "description" : "Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.", - "type" : "string", - "enum" : [ "SHA256", "SHA1", "SHA384", "MD2", "MD4", "SHA512", "MD6", "MD5", "SHA224" ] - }, - "checksumValue" : { - "description" : "The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.", - "type" : "string" - } - }, - "description" : "A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented." + "enum" : [ "SHA1", "BLAKE3", "SHA3-384", "SHA256", "SHA384", "BLAKE2b-512", "BLAKE2b-256", "SHA3-512", "MD2", "ADLER32", "MD4", "SHA3-256", "BLAKE2b-384", "SHA512", "MD6", "MD5", "SHA224" ] }, - "minItems" : 1 - }, - "noticeText" : { - "description" : "This field provides a place for the SPDX file creator to record potential legal notices found in the file. This may or may not include copyright statements.", - "type" : "string" - }, - "artifactOfs" : { - "description" : "Indicates the project in which the SpdxElement originated. Tools must preserve doap:homepage and doap:name properties and the URI (if one is known) of doap:Project resources that are values of this property. All other properties of doap:Projects are not directly supported by SPDX and may be dropped when translating to or from some SPDX formats.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { } - } - }, - "licenseComments" : { - "description" : "The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.", - "type" : "string" - }, - "fileName" : { - "description" : "The name of the file relative to the root of the package.", - "type" : "string" - }, - "name" : { - "description" : "Identify name of this SpdxElement.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "copyrightText" : { - "description" : "The text of copyright declarations recited in the Package or File.", - "type" : "string" - }, - "fileContributors" : { - "description" : "This field provides a place for the SPDX file creator to record file contributors. Contributors could include names of copyright holders and/or authors who may not be copyright holders yet contributed to the file content.", - "type" : "array", - "items" : { - "description" : "This field provides a place for the SPDX file creator to record file contributors. Contributors could include names of copyright holders and/or authors who may not be copyright holders yet contributed to the file content.", + "checksumValue" : { + "description" : "The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.", "type" : "string" } }, - "licenseInfoInFiles" : { - "description" : "Licensing information that was discovered directly in the subject file. This is also considered a declared license for the file.", - "type" : "array", - "items" : { - "description" : "License expression for licenseInfoInFile. Licensing information that was discovered directly in the subject file. This is also considered a declared license for the file.", - "type" : "string" - }, - "minItems" : 1 - }, - "licenseInfoFromFiles" : { - "description" : "The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.", - "type" : "array", - "items" : { - "description" : "License expression for licenseInfoFromFiles. The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.", - "type" : "string" - } - }, - "fileDependencies" : { - "type" : "array", - "items" : { - "description" : "SPDX ID for File", - "type" : "string" - } - } + "required" : [ "algorithm", "checksumValue" ], + "additionalProperties" : false, + "description" : "A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented." } - } - }, - "snippets" : { - "description" : "Snippets referenced in the SPDX document", - "type" : "array", - "items" : { + }, + "comment" : { + "type" : "string" + }, + "copyrightText" : { + "description" : "The text of copyright declarations recited in the package, file or snippet.\n\nIf the copyrightText field is not present, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + }, + "description" : { + "description" : "Provides a detailed description of the package.", + "type" : "string" + }, + "downloadLocation" : { + "description" : "The URI at which this package is available for download. Private (i.e., not publicly reachable) URIs are acceptable as values of this property. The values http://spdx.org/rdf/terms#none and http://spdx.org/rdf/terms#noassertion may be used to specify that the package is not downloadable or that no attempt was made to determine its download location, respectively.", + "type" : "string" + }, + "externalRefs" : { + "description" : "An External Reference allows a Package to reference an external source of additional information, metadata, enumerations, asset identifiers, or downloadable content believed to be relevant to the Package.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "comment" : { + "type" : "string" + }, + "referenceCategory" : { + "description" : "Category for the external reference", + "type" : "string", + "enum" : [ "OTHER", "PERSISTENT-ID", "PERSISTENT_ID", "SECURITY", "PACKAGE-MANAGER", "PACKAGE_MANAGER" ] + }, + "referenceLocator" : { + "description" : "The unique string with no spaces necessary to access the package-specific information, metadata, or content within the target location. The format of the locator is subject to constraints defined by the .", + "type" : "string" + }, + "referenceType" : { + "description" : "Type of the external reference. These are defined in an appendix in the SPDX specification.", + "type" : "string" + } + }, + "required" : [ "referenceCategory", "referenceLocator", "referenceType" ], + "additionalProperties" : false, + "description" : "An External Reference allows a Package to reference an external source of additional information, metadata, enumerations, asset identifiers, or downloadable content believed to be relevant to the Package." + } + }, + "filesAnalyzed" : { + "description" : "Indicates whether the file content of this package has been available for or subjected to analysis when creating the SPDX document. If false indicates packages that represent metadata or URI references to a project, product, artifact, distribution or a component. If set to false, the package must not contain any files.", + "type" : "boolean" + }, + "hasFiles" : { + "description" : "Indicates that a particular file belongs to a package.", + "type" : "array", + "items" : { + "description" : "SPDX ID for File. Indicates that a particular file belongs to a package.", + "type" : "string" + } + }, + "homepage" : { + "type" : "string" + }, + "licenseComments" : { + "description" : "The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.", + "type" : "string" + }, + "licenseConcluded" : { + "description" : "License expression for licenseConcluded. See SPDX Annex D for the license expression syntax. The licensing that the preparer of this SPDX document has concluded, based on the evidence, actually applies to the SPDX Item.\n\nIf the licenseConcluded field is not present for an SPDX Item, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + }, + "licenseDeclared" : { + "description" : "License expression for licenseDeclared. See SPDX Annex D for the license expression syntax. The licensing that the creators of the software in the package, or the packager, have declared. Declarations by the original software creator should be preferred, if they exist.", + "type" : "string" + }, + "licenseInfoFromFiles" : { + "description" : "The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.\n\nIf the licenseInfoFromFiles field is not present for a package and filesAnalyzed property for that same pacakge is true or omitted, it implies an equivalent meaning to NOASSERTION.", + "type" : "array", + "items" : { + "description" : "License expression for licenseInfoFromFiles. See SPDX Annex D for the license expression syntax. The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.\n\nIf the licenseInfoFromFiles field is not present for a package and filesAnalyzed property for that same pacakge is true or omitted, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + } + }, + "name" : { + "description" : "Identify name of this SpdxElement.", + "type" : "string" + }, + "originator" : { + "description" : "The name and, optionally, contact information of the person or organization that originally created the package. Values of this property must conform to the agent and tool syntax.", + "type" : "string" + }, + "packageFileName" : { + "description" : "The base name of the package file name. For example, zlib-1.2.5.tar.gz.", + "type" : "string" + }, + "packageVerificationCode" : { "type" : "object", "properties" : { - "ranges" : { - "description" : "This field defines the byte range in the original host file (in X.2) that the snippet information applies to", + "packageVerificationCodeExcludedFiles" : { + "description" : "A file that was excluded when calculating the package verification code. This is usually a file containing SPDX data regarding the package. If a package contains more than one SPDX file all SPDX files must be excluded from the package verification code. If this is not done it would be impossible to correctly calculate the verification codes in both files.", "type" : "array", "items" : { - "type" : "object", - "properties" : { - "startPointer" : { - "type" : "object", - "properties" : { - "reference" : { - "description" : "SPDX ID for File", - "type" : "string" - } - } - }, - "endPointer" : { - "type" : "object", - "properties" : { - "reference" : { - "description" : "SPDX ID for File", - "type" : "string" - } - } - } - } - }, - "minItems" : 1 - }, - "licenseComments" : { - "description" : "The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.", - "type" : "string" - }, - "attributionTexts" : { - "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", - "type" : "array", - "items" : { - "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", + "description" : "A file that was excluded when calculating the package verification code. This is usually a file containing SPDX data regarding the package. If a package contains more than one SPDX file all SPDX files must be excluded from the package verification code. If this is not done it would be impossible to correctly calculate the verification codes in both files.", "type" : "string" } }, - "name" : { - "description" : "Identify name of this SpdxElement.", + "packageVerificationCodeValue" : { + "description" : "The actual package verification code as a hex encoded value.", "type" : "string" - }, - "snippetFromFile" : { - "description" : "SPDX ID for File. File containing the SPDX element (e.g. the file contaning a snippet).", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "copyrightText" : { - "description" : "The text of copyright declarations recited in the Package or File.", - "type" : "string" - }, - "licenseInfoInSnippets" : { - "description" : "Licensing information that was discovered directly in the subject snippet. This is also considered a declared license for the snippet.", - "type" : "array", - "items" : { - "description" : "License expression for licenseInfoInSnippet. Licensing information that was discovered directly in the subject snippet. This is also considered a declared license for the snippet.", - "type" : "string" - } - }, - "annotations" : { - "description" : "Provide additional information about an SpdxElement.", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "annotationDate" : { - "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", - "type" : "string" - }, - "comment" : { - "type" : "string" - }, - "annotator" : { - "description" : "This field identifies the person, organization or tool that has commented on a file, package, or the entire document.", - "type" : "string" - }, - "annotationType" : { - "description" : "Type of the annotation.", - "type" : "string", - "enum" : [ "OTHER", "REVIEW" ] - } - }, - "description" : "An Annotation is a comment on an SpdxItem by an agent." - } - }, - "licenseInfoFromFiles" : { - "description" : "The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.", - "type" : "array", - "items" : { - "description" : "License expression for licenseInfoFromFiles. The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.", - "type" : "string" - } } - } + }, + "required" : [ "packageVerificationCodeValue" ], + "additionalProperties" : false, + "description" : "A manifest based verification code (the algorithm is defined in section 4.7 of the full specification) of the SPDX Item. This allows consumers of this data and/or database to determine if an SPDX item they have in hand is identical to the SPDX item from which the data was produced. This algorithm works even if the SPDX document is included in the SPDX item." + }, + "primaryPackagePurpose" : { + "description" : "This field provides information about the primary purpose of the identified package. Package Purpose is intrinsic to how the package is being used rather than the content of the package.", + "type" : "string", + "enum" : [ "OTHER", "INSTALL", "ARCHIVE", "FIRMWARE", "APPLICATION", "FRAMEWORK", "LIBRARY", "CONTAINER", "SOURCE", "DEVICE", "OPERATING_SYSTEM", "FILE" ] + }, + "releaseDate" : { + "description" : "This field provides a place for recording the date the package was released.", + "type" : "string" + }, + "sourceInfo" : { + "description" : "Allows the producer(s) of the SPDX document to describe how the package was acquired and/or changed from the original source.", + "type" : "string" + }, + "summary" : { + "description" : "Provides a short description of the package.", + "type" : "string" + }, + "supplier" : { + "description" : "The name and, optionally, contact information of the person or organization who was the immediate supplier of this package to the recipient. The supplier may be different than originator when the software has been repackaged. Values of this property must conform to the agent and tool syntax.", + "type" : "string" + }, + "validUntilDate" : { + "description" : "This field provides a place for recording the end of the support period for a package from the supplier.", + "type" : "string" + }, + "versionInfo" : { + "description" : "Provides an indication of the version of the package that is described by this SpdxDocument.", + "type" : "string" } }, - "relationships" : { - "description" : "Relationships referenced in the SPDX document", - "type" : "array", - "items" : { - "type" : "object", - "properties" : { - "comment" : { - "type" : "string" + "required" : [ "SPDXID", "downloadLocation", "name" ], + "additionalProperties" : false + } + }, + "files" : { + "description" : "Files referenced in the SPDX document", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "SPDXID" : { + "type" : "string", + "description" : "Uniquely identify any element in an SPDX document which may be referenced by other elements." + }, + "annotations" : { + "description" : "Provide additional information about an SpdxElement.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "annotationDate" : { + "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", + "type" : "string" + }, + "annotationType" : { + "description" : "Type of the annotation.", + "type" : "string", + "enum" : [ "OTHER", "REVIEW" ] + }, + "annotator" : { + "description" : "This field identifies the person, organization, or tool that has commented on a file, package, snippet, or the entire document.", + "type" : "string" + }, + "comment" : { + "type" : "string" + } }, - "relationshipType" : { - "description" : "Describes the type of relationship between two SPDX elements.", - "type" : "string", - "enum" : [ "VARIANT_OF", "COPY_OF", "PATCH_FOR", "TEST_DEPENDENCY_OF", "CONTAINED_BY", "DATA_FILE_OF", "OPTIONAL_COMPONENT_OF", "ANCESTOR_OF", "GENERATES", "CONTAINS", "OPTIONAL_DEPENDENCY_OF", "FILE_ADDED", "DEV_DEPENDENCY_OF", "DEPENDENCY_OF", "BUILD_DEPENDENCY_OF", "DESCRIBES", "PREREQUISITE_FOR", "HAS_PREREQUISITE", "PROVIDED_DEPENDENCY_OF", "DYNAMIC_LINK", "DESCRIBED_BY", "METAFILE_OF", "DEPENDENCY_MANIFEST_OF", "PATCH_APPLIED", "RUNTIME_DEPENDENCY_OF", "TEST_OF", "TEST_TOOL_OF", "DEPENDS_ON", "FILE_MODIFIED", "DISTRIBUTION_ARTIFACT", "DOCUMENTATION_OF", "GENERATED_FROM", "STATIC_LINK", "OTHER", "BUILD_TOOL_OF", "TEST_CASE_OF", "PACKAGE_OF", "DESCENDANT_OF", "FILE_DELETED", "EXPANDED_FROM_ARCHIVE", "DEV_TOOL_OF", "EXAMPLE_OF" ] - }, - "relatedSpdxElement" : { - "description" : "SPDX ID for SpdxElement. A related SpdxElement.", - "type" : "string" - } + "required" : [ "annotationDate", "annotationType", "annotator", "comment" ], + "additionalProperties" : false, + "description" : "An Annotation is a comment on an SpdxItem by an agent." } + }, + "artifactOfs" : { + "description" : "Indicates the project in which the SpdxElement originated. Tools must preserve doap:homepage and doap:name properties and the URI (if one is known) of doap:Project resources that are values of this property. All other properties of doap:Projects are not directly supported by SPDX and may be dropped when translating to or from some SPDX formats.", + "type" : "array", + "items" : { + "type" : "object" + } + }, + "attributionTexts" : { + "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include the actual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", + "type" : "array", + "items" : { + "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include the actual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", + "type" : "string" + } + }, + "checksums" : { + "description" : "The checksum property provides a mechanism that can be used to verify that the contents of a File or Package have not changed.", + "minItems" : 1, + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "algorithm" : { + "description" : "Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.", + "type" : "string", + "enum" : [ "SHA1", "BLAKE3", "SHA3-384", "SHA256", "SHA384", "BLAKE2b-512", "BLAKE2b-256", "SHA3-512", "MD2", "ADLER32", "MD4", "SHA3-256", "BLAKE2b-384", "SHA512", "MD6", "MD5", "SHA224" ] + }, + "checksumValue" : { + "description" : "The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.", + "type" : "string" + } + }, + "required" : [ "algorithm", "checksumValue" ], + "additionalProperties" : false, + "description" : "A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented." + } + }, + "comment" : { + "type" : "string" + }, + "copyrightText" : { + "description" : "The text of copyright declarations recited in the package, file or snippet.\n\nIf the copyrightText field is not present, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + }, + "fileContributors" : { + "description" : "This field provides a place for the SPDX file creator to record file contributors. Contributors could include names of copyright holders and/or authors who may not be copyright holders yet contributed to the file content.", + "type" : "array", + "items" : { + "description" : "This field provides a place for the SPDX file creator to record file contributors. Contributors could include names of copyright holders and/or authors who may not be copyright holders yet contributed to the file content.", + "type" : "string" + } + }, + "fileDependencies" : { + "description" : "This field is deprecated since SPDX 2.0 in favor of using Section 7 which provides more granularity about relationships.", + "type" : "array", + "items" : { + "description" : "SPDX ID for File. This field is deprecated since SPDX 2.0 in favor of using Section 7 which provides more granularity about relationships.", + "type" : "string" + } + }, + "fileName" : { + "description" : "The name of the file relative to the root of the package.", + "type" : "string" + }, + "fileTypes" : { + "description" : "The type of the file.", + "type" : "array", + "items" : { + "description" : "The type of the file.", + "type" : "string", + "enum" : [ "OTHER", "DOCUMENTATION", "IMAGE", "VIDEO", "ARCHIVE", "SPDX", "APPLICATION", "SOURCE", "BINARY", "TEXT", "AUDIO" ] + } + }, + "licenseComments" : { + "description" : "The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.", + "type" : "string" + }, + "licenseConcluded" : { + "description" : "License expression for licenseConcluded. See SPDX Annex D for the license expression syntax. The licensing that the preparer of this SPDX document has concluded, based on the evidence, actually applies to the SPDX Item.\n\nIf the licenseConcluded field is not present for an SPDX Item, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + }, + "licenseInfoInFiles" : { + "description" : "Licensing information that was discovered directly in the subject file. This is also considered a declared license for the file.\n\nIf the licenseInfoInFile field is not present for a file, it implies an equivalent meaning to NOASSERTION.", + "type" : "array", + "items" : { + "description" : "License expression for licenseInfoInFile. See SPDX Annex D for the license expression syntax. Licensing information that was discovered directly in the subject file. This is also considered a declared license for the file.\n\nIf the licenseInfoInFile field is not present for a file, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + } + }, + "noticeText" : { + "description" : "This field provides a place for the SPDX file creator to record potential legal notices found in the file. This may or may not include copyright statements.", + "type" : "string" } - } + }, + "required" : [ "SPDXID", "checksums", "fileName" ], + "additionalProperties" : false + } + }, + "snippets" : { + "description" : "Snippets referenced in the SPDX document", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "SPDXID" : { + "type" : "string", + "description" : "Uniquely identify any element in an SPDX document which may be referenced by other elements." + }, + "annotations" : { + "description" : "Provide additional information about an SpdxElement.", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "annotationDate" : { + "description" : "Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.", + "type" : "string" + }, + "annotationType" : { + "description" : "Type of the annotation.", + "type" : "string", + "enum" : [ "OTHER", "REVIEW" ] + }, + "annotator" : { + "description" : "This field identifies the person, organization, or tool that has commented on a file, package, snippet, or the entire document.", + "type" : "string" + }, + "comment" : { + "type" : "string" + } + }, + "required" : [ "annotationDate", "annotationType", "annotator", "comment" ], + "additionalProperties" : false, + "description" : "An Annotation is a comment on an SpdxItem by an agent." + } + }, + "attributionTexts" : { + "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include the actual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", + "type" : "array", + "items" : { + "description" : "This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include the actual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.", + "type" : "string" + } + }, + "comment" : { + "type" : "string" + }, + "copyrightText" : { + "description" : "The text of copyright declarations recited in the package, file or snippet.\n\nIf the copyrightText field is not present, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + }, + "licenseComments" : { + "description" : "The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.", + "type" : "string" + }, + "licenseConcluded" : { + "description" : "License expression for licenseConcluded. See SPDX Annex D for the license expression syntax. The licensing that the preparer of this SPDX document has concluded, based on the evidence, actually applies to the SPDX Item.\n\nIf the licenseConcluded field is not present for an SPDX Item, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + }, + "licenseInfoInSnippets" : { + "description" : "Licensing information that was discovered directly in the subject snippet. This is also considered a declared license for the snippet.\n\nIf the licenseInfoInSnippet field is not present for a snippet, it implies an equivalent meaning to NOASSERTION.", + "type" : "array", + "items" : { + "description" : "License expression for licenseInfoInSnippet. See SPDX Annex D for the license expression syntax. Licensing information that was discovered directly in the subject snippet. This is also considered a declared license for the snippet.\n\nIf the licenseInfoInSnippet field is not present for a snippet, it implies an equivalent meaning to NOASSERTION.", + "type" : "string" + } + }, + "name" : { + "description" : "Identify name of this SpdxElement.", + "type" : "string" + }, + "ranges" : { + "description" : "This field defines the byte range in the original host file (in X.2) that the snippet information applies to", + "minItems" : 1, + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "endPointer" : { + "type" : "object", + "properties" : { + "reference" : { + "description" : "SPDX ID for File", + "type" : "string" + }, + "offset" : { + "type" : "integer", + "description" : "Byte offset in the file" + }, + "lineNumber" : { + "type" : "integer", + "description" : "line number offset in the file" + } + }, + "required" : [ "reference" ], + "additionalProperties" : false + }, + "startPointer" : { + "type" : "object", + "properties" : { + "reference" : { + "description" : "SPDX ID for File", + "type" : "string" + }, + "offset" : { + "type" : "integer", + "description" : "Byte offset in the file" + }, + "lineNumber" : { + "type" : "integer", + "description" : "line number offset in the file" + } + }, + "required" : [ "reference" ], + "additionalProperties" : false + } + }, + "required" : [ "endPointer", "startPointer" ], + "additionalProperties" : false + } + }, + "snippetFromFile" : { + "description" : "SPDX ID for File. File containing the SPDX element (e.g. the file contaning a snippet).", + "type" : "string" + } + }, + "required" : [ "SPDXID", "name", "ranges", "snippetFromFile" ], + "additionalProperties" : false + } + }, + "relationships" : { + "description" : "Relationships referenced in the SPDX document", + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "spdxElementId" : { + "type" : "string", + "description" : "Id to which the SPDX element is related" + }, + "comment" : { + "type" : "string" + }, + "relatedSpdxElement" : { + "description" : "SPDX ID for SpdxElement. A related SpdxElement.", + "type" : "string" + }, + "relationshipType" : { + "description" : "Describes the type of relationship between two SPDX elements.", + "type" : "string", + "enum" : [ "VARIANT_OF", "COPY_OF", "PATCH_FOR", "TEST_DEPENDENCY_OF", "CONTAINED_BY", "DATA_FILE_OF", "OPTIONAL_COMPONENT_OF", "ANCESTOR_OF", "GENERATES", "CONTAINS", "OPTIONAL_DEPENDENCY_OF", "FILE_ADDED", "REQUIREMENT_DESCRIPTION_FOR", "DEV_DEPENDENCY_OF", "DEPENDENCY_OF", "BUILD_DEPENDENCY_OF", "DESCRIBES", "PREREQUISITE_FOR", "HAS_PREREQUISITE", "PROVIDED_DEPENDENCY_OF", "DYNAMIC_LINK", "DESCRIBED_BY", "METAFILE_OF", "DEPENDENCY_MANIFEST_OF", "PATCH_APPLIED", "RUNTIME_DEPENDENCY_OF", "TEST_OF", "TEST_TOOL_OF", "DEPENDS_ON", "SPECIFICATION_FOR", "FILE_MODIFIED", "DISTRIBUTION_ARTIFACT", "AMENDS", "DOCUMENTATION_OF", "GENERATED_FROM", "STATIC_LINK", "OTHER", "BUILD_TOOL_OF", "TEST_CASE_OF", "PACKAGE_OF", "DESCENDANT_OF", "FILE_DELETED", "EXPANDED_FROM_ARCHIVE", "DEV_TOOL_OF", "EXAMPLE_OF" ] + } + }, + "required" : [ "spdxElementId", "relatedSpdxElement", "relationshipType" ], + "additionalProperties" : false } } - } -} \ No newline at end of file + }, + "required" : [ "SPDXID", "creationInfo", "dataLicense", "name", "spdxVersion", "documentNamespace" ], + "additionalProperties" : false +} diff --git a/syft/artifact/relationship.go b/syft/artifact/relationship.go index 1ee73a559..0428192d1 100644 --- a/syft/artifact/relationship.go +++ b/syft/artifact/relationship.go @@ -17,6 +17,15 @@ const ( DescribedByRelationship RelationshipType = "described-by" ) +func AllRelationshipTypes() []RelationshipType { + return []RelationshipType{ + OwnershipByFileOverlapRelationship, + ContainsRelationship, + DependencyOfRelationship, + DescribedByRelationship, + } +} + type RelationshipType string type Relationship struct { diff --git a/syft/file/digest_cataloger.go b/syft/file/digest_cataloger.go index 50dccac8d..c435dd107 100644 --- a/syft/file/digest_cataloger.go +++ b/syft/file/digest_cataloger.go @@ -92,15 +92,11 @@ func DigestsFromFile(closer io.ReadCloser, hashes []crypto.Hash) ([]Digest, erro writers[idx] = hashers[idx] } - size, err := io.Copy(io.MultiWriter(writers...), closer) + _, err := io.Copy(io.MultiWriter(writers...), closer) if err != nil { return nil, err } - if size == 0 { - return make([]Digest, 0), nil - } - result := make([]Digest, len(hashes)) // only capture digests when there is content. It is important to do this based on SIZE and not // FILE TYPE. The reasoning is that it is possible for a tar to be crafted with a header-only diff --git a/syft/file/digest_cataloger_test.go b/syft/file/digest_cataloger_test.go index c2f3c6b5f..dc017fbf9 100644 --- a/syft/file/digest_cataloger_test.go +++ b/syft/file/digest_cataloger_test.go @@ -29,12 +29,6 @@ func testDigests(t testing.TB, root string, files []string, hashes ...crypto.Has t.Fatalf("could not read %q : %+v", f, err) } - if len(b) == 0 { - // we don't keep digests for empty files - digests[source.NewLocation(f).Coordinates] = []Digest{} - continue - } - for _, hash := range hashes { h := hash.New() h.Write(b) diff --git a/syft/formats/common/spdxhelpers/to_format_model.go b/syft/formats/common/spdxhelpers/to_format_model.go index be2c1018d..ed9c3220b 100644 --- a/syft/formats/common/spdxhelpers/to_format_model.go +++ b/syft/formats/common/spdxhelpers/to_format_model.go @@ -1,6 +1,8 @@ +//nolint:gosec // sha1 is used as a required hash function for SPDX, not a crypto function package spdxhelpers import ( + "crypto/sha1" "fmt" "sort" "strings" @@ -103,7 +105,7 @@ func ToFormatModel(s sbom.SBOM) *spdx.Document { // Cardinality: optional, one CreatorComment: "", }, - Packages: toPackages(s.Artifacts.PackageCatalog), + Packages: toPackages(s.Artifacts.PackageCatalog, s), Files: toFiles(s), Relationships: toRelationships(s.RelationshipsSorted()), } @@ -123,7 +125,7 @@ func toSPDXID(identifiable artifact.Identifiable) common.ElementID { // packages populates all Package Information from the package Catalog (see https://spdx.github.io/spdx-spec/3-package-information/) // //nolint:funlen -func toPackages(catalog *pkg.Catalog) (results []*spdx.Package) { +func toPackages(catalog *pkg.Catalog, sbom sbom.SBOM) (results []*spdx.Package) { for _, p := range catalog.Sorted() { // name should be guaranteed to be unique, but semantically useful and stable id := toSPDXID(p) @@ -132,7 +134,25 @@ func toPackages(catalog *pkg.Catalog) (results []*spdx.Package) { // in the Comments on License field (section 7.16). With respect to NOASSERTION, a written explanation in // the Comments on License field (section 7.16) is preferred. license := License(p) - checksums, filesAnalyzed := toPackageChecksums(p) + + // two ways to get filesAnalyzed == true: + // 1. syft has generated a sha1 digest for the package itself - usually in the java cataloger + // 2. syft has generated a sha1 digest for the package's contents + packageChecksums, filesAnalyzed := toPackageChecksums(p) + + packageVerificationCode := newPackageVerificationCode(p, sbom) + if packageVerificationCode != nil { + filesAnalyzed = true + } + + // invalid SPDX document state + if filesAnalyzed && packageVerificationCode == nil { + // this is an invalid document state + // we reset the filesAnalyzed flag to false to avoid + // cases where a package digest was generated but there was + // not enough metadata to generate a verification code regarding the files + filesAnalyzed = false + } results = append(results, &spdx.Package{ // NOT PART OF SPEC @@ -193,7 +213,7 @@ func toPackages(catalog *pkg.Catalog) (results []*spdx.Package) { // 7.9: Package Verification Code // Cardinality: optional, one if filesAnalyzed is true / omitted; // zero (must be omitted) if filesAnalyzed is false - PackageVerificationCode: nil, + PackageVerificationCode: packageVerificationCode, // 7.10: Package Checksum: may have keys for SHA1, SHA256 and/or MD5 // Cardinality: optional, one or many @@ -203,7 +223,7 @@ func toPackages(catalog *pkg.Catalog) (results []*spdx.Package) { // to determine if any file in the original package has been changed. If the SPDX file is to be included // in a package, this value should not be calculated. The SHA-1 algorithm will be used to provide the // checksum by default. - PackageChecksums: checksums, + PackageChecksums: packageChecksums, // 7.11: Package Home Page // Cardinality: optional, one @@ -275,17 +295,6 @@ func toPackages(catalog *pkg.Catalog) (results []*spdx.Package) { return results } -func toPackageOriginator(p pkg.Package) *common.Originator { - kind, originator := Originator(p) - if kind == "" || originator == "" { - return nil - } - return &common.Originator{ - Originator: originator, - OriginatorType: kind, - } -} - func toPackageChecksums(p pkg.Package) ([]common.Checksum, bool) { filesAnalyzed := false var checksums []common.Checksum @@ -293,6 +302,7 @@ func toPackageChecksums(p pkg.Package) ([]common.Checksum, bool) { // we generate digest for some Java packages // spdx.github.io/spdx-spec/package-information/#710-package-checksum-field case pkg.JavaMetadata: + // if syft has generated the digest here then filesAnalyzed is true if len(meta.ArchiveDigests) > 0 { filesAnalyzed = true for _, digest := range meta.ArchiveDigests { @@ -304,6 +314,7 @@ func toPackageChecksums(p pkg.Package) ([]common.Checksum, bool) { } } case pkg.GolangBinMetadata: + // because the H1 digest is found in the Golang metadata we cannot claim that the files were analyzed algo, hexStr, err := util.HDigestToSHA(meta.H1Digest) if err != nil { log.Debugf("invalid h1digest: %s: %v", meta.H1Digest, err) @@ -318,6 +329,17 @@ func toPackageChecksums(p pkg.Package) ([]common.Checksum, bool) { return checksums, filesAnalyzed } +func toPackageOriginator(p pkg.Package) *common.Originator { + kind, originator := Originator(p) + if kind == "" || originator == "" { + return nil + } + return &common.Originator{ + Originator: originator, + OriginatorType: kind, + } +} + func formatSPDXExternalRefs(p pkg.Package) (refs []*spdx.PackageExternalReference) { for _, ref := range ExternalRefs(p) { refs = append(refs, &spdx.PackageExternalReference{ @@ -414,6 +436,7 @@ func toFiles(s sbom.SBOM) (results []*spdx.File) { } func toFileChecksums(digests []file.Digest) (checksums []common.Checksum) { + checksums = make([]common.Checksum, 0, len(digests)) for _, digest := range digests { checksums = append(checksums, common.Checksum{ Algorithm: toChecksumAlgorithm(digest.Algorithm), @@ -462,3 +485,55 @@ func toFileTypes(metadata *source.FileMetadata) (ty []string) { return ty } + +// TODO: handle SPDX excludes file case +// f file is an "excludes" file, skip it /* exclude SPDX analysis file(s) */ +// see: https://spdx.github.io/spdx-spec/v2.3/package-information/#79-package-verification-code-field +// the above link contains the SPDX algorithm for a package verification code +func newPackageVerificationCode(p pkg.Package, sbom sbom.SBOM) *common.PackageVerificationCode { + // key off of the contains relationship; + // spdx validator will fail if a package claims to contain a file but no sha1 provided + // if a sha1 for a file is provided then the validator will fail if the package does not have + // a package verification code + coordinates := sbom.CoordinatesForPackage(p, artifact.ContainsRelationship) + var digests []file.Digest + for _, c := range coordinates { + digest := sbom.Artifacts.FileDigests[c] + if len(digest) == 0 { + continue + } + + var d file.Digest + for _, digest := range digest { + if digest.Algorithm == "sha1" { + d = digest + break + } + } + digests = append(digests, d) + } + + if len(digests) == 0 { + return nil + } + + // sort templist in ascending order by SHA1 value + sort.SliceStable(digests, func(i, j int) bool { + return digests[i].Value < digests[j].Value + }) + + // filelist = templist with "/n"s removed. /* ordered sequence of SHA1 values with no separators + var b strings.Builder + for _, digest := range digests { + b.WriteString(digest.Value) + } + + //nolint:gosec + hasher := sha1.New() + _, _ = hasher.Write([]byte(b.String())) + return &common.PackageVerificationCode{ + // 7.9.1: Package Verification Code Value + // Cardinality: mandatory, one + Value: fmt.Sprintf("%+x", hasher.Sum(nil)), + } +} diff --git a/syft/formats/common/spdxhelpers/to_format_model_test.go b/syft/formats/common/spdxhelpers/to_format_model_test.go index a68edf003..f3f90d7c6 100644 --- a/syft/formats/common/spdxhelpers/to_format_model_test.go +++ b/syft/formats/common/spdxhelpers/to_format_model_test.go @@ -12,6 +12,7 @@ import ( "github.com/anchore/syft/syft/artifact" "github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/pkg" + "github.com/anchore/syft/syft/sbom" "github.com/anchore/syft/syft/source" ) @@ -369,6 +370,7 @@ func Test_fileIDsForPackage(t *testing.T) { } func Test_H1Digest(t *testing.T) { + sbom := sbom.SBOM{} tests := []struct { name string pkg pkg.Package @@ -415,7 +417,7 @@ func Test_H1Digest(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { catalog := pkg.NewCatalog(test.pkg) - pkgs := toPackages(catalog) + pkgs := toPackages(catalog, sbom) require.Len(t, pkgs, 1) for _, p := range pkgs { if test.expectedDigest == "" { diff --git a/syft/formats/spdxjson/test-fixtures/snapshot/TestSPDXRelationshipOrder.golden b/syft/formats/spdxjson/test-fixtures/snapshot/TestSPDXRelationshipOrder.golden index c66e4989e..451f76e9b 100644 --- a/syft/formats/spdxjson/test-fixtures/snapshot/TestSPDXRelationshipOrder.golden +++ b/syft/formats/spdxjson/test-fixtures/snapshot/TestSPDXRelationshipOrder.golden @@ -3,14 +3,14 @@ "dataLicense": "CC0-1.0", "SPDXID": "SPDXRef-DOCUMENT", "name": "user-image-input", - "documentNamespace": "https://anchore.com/syft/image/user-image-input-55ad4afc-ecdc-46a4-8bc3-36b3e72da5d1", + "documentNamespace": "https://anchore.com/syft/image/user-image-input-ace88a38-4633-4bff-8fa3-8ae929dab37d", "creationInfo": { - "licenseListVersion": "3.18", + "licenseListVersion": "3.19", "creators": [ "Organization: Anchore, Inc", "Tool: syft-v0.42.0-bogus" ], - "created": "2022-11-19T13:46:57Z", + "created": "2022-12-14T18:21:40Z", "comment": "" }, "packages": [ @@ -70,7 +70,7 @@ "fileTypes": [ "OTHER" ], - "checksums": null, + "checksums": [], "licenseConcluded": "NOASSERTION", "copyrightText": "" }, @@ -80,7 +80,7 @@ "fileTypes": [ "OTHER" ], - "checksums": null, + "checksums": [], "licenseConcluded": "NOASSERTION", "copyrightText": "" }, @@ -90,7 +90,7 @@ "fileTypes": [ "OTHER" ], - "checksums": null, + "checksums": [], "licenseConcluded": "NOASSERTION", "copyrightText": "" }, @@ -100,7 +100,7 @@ "fileTypes": [ "OTHER" ], - "checksums": null, + "checksums": [], "licenseConcluded": "NOASSERTION", "copyrightText": "" }, @@ -110,7 +110,7 @@ "fileTypes": [ "OTHER" ], - "checksums": null, + "checksums": [], "licenseConcluded": "NOASSERTION", "copyrightText": "" }, @@ -120,7 +120,7 @@ "fileTypes": [ "OTHER" ], - "checksums": null, + "checksums": [], "licenseConcluded": "NOASSERTION", "copyrightText": "" } diff --git a/syft/formats/spdxjson/test-fixtures/snapshot/stereoscope-fixture-image-simple.golden b/syft/formats/spdxjson/test-fixtures/snapshot/stereoscope-fixture-image-simple.golden index 0a4b4d256..aca661202 100644 Binary files a/syft/formats/spdxjson/test-fixtures/snapshot/stereoscope-fixture-image-simple.golden and b/syft/formats/spdxjson/test-fixtures/snapshot/stereoscope-fixture-image-simple.golden differ diff --git a/syft/sbom/sbom.go b/syft/sbom/sbom.go index f867c49f4..ac6a7335c 100644 --- a/syft/sbom/sbom.go +++ b/syft/sbom/sbom.go @@ -3,6 +3,8 @@ package sbom import ( "sort" + "golang.org/x/exp/slices" + "github.com/anchore/syft/syft/artifact" "github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/linux" @@ -65,6 +67,36 @@ func (s SBOM) AllCoordinates() []source.Coordinates { return set.ToSlice() } +// RelationshipsForPackage returns all relationships for the provided types. +// If no types are provided, all relationships for the package are returned. +func (s SBOM) RelationshipsForPackage(p pkg.Package, rt ...artifact.RelationshipType) []artifact.Relationship { + if len(rt) == 0 { + rt = artifact.AllRelationshipTypes() + } + + var relationships []artifact.Relationship + for _, relationship := range s.Relationships { + // check if the relationship is one we're searching for; rt is inclusive + idx := slices.IndexFunc(rt, func(r artifact.RelationshipType) bool { return relationship.Type == r }) + if relationship.From.ID() == p.ID() && idx != -1 { + relationships = append(relationships, relationship) + } + } + + return relationships +} + +// CoordinatesForPackage returns all coordinates for the provided package for provided relationship types +// If no types are provided, all relationship types are considered. +func (s SBOM) CoordinatesForPackage(p pkg.Package, rt ...artifact.RelationshipType) []source.Coordinates { + var coordinates []source.Coordinates + for _, relationship := range s.RelationshipsForPackage(p, rt...) { + cords := extractCoordinates(relationship) + coordinates = append(coordinates, cords...) + } + return coordinates +} + func extractCoordinates(relationship artifact.Relationship) (results []source.Coordinates) { if coordinates, exists := relationship.From.(source.Coordinates); exists { results = append(results, coordinates) diff --git a/test/cli/cosign_test.go b/test/cli/cosign_test.go index 283d36b6e..78f8a2b75 100644 --- a/test/cli/cosign_test.go +++ b/test/cli/cosign_test.go @@ -1,8 +1,6 @@ package cli import ( - "bufio" - "io" "net/http" "os" "os/exec" @@ -15,30 +13,6 @@ import ( "github.com/stretchr/testify/require" ) -func runAndShow(t *testing.T, cmd *exec.Cmd) { - t.Helper() - - stderr, err := cmd.StderrPipe() - require.NoErrorf(t, err, "could not get stderr: +v", err) - - stdout, err := cmd.StdoutPipe() - require.NoErrorf(t, err, "could not get stdout: +v", err) - - err = cmd.Start() - require.NoErrorf(t, err, "failed to start cmd: %+v", err) - - show := func(label string, reader io.ReadCloser) { - scanner := bufio.NewScanner(reader) - scanner.Split(bufio.ScanLines) - for scanner.Scan() { - t.Logf("%s: %s", label, scanner.Text()) - } - } - - show("out", stdout) - show("err", stderr) -} - func TestCosignWorkflow(t *testing.T) { // found under test-fixtures/registry/Makefile img := "localhost:5000/attest:latest" @@ -113,7 +87,6 @@ func TestCosignWorkflow(t *testing.T) { cmd = exec.Command("make", "push") cmd.Dir = fixturesPath runAndShow(t, cmd) - }, cleanup: func() { cwd, err := os.Getwd() diff --git a/test/cli/spdx_json_schema_test.go b/test/cli/spdx_json_schema_test.go index 25c7d18c8..821781434 100644 --- a/test/cli/spdx_json_schema_test.go +++ b/test/cli/spdx_json_schema_test.go @@ -15,7 +15,6 @@ import ( const spdxJsonSchemaPath = "schema/spdx-json" func TestSPDXJSONSchema(t *testing.T) { - imageFixture := func(t *testing.T) string { fixtureImageName := "image-pkg-coverage" imagetest.GetFixtureImage(t, "docker-archive", fixtureImageName) @@ -35,11 +34,6 @@ func TestSPDXJSONSchema(t *testing.T) { args: []string{"-o", "spdx-json"}, fixture: imageFixture, }, - { - name: "power-user:image:docker-archive:pkg-coverage", - subcommand: "power-user", - fixture: imageFixture, - }, { name: "packages:dir:pkg-coverage", subcommand: "packages", diff --git a/test/cli/spdx_tooling_validation_test.go b/test/cli/spdx_tooling_validation_test.go new file mode 100644 index 000000000..00c9afedd --- /dev/null +++ b/test/cli/spdx_tooling_validation_test.go @@ -0,0 +1,83 @@ +package cli + +import ( + "fmt" + "os" + "os/exec" + "path" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestSpdxValidationTooling(t *testing.T) { + tests := []struct { + name string + syftArgs []string + images []string + setup func(t *testing.T) + env map[string]string + assertions []traitAssertion + }{ + { + name: "spdx validation tooling tag value", + syftArgs: []string{"packages", "-o", "spdx"}, + images: []string{"alpine:latest", "photon:3.0", "debian:latest"}, + env: map[string]string{ + "SYFT_FILE_METADATA_CATALOGER_ENABLED": "true", + "SYFT_FILE_METADATA_DIGESTS": "sha1", + }, + setup: func(t *testing.T) { + cwd, err := os.Getwd() + require.NoError(t, err) + fixturesPath := filepath.Join(cwd, "test-fixtures", "image-java-spdx-tools") + buildCmd := exec.Command("make", "build") + buildCmd.Dir = fixturesPath + err = buildCmd.Run() + require.NoError(t, err) + }, + assertions: []traitAssertion{ + assertSuccessfulReturnCode, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + // build the validation image + test.setup(t) + + for _, image := range test.images { + args := append(test.syftArgs, image) + cmd, stdout, stderr := runSyft(t, test.env, args...) + for _, traitFn := range test.assertions { + traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode()) + } + + cwd, err := os.Getwd() + require.NoError(t, err) + + f, err := os.CreateTemp(t.TempDir(), "temp") + require.NoError(t, err) + + // spdx tooling only takes a file with suffix spdx + rename := path.Join(path.Dir(f.Name()), fmt.Sprintf("%s.spdx", path.Base(f.Name()))) + err = os.Rename(f.Name(), rename) + require.NoError(t, err) + + // write file for validation + _, err = f.Write([]byte(stdout)) + require.NoError(t, err) + + // validate against spdx java tooling + fileArg := fmt.Sprintf("FILE=%s", rename) + mountArg := fmt.Sprintf("BASE=%s", path.Base(rename)) + + validateCmd := exec.Command("make", "validate", fileArg, mountArg) + validateCmd.Dir = filepath.Join(cwd, "test-fixtures", "image-java-spdx-tools") + runAndShow(t, validateCmd) + } + }) + } +} diff --git a/test/cli/test-fixtures/image-java-spdx-tools/Dockerfile b/test/cli/test-fixtures/image-java-spdx-tools/Dockerfile new file mode 100644 index 000000000..a0cc883f0 --- /dev/null +++ b/test/cli/test-fixtures/image-java-spdx-tools/Dockerfile @@ -0,0 +1,7 @@ +FROM cgr.dev/chainguard/jdk + +RUN wget https://github.com/spdx/tools-java/releases/download/v1.1.3/tools-java-1.1.3.zip && \ + unzip tools-java-1.1.3.zip && \ + rm tools-java-1.1.3.zip + +ENTRYPOINT ["java", "-jar", "tools-java-1.1.3-jar-with-dependencies.jar"] diff --git a/test/cli/test-fixtures/image-java-spdx-tools/Makefile b/test/cli/test-fixtures/image-java-spdx-tools/Makefile new file mode 100644 index 000000000..db77a010e --- /dev/null +++ b/test/cli/test-fixtures/image-java-spdx-tools/Makefile @@ -0,0 +1,8 @@ +all: build validate + +.PHONY: build +build: + docker build -t spdx-java-tools:latest . + +validate: + docker run --rm -v ${FILE}:/home/build/${BASE} spdx-java-tools:latest Verify ${BASE} diff --git a/test/cli/utils_test.go b/test/cli/utils_test.go index 5751dea66..0ee1ac121 100644 --- a/test/cli/utils_test.go +++ b/test/cli/utils_test.go @@ -1,8 +1,10 @@ package cli import ( + "bufio" "bytes" "fmt" + "io" "math" "os" "os/exec" @@ -14,9 +16,35 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/anchore/stereoscope/pkg/imagetest" ) +func runAndShow(t *testing.T, cmd *exec.Cmd) { + t.Helper() + + stderr, err := cmd.StderrPipe() + require.NoErrorf(t, err, "could not get stderr: +v", err) + + stdout, err := cmd.StdoutPipe() + require.NoErrorf(t, err, "could not get stdout: +v", err) + + err = cmd.Start() + require.NoErrorf(t, err, "failed to start cmd: %+v", err) + + show := func(label string, reader io.ReadCloser) { + scanner := bufio.NewScanner(reader) + scanner.Split(bufio.ScanLines) + for scanner.Scan() { + t.Logf("%s: %s", label, scanner.Text()) + } + } + + show("out", stdout) + show("err", stderr) +} + func setupPKI(t *testing.T, pw string) func() { err := os.Setenv("COSIGN_PASSWORD", pw) if err != nil {