gssapi

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2023 License: BSD-3-Clause Imports: 32 Imported by: 1

README

GitHub release Build Status Coverage Status Go Report Card GoDoc Go version Go version

GSSAPI wrapper for gokrb5

The github.com/bodgit/gssapi package implements a GSSAPI-like wrapper around the github.com/jcmturner/gokrb5 package.

Sample Initiator (Client):

package main

import (
	. "github.com/bodgit/gssapi"
	"github.com/jcmturner/gokrb5/v8/gssapi"
)

func main() {
	initiator, err := NewInitiator(WithRealm("EXAMPLE.COM"), WithUsername("test"), WithKeytab[Initiator]("test.keytab"))
	if err != nil {
		panic(err)
	}

	defer initiator.Close()

	output, cont, err := initiator.Initiate("host/ssh.example.com", gssapi.ContextFlagInteg|gssapi.ContextFlagMutual, nil)
	if err != nil {
		panic(err)
	}

	// transmit output to Acceptor

	signature, err := initiator.MakeSignature(message)
	if err != nil {
		panic(err)
	}

	// transmit message and signature to Acceptor
}

Sample Acceptor (Server):

package main

import (
	. "github.com/bodgit/gssapi"
	"github.com/jcmturner/gokrb5/v8/gssapi"
	"github.com/jcmturner/gokrb5/v8/iana/nametype"
	"github.com/jcmturner/gokrb5/v8/types"
)

func main() {
	principal := types.NewPrincipalName(nametype.KRB_NT_SRV_HST, "host/ssh.example.com")

	acceptor, err := NewAcceptor(WithServicePrincipal(&principal))
	if err != nil {
		panic(err)
	}

	defer acceptor.Close()

	// receive input from Initiator

	output, cont, err := acceptor.Accept(input)
	if err != nil {
		panic(err)
	}

	// transmit output back to Initiator

	// receive message and signature from Initiator

	if err := acceptor.VerifySignature(message, signature); err != nil {
		panic(err)
	}
}

Documentation

Overview

Package gssapi implements a simplified wrapper around the github.com/jcmturner/gokrb5 package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acceptor

type Acceptor struct {
	// contains filtered or unexported fields
}

Acceptor represents the server side of the GSSAPI protocol.

func NewAcceptor

func NewAcceptor(options ...Option[Acceptor]) (*Acceptor, error)

NewAcceptor returns a new Acceptor.

func (*Acceptor) Accept

func (ctx *Acceptor) Accept(input []byte) ([]byte, bool, error)

Accept responds to the token from the Initiator, returning a token to be sent back to the Initiator and whether another round is required.

func (*Acceptor) Close

func (ctx *Acceptor) Close() error

Close releases any resources held by the Acceptor.

func (*Acceptor) Established added in v0.0.2

func (ctx *Acceptor) Established() bool

Established returns the context state.

func (*Acceptor) Expiry added in v0.0.2

func (ctx *Acceptor) Expiry() time.Time

Expiry returns the ticket expiry for the context.

func (*Acceptor) MakeSignature

func (ctx *Acceptor) MakeSignature(message []byte) ([]byte, error)

MakeSignature creates a MIC token against the provided input.

func (*Acceptor) PeerName

func (ctx *Acceptor) PeerName() string

PeerName returns the peer Kerberos principal.

func (*Acceptor) VerifySignature

func (ctx *Acceptor) VerifySignature(message, signature []byte) error

VerifySignature verifies the MIC token against the provided input.

type Initiator

type Initiator struct {
	// contains filtered or unexported fields
}

Initiator represents the client side of the GSSAPI protocol.

func NewInitiator

func NewInitiator(options ...Option[Initiator]) (*Initiator, error)

NewInitiator returns a new Initiator.

func (*Initiator) Close

func (ctx *Initiator) Close() error

Close releases any resources held by the Initiator.

func (*Initiator) Established added in v0.0.2

func (ctx *Initiator) Established() bool

Established returns the context state.

func (*Initiator) Expiry added in v0.0.2

func (ctx *Initiator) Expiry() time.Time

Expiry returns the ticket expiry for the context.

func (*Initiator) Initiate

func (ctx *Initiator) Initiate(service string, flags int, input []byte) ([]byte, bool, error)

Initiate creates a new context targeting the service with the desired flags along with the initial input token, which will initially be nil. The output token is returned and whether another round is required.

func (*Initiator) MakeSignature

func (ctx *Initiator) MakeSignature(message []byte) ([]byte, error)

MakeSignature creates a MIC token against the provided input.

func (*Initiator) PeerName

func (ctx *Initiator) PeerName() string

PeerName returns the peer Kerberos principal.

func (*Initiator) VerifySignature

func (ctx *Initiator) VerifySignature(message, signature []byte) error

VerifySignature verifies the MIC token against the provided input.

type Option

type Option[T Initiator | Acceptor] func(*T) error

Option is the signature for all constructor options.

func WithClockSkew

func WithClockSkew[T Acceptor](clockSkew time.Duration) Option[T]

WithClockSkew sets the permitted amount of clock skew allowed between the Initiator and Acceptor.

func WithConfig

func WithConfig[T Initiator](config string) Option[T]

WithConfig permits passing krb5.conf contents directly to an Initiator.

func WithDomain

func WithDomain[T Initiator](domain string) Option[T]

WithDomain sets the Kerberos domain in the Initiator.

func WithKeytab

func WithKeytab[T Initiator | Acceptor](keytab string) Option[T]

WithKeytab sets the keytab path in either an Initiator or Acceptor.

func WithLogger

func WithLogger[T Initiator | Acceptor](logger logr.Logger) Option[T]

WithLogger configures a logr.Logger in either an Initiator or Acceptor.

func WithPassword

func WithPassword[T Initiator](password string) Option[T]

WithPassword sets the password in the Initiator.

func WithRealm

func WithRealm[T Initiator](realm string) Option[T]

WithRealm is an alias for WithDomain.

func WithServicePrincipal

func WithServicePrincipal[T Acceptor](principal *types.PrincipalName) Option[T]

WithServicePrincipal sets the principal that is looked up in the keytab.

func WithUsername

func WithUsername[T Initiator](username string) Option[T]

WithUsername sets the username in the Initiator.

Notes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL