SASL: Simple Authentication and Security Layer
This library provides implementations of some SASL (RFC 4422) mechanisms. Currently only client support is implemented; future versions of this library may add server support.
1 SASL Introduction
This library implements non-trivial (multi-message) authentication mechanisms using SASL protocol contexts. Since in general SASL is embedded as a sub-protocol of some application protocol, this library does not handle I/O directly. Instead, the user is responsible for transferring messages between the SASL context and the application protocol.
Note that some SASL authentication mechanisms leave the communication of authentication success or failure to the application layer. Even when a mechanism normally communicates the result of authentication, some applications choose to convey failure at the application layer.
server → client: ... Hello. I understand the following SASL mechanisms: SCRAM-SHA-1 and CRAM-MD5
client → server: I choose SCRAM-SHA-1. My initial SASL message is “<initial SCRAM-SHA-1 message>”.
server → client: My SASL response is “<SCRAM-SHA-1 response>”.
client → server: My final SASL message is “final <SCRAM-SHA-1 message>”.
server → client: My final SASL response is “<final SCRAM-SHA-1 response>”.
client → server: Great! Let’s get to work....
2 SASL Protocol Contexts
(require sasl) | package: sasl-lib |
procedure
(sasl-next-message ctx) → (or/c string? bytes?)
ctx : sasl-ctx?
This function may be called only when (sasl-state ctx) is 'send/receive or 'send/done; otherwise, an exception is raised.
If message represents progress or success, then ctx is updated and subseqent calls to sasl-next-message return a new message (or fail, if the protocol is done).
If message indicates authentication failure or if message is ill-formed or invalid, an exception is raised and ctx enters a permanent error state (see sasl-state). The user must take appropriate action after either kind of failure. For example, upon authentication failure the client might close the connection and try again with different credentials.
This function may be called only when (sasl-state ctx) is 'receive or 'send/receive; otherwise, an exception is raised.
procedure
(sasl-state ctx)
→ (or/c 'receive 'send/receive 'send/done 'done 'error) ctx : sasl-ctx?
'receive: the protocol starts with ctx receiving a message
'send/receive: send the current outgoing message (sasl-next-message) if it hasn’t already been sent, then receive
'send/done: send the current outgoing message (sasl-next-message) if it hasn’t already been sent, then the SASL protocol is done
'done: the SASL protocol ended with the last received message
'error: a fatal error occurred
3 SASLprep
(require sasl/saslprep) | package: sasl-lib |
procedure
(saslprep s [ #:allow-unassigned? allow-unassigned?]) → string? s : string? allow-unassigned? : boolean? = #f
In general, the mechanism implementations in this library call saslprep on their arguments when appropriate.
4 SCRAM Authentication
(require sasl/scram) | package: sasl-lib |
This module implements the SCRAM family of authentication mechanisms, namely SCRAM-SHA-1 and SCRAM-SHA-256. The -PLUS variants, which add channel binding, are not implemented.
client → server: initial message with nonce prefix
server → client: reply with complete nonce and PBKDF2 salt and iteration count
client → server: client signature
server → client: authentication result and server signature
procedure
(make-scram-client-ctx digest authentication-id password [ #:authorization-id authorization-id]) → sasl-ctx? digest : (or/c 'sha1 'sha256) authentication-id : string? password : string? authorization-id : (or/c string? #f) = #f
5 CRAM-MD5 Authentication
(require sasl/cram-md5) | package: sasl-lib |
This module implements the CRAM-MD5 authentication mechanism.
server → client: challenge
client → server: response
procedure
(make-cram-md5-client-ctx authentication-id password) → sasl-ctx? authentication-id : string? password : string?
6 PLAIN Authentication
(require sasl/plain) | package: sasl-lib |
This module implements the PLAIN mechanism.
Since the PLAIN mechanism consists of a single message from the client to the server, it is implemented as a simple procedure rather than a SASL protocol context. The authentication outcome is conveyed at the application protocol layer.
procedure
(plain-client-message authentication-id password [ #:authorization-id authorization-id]) → string? authentication-id : string? password : string? authorization-id : (or/c string? #f) = #f