source: creddy/generate.c @ 595a885

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since 595a885 was 595a885, checked in by Mike Ryan <mikeryan@…>, 13 years ago

check for CN arg

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[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
9void 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
[a0772a2]19    printf("Generating key, this will take a while. Create entropy!\n");
20    printf("    - move the mouse\n");
21    printf("    - generate disk activity (run find)\n");
[abd7c25]22
[39fed7c]23    ret = creddy_id_generate(&id, opts->cn, opts->validity);
[abd7c25]24
[a0772a2]25    if (ret == CREDDY_GENERATE_INVALID_CN) {
[abd7c25]26        printf("Invalid CN: must start with a letter and be alphanumeric\n");
27        usage(opts);
28    }
[a0772a2]29    if (ret == CREDDY_GENERATE_INVALID_VALIDITY) {
[abd7c25]30        printf("Validity must be >= 1 day\n");
31        usage(opts);
32    }
[39fed7c]33    // in both above cases: usage(opts) exits
[a0772a2]34
[39fed7c]35    //
36    // success!
37    //
[abd7c25]38
[39fed7c]39    // write the cert
40    filename = creddy_id_cert_filename(id);
41    out = fopen(filename, "w");
42    creddy_id_write_cert(id, out);
43    fclose(out);
[abd7c25]44    free(filename);
45
[39fed7c]46    // write the key
47    filename = creddy_id_privkey_filename(id);
48    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); // mode 600
[abd7c25]49    if (fd < 0)
[39fed7c]50        err(1, "Can't open private key file %s", filename);
51    out = fdopen(fd, "w");
52    creddy_id_write_privkey(id, out);
[abd7c25]53    fclose(out);
54
[39fed7c]55    creddy_id_free(id);
[abd7c25]56}
Note: See TracBrowser for help on using the repository browser.