Skip to content

Commit ea8e575

Browse files
committed
fix format
1 parent 16a41bb commit ea8e575

File tree

15 files changed

+51
-60
lines changed

15 files changed

+51
-60
lines changed

cve/src/api/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::impact::ImpactMetrics;
22
use crate::v4::configurations::Node;
3-
use crate::v4::{Description, Weaknesses, Reference};
3+
use crate::v4::{Description, Reference, Weaknesses};
44
use chrono::NaiveDateTime;
55
use serde::{Deserialize, Serialize};
66

77
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
8-
#[serde(rename_all(deserialize = "camelCase"))]
8+
#[serde(rename_all = "camelCase")]
99
pub struct CVE {
1010
pub id: String,
1111
pub source_identifier: String,

cve/src/impact.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88
/// Must contain: At least one entry, can be text, CVSSv2, CVSSv3, others may be added
99
///
1010
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
11-
#[serde(rename_all(deserialize = "camelCase"), deny_unknown_fields)]
11+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
1212
pub struct ImpactMetrics {
1313
// TODO: Implement V1?
1414
// cvssV2 过期
@@ -20,6 +20,17 @@ pub struct ImpactMetrics {
2020
// TODO: Implement V4?
2121
}
2222

23+
impl ImpactMetrics {
24+
pub fn severity(&self) -> String {
25+
if let Some(m) = self.base_metric_v3.inner() {
26+
return m.cvss_v3.base_severity.to_string();
27+
}
28+
if let Some(m) = self.base_metric_v2.inner() {
29+
return m.severity.to_string();
30+
}
31+
String::from("None")
32+
}
33+
}
2334
// 为了兼容API接口返回的数据和json归档数据结构
2435
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2536
#[serde(untagged)]

cvss/src/v2/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::version::Version;
3939
use serde::{Deserialize, Serialize};
4040

4141
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
42-
#[serde(rename_all(deserialize = "camelCase"))]
42+
#[serde(rename_all = "camelCase")]
4343
pub struct CVSS {
4444
// 版本
4545
pub version: Version,
@@ -164,7 +164,7 @@ impl CVSS {
164164
/// The CVSSv2 <https://www.first.org/cvss/v2/guide> scoring data, split up into Base Metrics Group (BM), Temporal Metrics Group (TM) and Environmental Metrics Group (EM).
165165
///
166166
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
167-
#[serde(rename_all(deserialize = "camelCase"), deny_unknown_fields)]
167+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
168168
pub struct ImpactMetricV2 {
169169
#[serde(default)]
170170
pub source: Option<String>,

cvss/src/v3/impact_metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl AvailabilityImpactType {
291291
///
292292
/// If a scope change has not occurred, the Impact metrics should reflect the confidentiality, integrity, and availability (CIA) impact to the vulnerable component. However, if a scope change has occurred, then the Impact metrics should reflect the CIA impact to either the vulnerable component, or the impacted component, whichever suffers the most severe outcome.
293293
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
294-
#[serde(rename_all(deserialize = "camelCase"))]
294+
#[serde(rename_all = "camelCase")]
295295
pub struct Impact {
296296
/// [`ConfidentialityImpactType`] 机密性影响(C)
297297
pub confidentiality_impact: ConfidentialityImpactType,

cvss/src/v3/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub mod user_interaction;
4242
/// As mentioned, the Exploitability metrics reflect the characteristics of the thing that is vulnerable, which we refer to formally as the vulnerable component. Therefore, each of the Exploitability metrics listed below should be scored relative to the vulnerable component, and reflect the properties of the vulnerability that lead to a successful attack.
4343
///
4444
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
45-
#[serde(rename_all(deserialize = "camelCase"))]
45+
#[serde(rename_all = "camelCase")]
4646
pub struct ExploitAbility {
4747
/// [`AttackVectorType`] 访问途径(AV)
4848
pub attack_vector: AttackVectorType,
@@ -75,7 +75,7 @@ impl ExploitAbility {
7575
/// The benefits of CVSS include the provision of a standardized vendor and platform agnostic vulnerability scoring methodology. It is an open framework, providing transparency to the individual characteristics and methodology used to derive a score.
7676
///
7777
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
78-
#[serde(rename_all(deserialize = "camelCase"))]
78+
#[serde(rename_all = "camelCase")]
7979
pub struct CVSS {
8080
/// Version 版本: 3.0 和 3.1
8181
pub version: Version,
@@ -273,7 +273,7 @@ impl CVSSBuilder {
273273
///
274274
/// The CVSSv3 <https://www.first.org/cvss/specification-document> scoring data.
275275
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
276-
#[serde(rename_all(deserialize = "camelCase"), deny_unknown_fields)]
276+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
277277
pub struct ImpactMetricV3 {
278278
#[serde(default)]
279279
pub source: Option<String>,

cvss/src/v4/environmental.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt::{Display, Formatter};
55
use std::str::FromStr;
66

77
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
8-
#[serde(rename_all(deserialize = "camelCase"))]
8+
#[serde(rename_all = "camelCase")]
99
pub struct Environmental {
1010
/// [`ConfidentialityImpactType`] 机密性影响(C)
1111
pub confidentiality_requirements: ConfidentialityRequirements,

cvss/src/v4/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mod vulnerable_impact_metrics;
5050
/// As mentioned, the Exploitability metrics reflect the characteristics of the thing that is vulnerable, which we refer to formally as the vulnerable component. Therefore, each of the Exploitability metrics listed below should be scored relative to the vulnerable component, and reflect the properties of the vulnerability that lead to a successful attack.
5151
///
5252
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
53-
#[serde(rename_all(deserialize = "camelCase"))]
53+
#[serde(rename_all = "camelCase")]
5454
pub struct ExploitAbility {
5555
/// [`AttackVectorType`] 访问途径(AV)
5656
pub attack_vector: AttackVectorType,
@@ -124,7 +124,7 @@ impl ExploitAbility {
124124
/// The benefits of CVSS include the provision of a standardized vendor and platform agnostic vulnerability scoring methodology. It is an open framework, providing transparency to the individual characteristics and methodology used to derive a score.
125125
///
126126
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
127-
#[serde(rename_all(deserialize = "camelCase"))]
127+
#[serde(rename_all = "camelCase")]
128128
pub struct CVSS {
129129
/// Version 版本: 4.0
130130
pub version: Version,

cvss/src/v4/subsequent_impact_metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl SubsequentAvailabilityImpactType {
326326
}
327327
}
328328
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
329-
#[serde(rename_all(deserialize = "camelCase"))]
329+
#[serde(rename_all = "camelCase")]
330330
pub struct SubsequentImpact {
331331
/// [`ConfidentialityImpactType`] 机密性影响(C)
332332
pub confidentiality_impact: SubsequentConfidentialityImpactType,

cvss/src/v4/vulnerable_impact_metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl VulnerableAvailabilityImpactType {
306306
///
307307
/// If a scope change has not occurred, the Impact metrics should reflect the confidentiality, integrity, and availability (CIA) impact to the vulnerable component. However, if a scope change has occurred, then the Impact metrics should reflect the CIA impact to either the vulnerable component, or the impacted component, whichever suffers the most severe outcome.
308308
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
309-
#[serde(rename_all(deserialize = "camelCase"))]
309+
#[serde(rename_all = "camelCase")]
310310
pub struct VulnerableImpact {
311311
/// [`ConfidentialityImpactType`] 机密性影响(C)
312312
pub confidentiality_impact: VulnerableConfidentialityImpactType,

helper/src/bin/cve_to_db.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use cached::proc_macro::cached;
22
use cached::SizedCache;
3-
use cve::impact::OneOrMany;
43
use cve::v4::{CVEContainer, CVEItem};
5-
use cvss::v2::ImpactMetricV2;
6-
use cvss::v3::ImpactMetricV3;
74
use diesel::mysql::MysqlConnection;
85
use helper::init_db_pool;
96
use nvd_server::error::DBResult;
@@ -19,27 +16,6 @@ use std::str::FromStr;
1916

2017
// https://cwe.mitre.org/data/downloads.html
2118
// curl -s -k https://cwe.mitre.org/data/downloads.html |grep -Eo '(/[^"]*\.xml.zip)'|xargs -I % wget -c https://cwe.mitre.org%
22-
fn v3(v3: &OneOrMany<ImpactMetricV3>) -> (String, f32) {
23-
match v3 {
24-
OneOrMany::None => (String::new(), 0.0),
25-
OneOrMany::One(v) => (v.cvss_v3.vector_string.to_string(), v.cvss_v3.base_score),
26-
OneOrMany::Many(vs) => (
27-
vs.first().unwrap().cvss_v3.vector_string.to_string(),
28-
vs.first().unwrap().cvss_v3.base_score,
29-
),
30-
}
31-
}
32-
33-
fn v2(v2: &OneOrMany<ImpactMetricV2>) -> (String, f32) {
34-
match v2 {
35-
OneOrMany::None => (String::new(), 0.0),
36-
OneOrMany::One(v) => (v.cvss_v2.vector_string.to_string(), v.cvss_v2.base_score),
37-
OneOrMany::Many(vs) => (
38-
vs.first().unwrap().cvss_v2.vector_string.to_string(),
39-
vs.first().unwrap().cvss_v2.base_score,
40-
),
41-
}
42-
}
4319

4420
fn import_to_db(connection: &mut MysqlConnection, cve_item: CVEItem) -> DBResult<String> {
4521
let id = cve_item.cve.meta.id;
@@ -48,16 +24,15 @@ fn import_to_db(connection: &mut MysqlConnection, cve_item: CVEItem) -> DBResult
4824
id: id.clone(),
4925
created_at: cve_item.published_date,
5026
updated_at: cve_item.last_modified_date,
51-
references: serde_json::json!(cve_item.cve.references),
52-
description: serde_json::json!(cve_item.cve.description),
53-
problem_type: serde_json::json!(cve_item.cve.problem_type),
54-
cvss3_vector: v3(&cve_item.impact.base_metric_v3).0,
55-
cvss3_score: v3(&cve_item.impact.base_metric_v3).1,
56-
cvss2_vector: v2(&cve_item.impact.base_metric_v2).0,
57-
cvss2_score: v2(&cve_item.impact.base_metric_v2).1,
27+
references: serde_json::json!(cve_item.cve.references.reference_data),
28+
description: serde_json::json!(cve_item.cve.description.description_data),
29+
severity: cve_item.impact.severity().to_string(),
30+
metrics: serde_json::json!(cve_item.impact),
5831
assigner: cve_item.cve.meta.assigner,
59-
configurations: serde_json::json!(cve_item.configurations),
32+
configurations: serde_json::json!(cve_item.configurations.nodes),
6033
year: i32::from_str(y).unwrap_or_default(),
34+
weaknesses: serde_json::json!(cve_item.cve.problem_type.problem_type_data),
35+
timeline: Default::default(),
6136
};
6237
// 插入到数据库
6338
match Cve::create(connection, &new_post) {
@@ -179,7 +154,7 @@ pub fn create_product(
179154

180155
fn main() {
181156
let connection_pool = init_db_pool();
182-
for y in 2004..2024 {
157+
for y in 2023..2024 {
183158
let p = format!("helper/examples/nvdcve/nvdcve-1.1-{y}.json.gz");
184159
println!("{p}");
185160
let gz_open_file = File::open(p).unwrap();
@@ -189,5 +164,6 @@ fn main() {
189164
for w in c.CVE_Items {
190165
import_to_db(connection_pool.get().unwrap().deref_mut(), w).unwrap_or_default();
191166
}
167+
break;
192168
}
193169
}

nvd-api/src/pagination.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::v2::vulnerabilities::{CveChanges, Vulnerabilities};
44
use chrono::NaiveDateTime;
55
use serde::{Deserialize, Serialize};
66
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
7-
#[serde(rename_all(deserialize = "camelCase"))]
7+
#[serde(rename_all = "camelCase")]
88
pub struct ListResponse {
99
#[serde(flatten)]
1010
pub results: Object,

nvd-server/nvd-er.mwb

15 Bytes
Binary file not shown.

nvd-server/src/modules/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub struct Cve {
2626
pub year: i32,
2727
pub assigner: String,
2828
pub description: Value,
29-
pub severity:String,
30-
pub metrics:Value,
29+
pub severity: String,
30+
pub metrics: Value,
3131
pub weaknesses: Value,
3232
pub configurations: Value,
3333
pub references: Value,

nvd-yew/src/component/cvss_tags.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use cvss::severity::{SeverityType, SeverityTypeV2};
44
use yew::prelude::*;
55

66
pub fn cvss2(metric: Option<&cvss::v2::ImpactMetricV2>) -> Html {
7-
let mut score = 0.0;
7+
let mut score = String::from("N/A");
88
let severity_class = match metric {
9-
None => "bg-secondary",
9+
None => "bg-secondary",
1010
Some(m) => {
11-
score = m.cvss_v2.base_score;
11+
score = format!("{} {}", m.cvss_v2.base_score, m.severity.to_string());
1212
match m.severity {
1313
SeverityTypeV2::None => "bg-secondary",
1414
SeverityTypeV2::Low => "bg-info",
@@ -20,11 +20,15 @@ pub fn cvss2(metric: Option<&cvss::v2::ImpactMetricV2>) -> Html {
2020
html!(<span class={classes!(["badge",severity_class])}><b style="font-size:larger">{score}</b></span>)
2121
}
2222
pub fn cvss3(metric: Option<&cvss::v3::ImpactMetricV3>) -> Html {
23-
let mut score = 0.0;
23+
let mut score = String::from("N/A");
2424
let severity_class = match metric {
25-
None => "bg-secondary",
25+
None => "bg-secondary",
2626
Some(m) => {
27-
score = m.cvss_v3.base_score;
27+
score = format!(
28+
"{} {}",
29+
m.cvss_v3.base_score,
30+
m.cvss_v3.base_severity.to_string()
31+
);
2832
match m.cvss_v3.base_severity {
2933
SeverityType::None => "bg-secondary",
3034
SeverityType::Low => "bg-info",

nvd-yew/src/routes/cve.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,24 @@ impl CVEDetails {
115115
<>
116116
<div class="card-tabs p-1">
117117
<ul class="nav nav-tabs p-1" role="tablist">
118-
if let Some(v3) = cvss_v3.clone(){
118+
if let Some(v3) = cvss_v3{
119119
<li class="nav-item">
120120
<a href="#tabs-cvss3" class="nav-link" data-bs-toggle="tab" aria-selected="true" role="tab">{format!("CVSS v{}",v3.cvss_v3.version.to_string())} {cvss3(cvss_v3)}</a>
121121
</li>
122122
}
123-
if let Some(v2) = cvss_v2.clone(){
123+
if let Some(v2) = cvss_v2{
124124
<li class="nav-item">
125125
<a href="#tabs-cvss2" class="nav-link" data-bs-toggle="tab">{format!("CVSS v{}",v2.cvss_v2.version.to_string())} {cvss2(cvss_v2)}</a>
126126
</li>
127127
}
128128
</ul>
129129
<div class="tab-content">
130-
if let Some(v3) = cvss_v3.clone(){
130+
if let Some(v3) = cvss_v3{
131131
<div class="tab-pane show active" id="tabs-cvss3">
132132
<CVSS3 v3={Some(v3.clone())}/>
133133
</div>
134134
}
135-
if let Some(v2) = cvss_v2.clone(){
135+
if let Some(v2) = cvss_v2{
136136
<div class="tab-pane show" id="tabs-cvss2">
137137
<CVSS2 v2={Some(v2.clone())}/>
138138
</div>

0 commit comments

Comments
 (0)