]> git.pld-linux.org Git - packages/ntp.git/blame - ntp-4.2.4p2-noseed.patch
- release 4
[packages/ntp.git] / ntp-4.2.4p2-noseed.patch
CommitLineData
6fca7355
ER
1--- ntp-4.2.4p2/html/keygen.html.noseed 2007-07-18 16:03:45.000000000 +0200
2+++ ntp-4.2.4p2/html/keygen.html 2007-07-18 16:03:33.000000000 +0200
3@@ -102,6 +102,7 @@
4 <p>All cryptographically sound key generation schemes must have means to randomize the entropy seed used to initialize the internal pseudo-random number generator used by the library routines. The OpenSSL library uses a designated random seed file for this purpose. The file must be available when starting the NTP daemon and <tt>ntp-keygen</tt> program. If a site supports OpenSSL or its companion OpenSSH, it is very likely that means to do this are already available.</p>
5 <p>It is important to understand that entropy must be evolved for each generation, for otherwise the random number sequence would be predictable. Various means dependent on external events, such as keystroke intervals, can be used to do this and some systems have built-in entropy sources. Suitable means are described in the OpenSSL software documentation, but are outside the scope of this page.</p>
6 <p>The entropy seed used by the OpenSSL library is contained in a file, usually called <tt>.rnd</tt>, which must be available when starting the NTP daemon or the <tt>ntp-keygen</tt> program. The NTP daemon will first look for the file using the path specified by the <tt>randfile</tt> subcommand of the <tt>crypto</tt> configuration command. If not specified in this way, or when starting the <tt>ntp-keygen</tt> program, the OpenSSL library will look for the file using the path specified by the <tt>RANDFILE</tt> environment variable in the user home directory, whether root or some other user. If the <tt>RANDFILE</tt> environment variable is not present, the library will look for the <tt>.rnd</tt> file in the user home directory. If the file is not available or cannot be written, the daemon exits with a message to the system log and the program exits with a suitable error message.</p>
7+ <p>On systems that provide /dev/urandom, the randomness device is used instead and the file specified by the <tt>randfile</tt> subcommand or the <tt>RANDFILE</tt> environment variable is ignored.</p>
8 <h4 id="priv">Cryptographic Data Files</h4>
9 <p>All other file formats begin with two lines. The first contains the file name, including the generated host name and filestamp. The second contains the datestamp in conventional Unix <tt>date</tt> format. Lines beginning with <tt>#</tt> are considered comments and ignored by the <i><tt>ntp-keygen </tt></i>program and <tt>ntpd</tt> daemon. Cryptographic values are encoded first using ASN.1 rules, then encrypted if necessary, and finally written PEM-encoded printable ASCII format preceded and followed by MIME content identifier lines.</p>
10 <p id="symkey">The format of the symmetric keys file is somewhat different than the other files in the interest of backward compatibility. Since DES-CBC is deprecated in NTPv4, the only key format of interest is MD5 alphanumeric strings. Following hte heard the keys are entered one per line in the format</p>
11--- ntp-4.2.4p2/util/ntp-keygen.c.noseed 2007-06-20 13:03:23.000000000 +0200
12+++ ntp-4.2.4p2/util/ntp-keygen.c 2007-07-18 16:03:45.000000000 +0200
13@@ -362,20 +362,24 @@ main(
14 */
15 ERR_load_crypto_strings();
16 OpenSSL_add_all_algorithms();
17- if (RAND_file_name(pathbuf, MAXFILENAME) == NULL) {
18- fprintf(stderr, "RAND_file_name %s\n",
19- ERR_error_string(ERR_get_error(), NULL));
20- return (-1);
21- }
22- temp = RAND_load_file(pathbuf, -1);
23- if (temp == 0) {
24+
25+ /* But only if openssl doesn't use /dev/urandom */
26+ if (RAND_status() != 1) {
27+ if (RAND_file_name(pathbuf, MAXFILENAME) == NULL) {
28+ fprintf(stderr, "RAND_file_name %s\n",
29+ ERR_error_string(ERR_get_error(), NULL));
30+ return (-1);
31+ }
32+ temp = RAND_load_file(pathbuf, -1);
33+ if (temp == 0) {
34+ fprintf(stderr,
35+ "RAND_load_file %s not found or empty\n", pathbuf);
36+ return (-1);
37+ }
38 fprintf(stderr,
39- "RAND_load_file %s not found or empty\n", pathbuf);
40- return (-1);
41+ "Random seed file %s %u bytes\n", pathbuf, temp);
42+ RAND_add(&epoch, sizeof(epoch), 4.0);
43 }
44- fprintf(stderr,
45- "Random seed file %s %u bytes\n", pathbuf, temp);
46- RAND_add(&epoch, sizeof(epoch), 4.0);
47 #endif
48
49 /*
50--- ntp-4.2.4p2/ntpd/ntp_crypto.c.noseed 2006-12-28 13:03:28.000000000 +0100
51+++ ntp-4.2.4p2/ntpd/ntp_crypto.c 2007-07-18 16:03:45.000000000 +0200
52@@ -3878,6 +3878,9 @@ crypto_setup(void)
53 memset(&pubkey, 0, sizeof(pubkey));
54 memset(&tai_leap, 0, sizeof(tai_leap));
55
56+ ERR_load_crypto_strings();
57+ OpenSSL_add_all_algorithms();
58+
59 /*
60 * Load required random seed file and seed the random number
61 * generator. Be default, it is found in the user home
62@@ -3885,40 +3888,49 @@ crypto_setup(void)
63 * depending on the system. Wiggle the contents a bit and write
64 * it back so the sequence does not repeat when we next restart.
65 */
66- ERR_load_crypto_strings();
67- if (rand_file == NULL) {
68- if ((RAND_file_name(filename, MAXFILENAME)) != NULL) {
69+
70+ /* But only if openssl doesn't use /dev/urandom */
71+ if (RAND_status() != 1) {
72+ if (rand_file == NULL) {
73+ if ((RAND_file_name(filename, MAXFILENAME)) != NULL) {
74+ rand_file = emalloc(strlen(filename) + 1);
75+ strcpy(rand_file, filename);
76+ }
77+ } else if (*rand_file != '/') {
78+ snprintf(filename, MAXFILENAME, "%s/%s", keysdir,
79+ rand_file);
80+ free(rand_file);
81 rand_file = emalloc(strlen(filename) + 1);
82 strcpy(rand_file, filename);
83 }
84- } else if (*rand_file != '/') {
85- snprintf(filename, MAXFILENAME, "%s/%s", keysdir,
86- rand_file);
87- free(rand_file);
88- rand_file = emalloc(strlen(filename) + 1);
89- strcpy(rand_file, filename);
90- }
91- if (rand_file == NULL) {
92- msyslog(LOG_ERR,
93- "crypto_setup: random seed file not specified");
94- exit (-1);
95- }
96- if ((bytes = RAND_load_file(rand_file, -1)) == 0) {
97- msyslog(LOG_ERR,
98- "crypto_setup: random seed file %s not found\n",
99- rand_file);
100- exit (-1);
101- }
102- get_systime(&seed);
103- RAND_seed(&seed, sizeof(l_fp));
104- RAND_write_file(rand_file);
105- OpenSSL_add_all_algorithms();
106+ if (rand_file == NULL) {
107+ msyslog(LOG_ERR,
108+ "crypto_setup: random seed file not specified");
109+ exit (-1);
110+ }
111+ if ((bytes = RAND_load_file(rand_file, -1)) == 0) {
112+ msyslog(LOG_ERR,
113+ "crypto_setup: random seed file %s not found\n",
114+ rand_file);
115+ exit (-1);
116+ }
117+ get_systime(&seed);
118+ RAND_seed(&seed, sizeof(l_fp));
119+ RAND_write_file(rand_file);
120 #ifdef DEBUG
121- if (debug)
122- printf(
123- "crypto_setup: OpenSSL version %lx random seed file %s bytes read %d\n",
124- SSLeay(), rand_file, bytes);
125+ if (debug)
126+ printf(
127+ "crypto_setup: OpenSSL version %lx random seed file %s bytes read %d\n",
128+ SSLeay(), rand_file, bytes);
129 #endif
130+ } else {
131+#ifdef DEBUG
132+ if (debug)
133+ printf(
134+ "crypto_setup: OpenSSL version %lx seeding not required\n",
135+ SSLeay());
136+#endif
137+ }
138
139 /*
140 * Load required host key from file "ntpkey_host_<hostname>". It
This page took 0.048369 seconds and 4 git commands to generate.