2022-11-20 14:25:16 +00:00
<!doctype html>
< html >
< head >
< meta charset = "utf-8" >
< title > StatiCrypt: Password protect static HTML< / title >
< meta name = "description" content = "" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet"
type="text/css"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
< style >
a.no-style {
color: inherit;
text-decoration: inherit;
}
body {
font-size: 16px;
}
label.no-style {
font-weight: normal;
}
< / style >
< / head >
< body >
< div class = "container" >
< div class = "row" >
< div class = "col-xs-12" >
< h1 >
StatiCrypt
< div class = "pull-right" >
< iframe src = "https://ghbtns.com/github-btn.html?user=robinmoisson&repo=staticrypt&type=star&size=large"
frameborder="0" scrolling="0" width="80px" height="30px">< / iframe >
< iframe src = "https://ghbtns.com/github-btn.html?user=robinmoisson&repo=staticrypt&type=fork&size=large"
frameborder="0" scrolling="0" width="80px" height="30px">< / iframe >
< / div >
< br >
< small > Password protect a static HTML page< / small >
< / h1 >
< p >
2023-03-29 08:50:31 +00:00
StatiCrypt uses AES-256 with WebCrypto to encrypt your html string with your long password, in your browser (client side).
2022-11-20 14:25:16 +00:00
< / p >
< p >
Download your encrypted string in a HTML page with a password prompt you can upload anywhere (see < a
2022-12-21 09:01:21 +00:00
target="_blank" href="example/example_encrypted.html">example< / a > ).
2022-11-20 14:25:16 +00:00
< / p >
< p >
The tool is also available as < a href = "https://npmjs.com/package/staticrypt" > a CLI on NPM< / a > and is < a
href="https://github.com/robinmoisson/staticrypt">open source on GitHub< / a > .
< / p >
< br >
< h4 >
< a class = "no-style" id = "toggle-concept" href = "#" >
< span id = "toggle-concept-sign" > ►< / span > HOW IT WORKS
< / a >
< / h4 >
< div id = "concept" class = "hidden" >
< p >
2023-03-01 17:46:48 +00:00
< b class = "text-danger" > Disclaimer< / b > if you are an at-risk activist, or have extra sensitive
banking data, you should probably use something else!
2022-11-20 14:25:16 +00:00
< / p >
< p >
StatiCrypt generates a static, password protected page that can be decrypted in-browser:
just send or upload the generated page to a place serving static content (github pages, for example)
and you're done: the javascript will prompt users for password, decrypt the page and load your HTML.
< / p >
2023-03-29 08:50:31 +00:00
< p >
The page is encrypted with AES-256 in CBC mode (see why this mode is appropriate for StatiCrypt in
< a href = "https://github.com/robinmoisson/staticrypt/issues/19" > #19< / a > ). The password is hashed with
PBKDF2 (599k iterations with SHA-256, plus 1k with SHA-1 for legacy reasons (see
< a href = "https://github.com/robinmoisson/staticrypt/issues/159" > #159< / a > ), for the added
< a href = "https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2" > recommended
total< / a > of 600k) and used to encrypt the page.
< / p >
2022-11-20 14:25:16 +00:00
< p >
It basically encrypts your page and puts everything with a user-friendly way to use a password
2023-03-01 17:46:48 +00:00
in the new file. AES-256 is state of the art but < b > brute-force/dictionary attacks would be easy to
do at a really fast pace: use a long, unusual password!< / b >
< br / > => To be safe, we recommend 16+ alphanum characters, and using a password manager like the
open-source < a href = "http://bitwarden.com" > Bitwarden< / a > .
2022-11-20 14:25:16 +00:00
< / p >
< p >
Feel free to contribute or report any thought to the
2023-03-01 17:46:48 +00:00
< a href = "https://github.com/robinmoisson/staticrypt" > GitHub project< / a > .
2022-11-20 14:25:16 +00:00
< / p >
< / div >
< br >
< / div >
< / div >
< div class = "row" >
< div class = "col-xs-12" >
< form id = "encrypt_form" >
< div class = "form-group" >
2023-03-01 17:46:48 +00:00
< label for = "passphrase" > Password< / label >
2022-11-20 14:25:16 +00:00
< input type = "password" class = "form-control" id = "passphrase"
2023-03-01 17:46:48 +00:00
placeholder="Password (choose a long one!)">
2022-11-20 14:25:16 +00:00
< / div >
< div class = "form-group" >
< label for = "unencrypted_html" > HTML/string to encrypt< / label >
< textarea class = "form-control"
id="unencrypted_html"
placeholder="< html > < head > ..."
rows="5">< / textarea >
< / div >
< div class = "form-group" >
< label class = "no-style" >
< input type = "checkbox" id = "remember" checked >
2023-03-29 09:49:10 +00:00
Add "Remember me" checkbox (append < code > #staticrypt_logout< / code > to your URL to logout)
2022-11-20 14:25:16 +00:00
< small >
< abbr class = "text-muted"
title="The password will be stored in clear text in the browser's localStorage upon entry by the user. See " More options" to set the expiration (default: none)">
(?)
< / abbr >
< / small >
< / label >
< / div >
< p >
< a href = "#" id = "toggle-extra-option" > + More options< / a >
< / p >
< div id = "extra-options" class = "hidden" >
< div class = "form-group" >
< label for = "title" > Page title< / label >
< input type = "text" class = "form-control" id = "title" placeholder = "Default: 'Protected Page'" >
< / div >
< div class = "form-group" >
< label for = "instructions" > Instructions to display the user< / label >
< textarea class = "form-control" id = "instructions" placeholder = "Default: nothing." > < / textarea >
< / div >
< div class = "form-group" >
2022-11-20 14:36:36 +00:00
< label for = "passphrase_placeholder" > Passphrase input placeholder< / label >
2022-11-20 14:25:16 +00:00
< input type = "text" class = "form-control" id = "passphrase_placeholder"
placeholder="Default: 'Passphrase'">
< / div >
< div class = "form-group" >
2022-11-20 14:36:36 +00:00
< label for = "remember_me" > "Remember me" checkbox label< / label >
2022-11-20 14:25:16 +00:00
< input type = "text" class = "form-control" id = "remember_me" placeholder = "Default: 'Remember me'" >
< / div >
< div class = "form-group" >
2022-11-20 14:36:36 +00:00
< label for = "remember_in_days" > "Remember me" expiration in days< / label >
2022-11-20 14:25:16 +00:00
< input type = "number"
class="form-control"
id="remember_in_days"
step="any"
placeholder="Default: 0 (no expiration)">
< small class = "form-text text-muted" >
After this many days, the user will have to enter the passphrase again. Leave empty or set
to 0 for no expiration.
< / small >
< / div >
< div class = "form-group" >
2022-11-20 14:36:36 +00:00
< label for = "decrypt_button" > Decrypt button label< / label >
2022-11-20 14:25:16 +00:00
< input type = "text" class = "form-control" id = "decrypt_button" placeholder = "Default: 'DECRYPT'" >
< / div >
< / div >
< button class = "btn btn-primary pull-right" type = "submit" > Generate passphrase protected HTML< / button >
< / form >
< / div >
< / div >
< div class = "row mb-5" >
< div class = "col-xs-12" >
< h2 > Encrypted HTML< / h2 >
< p > < a class = "btn btn-success download"
download="encrypted.html"
id="download-link"
disabled="disabled">Download html file with password prompt< / a > < / p >
< pre id = "encrypted_html_display" >
Your encrypted string< / pre >
< / div >
< / div >
< / div >
< script src = "https://cdn.ckeditor.com/4.7.0/standard/ckeditor.js" > < / script >
< script id = "cryptoEngine" >
window.cryptoEngine = {js_crypto_engine}
< / script >
< script id = "codec" >
window.codec = {js_codec}
< / script >
< script id = "formater" >
window.formater = {js_formater}
< / script >
< script >
2023-03-29 08:50:31 +00:00
const encode = codec.init(cryptoEngine).encode;
2022-11-20 14:25:16 +00:00
// enable CKEDIRTOR
CKEDITOR.replace('instructions');
2023-03-29 08:50:31 +00:00
let htmlToDownload;
2022-11-20 14:25:16 +00:00
/**
* Extract js code from < script > t a g a n d r e t u r n i t a s a s t r i n g
*
* @param {string} id
* @returns {string}
*/
2023-03-29 08:50:31 +00:00
function getScriptAsString(id) {
2022-11-20 14:25:16 +00:00
return document.getElementById(id)
.innerText.replace(/window\.\w+ = /, '');
}
2022-11-22 14:44:18 +00:00
/**
2023-03-29 14:12:44 +00:00
* Register something happened - this uses a simple Supabase function to implement a counter, and allows to drop
* google analytics. We don't store any personal data or IP.
2022-11-22 14:44:18 +00:00
*
* @param {string} action
*/
function trackEvent(action) {
2023-03-29 08:50:31 +00:00
const xhr = new XMLHttpRequest();
2022-11-22 14:44:18 +00:00
xhr.open('POST', 'https://zlgpaemmniviswibzuwt.supabase.co/rest/v1/rpc/increment_analytics', true);
xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8')
xhr.setRequestHeader('apikey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpsZ3BhZW1tbml2aXN3aWJ6dXd0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjkxMjM0OTcsImV4cCI6MTk4NDY5OTQ5N30.wNoVDHG7F6INx-IPotMs3fL1nudfaF2qvQDgG-1PhNI')
xhr.setRequestHeader('Authorization', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpsZ3BhZW1tbml2aXN3aWJ6dXd0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjkxMjM0OTcsImV4cCI6MTk4NDY5OTQ5N30.wNoVDHG7F6INx-IPotMs3fL1nudfaF2qvQDgG-1PhNI')
xhr.send(
JSON.stringify({
action_input: action
}
));
}
2022-11-20 14:25:16 +00:00
/**
* Fill the password prompt template with data provided.
* @param data
*/
2023-03-29 08:50:31 +00:00
function setFileToDownload (data) {
const request = new XMLHttpRequest();
2022-11-20 14:25:16 +00:00
request.open('GET', 'lib/password_template.html', true);
request.onload = function () {
2023-03-29 08:50:31 +00:00
const renderedTmpl = formater.renderTemplate(request.responseText, data);
2022-11-20 14:25:16 +00:00
2023-03-29 08:50:31 +00:00
const downloadLink = document.querySelector('a.download');
2022-11-20 14:25:16 +00:00
downloadLink.href = 'data:text/html,' + encodeURIComponent(renderedTmpl);
downloadLink.removeAttribute('disabled');
htmlToDownload = renderedTmpl;
};
request.send();
2023-03-29 08:50:31 +00:00
}
2022-11-20 14:25:16 +00:00
2022-11-22 14:44:18 +00:00
// register page load
window.onload = function () {
trackEvent('show_index');
};
2022-11-20 14:25:16 +00:00
/**
* Handle form submission.
*/
2023-03-29 08:50:31 +00:00
document.getElementById('encrypt_form').addEventListener('submit', async function (e) {
2022-11-20 14:25:16 +00:00
e.preventDefault();
2022-11-22 14:44:18 +00:00
trackEvent('generate_encrypted');
2022-11-20 14:25:16 +00:00
// update instruction textarea value with CKEDITOR content
// (see https://stackoverflow.com/questions/3147670/ckeditor-update-textarea)
CKEDITOR.instances['instructions'].updateElement();
2023-03-29 08:50:31 +00:00
const unencrypted = document.getElementById('unencrypted_html').value,
2022-11-20 14:25:16 +00:00
passphrase = document.getElementById('passphrase').value;
2023-03-29 08:50:31 +00:00
const salt = cryptoEngine.generateRandomSalt();
const encryptedMsg = await encode(unencrypted, passphrase, salt);
2022-11-20 14:25:16 +00:00
2023-03-29 08:50:31 +00:00
const decryptButton = document.getElementById('decrypt_button').value,
2022-11-20 14:25:16 +00:00
instructions = document.getElementById('instructions').value,
isRememberEnabled = document.getElementById('remember').checked,
pageTitle = document.getElementById('title').value.trim(),
passphrasePlaceholder = document.getElementById('passphrase_placeholder').value.trim(),
rememberDurationInDays = document.getElementById('remember_in_days').value || 0,
rememberMe = document.getElementById('remember_me').value;
2023-03-29 08:50:31 +00:00
const data = {
2022-11-20 14:25:16 +00:00
crypto_tag: '< script src = "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js" integrity = "sha384-lp4k1VRKPU9eBnPePjnJ9M2RF3i7PC30gXs70+elCVfgwLwx1tv5+ctxdtwxqZa7" crossorigin = "anonymous" > < / s c r ' + ' i p t > ' ,
decrypt_button: decryptButton ? decryptButton : 'DECRYPT',
encrypted: encryptedMsg,
instructions: instructions ? instructions : '',
is_remember_enabled: isRememberEnabled ? 'true' : 'false',
js_codec: getScriptAsString('codec'),
js_crypto_engine: getScriptAsString('cryptoEngine'),
passphrase_placeholder: passphrasePlaceholder ? passphrasePlaceholder : 'Passphrase',
remember_duration_in_days: rememberDurationInDays.toString(),
remember_me: rememberMe ? rememberMe : 'Remember me',
salt: salt,
title: pageTitle ? pageTitle : 'Protected Page',
};
document.getElementById('encrypted_html_display').textContent = encryptedMsg;
2023-03-29 08:50:31 +00:00
setFileToDownload(data);
2022-11-20 14:25:16 +00:00
});
document.getElementById('toggle-extra-option')
.addEventListener('click', function (e) {
e.preventDefault();
document.getElementById('extra-options').classList.toggle('hidden');
});
2023-03-29 08:50:31 +00:00
let isConceptShown = false;
2022-11-20 14:25:16 +00:00
document.getElementById('toggle-concept')
.addEventListener('click', function (e) {
e.preventDefault();
isConceptShown = !isConceptShown;
document.getElementById('toggle-concept-sign').innerText = isConceptShown ? '▼' : '►';
document.getElementById('concept').classList.toggle('hidden');
});
/**
* Browser specific download code.
*/
document.getElementById('download-link')
.addEventListener('click', function (e) {
2022-11-22 14:44:18 +00:00
// only register the click event if there is actually a generated file
if (htmlToDownload) {
trackEvent('download_encrypted');
}
2022-11-20 14:25:16 +00:00
2023-03-29 08:50:31 +00:00
const isIE = (navigator.userAgent.indexOf("MSIE") !== -1) || (!!document.documentMode === true); // >= 10
const isEdge = navigator.userAgent.indexOf("Edge") !== -1;
2022-11-20 14:25:16 +00:00
// download with MS specific feature
if (htmlToDownload & & (isIE || isEdge)) {
e.preventDefault();
2023-03-29 08:50:31 +00:00
const blobObject = new Blob([htmlToDownload]);
2022-11-20 14:25:16 +00:00
window.navigator.msSaveOrOpenBlob(blobObject, 'encrypted.html');
}
return true;
})
< / script >
< / body >
< / html >