-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add support for displaying TOTP keys as QR codes #1001
Add support for displaying TOTP keys as QR codes #1001
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code seems ok and works fine, but there are a lot of if
s that don't have brackets in the QRCode.cpp
/Base32.cpp
files.
We always enforce brackets (also on 1-line ifs) as codestyle.
@TheZ3ro Thanks for the review. I've corrected the single statment if s, they now use braces. Also, I applied BTW, should I modify the Dockerfile to include |
What do you think about zeroing the buffer used by libqrencode to store the "dots"?
// ...
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
// ...
QRCodePrivate::~QRCodePrivate()
{
if (nullptr != m_qrcode) {
#ifdef __STDC_LIB_EXT1__
if (nullptr != m_qrcode->data) {
const int nBytes = m_qrcode->width * m_qrcode->width;
memset_s(m_qrcode->data, nBytes, 0, nBytes);
}
#endif
QRcode_free(m_qrcode);
}
}
// ... |
An idea: how about stripping spaces from the TOTP seed before generating the URI? Take "jzls hdx6 fvhm yzpu c6o3 rybg 4ytt uuap" for example, removing spaces saves 7*3 bytes, as each space is encoded as |
@yan12125 You mean something like this? In // ...
QUrl QTotp::generateOtpString(const QString& secret,
const QString& type,
const QString& issuer,
const QString& username,
const QString& algorithm,
const quint8& digits,
const quint8& step)
{
QUrl keyUri;
keyUri.setScheme("otpauth");
keyUri.setHost(type);
keyUri.setPath(QString("/%1:%2").arg(issuer).arg(username));
QUrlQuery parameters;
parameters.addQueryItem("secret", secret.simplified()); // <- CHANGE IS HERE
parameters.addQueryItem("issuer", issuer);
parameters.addQueryItem("algorithm", algorithm);
parameters.addQueryItem("digits", QString::number(digits));
parameters.addQueryItem("period", QString::number(step));
keyUri.setQuery(parameters);
return keyUri;
}
// ...
Reference: http://doc.qt.io/qt-5/qstring.html#simplified Edit: I just noticed |
QString::replace(" ", "") |
Thanks @droidmonkey, that's what I think.
Or better, just calling Base32::sanitizeInput.
Regards,
Yen Chi Hsuan
…On Tue, Oct 3, 2017 at 2:17 AM, Jonathan White ***@***.***> wrote:
QString::replace(" ", "")
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Closing this PR in favor of the new implementation in PR #1167. |
Description
This PR is for adding the feature requested in #764. It replaces PR #964, as something strange happened with my tree of that branch and I decided to start a new one based on upstream/develop and cherry-pick the commit from the previous branch.
Changes
Instead of using
qtqrencode
, a new class,QRCode
is placed insrc/core
for enabling support for QR code generation usinglibqrencode
. Besides not having another dependency, we have the benefit of not linking againstQt::QtSvg
--whichqtqrencode
requires.QR code size is selected automatically by
libqrencode
based on input data.QR code error correction level is set to its highest.
Our local base32 implementation is compliant with RFC 4648. Three new methods were added for compatibility with Google Authenticator's "Key Uri Format" (which requires no padding characters):
Motivation and context
This is best explained by #764.
How has this been tested?
Currently, it is build for testing using Fedora 26 and the following nix environment:
You need to enable the option
WITH_CX_TOTPDISPLAYKEY
:mkdir build cd build cmake -DWITH_ASAN=ON -DWITH_XC_TOTPDISPLAYKEY=ON -DCMAKE_BUILD_TYPE=Debug ..
Test barcodes
Generate test data using: https://freeotp.github.io/qrcode.html and load it into a test DB.
Test:
Tested using:
Also, scan the QR code from the FreeOTP generator site using one of the authenticator apps and compare the TOTPs with those from KeePassXC.
Screenshots (if appropriate):
Below are two images that illustrate the proposed interface for this feature.
Note: you can actually read the barcode above! (Tested with the Ya.Key iOS app).
Types of changes
Checklist:
-DWITH_ASAN=ON
. [REQUIRED]