From 3007eb8ed579d6ea27fa220d25744b3d69dc3e21 Mon Sep 17 00:00:00 2001 From: Date: Sat, 12 Aug 2017 15:49:36 +0200 Subject: [PATCH 1/9] support 8-digit OTP, support manual input of 8-digit OTP, support QRCode input of 8-digit OTP --- _locales/en/messages.json | 8 ++++++++ _locales/zh_CN/messages.json | 8 ++++++++ javascript/background.js | 6 +++++- javascript/popup.js | 23 +++++++++++++++++++++-- popup.html | 12 +++++++++++- totp/totp.js | 4 ++-- 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a8af031..49db56e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -163,6 +163,14 @@ "message": "Counter Based", "description": "Counter Based" }, + "six_digit_otp": { + "message": "6 Digit OTP", + "description": "6 Digit OTP" + }, + "eight_digit_otp": { + "message": "8 Digit OTP", + "description": "8 Digit OTP" + }, "resize_popup_page": { "message": "Resize Popup Page", "description": "Resize Popup Page" diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index 94a2be1..981489e 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -163,6 +163,14 @@ "message": "基于计数器", "description": "Counter Based" }, + "six_digit_otp": { + "message": "6 Digit OTP", + "description": "6 Digit OTP" + }, + "eight_digit_otp": { + "message": "8 Digit OTP", + "description": "8 Digit OTP" + }, "resize_popup_page": { "message": "调整弹出页面尺寸", "description": "Resize Popup Page" diff --git a/javascript/background.js b/javascript/background.js index 5a4d23c..ab00a0d 100644 --- a/javascript/background.js +++ b/javascript/background.js @@ -54,7 +54,7 @@ function getTotp(text) { if (!label || !parameters) { chrome.tabs.sendMessage(id, {action: 'errorqr'}); } else { - var account, secret, issuer; + var account, secret, issuer, digits = 6; label = decodeURIComponent(label); if (label.indexOf(':') !== -1) { issuer = label.split(':')[0]; @@ -67,6 +67,8 @@ function getTotp(text) { var parameter = parameters[i].split('='); if (parameter[0].toLowerCase() === 'secret') { secret = parameter[1]; + } else if (parameter[0].toLowerCase() === 'digits' && parseInt(parameter[1], 10) === 8) { // strict check, 6 is default, only 6 or 8 allowed + digits = parameter[1]; } else if (parameter[0].toLowerCase() === 'issuer') { issuer = parameter[1]; } else if (parameter[0].toLowerCase() === 'counter') { @@ -84,6 +86,7 @@ function getTotp(text) { var addSecret = {}; if (decodedPhrase) { addSecret[CryptoJS.MD5(secret)] = { + digits: digits||6, account: account||'', issuer: issuer||'', type: type, @@ -93,6 +96,7 @@ function getTotp(text) { } } else { addSecret[CryptoJS.MD5(secret)] = { + digits: digits||6, account: account||'', issuer: issuer||'', type: type, diff --git a/javascript/popup.js b/javascript/popup.js index 0203169..fa6bd04 100644 --- a/javascript/popup.js +++ b/javascript/popup.js @@ -31,6 +31,8 @@ document.getElementById('add_qr').innerText = chrome.i18n.getMessage('add_qr'); document.getElementById('add_secret').innerText = chrome.i18n.getMessage('add_secret'); document.getElementById('totp_label').innerText = chrome.i18n.getMessage('based_on_time'); document.getElementById('hotp_label').innerText = chrome.i18n.getMessage('based_on_counter'); +document.getElementById('dig6_label').innerText = chrome.i18n.getMessage('six_digit_otp'); +document.getElementById('dig8_label').innerText = chrome.i18n.getMessage('eight_digit_otp'); document.getElementById('add_button').innerText = chrome.i18n.getMessage('ok'); document.getElementById('message_close').innerText = chrome.i18n.getMessage('ok'); document.getElementById('account_label').innerText = chrome.i18n.getMessage('account'); @@ -67,6 +69,8 @@ chrome.storage.sync.get(showCodes); document.getElementById('menuExImport').onclick = showExport; +document.getElementById('secret_input').onkeyup = toggle6and8; + document.getElementById('menuAbout').onclick = function () { document.getElementById('info').className = 'fadein'; setTimeout(function () { @@ -369,7 +373,20 @@ function checkSecret(secret, type) { } } +function toggle6and8() { + var secret = document.getElementById('secret_input').value; + var battleRegEx = /^(bliz-|blz-)/gi; + var steamRegEx = /^stm-/gi + if(battleRegEx.test(secret) || steamRegEx.test(secret)) { + document.getElementById('dig6and8').style.display="none"; + } + else { + document.getElementById('dig6and8').style.display="block"; + } +} + function saveSecret() { + var digits = document.getElementById('dig8').checked ? 8 : 6; var account = document.getElementById('account_input').value; var secret = document.getElementById('secret_input').value; var type = document.getElementById('totp').checked ? 'totp' : 'hotp'; @@ -395,6 +412,7 @@ function saveSecret() { var addSecret = {}; if (decodedPhrase) { addSecret[CryptoJS.MD5(secret)] = { + digits : digits, account : account, issuer : '', type : type, @@ -404,6 +422,7 @@ function saveSecret() { } } else { addSecret[CryptoJS.MD5(secret)] = { + digits : digits, account : account, issuer : '', type : type, @@ -566,7 +585,7 @@ function updateCode() { }, 200); } } else if (_secret[i].type !== 'hotp') { - document.getElementById('code-' + i).innerText = getCode(_secret[i].secret); + document.getElementById('code-' + i).innerText = getCode(_secret[i].secret, undefined, _secret[i].digits); document.getElementById('showqr-' + i).className = 'showqr'; } } @@ -963,7 +982,7 @@ function getNewHotpCode() { } .bind(this), 5000); document.getElementById('code-' + codeId).setAttribute('hasCode', 'true'); - document.getElementById('code-' + codeId).innerText = getCode(_secret[codeId].secret, _secret[codeId].counter); + document.getElementById('code-' + codeId).innerText = getCode(_secret[codeId].secret, _secret[codeId].counter, _secret[codeId].digits); _secret[codeId].counter++; chrome.storage.sync.get(function (secret) { secret[CryptoJS.MD5(_secret[codeId].secret)].counter = _secret[codeId].counter; diff --git a/popup.html b/popup.html index 8f9506a..53a9a19 100644 --- a/popup.html +++ b/popup.html @@ -51,7 +51,7 @@ - +
@@ -60,6 +60,16 @@
+
+
+ + +
+
+ + +
+
diff --git a/totp/totp.js b/totp/totp.js index ff5853d..6d9b92d 100644 --- a/totp/totp.js +++ b/totp/totp.js @@ -55,9 +55,9 @@ var KeyUtilities = function() { return output; }; - var generate = function(secret, counter) { + var generate = function(secret, counter, len) { secret = secret.replace(/\s/g, ''); - var len = 6; + len = parseInt(len, 10) === 8 ? 8 : 6; var b26 = false; if(/^[a-z2-7]+=*$/.test(secret.toLowerCase())) { var key = base32tohex(secret); From 57d7ff90caf85129b6f2f7541571d0783b29bee3 Mon Sep 17 00:00:00 2001 From: Remon Pel Date: Sun, 13 Aug 2017 13:11:34 +0200 Subject: [PATCH 2/9] Move add button to header for direct access (and more similar to the smartphone app) --- css/popup.css | 24 ++++++------------------ popup.html | 3 +-- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/css/popup.css b/css/popup.css index 440ad01..beb4026 100644 --- a/css/popup.css +++ b/css/popup.css @@ -1,4 +1,4 @@ -@font-face { +font-face { font-family: 'Droid Sans Mono'; font-style: normal; font-weight: 400; @@ -316,7 +316,6 @@ body { overflow: hidden; } -#add, #add_qr, #add_secret, #add_button, @@ -337,10 +336,6 @@ body { cursor: pointer; } -#add { - margin-right: 0; -} - #message_close, #add_button, #exportButton, @@ -353,16 +348,6 @@ body { cursor: pointer; } -#codes #add { - font-size: 16px; - line-height: 56px; - display: none; -} - -#codes.edit #add { - display: block; -} - #codes .deleteAction { font-size: 20px; color: #DD4B39; @@ -393,7 +378,7 @@ body { display: none; } -#editAction { +#editAction, #add { position: absolute; right: 20px; bottom: 0; @@ -404,6 +389,9 @@ body { cursor: pointer; } +#add { + right: 50px; +} .counter { color: #888; font-size: 18px; @@ -574,7 +562,7 @@ body { #add_qr:hover, #editAction:hover, #infoAction:hover, -#codes #add:hover, +#add:hover, #infoClose:hover, #addAccountClose:hover, #securityClose:hover, diff --git a/popup.html b/popup.html index 53a9a19..76d8ba5 100644 --- a/popup.html +++ b/popup.html @@ -12,10 +12,9 @@ - +
-
+ diff --git a/scss/popup.scss b/scss/popup.scss index f4eedc3..b979ace 100644 --- a/scss/popup.scss +++ b/scss/popup.scss @@ -986,3 +986,5 @@ body { display: none; z-index: 1000; } +.color-gray { color: $gray; } +.color-red { color: $red; } \ No newline at end of file