Skip to content

Commit 16a41bb

Browse files
committed
fix format
1 parent 51a5ca0 commit 16a41bb

File tree

15 files changed

+101
-135
lines changed

15 files changed

+101
-135
lines changed

cve/src/api/mod.rs

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

@@ -13,10 +13,10 @@ pub struct CVE {
1313
// 最后修改时间
1414
pub last_modified: NaiveDateTime,
1515
pub vuln_status: VulnStatus,
16-
pub descriptions: Vec<DescriptionData>,
16+
pub descriptions: Vec<Description>,
1717
pub metrics: ImpactMetrics,
1818
#[serde(default)]
19-
pub weaknesses: Vec<ProblemTypeDataItem>,
19+
pub weaknesses: Vec<Weaknesses>,
2020
#[serde(default)]
2121
pub configurations: Vec<Node>,
2222
pub references: Vec<Reference>,

cve/src/impact.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ impl<T> Default for OneOrMany<T> {
3535
}
3636
}
3737

38+
impl<T> OneOrMany<T> {
39+
pub fn inner(&self) -> Option<&T> {
40+
match self {
41+
OneOrMany::One(o) => Some(o),
42+
OneOrMany::Many(l) => l.iter().next(),
43+
OneOrMany::None => None,
44+
}
45+
}
46+
}
3847
impl<T> From<OneOrMany<T>> for Vec<T> {
3948
fn from(from: OneOrMany<T>) -> Self {
4049
match from {

cve/src/v4/configurations.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
use serde::{Deserialize, Serialize};
44
use std::collections::HashSet;
5-
65
/// A configuration is a container that holds a set of nodes which then contain CPE Name Match Criteria. Configurations consist of three different types.
76
///
87
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]

cve/src/v4/mod.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct CVE {
6464
// 参考
6565
pub references: References,
6666
// 描述
67-
pub description: Description,
67+
pub description: Descriptions,
6868
// 问题类型 关联:CWE
6969
#[serde(rename(deserialize = "problemtype"))]
7070
pub problem_type: ProblemType,
@@ -92,13 +92,13 @@ pub struct Reference {
9292

9393
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
9494
#[serde(deny_unknown_fields)]
95-
pub struct Description {
96-
pub description_data: Vec<DescriptionData>,
95+
pub struct Descriptions {
96+
pub description_data: Vec<Description>,
9797
}
9898

9999
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
100100
#[serde(deny_unknown_fields)]
101-
pub struct DescriptionData {
101+
pub struct Description {
102102
pub lang: String,
103103
pub value: String,
104104
}
@@ -122,20 +122,13 @@ pub struct Meta {
122122
#[serde(deny_unknown_fields)]
123123
pub struct ProblemType {
124124
#[serde(rename = "problemtype_data")]
125-
pub problem_type_data: Vec<ProblemTypeDataItem>,
125+
pub problem_type_data: Vec<Weaknesses>,
126126
}
127127

128128
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
129129
#[serde(deny_unknown_fields)]
130-
pub struct ProblemTypeDataItem {
130+
pub struct Weaknesses {
131131
pub source: Option<String>,
132132
pub r#type: Option<String>,
133-
pub description: Vec<ProblemTypeDescription>,
134-
}
135-
136-
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
137-
#[serde(deny_unknown_fields)]
138-
pub struct ProblemTypeDescription {
139-
pub lang: String,
140-
pub value: String,
133+
pub description: Vec<Description>,
141134
}

nvd-server/migrations/nvd-db.sql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- MySQL Script generated by MySQL Workbench
2-
-- 2023年09月17日 星期日 17时30分23秒
2+
-- 2023年12月03日 星期日 17时38分53秒
33
-- Model: New Model Version: 1.0
44
-- MySQL Workbench Forward Engineering
55

@@ -68,14 +68,13 @@ CREATE TABLE IF NOT EXISTS `nvd`.`cves` (
6868
`id` VARCHAR(32) NOT NULL COMMENT 'CVE编号',
6969
`year` INT(4) NOT NULL DEFAULT 0 COMMENT 'cve年份',
7070
`assigner` VARCHAR(64) NOT NULL COMMENT '分配者',
71-
`references` JSON NOT NULL COMMENT '参考链接',
7271
`description` JSON NOT NULL COMMENT '描述',
73-
`problem_type` JSON NOT NULL COMMENT '通用弱点枚举',
74-
`cvss3_vector` VARCHAR(64) NOT NULL COMMENT '通用漏洞评分系统',
75-
`cvss3_score` FLOAT NOT NULL DEFAULT 0.0 COMMENT 'cvss3评分',
76-
`cvss2_vector` VARCHAR(64) NOT NULL COMMENT '通用漏洞评分系统',
77-
`cvss2_score` FLOAT NOT NULL DEFAULT 0.0 COMMENT 'cvss2评分',
72+
`severity` VARCHAR(32) NOT NULL,
73+
`metrics` JSON NOT NULL,
74+
`weaknesses` JSON NOT NULL COMMENT '通用弱点枚举',
7875
`configurations` JSON NOT NULL COMMENT 'cpe匹配',
76+
`references` JSON NOT NULL COMMENT '参考链接',
77+
`timeline` JSON NOT NULL,
7978
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
8079
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
8180
PRIMARY KEY (`id`),

nvd-server/nvd-er.mwb

161 Bytes
Binary file not shown.

nvd-server/src/modules/cve_db.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ pub struct CreateCve {
1616
pub id: String,
1717
pub year: i32,
1818
pub assigner: String,
19-
pub references: Value,
2019
pub description: Value,
21-
pub problem_type: Value,
22-
pub cvss3_vector: String,
23-
pub cvss3_score: f32,
24-
pub cvss2_vector: String,
25-
pub cvss2_score: f32,
20+
pub severity: String,
21+
pub metrics: Value,
22+
pub weaknesses: Value,
2623
pub configurations: Value,
24+
pub references: Value,
25+
pub timeline: Value,
2726
pub created_at: NaiveDateTime,
2827
pub updated_at: NaiveDateTime,
2928
}
@@ -87,33 +86,7 @@ impl QueryCve {
8786
query = query.filter(cves::id.eq_any(cve_ids));
8887
}
8988
if let Some(severity) = &self.severity {
90-
match severity.to_lowercase().as_str() {
91-
"low" => {
92-
query = query.filter(
93-
cves::cvss3_score
94-
.between(0.1, 3.9)
95-
.or(cves::cvss2_score.between(0.1, 3.9)),
96-
);
97-
}
98-
"medium" => {
99-
query = query.filter(
100-
cves::cvss3_score
101-
.between(4.0, 6.9)
102-
.or(cves::cvss2_score.between(4.0, 6.9)),
103-
);
104-
}
105-
"high" => {
106-
query = query.filter(
107-
cves::cvss3_score
108-
.between(7.0, 8.9)
109-
.or(cves::cvss2_score.gt(7.0)),
110-
);
111-
}
112-
"critical" => {
113-
query = query.filter(cves::cvss3_score.gt(9.0));
114-
}
115-
_ => {}
116-
}
89+
query = query.filter(cves::severity.eq(severity.to_lowercase()));
11790
}
11891
Ok(query)
11992
}

nvd-server/src/modules/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ pub struct Cve {
2525
pub id: String,
2626
pub year: i32,
2727
pub assigner: String,
28-
pub references: Value,
2928
pub description: Value,
30-
pub problem_type: Value,
31-
pub cvss3_vector: String,
32-
pub cvss3_score: f32,
33-
pub cvss2_vector: String,
34-
pub cvss2_score: f32,
29+
pub severity:String,
30+
pub metrics:Value,
31+
pub weaknesses: Value,
3532
pub configurations: Value,
33+
pub references: Value,
34+
pub timeline: Value,
3635
pub created_at: NaiveDateTime,
3736
pub updated_at: NaiveDateTime,
3837
}

nvd-server/src/schema.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ diesel::table! {
1616
year -> Integer,
1717
#[max_length = 64]
1818
assigner -> Varchar,
19-
references -> Json,
2019
description -> Json,
21-
problem_type -> Json,
22-
#[max_length = 64]
23-
cvss3_vector -> Varchar,
24-
cvss3_score -> Float,
25-
#[max_length = 64]
26-
cvss2_vector -> Varchar,
27-
cvss2_score -> Float,
20+
#[max_length = 32]
21+
severity -> Varchar,
22+
metrics -> Json,
23+
weaknesses -> Json,
2824
configurations -> Json,
25+
references -> Json,
26+
timeline -> Json,
2927
created_at -> Timestamp,
3028
updated_at -> Timestamp,
3129
}

nvd-yew/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ web-sys = { version = "0.3.63", features = [
1919
wasm-bindgen = { version = "0.2.87", features = ["serde"] }
2020
cvss = { path = "../cvss" }
2121
cve = { path = "../cve" }
22+
cpe = { path = "../cpe" }
2223
chrono = { version = "0.4", default-features = false, features = ["serde", "wasmbind", "clock"] }
2324
js-sys = "0.3.65"
2425
reqwest = { version = "0.11", features = ["json", "cookies"] }

nvd-yew/src/component/cve_configuration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use cve::v4::configurations::Operator;
33
use yew::prelude::*;
44
#[derive(PartialEq, Clone, Properties)]
55
pub struct CVEConfigurationProps {
6-
pub props: cve::v4::configurations::Configurations,
6+
pub props: Vec<cve::v4::configurations::Node>,
77
}
88
pub struct CVEConfiguration;
99
impl Component for CVEConfiguration {
@@ -35,7 +35,7 @@ impl Component for CVEConfiguration {
3535
</tr>
3636
</thead>
3737
<tbody>
38-
{self.node(configuration.nodes)}
38+
{self.node(configuration)}
3939
</tbody>
4040
</table>
4141
</div>

nvd-yew/src/component/cve_row.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,23 @@ impl Component for CVERow {
3131
let cve_id = props.id;
3232
let description = props
3333
.description
34-
.description_data
3534
.iter()
3635
.map(|d| d.value.clone())
3736
.collect::<Vec<String>>();
3837
let update = props.created_at.to_string();
3938
let cwe: Vec<String> = props
40-
.problem_type
41-
.problem_type_data
39+
.weaknesses
4240
.iter()
4341
.map(|p| p.description.iter().map(|d| d.value.clone()).collect())
4442
.collect();
45-
let vendor_product = props.configurations.unique_vendor_product();
43+
let vendor_product = unique_vendor_product(props.configurations);
4644
let vendor: HashSet<String> = HashSet::from_iter(
4745
vendor_product
4846
.iter()
4947
.map(|v| v.vendor.clone())
5048
.collect::<Vec<String>>(),
5149
);
50+
let metrics = props.metrics.clone();
5251
html! {
5352
<>
5453
<tr class="table-group-divider">
@@ -87,10 +86,10 @@ impl Component for CVERow {
8786
{cwe}
8887
</td>
8988
<td>
90-
{cvss2(props.cvss2_score)}
89+
{cvss2(metrics.base_metric_v2.inner())}
9190
</td>
9291
<td>
93-
{cvss3(props.cvss3_score)}
92+
{cvss3(metrics.base_metric_v3.inner())}
9493
</td>
9594
<td>
9695
{update}
@@ -103,3 +102,9 @@ impl Component for CVERow {
103102
}
104103
}
105104
}
105+
pub fn unique_vendor_product(nodes: Vec<cve::v4::configurations::Node>) -> Vec<cpe::Product> {
106+
nodes
107+
.iter()
108+
.flat_map(|node| node.vendor_product())
109+
.collect()
110+
}

nvd-yew/src/component/cvss_tags.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,38 @@ use cvss::metric::{Help, Worth};
33
use cvss::severity::{SeverityType, SeverityTypeV2};
44
use yew::prelude::*;
55

6-
pub fn cvss2(score: f32) -> Html {
7-
let severity = cvss::severity::SeverityTypeV2::from(score);
8-
let severity_class = match severity {
9-
SeverityTypeV2::None => "bg-secondary",
10-
SeverityTypeV2::Low => "bg-info",
11-
SeverityTypeV2::Medium => "bg-warning",
12-
SeverityTypeV2::High => "bg-danger",
13-
};
14-
let score_str = if score == 0.0 {
15-
String::from("N/A")
16-
} else {
17-
score.to_string()
6+
pub fn cvss2(metric: Option<&cvss::v2::ImpactMetricV2>) -> Html {
7+
let mut score = 0.0;
8+
let severity_class = match metric {
9+
None => "bg-secondary",
10+
Some(m) => {
11+
score = m.cvss_v2.base_score;
12+
match m.severity {
13+
SeverityTypeV2::None => "bg-secondary",
14+
SeverityTypeV2::Low => "bg-info",
15+
SeverityTypeV2::Medium => "bg-warning",
16+
SeverityTypeV2::High => "bg-danger",
17+
}
18+
}
1819
};
19-
html!(<span class={classes!(["badge",severity_class])}><b style="font-size:larger">{score_str}</b></span>)
20+
html!(<span class={classes!(["badge",severity_class])}><b style="font-size:larger">{score}</b></span>)
2021
}
21-
pub fn cvss3(score: f32) -> Html {
22-
let severity = cvss::severity::SeverityType::from(score);
23-
let severity_class = match severity {
24-
SeverityType::None => "bg-secondary",
25-
SeverityType::Low => "bg-info",
26-
SeverityType::Medium => "bg-warning",
27-
SeverityType::High => "bg-danger",
28-
SeverityType::Critical => "bg-dark",
29-
};
30-
let score_str = if score == 0.0 {
31-
String::from("N/A")
32-
} else {
33-
format!("{} {}", score, severity)
22+
pub fn cvss3(metric: Option<&cvss::v3::ImpactMetricV3>) -> Html {
23+
let mut score = 0.0;
24+
let severity_class = match metric {
25+
None => "bg-secondary",
26+
Some(m) => {
27+
score = m.cvss_v3.base_score;
28+
match m.cvss_v3.base_severity {
29+
SeverityType::None => "bg-secondary",
30+
SeverityType::Low => "bg-info",
31+
SeverityType::Medium => "bg-warning",
32+
SeverityType::High => "bg-danger",
33+
SeverityType::Critical => "bg-dark",
34+
}
35+
}
3436
};
35-
html!(<span class={classes!(["badge",severity_class])}><b style="font-size:larger">{score_str}</b></span>)
37+
html!(<span class={classes!(["badge",severity_class])}><b style="font-size:larger">{score}</b></span>)
3638
}
3739
pub enum V3Card {
3840
AV(cvss::v3::attack_vector::AttackVectorType),

nvd-yew/src/modules/cve.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ pub struct Cve {
66
pub id: String,
77
pub year: i32,
88
pub assigner: String,
9-
pub references: cve::v4::References,
10-
pub description: cve::v4::Description,
11-
pub problem_type: cve::v4::ProblemType,
12-
pub cvss3_vector: String,
13-
pub cvss3_score: f32,
14-
pub cvss2_vector: String,
15-
pub cvss2_score: f32,
16-
pub configurations: cve::v4::configurations::Configurations,
9+
pub description: Vec<cve::v4::Description>,
10+
pub severity: String,
11+
pub metrics: cve::impact::ImpactMetrics,
12+
pub weaknesses: Vec<cve::v4::Weaknesses>,
13+
pub configurations: Vec<cve::v4::configurations::Node>,
14+
pub references: Vec<cve::v4::Reference>,
1715
pub created_at: NaiveDateTime,
1816
pub updated_at: NaiveDateTime,
1917
}

0 commit comments

Comments
 (0)