From fa46ebf45477e0dfdfa2c117e73f1ac09df81f80 Mon Sep 17 00:00:00 2001 From: Aaron Toponce Date: Mon, 11 Sep 2017 09:38:00 -0600 Subject: [PATCH] fix regression where entropy was not getting set correctly per generator --- README.md | 130 ++++++++++++++++++++++++++++++++-------------------- nodepassgen | 16 ++++++- 2 files changed, 95 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 995cf01..102a336 100644 --- a/README.md +++ b/README.md @@ -8,56 +8,86 @@ be needed to view the emoji characters correctly. Options are: - --help - Print this help and exit. - - --diceware - Choose a Diceware language. Default is English. - must be one of: - Basque, Beale, Bulgarian, Catalan, Chinese, Czech, - Danish, Dutch, English, Esperanto, Finnish, French, - German, Italian, Japanese, Maori, Norwegian, Polish, - Portuguese, Russian, Slovenian, Spanish, Swedish, Turkish. - - --eff - Choose an EFF wordlist. Default is Short. - must be one of: - Distant, Long, Short. - - --alternate - Choose an alternate wordlist. Default is PGP. - must be one of: - Bitcoin, Elvish, Klingon, PGP - RockYou, Simpsons, Trump - - --ninja - Choose Secret Ninja encoding. - - --cosby - Choose Bill Cosby Bebob. - - --kpop - Choose Korean K-pop words. - - --random - Choose a number base to generated. Default is Base94 - must be one of: - Base94, Base64, Base32, Base16, Base10. - - --only - Choose a generator instead of printing all six (default). - NOTE: A font supporting emoji may be needed for the Emoji generator. - must be one of: - Diceware, EFF, Alternate, Pseudowords, Random, Emoji - - --min-entropy - Set a minimum entropy requirement in bits. Default is 70. - - --json - Output the passwords and meta in JSON format. - - --hyphenate - Add hyphens to the Diceware, EFF, and Alternate passphrases. + -h + --help + Print this help and exit. + + -d + --diceware + Choose a Diceware language. Default is English. + must be one of: + Basque, Beale, Bulgarian, Catalan, Chinese, Czech, + Danish, Dutch, English, Esperanto, Finnish, French, + German, Italian, Japanese, Maori, Norwegian, Polish, + Portuguese, Russian, Slovenian, Spanish, Swedish, Turkish. + + -e + --eff + Choose an EFF wordlist. Default is Short. + must be one of: + Distant, Long, Short. + + -a + --alternate + Choose an alternate wordlist. Default is Trump. + must be one of: + Elvish, Klingon, PGP, Rockyou, Simposons, Trump + + -b + --bitcoin + Choose a Bitcoin language. Default is English. + must be one of: + Chinese, English, French, Italian, Japanese, Korean + NOTE: + Simplified Chinese is the default Chinese character set. + If you want to use Traditional Chinese, use --traditional. + + -t + --traditional + Use the Traditional Chinese character set with Bitcoin. + + -s + --system + Use /usr/share/dict/words for building your passphrase. + Obviously, the more words in that file, the more entropy per word. + Also, larger system word lists will contain more obscure words. + + -n + --ninja + Choose Secret Ninja encoding. + + -c + --cosby + Choose Bill Cosby Bebob. + + -k + --kpop + Choose Korean K-pop words. + + -e + --random + Choose a number base to generated. Default is Base94 + must be one of: + Base94, Base64, Base32, Base16, Base10. + + -o + --only + Choose a generator instead of printing all six (default). + must be one of: + Alternate, Bitcoin, Diceware, EFF System, + Pseudowords, Random, or Emoji + + -m + --min-entropy + Set a minimum entropy requirement in bits. Default is 70. + + -j + --json + Output the passwords and meta in JSON format. + + -H + --hyphenate + Add hyphens to the Diceware, EFF, and Alternate passphrases. Output can be valid JSON, meant to be both human and machine parseable. Default is unformatted plaintext: diff --git a/nodepassgen b/nodepassgen index 9b1a866..de9502f 100755 --- a/nodepassgen +++ b/nodepassgen @@ -5,7 +5,6 @@ const crypto = require('crypto'); var spaces=false; var results = []; var args = process.argv; -var entropy = get_entropy(); function print_usage() { console.log("Usage: node main.js [OPTION [ARG]]..."); @@ -284,6 +283,7 @@ function generate_diceware() { process.exit(1); } var assoc_arr = {}; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(wordlist.length)); var pass = generate_pass(len, wordlist, true); if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) { @@ -329,6 +329,7 @@ function generate_eff() { process.exit(); } var assoc_arr = {}; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(wordlist.length)); var pass = generate_pass(len, wordlist, true); if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) { @@ -391,6 +392,7 @@ function generate_alternate() { process.exit(1); } var assoc_arr = {}; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(wordlist.length)); var pass = generate_pass(len, wordlist, true); if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) { @@ -462,6 +464,7 @@ function generate_bitcoin() { process.exit(1); } var assoc_arr = {}; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(wordlist.length)); var pass = generate_pass(len, wordlist, true); if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) { @@ -479,6 +482,7 @@ function generate_sys_pass() { var dict = fs.readFileSync("/usr/share/dict/words").toString(); var wordlist = dict.split('\n'); var assoc_arr = {}; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(wordlist.length)); var pass = generate_pass(len, wordlist, true); if ((args.indexOf("--hyphenate") != -1) || (args.indexOf("-H")) != -1) { @@ -494,6 +498,7 @@ function generate_sys_pass() { function generate_ninja() { var ninja = ['ka','zu','mi','te','ku','lu','ji','ri','ki','zu','me','ta','rin','to','mo','no','ke','shi','ari','chi','do','ru','mei','na','fu','zi']; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(ninja.length)); var pass = ""; @@ -509,6 +514,7 @@ function generate_ninja() { function generate_cosby() { // 32 unique words = 5 bits of entropy per word var cosby = ['Bada','Badum','Bee','Bloo','Bop','Caw','Derp','Dip','Doo','Dub','Hip','Ka','Loo','Meep','Mim','Moom','Na','Naw','Nerp','Nup','Pa','Papa','Spee','Squee','Squoo','Woobly','Wop','Yee','Zap','Zip','Zop','Zoop','Zow']; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(cosby.length)); var pass = ""; @@ -524,6 +530,7 @@ function generate_cosby() { function generate_kpop() { // 64 unique words = 6 bits of entropy per word var kpop = ['A','Ah','Bae','Bin','Bo','Choi','Chul','Da','Do','Dong','Eun','Gi','Gun','Ha','Hae','Hee','Ho','Hu','Hwa','Hwan','Hye','Hyo','Hyun','Il','In','Ja','Jae','Ji','Jin','Jong','Joo','Joon','Ju','Jun','Jung','Ki','Kun','Kyu','Lee','Mi','Min','Moon','Nam','Ok','Park','Rin','Seo','Seul','Shi','Sik','So','Song','Soo','Su','Sun','Sung','Won','Woo','Ye','Yeon','Yoo','Yu','Yul','Yun']; + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(kpop.length)); var pass = ""; @@ -544,6 +551,7 @@ function generate_babble() { var c_ent = Math.log2(consonants.length); var out_ent = (2*c_ent)+(2*v_ent); var in_ent = (3*c_ent)+(2*v_ent); + var entropy = get_entropy(); entropy = entropy - (2*out_ent); var len = Math.ceil(entropy/in_ent); var tot_ent = out_ent + (len*in_ent) + out_ent; @@ -609,6 +617,7 @@ function generate_base94() { for (i=0; i<94; i++) { s += String.fromCharCode(33+i); } + var entropy = get_entropy(); var len = Math.ceil(entropy/Math.log2(s.length)); var pass = generate_pass(len, s); assoc_arr["Generator"] = "Random"; @@ -622,6 +631,7 @@ function generate_base94() { function generate_base64() { var assoc_arr = {}; var s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/"; + console.log(entropy); var len = Math.ceil(entropy/Math.log2(s.length)); var pass = generate_pass(len, s); assoc_arr["Generator"] = "Random"; @@ -635,6 +645,7 @@ function generate_base64() { function generate_base32() { var assoc_arr = {}; var s = "0123456789abcdefghjkmnpqrstvwxyz"; + console.log(entropy); var len = Math.ceil(entropy/Math.log2(s.length)); var pass = generate_pass(len, s); var result = "Base32: '" + pass + "', "; @@ -649,6 +660,7 @@ function generate_base32() { function generate_base16() { var assoc_arr = {}; var s = "0123456789abcdef" + console.log(entropy); var len = Math.ceil(entropy/Math.log2(s.length)); var pass = generate_pass(len, s); var result = "Base16: '" + pass + "', "; @@ -663,6 +675,7 @@ function generate_base16() { function generate_base10() { var assoc_arr = {}; var s = "0123456789" + console.log(entropy); var len = Math.ceil(entropy/Math.log2(s.length)); var pass = generate_pass(len, s); var result = "Base10: '" + pass + "', "; @@ -741,6 +754,7 @@ function generate_emoji() { const emoji_wordlist = require('./lists/random_emoji'); var wordlist = emoji_wordlist.wordlist; var assoc_arr = {}; + console.log(entropy); var len = Math.ceil(entropy/Math.log2(wordlist.length)); var pass = generate_pass(len, wordlist, true); pass = pass.replace(/ /g,"");