From 093851eb1d30f304abfd019bc85a287d777791df Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Fri, 25 Mar 2016 14:54:50 +0100 Subject: [PATCH] lowercase user/device for decryption key also spaces in device name are converted to dashes, so "Will-iPhone 6s" should now be key "will-iphone-6s" addresses #108 --- README.md | 2 +- recorder.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a17c4e..8e4e2d3 100644 --- a/README.md +++ b/README.md @@ -977,7 +977,7 @@ This named lmdb database is keyed on topic name (`owntracks/jane/phone`). If the #### `keys` -If the _recorder_ was built with encryption support (see below), this named database contains the secret decryption keys for users/device pairs. The LMDB key is the username followed by a dash followed by the device name, all lower case. For example, if user Jjolie with device iPhone needs a secret entered, the database key will be `jjolie-iphone`. This can be entered into the database as follows: +If the _recorder_ was built with encryption support (see below), this named database contains the secret decryption keys for users/device pairs. The LMDB key is the username followed by a dash followed by the device name, all lower case, with spaces translated to a single dash. For example, if user Jjolie with device iPhone needs a secret entered, the database key will be `jjolie-iphone`. This can be entered into the database as follows: ```bash echo "jjolie-iphone s3cr1t" | ocat --load=keys diff --git a/recorder.c b/recorder.c index 1125689..48be5a7 100644 --- a/recorder.c +++ b/recorder.c @@ -481,6 +481,12 @@ unsigned char *decrypt(struct udata *ud, char *topic, char *p64, char *username, utstring_renew(userdev); utstring_printf(userdev, "%s-%s", username, device); + lowercase(UB(userdev)); + for (n = 0; n < strlen(UB(userdev)); n++) { + if (UB(userdev)[n] == ' ') + UB(userdev)[n] = '-'; + } + memset(key, 0, sizeof(key)); klen = gcache_get(ud->keydb, (char *)UB(userdev), (char *)key, sizeof(key)); if (klen < 1) {