Skip to content

Commit da4704f

Browse files
committed
Do not include any padding in the otpauth URI
The IETF draft-linuxgemini-otpauth-uri-02 recommends to not include the padding in Section 3.3.1. cf. https://www.ietf.org/archive/id/draft-linuxgemini-otpauth-uri-02.html#section-3.3.1 (fixes issue #12540) Signed-off-by: Sven Strickroth <[email protected]>
1 parent 44daca9 commit da4704f

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/core/Totp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QUrlQuery>
2727
#include <QVariant>
2828
#include <QtEndian>
29+
#include <QRegularExpression>
2930

3031
#include <cmath>
3132

@@ -180,7 +181,7 @@ QString Totp::writeSettings(const QSharedPointer<Totp::Settings>& settings,
180181
auto urlstring = QString("otpauth://totp/%1:%2?secret=%3&period=%4&digits=%5&issuer=%1")
181182
.arg(title.isEmpty() ? "KeePassXC" : QString(QUrl::toPercentEncoding(title)),
182183
username.isEmpty() ? "none" : QString(QUrl::toPercentEncoding(username)),
183-
QString(QUrl::toPercentEncoding(Base32::sanitizeInput(settings->key.toLatin1()))),
184+
QString(Base32::sanitizeInput(settings->key.toLatin1())).remove(QRegularExpression("=+$")),
184185
QString::number(settings->step),
185186
QString::number(settings->digits));
186187

tests/TestTotp.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ void TestTotp::testParseSecret()
107107
QVERIFY(settings.isNull());
108108
}
109109

110+
void TestTotp::testTotpWriteSettings()
111+
{
112+
auto settings1 = Totp::createSettings("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", Totp::DEFAULT_DIGITS, Totp::DEFAULT_STEP);
113+
QCOMPARE(Totp::writeSettings(settings1, "ACME Co", "john", true), "otpauth://totp/ACME%20Co:john?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&period=30&digits=6&issuer=ACME%20Co");
114+
115+
auto settings2 = Totp::createSettings("63BEDWCQZKTQWPESARIERL5DTTQFCJTK", 3, 25);
116+
QCOMPARE(Totp::writeSettings(settings2, "ACME Co", "", true), "otpauth://totp/ACME%20Co:none?secret=63BEDWCQZKTQWPESARIERL5DTTQFCJTK&period=25&digits=3&issuer=ACME%20Co");
117+
118+
auto settings3 = Totp::createSettings("HXDMVJECJJWSRBY", Totp::DEFAULT_DIGITS, Totp::DEFAULT_STEP);
119+
QCOMPARE(Totp::writeSettings(settings3, "", "john", true), "otpauth://totp/KeePassXC:john?secret=HXDMVJECJJWSRBY&period=30&digits=6&issuer=KeePassXC");
120+
}
121+
110122
void TestTotp::testTotpCode()
111123
{
112124
// Test vectors from RFC 6238

tests/TestTotp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TestTotp : public QObject
2828
private slots:
2929
void initTestCase();
3030
void testParseSecret();
31+
void testTotpWriteSettings();
3132
void testTotpCode();
3233
void testSteamTotp();
3334
void testEntryHistory();

0 commit comments

Comments
 (0)