The cl-scram Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-scram Reference Manual

This is the cl-scram Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 04:08:40 2022 GMT+0.

Table of Contents


1 Introduction

cl-scram

Introduction

I started developing this library when I was trying to use MongoDB with the cl-mongo driver, and it became apparent that the driver had not been updated to use mongo's modern SCRAM-SHA1 authentication method.

Given the choices of relying on an antiquated MD5-based login method or writing a shiny new library, I chose the latter. The purpose of cl-scram is to allow for everything the client needs to do SCRAM login with the SHA1 hash algorithm.

The library is dependent on ironclad for all cryptographic functions. It does not rely on any DIY crypto.

License

The project is licensed under the Revised BSD License.

Copyright (c) 2015, Matt Prelude
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Matt Prelude nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL MATT PRELUDE BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Installation

Use ASDF to install cl-scram as it has a number of dependencies. I will be looking to include cl-scram in Quicklisp later on.

* (asdf:load-system :cl-scram)

All of the functions are in the #:cl-scram package.

Testing

TODO: Add regression tests.

Usage

Generating a client nonce

The first step in a SCRAM request is to generate a nonce for the request. This can be done as follows:

* (gen-client-nonce)

"x6uHptrIM6PAFMtmbGCN8uuy0LSnZCww"

This is fully supported by cl-scrams message-generating functions, which accept a :nonce parameter.

Generating first client message

Next, we need to generate the first client message. To generate an un-encoded message, you can call the gen-client-initial-message function with the username & nonce:

* (gen-client-initial-message :username "username" :nonce "x6uHptrIM6PAFMtmbGCN8uuy0LSnZCww")

"n,,n=username,r=x6uHptrIM6PAFMtmbGCN8uuy0LSnZCww"

You'll need to pass this to the server.

Generating final client message

The server should respond with a base64-encoded string, which when decoded looks something like this:

r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096

In order to generate the final response, we'll need to create a new request (this is based on the exchange from the RFC document, in order to show that it creates the same final message):

* (gen-client-final-message 
    :password "pencil" 
    :client-nonce "fyko+d2lbbFgONRv9qkxdawL" 
    :client-initial-message "n,,n=user,r=fyko+d2lbbFgONRv9qkxdawL" 
    :server-response "r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096")

((CL-SCRAM::SERVER-SIGNATURE
  . #(174 97 125 166 165 124 75 187 46 2 134 86 141 174 29 37 25 5 176 164))
 (CL-SCRAM::FINAL-MESSAGE
  . "c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts="))

Your application will want to send the final-message back to the server, and store the server-signature for validating the server's final response.

Dealing with final server message

The server will respond with a base64-encoded string. If this is the same as the server-signature from the last step, then authentication was successful.

Donations

If this library has been helpful to you, I don't seek any donations, but please feel free to donate to Quicklisp, one of the most important projects in the CL ecosystem.

Understanding the first server response

The server should respond with a base64-encoded string, when decoded, this will have three parameters:

r=6d442b5d9e51a740f369e3dcecf3178ec12b3985bbd4a8e6f814b422ab766573,s=Vdptv0j/N6fs2qtVADc1Xg==,i=8192

cl-scram provides three convenience methods to access & validate the data.

To get the nonce (and confirm that it correctly starts with the client nonce), call parse-server-nonce passing the decoded message response & the client nonce:

* (parse-server-nonce :nonce "6d44" :response "r=6d442b5d9e51a740f369e3dcecf3178ec12b3985bbd4a8e6f814b422ab766573,s=Vdptv0j/N6fs2qtVADc1Xg==,i=8192")

"6d442b5d9e51a740f369e3dcecf3178ec12b3985bbd4a8e6f814b422ab766573"

And to get the salt (base64-decoded), call parse-server-salt:

* (parse-server-salt :response "r=6d442b5d9e51a740f369e3dcecf3178ec12b3985bbd4a8e6f814b422ab766573,s=Vdptv0j/N6fs2qtVADc1Xg==,i=8192")

"UÚm¿Hÿ7§ìÚ«U75^"

And finally, to get the number of iterations, you can call parse-server-iterations:

* (parse-server-iterations :response "r=6d442b5d9e51a740f369e3dcecf3178ec12b3985bbd4a8e6f814b422ab766573,s=Vdptv0j/N6fs2qtVADc1Xg==,i=8192")

"8192"

TODO

  1. Implement SASLprep algorithm to support the full gamut of passwords. For now, using the library with passwords containing unsupported characters is considered unsupported behavior.
  2. Add regression tests.
  3. Support algorithms other than

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-scram

Common lisp library to implement SCRAM-SHA1 SASL mechanism.

Author

Matt Prelude <me@mprelu.de>

License

Revised BSD License (see LICENSE)

Version

0.1

Dependencies
  • cl-sasl (system).
  • cl-base64 (system).
  • ironclad (system).
  • secure-random (system).
  • split-sequence (system).
Source

cl-scram.asd.

Child Components

3 Modules

Modules are listed depth-first from the system components tree.


Previous: , Up: Modules   [Contents][Index]

3.1 cl-scram/src

Source

cl-scram.asd.

Parent Component

cl-scram (system).

Child Components

4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Next: , Previous: , Up: Files   [Contents][Index]

4.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

4.1.1 cl-scram/cl-scram.asd

Source

cl-scram.asd.

Parent Component

cl-scram (system).

ASDF Systems

cl-scram.

Packages

cl-scram-asd.


4.1.2 cl-scram/src/packages.lisp

Source

cl-scram.asd.

Parent Component

src (module).

Packages

cl-scram.


4.1.3 cl-scram/src/conditions.lisp

Dependency

packages.lisp (file).

Source

cl-scram.asd.

Parent Component

src (module).


4.1.4 cl-scram/src/utils.lisp

Dependency

conditions.lisp (file).

Source

cl-scram.asd.

Parent Component

src (module).

Public Interface
Internals

4.1.5 cl-scram/src/scram.lisp

Dependency

utils.lisp (file).

Source

cl-scram.asd.

Parent Component

src (module).

Public Interface
Internals

Previous: , Up: Files   [Contents][Index]

4.2 Static


Next: , Previous: , Up: Static   [Contents][Index]

4.2.1 cl-scram/README.md

Source

cl-scram.asd.

Parent Component

cl-scram (system).


Previous: , Up: Static   [Contents][Index]

4.2.2 cl-scram/LICENSE

Source

cl-scram.asd.

Parent Component

cl-scram (system).


5 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

5.1 cl-scram

Source

packages.lisp.

Use List
  • common-lisp.
  • split-sequence.
Public Interface
Internals

Previous: , Up: Packages   [Contents][Index]

5.2 cl-scram-asd

Source

cl-scram.asd.

Use List
  • asdf/interface.
  • common-lisp.

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

6.1 Public Interface


6.1.1 Ordinary functions

Function: base64-decode (string)
Package

cl-scram.

Source

utils.lisp.

Function: base64-encode (string)
Package

cl-scram.

Source

utils.lisp.

Function: base64-encode-octets (octets)
Package

cl-scram.

Source

utils.lisp.

Function: gen-client-encoded-initial-message (&key username nonce)
Package

cl-scram.

Source

scram.lisp.

Function: gen-client-final-message (&key password client-nonce client-initial-message server-response)
Package

cl-scram.

Source

scram.lisp.

Function: gen-client-initial-message (&key username nonce)
Package

cl-scram.

Source

scram.lisp.

Function: gen-client-nonce ()

Generate a random 32-character nonce.

Package

cl-scram.

Source

utils.lisp.

Function: gen-sasl-password (password)
Package

cl-scram.

Source

utils.lisp.

Function: parse-server-iterations (&key response)
Package

cl-scram.

Source

scram.lisp.

Function: parse-server-nonce (&key response nonce)
Package

cl-scram.

Source

scram.lisp.

Function: parse-server-salt (&key response)
Package

cl-scram.

Source

scram.lisp.


6.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

6.2.1 Ordinary functions

Function: bit-vector->integer (bit-vector)

Create a positive integer from a bit-vector.

Package

cl-scram.

Source

utils.lisp.

Function: gen-hmac-digest (&key key message)

Takes a key & a message, and generates a HMAC digest.

Package

cl-scram.

Source

utils.lisp.

Function: gen-sha1-digest (&key key)

Takes a key, and generates a SHA1 digest.

Package

cl-scram.

Source

utils.lisp.

Function: integer->bit-vector (integer)

Create a bit-vector from a positive integer.

Package

cl-scram.

Source

utils.lisp.

Function: parse-server-response (&key response)
Package

cl-scram.

Source

scram.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

6.2.2 Generic functions

Generic Reader: text (condition)
Package

cl-scram.

Methods
Reader Method: text ((condition unexpected-nonce))
Source

scram.lisp.

Target Slot

text.


Previous: , Up: Internals   [Contents][Index]

6.2.3 Conditions

Condition: unexpected-nonce
Package

cl-scram.

Source

scram.lisp.

Direct superclasses

error.

Direct methods

text.

Direct slots
Slot: text
Initargs

:text

Readers

text.

Writers

This slot is read-only.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   B   F   G   I   M   P   T  
Index Entry  Section

B
base64-decode: Public ordinary functions
base64-encode: Public ordinary functions
base64-encode-octets: Public ordinary functions
bit-vector->integer: Private ordinary functions

F
Function, base64-decode: Public ordinary functions
Function, base64-encode: Public ordinary functions
Function, base64-encode-octets: Public ordinary functions
Function, bit-vector->integer: Private ordinary functions
Function, gen-client-encoded-initial-message: Public ordinary functions
Function, gen-client-final-message: Public ordinary functions
Function, gen-client-initial-message: Public ordinary functions
Function, gen-client-nonce: Public ordinary functions
Function, gen-hmac-digest: Private ordinary functions
Function, gen-sasl-password: Public ordinary functions
Function, gen-sha1-digest: Private ordinary functions
Function, integer->bit-vector: Private ordinary functions
Function, parse-server-iterations: Public ordinary functions
Function, parse-server-nonce: Public ordinary functions
Function, parse-server-response: Private ordinary functions
Function, parse-server-salt: Public ordinary functions

G
gen-client-encoded-initial-message: Public ordinary functions
gen-client-final-message: Public ordinary functions
gen-client-initial-message: Public ordinary functions
gen-client-nonce: Public ordinary functions
gen-hmac-digest: Private ordinary functions
gen-sasl-password: Public ordinary functions
gen-sha1-digest: Private ordinary functions
Generic Function, text: Private generic functions

I
integer->bit-vector: Private ordinary functions

M
Method, text: Private generic functions

P
parse-server-iterations: Public ordinary functions
parse-server-nonce: Public ordinary functions
parse-server-response: Private ordinary functions
parse-server-salt: Public ordinary functions

T
text: Private generic functions
text: Private generic functions

Jump to:   B   F   G   I   M   P   T  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   S   T  
Index Entry  Section

S
Slot, text: Private conditions

T
text: Private conditions

Jump to:   S   T