longRunningClient.go 1.7 KB

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