#include <arpa/inet.h>#include <ctype.h>#include <errno.h>#include <fcntl.h>#include <gcrypt.h>#include <pwd.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <sys/param.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <atalk/afp.h>#include <atalk/constant_time.h>#include <atalk/logger.h>#include <atalk/uam.h>Macros | |
| #define | SRP_INIT_MARKER 0x0001 |
| #define | SRP_CLIENT_PROOF 0x0003 |
| #define | SRP_SERVER_PROOF 0x0004 |
| #define | SRP_SHA1_LEN 20 |
| #define | SRP_SALT_LEN 16 |
| #define | SRP_GROUP_INDEX 0x0002 /* RFC 5054 group #2 */ |
| #define | SRP_NBYTES 192 /* 1536-bit prime = 192 bytes */ |
| #define | SRP_SESSION_KEY_LEN 40 |
| #define | SRP_HEX_SALT_LEN (SRP_SALT_LEN * 2) |
| #define | SRP_HEX_V_LEN (SRP_NBYTES * 2) |
| #define | SRP_AUTH_FAILURE (-6754) |
| #define | unhex(x) |
Functions | |
| static const unsigned char * | strip_leading_zeros (const unsigned char *buf, size_t len, size_t *out_len) |
| Strip leading zero bytes from a big-endian integer buffer. | |
| static int | mgf1_sha1 (const unsigned char *seed, size_t seed_len, unsigned char *out, size_t out_len) |
| MGF1 mask generation function (PKCS#1 v2.1) with SHA-1. | |
| static int | sha1_multi (unsigned char *out,...) |
| Compute SHA-1 incrementally from multiple buffers. | |
| static void | mpi_to_padded_buf (unsigned char *buf, size_t nbytes, gcry_mpi_t m) |
| Write an MPI to a buffer as a big-endian integer, zero-padded. | |
| static void | write_uint16_be (unsigned char **p, uint16_t val) |
| Write a 2-byte big-endian unsigned integer and advance the pointer. | |
| static uint16_t | read_uint16_be (unsigned char **p) |
| Read a 2-byte big-endian unsigned integer and advance the pointer. | |
| static int | srp_lookup_verifier (const char *path, const char *username, unsigned char *salt_out, gcry_mpi_t *v_out) |
| Look up a user's salt and verifier from the SRP verifier file. | |
| static void | srp_session_free (void) |
| Release all per-session SRP state and zero sensitive buffers. | |
| static int | srp_setup (void *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) |
| SRP Round 1 setup. | |
| static int | srp_login (void *obj, struct passwd **uam_pwd, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) |
| FPLogin handler for SRP UAM. | |
| static int | srp_login_ext (void *obj, char *uname, struct passwd **uam_pwd, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) |
| FPLoginExt handler for SRP UAM. | |
| static int | srp_logincont (void *obj, struct passwd **uam_pwd, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) |
| SRP Round 2: FPLoginCont handler. | |
| static int | uam_setup (void *obj, const char *path) |
| static void | uam_cleanup (void) |
Variables | |
| static const unsigned char | srp_N_bytes [SRP_NBYTES] |
| static const unsigned char | srp_g_byte = 0x02 |
| static gcry_mpi_t | session_N |
| static gcry_mpi_t | session_g |
| static gcry_mpi_t | session_v |
| static gcry_mpi_t | session_b |
| static gcry_mpi_t | session_B |
| static unsigned char | session_salt [SRP_SALT_LEN] |
| static unsigned char | session_B_buf [SRP_NBYTES] |
| static char | session_username [UAM_USERNAMELEN+1] |
| static struct passwd * | srppwd |
| UAM_MODULE_EXPORT struct uam_export | uams_srp |
SRP (Secure Remote Password) User Authentication Method for AFP. Protocol: SRP-6a with SHA-1, MGF1 KDF, RFC 5054 group #2 (1536-bit).
| #define SRP_AUTH_FAILURE (-6754) |
| #define SRP_CLIENT_PROOF 0x0003 |
| #define SRP_GROUP_INDEX 0x0002 /* RFC 5054 group #2 */ |
| #define SRP_HEX_SALT_LEN (SRP_SALT_LEN * 2) |
| #define SRP_HEX_V_LEN (SRP_NBYTES * 2) |
| #define SRP_INIT_MARKER 0x0001 |
| #define SRP_NBYTES 192 /* 1536-bit prime = 192 bytes */ |
| #define SRP_SALT_LEN 16 |
| #define SRP_SERVER_PROOF 0x0004 |
| #define SRP_SESSION_KEY_LEN 40 |
| #define SRP_SHA1_LEN 20 |
| #define unhex | ( | x | ) |
|
static |
MGF1 mask generation function (PKCS#1 v2.1) with SHA-1.
| [in] | seed | The seed for the mask generation. |
| [in] | seed_len | The length of the seed. |
| [out] | out | The output buffer. |
| [in] | out_len | The length of the output buffer. |
|
static |
Write an MPI to a buffer as a big-endian integer, zero-padded.
| [out] | buf | Output buffer (must be at least nbytes). |
| [in] | nbytes | Target length with leading zero padding. |
| [in] | m | MPI to serialize. |
|
static |
Read a 2-byte big-endian unsigned integer and advance the pointer.
| [in,out] | p | Pointer to the read position (advanced by 2). |
|
static |
Compute SHA-1 incrementally from multiple buffers.
Arguments after out are pairs of (const unsigned char *data, size_t len), terminated by a NULL data pointer.
| [out] | out | 20-byte buffer for the SHA-1 digest. |
|
static |
FPLogin handler for SRP UAM.
Parses the username from the non-extended login request, validates the user, and delegates to srp_setup() for Round 1.
|
static |
FPLoginExt handler for SRP UAM.
Parses the UTF-8 username from the extended login request, validates the user, and delegates to srp_setup() for Round 1.
|
static |
SRP Round 2: FPLoginCont handler.
Parses the client's public ephemeral A and proof M1, computes the server-side shared secret S and session key K, verifies M1, and responds with server proof M2 to complete mutual authentication.
|
static |
Look up a user's salt and verifier from the SRP verifier file.
The file format is one line per user: username:hex_salt:hex_verifier
| [in] | path | Path to the verifier file. |
| [in] | username | User to look up. |
| [out] | salt_out | Buffer for the salt (SRP_SALT_LEN bytes). |
| [out] | v_out | MPI set to the verifier on success. |
|
static |
Release all per-session SRP state and zero sensitive buffers.
|
static |
SRP Round 1 setup.
Looks up the user's verifier from the verifier file, generates the server ephemeral key pair (b, B), and builds the FPLoginExt response containing the SRP group parameters, salt, and server public ephemeral B.
|
static |
Strip leading zero bytes from a big-endian integer buffer.
|
static |
|
static |
|
static |
Write a 2-byte big-endian unsigned integer and advance the pointer.
| [in,out] | p | Pointer to the write position (advanced by 2). |
| [in] | val | Value to write. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
RFC 5054 group #2: 1536-bit MODP group. N is the safe prime, g = 2.
|
static |
| UAM_MODULE_EXPORT struct uam_export uams_srp |