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
|
package nvdmirror
//
// Sync NVD data files to destination directory based on given sync
// configuration and cache.
//
// Returns an array of file names which have been updated in the
// destination directory.
//
// This function does the following:
//
// 1. Fetch the contents of the source meta URLs for CVE feeds and
// CPE matches. All source URLs are fetched concurrently.
//
// 2. Check the size and hash from meta files against the existing
// CVE feed and CPE match files in the destination directory. All
// file sizes and hashes are checked concurrently.
//
// 3. Fetch the contents of the changed CVE feeds, CPE match files, and
// the CPE dictionary.
//
// All HTTP requests are sent with the following headers:
//
// * if-modified-since: The last-modified header from the previous
// successful response, if it was set.
//
// * if-none-match: The etag header from the last successful response,
// if it was set.
//
// * user-agent: User agent from config, or the default user agent if
// the config value is unspecified.
//
func Sync(config SyncConfig, cache Cache, dstDir string) []string {
// build sync context
ctx := newSyncContext(config, cache, dstDir)
// fetch meta files, check for updates, append cpe dictionary URL,
// fetch updated files, and then return a list of changed files
return ctx.syncUrls(append(
ctx.checkMetas(ctx.fetchMetas()),
config.GetCpeDictUrl(),
config.GetCisaKevcUrl(),
config.GetCweListUrl(),
))
}
|