-
-
Notifications
You must be signed in to change notification settings - Fork 641
/
Copy pathg405_samples.go
67 lines (48 loc) · 1.16 KB
/
g405_samples.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
package testutils
import "github.com/securego/gosec/v2"
var (
// SampleCodeG405 - Use of weak crypto encryption DES
SampleCodeG405 = []CodeSample{
{[]string{`
package main
import (
"crypto/des"
"fmt"
)
func main() {
// Weakness: Usage of weak encryption algorithm
c, e := des.NewCipher([]byte("mySecret"))
if e != nil {
panic("We have a problem: " + e.Error())
}
data := []byte("hello world")
fmt.Println("Plain", string(data))
c.Encrypt(data, data)
fmt.Println("Encrypted", string(data))
c.Decrypt(data, data)
fmt.Println("Plain Decrypted", string(data))
}
`}, 1, gosec.NewConfig()},
}
// SampleCodeG405b - Use of weak crypto encryption RC4
SampleCodeG405b = []CodeSample{
{[]string{`
package main
import (
"crypto/rc4"
"fmt"
)
func main() {
// Weakness: Usage of weak encryption algorithm
c, _ := rc4.NewCipher([]byte("mySecret"))
data := []byte("hello world")
fmt.Println("Plain", string(data))
c.XORKeyStream(data, data)
cryptCipher2, _ := rc4.NewCipher([]byte("mySecret"))
fmt.Println("Encrypted", string(data))
cryptCipher2.XORKeyStream(data, data)
fmt.Println("Plain Decrypted", string(data))
}
`}, 2, gosec.NewConfig()},
}
)