forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanCategoryDetails.js
More file actions
247 lines (236 loc) · 6.84 KB
/
ScanCategoryDetails.js
File metadata and controls
247 lines (236 loc) · 6.84 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import React, { useState } from 'react'
import { object, string } from 'prop-types'
import { Box, Collapse, Divider, Heading, Stack, Text } from '@chakra-ui/core'
import { TrackerButton } from './TrackerButton'
import { GuidanceTagList } from './GuidanceTagList'
import WithPseudoBox from './withPseudoBox'
import { t, Trans } from '@lingui/macro'
function ScanCategoryDetails({ categoryName, categoryData }) {
const [showCategory, setShowCategory] = useState(true)
const handleShowCategory = () => setShowCategory(!showCategory)
const [showCiphers, setShowCiphers] = useState(true)
const handleShowCiphers = () => setShowCiphers(!showCiphers)
const [showCurves, setShowCurves] = useState(true)
const handleShowCurves = () => setShowCurves(!showCurves)
const data = categoryData.edges[0]?.node
if (!data)
return (
<Text fontWeight="bold" fontSize="2xl">
<Trans>
{t`No scan data available for ${categoryName.toUpperCase()}.`}
</Trans>
</Text>
)
const tagDetails =
categoryName === 'dkim' ? (
data.results.edges.map(({ node }, idx) => (
<GuidanceTagList
negativeTags={node.negativeGuidanceTags.edges}
positiveTags={node.positiveGuidanceTags.edges}
neutralTags={node.neutralGuidanceTags.edges}
selector={node.selector}
key={categoryName + idx}
/>
))
) : (
<GuidanceTagList
negativeTags={data.negativeGuidanceTags.edges}
positiveTags={data.positiveGuidanceTags.edges}
neutralTags={data.neutralGuidanceTags.edges}
key={categoryName}
/>
)
const webSummary =
categoryName === 'https' ? (
<Box bg="gray.100" px="2" py="1">
<Stack isInline>
<Text fontWeight="bold">
<Trans>Implementation:</Trans>
</Text>
<Text>{data?.implementation}</Text>
</Stack>
<Stack isInline>
<Text fontWeight="bold">
<Trans>Enforcement:</Trans>
</Text>
<Text>{data?.enforced}</Text>
</Stack>
<Stack isInline>
<Text fontWeight="bold">
<Trans>HSTS Status:</Trans>
</Text>
<Text>{data?.hsts}</Text>
</Stack>
{data?.hstsAge && (
<Stack isInline>
<Text fontWeight="bold">
<Trans>HSTS Age:</Trans>
</Text>
<Text>{data?.hstsAge}</Text>
</Stack>
)}
<Stack isInline>
<Text fontWeight="bold">
<Trans>Preloaded Status:</Trans>
</Text>
<Text> {data?.preloaded}</Text>
</Stack>
</Box>
) : categoryName === 'ssl' ? (
<Box bg="gray.100" px="2" py="1">
<Stack isInline>
<Text fontWeight="bold">
<Trans>CCS Injection Vulnerability:</Trans>
</Text>
<Text>{data?.ccsInjectionVulnerable ? t`Yes` : t`No`}</Text>
</Stack>
<Stack isInline>
<Text fontWeight="bold">
<Trans>Heartbleed Vulnerability:</Trans>
</Text>
<Text>{data?.heartbleedVulnerable ? t`Yes` : t`No`}</Text>
</Stack>
<Stack isInline>
<Text fontWeight="bold">
<Trans>Supports ECDH Key Exchange:</Trans>
</Text>
<Text>{data?.supportsEcdhKeyExchange ? t`Yes` : t`No`}</Text>
</Stack>
</Box>
) : null
const mapCiphers = (cipherList) => {
return (
<Box px="2">
{cipherList.length > 0 ? (
cipherList.map((cipher, id) => {
return (
<Text key={id} isTruncated fontSize={['sm', 'md']}>
{cipher}
</Text>
)
})
) : (
<Text>
<Trans>None</Trans>
</Text>
)}
</Box>
)
}
const ciphers = categoryName === 'ssl' && (
<Box>
<Stack>
<Box bg="strongMuted">
<Box bg="strong" color="white" px="2">
<Text fontWeight="bold">
<Trans>Strong Ciphers:</Trans>
</Text>
</Box>
{mapCiphers(data?.strongCiphers)}
</Box>
<Divider />
<Box bg="moderateMuted">
<Box bg="moderate" color="white" px="2">
<Text fontWeight="bold">
<Trans>Acceptable Ciphers:</Trans>
</Text>
</Box>
{mapCiphers(data?.acceptableCiphers)}
</Box>
<Divider />
<Box bg="weakMuted">
<Box bg="weak" color="white" px="2">
<Text fontWeight="bold">
<Trans>Weak Ciphers:</Trans>
</Text>
</Box>
{mapCiphers(data?.weakCiphers)}
</Box>
</Stack>
</Box>
)
const curves = categoryName === 'ssl' && (
<Box>
<Stack>
<Box bg="strongMuted">
<Box bg="strong" color="white" px="2">
<Text fontWeight="bold">
<Trans>Strong Curves:</Trans>
</Text>
</Box>
{mapCiphers(data?.strongCurves)}
</Box>
<Divider />
<Box bg="moderateMuted">
<Box bg="moderate" color="white" px="2">
<Text fontWeight="bold">
<Trans>Acceptable Curves:</Trans>
</Text>
</Box>
{mapCiphers(data?.acceptableCurves)}
</Box>
<Divider />
<Box bg="weakMuted">
<Box bg="weak" color="white" px="2">
<Text fontWeight="bold">
<Trans>Weak Curves:</Trans>
</Text>
</Box>
{mapCiphers(data?.weakCurves)}
</Box>
</Stack>
</Box>
)
return (
<Box pb="2">
<TrackerButton
variant="primary"
onClick={handleShowCategory}
w={['100%', '25%']}
mb="4"
>
<Heading as="h2" size="md">
{categoryName.toUpperCase()}
</Heading>
</TrackerButton>
<Collapse isOpen={showCategory}>
{webSummary}
<Divider />
{tagDetails}
{ciphers && (
<Box>
<Divider />
<TrackerButton
variant="primary"
onClick={handleShowCiphers}
w="100%"
mb="2"
>
<Trans>Ciphers</Trans>
</TrackerButton>
<Collapse isOpen={showCiphers}>{ciphers}</Collapse>
</Box>
)}
{curves && (
<Box>
<Divider />
<TrackerButton
variant="primary"
onClick={handleShowCurves}
w="100%"
mb="2"
>
<Trans>Curves</Trans>
</TrackerButton>
<Collapse isOpen={showCurves}>{curves}</Collapse>
</Box>
)}
</Collapse>
</Box>
)
}
ScanCategoryDetails.propTypes = {
categoryName: string,
categoryData: object,
}
export default WithPseudoBox(ScanCategoryDetails)