forked from jcmturner/gokrb5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pac_type.go
204 lines (196 loc) · 5.66 KB
/
pac_type.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package pac
import (
"encoding/binary"
"errors"
"fmt"
"gopkg.in/jcmturner/gokrb5.v2/crypto"
"gopkg.in/jcmturner/gokrb5.v2/iana/keyusage"
"gopkg.in/jcmturner/gokrb5.v2/ndr"
"gopkg.in/jcmturner/gokrb5.v2/types"
)
// PACType implements: https://msdn.microsoft.com/en-us/library/cc237950.aspx
type PACType struct {
CBuffers uint32
Version uint32
Buffers []InfoBuffer
Data []byte
KerbValidationInfo *KerbValidationInfo
CredentialsInfo *CredentialsInfo
ServerChecksum *SignatureData
KDCChecksum *SignatureData
ClientInfo *ClientInfo
S4UDelegationInfo *S4UDelegationInfo
UPNDNSInfo *UPNDNSInfo
ClientClaimsInfo *ClientClaimsInfo
DeviceInfo *DeviceInfo
DeviceClaimsInfo *DeviceClaimsInfo
ZeroSigData []byte
}
// Unmarshal bytes into the PACType struct
func (pac *PACType) Unmarshal(b []byte) error {
var p int
var e binary.ByteOrder = binary.LittleEndian
pac.Data = b
zb := make([]byte, len(b), len(b))
copy(zb, b)
pac.ZeroSigData = zb
pac.CBuffers = ndr.ReadUint32(&b, &p, &e)
pac.Version = ndr.ReadUint32(&b, &p, &e)
buf := make([]InfoBuffer, pac.CBuffers, pac.CBuffers)
for i := range buf {
buf[i] = ReadPACInfoBuffer(&b, &p, &e)
}
pac.Buffers = buf
return nil
}
// ProcessPACInfoBuffers processes the PAC Info Buffers.
// https://msdn.microsoft.com/en-us/library/cc237954.aspx
func (pac *PACType) ProcessPACInfoBuffers(key types.EncryptionKey) error {
for _, buf := range pac.Buffers {
p := make([]byte, buf.CBBufferSize, buf.CBBufferSize)
copy(p, pac.Data[int(buf.Offset):int(buf.Offset)+int(buf.CBBufferSize)])
switch int(buf.ULType) {
case ulTypeKerbValidationInfo:
if pac.KerbValidationInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k KerbValidationInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing KerbValidationInfo: %v", err)
}
pac.KerbValidationInfo = &k
case ulTypeCredentials:
if pac.CredentialsInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k CredentialsInfo
err := k.Unmarshal(p, key)
if err != nil {
return fmt.Errorf("Error processing CredentialsInfo: %v", err)
}
pac.CredentialsInfo = &k
case ulTypePACServerSignatureData:
if pac.ServerChecksum != nil {
//Must ignore subsequent buffers of this type
continue
}
var k SignatureData
zb, err := k.Unmarshal(p)
copy(pac.ZeroSigData[int(buf.Offset):int(buf.Offset)+int(buf.CBBufferSize)], zb)
if err != nil {
return fmt.Errorf("Error processing ServerChecksum: %v", err)
}
pac.ServerChecksum = &k
case ulTypePACKDCSignatureData:
if pac.KDCChecksum != nil {
//Must ignore subsequent buffers of this type
continue
}
var k SignatureData
zb, err := k.Unmarshal(p)
copy(pac.ZeroSigData[int(buf.Offset):int(buf.Offset)+int(buf.CBBufferSize)], zb)
if err != nil {
return fmt.Errorf("Error processing KDCChecksum: %v", err)
}
pac.KDCChecksum = &k
case ulTypePACClientInfo:
if pac.ClientInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k ClientInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing ClientInfo: %v", err)
}
pac.ClientInfo = &k
case ulTypeS4UDelegationInfo:
if pac.S4UDelegationInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k S4UDelegationInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing S4U_DelegationInfo: %v", err)
}
pac.S4UDelegationInfo = &k
case ulTypeUPNDNSInfo:
if pac.UPNDNSInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k UPNDNSInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing UPN_DNSInfo: %v", err)
}
pac.UPNDNSInfo = &k
case ulTypePACClientClaimsInfo:
if pac.ClientClaimsInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k ClientClaimsInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing ClientClaimsInfo: %v", err)
}
pac.ClientClaimsInfo = &k
case ulTypePACDeviceInfo:
if pac.DeviceInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k DeviceInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing DeviceInfo: %v", err)
}
pac.DeviceInfo = &k
case ulTypePACDeviceClaimsInfo:
if pac.DeviceClaimsInfo != nil {
//Must ignore subsequent buffers of this type
continue
}
var k DeviceClaimsInfo
err := k.Unmarshal(p)
if err != nil {
return fmt.Errorf("Error processing DeviceClaimsInfo: %v", err)
}
pac.DeviceClaimsInfo = &k
}
}
if ok, err := pac.validate(key); !ok {
return err
}
return nil
}
func (pac *PACType) validate(key types.EncryptionKey) (bool, error) {
if pac.KerbValidationInfo == nil {
return false, errors.New("PAC Info Buffers does not contain a KerbValidationInfo")
}
if pac.ServerChecksum == nil {
return false, errors.New("PAC Info Buffers does not contain a ServerChecksum")
}
if pac.KDCChecksum == nil {
return false, errors.New("PAC Info Buffers does not contain a KDCChecksum")
}
if pac.ClientInfo == nil {
return false, errors.New("PAC Info Buffers does not contain a ClientInfo")
}
etype, err := crypto.GetChksumEtype(int(pac.ServerChecksum.SignatureType))
if err != nil {
return false, err
}
if ok := etype.VerifyChecksum(key.KeyValue,
pac.ZeroSigData,
pac.ServerChecksum.Signature,
keyusage.KERB_NON_KERB_CKSUM_SALT); !ok {
return false, errors.New("PAC service checksum verification failed")
}
return true, nil
}