-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfc8489_test.go
79 lines (72 loc) · 2.59 KB
/
rfc8489_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
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
package stun
import (
"bytes"
"testing"
)
func TestRFC8489TestVectorB1_Errata(t *testing.T) {
const username = "\u30DE\u30C8\u30EA\u30C3\u30AF\u30B9"
const realm = "example.org"
const password = "TheMatrIX"
// nonce has the security features prefix and encoded security features removed
// as these will be specified separately and prefixed onto the nonce value.
const nonce = "f//499k954d6OL34oL9FSTvy64sA"
txID := TxID{0x78, 0xad, 0x34, 0x33,
0xc6, 0xad, 0x72, 0xc0,
0x29, 0xda, 0x41, 0x2e}
expected := []byte{
0x00, 0x01, 0x00, 0x90, // Request type and message length
0x21, 0x12, 0xa4, 0x42, // Magic cookie
0x78, 0xad, 0x34, 0x33, // }
0xc6, 0xad, 0x72, 0xc0, // } Transaction ID
0x29, 0xda, 0x41, 0x2e, // }
0x00, 0x1e, 0x00, 0x20, // USERHASH attribute header
0x4a, 0x3c, 0xf3, 0x8f, // }
0xef, 0x69, 0x92, 0xbd, // }
0xa9, 0x52, 0xc6, 0x78, // }
0x04, 0x17, 0xda, 0x0f, // } Userhash value (0x32, bytes)
0x24, 0x81, 0x94, 0x15, // }
0x56, 0x9e, 0x60, 0xb2, // }
0x05, 0xc4, 0x6e, 0x41, // }
0x40, 0x7f, 0x17, 0x04, // }
0x00, 0x15, 0x00, 0x29, // NONCE attribute header
0x6f, 0x62, 0x4d, 0x61, // }
0x74, 0x4a, 0x6f, 0x73, // }
0x32, 0x41, 0x41, 0x41, // }
0x43, 0x66, 0x2f, 0x2f, // }
0x34, 0x39, 0x39, 0x6b, // } Nonce value and padding (3 bytes)
0x39, 0x35, 0x34, 0x64, // }
0x36, 0x4f, 0x4c, 0x33, // }
0x34, 0x6f, 0x4c, 0x39, // }
0x46, 0x53, 0x54, 0x76, // }
0x79, 0x36, 0x34, 0x73, // }
0x41, 0x00, 0x00, 0x00, // }
0x00, 0x14, 0x00, 0x0b, // REALM attribute header
0x65, 0x78, 0x61, 0x6d, // }
0x70, 0x6c, 0x65, 0x2e, // } Realm value (0x11, bytes) and padding (1 byte)
0x6f, 0x72, 0x67, 0x00, // }
0x00, 0x1d, 0x00, 0x04, // PASSWORD-ALGORITHM attribute header
0x00, 0x02, 0x00, 0x00, // PASSWORD-ALGORITHM value, SHA-256 (0x0002), and parameters length, 0.
0x00, 0x1c, 0x00, 0x20, // MESSAGE-INTEGRITY-SHA256 attribute header
0xb5, 0xc7, 0xbf, 0x00, // }
0x5b, 0x6c, 0x52, 0xa2, // }
0x1c, 0x51, 0xc5, 0xe8, // }
0x92, 0xf8, 0x19, 0x24, // } HMAC-SHA256 value
0x13, 0x62, 0x96, 0xcb, // }
0x92, 0x7c, 0x43, 0x14, // }
0x93, 0x09, 0x27, 0x8c, // }
0xc6, 0x51, 0x8e, 0x65, // }
}
b := New(TypeBindingRequest, txID)
b.SetUserHash(username, realm)
b.SetNonceWithSecurityFeatures(FeatureUserAnonyminity, []byte(nonce))
b.SetRealm(realm)
b.SetKeyLongTerm(PasswordAlgorithmSHA256, username, realm, password)
b.AddMessageIntegritySHA256()
raw, err := b.Build()
if err != nil {
t.Fatalf("failed to build: %v", err)
}
if !bytes.Equal(raw, expected) {
t.Fatal("build generate different output")
}
}