-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·668 lines (580 loc) · 23.9 KB
/
index.html
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
<html>
<head>
<meta charset="UTF-8">
<title>SmallTalk.page -- Protect Your Small Talk</title>
<link rel="icon" type="image/png" href="shhh.png" />
<link rel="canonical" href="https://smalltalk.page/" />
<meta property="og:title" content="." />
<meta property="og:description" content="." />
<meta property="og:image" content="https://smalltalk.page/shhh.png" />
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<!-- Materialize -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-125586496-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-125586496-1');
</script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- crypto libs -->
<script type="text/javascript" src="https://cdn.rawgit.com/ricmoo/aes-js/e27b99df/index.js"></script>
<script type="text/javascript" src="https://rawgit.com/emn178/js-sha256/master/build/sha256.min.js"></script>
<script src="i18n.js"></script>
<style>
.inline {
display: inline;
}
</style>
</head>
<body><div class="container">
<h2 class="inline"><a href="https://smalltalk.page">SmallTalk.page</a></h2>
<!-- hidden image for search engine or bots for snippet -->
<img src="shhh.png" width=0 height=0 />
<h5 class="right">
<a href="https://www.facebook.com/shhh.pw" target="_blank">
<img width=30 src="f-ogo_RGB_HEX-58.png" />
</a>
<a href="https://play.google.com/store/apps/details?id=pw.shhh.shhh" target="_blank">
<i class="small material-icons">android</i>
</a>
<a href="mailto:[email protected]" target="_blank">
<i class="small material-icons">email</i>
</a>
</h5>
<h5><span id="short_desc">SmallTalk an online tool to do end-to-end and all-client-side encryption</span>
<a id="read_more" href="#">... more</a><span id="more_0"><span id="detail_0">.
It is perfect to be used to exchange confidential or secret information
with another person or a group of people. The pre-defined password
is the only key able to decrypt the encrypted messages.</span></span></h5>
<span id="more_1">
<h5 id="detail_1">A person having the URL you sent but not having the password cannot
decrypt the message. This menas your ISP, government, and the court
cannot decrypt it. Since we don't save your password, even we cannot
decrypt your message.</h5>
<h5><span id="detail_2_0">You can find the full source code on</span>
<a href="https://github.com/yjlou/smalltalk">github</a>
<span id="detail_2_1">. Includes Javascript and Android App code.</h5>
<h5 id="detail_3">Below is the diagram how your message is encrypted and decrypted.</h5>
<h5><img width="100%" src="encryption.png"></h5>
<h5 id="detail_4">Some highlights are listed below:</h5>
<ul>
<li id="detail_4_0">+ The hint message is optional, which is used to remind the receiver what the password is. Note that it is NOT encrypted.
<li id="detail_4_1">+ The password is pre-defined by both sender and receiver. Or a secret known by both sides.
<li id="detail_4_2">+ A random IV is generated while encrypted. It is used not only for hashing the encrypt/decrypt keys, but also for block cipher.
<li id="detail_4_3">+ The encrypt key is hashed by the IV and pre-defined password so that even the same password is used with other people, the key is still different.
<li id="detail_4_4">+ The same IV is also used in block cipher to increase the attack difficulty.
<li id="detail_4_5">+ The encrypted message and IV are transmitted via your regular chat apps, for example, Messenger, Whatsapp, WeChat ... It is just an encrypted URL.
<li id="detail_4_6">+ The URL will lead the receiver to the decryption page.
<li id="detail_4_7">+ All the receiver need to do is typing the pre-defined password.
<li id="detail_4_8">+ Then, the original message is decrypted on the receiver side.
<li id="detail_4_9">+ The receiver can reply the message by doing the same procedure with either the same or a different password.
</ul>
<h5 id="detail_5">Warning: there might be still some weaknesses in the communication. For example,
a browser extension with the ability to read the full content of the HTML page
can still read your information. Turn off those extensions if you have concerns.</h5>
</span>
<div id="dec_div">
<div id="decrypt_prompt">
<h4 id="i18n_decrypt">Decrypt</h4>
<!-- invisible -->
<textarea id="cipher_hex" rows="4" cols="80"></textarea>
<input type=text id="dec_iv_hex" value="The IV">
<div class="row">
<div class="input-field col s12">
<h5><span id="dec_hint_desc">Hint: </span><span id="dec_hint"></span></h5>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<input type=password id="dec_pwd">
<label id="i18n_dec_pwd" for="dec_pwd">Enter your password here</label>
</div>
<div class="input-field col s2">
<button id="btn_dec_visible" class="btn waves-effect waves-light" type="submit">
<i class="small material-icons">visibility</i>
</button>
<button id="btn_dec_invisible" class="btn waves-effect waves-light" type="submit">
<i class="small material-icons">visibility_off</i>
</button>
</div>
<div class="input-field col s4">
<button id="btn_decrypt" class="btn waves-effect waves-light"
type="submit">
Decrypt
</button>
</div>
</div>
</div>
<div id="decrypted_div">
<div class="row">
<div class="input-field col s12">
<h4 id="i18n_descrypted_text">Decrypted Text:</h4>
</div>
</div>
<div class="row">
<div class="input-field col s8 m10">
<textarea id="decrypted_text" class="materialize-textarea"
rows="4" cols="80" readonly></textarea>
</div>
<div class="input-field col s2 m1">
<button id="btn_refresh" class="btn waves-effect waves-light"
type="submit" name="action">
<i class="small material-icons">refresh</i>
</div>
<div class="input-field col s2 m1">
<button id="btn_copy_decrypted" class="btn waves-effect waves-light"
type="submit" name="action">
<i class="small material-icons">content_copy</i>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<button id="btn_reply" class="btn waves-effect waves-light"
type="submit"> Reply </button>
</div>
</div>
</div>
</div>
<div id="enc_div">
<h4 id="enc_h2_encrypt" class="row col s12">Encrypt</h4>
<h4 id="enc_h2_reply" class="row col s12">Reply</h4>
<div class="row">
<div class="input-field col s12">
<textarea id="plain_text" class="materialize-textarea"
rows="4" cols="80"></textarea>
<label id="i18n_plain_text" for="plain_text">
* Enter the text you want to send (can be multiple lines)
</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="enc_hint" type=text class="validate">
<label id="i18n_enc_hint" for="enc_hint">Hint of password. Will be prompted to receiver.
Not encrypted.</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<input id="enc_pwd" type=password class="validate">
<label id="i18n_enc_pwd" for="enc_pwd">* Enter your password here</label>
</div>
<div class="input-field col s2">
<button id="btn_enc_visible" class="btn waves-effect waves-light" type="submit">
<i class="small material-icons">visibility</i>
</button>
<button id="btn_enc_invisible" class="btn waves-effect waves-light" type="submit">
<i class="small material-icons">visibility_off</i>
</button>
</div>
<div class="input-field col s4">
<button id="btn_encrypt" class="btn waves-effect waves-light"
type="submit"> Encrypt </button>
</div>
</div>
<div id="url_div" class="row">
<div class="input-field col s10">
<input type=text id="url_for_share" readonly
value="URL for share is not generated yet.">
<label id="i18n_url_for_share" for "url_for_share">URL for share</label>
</div>
<div class="input-field col s2">
<button id="btn_copy_url" class="btn waves-effect waves-light"
type="submit" name="action">
<i class="small material-icons">content_copy</i>
</div>
</div>
</div>
<script>
// Messages used to notify user.
var i18n_url_copied = "URL copied.";
var i18n_no_enc_key = "Encrypt key is not provided yet!";
var i18n_gen_too_long = "The generated URL is too long. You still can copy the URL, but the receiver may not completely decode it.";
var i18n_shorten_failed = "Cannot shorten the URL. ";
// Credits: https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
// For iOS hack: https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios
function copyToClipboard(str) {
const el = document.createElement('textarea');
el.value = str;
document.body.appendChild(el);
if (navigator.userAgent.match(/ipad|ipod|iphone/i)) {
// For iOS only.
var range = document.createRange();
el.contentEditable = true;
el.readOnly = false;
range.selectNodeContents(el);
var s = window.getSelection();
s.removeAllRanges();
s.addRange(range);
el.setSelectionRange(0, 999999); // A big number, to cover anything that could be inside
// the element.
} else {
// For other moderm browers.
el.select();
}
document.execCommand('copy');
document.body.removeChild(el);
}
// from somewhere in stackoverflow
var getUrl = function(href) {
// Given a relative path or parameters, returns an A object of that.
var l = document.createElement("a");
l.href = href;
if (!l.href || l.href.startsWith("externalfile")) {
// The local developping code. At least we can append the query string to the URL.
return href;
} else {
// The normal case. 'l' is a URL.
return l.href;
}
};
function ShortenUrl(long_url, func) {
// Ask the shortener service to return a short URL.
//
// Args:
// long_url: the URL to compress.
// func: callback in response.
// (status_code, short_url)
//
// If this is http or a local developping code, use http instead.
if (location.protocol == 'https:') {
var protocol = "https://api-ssl";
} else {
var protocol = "http://api";
}
$.getJSON(protocol + ".bitly.com/v3/shorten?callback=?", {
"format": "json",
"apiKey": "R_f384bb9a1d1248f4a12e72a07b98f7e2",
"login": "o_67j98qnsjg",
"longUrl": long_url
}, function(resp) {
// resp:
// data:
// global_hash: "2OWGqDd"
// hash: "2OWGqmH"
// long_url: "https://smalltalk.page/?iv=1232"
// new_hash: 1
// url: "http://bit.ly/2OWGqmH"
// status_code: 200
// status_txt: "OK"
func(resp.status_code, resp.data.url);
}
)
}
// Maintains the toggle-able buttons.
function Toggleable(btn_on, btn_off, is_on, updated) {
// Args:
// btn_on: the jQuery object of ON.
// btn_off: the jQuery object of OFF.
// is_on: function returning true if the status is ON.
// updated(on): callback function when state changed.
// If the new state is ON, then |on| is set to true.
var self_ = this;
this.btn_on_ = btn_on;
this.btn_off_ = btn_off;
this.is_on_ = is_on;
this.updated_ = updated;
this.setOn = function() {
self_.btn_off_.hide();
self_.btn_on_.show();
self_.updated_(true);
};
this.setOff = function() {
self_.btn_on_.hide();
self_.btn_off_.show();
self_.updated_(false);
};
this.update = function() {
if (self_.is_on_()) {
self_.setOn();
} else {
self_.setOff();
}
};
// Mouse click events.
self_.btn_on_.click(function() {
self_.setOff();
return false; // for submit type.
});
self_.btn_off_.click(function() {
self_.setOn();
return false; // for submit type.
});
// Init
self_.update();
}
function Visibility(pwd, btn_on, btn_off) {
// Args:
// pwd: a jQuery object of the password field.
// btn_on: a jQuery object of the ON.
// btn_off: a jQuery object of the OFF.
var self_ = this;
this.pwd_ = pwd;
this.btn_on_ = btn_on;
this.btn_off_ = btn_off;
var toggleable = new Toggleable(btn_on, btn_off,
function() { // is_on
return (self_.pwd_.attr("type") != "password");
},
function(on) { // updated
if (on) {
self_.pwd_.attr("type", "text");
} else {
self_.pwd_.attr("type", "password");
}
}
);
}
function EnforceHttps() {
// Redirect to HTTPS (for geo location API). For non-local file and non-192.168. hosts.
if (location.protocol == 'http:' && !location.hostname.startsWith("192.168.")) {
location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
}
}
EnforceHttps();
// Visible button for Encrypt password.
var enc_visibility = new Visibility($("#enc_pwd"), $("#btn_enc_visible"), $("#btn_enc_invisible"));
var dev_visibility = new Visibility($("#dec_pwd"), $("#btn_dec_visible"), $("#btn_dec_invisible"));
// https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript
function getJsonFromUrl() {
// Returns URL parameters in JSON form.
// If the info are carried in hashtag, use it.
var hash = window.location.hash;
if (hash) {
var query = hash.substr(1);
} else {
// Otherwise, use it from the parameters.
var query = location.search.substr(1);
}
console.log("The query string retried: " + query);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
}
var params = getJsonFromUrl();
// Auto-select-all when click on text box and area.
$("input:text").focus(function() { $(this).select(); } );
$("textarea").focus(function() { $(this).select(); } );
// Initial UI state.
$("#enc_div").hide();
$("#dec_div").hide();
$("#decrypted_div").hide();
$("#cipher_hex").hide();
$("#dec_iv_hex").hide();
$("#more_0").hide();
$("#more_1").hide();
$("#enc_h2_reply").hide();
$("#url_div").hide();
if (!params["cipher_hex"]) {
// Encrypt, display Cipher section.
$("#enc_div").show();
$("#plain_text").focus();
} else {
// Decrypt. Display De-cipher section.
$("#dec_div").show();
$("#dec_pwd").focus();
// Parse cipher text from URL parameter and fill into |cipher_hex|.
$("#cipher_hex").val(params["cipher_hex"]);
$("#dec_iv_hex").val(params["iv_hex"]);
if (params["hint"]) {
$("#dec_hint").text(params["hint"]);
} else {
// No hint provided. Don't show the description of hint.
$("#dec_hint_desc").hide();
}
}
function gen_iv() {
// Returns an array of integers (16-byte).
var iv = [];
for (var i = 0; i < 16; i++) {
iv.push(Math.floor(Math.random() * 256));
}
return iv;
}
function hash256(msg) {
// Returns an array of integers (32-byte).
var hash = sha256.create();
hash.update(msg);
return hash.digest();
}
function block_enc(msg) {
// Returns 16-byte blocks with length info and padding
var len = msg.length;
var output = [len % 256, Math.floor(len / 256)].concat(Array.from(msg)); // little-endian
for(var i = 0; (16 - (i < output.length % 16)) % 16; i++) {
output.push(i);
}
return output;
}
function block_dec(msg) {
// Returns a string
var len = msg[0] + msg[1] * 256;
return aesjs.utils.utf8.fromBytes(msg.slice(2, 2 + len));
}
function btn_encrypt_clicked() {
// Check key is input already.
var enc_pwd = $("#enc_pwd").val();
if (!enc_pwd) {
M.toast({html: i18n_no_enc_key, displayLength: 3000});
return;
}
// Encrypt the message.
var plain_text = aesjs.utils.utf8.toBytes($("#plain_text").val());
var iv_bytes = gen_iv();
var iv_hex = aesjs.utils.hex.fromBytes(iv_bytes);
var enc_key = hash256(aesjs.utils.utf8.toBytes(enc_pwd) + iv_bytes);
var aesCbc = new aesjs.ModeOfOperation.cbc(enc_key, iv_bytes);
var encrypted_bytes = aesCbc.encrypt(block_enc(plain_text));
var encrypted_hex = aesjs.utils.hex.fromBytes(encrypted_bytes);
var hint = encodeURIComponent($("#enc_hint").val());
// Update |cipher_hex|.
$("#cipher_hex").val(encrypted_hex);
$("#dec_iv_hex").val(iv_hex);
// Update the |url_for_share|.
var url_for_share = getUrl(
"#iv_hex=" + iv_hex +
"&cipher_hex=" + encrypted_hex +
"&hint=" + hint);
$("#url_for_share").val(url_for_share);
$("#url_div").show();
// Check the URL length.
actual_len = $("#url_for_share").val().length;
max_url_len = 2053;
if (actual_len > max_url_len) {
M.toast({html: i18n_gen_too_long + 'Must be shorter than [' + max_url_len +
'] bytes, but actually [' + actual_len + '] bytes.', // TODO: i18n
displayLength: 10000});
return;
}
// If this is a local development code, insert the host name before shortening.
if (!url_for_share.startsWith("http")) {
url_for_share = "https://smalltalk.page/" + url_for_share;
}
// Shorten it!
console.log("URL to be shortened: " + url_for_share);
ShortenUrl(url_for_share, function(status, short_url) {
if (status == 200) {
if (0) { // Temporarily disable this feature.
// Rewrite URL for iOS.
// https://bit.ly/GgyY56 --> https://smalltalk.page/302/?GyyG56
var bitly_pos = short_url.search("bit.ly/");
if (bitly_pos >= 0) {
bitly_pos += "bit.ly/".length; // Points to short hash now.
short_url = window.location.protocol + "//" +
window.location.host + "/302/?" +
short_url.substring(bitly_pos);
}
}
$("#url_for_share").val(short_url);
} else {
M.toast({html: i18n_shorten_failed + 'Error code: [' + status + ']',
displayLength: 10000});
return;
}
});
}
function btn_decrypt_clicked() {
// Check key is input already.
var dec_pwd = $("#dec_pwd").val();
if (!dec_pwd) {
alert("Decrypt key is not provided yet!");
return;
}
// Decrypt the message.
var cipher_bytes = aesjs.utils.hex.toBytes($("#cipher_hex").val());
var iv_bytes = aesjs.utils.hex.toBytes($("#dec_iv_hex").val());
var dec_key = hash256(aesjs.utils.utf8.toBytes(dec_pwd) + iv_bytes);
var aesCbc = new aesjs.ModeOfOperation.cbc(dec_key, iv_bytes);
var decrypted_bytes = aesCbc.decrypt(cipher_bytes);
var plain_text = block_dec(decrypted_bytes);
// Fill into the |decrypted_text|.
$("#decrypted_div").show();
$("#decrypted_text").val(plain_text);
M.textareaAutoResize($('#decrypted_text'));
// Hide the key fields.
$("#decrypt_prompt").hide();
}
function btn_reply_clicked() {
$("#enc_div").show();
$("#decrypt_prompt").hide();
$("#btn_reply").hide();
$("#enc_h2_encrypt").hide();
$("#enc_h2_reply").show();
$("#plain_text").focus();
// Pass the password to encryption.
$("#enc_pwd").attr('type', 'password');
$("#enc_pwd").val($("#dec_pwd").val());
// Pass hint field.
$("#enc_hint").val($("#dec_hint").text());
// Update the pre-filled password field.
M.updateTextFields();
}
// Button click events!
$("#btn_encrypt").on( "click", function(event) {
btn_encrypt_clicked();
return false; // not submit the form
});
$("#btn_decrypt").on( "click", function(event) {
btn_decrypt_clicked();
return false;
});
$("#btn_reply").on( "click", function(event) {
btn_reply_clicked();
return false;
});
$("#read_more").on( "click", function(event) {
$("#read_more").hide();
$("#more_0").show();
$("#more_1").show();
return false;
});
$("#btn_copy_url").on( "click", function(event) {
copyToClipboard($("#url_for_share").val());
M.toast({html: i18n_url_copied})
return false;
});
$("#btn_refresh").on( "click", function(event) {
location.reload();
return false;
});
$("#btn_copy_decrypted").on( "click", function(event) {
copyToClipboard($("#decrypted_text").val());
M.toast({html: i18n_url_copied})
return false;
});
// ENTER key pressed.
$("#enc_hint").keypress(function(event) {
if (event.which == 13) {
$("#enc_pwd").focus();
return false;
}
});
$("#enc_pwd").keypress(function(event) {
if (event.which == 13) {
btn_encrypt_clicked();
return false;
}
});
$("#dec_pwd").keypress(function(event) {
if (event.which == 13) {
btn_decrypt_clicked();
return false;
}
});
$(document).ready(function() {
ApplyI18N();
});
</script>
</div><!-- end of container --></body>
</html>