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