From 0e5077d427dc144ab70f208a4794a903d5e8a5a8 Mon Sep 17 00:00:00 2001 From: Aria Date: Sun, 1 Oct 2023 23:41:37 +0100 Subject: a working version with principal creation --- client/messages.go | 69 ------------------------------------------------------ 1 file changed, 69 deletions(-) delete mode 100644 client/messages.go (limited to 'client/messages.go') diff --git a/client/messages.go b/client/messages.go deleted file mode 100644 index b3d2c4f..0000000 --- a/client/messages.go +++ /dev/null @@ -1,69 +0,0 @@ -package client - -import ( - "github.com/jcmturner/gokrb5/v8/crypto" - "github.com/jcmturner/gokrb5/v8/kadmin" - "github.com/jcmturner/gokrb5/v8/krberror" - "github.com/jcmturner/gokrb5/v8/messages" - "github.com/jcmturner/gokrb5/v8/types" -) - -// ChangePasswdMsg generate a change password request and also return the key needed to decrypt the reply. -func ChangePasswdMsg(targetName types.PrincipalName, cname types.PrincipalName, realm, password string, tkt messages.Ticket, sessionKey types.EncryptionKey) (r kadmin.Request, k types.EncryptionKey, err error) { - // Create change password data struct and marshal to bytes - chgpasswd := kadmin.ChangePasswdData{ - NewPasswd: []byte(password), - TargName: targetName, - TargRealm: realm, - } - chpwdb, err := chgpasswd.Marshal() - if err != nil { - err = krberror.Errorf(err, krberror.KRBMsgError, "error marshaling change passwd data") - return - } - - // Generate authenticator - auth, err := types.NewAuthenticator(realm, cname) - if err != nil { - err = krberror.Errorf(err, krberror.KRBMsgError, "error generating new authenticator") - return - } - etype, err := crypto.GetEtype(sessionKey.KeyType) - if err != nil { - err = krberror.Errorf(err, krberror.KRBMsgError, "error generating subkey etype") - return - } - err = auth.GenerateSeqNumberAndSubKey(etype.GetETypeID(), etype.GetKeyByteSize()) - if err != nil { - err = krberror.Errorf(err, krberror.KRBMsgError, "error generating subkey") - return - } - k = auth.SubKey - - // Generate AP_REQ - APreq, err := messages.NewAPReq(tkt, sessionKey, auth) - if err != nil { - return - } - - // Form the KRBPriv encpart data - kp := messages.EncKrbPrivPart{ - UserData: chpwdb, - Timestamp: auth.CTime, - Usec: auth.Cusec, - SequenceNumber: auth.SeqNumber, - } - kpriv := messages.NewKRBPriv(kp) - - err = kpriv.EncryptEncPart(k) - if err != nil { - err = krberror.Errorf(err, krberror.EncryptingError, "error encrypting change passwd data") - return - } - - r = kadmin.Request{ - APREQ: APreq, - KRBPriv: kpriv, - } - return -} -- cgit v1.2.3