Store encryption key's in XDG cache directory and make location changable

This commit is contained in:
Iwan Timmer
2015-08-02 19:57:34 +02:00
parent 2d365fbeed
commit ddbec9661a
4 changed files with 22 additions and 2 deletions
+2
View File
@@ -25,6 +25,7 @@
#include "limelight-common/Limelight.h" #include "limelight-common/Limelight.h"
#include <sys/stat.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -416,6 +417,7 @@ int gs_quit_app(PSERVER_DATA server) {
} }
int gs_init(PSERVER_DATA server, const char *address, const char *keyDirectory) { int gs_init(PSERVER_DATA server, const char *address, const char *keyDirectory) {
mkdir(keyDirectory, 00755);
if (load_unique_id(keyDirectory) != GS_OK) if (load_unique_id(keyDirectory) != GS_OK)
return GS_FAILED; return GS_FAILED;
+16
View File
@@ -30,6 +30,8 @@
#define MOONLIGHT_PATH "/moonlight/" #define MOONLIGHT_PATH "/moonlight/"
#define USER_PATHS ":~/.moonlight/:./" #define USER_PATHS ":~/.moonlight/:./"
#define DEFAULT_CACHE_DIR ".cache/"
#define write_config_string(fd, key, value) fprintf(fd, "%s = %s\n", key, value) #define write_config_string(fd, key, value) fprintf(fd, "%s = %s\n", key, value)
#define write_config_int(fd, key, value) fprintf(fd, "%s = %d\n", key, value) #define write_config_int(fd, key, value) fprintf(fd, "%s = %d\n", key, value)
#define write_config_bool(fd, key, value) fprintf(fd, "%s = %s\n", key, value?"true":"false"); #define write_config_bool(fd, key, value) fprintf(fd, "%s = %s\n", key, value?"true":"false");
@@ -55,6 +57,7 @@ static struct option long_options[] = {
{"config", required_argument, NULL, 'o'}, {"config", required_argument, NULL, 'o'},
{"platform", required_argument, 0, 'p'}, {"platform", required_argument, 0, 'p'},
{"save", required_argument, NULL, 'q'}, {"save", required_argument, NULL, 'q'},
{"keydir", required_argument, NULL, 'r'},
{0, 0, 0, 0}, {0, 0, 0, 0},
}; };
@@ -168,6 +171,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
case 'q': case 'q':
config->config_file = value; config->config_file = value;
break; break;
case 'r':
strcpy(config->key_dir, value);
break;
case 1: case 1:
if (config->action == NULL) if (config->action == NULL)
config->action = value; config->action = value;
@@ -266,6 +272,16 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
if (config->config_file != NULL) if (config->config_file != NULL)
config_save(config->config_file, config); config_save(config->config_file, config);
if (config->key_dir[0] == 0x0) {
const char *xdg_cache_dir = getenv("XDG_CACHE_DIR");
if (xdg_cache_dir != NULL)
sprintf(config->key_dir, "%s/moonlight", xdg_cache_dir);
else {
const char *xdg_cache_dir = getenv("HOME");
sprintf(config->key_dir, "%s/" DEFAULT_CACHE_DIR "moonlight", xdg_cache_dir);
}
}
if (config->stream.bitrate == -1) { if (config->stream.bitrate == -1) {
if (config->stream.height >= 1080 && config->stream.fps >= 60) if (config->stream.height >= 1080 && config->stream.fps >= 60)
config->stream.bitrate = 20000; config->stream.bitrate = 20000;
+1
View File
@@ -36,6 +36,7 @@ typedef struct _CONFIGURATION {
char* mapping; char* mapping;
char* platform; char* platform;
char* config_file; char* config_file;
char key_dir[4096];
bool sops; bool sops;
bool localaudio; bool localaudio;
struct input_config inputs[MAX_INPUTS]; struct input_config inputs[MAX_INPUTS];
+3 -2
View File
@@ -120,7 +120,8 @@ static void help() {
printf("\t-input <device>\t\tUse <device> as input. Can be used multiple times\n"); printf("\t-input <device>\t\tUse <device> as input. Can be used multiple times\n");
printf("\t-mapping <file>\t\tUse <file> as gamepad mapping configuration file (use before -input)\n"); printf("\t-mapping <file>\t\tUse <file> as gamepad mapping configuration file (use before -input)\n");
printf("\t-audio <device>\t\tUse <device> as ALSA audio output device (default sysdefault)\n"); printf("\t-audio <device>\t\tUse <device> as ALSA audio output device (default sysdefault)\n");
printf("\t-localaudio\t\tPlay audio locally\n\n"); printf("\t-localaudio\t\tPlay audio locally\n");
printf("\t-keydir <directory>\tLoad encryption keys from directory\n\n");
printf("Use Ctrl+Alt+Shift+Q to exit streaming session\n\n"); printf("Use Ctrl+Alt+Shift+Q to exit streaming session\n\n");
exit(0); exit(0);
} }
@@ -173,7 +174,7 @@ int main(int argc, char* argv[]) {
} }
PSERVER_DATA server; PSERVER_DATA server;
if (gs_init(server, config.address, ".") != GS_OK) { if (gs_init(server, config.address, config.key_dir) != GS_OK) {
fprintf(stderr, "Can't connect to server %s\n", config.address); fprintf(stderr, "Can't connect to server %s\n", config.address);
exit(-1); exit(-1);
} }