commit a4c60032ba4815e1fb26c1e894f9fee3098f1809
parent 86df1cf0106fccda62c89c23c859bf63d31bf451
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date: Tue, 17 May 2016 20:16:12 +0000
Add actual support for CSV data signature
Diffstat:
M | src/js/app.js | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 51 insertions(+), 0 deletions(-)
diff --git a/src/js/app.js b/src/js/app.js
@@ -16,16 +16,29 @@
var cfg_endpoint = null;
var cfg_data_field = null;
+var cfg_sign_algo = "";
+var cfg_sign_field = "";
+var cfg_sign_field_format = "";
+var cfg_sign_key = "";
+var cfg_sign_key_format = "";
var cfg_extra_fields = [];
var to_send = [];
var senders = [new XMLHttpRequest(), new XMLHttpRequest()];
var i_sender = 1;
+var jsSHA = require("sha");
function sendPayload(payload) {
var data = new FormData();
data.append(cfg_data_field, payload);
+ if (cfg_sign_field) {
+ var sha = new jsSHA(cfg_sign_algo, "TEXT");
+ sha.setHMACKey(cfg_sign_key, cfg_sign_key_format);
+ sha.update(payload);
+ data.append(cfg_sign_field, sha.getHMAC(cfg_sign_field_format));
+ }
+
if (cfg_extra_fields.length > 0) {
for (var i = 0; i < cfg_extra_fields.length; i += 1) {
var decoded = decodeURIComponent(cfg_extra_fields[i]).split("=");
@@ -78,6 +91,11 @@ Pebble.addEventListener("ready", function(e) {
cfg_endpoint = localStorage.getItem("cfgEndpoint");
cfg_data_field = localStorage.getItem("cfgDataField");
+ cfg_sign_algo = localStorage.getItem("cfgSignAlgorithm");
+ cfg_sign_field = localStorage.getItem("cfgSignFieldName");
+ cfg_sign_field_format = localStorage.getItem("cfgSignFieldFormat");
+ cfg_sign_key = localStorage.getItem("cfgSignKey");
+ cfg_sign_key_format = localStorage.getItem("cfgSignKeyFormat");
if (cfg_endpoint && cfg_data_field) {
Pebble.sendAppMessage({ "lastSent":
@@ -106,6 +124,14 @@ Pebble.addEventListener("showConfiguration", function() {
settings += "&data_field=" + encodeURIComponent(cfg_data_field);
}
+ if (cfg_sign_field) {
+ settings += "&s_algo=" + encodeURIComponent(cfg_sign_algo)
+ + "&s_field=" + encodeURIComponent(cfg_sign_field)
+ + "&s_fieldf=" + encodeURIComponent(cfg_sign_field_format)
+ + "&s_key=" + encodeURIComponent(cfg_sign_key)
+ + "&s_keyf=" + encodeURIComponent(cfg_sign_key_format);
+ }
+
if (cfg_extra_fields.length > 0) {
settings += "&extra=" + cfg_extra_fields.join(",");
}
@@ -127,6 +153,31 @@ Pebble.addEventListener("webviewclosed", function(e) {
localStorage.setItem("cfgDataField", cfg_data_field);
}
+ if (configData.signAlgorithm) {
+ cfg_sign_algo = configData.signAlgorithm;
+ localStorage.setItem("cfgSignAlgorithm", cfg_sign_algo);
+ }
+
+ if (configData.signFieldName) {
+ cfg_sign_field = configData.signFieldName;
+ localStorage.setItem("cfgSignFieldName", cfg_sign_field);
+ }
+
+ if (configData.signFieldFormat) {
+ cfg_sign_field_format = configData.signFieldFormat;
+ localStorage.setItem("cfgSignFieldFormat", cfg_sign_field_format);
+ }
+
+ if (configData.signKey) {
+ cfg_sign_key = decodeURIComponent(configData.signKey);
+ localStorage.setItem("cfgSignKey", cfg_sign_key);
+ }
+
+ if (configData.signKeyFormat) {
+ cfg_sign_key_format = configData.signKeyFormat;
+ localStorage.setItem("cfgSignKeyFormat", cfg_sign_key_format);
+ }
+
if (configData.extraFields !== null) {
cfg_extra_fields = configData.extraFields
? configData.extraFields.split(",") : [];