forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_test.go
48 lines (39 loc) · 1.14 KB
/
simple_test.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
package crypto
import (
"testing"
assert "github.com/stretchr/testify/assert"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
)
func TestObfuscation(t *testing.T) {
name := "Foobar"
config_obj := &config_proto.Config{
Frontend: &config_proto.FrontendConfig{
// The obfuscation key is simply the hash of
// the PEM private key.
PrivateKey: "hello",
},
}
obfuscator := &Obfuscator{}
// Decrypting a string encrypted with another key should
// error.
test_str := "$3f6d20f47d3a66dc1e74378916882a74899f0503ec650795d284403286b9fd79"
_, err := obfuscator.Decrypt(config_obj, test_str)
assert.Error(t, err)
// Not hex encoded.
_, err = obfuscator.Decrypt(config_obj,
"$3")
assert.Error(t, err)
// Block cipher too short
_, err = obfuscator.Decrypt(config_obj,
"$3f")
assert.Error(t, err)
// Make sure we can obfuscate a string of any length.
for i := 0; i < 16; i++ {
obf, err := obfuscator.Encrypt(config_obj, name)
assert.NoError(t, err, "Cant encrypt")
plain, err := obfuscator.Decrypt(config_obj, obf)
assert.NoError(t, err, "Cant decrypt")
assert.Equal(t, plain, name)
name = name + "X"
}
}