* dumpdir directive:: Specify directory for dumping measurements
* dumponexit directive:: Dump measurements when daemon exits
* fallbackdrift directive:: Specify fallback drift intervals
+* generatecommandkey directive:: Generate command key automatically
* include directive:: Include a configuration file
* initstepslew directive:: Trim the system clock on boot-up.
* keyfile directive:: Specify location of file containing keys
the form
@example
-20 foobar
+20 MD5 HEX:B028F91EA5C38D06C2E140B26C7F41EC
@end example
When running the chronyc program to perform run-time configuration,
will be used and the clock frequency will stay at the last value
calculated before synchronisation was lost.
@c }}}
+@c {{{ generatecommandkey
+@node generatecommandkey directive
+@subsection generatecommandkey
+With this directive, if the command key is not found on start in the file
+specified by the @code{keyfile} directive, @code{chronyd} will generate a new
+command key from the /dev/urandom file and write it to the key file.
+
+The generated key will use SHA1 if @code{chronyd} is compiled with the support,
+otherwise MD5 will be used.
+@c }}}
@c {{{ include
@node include directive
@subsection include
optional @code{ASCII:} prefix or as a hexadecimal number with @code{HEX:}
prefix.
-The ID for the chronyc authentication key is specified with the
-commandkey command (see earlier).
+The ID for the chronyc authentication key is specified with the commandkey
+command (see earlier). The command key can be generated automatically on
+start with the @code{generatecommandkey} directive.
@c }}}
@c {{{ leapsectz
@node leapsectz directive
static void parse_dumpdir(char *);
static void parse_dumponexit(char *);
static void parse_fallbackdrift(char *);
+static void parse_generatecommandkey(char *);
static void parse_include(char *);
static void parse_initstepslew(char *);
static void parse_keyfile(char *);
/* Configuration variables */
static int restarted = 0;
+static int generate_command_key = 0;
static char *rtc_device = "/dev/rtc";
static int acquisition_port = 0; /* 0 means let kernel choose port */
static int ntp_port = 123;
parse_dumponexit(p);
} else if (!strcasecmp(command, "fallbackdrift")) {
parse_fallbackdrift(p);
+ } else if (!strcasecmp(command, "generatecommandkey")) {
+ parse_generatecommandkey(p);
} else if (!strcasecmp(command, "include")) {
parse_include(p);
} else if (!strcasecmp(command, "initstepslew")) {
/* ================================================== */
+static void
+parse_generatecommandkey(char *line)
+{
+ check_number_of_args(line, 0);
+ generate_command_key = 1;
+}
+
+/* ================================================== */
+
static void
parse_makestep(char *line)
{
/* ================================================== */
+int
+CNF_GetGenerateCommandKey(void)
+{
+ return generate_command_key;
+}
+
+/* ================================================== */
+
int
CNF_GetDumpOnExit(void)
{
extern char *CNF_GetKeysFile(void);
extern char *CNF_GetRtcFile(void);
extern unsigned long CNF_GetCommandKey(void);
+extern int CNF_GetGenerateCommandKey(void);
extern int CNF_GetDumpOnExit(void);
extern int CNF_GetManualEnabled(void);
extern int CNF_GetCommandPort(void);
HASH_OBJ="hash_nss.o"
HASH_COMPILE="$test_cflags"
HASH_LINK="$test_link"
+ add_def GENERATE_SHA1_KEY
fi
fi
HASH_OBJ="hash_tomcrypt.o"
HASH_COMPILE="-I/usr/include/tomcrypt"
HASH_LINK="-ltomcrypt"
+ add_def GENERATE_SHA1_KEY
fi
fi
/* ================================================== */
+static int
+generate_key(unsigned long key_id)
+{
+#ifdef GENERATE_SHA1_KEY
+ unsigned char key[20];
+ const char *hashname = "SHA1";
+#else
+ unsigned char key[16];
+ const char *hashname = "MD5";
+#endif
+ const char *key_file, *rand_dev = "/dev/urandom";
+ FILE *f;
+ struct stat st;
+ int i;
+
+ key_file = CNF_GetKeysFile();
+
+ if (!key_file)
+ return 0;
+
+ f = fopen(rand_dev, "r");
+ if (!f || fread(key, sizeof (key), 1, f) != 1) {
+ if (f)
+ fclose(f);
+ LOG_FATAL(LOGF_Keys, "Could not read %s", rand_dev);
+ return 0;
+ }
+ fclose(f);
+
+ f = fopen(key_file, "a");
+ if (!f) {
+ LOG_FATAL(LOGF_Keys, "Could not open keyfile %s for writing", key_file);
+ return 0;
+ }
+
+ /* Make sure the keyfile is not world-readable */
+ if (stat(key_file, &st) || chmod(key_file, st.st_mode & 0770)) {
+ fclose(f);
+ LOG_FATAL(LOGF_Keys, "Could not change permissions of keyfile %s", key_file);
+ return 0;
+ }
+
+ fprintf(f, "\n%lu %s HEX:", key_id, hashname);
+ for (i = 0; i < sizeof (key); i++)
+ fprintf(f, "%02hhX", key[i]);
+ fprintf(f, "\n");
+ fclose(f);
+
+ /* Erase the key from stack */
+ memset(key, sizeof (key), 0);
+
+ LOG(LOGS_INFO, LOGF_Keys, "Generated key %lu", key_id);
+
+ return 1;
+}
+
+/* ================================================== */
+
void
KEY_Initialise(void)
{
command_key_valid = 0;
cache_valid = 0;
KEY_Reload();
+
+ if (CNF_GetGenerateCommandKey() && !KEY_KeyKnown(KEY_GetCommandKey())) {
+ if (generate_key(KEY_GetCommandKey()))
+ KEY_Reload();
+ }
+
return;
}
TMC_Finalise();
MNL_Finalise();
ACQ_Finalise();
- KEY_Finalise();
CLG_Finalise();
NSR_Finalise();
NCR_Finalise();
BRD_Finalise();
SST_Finalise();
REF_Finalise();
+ KEY_Finalise();
RCL_Finalise();
SRC_Finalise();
RTC_Finalise();
RTC_Initialise();
SRC_Initialise();
RCL_Initialise();
+ KEY_Initialise();
/* Command-line switch must have priority */
if (!sched_priority) {
NCR_Initialise();
NSR_Initialise();
CLG_Initialise();
- KEY_Initialise();
ACQ_Initialise();
MNL_Initialise();
TMC_Initialise();