summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/test.c b/test.c
index 50a9c93..05276d1 100644
--- a/test.c
+++ b/test.c
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2010 Samuel Lidén Borell <samuel@kodafritt.se>
+ Copyright (c) 2010-2015 Samuel Lidén Borell <samuel@kodafritt.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include "fish.h"
+#include "keystore.h"
// We can't use the XChat plugin API from here...
gchar *get_config_filename() {
@@ -78,13 +79,45 @@ static int encrypt(int nick_count, char *nicks[]) {
return 0;
}
+static int setkeys(int nick_count, char *nicks[]) {
+ fprintf(stderr, "NOTE: Passphrases are NOT hidden!\n");
+ for (int i = 0; i < nick_count; i++) {
+ char password[8192];
+ fprintf(stderr, "Enter passphrase for %s: ", nicks[i]);
+
+ if (!fgets(password, sizeof(password), stdin)) {
+ fprintf(stderr, "Cancelled.\n");
+ return 1;
+ }
+
+ char *newline = strchr(password, '\n');
+ if (newline) *newline = '\0';
+
+ if (!keystore_store_key(nicks[i], password)) {
+ fprintf(stderr, "Failed to update key file.\n");
+ return 1;
+ }
+ }
+ return 0;
+}
+
int main(int argc, char *argv[]) {
if (argc < 2) {
- fprintf(stderr, "usage: %s [-e] nick...\n", argv[0]);
+ fprintf(stderr, "usage: %s [-e] nick...\n"
+ "usage: %s -k nick...\n"
+ "\n"
+ "Options:\n"
+ " -e Encrypt (default is to decrypt\n"
+ " -k Set key (will prompt for password)\n"
+ "\n"
+ "This tool will read/write keys from %s\n",
+ argv[0], argv[0], get_config_filename());
return 2;
}
- if (strcmp(argv[1], "-e") == 0) {
+ if (strcmp(argv[1], "-k") == 0) {
+ return setkeys(argc-2, &argv[2]);
+ } else if (strcmp(argv[1], "-e") == 0) {
return encrypt(argc-2, &argv[2]);
} else {
return decrypt(argc-1, &argv[1]);