-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.html
186 lines (155 loc) · 5 KB
/
template.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
<!DOCTYPE html>
<html class="html">
<head>
<meta charset="utf-8" />
<title>Protected Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<style>
.hr {
margin-top: 20px;
margin-bottom: 20px;
border: 0;
border-top: 1px solid #eee;
}
.page {
width: 360px;
padding: 8% 0 0;
margin: auto;
box-sizing: border-box;
}
.form {
position: relative;
z-index: 1;
background: #ffffff;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
border-radius: 3px;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2),
0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
outline: 0;
background: #f2f2f2;
width: 100%;
border: 0;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
border-radius: 3px;
}
.form .decrypt-button {
text-transform: uppercase;
outline: 0;
background: #00cae9;
width: 100%;
border: 0;
padding: 15px;
color: #ffffff;
font-size: 14px;
cursor: pointer;
border-radius: 3px;
}
.form .decrypt-button:active {
background: #009db5;
}
.html {
height: 100%;
}
.body {
margin-bottom: 1em;
background: #00cae9;
font-family: "Arial", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
display: none;
}
.instructions {
margin-top: -1em;
margin-bottom: 1em;
}
.title {
font-size: 1.5em;
}
</style>
</head>
<body class="body" onload="onload()">
<div class="page">
<div class="form">
<div class="instructions">
<p class="title">Protected Page</p>
</div>
<hr class="hr" />
<form id="form" action="#" method="post">
<input id="password" type="password" name="password" placeholder="Password" autofocus />
<input type="submit" class="decrypt-button" value="DECRYPT"/>
</form>
</div>
</div>
<script>
const STORAGE_KEY = 'coverage';
function decryptContent(encryptedMsg, pass) {
const salt = CryptoJS.enc.Hex.parse(encryptedMsg.substr(0, 32));
const iv = CryptoJS.enc.Hex.parse(encryptedMsg.substr(32, 32));
const encrypted = encryptedMsg.substring(64);
const key = CryptoJS.PBKDF2(pass, salt, {
keySize: 8,
iterations: 10
});
return CryptoJS.AES.decrypt(encrypted, key, {
iv,
padding: CryptoJS.pad.Pkcs7,
mode: CryptoJS.mode.CBC
}).toString(CryptoJS.enc.Utf8);
}
function decryptAndReplace(pass, suppress = false) {
const encryptedMsg = "{encrypted}";
const encryptedHMAC = encryptedMsg.substring(0, 64);
const encryptedHTML = encryptedMsg.substring(64);
const decryptedHMAC = CryptoJS.HmacSHA256(
encryptedHTML,
CryptoJS.SHA256(pass).toString()
).toString();
if (decryptedHMAC !== encryptedHMAC) {
if (!suppress) {
alert( 'Wrong password!' );
}
sessionStorage.removeItem(STORAGE_KEY);
return false;
}
// Save for the session
sessionStorage.setItem(STORAGE_KEY, pass);
const plainHTML = decryptContent(encryptedHTML, pass);
document.write(plainHTML);
document.close();
return true;
}
function onload() {
if (sessionStorage.getItem(STORAGE_KEY) && decryptAndReplace(sessionStorage.getItem(STORAGE_KEY),true)) {
return;
}
// Show page because there isn't a good password
// Otherwise, document.write would have stop this
document
.querySelectorAll(".body")
.forEach(el => (el.style.display = "block"));
document
.getElementById("form")
.addEventListener("submit", e => {
e.preventDefault();
decryptAndReplace(
document.getElementById("password").value
);
});
}
</script>
<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"></script>
</body>
</html>