-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyGen.html
219 lines (176 loc) · 6.31 KB
/
KeyGen.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, input {
text-align: center;
}
input, #user_name, #user_name2 {
font-family: monospace, monospace;
}
body, input {
background: #000;
color: #bbb;
}
button {
background: #000;
padding: 0.25em 0.5em 0.25em 0.5em;
}
button:enabled {
cursor: pointer;
}
#div_gen {
background: #121010;
border-radius: 0.5em;
border: 0.25em solid #422;
width: fit-content;
margin: auto;
padding: 1em;
}
#div_gen_btn {
margin-top: 1em;
margin-bottom: 1em;
}
#agree {
margin-top: 1em;
line-height: 2em;
}
#btn_ready {
display: block;
margin: 1em auto;
line-height: 2em;
font-size: 1em;
color: #bbb;
}
#btn_cpy, #btn_shw {
color: #ccc;
font-family: monospace, monospace;
}
#btn_gen {
margin-left: 1em;
margin-right: 1em;
padding: 0.25em;
font-size: large;
color: #bbb;
}
#btn_cpy_uak, #btn_cpy_epk {
color: #bbb;
}
#btn_cpy_uak {
margin-right: 1em;
}
#btn_cpy_epk {
margin-left: 1em;
}
</style>
<title>All-Ears Mail Account Creator</title>
</head>
<body>
<div id="div_one">
<div id="div_gen">
Your name: <span id="user_uid">---</span>
<div id="div_gen_btn">
<button type="button" id="btn_shw" disabled autocomplete="off">Show</button> <button type="button" id="btn_gen" autofocus>Generate</button> <button type="button" id="btn_cpy" disabled autocomplete="off">Copy</button>
</div>
Your User Master Key (UMK):
<br>
<input type="password" readonly="readonly" size="60" id="user_umk" placeholder="Press Generate" autocomplete="off">
<br>
<b style="color: #b44;">Never share this key with anyone.</b>
</div>
<div>
<p>
If you lose your UMK, you will <b>never be able to access</b> your account again.
<br>
If anyone else discovers your UMK, they will gain <b>irrevocable full access</b> to your account.
</p>
<button id="btn_ready" disabled autocomplete="off">I have stored my UMK in a safe way</button>
</div>
</div>
<div id="div_two" hidden>
<p>
Your name will be: <span id="user_uid2">---</span>
</p>
<p>
<b style="color:red;">Never share your User Master Key (UMK) with anyone.</b>
</p>
<hr>
<p>To register your account, an administrator needs two different keys from you:</p>
<p>
Your User Access Key (UAK):
<br>
<input type="text" readonly="readonly" size="74" id="user_uak">
</p>
<p>
Your Envelope Public Key (EPK):
<br>
<input type="text" readonly="readonly" size="64" id="user_epk">
</p>
<p>
<button id="btn_cpy_uak">Copy UAK</button>
<button id="btn_cpy_epk">Copy EPK</button>
</p>
<p><b style="color:lightgreen;">Only share these two keys with an administrator.</b></p>
<p>They are only needed for creating your account.</p>
<p>Do not store or share them unnecessarily.</p>
</div>
<script src="https://cdn.jsdelivr.net/gh/jedisct1/[email protected]/dist/browsers-sumo/sodium.js" integrity="sha384-xE+e4s598d4A0BKvbnkYaqRYutiZTg3KzqnWK51WA6h0yoCZ3uuV52KsntFIWScg" crossorigin="anonymous"></script>
<script>
sodium.ready.then(function() {
const _AEM_KDF_KEYID_UMK_UAK = 1;
const _AEM_KDF_KEYID_UMK_ESK = 2;
const _AEM_KDF_KEYID_UAK_UID = new Uint8Array([0x01,0,0,0,0,0,0,0]);
const _aem_kdf_umk = function(size, id, key) {
const counter = (id << 8) | (key[44] << 16);
return sodium.crypto_stream_chacha20_ietf_xor_ic(new Uint8Array(size), key.slice(32, 44), counter, key.slice(0, 32));
}
const _aem_kdf_sub = function(size, n, key) {
const counter = ((key[36] & 127) << 24) | ((key[36] & 128) << 16);
const nonce = new Uint8Array([key[32], key[33], key[34], key[35], n[0], n[1], n[2], n[3], n[4], n[5], n[6], n[7]]);
return sodium.crypto_stream_chacha20_ietf_xor_ic(new Uint8Array(size), nonce, counter, key.slice(0, 32));
}
document.getElementById("btn_gen").onclick = function() {
const umk = window.crypto.getRandomValues(new Uint8Array(45));
const uak = _aem_kdf_umk(37, _AEM_KDF_KEYID_UMK_UAK, umk);
const esk = _aem_kdf_umk(32, _AEM_KDF_KEYID_UMK_ESK, umk);
const epk = sodium.crypto_scalarmult_base(esk);
const uid = new Uint16Array(_aem_kdf_sub(2, _AEM_KDF_KEYID_UAK_UID, uak).buffer)[0] & 4095;
if (uid === 0) return document.getElementById("btn_gen").onclick();
document.getElementById("user_uid").textContent = String.fromCharCode(97 + (uid & 15)) + String.fromCharCode(97 + ((uid >> 4) & 15)) + String.fromCharCode(97 + ((uid >> 8) & 15));
document.getElementById("user_umk").value = sodium.to_base64(umk, sodium.base64_variants.ORIGINAL_NO_PADDING);
document.getElementById("user_uak").value = sodium.to_hex(uak);
document.getElementById("user_epk").value = sodium.to_hex(epk);
document.getElementById("btn_ready").disabled = false;
document.getElementById("btn_shw").disabled = false;
document.getElementById("btn_cpy").disabled = false;
}
document.getElementById("btn_ready").onclick = function() {
document.getElementById("user_umk").value = "";
document.getElementById("user_uid2").textContent = document.getElementById("user_uid").textContent;
document.getElementById("div_one").hidden = true;
document.getElementById("div_two").hidden = false;
}
document.getElementById("btn_cpy").onclick = function() {
navigator.clipboard.writeText(document.getElementById("user_umk").value);
}
document.getElementById("btn_cpy_uak").onclick = function() {
navigator.clipboard.writeText(document.getElementById("user_uak").value);
}
document.getElementById("btn_cpy_epk").onclick = function() {
navigator.clipboard.writeText(document.getElementById("user_epk").value);
}
document.getElementById("btn_shw").onclick = function() {
if (document.getElementById("btn_shw").textContent === "Show") {
document.getElementById("btn_shw").textContent = "Hide";
document.getElementById("user_umk").type = "text";
} else {
document.getElementById("btn_shw").textContent = "Show";
document.getElementById("user_umk").type = "password";
}
}
});
</script>
</body>
</html>