ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/gvpectrl.C
(Generate patch)

Comparing gvpe/src/gvpectrl.C (file contents):
Revision 1.13 by root, Fri Jul 5 10:04:22 2013 UTC vs.
Revision 1.19 by root, Wed Jun 29 22:36:23 2016 UTC

75static int quiet; 75static int quiet;
76 76
77/* If nonzero, generate public/private keypair for this net. */ 77/* If nonzero, generate public/private keypair for this net. */
78static int generate_keys; 78static int generate_keys;
79 79
80// output some debugging info, interna constants &c
81static int debug_info;
82
80static struct option const long_options[] = 83static struct option const long_options[] =
81{ 84{
82 {"config", required_argument, NULL, 'c'}, 85 {"config", required_argument, NULL, 'c'},
83 {"kill", optional_argument, NULL, 'k'}, 86 {"kill", optional_argument, NULL, 'k'},
84 {"help", no_argument, &show_help, 1}, 87 {"help", no_argument, &show_help, 1},
85 {"version", no_argument, &show_version, 1}, 88 {"version", no_argument, &show_version, 1},
86 {"generate-keys", no_argument, NULL, 'g'}, 89 {"generate-keys", no_argument, NULL, 'g'},
87 {"quiet", no_argument, &quiet, 1}, 90 {"quiet", no_argument, &quiet, 1},
88 {"show-config", no_argument, &show_config, 's'}, 91 {"show-config", no_argument, &show_config, 's'},
92 {"debug-info", no_argument, &debug_info, 1},
89 {NULL, 0, NULL, 0} 93 {NULL, 0, NULL, 0}
90}; 94};
91 95
92static void 96static void
93usage (int status) 97usage (int status)
163 kill_gvpe = SIGTERM; 167 kill_gvpe = SIGTERM;
164 168
165 break; 169 break;
166 170
167 case 'g': /* generate public/private keypair */ 171 case 'g': /* generate public/private keypair */
168 generate_keys = RSA_KEYBITS; 172 generate_keys = RSABITS;
169 break; 173 break;
170 174
171 case 's': 175 case 's':
172 show_config = 1; 176 show_config = 1;
173 break; 177 break;
233 * generate public/private RSA keypairs for all hosts that don't have one. 237 * generate public/private RSA keypairs for all hosts that don't have one.
234 */ 238 */
235static int 239static int
236keygen (int bits) 240keygen (int bits)
237{ 241{
238 FILE *f; 242 FILE *f, *pubf;
239 char *name = NULL;
240 char *fname; 243 char *fname;
241
242 asprintf (&fname, "%s/hostkeys", confbase);
243 mkdir (fname, 0700);
244 free (fname);
245 244
246 asprintf (&fname, "%s/pubkey", confbase); 245 asprintf (&fname, "%s/pubkey", confbase);
247 mkdir (fname, 0700); 246 mkdir (fname, 0700);
248 free (fname); 247 free (fname);
249 248
250 for (configuration::node_vector::iterator i = conf.nodes.begin (); i != conf.nodes.end (); ++i) 249 for (configuration::node_vector::iterator i = conf.nodes.begin (); i != conf.nodes.end (); ++i)
251 { 250 {
252 conf_node *node = *i; 251 conf_node *node = *i;
253 252
254 asprintf (&fname, "%s/pubkey/%s", confbase, node->nodename); 253 ::thisnode = node->nodename;
255 254
255 fname = conf.config_filename (conf.prikeyfile, "hostkey");
256
256 f = fopen (fname, "a"); 257 f = fopen (fname, "ab");
257 258
258 /* some libcs are buggy and require an extra seek to the end */ 259 /* some libcs are buggy and require an extra seek to the end */
259 if (!f || fseek (f, 0, SEEK_END)) 260 if (!f || fseek (f, 0, SEEK_END))
260 { 261 {
261 perror (fname); 262 perror (fname);
263 } 264 }
264 265
265 if (ftell (f)) 266 if (ftell (f))
266 { 267 {
267 if (!quiet) 268 if (!quiet)
268 fprintf (stderr, "'%s' already exists, skipping this node %d\n", 269 fprintf (stderr, "'%s' already exists, skipping node %s\n", fname, node->nodename);
269 fname, quiet);
270 270
271 free (fname);
271 fclose (f); 272 fclose (f);
272 continue; 273 continue;
273 } 274 }
274 275
276 free (fname);
277
275 fprintf (stderr, _("generating %d bits key for %s:\n"), bits, 278 fprintf (stderr, _("generating %d bits key for %s:\n"), bits, node->nodename);
276 node->nodename);
277 279
278 RSA *rsa = RSA_new (); 280 RSA *rsa = RSA_new ();
279 BIGNUM *e = BN_new (); 281 BIGNUM *e = BN_new ();
280 BN_set_bit (e, 0); BN_set_bit (e, 16); // 0x10001, 65537 282 BN_set_bit (e, 0); BN_set_bit (e, 16); // 0x10001, 65537
283
284#if OPENSSL_VERSION_NUMBER < 0x10100000
281 BN_GENCB cb; 285 BN_GENCB cb;
282 BN_GENCB_set (&cb, indicator, 0); 286 BN_GENCB_set (&cb, indicator, 0);
283
284 require (RSA_generate_key_ex (rsa, bits, e, &cb)); 287 require (RSA_generate_key_ex (rsa, bits, e, &cb));
288#else
289 BN_GENCB *cb = BN_GENCB_new ();
290 BN_GENCB_set (cb, indicator, 0);
291 require (RSA_generate_key_ex (rsa, bits, e, cb));
292#endif
285 293
286 fprintf (stderr, _("Done.\n")); 294 fprintf (stderr, _("Done.\n"));
287 295
288 require (PEM_write_RSAPublicKey (f, rsa)); 296 fname = conf.config_filename ("pubkey/%s", 0);
289 fclose (f);
290 free (fname);
291
292 asprintf (&fname, "%s/hostkeys/%s", confbase, node->nodename);
293
294 f = fopen (fname, "a"); 297 pubf = fopen (fname, "wb");
295 if (!f) 298 if (!pubf)
296 { 299 {
297 perror (fname); 300 perror (fname);
298 exit (EXIT_FAILURE); 301 exit (EXIT_FAILURE);
299 } 302 }
300 303
304 free (fname);
305
306 require (PEM_write_RSAPublicKey (pubf, rsa));
307 fclose (pubf);
308
301 require (PEM_write_RSAPrivateKey (f, rsa, NULL, NULL, 0, NULL, NULL)); 309 require (PEM_write_RSAPrivateKey (f, rsa, NULL, NULL, 0, NULL, NULL));
302 fclose (f); 310 fclose (f);
303 free (fname);
304 311
305 BN_free (e); 312 BN_free (e);
306 RSA_free (rsa); 313 RSA_free (rsa);
307 } 314 }
308 315
341 348
342 { 349 {
343 configuration_parser (conf, false, 0, 0); 350 configuration_parser (conf, false, 0, 0);
344 } 351 }
345 352
353 if (debug_info)
354 {
355 printf ("cipher_nid=%d\n", EVP_CIPHER_nid (CIPHER ()));
356 printf ("mac_nid=%d\n", EVP_MD_type (MAC_DIGEST ()));
357 printf ("auth_nid=%d\n", EVP_MD_type (AUTH_DIGEST ()));
358 printf ("sizeof_auth_data=%d\n", sizeof (auth_data));
359 printf ("sizeof_rsa_data=%d\n", sizeof (rsa_data));
360 printf ("sizeof_rsa_data_extra_auth=%d\n", sizeof (((rsa_data *)0)->extra_auth));
361 printf ("raw_overhead=%d\n", VPE_OVERHEAD);
362 printf ("vpn_overhead=%d\n", VPE_OVERHEAD + 6 + 6);
363 printf ("udp_overhead=%d\n", UDP_OVERHEAD + VPE_OVERHEAD + 6 + 6);
364 exit (EXIT_SUCCESS);
365 }
366
346 if (generate_keys) 367 if (generate_keys)
347 { 368 {
348 RAND_load_file ("/dev/urandom", 1024); 369 RAND_load_file (conf.seed_dev, SEED_SIZE);
349 exit (keygen (generate_keys)); 370 exit (keygen (generate_keys));
350 } 371 }
351 372
352 if (kill_gvpe) 373 if (kill_gvpe)
353 exit (kill_other (kill_gvpe)); 374 exit (kill_other (kill_gvpe));
358 exit (EXIT_SUCCESS); 379 exit (EXIT_SUCCESS);
359 } 380 }
360 381
361 usage (1); 382 usage (1);
362} 383}
384

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines