The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
password.c File Reference

Password normalisation functions. More...

#include <freeradius-devel/server/password.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/base64.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/md4.h>
#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/sha1.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/protocol/freeradius/freeradius.internal.password.h>
+ Include dependency graph for password.c:

Go to the source code of this file.

Data Structures

struct  password_info_t
 Password information. More...
 

Macros

#define MIN_LEN(_info)   (info->type == PASSWORD_HASH_SALTED ? (info->min_hash_len + 1) : info->min_hash_len)
 

Typedefs

typedef fr_pair_t *(* password_preprocess_t) (TALLOC_CTX *ctx, request_t *request, fr_pair_t *in)
 Apply preprocessing logic to a password value. More...
 

Enumerations

enum  normalise_t {
  NORMALISED_NOTHING = 0 ,
  NORMALISED_B64 ,
  NORMALISED_HEX
}
 
enum  password_type_t {
  PASSWORD_CLEARTEXT = 0 ,
  PASSWORD_HASH ,
  PASSWORD_HASH_SALTED ,
  PASSWORD_HASH_VARIABLE
}
 

Functions

static int _password_free (UNUSED void *uctx)
 
static int _password_init (UNUSED void *uctx)
 
static ssize_t normify (normalise_t *action, uint8_t *buffer, size_t bufflen, char const *known_good, size_t len, size_t min_len)
 
fr_pair_tpassword_find (bool *ephemeral, TALLOC_CTX *ctx, request_t *request, fr_dict_attr_t const *allowed_attrs[], size_t allowed_attrs_len, bool normify)
 Find a "known good" password in the control list of a request. More...
 
int password_init (void)
 Load our dictionaries. More...
 
static fr_pair_tpassword_normalise_and_recheck (TALLOC_CTX *ctx, request_t *request, fr_dict_attr_t const *allowed_attrs[], size_t allowed_attrs_len, bool normify, fr_pair_t *const known_good)
 
int password_normalise_and_replace (request_t *request, bool normify)
 Find all password attributes in the control list of a request and normalise them. More...
 
static fr_pair_tpassword_normify (TALLOC_CTX *ctx, request_t *request, fr_pair_t const *known_good)
 Hex or base64 or bin auto-discovery. More...
 
static fr_pair_tpassword_process (TALLOC_CTX *ctx, request_t *request, fr_pair_t *known_good, bool normify)
 Apply any processing and normification. More...
 
static fr_pair_tpassword_process_header (TALLOC_CTX *ctx, request_t *request, fr_pair_t *known_good)
 Convert a Password.With-Header attribute to the correct type. More...
 

Variables

static fr_dict_attr_t const * attr_cleartext
 
static fr_dict_attr_t const * attr_crypt
 
static fr_dict_attr_t const * attr_lm
 
static fr_dict_attr_t const * attr_md5
 
static fr_dict_attr_t const * attr_ns_mta_md5
 
static fr_dict_attr_t const * attr_nt
 
static fr_dict_attr_t const * attr_pbkdf2
 
static fr_dict_attr_t const * attr_root
 
static fr_dict_attr_t const * attr_sha1
 
static fr_dict_attr_t const * attr_sha2
 
static fr_dict_attr_t const * attr_sha2_224
 
static fr_dict_attr_t const * attr_sha2_256
 
static fr_dict_attr_t const * attr_sha2_384
 
static fr_dict_attr_t const * attr_sha2_512
 
static fr_dict_attr_t const * attr_sha3
 
static fr_dict_attr_t const * attr_sha3_224
 
static fr_dict_attr_t const * attr_sha3_256
 
static fr_dict_attr_t const * attr_sha3_384
 
static fr_dict_attr_t const * attr_sha3_512
 
static fr_dict_attr_t const * attr_smd5
 
static fr_dict_attr_t const * attr_ssha1
 
static fr_dict_attr_t const * attr_ssha2_224
 
static fr_dict_attr_t const * attr_ssha2_256
 
static fr_dict_attr_t const * attr_ssha2_384
 
static fr_dict_attr_t const * attr_ssha2_512
 
static fr_dict_attr_t const * attr_ssha3_224
 
static fr_dict_attr_t const * attr_ssha3_256
 
static fr_dict_attr_t const * attr_ssha3_384
 
static fr_dict_attr_t const * attr_ssha3_512
 
static fr_dict_attr_t const * attr_user
 
static fr_dict_attr_t const * attr_with_header
 
static fr_dict_t const * dict_freeradius = NULL
 
static fr_dict_t const * dict_radius = NULL
 
static fr_table_num_sorted_t const normalise_table []
 
static size_t normalise_table_len = NUM_ELEMENTS(normalise_table)
 
fr_dict_autoload_t password_dict []
 
fr_dict_attr_autoload_t password_dict_attr []
 
static fr_table_num_sorted_t const password_header_table []
 
static size_t password_header_table_len = NUM_ELEMENTS(password_header_table)
 
static password_info_t password_info []
 Metadata for various password attributes. More...
 
static fr_table_num_sorted_t const password_type_table []
 
static size_t password_type_table_len = NUM_ELEMENTS(password_type_table)
 

Detailed Description

Password normalisation functions.

Definition in file password.c.


Data Structure Documentation

◆ password_info_t

struct password_info_t

Password information.

Definition at line 64 of file password.c.

+ Collaboration diagram for password_info_t:
Data Fields
bool always_allow Always allow processing of this attribute, irrespective of what the caller says.
fr_dict_attr_t const ** da Dictionary attribute representing this type of password.
password_preprocess_t func Preprocessing function.
size_t max_hash_len Maximum length of the decoded string if normifying.

If 0, will be ignored.

size_t min_hash_len Minimum length of the decoded string if normifying.

If 0, will be ignored.

bool no_normify Don't attempt to normalise the contents of this attribute using the hex/base64 decoders.
password_type_t type What type of password value this is.

Macro Definition Documentation

◆ MIN_LEN

#define MIN_LEN (   _info)    (info->type == PASSWORD_HASH_SALTED ? (info->min_hash_len + 1) : info->min_hash_len)

Definition at line 398 of file password.c.

Typedef Documentation

◆ password_preprocess_t

typedef fr_pair_t*(* password_preprocess_t) (TALLOC_CTX *ctx, request_t *request, fr_pair_t *in)

Apply preprocessing logic to a password value.

Parameters
[in]ctxto allocate returned value in.
[in]requestcurrently being processed.
[in]inPair containing the password to process. @

Definition at line 59 of file password.c.

Enumeration Type Documentation

◆ normalise_t

Enumerator
NORMALISED_NOTHING 
NORMALISED_B64 
NORMALISED_HEX 

Definition at line 172 of file password.c.

◆ password_type_t

Enumerator
PASSWORD_CLEARTEXT 

Variable length.

PASSWORD_HASH 

Fixed length.

PASSWORD_HASH_SALTED 

Fixed length hash, variable length salt.

PASSWORD_HASH_VARIABLE 

Variable length everything.

Definition at line 45 of file password.c.

Function Documentation

◆ _password_free()

static int _password_free ( UNUSED void *  uctx)
static

Definition at line 1034 of file password.c.

+ Here is the caller graph for this function:

◆ _password_init()

static int _password_init ( UNUSED void *  uctx)
static

Definition at line 1019 of file password.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normify()

static ssize_t normify ( normalise_t action,
uint8_t buffer,
size_t  bufflen,
char const *  known_good,
size_t  len,
size_t  min_len 
)
static

Definition at line 400 of file password.c.

+ Here is the caller graph for this function:

◆ password_find()

fr_pair_t* password_find ( bool ephemeral,
TALLOC_CTX *  ctx,
request_t request,
fr_dict_attr_t const *  allowed_attrs[],
size_t  allowed_attrs_len,
bool  normify 
)

Find a "known good" password in the control list of a request.

Searches for a "known good" password attribute, and applies any processing and normification operations to it, returning a new normalised fr_pair_t.

The ctx passed in should be freed when the caller is done with the returned fr_pair_t, or alternatively, a persistent ctx may be used and the value of ephemeral checked. If ephemeral is false the returned pair MUST NOT BE FREED, it may be an attribute in the request->control_pairs list. If ephemeral is true, the returned pair MUST be freed, or added to one of the pair lists appropriate to the ctx passed in.

Parameters
[out]ephemeralIf true, the caller must use TALLOC_FREE to free the return value of this function. Alternatively 'ctx' can be freed, which is simpler and cleaner, but some people have religious objections to that.
[in]ctxEphemeral ctx to allocate new attributes in.
[in]requestThe current request.
[in]allowed_attrsOptional list of allowed attributes.
[in]allowed_attrs_lenLength of allowed attributes list.
[in]normifyApply hex/base64 normalisation to attributes.
Returns
  • A fr_pair_t containing a "known good" password.
  • NULL on error, or if no usable password attributes were found.

Definition at line 954 of file password.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ password_init()

int password_init ( void  )

Load our dictionaries.

Definition at line 1044 of file password.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ password_normalise_and_recheck()

static fr_pair_t* password_normalise_and_recheck ( TALLOC_CTX *  ctx,
request_t request,
fr_dict_attr_t const *  allowed_attrs[],
size_t  allowed_attrs_len,
bool  normify,
fr_pair_t *const  known_good 
)
static

Definition at line 891 of file password.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ password_normalise_and_replace()

int password_normalise_and_replace ( request_t request,
bool  normify 
)

Find all password attributes in the control list of a request and normalise them.

Parameters
[in]requestThe current request.
[in]normifyApply hex/base64 normalisation to attributes.
Returns
the number of attributes normalised.

Definition at line 858 of file password.c.

+ Here is the call graph for this function:

◆ password_normify()

static fr_pair_t* password_normify ( TALLOC_CTX *  ctx,
request_t request,
fr_pair_t const *  known_good 
)
static

Hex or base64 or bin auto-discovery.

Here we try and autodiscover what encoding was used for the password/hash, and convert it back to binary or plaintext.

Note
Earlier versions used a 0x prefix as a hard indicator that the string was hex encoded, and would fail if the 0x was present but the string didn't consist of hexits. The base64 char set is a superset of hex, and it was observed in the wild, that occasionally base64 encoded data really could start with 0x. That's why min_len (and decodability) are used as the only heuristics now.
Parameters
[in]ctxto allocate new pairs in.
[in]requestThe current request.
[in]known_goodpassword to normify.
Returns
  • NULL if known_good was already normalised, or couldn't be normalised.
  • A new normalised password pair.

Definition at line 463 of file password.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ password_process()

static fr_pair_t* password_process ( TALLOC_CTX *  ctx,
request_t request,
fr_pair_t known_good,
bool  normify 
)
static

Apply any processing and normification.

Definition at line 755 of file password.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ password_process_header()

static fr_pair_t * password_process_header ( TALLOC_CTX *  ctx,
request_t request,
fr_pair_t known_good 
)
static

Convert a Password.With-Header attribute to the correct type.

Attribute may be base64 encoded, in which case it will be decoded first, then evaluated.

Note
The buffer for octets types\ attributes is extended by one byte and '\0' terminated, to allow it to be used as a char buff.
Parameters
[in]ctxto allocate new pairs in.
[in]requestCurrent request.
[in]known_goodPassword.With-Header attribute to convert.
Returns
  • Buffer containing normified value on success.
  • NULL on error.

Definition at line 615 of file password.c.

+ Here is the call graph for this function:

Variable Documentation

◆ attr_cleartext

fr_dict_attr_t const* attr_cleartext
static

Definition at line 81 of file password.c.

◆ attr_crypt

fr_dict_attr_t const* attr_crypt
static

Definition at line 87 of file password.c.

◆ attr_lm

fr_dict_attr_t const* attr_lm
static

Definition at line 115 of file password.c.

◆ attr_md5

fr_dict_attr_t const* attr_md5
static

Definition at line 85 of file password.c.

◆ attr_ns_mta_md5

fr_dict_attr_t const* attr_ns_mta_md5
static

Definition at line 117 of file password.c.

◆ attr_nt

fr_dict_attr_t const* attr_nt
static

Definition at line 116 of file password.c.

◆ attr_pbkdf2

fr_dict_attr_t const* attr_pbkdf2
static

Definition at line 114 of file password.c.

◆ attr_root

fr_dict_attr_t const* attr_root
static

Definition at line 83 of file password.c.

◆ attr_sha1

fr_dict_attr_t const* attr_sha1
static

Definition at line 89 of file password.c.

◆ attr_sha2

fr_dict_attr_t const* attr_sha2
static

Definition at line 92 of file password.c.

◆ attr_sha2_224

fr_dict_attr_t const* attr_sha2_224
static

Definition at line 93 of file password.c.

◆ attr_sha2_256

fr_dict_attr_t const* attr_sha2_256
static

Definition at line 94 of file password.c.

◆ attr_sha2_384

fr_dict_attr_t const* attr_sha2_384
static

Definition at line 95 of file password.c.

◆ attr_sha2_512

fr_dict_attr_t const* attr_sha2_512
static

Definition at line 96 of file password.c.

◆ attr_sha3

fr_dict_attr_t const* attr_sha3
static

Definition at line 103 of file password.c.

◆ attr_sha3_224

fr_dict_attr_t const* attr_sha3_224
static

Definition at line 104 of file password.c.

◆ attr_sha3_256

fr_dict_attr_t const* attr_sha3_256
static

Definition at line 105 of file password.c.

◆ attr_sha3_384

fr_dict_attr_t const* attr_sha3_384
static

Definition at line 106 of file password.c.

◆ attr_sha3_512

fr_dict_attr_t const* attr_sha3_512
static

Definition at line 107 of file password.c.

◆ attr_smd5

fr_dict_attr_t const* attr_smd5
static

Definition at line 86 of file password.c.

◆ attr_ssha1

fr_dict_attr_t const* attr_ssha1
static

Definition at line 90 of file password.c.

◆ attr_ssha2_224

fr_dict_attr_t const* attr_ssha2_224
static

Definition at line 98 of file password.c.

◆ attr_ssha2_256

fr_dict_attr_t const* attr_ssha2_256
static

Definition at line 99 of file password.c.

◆ attr_ssha2_384

fr_dict_attr_t const* attr_ssha2_384
static

Definition at line 100 of file password.c.

◆ attr_ssha2_512

fr_dict_attr_t const* attr_ssha2_512
static

Definition at line 101 of file password.c.

◆ attr_ssha3_224

fr_dict_attr_t const* attr_ssha3_224
static

Definition at line 109 of file password.c.

◆ attr_ssha3_256

fr_dict_attr_t const* attr_ssha3_256
static

Definition at line 110 of file password.c.

◆ attr_ssha3_384

fr_dict_attr_t const* attr_ssha3_384
static

Definition at line 111 of file password.c.

◆ attr_ssha3_512

fr_dict_attr_t const* attr_ssha3_512
static

Definition at line 112 of file password.c.

◆ attr_user

fr_dict_attr_t const* attr_user
static

Definition at line 119 of file password.c.

◆ attr_with_header

fr_dict_attr_t const* attr_with_header
static

Definition at line 82 of file password.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius = NULL
static

Definition at line 78 of file password.c.

◆ dict_radius

fr_dict_t const* dict_radius = NULL
static

Definition at line 79 of file password.c.

◆ normalise_table

fr_table_num_sorted_t const normalise_table[]
static
Initial value:
= {
{ L("base64"), NORMALISED_B64 },
{ L("hex"), NORMALISED_HEX },
{ L("nothing"), NORMALISED_NOTHING }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ NORMALISED_B64
Definition: password.c:174
@ NORMALISED_HEX
Definition: password.c:175
@ NORMALISED_NOTHING
Definition: password.c:173

Definition at line 178 of file password.c.

◆ normalise_table_len

size_t normalise_table_len = NUM_ELEMENTS(normalise_table)
static

Definition at line 183 of file password.c.

◆ password_dict

fr_dict_autoload_t password_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ .out = &dict_radius, .proto = "radius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition: password.c:78
static fr_dict_t const * dict_radius
Definition: password.c:79

Definition at line 122 of file password.c.

◆ password_dict_attr

fr_dict_attr_autoload_t password_dict_attr

Definition at line 129 of file password.c.

◆ password_header_table

fr_table_num_sorted_t const password_header_table[]
static

Definition at line 198 of file password.c.

◆ password_header_table_len

size_t password_header_table_len = NUM_ELEMENTS(password_header_table)
static

Definition at line 234 of file password.c.

◆ password_info

password_info_t password_info[]
static

Metadata for various password attributes.

Definition at line 245 of file password.c.

◆ password_type_table

fr_table_num_sorted_t const password_type_table[]
static
Initial value:
= {
{ L("cleartext"), PASSWORD_CLEARTEXT },
{ L("hashed"), PASSWORD_HASH },
{ L("salted-hash"), PASSWORD_HASH_SALTED },
{ L("variable-length-hash"), PASSWORD_HASH_VARIABLE }
}
@ PASSWORD_HASH
Fixed length.
Definition: password.c:47
@ PASSWORD_HASH_VARIABLE
Variable length everything.
Definition: password.c:49
@ PASSWORD_HASH_SALTED
Fixed length hash, variable length salt.
Definition: password.c:48
@ PASSWORD_CLEARTEXT
Variable length.
Definition: password.c:46

Definition at line 185 of file password.c.

◆ password_type_table_len

size_t password_type_table_len = NUM_ELEMENTS(password_type_table)
static

Definition at line 191 of file password.c.