-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
156 lines (135 loc) · 4.47 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* global EchoesSocket */
/* global EchoesIdentity */
/**
* Echoes Client
*
* @author Adrian@Slacknet
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
*/
/**
* require('../lib/config.js'); //AppConfig
* require('../lib/object.js'); //EchoesObject
* require('../lib/crypto.js'); //EchoesCrypto
*/
/**
* @type EchoesClient Global client object
*/
var $client = null;
$(document).ready(function() {
$client = new EchoesClient();
/**
* Set controller references
*/
$client.crypto = new EchoesCrypto();
$client.ui = new EchoesUi();
$client.id = new EchoesIdentity();
$client.id.storage = new EchoesStorage();
$client.socket = new EchoesSocket();
/**
* Client controller cross reference
*/
$client.socket.client = $client;
$client.id.client = $client;
$client.id.storage.get_store();
$client.crypto.does_browser_support('crypto');
$client.crypto.does_browser_support('ec');
$.ajaxSetup({ // csp on openwebapp
xhr: function() {
return new window.XMLHttpRequest({
mozSystem: true
});
}
});
/**
* authenticate and generate new key(s) if crypto is supported
*/
if ($client.crypto.browser_support.crypto.supported) {
$client.ui.progress(10);
$client.id.load_identity().then(function() {
$client.ui.progress(30);
$client.connect();
}).catch(function(e) {
$client.id.device = $client.crypto.bytes_to_hex($client.crypto.new_iv(32));
$client.ui.popup('Identity', e, 'NEW', 'RECOVER',
function() {
$client.register_show();
},
function() {
$client.recovery_show();
});
});
$client.keyx_new_key(null, 'asym');
if ($client.crypto.browser_support.ec.supported) {
$client.keyx_new_key(null, 'keyx');
}
} else {
$client.ui.popup('Error', 'Unsupported client :( Try the latest Chrome or Firefox!', 'OK, I WILL', null, function() {
return false;
});
}
$(window).keydown(function(event) {
// change input focus depending on what window is visible
if (! (event.ctrlKey ||
event.metaKey ||
event.altKey ||
$client.ui.ui.popup.window.is(':visible'))) {
$client.ui.ui.input.focus();
}
// on return keydown
if (event.which == 13) {
if ($client.ui.ui.popup.window.is(':visible')) {
if ($client.ui.ui.popup.yes.is(':visible')) {
$client.ui.ui.popup.yes.click();
return;
} else if ($client.ui.ui.popup.no.is(':visible')) {
$client.ui.ui.popup.no.click();
return;
} else {
$client.ui.popup_close();
return;
}
}
$client.ui.ui.buttons.send.click();
}
});
$client.ui.ui.buttons.exit.click(function() {
$client.execute_command(['/exit']);
});
$client.ui.ui.buttons.help.click(function() {
$client.execute_command(['/help']);
});
$client.ui.ui.buttons.send.click(function() {
$client.send_echo();
});
$client.ui.ui.buttons.encrypt.click(function() {
if (! $client.is_connected()) {
$client.ui.error('Not connected :(');
return;
}
var endpoint = $client.ui.active_window().attr('windowname');
var current_state = $client.ui.get_window_state(endpoint);
$client.ui.log('window current encryption state: ' + current_state, 0);
switch (current_state) {
case 'encrypted':
$client.ui.popup('Encryption', 'Turn off encryption for ' + endpoint + '?', 'YES', 'NO', function() {
$client.execute_command(['/keyx_off', endpoint]);
$client.ui.popup_close();
});
break;
case 'unencrypted':
case 'oneway':
$client.execute_command(['/keyx', endpoint]);
break;
}
});
/**
* Set the callback for show_window() to update encryption state
*
* @param {string} w Windowname to update encryption state on
*
* @returns {null}
*/
$client.ui.ui.show_window_callback = function(w) {
$client.update_encrypt_state(w);
};
});