forked from jcmturner/gokrb5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credentials_info.go
86 lines (76 loc) · 2.45 KB
/
credentials_info.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
package pac
import (
"bytes"
"errors"
"fmt"
"gopkg.in/jcmturner/gokrb5.v7/crypto"
"gopkg.in/jcmturner/gokrb5.v7/iana/keyusage"
"gopkg.in/jcmturner/gokrb5.v7/types"
"gopkg.in/jcmturner/rpc.v1/mstypes"
"gopkg.in/jcmturner/rpc.v1/ndr"
)
// https://msdn.microsoft.com/en-us/library/cc237931.aspx
// CredentialsInfo implements https://msdn.microsoft.com/en-us/library/cc237953.aspx
type CredentialsInfo struct {
Version uint32 // A 32-bit unsigned integer in little-endian format that defines the version. MUST be 0x00000000.
EType uint32
PACCredentialDataEncrypted []byte // Key usage number for encryption: KERB_NON_KERB_SALT (16)
PACCredentialData CredentialData
}
// Unmarshal bytes into the CredentialsInfo struct
func (c *CredentialsInfo) Unmarshal(b []byte, k types.EncryptionKey) (err error) {
//The CredentialsInfo structure is a simple structure that is not NDR-encoded.
r := mstypes.NewReader(bytes.NewReader(b))
c.Version, err = r.Uint32()
if err != nil {
return
}
if c.Version != 0 {
err = errors.New("credentials info version is not zero")
return
}
c.EType, err = r.Uint32()
if err != nil {
return
}
c.PACCredentialDataEncrypted, err = r.ReadBytes(len(b) - 8)
if err != nil {
err = fmt.Errorf("error reading credentials info: %v", err)
return
}
err = c.DecryptEncPart(k)
if err != nil {
err = fmt.Errorf("error decrypting PAC Credentials Data: %v", err)
return
}
return
}
// DecryptEncPart decrypts the encrypted part of the CredentialsInfo.
func (c *CredentialsInfo) DecryptEncPart(k types.EncryptionKey) error {
if k.KeyType != int32(c.EType) {
return fmt.Errorf("key provided is not the correct type. Type needed: %d, type provided: %d", c.EType, k.KeyType)
}
pt, err := crypto.DecryptMessage(c.PACCredentialDataEncrypted, k, keyusage.KERB_NON_KERB_SALT)
if err != nil {
return err
}
err = c.PACCredentialData.Unmarshal(pt)
if err != nil {
return err
}
return nil
}
// CredentialData implements https://msdn.microsoft.com/en-us/library/cc237952.aspx
type CredentialData struct {
CredentialCount uint32
Credentials []SECPKGSupplementalCred // Size is the value of CredentialCount
}
// Unmarshal converts the bytes provided into a CredentialData type.
func (c *CredentialData) Unmarshal(b []byte) (err error) {
dec := ndr.NewDecoder(bytes.NewReader(b))
err = dec.Decode(c)
if err != nil {
err = fmt.Errorf("error unmarshaling KerbValidationInfo: %v", err)
}
return
}