summaryrefslogtreecommitdiff
path: root/cleopatre
diff options
context:
space:
mode:
authorJulien Lacour2013-10-22 10:09:18 +0200
committerJulien Lacour2013-11-05 16:58:01 +0100
commit860eadf7be95eddb9005167ddcf143b84e48bacc (patch)
tree49fc5952349037c3824f620165d2247efcae2635 /cleopatre
parent825997147e1d9a67d11ed4023d0aa36ae30443c4 (diff)
cleo/app/{libspid,spidapp}: factorize 'nmk gen from npw' code, refs #4257
Diffstat (limited to 'cleopatre')
-rw-r--r--cleopatre/application/libspid/inc/libspid.h1
-rw-r--r--cleopatre/application/libspid/src/secu.c37
-rw-r--r--cleopatre/application/spidapp/src/spidapp.c19
3 files changed, 40 insertions, 17 deletions
diff --git a/cleopatre/application/libspid/inc/libspid.h b/cleopatre/application/libspid/inc/libspid.h
index b47cb75354..0cd34765f4 100644
--- a/cleopatre/application/libspid/inc/libspid.h
+++ b/cleopatre/application/libspid/inc/libspid.h
@@ -186,6 +186,7 @@ extern libspid_error_t libspid_system_file_update_unregister (pid_t rx_pid, cons
extern libspid_error_t libspid_system_file_update_is_registered (pid_t rx_pid, const char *filename, libspid_boolean_t *is_registered);
extern libspid_error_t libspid_system_file_update_warn (pid_t tx_pid, const char *filename);
extern libspid_error_t libspid_secu_pbkdf1 (const unsigned char input[], const unsigned int input_length, const libspid_secu_salt_type_t salt_type, const unsigned int it_count, unsigned char output[], unsigned int output_length);
+extern libspid_error_t libspid_secu_nmk_update (const unsigned char npw[]);
extern libspid_error_t
libspid_multicast_info_read_file (libspid_multicast_info_t *mcast_info,
diff --git a/cleopatre/application/libspid/src/secu.c b/cleopatre/application/libspid/src/secu.c
index d2be8eb2b8..66f4e45783 100644
--- a/cleopatre/application/libspid/src/secu.c
+++ b/cleopatre/application/libspid/src/secu.c
@@ -17,6 +17,7 @@
#include <string.h>
#include <assert.h>
#include "libspid.h"
+#include <syslog.h>
static void
libspid_secu_sha256 (unsigned char *data, unsigned int length, unsigned char *output)
@@ -89,7 +90,12 @@ secu_pbkdf1 (const unsigned char input[], const unsigned int input_length,
* \return error type (LIBSPID_SUCCESS if success)
* \return LIBSPID_ERROR_PARAM: bad input parameters
*/
-libspid_error_t libspid_secu_pbkdf1 (const unsigned char input[], const unsigned int input_length, const libspid_secu_salt_type_t salt_type, const unsigned int it_count, unsigned char output[], unsigned int output_length)
+libspid_error_t libspid_secu_pbkdf1 (const unsigned char input[],
+ const unsigned int input_length,
+ const libspid_secu_salt_type_t salt_type,
+ const unsigned int it_count,
+ unsigned char output[],
+ unsigned int output_length)
{
unsigned char *pbkdf1;
/* The salt to use for the PBKDF1 function. */
@@ -125,4 +131,31 @@ libspid_error_t libspid_secu_pbkdf1 (const unsigned char input[], const unsigned
return LIBSPID_SUCCESS;
}
-
+/** Generate nmk from npw, and activate it (/etc/hpav.conf). */
+libspid_error_t libspid_secu_nmk_update (const unsigned char npw[])
+{
+ unsigned char nmk_bin[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0};
+ char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN] = {0};
+
+ libspid_error_t ret;
+ ret = libspid_secu_pbkdf1 (npw, strlen ((char *) npw),
+ LIBSPID_SECU_SALT_TYPE_NMK,
+ LIBSPID_SECU_PBKDF1_ITERATION,
+ nmk_bin, LIBSPID_SECU_OUTPUT_KEY_SIZE);
+ if (ret == LIBSPID_SUCCESS)
+ {
+ ret = libspid_binary_to_hexstring (nmk_bin,
+ LIBSPID_HPAV_CONF_NMK_BIN_LEN, nmk_str);
+ }
+ if (ret == LIBSPID_SUCCESS)
+ {
+ ret = libspid_config_write_item (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str);
+ }
+ if (ret != LIBSPID_SUCCESS)
+ {
+ syslog (LOG_ERR, "%s: libspid error\n",
+ LIBSPID_HPAV_CONF_LABEL_NMK);
+ }
+ return ret;
+}
diff --git a/cleopatre/application/spidapp/src/spidapp.c b/cleopatre/application/spidapp/src/spidapp.c
index e1dc6644e4..f72863980c 100644
--- a/cleopatre/application/spidapp/src/spidapp.c
+++ b/cleopatre/application/spidapp/src/spidapp.c
@@ -57,9 +57,7 @@ cmd_config (struct cmd_entry *cmd_entry, int argc, char **argv)
{
libspid_boolean_t save_and_warn = LIBSPID_FALSE;
int c = 0, i = 0, opt_index = 0;
- char npw[LIBSPID_HPAV_CONF_NPW_MAX_LEN] = {0},
- nmk_bin[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0},
- nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN] = {0};
+ char npw[LIBSPID_HPAV_CONF_NPW_MAX_LEN] = {0};
struct option long_opts[] =
{
@@ -149,21 +147,12 @@ cmd_config (struct cmd_entry *cmd_entry, int argc, char **argv)
printf ("NPW: cannot be created using less than 8 or more than 64 characters\n");
return -1;
}
- if ((LIBSPID_SUCCESS != libspid_secu_pbkdf1 (npw, strlen (npw),
- LIBSPID_SECU_SALT_TYPE_NMK, LIBSPID_SECU_PBKDF1_ITERATION,
- nmk_bin, LIBSPID_SECU_OUTPUT_KEY_SIZE))
- || (LIBSPID_SUCCESS != libspid_binary_to_hexstring (nmk_bin,
- LIBSPID_HPAV_CONF_NMK_BIN_LEN, nmk_str))
- || (LIBSPID_SUCCESS != libspid_config_write_item \
- (LIBSPID_HPAV_CONF_PATH,
- LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str)))
+ if (LIBSPID_SUCCESS != libspid_secu_nmk_update (npw))
{
- printf ("%s: libspid error\n",
- LIBSPID_HPAV_CONF_LABEL_NMK);
return -1;
}
- printf ("%s: updated (%s)\n",
- LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str);
+ printf ("%s: updated (see %s)\n", LIBSPID_HPAV_CONF_LABEL_NMK,
+ LIBSPID_HPAV_CONF_PATH);
save_and_warn = LIBSPID_TRUE;
break;
case 'n':