-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
96 lines (83 loc) · 2.37 KB
/
main_test.go
File metadata and controls
96 lines (83 loc) · 2.37 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
package main
import (
"testing"
"encoding/base64"
"log"
"encoding/json"
)
func TestRSA(t *testing.T) {
print("RSA-Test\n")
rsakey,_ := loadKey("keys/blub.priv")
p1 := "abcdef0123456789"
c, err := rsaEncrypt([]byte(p1), &rsakey)
if err != nil {
t.Error(err)
}
print(base64.StdEncoding.EncodeToString(c)+"\n")
p2, err := rsaDecrypt(c, &rsakey)
if err != nil {
t.Error(err)
} else if (p1 != string(p2)) {
t.Error("should be '", p1, "' is '", string(p2), "'")
}
}
func TestValidateTask(t *testing.T) {
ta := Task{
PrimaryURI : "http://127.0.0.1:8016/samples/3a12f43eeb0c45d241a8f447d4661d9746d6ea35990953334f5ec675f60e36c5",
SecondaryURI : "",
Filename : "myfile",
Tasks: map[string][]string{"PEINFO": []string{""}, "YARA": []string{""}},
Tags : []string{"test1"},
Attempts : 0 }
task, err := json.Marshal([]Task{ta})
if err != nil {
t.Error(err)
}
v, err := validateTask(string(task))
if err != nil {
t.Error(err)
} else if ((v[0].PrimaryURI != ta.PrimaryURI) || (v[0].SecondaryURI != ta.SecondaryURI)) {
t.Error("Error: ", v)
}
}
func TestAESDecrypt(t *testing.T) {
ciphertext, err := base64.StdEncoding.DecodeString("H6bNAXHIFpgqeJ2Kd+SJOnBjz94QSGAy+OeP096SZDM=")
if err != nil {
t.Error(err)
}
v, err := aesDecrypt(ciphertext, []byte("abcdef0123456789"), []byte("0000111122223333"))
if err != nil {
t.Error(err)
} else if (string(v) != ("test encryption!")) {
t.Error("Should be 'test encryption!' ", string(v), v)
}
}
func TestAES(t *testing.T) {
print("AES-Test\n")
ta := Task{
PrimaryURI : "http://127.0.0.1:8016/samples/3a12f43eeb0c45d241a8f447d4661d9746d6ea35990953334f5ec675f60e36c5",
SecondaryURI : "",
Filename : "myfile",
Tasks: map[string][]string{"PEINFO": []string{""}, "YARA": []string{""}},
Tags : []string{"test1"},
Attempts : 5 }
task, err := json.Marshal([]Task{ta})
if err != nil {
t.Error(err)
}
plaintext := []byte(task)
log.Printf(string(plaintext))
key := []byte("abcdef0123456789")
iv := []byte("0000111122223333")
ciphertext, err := aesEncrypt(plaintext, key, iv)
if err != nil {
t.Error(err)
}
print(base64.StdEncoding.EncodeToString(ciphertext)+"\n")
plaintext2, err := aesDecrypt(ciphertext, key, iv)
if err != nil {
t.Error(err)
} else if (string(plaintext2) != string(plaintext)) {
t.Error("Should be", len(string(plaintext)), len(string(plaintext2)), "\n", plaintext,"\n", plaintext2)
}
}