From a10b0d36cca8444abc0934f70da4e47931752633 Mon Sep 17 00:00:00 2001 From: Douglas Muth Date: Mon, 27 Apr 2015 20:48:57 -0400 Subject: [PATCH] Added a check to see if proper crypto is available, and a warning if it is not. --- index.html | 23 ++++++++++++++++++++++- main.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 8694985..63ffba9 100644 --- a/index.html +++ b/index.html @@ -89,12 +89,23 @@
Your passphrase is:
- + + + +
+
+

Number of Dice to roll:

@@ -166,10 +177,20 @@ By all means, feel free to do so. LastPass is an excellent product and I highly If, on the other hand, you prefer to be able to actually remember your passwords, I recommend Diceware or a similar system. + +

FAQ: Are these dice roles cryptographically secure?

+ +Yes, insofar as we're using the getRandomValues() function in Javascript, and you trust that your +browser and computer have not been compromised or otherwise tampered with. Keep in mind that a not-so-theoretical attack +would be for an attacker to compromise the random number generator on your computer so that +anything that is encrypted (or passkeys generated) would be suspectible to less intense cryptoanalysis. + +

FAQ: Is the source available?

Yep! You can grab a copy at https://github.com/dmuth/diceware +

Who built this? / Contact

My name is Douglas Muth, and I am a software engineer in Philadelphia, PA. diff --git a/main.js b/main.js index ddaab54..1d8538f 100644 --- a/main.js +++ b/main.js @@ -3,14 +3,48 @@ */ (function() { + +/** +* Return true if we have a function that returns cryptographically random +* values. False otherwise. +*/ +function i_can_has_good_crypto() { + + if (window.crypto && window.crypto.getRandomValues) { + return(true); + } + + return(false); + +} // End of i_can_has_good_crypto() + + /** * Roll a die. * * @return integer A random number between 1 and 6, inclusive. */ function die_roll() { - return(Math.floor(Math.random() * 6) + 1); -} + + var retval; + + if (i_can_has_good_crypto()) { + var a = new Uint32Array(1); + window.crypto.getRandomValues(a); + retval = (a[0] % 6) + 1; + + } else { + // + // Fall back to something way less secure. The user has already + // been warned. + // + retval = Math.floor(Math.random() * 6) + 1; + + } + + return(retval); + +} // End of die_roll() /** @@ -246,6 +280,7 @@ jQuery("#roll_dice").on("click", function(e) { }); + // // If we're not on a mobile, bring in the GitHub ribbon. // @@ -253,6 +288,10 @@ if (!is_mobile()) { jQuery("#github_ribbon").fadeIn(1000); } +if (!i_can_has_good_crypto()) { + jQuery(".source .bad_crypto").clone().hide().fadeIn(800).appendTo(".message"); +} + // // Load our wordlist. //