abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change
on this file since 00d21a1 was
8231b92,
checked in by Mike Ryan <mikeryan@…>, 13 years ago
|
add output dir option to creddy generate
closes #19
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[abd7c25] | 1 | #include <fcntl.h> |
---|
| 2 | |
---|
| 3 | #include <credentials/keys/private_key.h> |
---|
| 4 | |
---|
[04f5da1] | 5 | #include <creddy.h> |
---|
| 6 | |
---|
| 7 | #include "creddy_common.h" |
---|
[abd7c25] | 8 | |
---|
| 9 | void generate_main(options_t *opts) { |
---|
[39fed7c] | 10 | int ret, fd; |
---|
| 11 | creddy_id_t *id; |
---|
| 12 | char *filename; |
---|
| 13 | FILE *out; |
---|
| 14 | |
---|
[595a885] | 15 | // make sure we have at least a CN |
---|
| 16 | if (opts->cn == NULL) |
---|
| 17 | usage(opts); |
---|
| 18 | |
---|
[8231b92] | 19 | // if we have an outdir, chdir there |
---|
| 20 | if (opts->out) { |
---|
| 21 | ret = chdir(opts->out); |
---|
| 22 | if (ret < 0) |
---|
| 23 | err(1, "can't open output directory '%s'", opts->out); |
---|
| 24 | } |
---|
| 25 | |
---|
[a0772a2] | 26 | printf("Generating key, this will take a while. Create entropy!\n"); |
---|
| 27 | printf(" - move the mouse\n"); |
---|
| 28 | printf(" - generate disk activity (run find)\n"); |
---|
[abd7c25] | 29 | |
---|
[39fed7c] | 30 | ret = creddy_id_generate(&id, opts->cn, opts->validity); |
---|
[abd7c25] | 31 | |
---|
[a0772a2] | 32 | if (ret == CREDDY_GENERATE_INVALID_CN) { |
---|
[abd7c25] | 33 | printf("Invalid CN: must start with a letter and be alphanumeric\n"); |
---|
| 34 | usage(opts); |
---|
| 35 | } |
---|
[a0772a2] | 36 | if (ret == CREDDY_GENERATE_INVALID_VALIDITY) { |
---|
[abd7c25] | 37 | printf("Validity must be >= 1 day\n"); |
---|
| 38 | usage(opts); |
---|
| 39 | } |
---|
[39fed7c] | 40 | // in both above cases: usage(opts) exits |
---|
[a0772a2] | 41 | |
---|
[39fed7c] | 42 | // |
---|
| 43 | // success! |
---|
| 44 | // |
---|
[abd7c25] | 45 | |
---|
[39fed7c] | 46 | // write the cert |
---|
| 47 | filename = creddy_id_cert_filename(id); |
---|
| 48 | out = fopen(filename, "w"); |
---|
| 49 | creddy_id_write_cert(id, out); |
---|
| 50 | fclose(out); |
---|
[abd7c25] | 51 | free(filename); |
---|
| 52 | |
---|
[39fed7c] | 53 | // write the key |
---|
| 54 | filename = creddy_id_privkey_filename(id); |
---|
| 55 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); // mode 600 |
---|
[abd7c25] | 56 | if (fd < 0) |
---|
[39fed7c] | 57 | err(1, "Can't open private key file %s", filename); |
---|
| 58 | out = fdopen(fd, "w"); |
---|
| 59 | creddy_id_write_privkey(id, out); |
---|
[abd7c25] | 60 | fclose(out); |
---|
| 61 | |
---|
[39fed7c] | 62 | creddy_id_free(id); |
---|
[abd7c25] | 63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.