Skip to content

JuliaServices/SASLAuth.jl

Repository files navigation

SASLAuth.jl

Build Status codecov.io


πŸ” Overview

SASLAuth.jl is a pure Julia implementation of the Simple Authentication and Security Layer (SASL) framework. It provides both client and server support for multiple authentication mechanisms, suitable for implementing protocol layers such as IMAP, LDAP, SMTP, XMPP, or custom client-server auth.

Supported mechanisms:

  • βœ… SCRAM-SHA-256 β€” secure, salted password-based challenge-response
  • βœ… PLAIN β€” simple username/password (must be used over TLS)
  • βœ… EXTERNAL β€” identity established by external means (e.g. TLS client cert)

πŸ“¦ Installation

Install from the Julia registry:

using Pkg
Pkg.add("SASLAuth")

For the development version:

Pkg.add(url="https://github.com/JuliaServices/SASLAuth.jl")

πŸ“˜ Usage

Common API

Each mechanism provides:

  • Client <: SASLClient
  • Server <: SASLServer

With the shared interface:

  • step!(client::SASLClient, input) β†’ (message, done::Bool)
  • step!(server::SASLServer, input) β†’ (reply, done::Bool, success::Bool)

πŸ” SCRAM-SHA-256

Client

client = SCRAMSHA256Client("alice", "correcthorsebatterystaple")

msg1, _ = step!(client, nothing)
msg2, _ = step!(client, "r=nonceXYZ,s=\$(Base64.base64encode("salt")),i=4096")
msg3, _ = step!(client, "v=\$(Base64.base64encode("serversignature"))"; verify_server_signature=false)

Server

salt = rand(UInt8, 16)
iterations = 4096
salted_password = pbkdf2(Vector{UInt8}("correcthorsebatterystaple"), salt, iterations)

server = SCRAMSHA256Server("alice", salted_password, salt, iterations)

challenge, _, _ = step!(server, msg1)
response, done, success = step!(server, msg2)

🧾 PLAIN

client = PLAINClient("alice", "hunter2")
msg, _ = step!(client, nothing)

server = PLAINServer(username -> username == "alice" ? "hunter2" : nothing)
_, _, ok = step!(server, msg)

🌐 EXTERNAL

client = EXTERNALClient("alice")
msg, _ = step!(client, nothing)

server = EXTERNALServer(authzid -> authzid == "alice")
_, _, ok = step!(server, msg)

πŸ§ͺ Running Tests

using Pkg
Pkg.test("SASLAuth")

πŸ“„ License

MIT Β© 2024 JuliaServices

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages