Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added password capability
  • Loading branch information
Joshua Steiner committed Sep 27, 2012
commit 39827d03d451af64e1a2ca996adab5068385d268
32 changes: 21 additions & 11 deletions js/zerobin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function decompress(data) {
* @return encrypted string data
*/
function zeroCipher(key, message) {
return sjcl.encrypt(key,compress(message));
if ($('input#password').val().length==0) {
return sjcl.encrypt(key,compress(message));
}
return sjcl.encrypt(key+sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash($("input#password").val())),compress(message));
}
/**
* Decrypt message with key, then decompress.
Expand All @@ -59,7 +62,12 @@ function zeroCipher(key, message) {
* @return string readable message
*/
function zeroDecipher(key, data) {
return decompress(sjcl.decrypt(key,data));
try {
return decompress(sjcl.decrypt(key,data));
} catch(err){
var password = prompt("Please enter the password for this paste.","");
return decompress(sjcl.decrypt(key+sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(password)),data));
}
}

/**
Expand Down Expand Up @@ -108,13 +116,13 @@ function displayMessages(key, comments) {
try { // Try to decrypt the paste.
var cleartext = zeroDecipher(key, comments[0].data);
} catch(err) {
$('div#cleartext').hide();
$('pre#cleartext').hide();
$('button#clonebutton').hide();
showError('Could not decrypt data (Wrong key ?)');
return;
}
setElementText($('div#cleartext'), cleartext);
urls2links($('div#cleartext')); // Convert URLs to clickable links.
setElementText($('pre#cleartext'), cleartext);
urls2links($('pre#cleartext')); // Convert URLs to clickable links.

// Display paste expiration.
if (comments[0].meta.expire_date) $('div#remainingtime').removeClass('foryoureyesonly').text('This document will expire in '+secondsToHuman(comments[0].meta.remaining_time)+'.').show();
Expand Down Expand Up @@ -256,9 +264,10 @@ function send_data() {
var url = scriptLocation() + "?" + data.id + '#' + randomkey;
showStatus('');
$('div#pastelink').html('Your paste is <a href="' + url + '">' + url + '</a>').show();
setElementText($('div#cleartext'), $('textarea#message').val());
urls2links($('div#cleartext'));
setElementText($('pre#cleartext'), $('textarea#message').val());
urls2links($('pre#cleartext'));
showStatus('');
prettyPrint();
}
else if (data.status==1) {
showError('Could not create paste: '+data.message);
Expand All @@ -278,13 +287,13 @@ function stateNewPaste() {
$('div#expiration').show();
$('div#remainingtime').hide();
$('div#language').hide(); // $('#language').show();
$('input#password').hide(); //$('#password').show();
$('#password').show();
$('div#opendisc').show();
$('button#newbutton').show();
$('div#pastelink').hide();
$('textarea#message').text('');
$('textarea#message').show();
$('div#cleartext').hide();
$('pre#cleartext').hide();
$('div#message').focus();
$('div#discussion').hide();
}
Expand All @@ -310,7 +319,7 @@ function stateExistingPaste() {
$('button#newbutton').show();
$('div#pastelink').hide();
$('textarea#message').hide();
$('div#cleartext').show();
$('pre#cleartext').show();
}

/**
Expand All @@ -319,7 +328,7 @@ function stateExistingPaste() {
function clonePaste() {
stateNewPaste();
showStatus('');
$('textarea#message').text($('div#cleartext').text());
$('textarea#message').text($('pre#cleartext').text());
}

/**
Expand Down Expand Up @@ -436,6 +445,7 @@ $(function() {
stateExistingPaste();

displayMessages(pageKey(), messages);
prettyPrint();
}
// Display error message from php code.
else if ($('div#errormessage').text().length>1) {
Expand Down
15 changes: 4 additions & 11 deletions tpl/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<head>
<title>ZeroBin</title>
<link type="text/css" rel="stylesheet" href="css/zerobin.css?{$VERSION|rawurlencode}#" />
<link type="text/css" rel="stylesheet" href="../lib/google-code-prettify/prettify.css" />
<script src="js/jquery.js#"></script>
<script src="js/sjcl.js#"></script>
<script src="js/base64.js#"></script>
<script src="js/rawdeflate.js#"></script>
<script src="js/rawinflate.js#"></script>
<script src="js/zerobin.js?{$VERSION|rawurlencode}#"></script>

<script src="lib/google-code-prettify/prettify.js#"></script>
<!--[if lt IE 10]>
<style> body {padding-left:60px;padding-right:60px;} div#ienotice {display:block;} </style>
<![endif]-->
Expand Down Expand Up @@ -55,22 +56,14 @@ <h3>{$VERSION}</h3>
</select>
</div>
<div id="remainingtime" style="display:none;"></div>
<div id="language" style="display:none;">
<select name="language">
<option value="language" selected="selected">Language</option>
<option value="C/C++">C/C++</option>
<option value="php">php</option>
<option value="python">Python</option>
</select>
</div>
<input id="password" value="Optional password..." style="display:none;" />
<input id="password" placeholder="Optional password..." style="display:none;" />
<div id="opendisc" class="button" style="display:none;">
<input type="checkbox" id="opendiscussion" name="opendiscussion" />
<label for="opendiscussion">Open discussion</label>
</div>
</div>
<div id="pastelink" style="display:none;"></div>
<div id="cleartext" style="display:none;"></div>
<pre id="cleartext" class="prettyprint" style="display:none;"></pre>
<textarea id="message" name="message" cols="80" rows="25" style="display:none;"></textarea>
<div id="discussion" style="display:none;">
<h4>Discussion</h4>
Expand Down