mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 10:23:55 +01:00
“Transport commit”
This commit is contained in:
119
src/libexim-encrypt-dlfunc-decrypt-sealedbox.c
Normal file
119
src/libexim-encrypt-dlfunc-decrypt-sealedbox.c
Normal file
@ -0,0 +1,119 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <linux/limits.h>
|
||||
#include <sodium.h>
|
||||
|
||||
/*
|
||||
#define PASSWORD_MAXLEN 1024
|
||||
#define CIPHERSTRING_MAX (1024*64)
|
||||
|
||||
void print_usage(char * progname) {
|
||||
printf("Usage: %s [OPTIONS]\n\n", progname);
|
||||
printf("Secret and public key:\n");
|
||||
printf(" -s, --secret-key FILE read secret key from file FILE\n");
|
||||
printf(" -p, --public-key FILE read public key from file FILE\n");
|
||||
printf("\n");
|
||||
printf("Select input:\n");
|
||||
printf(" -c, --input STRING decrypt contents of STRING\n");
|
||||
printf(" -f, --infile FILE decrypt contents of the first line of file FILE\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
PASSWORD = 1,
|
||||
SECRETKEY = 2
|
||||
} decryption_mode;
|
||||
|
||||
typedef enum {
|
||||
ARGUMENT = 1,
|
||||
FROMFILE = 2
|
||||
} input_source;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int opt= 0;
|
||||
char password[PASSWORD_MAXLEN];
|
||||
char secret_key[PATH_MAX];
|
||||
char cipherstring[CIPHERSTRING_MAX];
|
||||
char infile[PATH_MAX];
|
||||
bool pass_from_env = false;
|
||||
|
||||
decryption_mode mode = 0;
|
||||
input_source input = 0;
|
||||
|
||||
if (sodium_init() < 0) {
|
||||
fputs("Unable to initialize libsodium", stderr);
|
||||
exit(128);
|
||||
}
|
||||
|
||||
// define arguments
|
||||
static struct option long_options[] = {
|
||||
{"password", required_argument, NULL, 'p'},
|
||||
{"pass-from-env", no_argument, NULL, 'e'},
|
||||
{"secret-key", required_argument, NULL, 'k'},
|
||||
{"public-key", required_argument, NULL, 'k'},
|
||||
{"cipherstring", required_argument, NULL, 's'},
|
||||
{"infile", required_argument, NULL, 'f'}
|
||||
};
|
||||
|
||||
// parse arguments
|
||||
int long_index = 0;
|
||||
while ((opt = getopt_long(argc, argv,"p:ek:s:f:",
|
||||
long_options, &long_index )) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
strncpy(password, optarg, sizeof(password)-1);
|
||||
mode |= PASSWORD;
|
||||
break;
|
||||
case 'e':
|
||||
pass_from_env = true;
|
||||
mode |= PASSENV;
|
||||
break;
|
||||
case 'k':
|
||||
strncpy(secret_key, optarg, sizeof(secret_key)-1);
|
||||
mode |= SECRETKEY;
|
||||
break;
|
||||
case 's':
|
||||
strncpy(cipherstring, optarg, sizeof(cipherstring)-1);
|
||||
input |= ARGUMENT;
|
||||
break;
|
||||
case 'f':
|
||||
strncpy(infile, optarg, sizeof(infile)-1);
|
||||
input |= FROMFILE;
|
||||
break;
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve password/key
|
||||
switch (mode) {
|
||||
case PASSWORD:
|
||||
if (pass_from_env == true) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
break;
|
||||
case SECRETKEY:
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: Please specify a password OR a key file.\n\n");
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
switch (input) {
|
||||
case ARGUMENT:
|
||||
case FROMFILE:
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: Please specify a ciphertext.\n\n");
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
int main(void) { return 0; }
|
||||
Reference in New Issue
Block a user