This commit is contained in:
Jan-Piet Mens 2016-02-24 10:19:00 +01:00
parent 8c96d7bd3c
commit 215e1beee2
2 changed files with 8 additions and 2 deletions

3
http.c
View File

@ -537,6 +537,8 @@ char *j_encrypt(struct udata *ud, JsonNode *json, char *userdevice)
memcpy(encrypted + crypto_secretbox_NONCEBYTES, ciphertext, ciphertext_len);
b64 = base64_encode(encrypted, ciphertext_len + crypto_secretbox_NONCEBYTES);
free(js_string);
free(ciphertext);
free(encrypted);
return (b64);
@ -602,6 +604,7 @@ static int dopublish(struct mg_connection *conn, const char *uri)
json_append_member(json, "_type", json_mkstring("encrypted"));
json_append_member(json, "data", json_mkstring(enc));
free(enc);
return json_response(conn, json);
}

View File

@ -542,9 +542,9 @@ unsigned char *decrypt(struct udata *ud, char *topic, char *p64, char *username,
unsigned char *ciphertext, *cleartext;
size_t ciphertext_len;
int n, klen;
UT_string *userdev;
static UT_string *userdev = NULL;
utstring_new(userdev);
utstring_renew(userdev);
utstring_printf(userdev, "%s-%s", username, device);
memset(key, 0, sizeof(key));
@ -857,10 +857,13 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
handle_message(ud, topic, cleartext, strlen(cleartext), retain);
free(cleartext);
}
if (_typestr) free(_typestr);
json_delete(json);
return;
}
}
olog(LOG_ERR, "no `data' in encrypted %s", topic);
json_delete(json);
return;
break;
#endif /* WITH_ENCRYPT */