20#define G_LOG_DOMAIN "libgvm util"
28 "radius_connect", NULL};
43#ifdef ENABLE_LDAP_AUTH
58#ifdef ENABLE_RADIUS_AUTH
95 for (
int i = 0; i < 1000; i++)
113 g_warning (
"gvm_auth_init called a second time.");
120 if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
130 if (!gcry_check_version (NULL))
132 g_critical (
"%s: libgcrypt version check failed\n", __func__);
138 gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
146 gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
150 gcry_control (GCRYCTL_RESUME_SECMEM_WARN);
155 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
180 gcry_error_t err = gcry_md_test_algo (gcrypt_algorithm);
183 g_warning (
"Could not select gcrypt algorithm: %s", gcry_strerror (err));
187 hex = g_malloc0 (gcry_md_get_algo_dlen (gcrypt_algorithm) * 2 + 1);
188 for (i = 0; i < gcry_md_get_algo_dlen (gcrypt_algorithm); i++)
190 g_snprintf (hex + i * 2, 3,
"%02x", digest[i]);
214 unsigned char *nonce_buffer[256];
215 guchar *seed = g_malloc0 (gcry_md_get_algo_dlen (GCRY_MD_MD5));
216 gchar *seed_hex = NULL;
217 gchar *seed_pass = NULL;
218 guchar *hash = g_malloc0 (gcry_md_get_algo_dlen (GCRY_MD_MD5));
219 gchar *hash_hex = NULL;
220 gchar *hashes_out = NULL;
222 gcry_create_nonce (nonce_buffer, 256);
223 gcry_md_hash_buffer (GCRY_MD_MD5, seed, nonce_buffer, 256);
225 seed_pass = g_strconcat (seed_hex, password, NULL);
226 gcry_md_hash_buffer (GCRY_MD_MD5, hash, seed_pass, strlen (seed_pass));
229 hashes_out = g_strjoin (
" ", hash_hex, seed_hex, NULL);
253 gchar *hash_hex = NULL;
254 guchar *hash = g_malloc0 (gcry_md_get_algo_dlen (GCRY_MD_MD5));
256 gcry_md_hash_buffer (GCRY_MD_MD5, hash,
string, strlen (
string));
275 const gchar *hash_arg)
277 int gcrypt_algorithm = GCRY_MD_MD5;
279 gchar *actual, *expect, *seed_pass;
281 gchar *hash_hex, **seed_hex, **split;
284 if (hash_arg == NULL)
286 actual = g_strdup (hash_arg);
288 split = g_strsplit_set (g_strchomp (actual),
" ", 2);
289 seed_hex = split + 1;
290 if (*split == NULL || *seed_hex == NULL)
292 g_warning (
"Failed to split auth contents.");
298 seed_pass = g_strconcat (*seed_hex, password, NULL);
299 hash = g_malloc0 (gcry_md_get_algo_dlen (gcrypt_algorithm));
300 gcry_md_hash_buffer (GCRY_MD_MD5, hash, seed_pass, strlen (seed_pass));
303 expect = g_strjoin (
" ", hash_hex, *seed_hex, NULL);
310 ret = strcmp (expect, actual) ? 1 : 0;
int auth_method_name_valid(const gchar *name)
Check if name is a valid auth method name.
Definition authutils.c:91
int gvm_auth_radius_enabled(void)
Return whether libraries has been compiled with RADIUS support.
Definition authutils.c:56
gchar * get_md5_hash_from_string(const gchar *string)
Calculate the MD5 hash value for a given string.
Definition authutils.c:249
int gvm_authenticate_classic(const gchar *username, const gchar *password, const gchar *hash_arg)
Authenticate a credential pair against user file contents.
Definition authutils.c:274
static const gchar * authentication_methods[]
Array of string representations of the supported authentication methods.
Definition authutils.c:27
int gvm_auth_init(void)
Initializes Gcrypt.
Definition authutils.c:109
gchar * digest_hex(int gcrypt_algorithm, const guchar *digest)
Generate a hexadecimal representation of a message digest.
Definition authutils.c:175
gchar * get_password_hashes(const gchar *password)
Generate a pair of md5 hashes to be used in the "auth/hash" file for the user.
Definition authutils.c:210
static gboolean initialized
Flag whether the config file was read.
Definition authutils.c:33
int gvm_auth_ldap_enabled(void)
Return whether libraries has been compiled with LDAP support.
Definition authutils.c:41
const gchar * auth_method_name(auth_method_t method)
Return name of auth_method_t.
Definition authutils.c:76
Authentication mechanism(s).
enum authentication_method auth_method_t
Type for the numerical representation of the supported authentication methods.
Definition authutils.h:31
@ AUTHENTICATION_METHOD_LAST
Definition authutils.h:26