Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard-free password generator, courtesy of JasonJShuler #218

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 180 additions & 1 deletion app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,12 @@ <h3>
<h1>Please connect your OnlyKey</h1>
</dialog>

<dialog id="udev-dialog" class="silver-gradient-bg">
<h1>Error connecting</h1>
<h3>Do you need a UDEV rule?</h3>
<p>See the <u><a class="external" href="https://docs.onlykey.io/linux.html#udev-rule">OnlyKey for Linux docs</a></u> for more info.</p>
</dialog>

<dialog id="working-dialog" class="silver-gradient-bg">
<h1>Working...</h1>
<h2>Please wait</h2>
Expand Down Expand Up @@ -1459,6 +1465,171 @@ <h2>Please choose a key</h2>
<div id="selectPrivateKeyError" class="form-error"></div>
</dialog>

<dialog id="password-generator-dialog">
<h2>Strong Random Password Generator</h2>
<p>Generate complex, random password without the risk of a clipboard leak.<br/>
Make any necessary modifications before applying.</p>
<form name="password-generator-form" id="password-generator-form">
<table>
<tr class="universal-option">
<td colspan="2">
<input
type="text"
id="txtPassGen"
name="txtPassGen"
value=""
maxlength="56"
style="width: 100%;"
/>
</td>
</tr>
<tr class="universal-option">
<td>
<label>
<input
type="number"
id="numPassGenLen"
name="numPassGenLen"
value="48"
min="6"
max="56"
/>
Length (6-56)
</label>
</td>
<td>
<input
type="button"
id="btnPassGen"
name="btnPassGen"
value="Generate New Password"
/>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenUpper"
name="chkPassGenUpper"
checked="checked"
/>
Uppercase A-Z
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenLower"
name="chkPassGenLower"
checked="checked"
/>
Lowercase a-z
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenDigits"
name="chkPassGenDigits"
checked="checked"
/>
Digits 0-9
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenSpecial"
name="chkPassGenSpecial"
checked="checked"
/>
Special ~!@#$%^&amp;*+=-_
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenPunct"
name="chkPassGenPunct"
checked="checked"
/>
Punctuation &quot;&apos;;:,.?
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenBraces"
name="chkPassGenBraces"
checked="checked"
/>
Braces (){}[]&lt;&gt;
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="checkbox"
id="chkPassGenSpace"
name="chkPassGenSpace"
/>
Space
</label>
</td>
</tr>
<tr class="universal-option">
<td colspan="2">
<label>
<input
type="text"
id="txtPassGenOmit"
name="txtPassGenOmit"
value=""
/>
Disallowed character list
</label>
</td>
</tr>
<tr class="universal-option">
<td>
<input
type="button"
id="passGenCancel"
name="passGenCancel"
value="Cancel"
/>
</td>
<td>
<input
type="button"
id="passGenSubmit"
name="passGenSubmit"
value="Use Password"
/>
</td>
</tr>
</table>
</form>
</dialog>
<dialog id="slot-config-dialog" data-mode="basic" class="silver-gradient-bg">
<div id="slot-config-top-links">
<a href="" class="slot-config-close" title="Close">close &#9746;</a>
Expand Down Expand Up @@ -1637,6 +1808,14 @@ <h2>OnlyKey Slot <span class="slotId">1a</span> Configuration</h2>
maxlength="56"
/>
</td>
<td>
<input
type="button"
id="btnLaunchPassGen"
name="btnLaunchPassGen"
value="Gen"
/>
</td>
</tr>
<tr class="basic-option">
<td>Re-enter Password</td>
Expand Down Expand Up @@ -1915,4 +2094,4 @@ <h2>Example #3</h2>
<script src="/scripts/external-links.js"></script>
<script src="/scripts/dialog-links.js"></script>
</body>
</html>
</html>
13 changes: 9 additions & 4 deletions app/scripts/external-links.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const openMethod = typeof nw === 'undefined' ? window.open : nw.Shell.openExternal;

// Formerly checked for 'external' in classList. Now fires for all https:// links.
document.querySelector('#main').addEventListener('click', evt => {
const handler = evt => {
let href = evt.target && evt.target.href;
if (!href) href = evt.target && evt.target.offsetParent && evt.target.offsetParent.href;
if (!href) href = evt.path && evt.path[1] && evt.path[1].href;


// Formerly checked for 'external' in classList. Now fires for all https:// links.
if (!!href && href.indexOf('https://') == 0) {
openMethod(href);
evt.preventDefault && evt.preventDefault();
evt.stopPropgation && evt.stopPropagation();
}
});
};

[
'#main',
'#udev-dialog',
].forEach(sel => document.querySelector(sel).addEventListener('click', handler));
20 changes: 19 additions & 1 deletion app/scripts/onlyKey/OnlyKeyComm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if (desktopApp) {
request = require("request");
}

const os = require('os');
const linux = os.platform() === 'linux';

let backupsigFlag = -1;
let fwchecked = false;
let dialog;
Expand Down Expand Up @@ -1077,6 +1080,7 @@ var ui = {
lockedDialogDuo: null,
workingDialog: null,
disconnectedDialog: null,
udevDialog: null,
main: null,
};

Expand Down Expand Up @@ -1267,9 +1271,23 @@ var connectDevice = async function (device) {

chromeHid.connect(deviceId, async function (connectInfo) {
if (chrome.runtime.lastError) {
console.error("ERROR CONNECTING:", chrome.runtime.lastError);
console.error(`ERROR CONNECTING: ${chrome.runtime.lastError.message}`, device);
if (linux) {
dialog.open(ui.udevDialog);
} else {
if (confirm(`ERROR: ${chrome.runtime.lastError.message}\n\nRetry?`)) {
return await connectDevice(device);
}
}
} else if (!connectInfo) {
console.warn("Unable to connect to device.");
if (confirm(`ERROR: Unable to read device info.\n\nRetry?`)) {
return await connectDevice(device);
}
}

if (!connectInfo) {
return;
}

myOnlyKey.setConnection(connectInfo.connectionId);
Expand Down
107 changes: 106 additions & 1 deletion app/scripts/onlyKey/OnlyKeyWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,35 @@ if (chrome.passwordsPrivate) {
this.setSlot();
};

this.passwordGeneratorForm = document['password-generator-form'];
this.passwordGeneratorDialog = document.getElementById('password-generator-dialog');

this.btnLaunchPassGen = document.getElementById('btnLaunchPassGen');
this.btnLaunchPassGen.onclick = e => {
e && e.preventDefault && e.preventDefault();
this.dialog.open(this.passwordGeneratorDialog, true);
};

this.btnPassGen = document.getElementById('btnPassGen');
this.btnPassGen.onclick = e => {
e && e.preventDefault && e.preventDefault();
this.generatePassword();
};

this.passGenSubmit = document.getElementById('passGenSubmit');
this.passGenSubmit.onclick = e => {
e && e.preventDefault && e.preventDefault();
this.dialog.close(this.passwordGeneratorDialog);
this.setPassword(this.passwordGeneratorForm.txtPassGen.value);
this.passwordGeneratorForm.txtPassGen.value = "";
};

this.passGenCancel = document.getElementById('passGenCancel');
this.passGenCancel.onclick = e => {
e && e.preventDefault && e.preventDefault();
this.dialog.close(this.passwordGeneratorDialog);
this.passwordGeneratorForm.txtPassGen.value = "";
};

document.getElementById("locked-text-duo").classList.remove("hide");
document.getElementById("max-pin-attempts-duo").classList.add("hide");
Expand Down Expand Up @@ -1141,6 +1170,82 @@ if (chrome.passwordsPrivate) {
this.dialog.close(this.slotConfigDialog);
}

Wizard.prototype.generatePassword = function () {
const crypto = require("crypto");
const form = this.passwordGeneratorForm;
const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lower = "abcedfghijklmnopqrstuvwxyz";
const digit = "0123456789";
const special = "~!@#$%^&*+=-_";
const punct = "\"\';:,.?";
const brace = "(){}[]<>";
const space = " ";

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

pwLen = form.numPassGenLen.value;

charMap = "";

if (form.chkPassGenUpper.checked) {
charMap += upper;
}
if (form.chkPassGenLower.checked) {
charMap += lower;
}
if (form.chkPassGenDigits.checked) {
charMap += digit;
}
if (form.chkPassGenSpecial.checked) {
charMap += special;
}
if (form.chkPassGenPunct.checked) {
charMap += punct;
}
if (form.chkPassGenBraces.checked) {
charMap += brace;
}
if (form.chkPassGenSpace.checked) {
charMap += space;
}

if (form.txtPassGenOmit.value != "") {
badCharRegex = new RegExp('[' + escapeRegExp(form.txtPassGenOmit.value) + ']', 'gm');
charMap = charMap.replace(badCharRegex,'');
}

mapLen = charMap.length;

newPw = "";

for (let i=0; i < pwLen; i++) {
newChar = charMap[crypto.randomInt(0, mapLen - 1)];

// Ensure a space isn't used as the first or last character - likelihood of string trimming causing problems is too high
if ((i == 0 || i == pwLen - 1) && newChar === ' ') {
while (newChar !== ' ') {
newChar = charMap[crypto.randomInt(0, mapLen - 1)];
}
}

newPw += newChar;
}

form.txtPassGen.value = newPw;
newPw = "";
}

Wizard.prototype.setPassword = function (pw) {
const form = this.slotConfigForm;
form.txtPassword.value = pw;
form.txtPasswordConfirm.value = pw;
//Ensure any present or future validation events are fired
form.txtPassword.dispatchEvent(new Event('input', { 'bubbles': true }));
form.txtPasswordConfirm.dispatchEvent(new Event('input', { 'bubbles': true }));
};

Wizard.prototype.getMode = function () {
return this.initForm['ConfigMode'].value;
};
Expand Down Expand Up @@ -1542,4 +1647,4 @@ function base32tohex(base32) {
}

return hex;
}
}
Loading