Skip to content
vitalvasPublic

About

A Go implementation of the TACACS+ protocol as defined in RFC 8907, with TLS 1.3 transport support per RFC 9887.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gotacacs

A Go implementation of the TACACS+ protocol as defined in RFC 8907, with TLS 1.3 transport support per RFC 9887.

Provides both client and server SDK interfaces for Authentication, Authorization, and Accounting (AAA) services.

Features

  • TACACS+ authentication, authorization, and accounting packet types (RFC 8907)
  • TLS 1.3 transport support (RFC 9887)
  • Client SDK with high-level API (PAP, CHAP, and ASCII interactive authentication)
  • Server SDK with pluggable handler interfaces
  • TCP and TLS transport support
  • Body obfuscation (MD5-based pseudo-pad)
  • Single-connect mode for connection reuse, with server-side refusal
  • Per-client secret provider with custom user data
  • Argument helpers preserving the mandatory (=) and optional (*) separators
  • Username and text-field validation (RFC 8907 Section 3.7)
  • RFC conformance guards: mandatory shared secret, unencrypted-flag rejection, accounting flag validation, and an authentication retry limit
  • Graceful server shutdown

Requirements

  • Go 1.27 or later

Installation

go get go.vitalvas.com/gotacacs

Quick Start

Client

client := gotacacs.NewClient(
    gotacacs.WithAddress("tacacs.example.com:49"),
    gotacacs.WithSecret("sharedsecret"),
)
defer client.Close()

// Authentication (PAP)
reply, err := client.Authenticate(ctx, "username", "password")
if err != nil {
    log.Fatal(err)
}
if reply.IsPass() {
    fmt.Println("Authentication successful")
}

// Authorization
resp, err := client.Authorize(ctx, "username", []string{"service=shell", "cmd=show"})
if err != nil {
    log.Fatal(err)
}
if resp.IsPass() {
    fmt.Println("Authorization granted")
}

// Accounting
acctReply, err := client.Accounting(ctx, gotacacs.AcctFlagStart, "username", []string{
    "task_id=123",
    "service=shell",
    "cmd=",
})
if err != nil {
    log.Fatal(err)
}
if acctReply.IsSuccess() {
    fmt.Println("Accounting recorded")
}

Server

ln, err := gotacacs.ListenTCP(":49")
if err != nil {
    log.Fatal(err)
}

server := gotacacs.NewServer(
    gotacacs.WithServerListener(ln),
    gotacacs.WithServerSecret("sharedsecret"),
    gotacacs.WithHandler(&myHandler{}),
)

if err := server.Serve(); err != nil {
    log.Fatal(err)
}

Implement the Handler interface. This example supports PAP login:

type myHandler struct{}

func (h *myHandler) HandleAuthenStart(_ context.Context, req *gotacacs.AuthenRequest) *gotacacs.AuthenReply {
    if req.Start.Action != gotacacs.AuthenActionLogin ||
        req.Start.AuthenType != gotacacs.AuthenTypePAP ||
        req.Start.Service != gotacacs.AuthenServiceLogin {
        return &gotacacs.AuthenReply{Status: gotacacs.AuthenStatusFail}
    }
    // Demo only: real deployments store salted password hashes, not plaintext.
    // Compare in constant time so a reply cannot leak password-prefix timing.
    if string(req.Start.User) == "admin" &&
        subtle.ConstantTimeCompare(req.Start.Data, []byte("secret")) == 1 {
        return &gotacacs.AuthenReply{Status: gotacacs.AuthenStatusPass}
    }
    return &gotacacs.AuthenReply{Status: gotacacs.AuthenStatusFail}
}

func (h *myHandler) HandleAuthenContinue(_ context.Context, _ *gotacacs.AuthenContinueRequest) *gotacacs.AuthenReply {
    return &gotacacs.AuthenReply{Status: gotacacs.AuthenStatusError, ServerMsg: []byte("CONTINUE not supported")}
}

func (h *myHandler) HandleAuthorRequest(_ context.Context, _ *gotacacs.AuthorRequestContext) *gotacacs.AuthorResponse {
    return &gotacacs.AuthorResponse{
        Status:  gotacacs.AuthorStatusPassAdd,
        RawArgs: gotacacs.ArgsFromMap(map[string]string{"priv-lvl": "15"}),
    }
}

func (h *myHandler) HandleAcctRequest(_ context.Context, _ *gotacacs.AcctRequestContext) *gotacacs.AcctReply {
    return &gotacacs.AcctReply{Status: gotacacs.AcctStatusSuccess}
}

Per-Client Secret Provider

secretProvider := gotacacs.SecretProviderFunc(func(_ context.Context, req gotacacs.SecretRequest) gotacacs.SecretResponse {
    return gotacacs.SecretResponse{
        Secret: []byte("sharedsecret"),
        UserData: map[string]string{
            "client_ip": req.RemoteAddr.String(),
            "local_ip":  req.LocalAddr.String(),
        },
    }
})

server := gotacacs.NewServer(
    gotacacs.WithServerListener(ln),
    gotacacs.WithSecretProvider(secretProvider),
    gotacacs.WithHandler(&myHandler{}),
)

TLS 1.3 (RFC 9887)

Configure certificates and trusted CA pools on both peers for mutual authentication:

// clientCert and serverCert are loaded with tls.LoadX509KeyPair.
// serverCAs and clientCAs contain the trusted CA certificates for each peer.
client := gotacacs.NewClient(
    gotacacs.WithAddress("tacacs.example.com:300"),
    gotacacs.WithTLSConfig(&tls.Config{
        Certificates: []tls.Certificate{clientCert},
        RootCAs:      serverCAs,
        ServerName:   "tacacs.example.com",
    }),
)
defer client.Close()

// Server with TLS
ln, err := gotacacs.ListenTLS(":300", &tls.Config{
    Certificates: []tls.Certificate{serverCert},
    ClientCAs:    clientCAs,
    ClientAuth:   tls.RequireAndVerifyClientCert,
})
if err != nil {
    log.Fatal(err)
}

When using TLS, the FlagUnencrypted header flag is set automatically and body obfuscation is disabled, as specified by RFC 9887.

RFC 9887 also requires certificate revocation and peer identity checks. Configure these through tls.Config, including VerifyConnection; see the client and server guides. TCP shared-secret obfuscation does not provide TLS encryption or integrity protection.

Examples

The package includes example binaries in examples/:

# TCP mode
go run ./examples/tacacs-server -addr :49 -secret sharedsecret
go run ./examples/tacacs-client -addr localhost:49 -secret sharedsecret

# Basic TLS transport demonstration (server certificate must be trusted)
go run ./examples/tacacs-server-tls -addr :300 -cert server.crt -key server.key
go run ./examples/tacacs-client-tls -addr localhost:300

The TLS example binaries do not configure mutual authentication or certificate revocation checks. Use the SDK configuration above and the linked guides for RFC 9887 deployments.

Documentation

Protocol Reference

About

A Go implementation of the TACACS+ protocol as defined in RFC 8907, with TLS 1.3 transport support per RFC 9887.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages