@@ -8,9 +8,47 @@ import (
8
8
"github.com/jcmturner/gokrb5/v8/iana"
9
9
"github.com/jcmturner/gokrb5/v8/iana/msgtype"
10
10
"github.com/jcmturner/gokrb5/v8/test/testdata"
11
+ "github.com/jcmturner/gokrb5/v8/types"
11
12
"github.com/stretchr/testify/assert"
12
13
)
13
14
15
+ // Sample data from MIT Kerberos v1.19.1
16
+
17
+ // from src/tests/asn.1/ktest.h
18
+ const (
19
+ SAMPLE_USEC = 123456
20
+ SAMPLE_SEQ_NUMBER = 17
21
+ SAMPLE_NONCE = 42
22
+ SAMPLE_FLAGS = 0xFEDCBA98
23
+ SAMPLE_ERROR = 0x3C
24
+ )
25
+
26
+ func ktest_make_sample_ap_rep_enc_part () * EncAPRepPart {
27
+ tm , _ := time .Parse (testdata .TEST_TIME_FORMAT , testdata .TEST_TIME )
28
+ return & EncAPRepPart {
29
+ CTime : tm ,
30
+ Cusec : SAMPLE_USEC ,
31
+ Subkey : * ktest_make_sample_keyblock (),
32
+ SequenceNumber : SAMPLE_SEQ_NUMBER ,
33
+ }
34
+ }
35
+
36
+ func ktest_make_sample_keyblock () * types.EncryptionKey {
37
+ kv := []byte ("12345678" )
38
+ return & types.EncryptionKey {
39
+ KeyType : 1 ,
40
+ KeyValue : kv ,
41
+ }
42
+ }
43
+
44
+ func ktest_make_sample_enc_data () * types.EncryptedData {
45
+ return & types.EncryptedData {
46
+ EType : 0 ,
47
+ KVNO : 5 ,
48
+ Cipher : []byte ("krbASN.1 test message" ),
49
+ }
50
+ }
51
+
14
52
func TestUnmarshalAPRep (t * testing.T ) {
15
53
t .Parallel ()
16
54
var a APRep
@@ -67,3 +105,50 @@ func TestUnmarshalEncAPRepPart_optionalsNULL(t *testing.T) {
67
105
assert .Equal (t , tt , a .CTime , "CTime not as expected" )
68
106
assert .Equal (t , 123456 , a .Cusec , "Client microseconds not as expected" )
69
107
}
108
+
109
+ // test with all fields populated
110
+ func TestAPRepEncPartMarshall (t * testing.T ) {
111
+ t .Parallel ()
112
+
113
+ want , err := hex .DecodeString (testdata .MarshaledKRB5ap_rep_enc_part )
114
+ assert .Nil (t , err , "error not expected decoding test data" )
115
+
116
+ encpart := ktest_make_sample_ap_rep_enc_part ()
117
+
118
+ b , err := encpart .Marshal ()
119
+ assert .Nil (t , err , "enc part marshal error not expected" )
120
+ assert .Equal (t , want , b )
121
+ }
122
+
123
+ // test with the optionals not present
124
+ func TestAPRepEncPartMarshall_optionalsNULL (t * testing.T ) {
125
+ t .Parallel ()
126
+
127
+ want , err := hex .DecodeString (testdata .MarshaledKRB5ap_rep_enc_partOptionalsNULL )
128
+ assert .Nil (t , err , "error not expected decoding test data" )
129
+
130
+ encpart := ktest_make_sample_ap_rep_enc_part ()
131
+ encpart .SequenceNumber = 0
132
+ encpart .Subkey = types.EncryptionKey {}
133
+
134
+ b , err := encpart .Marshal ()
135
+ assert .Nil (t , err , "enc part marshal error not expected" )
136
+ assert .Equal (t , want , b )
137
+ }
138
+
139
+ func TestAprepMarshal (t * testing.T ) {
140
+ t .Parallel ()
141
+
142
+ want , err := hex .DecodeString (testdata .MarshaledKRB5ap_rep )
143
+ assert .Nil (t , err , "error not expected decoding test data" )
144
+
145
+ aprep := APRep {
146
+ PVNO : iana .PVNO ,
147
+ MsgType : msgtype .KRB_AP_REP ,
148
+ EncPart : * ktest_make_sample_enc_data (),
149
+ }
150
+
151
+ b , err := aprep .Marshal ()
152
+ assert .Nil (t , err , "enc part marshal error not expected" )
153
+ assert .Equal (t , want , b )
154
+ }
0 commit comments