longRunningClient.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // +build examples
  2. package main
  3. import (
  4. "encoding/hex"
  5. "log"
  6. "os"
  7. "time"
  8. "github.com/jcmturner/gokrb5/v8/client"
  9. "github.com/jcmturner/gokrb5/v8/config"
  10. "github.com/jcmturner/gokrb5/v8/keytab"
  11. "github.com/jcmturner/gokrb5/v8/test/testdata"
  12. )
  13. const (
  14. kRB5CONF = `[libdefaults]
  15. default_realm = TEST.GOKRB5
  16. dns_lookup_realm = false
  17. dns_lookup_kdc = false
  18. ticket_lifetime = 24h
  19. forwardable = yes
  20. default_tkt_enctypes = aes256-cts-hmac-sha1-96
  21. default_tgs_enctypes = aes256-cts-hmac-sha1-96
  22. [realms]
  23. TEST.GOKRB5 = {
  24. kdc = 10.80.88.88:88
  25. admin_server = 10.80.88.88:749
  26. default_domain = test.gokrb5
  27. }
  28. [domain_realm]
  29. .test.gokrb5 = TEST.GOKRB5
  30. test.gokrb5 = TEST.GOKRB5
  31. `
  32. )
  33. func main() {
  34. l := log.New(os.Stderr, "GOKRB5 Client: ", log.LstdFlags)
  35. //defer profile.Start(profile.TraceProfile).Stop()
  36. // Load the keytab
  37. kb, _ := hex.DecodeString(testdata.TESTUSER2_KEYTAB)
  38. kt := keytab.New()
  39. err := kt.Unmarshal(kb)
  40. if err != nil {
  41. l.Fatalf("could not load client keytab: %v", err)
  42. }
  43. // Load the client krb5 config
  44. conf, err := config.NewFromString(kRB5CONF)
  45. if err != nil {
  46. l.Fatalf("could not load krb5.conf: %v", err)
  47. }
  48. addr := os.Getenv("TEST_KDC_ADDR")
  49. if addr != "" {
  50. conf.Realms[0].KDC = []string{addr + ":88"}
  51. }
  52. // Create the client with the keytab
  53. cl := client.NewWithKeytab("testuser2", "TEST.GOKRB5", kt, conf, client.Logger(l), client.DisablePAFXFAST(true))
  54. // Log in the client
  55. err = cl.Login()
  56. if err != nil {
  57. l.Fatalf("could not login client: %v", err)
  58. }
  59. for {
  60. _, _, err := cl.GetServiceTicket("HTTP/host.test.gokrb5")
  61. if err != nil {
  62. l.Printf("failed to get service ticket: %v\n", err)
  63. }
  64. time.Sleep(time.Minute * 5)
  65. }
  66. }