blob: 9c244f074ecedfd46e4edc2938e64ed2317b4f89 [file] [log] [blame]
Scott Baker8461e152019-10-01 14:44:30 -07001package messages
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/jcmturner/gofork/encoding/asn1"
8 "gopkg.in/jcmturner/gokrb5.v7/iana/asnAppTag"
9 "gopkg.in/jcmturner/gokrb5.v7/iana/msgtype"
10 "gopkg.in/jcmturner/gokrb5.v7/krberror"
11 "gopkg.in/jcmturner/gokrb5.v7/types"
12)
13
14/*
15AP-REP ::= [APPLICATION 15] SEQUENCE {
16pvno [0] INTEGER (5),
17msg-type [1] INTEGER (15),
18enc-part [2] EncryptedData -- EncAPRepPart
19}
20
21EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
22 ctime [0] KerberosTime,
23 cusec [1] Microseconds,
24 subkey [2] EncryptionKey OPTIONAL,
25 seq-number [3] UInt32 OPTIONAL
26}
27*/
28
29// APRep implements RFC 4120 KRB_AP_REP: https://tools.ietf.org/html/rfc4120#section-5.5.2.
30type APRep struct {
31 PVNO int `asn1:"explicit,tag:0"`
32 MsgType int `asn1:"explicit,tag:1"`
33 EncPart types.EncryptedData `asn1:"explicit,tag:2"`
34}
35
36// EncAPRepPart is the encrypted part of KRB_AP_REP.
37type EncAPRepPart struct {
38 CTime time.Time `asn1:"generalized,explicit,tag:0"`
39 Cusec int `asn1:"explicit,tag:1"`
40 Subkey types.EncryptionKey `asn1:"optional,explicit,tag:2"`
41 SequenceNumber int64 `asn1:"optional,explicit,tag:3"`
42}
43
44// Unmarshal bytes b into the APRep struct.
45func (a *APRep) Unmarshal(b []byte) error {
46 _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.APREP))
47 if err != nil {
48 return processUnmarshalReplyError(b, err)
49 }
50 expectedMsgType := msgtype.KRB_AP_REP
51 if a.MsgType != expectedMsgType {
52 return krberror.NewErrorf(krberror.KRBMsgError, "message ID does not indicate a KRB_AP_REP. Expected: %v; Actual: %v", expectedMsgType, a.MsgType)
53 }
54 return nil
55}
56
57// Unmarshal bytes b into the APRep encrypted part struct.
58func (a *EncAPRepPart) Unmarshal(b []byte) error {
59 _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.EncAPRepPart))
60 if err != nil {
61 return krberror.Errorf(err, krberror.EncodingError, "AP_REP unmarshal error")
62 }
63 return nil
64}