forked from Fraunhofer-AISEC/cmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policies-ids.js
94 lines (79 loc) · 3.08 KB
/
policies-ids.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Parse the verification result
var obj = JSON.parse(json);
var success = true;
// Basic checks
if (obj.type != "Verification Result") {
console.log("Invalid type");
success = false;
}
if (!obj.raSuccessful) {
console.log("Attestation not successful")
success = false;
}
//Generic function for checking roles in SignatureResults
function checkRoles(signatureResults, expectedRoles){
if (signatureResults.length != expectedRoles.length) {
console.log("Number of expected roles does not match number of signatures")
return false;
}
for (i = 0; i < signatureResults.length; i++) {
if (signatureResults[i].validatedCerts.length == 0) {
console.log("Cert chain for signed artifact is empty")
return false;
}
if (signatureResults[i].validatedCerts.length == 0) {
console.log("No validated cert chain provided for signed artifact")
return false;
}
if (signatureResults[i].validatedCerts[0].length == 0) {
console.log("Cert chain for signed artifact is empty")
return false;
}
//initial cert should be the same in each chain if multiple validated chains are provided -> it is sufficient to verify the role in validatedCerts[0][0]
if (signatureResults[i].validatedCerts[0][0].subject.organizationalUnit != expectedRoles[i]){
console.log("Role " + i + " in cert does not match: " + signatureResults[i].validatedCerts[0][0].subject.organizationalUnit + " vs. " + expectedRoles[i])
return false;
}
}
return true;
}
//Verify AR was signed by a device
if (!checkRoles(obj.reportSignatureCheck, ["device"])) {
console.log("Role check for Attestation Report Signature failed")
success = false;
} else {
console.log("Role check for Attestation Report Signature successful")
}
//Verify roles used to sign RTM Manifest
if (!checkRoles(obj.rtmValidation.signatureValidation, ["Developer", "Evaluator", "Certifier"])) {
console.log("Role check for RTM Manifest Signatures failed")
success = false;
} else {
console.log("Role check for RTM Manifest Signature successful")
}
//Verify roles used to sign OS Manifest
if (!checkRoles(obj.osValidation.signatureValidation, ["Developer", "Evaluator", "Certifier"])) {
console.log("Role check for OS Manifest Signatures failed")
success = false;
} else {
console.log("Role check for OS Manifest Signature successful")
}
//Verify roles used to sign App Manifests (if applicable)
if (obj.appValidation) {
for (i=0; i < obj.appValidation.length; i++){
if (!checkRoles(obj.appValidation[i].signatureValidation, ["Developer", "Evaluator", "Certifier"])) {
console.log("Role check for Signatures of App Manifest " + i + " failed")
success = false;
} else {
console.log("Role check for Signatures of App Manifest " + i + " successful")
}
}
}
//Verify roles used to sign Company Description
if (!checkRoles(obj.companyValidation.signatureValidation, ["Operator", "Evaluator", "Certifier"])) {
console.log("Role check for Company Description Signatures failed")
success = false;
} else {
console.log("Role check for Company Description Signatures successful")
}
success