API

November 29, 2023 ยท View on GitHub

Additional API documentation regarding quick-start, development, endpoints, and the database.

Index

System Requirements

  • Java 17
  • Gradle
  • Docker (run docker ps to determine installation status)

SVIP API

The SBOM-in-a-Box back-end API. See Endpoints for detailed endpoint documentation.

Deployment

First ensure Docker is installed and running and then deploy using the docker-compose script.

# Ensure Docker is installed and running
$ docker ps
# Start API & MySQL containers. Use --build to force rebuild the image with any updated source code
$ docker compose up

Development

To modify and test this project, you will need to run the MySQL server in a Docker container and the API detached as either a compiled JAR file or with your IDE of choice.

# Build detached API jar (skip if running in IDE)
$ ./gradlew build
# Build and deploy MySQL server ONLY to allow running API outside of its container. Use -d to run detached.
$ docker compose up mysql
# Rename jar file
$ move api/build/libs/api-1.0.0-alpha.jar SVIP_API.jar
# Run detached jar file or in IDE
$ java -jar SVIP_API.jar

Tips

  • Append -x test to the Gradle build command in the Dockerfile to skip Gradle tests. This makes it much faster as skipping the tests saves 1-2 minutes per build.
  • To edit the MySQL configuration/Docker port mappings, edit the .env file in the repository root.

Endpoints

The API is located on http://localhost:8080/svip.

Upload SBOMs

Upload an SBOM file to the Database

Endpoint: http://localhost:8080/svip/sboms

Request Method: POST

Request Body

BodyTypeDescriptionIs Required?
fileNameStringThe name of the SBOM fileYES
contentsStringThe contents of the SBOM fileYES

Responses

Response CodeTypeDescription
200LongThe ID corresponding to the uploaded file
400StringInvalid field(s) / Unable to process SBOM. Body contains error message

Example

curl -X POST -d '{"fileName":"mySBOM","contents":"SBOM Data"}' http://localhost:8080/svip/sboms

Get SBOM File

Get the contents of an SBOM object from the Database

Endpoint: http://localhost:8080/svip/sboms/content

Request Method: GET

Parameters

ParameterTypeDescriptionIs Required?
idLongThe ID of the SBOM file to retrieveYES

Responses

Response CodeTypeDescription
200SBOMFileJSON File containing SBOM name and contents
404StringSBOM with given ID does not exist

Example

curl -X GET -G http://localhost:8080/svip/sboms/content -d 'id=1'

Get all SBOMs IDs

Get all SBOM ids stored in the database

Endpoint: http://localhost:8080/svip/sboms

Request Method: GET

Responses

Response CodeTypeDescription
200Long[]Array of SBOM IDs
204---No data in the database

Example

curl -X GET http://localhost:8080/svip/sboms

Get SBOM Object

Get a single deserialized SBOM object from the database using its ID

Endpoint: http://localhost:8080/svip/sbom

Request Method: GET

Parameters

ParameterTypeDescriptionIs Required?
idLongThe ID of the SBOM file to retrieveYES

Responses

Response CodeTypeDescription
200SBOMA JSON of the SBOM Object
404StringSBOM with given ID does not exist
500StringFailed to deserialize content

Example

curl -X GET -G http://localhost:8080/svip/sbom -d 'id=1'

Delete SBOMs

Delete an SBOM file from the SQL Database using its ID

Endpoint: http://localhost:8080/svip/sboms

Request Method: DELETE

Parameters

ParameterTypeDescriptionIs Required?
idLongThe ID of the SBOM file to retrieveYES

Responses

Response CodeTypeDescription
200LongThe id of the deleted SBOM
404---SBOM with given ID does not exist

Example

curl -X DELETE -G http://localhost:8080/svip/sboms 'id=1'

Convert an SBOM

Convert an SBOM to a desired format and schema

Endpoint: http://localhost:8080/svip/sboms

Request Method: PUT

Parameters

ParameterTypeDescriptionIs Required?
idLongThe ID of the SBOM file to convertYES
schemaSerializer.SchemaSchema to convert toYES
formatSerializer.FormatFormat to convert toYES
overwriteBooleanOverwrite given fileYES

Supported Schema Params: CDX14, SPDX23, SVIP Supported Format Params: JSON, TAGVALUE

Responses

Response CodeTypeDescription
200StringConverted SBOM
204---No content found
404---SBOM with given ID does not exist
500---SBOM Failed to convert

Example

curl -X PUT -G http://localhost:8080/svip/sboms/content \
-d 'id=1' \
-d 'schema=SPDX23' \
-d 'format=TAGVALUE' \
-d 'overwrite=true'

Compare SBOMs

Compares two or more given SBOMs (split into filename and contents), with the first one used as the baseline, and returns a comparison report.

Endpoint: http://localhost:8080/svip/sboms/compare

Request Method: POST

Parameters

ParameterTypeDescriptionIs Required?
idsLong[]Array of SBOM IDsYES
targetIndexIntegerIndex of target SBOM in arrayYES

Responses

Response CodeTypeDescription
200ComparisonA Comparison report of all provided SBOMs
400StringA list of invalid fields received from the client
500StringSBOM Failed to be deserialized

Example

curl -X POST -G http://localhost:8080/svip/sboms/compare \
-d 'ids=[1,2]' \
-d 'targetIndex=0'

Merge SBOMs

Merge 2 SBOMs together, regardless of origin format

Endpoint: http://localhost:8080/svip/sboms/merge

Request Method: POST

Request Body

BodyTypeDescriptionIs Required?
idsLong[]Array of SBOM IDsYES

Responses

Response CodeTypeDescription
200LongID of the merged SBOM
400---SBOM has null properties
404---Error in merging SBOMs
500StringSBOM Failed to be deserialized

Example

curl -X POST -d '{"ids":[1,2]}' http://localhost:8080/svip/sboms/merge

Generate Quality Report

Analyze a given SBOM file and return a QualityReport

Endpoint: http://localhost:8080/svip/sboms/qa

Request Method: GET

Parameters

ParameterTypeDescriptionIs Required?
idLongThe ID of the SBOM file to run QA tests onYES

Responses

Response CodeTypeDescription
200QualityReportJSON QualityReport of the SBOM
404---SBOM with given ID does not exist
500StringSBOM Failed to be deserialized

Example

curl -X GET -G http://localhost:8080/svip/sboms/qa -d 'id=1'

Generate an SBOM using SBOM-in-a-Box Parsers

Generates an SBOM with a given schema and format from project source files using SBOM-in-a-Box parsers. Request body contains an array of multiple objects with properties fileName and contents (one for each source file)

Endpoint: http://localhost:8080/svip/generators/parsers

Request Method: POST

Parameters

ParameterTypeDescriptionIs Required?
zipFileMultipartFileZipped folder of projectYES
projectNameStringName of SBOM to generateYES
schemaSerializer SchemaSchema to convert toYES
formatSerializer FormatFormat to convert toYES

Note: Request must be sent using type multipart/form-data

Responses

Response CodeTypeDescription
200LongID from Generated SBOM from supported project
404StringDescription of error during generation
400StringSchema, format or body contents invalid

Example

curl -X POST -G http://localhost:8080/svip/generators/parsers \
-d 'projectName=Java_Project_1' \
-d 'schema=SPDX23' \
-d 'format=TAGVALUE' \
-d '[{"fileName": "testfile1.java", "contents": "..."}, {"fileName": "testfile2.java", "contents": "..."}]'

Upload a project for OSI

Upload a code project to generate SBOMs for using OSI

Endpoint: http://localhost:8080/svip/generators/osi/project

Request Method: POST

Request Body

ParameterTypeDescriptionIs Required?
projectMultipartFileZipped folder of projectYES

Responses

Response CodeTypeDescription
200String[]A list of tools relevant to the uploaded project
400StringError message, project file is bad
404StringError message, OSI is disabled
Example
curl --request POST \
  --url http://localhost:8080/svip/generators/osi/project \
  --header 'Content-Type: multipart/form-data' \
  --form 'project=path\to\project.zip'

Get List of Open-Source Tools Supported By OSI

Gets a list of all tool names currently supported by Open Source Integration that can then be passed into /generators/osi.

Endpoint: http://localhost:8080/svip/generators/osi/tools

Request Method: GET

Parameters

ParameterTypeDescriptionIs Required?
listStringEither all (default) or projectNO
  • all: Get all tools installed on OSI
  • project: Get all tools relevant to the project uploaded to OSI

Responses

Response CodeTypeDescription
200String[]A list of all tool names
404StringError message, OSI is disabled
500StringError message, failed to get tool list from OSI

Example

curl -X GET -G http://localhost:8080/svip/generators/osi/tools
curl -X GET -G http://localhost:8080/svip/generators/osi/tools?list=project

Generate an SBOM using OSI

Generates an SBOM with a given schema and format from project source files using Open Source Integration. Request body contains an array of multiple objects with properties fileName and contents (one for each source file) Use the http://localhost:8080/svip/generators/osi/project endpoint to upload a project before generation

Endpoint: http://localhost:8080/svip/generators/osi

Request Method: POST

Parameters

ParameterTypeDescriptionIs Required?
projectNameStringName of SBOM to generateYES
schemaSerializer SchemaSchema to generateYES
formatSerializer FormatFormat to generateYES
toolNamesString[]JSON-formatted string array of open-source tool names to use when generating SBOMs. If not provided, defaults to all.NO

Responses

Response CodeTypeDescription
200LongID from Generated SBOM from supported project
204No SBOMs were generated by the OSI container or able to be parsed
400StringSchema, format or body contents invalid
404StringDescription of error during generation
500StringError message

Example

curl --request POST \
  --url 'http://localhost:8080/svip/generators/osi?projectName=foo&schema=SPDX23&format=TAGVALUE'

Generate VEX

Generate a VEX document using an SBOM's components and information

Endpoint: http://localhost:8080/svip/sboms/vex

Request Method: GET

Headers

ParameterTypeDescriptionIs Required?
apiKeyStringThe user's NVD API Key to useNO

Parameters

ParameterTypeDescriptionIs Required?
idLongThe ID of the SBOM file to get information for VEXYES
formatStringThe format of the VEX DocumentYES
clientStringThe API Client to useYES

Supported format Params: [CycloneDX](https://github.com/CycloneDX/bom-examples/tree/master/VEX), CSAF

Supported Client Params: nvd, osv

Responses

Response CodeTypeDescription
200VEXResultA VEX and HashMap of any errors that occurred
400---Invalid Format or Client
404---SBOM with given ID does not exist
500---The message of the error that occurred

Example

curl -X GET -G http://localhost:8080/svip/sboms/vex \
-H 'apiKey: 0imfnc8mVLWwsAawjYr4Rx-Af50DDqtlx' \
-d 'id=1' \
-d 'format=CSAF' \
-d 'client=OSV'

MySQL Database

Located at localhost:3306 while the svip-mysql Docker container is running.

Use the following command to interact with the MySQL server instance:

$ docker exec -it svip-mysql mysql -uroot -psvipMySQL -D svip -e "<YOUR SQL STATEMENT HERE>"

Table files Schema:

FieldTypeNullKeyDefaultExtra
idbigint(20)NOPRINULL
contentslongtextYESNULL
file_nametextYESNULL