init: working template generation

pull/8/head
Robin Moisson 2017-04-29 18:44:06 +05:30
commit bed4febc77
7 zmienionych plików z 8722 dodań i 0 usunięć

1
.gitignore vendored 100644
Wyświetl plik

@ -0,0 +1 @@
.idea

6
bootstrap.min.css vendored 100644

File diff suppressed because one or more lines are too long

5988
crypto-js.js 100644

Plik diff jest za duży Load Diff

116
index.html 100644
Wyświetl plik

@ -0,0 +1,116 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Static HTML Crypto</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">-->
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>StatiCrypt</h1>
<p>
Password protect a static HTML page.
</p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<form id="encrypt_form">
<div class="form-group">
<label for="passphrase">Passphrase</label>
<input type="password" class="form-control" id="passphrase"
placeholder="Passphrase (choose a long one!)">
</div>
<div class="form-group">
<label for="html_title">HTML title of generated page</label>
<input type="text" class="form-control" id="html_title">
</div>
<div class="form-group">
<label for="title">Page name</label>
<input type="text" class="form-control" id="title">
</div>
<div class="form-group">
<label for="instructions">Instructions to display the user</label>
<textarea class="form-control" id="instructions"></textarea>
</div>
<div class="form-group">
<label for="unencrypted_html">HTML to encrypt</label>
<textarea class="form-control" id="unencrypted_html" placeholder="<html><head>..."></textarea>
</div>
<button class="btn btn-primary" type="submit">Generate passphrase protected HTML</button>
</form>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h2>Encrypted HTML</h2>
<a href="#" class="btn btn-primary download" target="_blank" download="encrypted.html" disabled>Download</a>
<pre id="encrypted_html_display">
Nothing generated yet.</pre>
</div>
</div>
</div>
<!--<script-->
<!--src="https://code.jquery.com/jquery-3.2.1.min.js"-->
<!--integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="-->
<!--crossorigin="anonymous"-->
<script src="jquery-3.2.1.min.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>-->
<script src="crypto-js.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jsrender/0.9.84/jsrender.js"></script>-->
<script src="jsrender.js"></script>
<script>
$(function () {
var renderTemplate = function(data) {
$.when($.get('password_template.html'))
.done(function(tmplData) {
$.templates({ tmpl: tmplData });
var renderedTmpl = $.render.tmpl(data);
$('#encrypted_html_display').text(renderedTmpl);
var downloadLink = $('a.download');
downloadLink.attr('href', 'data:attachment/text,' + encodeURI(renderedTmpl));
downloadLink.removeAttr('disabled');
});
};
$('#encrypt_form').submit(function (e) {
e.preventDefault();
var unencrypted = $('#unencrypted_html').val();
var passphrase = $('#passphrase').val();
var encrypted = CryptoJS.AES.encrypt(unencrypted, passphrase);
var hmac = CryptoJS.HmacSHA256(encrypted.toString(), CryptoJS.SHA256(passphrase)).toString();
var encryptedMsg = hmac + encrypted;
var data = {
html_title: $('#html_title').val(),
title: $('#title').val(),
instructions: $('#instructions').val(),
encrypted: encryptedMsg
};
renderTemplate(data);
});
});
</script>
</body>
</html>

4
jquery-3.2.1.min.js vendored 100644

File diff suppressed because one or more lines are too long

2445
jsrender.js 100644

Plik diff jest za duży Load Diff

Wyświetl plik

@ -0,0 +1,162 @@
<!doctype html>
<html class="staticrypt-html">
<head>
<meta charset="utf-8">
<title>{{:html_title}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/*@font-face {*/
/*font-family: 'Roboto';*/
/*src: url('../fonts/roboto-light-webfont.woff2') format('woff2'),*/
/*url('../fonts/roboto-light-webfont.woff') format('woff'),*/
/*url('../fonts/Roboto-Light.ttf') format('ttf');*/
/*font-weight: normal;*/
/*font-style: normal;*/
/*}*/
.staticrypt-page {
width: 360px;
padding: 8% 0 0;
margin: auto;
}
.staticrypt-form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.staticrypt-form label {
/*font-family: "Roboto", sans-serif;*/
}
.staticrypt-form input {
/*font-family: "Roboto", sans-serif;*/
outline: 0;
background: #f2f2f2;
width: 100%;
border: 0;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
}
.staticrypt-form .login-btn {
/*font-family: "Roboto", sans-serif;*/
text-transform: uppercase;
outline: 0;
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
}
.staticrypt-form .staticrypt-decrypt-button:hover, .staticrypt-form .staticrypt-decrypt-button:active, .staticrypt-form .staticrypt-decrypt-button:focus {
background: #43A047;
}
.staticrypt-html {
height: 100%;
}
.staticrypt-body {
height: 100%;
margin-bottom: 2em;
background: #76b852; /* fallback for old browsers */
background: -webkit-linear-gradient(right, #76b852, #8DC26F);
background: -moz-linear-gradient(right, #76b852, #8DC26F);
background: -o-linear-gradient(right, #76b852, #8DC26F);
background: linear-gradient(to left, #76b852, #8DC26F);
/*font-family: "Roboto", sans-serif;*/
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.staticrypt-title {
font-size: 1.5em;
margin-top: -1em;
margin-bottom: 1em;
}
.staticrypt-footer {
position: fixed;
height: 2em;
background-color: white;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 0;
text-align: center;
}
</style>
</head>
<body class="staticrypt-body">
<div class="staticrypt-page">
<div class="form">
<div class="staticrypt-title">
<p>{{:title}}</p>
<p>{{:instructions}}</p>
</div>
<hr>
<form id="staticrypt-form" action="#" method="post">
<input id="staticrypt-password"
type="password"
name="password"
placeholder="password"/>
<input type="submit" class="staticrypt-decrypt-button" value="DECRYPT"/>
</form>
</div>
</div>
<footer class="staticrypt-footer">
<p>Created with StatiCrypt</p>
</footer>
<!--<script-->
<!--src="https://code.jquery.com/jquery-3.2.1.min.js"-->
<!--integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="-->
<!--crossorigin="anonymous"></script>-->
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>-->
<script src="jquery-3.2.1.min.js"></script>
<script src="crypto-js.js"></script>
<script>
$(function(){
$('#staticrypt-form').submit(function(e){
e.preventDefault();
var passphrase = $('#staticrypt-password').val();
var encryptedMsg = '{{:encrypted}}';
var encryptedHMAC = encryptedMsg.substring(0, 64);
var encryptedHTML = encryptedMsg.substring(64);
var decryptedHMAC = CryptoJS.HmacSHA256(encryptedHTML, CryptoJS.SHA256(passphrase)).toString();
if (decryptedHMAC !== encryptedHMAC) {
alert('Bad passphrase !');
return;
}
var plainHTML = CryptoJS.AES.decrypt(encryptedHTML, passphrase).toString(CryptoJS.enc.Utf8);
document.write(plainHTML);
});
});
</script>
</body>
</html>