forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanDomain.js
More file actions
375 lines (355 loc) · 14.3 KB
/
ScanDomain.js
File metadata and controls
375 lines (355 loc) · 14.3 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import React from 'react'
import { t, Trans } from '@lingui/macro'
import { Formik } from 'formik'
import {
Accordion,
AccordionButton,
AccordionIcon,
AccordionItem,
AccordionPanel,
Box,
Button,
Divider,
Flex,
Heading,
Stack,
Tab,
TabList,
TabPanel,
TabPanels,
Tabs,
Text,
useToast,
} from '@chakra-ui/react'
import { WarningTwoIcon } from '@chakra-ui/icons'
import { useMutation, useQuery } from '@apollo/client'
import { DomainField } from '../components/fields/DomainField'
import { StatusBadge } from './StatusBadge'
// import { ScanDetails } from '../guidance/ScanDetails'
import { LoadingMessage } from '../components/LoadingMessage'
import { StatusIcon } from '../components/StatusIcon'
import { createValidationSchema } from '../utilities/fieldRequirements'
import { GET_ONE_TIME_SCANS } from '../graphql/queries'
import { REQUEST_SCAN } from '../graphql/mutations'
export function ScanDomain() {
const toast = useToast()
const [requestScan, { loading }] = useMutation(REQUEST_SCAN, {
onError(error) {
toast({
title: error.message,
description: t`Unable to request scan, please try again.`,
status: 'error',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
onCompleted() {
toast({
title: t`Scan Request`,
description: t`Scan of domain successfully requested`,
status: 'success',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
const { data: oneTimeScansData } = useQuery(GET_ONE_TIME_SCANS)
if (loading) return <LoadingMessage />
const getScanTypeFromScan = (scan) => {
switch (scan.__typename) {
case 'HttpsSub':
return 'https'
case 'DkimSub':
return 'dkim'
case 'DmarcSub':
return 'dmarc'
case 'SslSub':
return 'ssl'
case 'SpfSub':
return 'spf'
}
return scan.__typename
}
const mergedScans = []
const oneTimeScans = oneTimeScansData?.getOneTimeScans
if (oneTimeScans) {
oneTimeScans.forEach((scan) => {
const curScanType = getScanTypeFromScan(scan)
// check if merged scan with same sharedId already exists
const mergedScanMatchIndex = mergedScans.findIndex((mergedScan) => {
return mergedScan.sharedId === scan.sharedId
})
if (mergedScanMatchIndex === -1) {
// no matching scan found, place new merged scan at end of array
mergedScans.push({
sharedId: scan.sharedId,
scan: { [curScanType]: scan },
domain: scan.domain.domain,
})
} else {
// matching merged scan found, merge current scan with it
mergedScans[mergedScanMatchIndex].scan[curScanType] = scan
}
})
}
const dmarcSteps = {
assess: [
t`Identify all domains and subdomains used to send mail;`,
t`Assess current state;`,
t`Deploy initial DMARC records with policy of none; and`,
t`Collect and analyze DMARC reports.`,
],
deploy: [
t`Identify all authorized senders;`,
t`Deploy SPF records for all domains;`,
t`Deploy DKIM records and keys for all domains and senders; and`,
t`Monitor DMARC reports and correct misconfigurations.`,
],
enforce: [
t`Upgrade DMARC policy to quarantine (gradually increment enforcement from 25% to 100%);`,
t`Upgrade DMARC policy to reject (gradually increment enforcement from 25%to 100%); and`,
t`Reject all messages from non-mail domains.`,
],
maintain: [
t`Monitor DMARC reports;`,
t`Correct misconfigurations and update records as required; and`,
t`Rotate DKIM keys annually.`,
],
}
const statusGroupingProps = {
flexDirection: { base: 'column', md: 'row' },
border: '1px solid',
borderColor: 'gray.300',
borderRadius: 'md',
px: { base: 2, md: 0 },
py: { base: 1, md: 2 },
mx: { base: 0, md: 1 },
my: { base: 2, md: 0 },
bg: 'gray.100',
}
return (
<Box px="2" mx="auto" overflow="hidden">
<Formik
validationSchema={createValidationSchema(['domainUrl'])}
initialValues={{ domainUrl: '' }}
onSubmit={async (values) =>
requestScan({
variables: {
domainUrl: values.domainUrl.toLowerCase(),
},
})
}
>
{({ handleSubmit, isSubmitting }) => {
return (
<form onSubmit={handleSubmit} role="form" aria-label="form" name="form">
<Box>
<Text fontSize="2xl" mb="2" textAlign={{ base: 'center', md: 'left' }}>
<Trans>Request a domain to be scanned:</Trans>
</Text>
<DomainField name="domainUrl" mb="4" />
<Button
w={{ base: '100%', md: '25%' }}
variant="primary"
isLoading={isSubmitting}
type="submit"
name="submitBtn"
id="submitBtn"
fontSize="lg"
>
<Trans>Scan Domain</Trans>
</Button>
</Box>
</form>
)
}}
</Formik>
<Accordion allowMultiple defaultIndex={[]} mt={4}>
{mergedScans.reverse().map((mergedScan, index) => {
return (
<AccordionItem key={index} mb={8} borderRadius="sm">
<h2>
<AccordionButton
width="100%"
p="4"
pl={{ md: '8' }}
alignItems={{ base: 'flex-start', md: 'center' }}
flexDirection={{ base: 'column', md: 'row' }}
textAlign="left"
fontWeight="inherit"
bg="gray.100"
_hover={{ bg: ['', 'gray.300'] }}
>
<Box
flexGrow={{ md: '2' }}
flexBasis={{ md: '5em' }}
mr={{ md: '1em' }}
flexShrink={{ md: '0.5' }}
minWidth={{ md: '3em' }}
>
<Text fontWeight="semibold">
<Trans>Domain:</Trans>
</Text>
<Text isTruncated>{mergedScan.domain}</Text>
</Box>
<Flex flexDirection={{ base: 'column', md: 'row' }} flexGrow={{ base: 0, md: '1' }}>
<Flex {...statusGroupingProps}>
<StatusBadge
text="HTTPS:"
status={mergedScan.scan?.https ? mergedScan.scan.https.status : 'LOADING'}
/>
<StatusBadge text="TLS:" status={mergedScan.scan?.ssl ? mergedScan.scan.ssl.status : 'LOADING'} />
</Flex>
<Flex {...statusGroupingProps}>
<StatusBadge text="SPF:" status={mergedScan.scan?.spf ? mergedScan.scan.spf.status : 'LOADING'} />
<StatusBadge
text="DKIM:"
status={mergedScan.scan?.dkim ? mergedScan.scan.dkim.status : 'LOADING'}
/>
<StatusBadge
text="DMARC:"
status={mergedScan.scan?.dmarc ? mergedScan.scan.dmarc.status : 'LOADING'}
/>
</Flex>
<Divider orientation={{ base: 'horizontal', md: 'vertical' }} alignSelf="stretch" />
</Flex>
</AccordionButton>
</h2>
<AccordionPanel>
<Tabs isFitted variant="enclosed-colored">
<TabList mb="4">
<Tab borderTopWidth="4px">
<Trans>Web Guidance</Trans>
</Tab>
<Tab borderTopWidth="4px">
<Trans>Email Guidance</Trans>
</Tab>
</TabList>
<TabPanels>
<TabPanel>
<Box bg="white" rounded="lg" overflow="hidden" boxShadow="medium" pb="1">
<Box bg="primary" color="gray.50">
<Stack px="3" py="1">
<Heading as="h1" size="lg">
<Trans>Web Scan Results</Trans>
</Heading>
<Text fontSize={['md', 'lg']}>
<Trans>Results for scans of web technologies (TLS, HTTPS).</Trans>
</Text>
</Stack>
</Box>
<Box>
<Stack spacing="30px" px="1" mt="1">
<Box pb="1">
{mergedScan.scan.https && mergedScan.scan.ssl ? (
mergedScan.scan.https.status === 'PASS' && mergedScan.scan.ssl.status === 'PASS' ? (
<Stack isInline align="center" px="2">
<StatusIcon status="PASS" />
<Text fontWeight="bold" fontSize="2xl">
<Trans>ITPIN Compliant</Trans>
</Text>
</Stack>
) : (
<Stack isInline align="center" px="2">
<WarningTwoIcon color="moderate" size="icons.md" />
<Text fontWeight="bold" fontSize="2xl">
<Trans>Changes Required for ITPIN Compliance</Trans>
</Text>
</Stack>
)
) : (
<LoadingMessage>One Time Scan</LoadingMessage>
)}
</Box>
<Accordion allowMultiple defaultIndex={[0, 1]}>
{/* {mergedScan?.scan.https && (
<ScanDetails
categoryName="https"
categoryData={mergedScan.scan.https}
/>
)}
{mergedScan?.scan.ssl && (
<ScanDetails
categoryName="TLS"
categoryData={mergedScan.scan.ssl}
/>
)} */}
</Accordion>
</Stack>
</Box>
</Box>
</TabPanel>
<TabPanel>
<Box bg="white" rounded="lg" overflow="hidden" boxShadow="medium" pb="1">
<Box bg="primary" color="gray.50">
<Stack px="3" py="1">
<Heading as="h1" size="lg">
<Trans>Email Scan Results</Trans>
</Heading>
<Text fontSize={['md', 'lg']}>
<Trans>Results for scans of email technologies (DMARC, SPF, DKIM).</Trans>
</Text>
</Stack>
</Box>
<Box>
<Stack spacing="30px" px="1" mt="1">
<Box pb="1">
{mergedScan.scan.dmarc ? (
<Box pb="1">
<Stack isInline align="center" px="2">
<Text fontWeight="bold" fontSize="2xl">
<Trans>
DMARC Implementation Phase:{' '}
{mergedScan.scan.dmarc.dmarcPhase
? mergedScan.scan.dmarc.dmarcPhase.toUpperCase()
: 'UNKNOWN'}
</Trans>
</Text>
</Stack>
{mergedScan.scan.dmarc.dmarcPhase &&
mergedScan.scan.dmarc.dmarcPhase !== 'not implemented' && (
<Box bg="gray.100" px="2" py="1">
{dmarcSteps[mergedScan.scan.dmarc.dmarcPhase].map((step, index) => (
<Text key={index}>
{index + 1}. {step}
</Text>
))}
</Box>
)}
</Box>
) : (
<LoadingMessage>One Time Scan</LoadingMessage>
)}
</Box>
<Accordion allowMultiple defaultIndex={[0, 1, 2]}>
{/* {mergedScan?.scan.dkim && (
<ScanDetails categoryName="dkim" categoryData={mergedScan.scan.dkim} />
)}
{mergedScan?.scan.dmarc && (
<ScanDetails categoryName="dmarc" categoryData={mergedScan.scan.dmarc} />
)}
{mergedScan?.scan.spf && (
<ScanDetails categoryName="spf" categoryData={mergedScan.scan.spf} />
)} */}
</Accordion>
</Stack>
</Box>
</Box>
</TabPanel>
</TabPanels>
</Tabs>
</AccordionPanel>
<h2>
<AccordionButton justifyContent="center" bg="gray.100" _hover={{ bg: ['', 'gray.300'] }}>
<AccordionIcon />
</AccordionButton>
</h2>
</AccordionItem>
)
})}
</Accordion>
</Box>
)
}