diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-12-01 13:31:33 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-12-03 15:07:52 +0100 |
commit | b1aa43c51e72fb0744ae1e98f4251d09f5b20bfb (patch) | |
tree | e796a6aac07924daac52c67350dd549bc9826ed2 /contrib/examples/keygen-html/keygen.html | |
parent | kernel-tree: jury rig is the more common spelling (diff) | |
download | wireguard-monolithic-historical-b1aa43c51e72fb0744ae1e98f4251d09f5b20bfb.tar.xz wireguard-monolithic-historical-b1aa43c51e72fb0744ae1e98f4251d09f5b20bfb.zip |
contrib: keygen-html for generating keys in the browser
Diffstat (limited to 'contrib/examples/keygen-html/keygen.html')
-rw-r--r-- | contrib/examples/keygen-html/keygen.html | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/contrib/examples/keygen-html/keygen.html b/contrib/examples/keygen-html/keygen.html new file mode 100644 index 0000000..a6c7392 --- /dev/null +++ b/contrib/examples/keygen-html/keygen.html @@ -0,0 +1,71 @@ +<script src="curve25519_generate.js"></script> +<script> +// License: GPLv2 +function generateWireguardKeypair() +{ + var privateKey = Module._malloc(32); + var publicKey = Module._malloc(32); + Module._curve25519_generate_private(privateKey); + Module._curve25519_generate_public(publicKey, privateKey); + var privateBase64 = Module._malloc(45); + var publicBase64 = Module._malloc(45); + Module._key_to_base64(privateBase64, privateKey); + Module._key_to_base64(publicBase64, publicKey); + Module._free(privateKey); + Module._free(publicKey); + var keypair = { + publicKey: Module.Pointer_stringify(publicBase64), + privateKey: Module.Pointer_stringify(privateBase64) + }; + Module._free(privateBase64); + Module._free(publicBase64); + return keypair; +} + +function sendPubkeyToServer(pubkey, username, password) +{ + alert("Sending " + username + ":" + password + " to server for new pubkey " + pubkey + "..."); + + // send info to server + + var serverResponse = { + publicKey: "6spHEFoJrp9pijbxjJoS6fHjZaAWQqtdFFO/OtpVe3w=", + allowedIPs: [ "0.0.0.0/0", "::/0" ], + endpoint: "demo.wireguard.com:63321", + address: [ "192.168.18.42/32", "fd08:1234:1111::77/128" ], + dns: [ "8.8.8.8", "8.8.4.4" ] + } + + return serverResponse; +} + +function downloadNewConfiguration() +{ + var keypair = generateWireguardKeypair(); + var serverResponse = sendPubkeyToServer(keypair.publicKey, "zx2c4", "supersecretpassword"); + + var config = []; + config.push("[Interface]"); + config.push("PrivateKey = " + keypair.privateKey); + config.push("Address = " + serverResponse.address.join(", ")); + config.push("DNS = " + serverResponse.dns.join(", ")); + config.push(""); + config.push("[Peer]"); + config.push("PublicKey = " + serverResponse.publicKey); + config.push("AllowedIPs = " + serverResponse.allowedIPs.join(", ")); + config.push("Endpoint = " + serverResponse.endpoint); + config.push(""); + config = config.join("\n"); + + var blob = new Blob([config], { type: "text/plain" }); + var a = document.createElement("a"); + a.download = "demo0.conf"; + a.href = URL.createObjectURL(blob); + a.style.display = "none"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); +} +</script> + +<a href="javascript:downloadNewConfiguration()">Download a WireGuard configuration file</a> |