Jelajahi Sumber

doco comments

Jonathan Turner 9 tahun lalu
induk
melakukan
b177ae11aa

+ 1 - 1
asn1tools/tools.go

@@ -1,7 +1,7 @@
 package asn1tools
 package asn1tools
 
 
 
 
-// Get the ASN1 encoded bytes for the length 'l'.
+// Get the ASN1 encoded bytes for the length 'l'
 // There are two forms: short (for lengths between 0 and 127), and long definite (for lengths between 0 and 2^1008 -1).
 // There are two forms: short (for lengths between 0 and 127), and long definite (for lengths between 0 and 2^1008 -1).
 // Short form: One octet. Bit 8 has value "0" and bits 7-1 give the length.
 // Short form: One octet. Bit 8 has value "0" and bits 7-1 give the length.
 // Long form: Two to 127 octets. Bit 8 of first octet has value "1" and bits 7-1 give the number of additional length octets. Second and following octets give the length, base 256, most significant digit first.
 // Long form: Two to 127 octets. Bit 8 of first octet has value "1" and bits 7-1 give the number of additional length octets. Second and following octets give the length, base 256, most significant digit first.

+ 2 - 2
client/ASExchange.go

@@ -11,12 +11,12 @@ import (
 	"sort"
 	"sort"
 )
 )
 
 
-// Login the client with the KDC via an AS exchange
+// Login the client with the KDC via an AS exchange.
 func (cl *Client) Login() error {
 func (cl *Client) Login() error {
 	return cl.ASExchange()
 	return cl.ASExchange()
 }
 }
 
 
-// Perform an AS exchange for the client to retrieve a TGT
+// Perform an AS exchange for the client to retrieve a TGT.
 func (cl *Client) ASExchange() error {
 func (cl *Client) ASExchange() error {
 	if !cl.IsConfigured() {
 	if !cl.IsConfigured() {
 		return errors.New("Client is not configured correctly.")
 		return errors.New("Client is not configured correctly.")

+ 1 - 1
client/TGSExchange.go

@@ -7,7 +7,7 @@ import (
 )
 )
 
 
 // Perform a TGS exchange to retrieve a ticket to the specified SPN.
 // Perform a TGS exchange to retrieve a ticket to the specified SPN.
-// The ticket retrieved is added to the client's cache
+// The ticket retrieved is added to the client's cache.
 func (cl *Client) TGSExchange(spn string) error {
 func (cl *Client) TGSExchange(spn string) error {
 	if cl.Session == nil {
 	if cl.Session == nil {
 		return errors.New("Error client does not have a session. Client needs to login first")
 		return errors.New("Error client does not have a session. Client needs to login first")

+ 7 - 7
client/cache.go

@@ -8,12 +8,12 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-// Client ticket cache
+// Client ticket cache.
 type Cache struct {
 type Cache struct {
 	Entries map[string]CacheEntry
 	Entries map[string]CacheEntry
 }
 }
 
 
-// Ticket cache entry
+// Ticket cache entry.
 type CacheEntry struct {
 type CacheEntry struct {
 	Ticket    types.Ticket
 	Ticket    types.Ticket
 	AuthTime  time.Time
 	AuthTime  time.Time
@@ -56,7 +56,7 @@ func (c *Cache) RenewEntry(spn string) error {
 	return fmt.Errorf("No entry for this SPN: %s", spn)
 	return fmt.Errorf("No entry for this SPN: %s", spn)
 }
 }
 
 
-// Add a ticket to the cache
+// Add a ticket to the cache.
 func (c *Cache) AddEntry(tkt types.Ticket, authTime, endTime, renewTill time.Time) {
 func (c *Cache) AddEntry(tkt types.Ticket, authTime, endTime, renewTill time.Time) {
 	(*c).Entries[strings.Join(tkt.SName.NameString, "/")] = CacheEntry{
 	(*c).Entries[strings.Join(tkt.SName.NameString, "/")] = CacheEntry{
 		Ticket:    tkt,
 		Ticket:    tkt,
@@ -66,22 +66,22 @@ func (c *Cache) AddEntry(tkt types.Ticket, authTime, endTime, renewTill time.Tim
 	}
 	}
 }
 }
 
 
-// Remove the cache entry for the defined SPN
+// Remove the cache entry for the defined SPN.
 func (c *Cache) RemoveEntry(spn string) {
 func (c *Cache) RemoveEntry(spn string) {
 	delete(c.Entries, spn)
 	delete(c.Entries, spn)
 }
 }
 
 
-// Enable background auto renew of the ticket for the specified SPN
+// Enable background auto renew of the ticket for the specified SPN.
 func (c *Cache) EnableAutoRenew(spn string) error {
 func (c *Cache) EnableAutoRenew(spn string) error {
 	return nil
 	return nil
 }
 }
 
 
-// Disable background auto renew of the ticket for the specified SPN
+// Disable background auto renew of the ticket for the specified SPN.
 func (c *Cache) DisableAutoRenew(spn string) error {
 func (c *Cache) DisableAutoRenew(spn string) error {
 	return nil
 	return nil
 }
 }
 
 
-// Renew the cache entry
+// Renew the cache entry.
 func (e *CacheEntry) Renew() error {
 func (e *CacheEntry) Renew() error {
 	if time.Now().After(e.RenewTill) {
 	if time.Now().After(e.RenewTill) {
 		return errors.New("Past renew till time. Cannot renew.")
 		return errors.New("Past renew till time. Cannot renew.")

+ 6 - 6
client/client.go

@@ -6,7 +6,7 @@ import (
 	"github.com/jcmturner/gokrb5/keytab"
 	"github.com/jcmturner/gokrb5/keytab"
 )
 )
 
 
-// Client struct
+// Client struct.
 type Client struct {
 type Client struct {
 	Credentials *credentials.Credentials
 	Credentials *credentials.Credentials
 	Config      *config.Config
 	Config      *config.Config
@@ -14,7 +14,7 @@ type Client struct {
 	Cache       *Cache
 	Cache       *Cache
 }
 }
 
 
-// Create a new client with a password credential
+// Create a new client with a password credential.
 func NewClientWithPassword(username, password string) Client {
 func NewClientWithPassword(username, password string) Client {
 	creds := credentials.NewCredentials(username)
 	creds := credentials.NewCredentials(username)
 	return Client{
 	return Client{
@@ -24,7 +24,7 @@ func NewClientWithPassword(username, password string) Client {
 	}
 	}
 }
 }
 
 
-// Create a new client with a keytab credential
+// Create a new client with a keytab credential.
 func NewClientWithKeytab(username string, kt keytab.Keytab) Client {
 func NewClientWithKeytab(username string, kt keytab.Keytab) Client {
 	creds := credentials.NewCredentials(username)
 	creds := credentials.NewCredentials(username)
 	return Client{
 	return Client{
@@ -34,13 +34,13 @@ func NewClientWithKeytab(username string, kt keytab.Keytab) Client {
 	}
 	}
 }
 }
 
 
-// Set the Kerberos configuration for the client
+// Set the Kerberos configuration for the client.
 func (cl *Client) WithConfig(cfg *config.Config) *Client {
 func (cl *Client) WithConfig(cfg *config.Config) *Client {
 	cl.Config = cfg
 	cl.Config = cfg
 	return cl
 	return cl
 }
 }
 
 
-// Load the Kerberos configuration for the client from file path specified
+// Load the Kerberos configuration for the client from file path specified.
 func (cl *Client) LoadConfig(cfgPath string) (*Client, error) {
 func (cl *Client) LoadConfig(cfgPath string) (*Client, error) {
 	cfg, err := config.Load(cfgPath)
 	cfg, err := config.Load(cfgPath)
 	if err != nil {
 	if err != nil {
@@ -50,7 +50,7 @@ func (cl *Client) LoadConfig(cfgPath string) (*Client, error) {
 	return cl, nil
 	return cl, nil
 }
 }
 
 
-// Has the client got sufficient values required
+// Has the client got sufficient values required.
 func (cl *Client) IsConfigured() bool {
 func (cl *Client) IsConfigured() bool {
 	if !cl.Credentials.HasPassword() && !cl.Credentials.HasKeytab() {
 	if !cl.Credentials.HasPassword() && !cl.Credentials.HasKeytab() {
 		return false
 		return false

+ 3 - 3
client/network.go

@@ -8,7 +8,7 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-// Send bytes to the KDC
+// Send bytes to the KDC.
 func (cl *Client) SendToKDC(b []byte) ([]byte, error) {
 func (cl *Client) SendToKDC(b []byte) ([]byte, error) {
 	var rb []byte
 	var rb []byte
 	var kdcs []string
 	var kdcs []string
@@ -68,7 +68,7 @@ func (cl *Client) SendToKDC(b []byte) ([]byte, error) {
 	return rb, nil
 	return rb, nil
 }
 }
 
 
-// Send the bytes to the KDC over UDP
+// Send the bytes to the KDC over UDP.
 func sendUDP(kdc string, b []byte) ([]byte, error) {
 func sendUDP(kdc string, b []byte) ([]byte, error) {
 	var r []byte
 	var r []byte
 	udpAddr, err := net.ResolveUDPAddr("udp", kdc)
 	udpAddr, err := net.ResolveUDPAddr("udp", kdc)
@@ -94,7 +94,7 @@ func sendUDP(kdc string, b []byte) ([]byte, error) {
 	return r, nil
 	return r, nil
 }
 }
 
 
-// Send the bytes to the KDC over TCP
+// Send the bytes to the KDC over TCP.
 func sendTCP(kdc string, b []byte) ([]byte, error) {
 func sendTCP(kdc string, b []byte) ([]byte, error) {
 	var r []byte
 	var r []byte
 	tcpAddr, err := net.ResolveTCPAddr("tcp", kdc)
 	tcpAddr, err := net.ResolveTCPAddr("tcp", kdc)

+ 1 - 1
client/session.go

@@ -5,7 +5,7 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-// Client session struct
+// Client session struct.
 type Session struct {
 type Session struct {
 	AuthTime             time.Time
 	AuthTime             time.Time
 	EndTime              time.Time
 	EndTime              time.Time

+ 20 - 20
config/krb5conf.go

@@ -1,3 +1,4 @@
+// Implements KRB5 client and service configuration as described at https://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html
 package config
 package config
 
 
 import (
 import (
@@ -16,9 +17,8 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-// Implements KRB5 client and service configuration as described at https://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html
 
 
-// Struct representing the KRB5 configuration
+// Struct representing the KRB5 configuration.
 type Config struct {
 type Config struct {
 	LibDefaults *LibDefaults
 	LibDefaults *LibDefaults
 	Realms      []Realm
 	Realms      []Realm
@@ -33,7 +33,7 @@ const (
 	WEAK_ETYPE_LIST = "des-cbc-crc des-cbc-md4 des-cbc-md5 des-cbc-raw des3-cbc-raw des-hmac-sha1 arcfour-hmac-exp rc4-hmac-exp arcfour-hmac-md5-exp des"
 	WEAK_ETYPE_LIST = "des-cbc-crc des-cbc-md4 des-cbc-md5 des-cbc-raw des3-cbc-raw des-hmac-sha1 arcfour-hmac-exp rc4-hmac-exp arcfour-hmac-md5-exp des"
 )
 )
 
 
-// Create a new config struct
+// Create a new config struct.
 func NewConfig() *Config {
 func NewConfig() *Config {
 	d := make(DomainRealm)
 	d := make(DomainRealm)
 	return &Config{
 	return &Config{
@@ -42,7 +42,7 @@ func NewConfig() *Config {
 	}
 	}
 }
 }
 
 
-// Struct representing the [libdefaults] section of the configuration
+// Struct representing the [libdefaults] section of the configuration.
 type LibDefaults struct {
 type LibDefaults struct {
 	Allow_weak_crypto bool //default false
 	Allow_weak_crypto bool //default false
 	// ap_req_checksum_type int //unlikely to support this
 	// ap_req_checksum_type int //unlikely to support this
@@ -83,7 +83,7 @@ type LibDefaults struct {
 	Verify_ap_req_nofail    bool          //default false
 	Verify_ap_req_nofail    bool          //default false
 }
 }
 
 
-// Create a new LibDefaults struct
+// Create a new LibDefaults struct.
 func newLibDefaults() *LibDefaults {
 func newLibDefaults() *LibDefaults {
 	usr, _ := user.Current()
 	usr, _ := user.Current()
 	opts := asn1.BitString{}
 	opts := asn1.BitString{}
@@ -111,7 +111,7 @@ func newLibDefaults() *LibDefaults {
 	}
 	}
 }
 }
 
 
-// Parse the lines of the [libdefaults] section of the configuration into the LibDefaults struct
+// Parse the lines of the [libdefaults] section of the configuration into the LibDefaults struct.
 func (l *LibDefaults) parseLines(lines []string) error {
 func (l *LibDefaults) parseLines(lines []string) error {
 	for _, line := range lines {
 	for _, line := range lines {
 		if !strings.Contains(line, "=") {
 		if !strings.Contains(line, "=") {
@@ -292,7 +292,7 @@ func (l *LibDefaults) parseLines(lines []string) error {
 	return nil
 	return nil
 }
 }
 
 
-// Struct representing an entry in the [realms] section of the configuration
+// Struct representing an entry in the [realms] section of the configuration.
 type Realm struct {
 type Realm struct {
 	Realm        string
 	Realm        string
 	Admin_server []string
 	Admin_server []string
@@ -304,7 +304,7 @@ type Realm struct {
 	Master_kdc     []string
 	Master_kdc     []string
 }
 }
 
 
-// Parse the lines of a [realms] entry into the Realm struct
+// Parse the lines of a [realms] entry into the Realm struct.
 func (r *Realm) parseLines(name string, lines []string) error {
 func (r *Realm) parseLines(name string, lines []string) error {
 	r.Realm = name
 	r.Realm = name
 	var admin_server_final bool
 	var admin_server_final bool
@@ -345,7 +345,7 @@ func (r *Realm) parseLines(name string, lines []string) error {
 	return nil
 	return nil
 }
 }
 
 
-// Parse the lines of the [realms] section of the configuration into an slice of Realm structs
+// Parse the lines of the [realms] section of the configuration into an slice of Realm structs.
 func parseRealms(lines []string) ([]Realm, error) {
 func parseRealms(lines []string) ([]Realm, error) {
 	var realms []Realm
 	var realms []Realm
 	start := -1
 	start := -1
@@ -377,10 +377,10 @@ func parseRealms(lines []string) ([]Realm, error) {
 	return realms, nil
 	return realms, nil
 }
 }
 
 
-// Mapping of domains to realms representing the [domain_realm] section of the configuration
+// Mapping of domains to realms representing the [domain_realm] section of the configuration.
 type DomainRealm map[string]string
 type DomainRealm map[string]string
 
 
-// Parse the lines of the [domain_realm] section of the configuration and add to the mapping
+// Parse the lines of the [domain_realm] section of the configuration and add to the mapping.
 func (d *DomainRealm) parseLines(lines []string) error {
 func (d *DomainRealm) parseLines(lines []string) error {
 	for _, line := range lines {
 	for _, line := range lines {
 		if !strings.Contains(line, "=") {
 		if !strings.Contains(line, "=") {
@@ -394,12 +394,12 @@ func (d *DomainRealm) parseLines(lines []string) error {
 	return nil
 	return nil
 }
 }
 
 
-// Add a domain to realm mapping
+// Add a domain to realm mapping.
 func (d *DomainRealm) addMapping(domain, realm string) {
 func (d *DomainRealm) addMapping(domain, realm string) {
 	(*d)[domain] = realm
 	(*d)[domain] = realm
 }
 }
 
 
-// Delete a domain to realm mapping
+// Delete a domain to realm mapping.
 func (d *DomainRealm) deleteMapping(domain, realm string) {
 func (d *DomainRealm) deleteMapping(domain, realm string) {
 	delete(*d, domain)
 	delete(*d, domain)
 }
 }
@@ -418,7 +418,7 @@ func (c *Config) ResolveRealm(domainName string) string {
 	return c.LibDefaults.Default_realm
 	return c.LibDefaults.Default_realm
 }
 }
 
 
-// Load the KRB5 configuration from the specified file path
+// Load the KRB5 configuration from the specified file path.
 func Load(cfgPath string) (*Config, error) {
 func Load(cfgPath string) (*Config, error) {
 	fh, err := os.Open(cfgPath)
 	fh, err := os.Open(cfgPath)
 	if err != nil {
 	if err != nil {
@@ -429,19 +429,19 @@ func Load(cfgPath string) (*Config, error) {
 	return NewConfigFromScanner(scanner)
 	return NewConfigFromScanner(scanner)
 }
 }
 
 
-// Create a new Config struct from a string
+// Create a new Config struct from a string.
 func NewConfigFromString(s string) (*Config, error) {
 func NewConfigFromString(s string) (*Config, error) {
 	reader := strings.NewReader(s)
 	reader := strings.NewReader(s)
 	return NewConfigFromReader(reader)
 	return NewConfigFromReader(reader)
 }
 }
 
 
-// Create a new Config struct from an io.Reader
+// Create a new Config struct from an io.Reader.
 func NewConfigFromReader(r io.Reader) (*Config, error) {
 func NewConfigFromReader(r io.Reader) (*Config, error) {
 	scanner := bufio.NewScanner(r)
 	scanner := bufio.NewScanner(r)
 	return NewConfigFromScanner(scanner)
 	return NewConfigFromScanner(scanner)
 }
 }
 
 
-// Create a new Config struct from a bufio.Scanner
+// Create a new Config struct from a bufio.Scanner.
 func NewConfigFromScanner(scanner *bufio.Scanner) (*Config, error) {
 func NewConfigFromScanner(scanner *bufio.Scanner) (*Config, error) {
 	c := NewConfig()
 	c := NewConfig()
 	sections := make(map[int]string)
 	sections := make(map[int]string)
@@ -505,7 +505,7 @@ func NewConfigFromScanner(scanner *bufio.Scanner) (*Config, error) {
 	return c, nil
 	return c, nil
 }
 }
 
 
-// Parse a space delimited list of ETypes into a list of EType numbers optionally filtering out weak ETypes
+// Parse a space delimited list of ETypes into a list of EType numbers optionally filtering out weak ETypes.
 func parseETypes(s []string, w bool) []int {
 func parseETypes(s []string, w bool) []int {
 	var eti []int
 	var eti []int
 	for _, et := range s {
 	for _, et := range s {
@@ -562,7 +562,7 @@ func parseDuration(s string) (time.Duration, error) {
 	return time.Duration(0), errors.New("Invalid time duration value")
 	return time.Duration(0), errors.New("Invalid time duration value")
 }
 }
 
 
-// Parse possible boolean values to golang bool
+// Parse possible boolean values to golang bool.
 func parseBoolean(s string) (bool, error) {
 func parseBoolean(s string) (bool, error) {
 	s = strings.Replace(s, " ", "", -1)
 	s = strings.Replace(s, " ", "", -1)
 	v, err := strconv.ParseBool(s)
 	v, err := strconv.ParseBool(s)
@@ -582,7 +582,7 @@ func parseBoolean(s string) (bool, error) {
 	return false, errors.New("Invalid boolean value")
 	return false, errors.New("Invalid boolean value")
 }
 }
 
 
-// Parse array of strings but stop if an asterisk is placed at the end of a line
+// Parse array of strings but stop if an asterisk is placed at the end of a line.
 func appendUntilFinal(s *[]string, value string, final *bool) {
 func appendUntilFinal(s *[]string, value string, final *bool) {
 	if *final {
 	if *final {
 		return
 		return

+ 5 - 5
credentials/credentials.go

@@ -11,7 +11,7 @@ type Credentials struct {
 	Password string
 	Password string
 }
 }
 
 
-// Create a new Credentials struct
+// Create a new Credentials struct.
 func NewCredentials(username string) Credentials {
 func NewCredentials(username string) Credentials {
 	return Credentials{
 	return Credentials{
 		Username: username,
 		Username: username,
@@ -19,19 +19,19 @@ func NewCredentials(username string) Credentials {
 	}
 	}
 }
 }
 
 
-// Set the Keytab in the Credentials struct
+// Set the Keytab in the Credentials struct.
 func (c *Credentials) WithKeytab(kt keytab.Keytab) *Credentials {
 func (c *Credentials) WithKeytab(kt keytab.Keytab) *Credentials {
 	c.Keytab = kt
 	c.Keytab = kt
 	return c
 	return c
 }
 }
 
 
-// Set the password in the Credentials struct
+// Set the password in the Credentials struct.
 func (c *Credentials) WithPassword(password string) *Credentials {
 func (c *Credentials) WithPassword(password string) *Credentials {
 	c.Password = password
 	c.Password = password
 	return c
 	return c
 }
 }
 
 
-// Query if the Credentials has a keytab defined
+// Query if the Credentials has a keytab defined.
 func (c *Credentials) HasKeytab() bool {
 func (c *Credentials) HasKeytab() bool {
 	if len(c.Keytab.Entries) > 0 {
 	if len(c.Keytab.Entries) > 0 {
 		return true
 		return true
@@ -39,7 +39,7 @@ func (c *Credentials) HasKeytab() bool {
 	return false
 	return false
 }
 }
 
 
-// Query if the Credentials has a password defined
+// Query if the Credentials has a password defined.
 func (c *Credentials) HasPassword() bool {
 func (c *Credentials) HasPassword() bool {
 	if c.Password != "" {
 	if c.Password != "" {
 		return true
 		return true