-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (62 loc) · 1.96 KB
/
main.go
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
package main
import (
"fmt"
"math"
"regexp"
"time"
)
var (
inputFile string
s3ObjectUrl string
s3Region string
threadCount int
defaultS3Region = "us-east-1"
md5Reg, _ = regexp.Compile("(?i)([0-9|A-F]){32}")
mB = 1024 * 1024
defaultChunkSize = mB * 5
)
func main() {
rootCmd.Execute()
}
func validate() {
//===============
// PARSE THE ETAG
//===============
var etag *eTag
var err error
if etag, err = getS3ObjectETag(s3ObjectUrl, s3Region); err != nil {
eLog.Println("Failed to retrieve S3 object ETag via API")
eLog.Fatalf("%v", err)
}
iLog.Printf("Retrieved ETag information via S3 API")
iLog.Printf("ETag Value: %s", etag.Value)
//==================
// VALIDATE THE FILE
//==================
iLog.Printf("Input File: %s", inputFile)
var calculated *eTag
var isValid bool
wLog.Printf("Verifying file integrity. This will take some time.")
wLog.Printf("Using process count: %v", threadCount)
start := time.Now()
if calculated, isValid, err = etag.validateFile(inputFile); err != nil {
eLog.Fatalf("Failed to verify integrity of file: %v", err)
}
duration := time.Since(start)
iLog.Printf("Integrity check finished")
iLog.Printf("AWS ETag > %s", etag.Value)
iLog.Printf("Calculated ETag > %s", calculated.Value)
var outcome string
if isValid {
iLog.Printf("ETag values matched")
iLog.Printf("File integrity status: confirmed")
outcome = "verified"
} else {
iLog.Print("ETag values mismatched")
wLog.Printf("File integrity status: compromised")
outcome = "compromised"
}
iLog.Printf("Verification Duration: %v:%v:%v.%v", math.Round(duration.Hours()),
math.Round(duration.Minutes()), math.Round(duration.Seconds()), duration.Milliseconds())
fmt.Printf("\nFile integrity: %s\n", outcome)
}