| @@ -20,34 +20,27 @@ | | | @@ -20,34 +20,27 @@ |
20 | */ | | 20 | */ |
21 | | | 21 | |
22 | /** | | 22 | /** |
23 | \file Command line program to perform openpgp operations | | 23 | \file Command line program to perform openpgp operations |
24 | */ | | 24 | */ |
25 | | | 25 | |
26 | #include <stdio.h> | | 26 | #include <stdio.h> |
27 | #include <stdlib.h> | | 27 | #include <stdlib.h> |
28 | #include <string.h> | | 28 | #include <string.h> |
29 | #include <getopt.h> | | 29 | #include <getopt.h> |
30 | #include <libgen.h> | | 30 | #include <libgen.h> |
31 | #include <unistd.h> | | 31 | #include <unistd.h> |
32 | | | 32 | |
33 | #include <openpgpsdk/keyring.h> | | 33 | #include <openpgpsdk/openpgpsdk.h> |
34 | #include <openpgpsdk/crypto.h> | | | |
35 | #include <openpgpsdk/signature.h> | | | |
36 | #include <openpgpsdk/validate.h> | | | |
37 | #include <openpgpsdk/readerwriter.h> | | | |
38 | #include <openpgpsdk/std_print.h> | | | |
39 | #include <openpgpsdk/packet-show.h> | | | |
40 | #include <openpgpsdk/util.h> | | | |
41 | | | 34 | |
42 | #define DEFAULT_NUMBITS 2048 | | 35 | #define DEFAULT_NUMBITS 2048 |
43 | | | 36 | |
44 | #define MAXBUF 1024 | | 37 | #define MAXBUF 1024 |
45 | | | 38 | |
46 | static const char *usage = "%s --list-keys | --list-packets | --encrypt | --decrypt | --sign | --clearsign | --verify [--keyring=<keyring>] [--userid=<userid>] [--armour] [--homedir=<homedir>] files...\n"; | | 39 | static const char *usage = "%s --list-keys | --list-packets | --encrypt | --decrypt | --sign | --clearsign | --verify [--keyring=<keyring>] [--userid=<userid>] [--armour] [--homedir=<homedir>] files...\n"; |
47 | static const char *usage_find_key = "%s --find-key --userid=<userid> [--keyring=<keyring>] \n"; | | 40 | static const char *usage_find_key = "%s --find-key --userid=<userid> [--keyring=<keyring>] \n"; |
48 | static const char *usage_export_key = "%s --export-key --userid=<userid> [--keyring=<keyring>] \n"; | | 41 | static const char *usage_export_key = "%s --export-key --userid=<userid> [--keyring=<keyring>] \n"; |
49 | static const char *usage_encrypt = "%s --encrypt --userid=<userid> [--armour] [--homedir=<homedir>] files...\n"; | | 42 | static const char *usage_encrypt = "%s --encrypt --userid=<userid> [--armour] [--homedir=<homedir>] files...\n"; |
50 | static const char *usage_sign = "%s --sign --userid=<userid> [--armour] [--homedir=<homedir>] files...\n"; | | 43 | static const char *usage_sign = "%s --sign --userid=<userid> [--armour] [--homedir=<homedir>] files...\n"; |
51 | static const char *usage_clearsign = "%s --clearsign --userid=<userid> [--homedir=<homedir>] files...\n"; | | 44 | static const char *usage_clearsign = "%s --clearsign --userid=<userid> [--homedir=<homedir>] files...\n"; |
52 | | | 45 | |
53 | static char *pname; | | 46 | static char *pname; |
| @@ -55,26 +48,27 @@ static char *pname; | | | @@ -55,26 +48,27 @@ static char *pname; |
55 | enum optdefs { | | 48 | enum optdefs { |
56 | /* commands */ | | 49 | /* commands */ |
57 | LIST_KEYS = 1, | | 50 | LIST_KEYS = 1, |
58 | FIND_KEY, | | 51 | FIND_KEY, |
59 | EXPORT_KEY, | | 52 | EXPORT_KEY, |
60 | IMPORT_KEY, | | 53 | IMPORT_KEY, |
61 | GENERATE_KEY, | | 54 | GENERATE_KEY, |
62 | ENCRYPT, | | 55 | ENCRYPT, |
63 | DECRYPT, | | 56 | DECRYPT, |
64 | SIGN, | | 57 | SIGN, |
65 | CLEARSIGN, | | 58 | CLEARSIGN, |
66 | VERIFY, | | 59 | VERIFY, |
67 | LIST_PACKETS, | | 60 | LIST_PACKETS, |
| | | 61 | VERSION, |
68 | | | 62 | |
69 | /* options */ | | 63 | /* options */ |
70 | KEYRING, | | 64 | KEYRING, |
71 | USERID, | | 65 | USERID, |
72 | PASSPHRASE, | | 66 | PASSPHRASE, |
73 | ARMOUR, | | 67 | ARMOUR, |
74 | HOMEDIR, | | 68 | HOMEDIR, |
75 | NUMBITS, | | 69 | NUMBITS, |
76 | | | 70 | |
77 | /* debug */ | | 71 | /* debug */ |
78 | OPS_DEBUG | | 72 | OPS_DEBUG |
79 | | | 73 | |
80 | }; | | 74 | }; |
| @@ -92,26 +86,28 @@ static struct option long_options[] = { | | | @@ -92,26 +86,28 @@ static struct option long_options[] = { |
92 | {"find-key", no_argument, NULL, FIND_KEY}, | | 86 | {"find-key", no_argument, NULL, FIND_KEY}, |
93 | {"export-key", no_argument, NULL, EXPORT_KEY}, | | 87 | {"export-key", no_argument, NULL, EXPORT_KEY}, |
94 | {"import-key", no_argument, NULL, IMPORT_KEY}, | | 88 | {"import-key", no_argument, NULL, IMPORT_KEY}, |
95 | {"generate-key", no_argument, NULL, GENERATE_KEY}, | | 89 | {"generate-key", no_argument, NULL, GENERATE_KEY}, |
96 | | | 90 | |
97 | {"encrypt", no_argument, NULL, ENCRYPT}, | | 91 | {"encrypt", no_argument, NULL, ENCRYPT}, |
98 | {"decrypt", no_argument, NULL, DECRYPT}, | | 92 | {"decrypt", no_argument, NULL, DECRYPT}, |
99 | {"sign", no_argument, NULL, SIGN}, | | 93 | {"sign", no_argument, NULL, SIGN}, |
100 | {"clearsign", no_argument, NULL, CLEARSIGN}, | | 94 | {"clearsign", no_argument, NULL, CLEARSIGN}, |
101 | {"verify", no_argument, NULL, VERIFY}, | | 95 | {"verify", no_argument, NULL, VERIFY}, |
102 | | | 96 | |
103 | {"list-packets", no_argument, NULL, LIST_PACKETS}, | | 97 | {"list-packets", no_argument, NULL, LIST_PACKETS}, |
104 | | | 98 | |
| | | 99 | {"version", no_argument, NULL, VERSION}, |
| | | 100 | |
105 | /* options */ | | 101 | /* options */ |
106 | {"keyring", required_argument, NULL, KEYRING}, | | 102 | {"keyring", required_argument, NULL, KEYRING}, |
107 | {"userid", required_argument, NULL, USERID}, | | 103 | {"userid", required_argument, NULL, USERID}, |
108 | {"passphrase", required_argument, NULL, PASSPHRASE}, | | 104 | {"passphrase", required_argument, NULL, PASSPHRASE}, |
109 | {"homedir", required_argument, NULL, HOMEDIR}, | | 105 | {"homedir", required_argument, NULL, HOMEDIR}, |
110 | {"armor", no_argument, NULL, ARMOUR}, | | 106 | {"armor", no_argument, NULL, ARMOUR}, |
111 | {"armour", no_argument, NULL, ARMOUR}, | | 107 | {"armour", no_argument, NULL, ARMOUR}, |
112 | {"numbits", required_argument, NULL, NUMBITS}, | | 108 | {"numbits", required_argument, NULL, NUMBITS}, |
113 | | | 109 | |
114 | /* debug */ | | 110 | /* debug */ |
115 | {"debug", required_argument, NULL, OPS_DEBUG}, | | 111 | {"debug", required_argument, NULL, OPS_DEBUG}, |
116 | | | 112 | |
117 | { NULL, 0, NULL, 0}, | | 113 | { NULL, 0, NULL, 0}, |
| @@ -448,26 +444,30 @@ main(int argc, char **argv) | | | @@ -448,26 +444,30 @@ main(int argc, char **argv) |
448 | case FIND_KEY: | | 444 | case FIND_KEY: |
449 | case EXPORT_KEY: | | 445 | case EXPORT_KEY: |
450 | case IMPORT_KEY: | | 446 | case IMPORT_KEY: |
451 | case GENERATE_KEY: | | 447 | case GENERATE_KEY: |
452 | case ENCRYPT: | | 448 | case ENCRYPT: |
453 | case DECRYPT: | | 449 | case DECRYPT: |
454 | case SIGN: | | 450 | case SIGN: |
455 | case CLEARSIGN: | | 451 | case CLEARSIGN: |
456 | case VERIFY: | | 452 | case VERIFY: |
457 | case LIST_PACKETS: | | 453 | case LIST_PACKETS: |
458 | p.cmd = long_options[optindex].val; | | 454 | p.cmd = long_options[optindex].val; |
459 | break; | | 455 | break; |
460 | | | 456 | |
| | | 457 | case VERSION: |
| | | 458 | printf("%s version: %s\n", *argv, ops_get_version()); |
| | | 459 | exit(EXIT_SUCCESS); |
| | | 460 | |
461 | /* option */ | | 461 | /* option */ |
462 | | | 462 | |
463 | case KEYRING: | | 463 | case KEYRING: |
464 | if (optarg == NULL) { | | 464 | if (optarg == NULL) { |
465 | (void) fprintf(stderr, "No keyring argument provided\n"); | | 465 | (void) fprintf(stderr, "No keyring argument provided\n"); |
466 | exit(EXIT_ERROR); | | 466 | exit(EXIT_ERROR); |
467 | } | | 467 | } |
468 | snprintf(p.keyring, MAXBUF, "%s", optarg); | | 468 | snprintf(p.keyring, MAXBUF, "%s", optarg); |
469 | break; | | 469 | break; |
470 | | | 470 | |
471 | case USERID: | | 471 | case USERID: |
472 | if (optarg == NULL) { | | 472 | if (optarg == NULL) { |
473 | (void) fprintf(stderr, "No userid argument provided\n"); | | 473 | (void) fprintf(stderr, "No userid argument provided\n"); |