Browse Source

Add password encryption mode.

tags/0.9.0
Vsevolod Stakhov 9 years ago
parent
commit
c385e1f395
3 changed files with 54 additions and 7 deletions
  1. 1
    7
      src/controller.c
  2. 46
    0
      src/main.c
  3. 7
    0
      src/main.h

+ 1
- 7
src/controller.c View File

@@ -133,14 +133,8 @@ struct rspamd_controller_session {
gboolean is_spam;
};

struct rspamd_controller_pbkdf {
gint id;
guint rounds;
gsize salt_len;
gsize key_len;
};

static const struct rspamd_controller_pbkdf pbkdf_list[] = {
const struct rspamd_controller_pbkdf pbkdf_list[] = {
{
.id = RSPAMD_PBKDF_ID_V1,
.rounds = 16000,

+ 46
- 0
src/main.c View File

@@ -84,6 +84,7 @@ static gboolean dump_cache = FALSE;
static gboolean is_debug = FALSE;
static gboolean is_insecure = FALSE;
static gboolean gen_keypair = FALSE;
static gboolean encrypt_password = FALSE;
/* List of workers that are pending to start */
static GList *workers_pending = NULL;

@@ -129,9 +130,12 @@ static GOptionEntry entries[] =
"Specify private key to sign", NULL },
{ "gen-keypair", 0, 0, G_OPTION_ARG_NONE, &gen_keypair, "Generate new encryption "
"keypair", NULL},
{ "encrypt-password", 0, 0, G_OPTION_ARG_NONE, &encrypt_password, "Encrypt "
"controller password to store in the configuration file", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};

extern const struct rspamd_controller_pbkdf pbkdf_list[];

#ifndef HAVE_SA_SIGINFO
static void
@@ -1037,6 +1041,43 @@ perform_configs_sign (void)
#endif
}

static void
do_encrypt_password (void)
{
const struct rspamd_controller_pbkdf *pbkdf;
guchar *salt, *key;
gchar *encoded_salt, *encoded_key;
gchar password[BUFSIZ];
gsize plen;

pbkdf = &pbkdf_list[0];
g_assert (pbkdf != NULL);

plen = rspamd_read_passphrase (password, sizeof (password), 0, NULL);

if (plen == 0) {
fprintf (stderr, "Invalid password\n");
exit (EXIT_FAILURE);
}

salt = g_alloca (pbkdf->salt_len);
key = g_alloca (pbkdf->key_len);
ottery_rand_bytes (salt, pbkdf->salt_len);
/* Derive key */
rspamd_cryptobox_pbkdf (password, strlen (password),
salt, pbkdf->salt_len, key, pbkdf->key_len, pbkdf->rounds);

encoded_salt = rspamd_encode_base32 (salt, pbkdf->salt_len);
encoded_key = rspamd_encode_base32 (key, pbkdf->key_len);

rspamd_printf ("$%d$%s$%s\n", pbkdf->id, encoded_salt,
encoded_key);

g_free (encoded_salt);
g_free (encoded_key);
rspamd_explicit_memzero (password, sizeof (password));
}

static void
rspamd_init_main (struct rspamd_main *rspamd)
{
@@ -1140,6 +1181,11 @@ main (gint argc, gchar **argv, gchar **env)
exit (EXIT_SUCCESS);
}

if (encrypt_password) {
do_encrypt_password ();
exit (EXIT_SUCCESS);
}

if (rspamd_main->cfg->config_test || dump_cache) {
if (!load_rspamd_config (rspamd_main->cfg, FALSE)) {
exit (EXIT_FAILURE);

+ 7
- 0
src/main.h View File

@@ -69,6 +69,13 @@ struct rspamd_worker_signal_handler {
void *handler_data;
};

struct rspamd_controller_pbkdf {
gint id;
guint rounds;
gsize salt_len;
gsize key_len;
};


/**
* Module

Loading…
Cancel
Save