Skip to content

Commit be4a7b8

Browse files
authored
Merge pull request #185 from sahibamittal/Issue-1775-policy-component-hash
Issue 1775 : policy condition - component hash
2 parents 1ef89df + 3969b81 commit be4a7b8

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/i18n/locales/en.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"component_created": "Component created",
101101
"component_updated": "Component updated",
102102
"component_deleted": "Component deleted",
103+
"component_hash": "Component Hash",
103104
"property_created": "Property created",
104105
"property_deleted": "Property deleted",
105106
"create_project": "Create Project",
@@ -552,6 +553,20 @@
552553
"contains_any": "contains any",
553554
"contains_all": "contains all"
554555
},
556+
"hashes" : {
557+
"md5": "MD5",
558+
"sha_1": "SHA-1",
559+
"sha_256": "SHA-256",
560+
"sha_384": "SHA-384",
561+
"sha_512": "SHA-512",
562+
"sha3_256": "SHA3-256",
563+
"sha3_384": "SHA3-384",
564+
"sha3_512": "SHA3-512",
565+
"blake_256": "BLAKE2b-256",
566+
"blake_384": "BLAKE2b-384",
567+
"blake_512": "BLAKE2b-512",
568+
"blake3": "BLAKE3"
569+
},
555570
"policy_violation": {
556571
"fails": "Violation Failures",
557572
"warns": "Violation Warnings",

src/views/policy/PolicyCondition.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
{value: 'CPE', text: this.$t('message.cpe_full')},
7575
{value: 'SWID_TAGID', text: this.$t('message.swid_tagid')},
7676
{value: 'VERSION', text: this.$t('message.version')},
77+
{value: 'COMPONENT_HASH', text: this.$t('message.component_hash')},
7778
{value: 'CWE', text: this.$t('message.cwe_full')}
7879
],
7980
objectOperators: [
@@ -92,6 +93,20 @@
9293
{value: 'NUMERIC_GREATER_THAN_OR_EQUAL', text: ''},
9394
{value: 'NUMERIC_LESSER_THAN_OR_EQUAL', text: ''}
9495
],
96+
hashAlgorithms: [
97+
{value: 'MD5', text: this.$t('hashes.md5')},
98+
{value: 'SHA-1', text: this.$t('hashes.sha_1')},
99+
{value: 'SHA-256', text: this.$t('hashes.sha_256')},
100+
{value: 'SHA-384', text: this.$t('hashes.sha_384')},
101+
{value: 'SHA-512', text: this.$t('hashes.sha_512')},
102+
{value: 'SHA3-256', text: this.$t('hashes.sha3_256')},
103+
{value: 'SHA3-384', text: this.$t('hashes.sha3_384')},
104+
{value: 'SHA3-512', text: this.$t('hashes.sha3_512')},
105+
{value: 'BLAKE2b-256', text: this.$t('hashes.blake_256')},
106+
{value: 'BLAKE2b-384', text: this.$t('hashes.blake_384')},
107+
{value: 'BLAKE2b-512', text: this.$t('hashes.blake_512')},
108+
{value: 'BLAKE3', text: this.$t('hashes.blake3')}
109+
],
95110
listOperators: [
96111
{value: 'CONTAINS_ANY', text: this.$t('operator.contains_any')},
97112
{value: 'CONTAINS_ALL', text: this.$t('operator.contains_all')}
@@ -125,6 +140,8 @@
125140
return false;
126141
case 'VERSION':
127142
return false;
143+
case 'COMPONENT_HASH':
144+
return false;
128145
case 'CWE':
129146
return false;
130147
default:
@@ -156,7 +173,7 @@
156173
break;
157174
case 'SEVERITY':
158175
this.operators = this.objectOperators;
159-
this.populateSeverity()
176+
this.populateSeverity();
160177
break;
161178
case 'COORDINATES':
162179
this.operators = this.regexOperators;
@@ -181,6 +198,9 @@
181198
case 'VERSION':
182199
this.operators = this.numericOperators;
183200
break;
201+
case 'COMPONENT_HASH':
202+
this.operators = this.hashAlgorithms;
203+
break;
184204
case 'CWE':
185205
this.operators = this.listOperators;
186206
break;
@@ -196,6 +216,11 @@
196216
name: common.trimToNull(this.coordinatesName),
197217
version: common.trimToNull(this.coordinatesVersion)
198218
});
219+
} else if (this.subject === "COMPONENT_HASH") {
220+
return JSON.stringify({
221+
algorithm: common.trimToNull(this.operator),
222+
value: common.trimToNull(this.value)
223+
});
199224
} else {
200225
return this.value;
201226
}
@@ -210,7 +235,7 @@
210235
this.axios.post(url, {
211236
uuid: this.condition.uuid,
212237
subject: this.subject,
213-
operator: this.operator,
238+
operator: this.subject === 'COMPONENT_HASH' ? 'IS' : this.operator,
214239
value: dynamicValue
215240
}).then((response) => {
216241
this.condition = response.data;
@@ -222,7 +247,7 @@
222247
let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/condition`;
223248
this.axios.put(url, {
224249
subject: this.subject,
225-
operator: this.operator,
250+
operator: this.subject === 'COMPONENT_HASH' ? 'IS' : this.operator,
226251
value: dynamicValue
227252
}).then((response) => {
228253
this.condition = response.data;

0 commit comments

Comments
 (0)