Переглянути джерело

code tidy and readme update

Jonathan Turner 8 роки тому
батько
коміт
122b0ce910
3 змінених файлів з 43 додано та 14 видалено
  1. 38 0
      README.md
  2. 1 6
      client/TGSExchange.go
  3. 4 8
      credentials/credentials.go

+ 38 - 0
README.md

@@ -19,6 +19,7 @@ import "gopkg.in/jcmturner/gokrb5.v4/<sub package>"
   * HTTP handler wrapper decodes Microsoft AD PAC authorization data
 * Client Side
   * Client that can authenticate to an SPNEGO Kerberos authenticated web service
+  * Ability to change client's password
 * General
   * Kerberos libraries for custom integration
   * Parsing Keytab files
@@ -144,6 +145,43 @@ APReq, err := messages.NewAPReq(tkt, key, auth)
 
 Now send the AP_REQ to the service. How this is done will be specific to the application use case.
 
+#### Changing a Client Password
+This feature uses the Microsoft Kerberos Password Change protocol (RFC 3244). 
+This is implemented in Microsoft Active Directory and in MIT krb5kdc as of version 1.7.
+Typically the kpasswd server listens on port 464.
+
+Below is example code for how to use this feature:
+```go
+cfg, err := config.Load("/path/to/config/file")
+if err != nil {
+	panic(err.Error())
+}
+kt, err := keytab.Load("/path/to/file.keytab")
+if err != nil {
+	panic(err.Error())
+}
+cl := client.NewClientWithKeytab("username", "REALM.COM", kt)
+cl.WithConfig(cfg)
+
+ok, err := cl.ChangePasswd("newpassword")
+if err != nil {
+	panic(err.Error())
+}
+if !ok {
+	panic("failed to change password")
+}
+```
+
+The client kerberos config (krb5.conf) will need to have either the kpassd_server or admin_server defined in the relevant [realms] section.
+For example:
+```
+REALM.COM = {
+  kdc = 127.0.0.1:88
+  kpasswd_server = 127.0.0.1:464
+  default_domain = realm.com
+ }
+```
+See https://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html#realms for more information.
 
 ---
 

+ 1 - 6
client/TGSExchange.go

@@ -1,7 +1,6 @@
 package client
 
 import (
-	"strings"
 	"time"
 
 	"gopkg.in/jcmturner/gokrb5.v4/iana/nametype"
@@ -69,11 +68,7 @@ func (cl *Client) GetServiceTicket(spn string) (messages.Ticket, types.Encryptio
 		// Already a valid ticket in the cache
 		return tkt, skey, nil
 	}
-	s := strings.Split(spn, "/")
-	princ := types.PrincipalName{
-		NameType:   nametype.KRB_NT_PRINCIPAL,
-		NameString: s,
-	}
+	princ := types.NewPrincipalName(nametype.KRB_NT_PRINCIPAL, spn)
 	sess, err := cl.GetSessionFromPrincipalName(princ)
 	if err != nil {
 		return tkt, skey, err

+ 4 - 8
credentials/credentials.go

@@ -6,7 +6,6 @@ import (
 	"gopkg.in/jcmturner/gokrb5.v4/iana/nametype"
 	"gopkg.in/jcmturner/gokrb5.v4/keytab"
 	"gopkg.in/jcmturner/gokrb5.v4/types"
-	"strings"
 	"time"
 )
 
@@ -58,13 +57,10 @@ func NewCredentials(username string, realm string) Credentials {
 		Username:    username,
 		displayName: username,
 		Realm:       realm,
-		CName: types.PrincipalName{
-			NameType:   nametype.KRB_NT_PRINCIPAL,
-			NameString: strings.Split(username, "/"),
-		},
-		Keytab:     keytab.NewKeytab(),
-		Attributes: make(map[int]interface{}),
-		sessionID:  uid,
+		CName:       types.NewPrincipalName(nametype.KRB_NT_PRINCIPAL, username),
+		Keytab:      keytab.NewKeytab(),
+		Attributes:  make(map[int]interface{}),
+		sessionID:   uid,
 	}
 }