keygen-html: remove prebuilt file

We also reduce the optimization level, just in case, but add closure
compiler into the mix.

Suggested-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2017-12-12 01:08:18 +01:00
parent 01d00bc035
commit 89b983fa22
7 changed files with 42 additions and 45 deletions

1
contrib/keygen-html/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
curve25519_generate.js

View file

@ -0,0 +1,6 @@
curve25519_generate.js: src/curve25519_generate.c src/glue.js
emcc -O2 --memory-init-file 0 --closure 1 --post-js src/glue.js -o $@ src/curve25519_generate.c
clean:
rm -f curve25519_generate.js
all: curve25519_generate.js
.PHONY: clean all

View file

@ -17,3 +17,11 @@ introduces interesting side-channel attacks.
Secrets aren't zerored after use. Maybe you can get around this with Secrets aren't zerored after use. Maybe you can get around this with
some tricks taking advantage of browser allocator behavior and different some tricks taking advantage of browser allocator behavior and different
processes, but it seems pretty hard. processes, but it seems pretty hard.
Building
--------
In order to use the example `keygen.html` file, you must first build
the C sources using emscripten. Simply run:
$ make

File diff suppressed because one or more lines are too long

View file

@ -1,29 +1,9 @@
<script src="curve25519_generate.js"></script> <script src="curve25519_generate.js" onError='document.write("<h3>Did you forget to run \"make\" to compile curve25519_generate.js?</h3><!--");'></script>
<script> <script>
/* SPDX-License-Identifier: GPL-2.0 /* SPDX-License-Identifier: GPL-2.0
* *
* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. * Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/ */
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) function sendPubkeyToServer(pubkey, username, password)
{ {
@ -44,7 +24,7 @@ function sendPubkeyToServer(pubkey, username, password)
function downloadNewConfiguration() function downloadNewConfiguration()
{ {
var keypair = generateWireguardKeypair(); var keypair = WireGuard.generateKeypair();
var serverResponse = sendPubkeyToServer(keypair.publicKey, "zx2c4", "supersecretpassword"); var serverResponse = sendPubkeyToServer(keypair.publicKey, "zx2c4", "supersecretpassword");
var config = []; var config = [];

View file

@ -2,8 +2,6 @@
* *
* Copyright (C) 2008 Google Inc. All Rights Reserved. * Copyright (C) 2008 Google Inc. All Rights Reserved.
* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. * Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*
* Build with emcc -O3 --memory-init-file 0 -o curve25519_generate.js curve25519_generate.c
*/ */
#include <emscripten.h> #include <emscripten.h>

View file

@ -0,0 +1,25 @@
/*! SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
window["WireGuard"] = {
"generateKeypair": function() {
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;
}
};