nvd_api/v2/vulnerabilities.rs
1use chrono::NaiveDateTime;
2use derive_builder::Builder;
3use serde::{Deserialize, Serialize};
4
5/// <https://nvd.nist.gov/developers/vulnerabilities>
6/// This documentation assumes that you already understand at least one common programming language and are generally familiar with JSON RESTful services. JSON specifies the format of the data returned by the REST service. REST refers to a style of services that allow computers to communicate via HTTP over the Internet. Click here for a list of best practices and additional information on where to start. The NVD is also documenting popular workflows to assist developers working with the APIs.
7///
8/// Please note, new users are discouraged from starting with the 1.0 API as it will be retired in 2023 but you may still view documentation for the 1.0 Vulnerability and 1.0 Product APIs.
9///
10use crate::v2::{Keyword, LastModDate, LimitOffset};
11
12/// The CVE API is used to easily retrieve information on a single CVE or a collection of CVE from the NVD. The NVD contains 232,639 CVE records. Because of this, its APIs enforce offset-based pagination to answer requests for large collections. Through a series of smaller “chunked” responses controlled by an offset startIndex and a page limit resultsPerPage users may page through all the CVE in the NVD.
13///
14/// The URL stem for retrieving CVE information is shown below.
15///
16#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Eq, Builder)]
17#[serde(rename_all = "camelCase")]
18#[builder(setter(into))]
19pub struct CveParameters {
20 /// This parameter returns all CVE associated with a specific CPE. The exact value provided with cpeName is compared against the CPE Match Criteria within a CVE applicability statement. If the value of cpeName is considered to match, the CVE is included in the results.
21 pub cpe_name: Option<String>,
22 /// This parameter returns a specific vulnerability identified by its unique Common Vulnerabilities and Exposures identifier (the CVE ID). cveId will not accept {CVE-ID} for vulnerabilities not yet published in the NVD.
23 pub cve_id: Option<String>,
24 /// This parameter returns only the CVEs that match the provided {CVSSv2 vector string}. Either full or partial vector strings may be used. This parameter cannot be used in requests that include cvssV3Metrics.
25 pub cvss_v2_metrics: Option<String>,
26 /// This parameter returns only the CVEs that match the provided CVSSv2 qualitative severity rating. This parameter cannot be used in requests that include cvssV3Severity.
27 pub cvss_v2_severity: Option<nvd_cvss::severity::SeverityTypeV2>,
28 /// This parameter returns only the CVEs that match the provided {CVSSv3 vector string}. Either full or partial vector strings may be used. This parameter cannot be used in requests that include cvssV2Metrics.
29 pub cvss_v3_metrics: Option<String>,
30 /// This parameter returns only the CVEs that match the provided CVSSv3 qualitative severity rating. This parameter cannot be used in requests that include cvssV2Severity.
31 /// Note: The NVD will not contain CVSS v3 vector strings with a severity of NONE. This is why that severity is not an included option.
32 pub cvss_v3_severity: Option<nvd_cvss::severity::SeverityType>,
33 /// This parameter returns only the CVE that include a weakness identified by Common Weakness Enumeration using the provided {CWE-ID}.
34 /// Note: The NVD also makes use of two placeholder CWE-ID values NVD-CWE-Other and NVD-CWE-noinfo which can also be used.
35 pub cwe_id: Option<String>,
36 /// This parameter returns the CVE that contain a Technical Alert from US-CERT. Please note, this parameter is provided without a parameter value.
37 pub has_cert_alerts: Option<bool>,
38 /// This parameter returns the CVE that contain a Vulnerability Note from CERT/CC. Please note, this parameter is provided without a parameter value.
39 pub has_cert_notes: Option<bool>,
40 /// This parameter returns the CVE that appear in CISA's Known Exploited Vulnerabilities (KEV) Catalog. Please note, this parameter is provided without a parameter value.
41 pub has_kev: Option<bool>,
42 /// This parameter returns the CVE that contain information from MITRE's Open Vulnerability and Assessment Language (OVAL) before this transitioned to the Center for Internet Security (CIS). Please note, this parameter is provided without a parameter value.
43 pub has_oval: Option<bool>,
44 /// This parameter returns only CVE associated with a specific CPE, where the CPE is also considered vulnerable. The exact value provided with cpeName is compared against the CPE Match Criteria within a CVE applicability statement. If the value of cpeName is considered to match, and is also considered vulnerable the CVE is included in the results.
45 pub is_vulnerable: Option<bool>,
46 /// keyword [Keyword]
47 #[serde(flatten)]
48 pub keyword: Option<Keyword>,
49 /// last_mod [LastModDate]
50 #[serde(flatten)]
51 pub last_mod: Option<LastModDate>,
52 /// By default, the CVE API includes CVE records with the REJECT or Rejected status. This parameter excludes CVE records with the REJECT or Rejected status from API response. Please note, this parameter is provided without a parameter value.
53 pub no_rejected: Option<bool>,
54 /// pub_date [PubDate]
55 #[serde(flatten)]
56 pub pub_date: Option<PubDate>,
57 /// limit_offset [LimitOffset]
58 #[serde(flatten)]
59 pub limit_offset: Option<LimitOffset>,
60 /// This parameter returns CVE where the exact value of {sourceIdentifier} appears as a data source in the CVE record. The CVE API returns {sourceIdentifier} values within the descriptions object. The Source API returns detailed information on the organizations that provide the data contained in the NVD dataset, including every valid {sourceIdentifier} value.
61 pub source_identifier: Option<String>,
62 /// virtual_match [VirtualMatch]
63 #[serde(flatten)]
64 pub virtual_match: Option<VirtualMatch>,
65}
66
67#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Eq)]
68#[serde(rename_all = "camelCase")]
69pub struct VirtualMatch {
70 /// This parameter filters CVE more broadly than cpeName. The exact value of {cpe match string} is compared against the CPE Match Criteria present on CVE applicability statements.
71 pub virtual_match_string: String,
72 #[serde(flatten)]
73 pub version_start: Option<VersionStart>,
74 #[serde(flatten)]
75 pub version_end: Option<VersionEnd>,
76}
77
78/// The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.
79#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
80#[serde(rename_all = "camelCase")]
81pub struct VersionStart {
82 pub version_start: String,
83 pub version_start_type: String,
84}
85
86/// The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.
87#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
88#[serde(rename_all = "camelCase")]
89pub struct VersionEnd {
90 pub version_end: String,
91 pub version_end_type: String,
92}
93
94#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
95#[serde(rename_all = "camelCase")]
96pub enum VersionType {
97 Including,
98 Excluding,
99}
100
101/// If filtering by the published date, both pubStartDate and pubEndDate are required. The maximum allowable range when using any date range parameters is 120 consecutive days.
102/// Values must be entered in the extended ISO-8601 date/time format:
103#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
104#[serde(rename_all = "camelCase")]
105pub struct PubDate {
106 pub pub_start_date: String,
107 pub pub_end_date: String,
108}
109
110#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
111pub struct Vulnerabilities {
112 pub cve: nvd_cves::api::CVE,
113}
114
115#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq, Builder)]
116#[serde(rename_all = "camelCase")]
117#[builder(setter(into))]
118pub struct CveHistoryParameters {
119 pub cve_id: Option<String>,
120 #[serde(flatten)]
121 pub change_date: Option<ChangeDate>,
122 pub event_name: Option<EventName>,
123 #[serde(flatten)]
124 pub limit_offset: Option<LimitOffset>,
125}
126
127#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
128#[serde(rename_all = "camelCase")]
129pub struct ChangeDate {
130 pub change_start_date: String,
131 pub change_end_date: String,
132}
133
134#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
135pub enum EventName {
136 #[serde(rename = "CVE Received")]
137 CVEReceived,
138 #[serde(rename = "Initial Analysis")]
139 InitialAnalysis,
140 Reanalysis,
141 #[serde(rename = "CVE Modified")]
142 CVEModified,
143 #[serde(rename = "Modified Analysis")]
144 ModifiedAnalysis,
145 #[serde(rename = "CVE Translated")]
146 CVETranslated,
147 #[serde(rename = "Vendor Comment")]
148 VendorComment,
149 #[serde(rename = "CVE Source Update")]
150 CVESourceUpdate,
151 #[serde(rename = "CPE Deprecation Remap")]
152 CPEDeprecationRemap,
153 #[serde(rename = "CWE Remap")]
154 CWERemap,
155 #[serde(rename = "CVE Rejected")]
156 CVERejected,
157 #[serde(rename = "CVE Unrejected")]
158 CVEUnRejected,
159}
160
161#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
162#[serde(rename_all = "camelCase")]
163pub struct CveChanges {
164 pub change: Change,
165}
166
167#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
168#[serde(rename_all = "camelCase")]
169pub struct Change {
170 pub cve_id: String,
171 pub event_name: EventName,
172 pub cve_change_id: String,
173 pub source_identifier: String,
174 pub created: NaiveDateTime,
175 pub details: Vec<Details>,
176}
177
178#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
179#[serde(rename_all = "camelCase")]
180pub struct Details {
181 pub action: Action,
182 pub r#type: String,
183 pub old_value: Option<String>,
184 pub new_value: Option<String>,
185}
186
187#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
188pub enum Action {
189 Added,
190 Removed,
191 Changed,
192}