forked from hirochachacha/go-smb2
-
Notifications
You must be signed in to change notification settings - Fork 4
/
sign_test.go
52 lines (40 loc) · 1.04 KB
/
sign_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
49
50
51
52
package smb2
import (
"bytes"
"crypto/aes"
"encoding/hex"
"github.com/LeakIX/go-smb2/lib/crypto/cmac"
. "github.com/LeakIX/go-smb2/lib/smb2"
"testing"
)
func TestSign(t *testing.T) {
sessionKey, err := hex.DecodeString("726d4c454e63516446695457664e5042")
if err != nil {
t.Fatal(err)
}
pkt, err := hex.DecodeString("fe534d42400001000000000001007f00090000000000000003000000000000000000000000000000020000007bfba3f4041393e756a048c9092c4e52dc7037190900000048000900a1073005a0030a0100")
if err != nil {
t.Fatal(err)
}
signature, err := hex.DecodeString("041393e756a048c9092c4e52dc703719")
if err != nil {
t.Fatal(err)
}
signingKey := kdf(sessionKey, []byte("SMB2AESCMAC\x00"), []byte("SmbSign\x00"))
ciph, err := aes.NewCipher(signingKey)
if err != nil {
t.Fatal(err)
}
signer := cmac.New(ciph)
p := PacketCodec(pkt)
if !bytes.Equal(p.Signature(), signature) {
t.Error("fail")
}
p.SetSignature(zero[:])
signer.Reset()
signer.Write(pkt)
signer.Sum(pkt[:48])
if !bytes.Equal(p.Signature(), signature) {
t.Error("fail")
}
}