blob: 555fb8072074fb25eacab49390897c220fca1da4 [file] [log] [blame]
David K. Bainbridgebd6b2882021-08-26 13:31:02 +00001package messages
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/jcmturner/gofork/encoding/asn1"
8 "github.com/jcmturner/gokrb5/v8/iana/asnAppTag"
9 "github.com/jcmturner/gokrb5/v8/iana/msgtype"
10 "github.com/jcmturner/gokrb5/v8/krberror"
11 "github.com/jcmturner/gokrb5/v8/types"
12)
13
14// APRep implements RFC 4120 KRB_AP_REP: https://tools.ietf.org/html/rfc4120#section-5.5.2.
15type APRep struct {
16 PVNO int `asn1:"explicit,tag:0"`
17 MsgType int `asn1:"explicit,tag:1"`
18 EncPart types.EncryptedData `asn1:"explicit,tag:2"`
19}
20
21// EncAPRepPart is the encrypted part of KRB_AP_REP.
22type EncAPRepPart struct {
23 CTime time.Time `asn1:"generalized,explicit,tag:0"`
24 Cusec int `asn1:"explicit,tag:1"`
25 Subkey types.EncryptionKey `asn1:"optional,explicit,tag:2"`
26 SequenceNumber int64 `asn1:"optional,explicit,tag:3"`
27}
28
29// Unmarshal bytes b into the APRep struct.
30func (a *APRep) Unmarshal(b []byte) error {
31 _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.APREP))
32 if err != nil {
33 return processUnmarshalReplyError(b, err)
34 }
35 expectedMsgType := msgtype.KRB_AP_REP
36 if a.MsgType != expectedMsgType {
37 return krberror.NewErrorf(krberror.KRBMsgError, "message ID does not indicate a KRB_AP_REP. Expected: %v; Actual: %v", expectedMsgType, a.MsgType)
38 }
39 return nil
40}
41
42// Unmarshal bytes b into the APRep encrypted part struct.
43func (a *EncAPRepPart) Unmarshal(b []byte) error {
44 _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.EncAPRepPart))
45 if err != nil {
46 return krberror.Errorf(err, krberror.EncodingError, "AP_REP unmarshal error")
47 }
48 return nil
49}