Request 2357 (superseded)
No description set
- Created by slava over 1 year ago
- In state superseded
- Superseded by 2359
Submit package home:slava / harbour-yubikey (revision 7) to package sailfishos:chum / harbour-yubikey
[-] [+] | Changed | _service:tar_git:harbour-yubikey.changes |
[-] [+] | Changed | _service:tar_git:harbour-yubikey.spec ^ |
[-] [+] | Changed | _service ^ |
@@ -2,6 +2,6 @@ <service name="tar_git"> <param name="url">https://github.com/monich/harbour-yubikey.git</param> <param name="branch">master</param> - <param name="revision">42e3746</param> + <param name="revision">a15e664</param> </service> </services> \ No newline at end of file | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/LICENSE ^ |
@@ -1,31 +1,33 @@ -Copyright (C) 2022-2023 Slava Monich <slava@monich.com> Copyright (C) 2022 Jolla Ltd. +Copyright (C) 2022 Slava Monich <slava@monich.com> -You may use this file under the terms of the BSD license as follows: +You may use this file under the terms of BSD license as follows: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - 3. Neither the names of the copyright holders nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the names of the copyright holders nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING -IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/app.pro ^ |
@@ -67,14 +67,11 @@ src/YubiKeyAuth.h \ src/YubiKeyAuthListModel.h \ src/YubiKeyCard.h \ - src/YubiKeyCardSettings.h \ src/YubiKeyDefs.h \ src/YubiKeyConstants.h \ - src/YubiKeyImportModel.h \ src/YubiKeyRecognizer.h \ src/YubiKeySettings.h \ src/YubiKeyTag.h \ - src/YubiKeyToken.h \ src/YubiKeyTypes.h \ src/YubiKeyUtil.h @@ -86,11 +83,8 @@ src/YubiKeyAuth.cpp \ src/YubiKeyAuthListModel.cpp \ src/YubiKeyCard.cpp \ - src/YubiKeyCardSettings.cpp \ - src/YubiKeyImportModel.cpp \ src/YubiKeyRecognizer.cpp \ src/YubiKeyTag.cpp \ - src/YubiKeyToken.cpp \ src/YubiKeySettings.cpp \ src/YubiKeyUtil.cpp @@ -140,7 +134,8 @@ SOURCES += \ $${LIBGLIBUTIL_SRC}/gutil_log.c \ $${LIBGLIBUTIL_SRC}/gutil_misc.c \ - $${LIBGLIBUTIL_SRC}/gutil_strv.c + $${LIBGLIBUTIL_SRC}/gutil_strv.c \ + $${LIBGLIBUTIL_SRC}/gutil_timenotify.c # libgnfcdc @@ -163,8 +158,7 @@ $${LIBGNFCDC_SRC}/nfcdc_error.c \ $${LIBGNFCDC_SRC}/nfcdc_isodep.c \ $${LIBGNFCDC_SRC}/nfcdc_log.c \ - $${LIBGNFCDC_SRC}/nfcdc_tag.c \ - $${LIBGNFCDC_SRC}/nfcdc_util.c + $${LIBGNFCDC_SRC}/nfcdc_tag.c OTHER_FILES += \ $${LIBGNFCDC_SPEC}/*.xml @@ -220,12 +214,14 @@ HEADERS += \ $${LIBQNFCDC_INCLUDE}/NfcAdapter.h \ $${LIBQNFCDC_INCLUDE}/NfcMode.h \ - $${LIBQNFCDC_INCLUDE}/NfcSystem.h + $${LIBQNFCDC_INCLUDE}/NfcSystem.h \ + $${LIBQNFCDC_INCLUDE}/NfcTag.h SOURCES += \ $${LIBQNFCDC_SRC}/NfcAdapter.cpp \ $${LIBQNFCDC_SRC}/NfcMode.cpp \ - $${LIBQNFCDC_SRC}/NfcSystem.cpp + $${LIBQNFCDC_SRC}/NfcSystem.cpp \ + $${LIBQNFCDC_SRC}/NfcTag.cpp # harbour-lib @@ -239,15 +235,13 @@ HEADERS += \ $${HARBOUR_LIB_INCLUDE}/HarbourBase32.h \ $${HARBOUR_LIB_INCLUDE}/HarbourDebug.h \ - $${HARBOUR_LIB_INCLUDE}/HarbourProtoBuf.h \ $${HARBOUR_LIB_INCLUDE}/HarbourSingleImageProvider.h \ - $${HARBOUR_LIB_INCLUDE}/HarbourUtil.h + $${HARBOUR_LIB_INCLUDE}/HarbourSystemInfo.h SOURCES += \ $${HARBOUR_LIB_SRC}/HarbourBase32.cpp \ - $${HARBOUR_LIB_SRC}/HarbourProtoBuf.cpp \ $${HARBOUR_LIB_SRC}/HarbourSingleImageProvider.cpp \ - $${HARBOUR_LIB_SRC}/HarbourUtil.cpp + $${HARBOUR_LIB_SRC}/HarbourSystemInfo.cpp HARBOUR_QML_COMPONENTS = \ $${HARBOUR_LIB_QML}/HarbourFitLabel.qml \ | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/LICENSE ^ |
@@ -1,5 +1,5 @@ Copyright (C) 2015-2021 Jolla Ltd. -Copyright (C) 2015-2023 Slava Monich <slava@monich.com> +Copyright (C) 2015-2021 Slava Monich <slava@monich.com> You may use this file under the terms of BSD license as follows: | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/harbour-lib.pro ^ |
@@ -25,7 +25,6 @@ SOURCES += \ src/HarbourBase32.cpp \ src/HarbourBase45.cpp \ - src/HarbourBattery.cpp \ src/HarbourClipboard.cpp \ src/HarbourColorEditorModel.cpp \ src/HarbourDisplayBlanking.cpp \ @@ -37,7 +36,6 @@ src/HarbourOrganizeListModel.cpp \ src/HarbourPolicyPlugin.cpp \ src/HarbourProcessState.cpp \ - src/HarbourProtoBuf.cpp \ src/HarbourSelectionListModel.cpp \ src/HarbourSigChildHandler.cpp \ src/HarbourSingleImageProvider.cpp \ @@ -48,8 +46,7 @@ src/HarbourTask.cpp \ src/HarbourTemporaryFile.cpp \ src/HarbourTransferMethodInfo.cpp \ - src/HarbourTransferMethodsModel.cpp \ - src/HarbourUtil.cpp + src/HarbourTransferMethodsModel.cpp greaterThan(QT_MAJOR_VERSION, 4) { SOURCES += \ @@ -62,7 +59,6 @@ PUBLIC_HEADERS += \ include/HarbourBase32.h \ include/HarbourBase45.h \ - include/HarbourBattery.h \ include/HarbourClipboard.h \ include/HarbourColorEditorModel.h \ include/HarbourDebug.h \ @@ -74,7 +70,6 @@ include/HarbourOrganizeListModel.h \ include/HarbourPolicyPlugin.h \ include/HarbourProcessState.h \ - include/HarbourProtoBuf.h \ include/HarbourSelectionListModel.h \ include/HarbourSigChildHandler.h \ include/HarbourSingleImageProvider.h \ @@ -85,8 +80,7 @@ include/HarbourTask.h \ include/HarbourTemporaryFile.h \ include/HarbourTransferMethodInfo.h \ - include/HarbourTransferMethodsModel.h \ - include/HarbourUtil.h + include/HarbourTransferMethodsModel.h greaterThan(QT_MAJOR_VERSION, 4) { PUBLIC_HEADERS += \ | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/include/HarbourBase32.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2019-2022 Jolla Ltd. - * Copyright (C) 2019-2022 Slava Monich <slava.monich@jolla.com> + * Copyright (C) 2019-2021 Jolla Ltd. + * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -37,15 +37,13 @@ #include <QString> #include <QByteArray> -class HarbourBase32 -{ +class HarbourBase32 { class Private; - HarbourBase32() Q_DECL_EQ_DELETE; - + HarbourBase32(); public: - static bool isValidBase32(const QString); - static QString toBase32(const QByteArray, bool aLowerCase = true); - static QByteArray fromBase32(const QString); + static QByteArray fromBase32(QString aBase32); + static QString toBase32(QByteArray aBinary, bool aLowerCase = true); + static bool isValidBase32(QString aBase32); }; #endif // HARBOUR_BASE32_H | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/include/HarbourBase45.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2021-2022 Jolla Ltd. - * Copyright (C) 2021-2022 Slava Monich <slava.monich@jolla.com> + * Copyright (C) 2021 Jolla Ltd. + * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -37,15 +37,13 @@ #include <QString> #include <QByteArray> -class HarbourBase45 -{ +class HarbourBase45 { class Private; - HarbourBase45() Q_DECL_EQ_DELETE; - + HarbourBase45(); public: - static bool isValidBase45(const QString); - static QString toBase45(const QByteArray); - static QByteArray fromBase45(const QString); + static bool isValidBase45(QString aBase45); + static QByteArray fromBase45(QString aBase45); + static QString toBase45(QByteArray aBinary); }; #endif // HARBOUR_BASE45_H | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/include/HarbourSelectionListModel.h ^ |
@@ -1,6 +1,6 @@ /* * Copyright (C) 2019 Jolla Ltd. - * Copyright (C) 2019-2023 Slava Monich <slava@jolla.com> + * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -37,44 +37,33 @@ #include <QtQml> #include <QIdentityProxyModel> -class HarbourSelectionListModel : public QIdentityProxyModel -{ +class HarbourSelectionListModel : public QIdentityProxyModel { Q_OBJECT Q_PROPERTY(QObject* sourceModel READ sourceModel WRITE setSourceModelObject NOTIFY sourceModelObjectChanged) - Q_PROPERTY(QList<int> nonSelectableRows READ nonSelectableRows WRITE setNonSelectableRows NOTIFY nonSelectableRowsChanged) Q_PROPERTY(QList<int> selectedRows READ selectedRows NOTIFY selectedRowsChanged) - Q_PROPERTY(int selectableCount READ selectableCount NOTIFY selectableCountChanged) - Q_PROPERTY(int selectionCount READ selectionCount NOTIFY selectionCountChanged) + Q_PROPERTY(int selectionCount READ selectionCount NOTIFY selectedRowsChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) public: HarbourSelectionListModel(QObject* aParent = Q_NULLPTR); - void setSourceModelObject(QObject*); - - QList<int> nonSelectableRows() const; - void setNonSelectableRows(const QList<int>); + void setSourceModelObject(QObject* aModel); QList<int> selectedRows() const; - int selectableCount() const; int selectionCount() const; Q_INVOKABLE void selectAll(); Q_INVOKABLE void clearSelection(); - Q_INVOKABLE void toggleRows(const QList<int>); // QAbstractItemModel - Qt::ItemFlags flags(const QModelIndex&) const Q_DECL_OVERRIDE; + Qt::ItemFlags flags(const QModelIndex& aIndex) const Q_DECL_OVERRIDE; QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE; - QVariant data(const QModelIndex&, int) const Q_DECL_OVERRIDE; - bool setData(const QModelIndex&, const QVariant&, int) Q_DECL_OVERRIDE; + QVariant data(const QModelIndex& aIndex, int aRole) const Q_DECL_OVERRIDE; + bool setData(const QModelIndex& aIndex, const QVariant& aValue, int aRole) Q_DECL_OVERRIDE; Q_SIGNALS: void sourceModelObjectChanged(); - void nonSelectableRowsChanged(); void selectedRowsChanged(); - void selectableCountChanged(); - void selectionCountChanged(); void countChanged(); private: | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/include/HarbourTheme.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2018-2022 Jolla Ltd. - * Copyright (C) 2018-2022 Slava Monich <slava@monich.com> + * Copyright (C) 2018-2021 Jolla Ltd. + * Copyright (C) 2018-2021 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -81,6 +81,8 @@ qreal opacityHigh() const; qreal opacityOverlay() const; + static QRgb invertedRgb(QRgb aRgb); + Q_INVOKABLE static QColor invertedColor(const QColor& aColor); Q_INVOKABLE static qreal colorDifference(const QColor& aColor1, const QColor& aColor2); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/src/HarbourBase32.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2019-2022 Jolla Ltd. - * Copyright (C) 2019-2022 Slava Monich <slava.monich@jolla.com> + * Copyright (C) 2019 Jolla Ltd. + * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -46,33 +46,25 @@ // HarbourBase32::Private // ========================================================================== -class HarbourBase32::Private -{ +class HarbourBase32::Private { public: - static char nibbleToBase32(int, char); - static int base32ToNibble(char); + static char nibbleToBase32(int nibble, char a); + static int base32ToNibble(char a); }; -inline -char -HarbourBase32::Private::nibbleToBase32( - int aNibble, - char aBaseChar) +inline char HarbourBase32::Private::nibbleToBase32(int nibble, char a) { - return (aNibble < 26) ? (aBaseChar + aNibble) : ('2' + (aNibble - 26)); + return (nibble < 26) ? (a + nibble) : ('2' + (nibble - 26)); } -inline -int -HarbourBase32::Private::base32ToNibble( - char aChar) +inline int HarbourBase32::Private::base32ToNibble(char c) { - if (aChar >= 'a' && aChar <= 'z') { - return aChar - 'a'; - } else if (aChar >= 'A' && aChar <= 'Z') { - return aChar - 'A'; - } else if (aChar >= '2' && aChar <= '7') { - return 26 + (aChar - '2'); + if (c >= 'a' && c <= 'z') { + return c - 'a'; + } else if (c >= 'A' && c <= 'Z') { + return c - 'A'; + } else if (c >= '2' && c <= '7') { + return 26 + (c - '2'); } else { return -1; } @@ -82,9 +74,7 @@ // HarbourBase32 // ========================================================================== -bool -HarbourBase32::isValidBase32( - QString aBase32) +bool HarbourBase32::isValidBase32(QString aBase32) { const int n = aBase32.length(); const QChar* chars = aBase32.constData(); @@ -143,9 +133,7 @@ return !empty; } -QByteArray -HarbourBase32::fromBase32( - const QString aBase32) +QByteArray HarbourBase32::fromBase32(QString aBase32) { QByteArray out; @@ -217,10 +205,7 @@ return out; } -QString -HarbourBase32::toBase32( - const QByteArray aBinary, - bool aLowerCase) +QString HarbourBase32::toBase32(QByteArray aBinary, bool aLowerCase) { QString str; const int n = aBinary.size(); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/src/HarbourBase45.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2021-2022 Jolla Ltd. - * Copyright (C) 2021-2022 Slava Monich <slava.monich@jolla.com> + * Copyright (C) 2021 Jolla Ltd. + * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -39,8 +39,7 @@ // HarbourBase45::Private // ========================================================================== -class HarbourBase45::Private -{ +class HarbourBase45::Private { public: enum { BASE = 45, @@ -49,7 +48,7 @@ }; static const char mapBase45[BASE]; static const int reverseMapBase45[REVERSE_MAP_SIZE]; - static bool isValidChar(uint); + static bool isValidChar(uint x); }; const char HarbourBase45::Private::mapBase45[HarbourBase45::Private::BASE] = { @@ -76,22 +75,16 @@ 33, 34, 35 }; -inline -bool -HarbourBase45::Private::isValidChar( - uint aChar) +inline bool HarbourBase45::Private::isValidChar(uint x) { - return (aChar < Private::REVERSE_MAP_SIZE) && - Private::reverseMapBase45[aChar] >= 0; + return (x < Private::REVERSE_MAP_SIZE) && Private::reverseMapBase45[x] >= 0; } // ========================================================================== // HarbourBase45::Private // ========================================================================== -bool -HarbourBase45::isValidBase45( - const QString aBase45) +bool HarbourBase45::isValidBase45(QString aBase45) { const int len = aBase45.length(); @@ -130,9 +123,7 @@ return false; } -QByteArray -HarbourBase45::fromBase45( - const QString aBase45) +QByteArray HarbourBase45::fromBase45(QString aBase45) { QByteArray out; const int len = aBase45.length(); @@ -184,9 +175,7 @@ return out; } -QString -HarbourBase45::toBase45( - const QByteArray aBinary) +QString HarbourBase45::toBase45(QByteArray aBinary) { const uchar* ptr = (uchar*)aBinary.constData(); const int n = aBinary.size(); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/src/HarbourSelectionListModel.cpp ^ |
@@ -1,6 +1,6 @@ -/* +/* * Copyright (C) 2019 Jolla Ltd. - * Copyright (C) 2019-2023 Slava Monich <slava@jolla.com> + * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -41,47 +41,20 @@ // HarbourSelectionListModel::Private // ========================================================================== -// s(SignalName,signalName) -#define QUEUED_SIGNALS(s) \ - s(NonSelectableRows,nonSelectableRows) \ - s(SelectedRows,selectedRows) \ - s(SelectableCount,selectableCount) \ - s(SelectionCount,selectionCount) \ - s(Count,count) - -class HarbourSelectionListModel::Private : public QObject -{ +class HarbourSelectionListModel::Private : public QObject { Q_OBJECT public: - typedef void (HarbourSelectionListModel::*SignalEmitter)(); - typedef uint SignalMask; - - enum Signal { -#define SIGNAL_ENUM_(Name,name) Signal##Name##Changed, - QUEUED_SIGNALS(SIGNAL_ENUM_) -#undef SIGNAL_ENUM_ - SignalCount - }; - - Private(HarbourSelectionListModel*); - - static int binaryFind(const QList<int>, int); + Private(HarbourSelectionListModel* aParent); HarbourSelectionListModel* parentModel(); - void queueSignal(Signal aSignal); - void emitQueuedSignals(); - bool isSelectionRole(int) const; - bool isSelectedRow(int) const; - bool isSelectableRow(int) const; - int findSelectedRow(int) const; - void updateCounts(); - void selectRow(int); - void unselectRow(int); - void toggleRows(const QList<int>); - void setNonSelectableRows(const QList<int>); - void selectedRowChanged(int); - void selectionChangedAt(int); + static int binaryFind(const QList<int> aList, int aValue); + bool isSelectionRole(int aRole) const; + bool isSelectedRow(int aRow) const; + int findSelectedRow(int aRow) const; + void selectRow(int aRow); + void unselectRow(int aRow); + void selectionChangedAt(int aRow); void clearSelection(); void selectAll(); void reset(); @@ -90,20 +63,13 @@ void onCountChanged(); public: - SignalMask iQueuedSignals; - Signal iFirstQueuedSignal; QList<int> iSelectedRows; - QList<int> iNonSelectableRows; - QList<int> iNormalizedNonSelectableRows; - QVector<int> iSelectedRole; // Passed to dataChanged as an argument - int iLastKnownSelectableCount; + QVector<int> iSelectedRole; int iLastKnownCount; }; -HarbourSelectionListModel::Private::Private( - HarbourSelectionListModel* aParent) : +HarbourSelectionListModel::Private::Private(HarbourSelectionListModel* aParent) : QObject(aParent), - iLastKnownSelectableCount(0), iLastKnownCount(0) { connect(aParent, SIGNAL(modelReset()), SLOT(onCountChanged())); @@ -111,10 +77,22 @@ connect(aParent, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(onCountChanged())); } -int -HarbourSelectionListModel::Private::binaryFind( - const QList<int> aList, - int aValue) +inline HarbourSelectionListModel* HarbourSelectionListModel::Private::parentModel() +{ + return qobject_cast<HarbourSelectionListModel*>(parent()); +} + +inline bool HarbourSelectionListModel::Private::isSelectionRole(int aRole) const +{ + return !iSelectedRole.isEmpty() && iSelectedRole.first() == aRole; +} + +inline bool HarbourSelectionListModel::Private::isSelectedRow(int aRow) const +{ + return findSelectedRow(aRow) >= 0; +} + +int HarbourSelectionListModel::Private::binaryFind(const QList<int> aList, int aValue) { // It turned out to be significantly easier to copy/paste this code // than to fight with qBinaryFind and iterators which behave strangely @@ -139,131 +117,34 @@ return -(low + 1); } -inline -HarbourSelectionListModel* -HarbourSelectionListModel::Private::parentModel() -{ - return qobject_cast<HarbourSelectionListModel*>(parent()); -} - -void -HarbourSelectionListModel::Private::queueSignal( - Signal aSignal) -{ - if (aSignal >= 0 && aSignal < SignalCount) { - const SignalMask signalBit = (SignalMask(1) << aSignal); - if (iQueuedSignals) { - iQueuedSignals |= signalBit; - if (iFirstQueuedSignal > aSignal) { - iFirstQueuedSignal = aSignal; - } - } else { - iQueuedSignals = signalBit; - iFirstQueuedSignal = aSignal; - } - } -} - -void -HarbourSelectionListModel::Private::emitQueuedSignals() -{ - static const SignalEmitter emitSignal [] = { -#define SIGNAL_EMITTER_(Name,name) &HarbourSelectionListModel::name##Changed, - QUEUED_SIGNALS(SIGNAL_EMITTER_) -#undef SIGNAL_EMITTER_ - }; - if (iQueuedSignals) { - HarbourSelectionListModel* model = parentModel(); - // Reset first queued signal before emitting the signals. - // Signal handlers may emit new signals. - uint i = iFirstQueuedSignal; - iFirstQueuedSignal = SignalCount; - for (; i < SignalCount && iQueuedSignals; i++) { - const SignalMask signalBit = (SignalMask(1) << i); - if (iQueuedSignals & signalBit) { - iQueuedSignals &= ~signalBit; - Q_EMIT (model->*(emitSignal[i]))(); - } - } - } -} - -inline -bool -HarbourSelectionListModel::Private::isSelectionRole( - int aRole) const -{ - return !iSelectedRole.isEmpty() && iSelectedRole.first() == aRole; -} - -inline -bool -HarbourSelectionListModel::Private::isSelectedRow( - int aRow) const -{ - return findSelectedRow(aRow) >= 0; -} - -inline -bool -HarbourSelectionListModel::Private::isSelectableRow( - int aRow) const -{ - return binaryFind(iNonSelectableRows, aRow) < 0; -} - -int -HarbourSelectionListModel::Private::findSelectedRow( - int aRow) const +int HarbourSelectionListModel::Private::findSelectedRow(int aRow) const { return binaryFind(iSelectedRows, aRow); } -void -HarbourSelectionListModel::Private::updateCounts() +void HarbourSelectionListModel::Private::onCountChanged() { - const int count = parentModel()->rowCount(); - - int selectableCount = count; - const int n = iNormalizedNonSelectableRows.count(); - for (int i = 0; i < n; i++) { - const int row = iNormalizedNonSelectableRows.at(i); - - if (row < count) { - selectableCount--; - } else { - break; - } - } - - if (iLastKnownSelectableCount != selectableCount) { - iLastKnownSelectableCount = selectableCount; - queueSignal(SignalSelectableCountChanged); - } - + HarbourSelectionListModel* model = parentModel(); + const int count = model->rowCount(); if (iLastKnownCount != count) { iLastKnownCount = count; - queueSignal(SignalCountChanged); + bool changed = false; while (!iSelectedRows.isEmpty() && iSelectedRows.last() >= count) { iSelectedRows.removeAt(iSelectedRows.count() - 1); - queueSignal(SignalSelectionCountChanged); - queueSignal(SignalSelectedRowsChanged); + changed = true; + } + if (changed) { + Q_EMIT model->selectedRowsChanged(); } + Q_EMIT model->countChanged(); } } -void -HarbourSelectionListModel::Private::onCountChanged() -{ - updateCounts(); - emitQueuedSignals(); -} - -void -HarbourSelectionListModel::Private::clearSelection() +void HarbourSelectionListModel::Private::clearSelection() { if (!iSelectedRows.isEmpty()) { HDEBUG("clearing selection"); + HarbourSelectionListModel* model = parentModel(); if (!iSelectedRole.isEmpty()) { const QList<int> rows(iSelectedRows); iSelectedRows.clear(); @@ -274,57 +155,36 @@ } else { iSelectedRows.clear(); } - - queueSignal(SignalSelectionCountChanged); - queueSignal(SignalSelectedRowsChanged); - emitQueuedSignals(); + Q_EMIT model->selectedRowsChanged(); } } -void -HarbourSelectionListModel::Private::selectAll() +void HarbourSelectionListModel::Private::selectAll() { - const int count = parentModel()->rowCount(); - QList<int> rows; - int i; - - rows.reserve(count); - for (i = 0; i < count; i++) { - if (binaryFind(iNormalizedNonSelectableRows, i) < 0) { - rows.append(i); - } - } - - if (iSelectedRows.count() != rows.count()) { - queueSignal(SignalSelectionCountChanged); - } - - const QList<int> prevSelection(iSelectedRows); - if (iSelectedRows != rows) { - iSelectedRows = rows; - queueSignal(SignalSelectedRowsChanged); - } - - for (i = 0; i < iSelectedRows.count(); i++) { - const int row = iSelectedRows.at(i); - - if (binaryFind(prevSelection, row) < 0) { - selectionChangedAt(row); + HarbourSelectionListModel* model = parentModel(); + const int count = model->rowCount(); + if (iSelectedRows.count() < count) { + const QList<int> prevSelection(iSelectedRows); + iSelectedRows.reserve(count); + int i; + for (i = 0; i < iSelectedRows.count(); i++) iSelectedRows[i] = i; + while (i < count) iSelectedRows.append(i++); + for (i = 0; i < count; i++) { + if (binaryFind(prevSelection, i) < 0) { + selectionChangedAt(i); + } } + Q_EMIT model->selectedRowsChanged(); } - emitQueuedSignals(); } -void -HarbourSelectionListModel::Private::reset() +void HarbourSelectionListModel::Private::reset() { iSelectedRole.clear(); clearSelection(); } -void -HarbourSelectionListModel::Private::selectionChangedAt( - int aRow) +void HarbourSelectionListModel::Private::selectionChangedAt(int aRow) { if (!iSelectedRole.isEmpty()) { HarbourSelectionListModel* model = parentModel(); @@ -333,116 +193,31 @@ } } -void -HarbourSelectionListModel::Private::selectedRowChanged( - int aRow) +void HarbourSelectionListModel::Private::selectRow(int aRow) { - queueSignal(SignalSelectionCountChanged); - queueSignal(SignalSelectedRowsChanged); - selectionChangedAt(aRow); - emitQueuedSignals(); -} - -void -HarbourSelectionListModel::Private::selectRow( - int aRow) -{ - if (aRow >= 0 && aRow < parentModel()->rowCount()) { + HarbourSelectionListModel* model = parentModel(); + if (aRow >= 0 && aRow < model->rowCount()) { const int pos = findSelectedRow(aRow); if (pos < 0) { - if (isSelectableRow(aRow)) { - HDEBUG(aRow << "selected at" << (-pos - 1)); - iSelectedRows.insert(-pos - 1, aRow); - selectedRowChanged(aRow); - } else { - HDEBUG("Row" << aRow << "is not selectable"); - } + HDEBUG(aRow << "selected at" << (-pos - 1)); + iSelectedRows.insert(-pos - 1, aRow); + selectionChangedAt(aRow); + Q_EMIT model->selectedRowsChanged(); } } } -void -HarbourSelectionListModel::Private::unselectRow( - int aRow) +void HarbourSelectionListModel::Private::unselectRow(int aRow) { - if (aRow >= 0 && aRow < parentModel()->rowCount()) { - const int pos = findSelectedRow(aRow); - if (pos >= 0) { - HDEBUG(aRow << "unselected at" << pos); - iSelectedRows.removeAt(pos); - selectedRowChanged(aRow); - } - } -} - -void -HarbourSelectionListModel::Private::toggleRows( - const QList<int> aRows) -{ - int i; - const int n = aRows.count(); - - // Sort and remove duplicates - QList<int> rows; - rows.reserve(n); - for (i = 0; i < n; i++) { - const int row = aRows.at(i); - const int pos = binaryFind(rows, row); - if (pos < 0) rows.insert(-pos - 1, row); - } - HarbourSelectionListModel* model = parentModel(); - const int k = rows.count(); - const int prevSelectedCount = iSelectedRows.count(); - - for (i = 0; i < k; i++) { - const int row = rows.at(i); - if (row >= 0 && row < model->rowCount()) { - const int pos = findSelectedRow(row); - if (pos >= 0) { - HDEBUG(row << "unselected at" << pos); - iSelectedRows.removeAt(pos); - selectionChangedAt(row); - } else if (isSelectableRow(row)) { - HDEBUG(row << "selected at" << (-pos - 1)); - iSelectedRows.insert(-pos - 1, row); - selectionChangedAt(row); - } - queueSignal(SignalSelectedRowsChanged); - } - } - - if (prevSelectedCount != iSelectedRows.count()) { - queueSignal(SignalSelectionCountChanged); - } - - emitQueuedSignals(); -} - -void -HarbourSelectionListModel::Private::setNonSelectableRows( - const QList<int> aRows) -{ - if (iNonSelectableRows != aRows) { - iNonSelectableRows = aRows; - queueSignal(SignalNonSelectableRowsChanged); - - // Sort and remove regatives and duplicates - iNormalizedNonSelectableRows.clear(); - iNormalizedNonSelectableRows.reserve(aRows.count()); - - const int n = aRows.count(); - for (int i = 0; i < n; i++) { - const int row = aRows.at(i); - if (row >= 0) { - const int pos = binaryFind(iNormalizedNonSelectableRows, row); - if (pos < 0) iNormalizedNonSelectableRows.insert(-pos - 1, row); - } + if (aRow >= 0 && aRow < model->rowCount()) { + const int pos = findSelectedRow(aRow); + if (pos >= 0) { + HDEBUG(aRow << "unselected at" << pos); + iSelectedRows.removeAt(pos); + selectionChangedAt(aRow); + Q_EMIT model->selectedRowsChanged(); } - - HDEBUG(iNormalizedNonSelectableRows); - updateCounts(); - emitQueuedSignals(); } } @@ -452,17 +227,14 @@ #define SUPER QIdentityProxyModel -HarbourSelectionListModel::HarbourSelectionListModel( - QObject* aParent) : +HarbourSelectionListModel::HarbourSelectionListModel(QObject* aParent) : SUPER(aParent), iPrivate(new Private(this)) { connect(this, SIGNAL(sourceModelChanged()), SIGNAL(sourceModelObjectChanged())); } -void -HarbourSelectionListModel::setSourceModelObject( - QObject* aModel) +void HarbourSelectionListModel::setSourceModelObject(QObject* aModel) { if (sourceModel() != aModel) { HDEBUG(aModel); @@ -471,65 +243,32 @@ } } -QList<int> -HarbourSelectionListModel::nonSelectableRows() const -{ - return iPrivate->iNonSelectableRows; -} - -void -HarbourSelectionListModel::setNonSelectableRows( - const QList<int> aRows) -{ - iPrivate->setNonSelectableRows(aRows); -} - -QList<int> -HarbourSelectionListModel::selectedRows() const +QList<int> HarbourSelectionListModel::selectedRows() const { return iPrivate->iSelectedRows; } -int -HarbourSelectionListModel::selectionCount() const +int HarbourSelectionListModel::selectionCount() const { return iPrivate->iSelectedRows.count(); } -int -HarbourSelectionListModel::selectableCount() const -{ - return iPrivate->iLastKnownSelectableCount; -} - -void -HarbourSelectionListModel::selectAll() +void HarbourSelectionListModel::selectAll() { iPrivate->selectAll(); } -void -HarbourSelectionListModel::clearSelection() +void HarbourSelectionListModel::clearSelection() { iPrivate->clearSelection(); } -void -HarbourSelectionListModel::toggleRows( - const QList<int> aRows) -{ - iPrivate->toggleRows(aRows); -} - -Qt::ItemFlags -HarbourSelectionListModel::flags( - const QModelIndex& aIndex) const +Qt::ItemFlags HarbourSelectionListModel::flags(const QModelIndex& aIndex) const { return SUPER::flags(aIndex) | Qt::ItemIsEditable; } -QHash<int,QByteArray> -HarbourSelectionListModel::roleNames() const +QHash<int,QByteArray> HarbourSelectionListModel::roleNames() const { QHash<int,QByteArray> roles = SUPER::roleNames(); int selectedRole; @@ -547,10 +286,7 @@ return roles; } -QVariant -HarbourSelectionListModel::data( - const QModelIndex& aIndex, - int aRole) const +QVariant HarbourSelectionListModel::data(const QModelIndex& aIndex, int aRole) const { if (iPrivate->isSelectionRole(aRole)) { return iPrivate->isSelectedRow(aIndex.row()); @@ -559,11 +295,7 @@ } } -bool -HarbourSelectionListModel::setData( - const QModelIndex& aIndex, - const QVariant& aValue, - int aRole) +bool HarbourSelectionListModel::setData(const QModelIndex& aIndex, const QVariant& aValue, int aRole) { if (iPrivate->isSelectionRole(aRole)) { if (aValue.toBool()) { | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/src/HarbourTheme.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2018-2022 Jolla Ltd. - * Copyright (C) 2018-2022 Slava Monich <slava@monich.com> + * Copyright (C) 2018-2021 Jolla Ltd. + * Copyright (C) 2018-2021 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -31,10 +31,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "HarbourDebug.h" -#include "HarbourSystem.h" #include "HarbourTheme.h" -#include "HarbourUtil.h" +#include "HarbourSystem.h" +#include "HarbourDebug.h" #include <QQmlEngine> @@ -213,12 +212,21 @@ QColor HarbourTheme::invertedPrimaryColor() const { - return HarbourUtil::invertedColor(Private::primaryColor()); + return invertedColor(Private::primaryColor()); +} + +QRgb HarbourTheme::invertedRgb(QRgb aRgb) +{ + return ((~(aRgb & RGB_MASK)) & RGB_MASK) | (aRgb & (~RGB_MASK)); } QColor HarbourTheme::invertedColor(const QColor& aColor) { - return HarbourUtil::invertedColor(aColor); + if (aColor.isValid()) { + return QColor(invertedRgb(aColor.rgba())); + } else { + return aColor; + } } qreal HarbourTheme::colorDifference(const QColor& aColor1, const QColor& aColor2) | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/src/libcrypto.c ^ |
@@ -1,6 +1,6 @@ /* * Copyright (C) 2021 Jolla Ltd. - * Copyright (C) 2021-2023 Slava Monich <slava@monich.com> + * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com> * * You may use this file under the terms of the BSD license as follows: * @@ -112,22 +112,14 @@ (const unsigned char* in, unsigned char* out, const AES_KEY* key, \ const int enc), \ (in, out, key, enc)) \ - f(BN_clear_free, (BIGNUM *a), (a)) \ f(BN_free, (BIGNUM *a), (a)) \ f(DES_ede3_cbc_encrypt, \ (const unsigned char* input, unsigned char* output, long length, \ DES_key_schedule* ks1, DES_key_schedule* ks2, DES_key_schedule* ks3, \ DES_cblock* ivec, int enc), \ (input, output, length, ks1, ks2, ks3, ivec, enc)) \ - f(/* libcrypto.so.10 */ ERR_load_crypto_strings, (void), ()) \ - f(RSA_free, (RSA* r), (r)) \ - f(/* libcrypto.so.1.1 */ RSA_get0_key, (const RSA* r, const BIGNUM** n, \ - const BIGNUM** e, const BIGNUM** d), (r, n, e, d)) \ - f(/* libcrypto.so.1.1 */ RSA_get0_factors, (const RSA* r, \ - const BIGNUM** p, const BIGNUM** q), (r, p, q)) \ - f(/* libcrypto.so.1.1 */ RSA_get0_crt_params, (const RSA* r, \ - const BIGNUM** dmp1, const BIGNUM** dmq1, const BIGNUM** iqmp), \ - (r, dmp1, dmq1, iqmp)) + f(ERR_load_crypto_strings, (void), ()) \ + f(RSA_free, (RSA* r), (r)) /* f(ret,name,params,args,def) */ #define LIBCRYPTO_FUNCTIONS2(f) \ @@ -157,7 +149,7 @@ f(int, MD5_Init, (MD5_CTX* c), (c), 0) \ f(int, MD5_Update, (MD5_CTX* c, const void* data, size_t len), \ (c, data, len), 0) \ - f(int, /* libcrypto.so.1.1 */ OPENSSL_init_crypto, \ + f(int, OPENSSL_init_crypto, \ (uint64_t opts, const OPENSSL_INIT_SETTINGS* settings), \ (opts, settings), 0) \ f(int, RAND_bytes, (unsigned char* buf, int num), (buf, num), 0) \ @@ -181,12 +173,6 @@ (int flen, const unsigned char* from, unsigned char* to, RSA* rsa, \ int padding), (flen, from, to, rsa, padding), 0) \ f(int, RSA_size, (const RSA* rsa), (rsa), 0) \ - f(int, /* libcrypto.so.1.1 */ RSA_set0_key, (RSA* r, BIGNUM* n, \ - BIGNUM* e, BIGNUM* d), (r, n, e, d), 0) \ - f(int, /* libcrypto.so.1.1 */ RSA_set0_factors, (RSA* r, BIGNUM* p, \ - BIGNUM* q), (r, p, q), 0) \ - f(int, /* libcrypto.so.1.1 */ RSA_set0_crt_params, (RSA* r, \ - BIGNUM* dmp1, BIGNUM* dmq1, BIGNUM* iqmp), (r, dmp1, dmq1, iqmp), 0) \ f(unsigned char*, SHA1, (const unsigned char* d, size_t n, \ unsigned char* md), (d, n, md), NULL) \ f(int, SHA1_Final, (unsigned char* md, SHA_CTX* c), (md, c), 0) \ | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/test/Makefile ^ |
@@ -4,5 +4,3 @@ %: @$(MAKE) -C TestHarbourBase32 $* @$(MAKE) -C TestHarbourBase45 $* - @$(MAKE) -C TestHarbourProtoBuf $* - @$(MAKE) -C TestHarbourUtil $* | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/test/Makefile.common ^ |
@@ -31,8 +31,6 @@ SRC_DIR = . TOP_DIR = ../.. HARBOUR_DIR = $(TOP_DIR) -HARBOUR_INCLUDE_DIR = $(HARBOUR_DIR)/include -HARBOUR_SRC_DIR = $(HARBOUR_DIR)/src BUILD_DIR = build DEBUG_BUILD_DIR = $(BUILD_DIR)/debug RELEASE_BUILD_DIR = $(BUILD_DIR)/release @@ -46,7 +44,7 @@ LD = $(CC) MOC = qtchooser -run-tool=moc -qt=5 WARNINGS = -Wall -INCLUDES = -I$(BUILD_DIR) -I$(HARBOUR_INCLUDE_DIR) +INCLUDES = -I$(BUILD_DIR) -I$(HARBOUR_DIR)/include BASE_FLAGS = -fPIC BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) BASE_CFLAGS = $(BASE_FLAGS) $(CFLAGS) @@ -86,9 +84,6 @@ $(MOC_CPP:%.cpp=$(COVERAGE_BUILD_DIR)/moc_cpp_%.o) \ $(SRC:%.cpp=$(COVERAGE_BUILD_DIR)/%.o) \ $(HARBOUR_SRC:%.cpp=$(COVERAGE_BUILD_DIR)/harbour_%.o) -GEN_FILES = \ - $(MOC_H:%.h=$(BUILD_DIR)/moc_%.cpp) \ - $(MOC_CPP:%.cpp=$(BUILD_DIR)/%.moc) # # Dependencies @@ -101,7 +96,6 @@ endif endif -$(GEN_FILES): | $(BUILD_DIR) $(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) $(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) $(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR) @@ -145,10 +139,10 @@ $(COVERAGE_BUILD_DIR): mkdir -p $@ -$(BUILD_DIR)/moc_%.cpp : $(HARBOUR_INCLUDE_DIR)/%.h +$(BUILD_DIR)/moc_%.cpp : $(APP_DIR)/%.h $(MOC) $< -o $@ -$(BUILD_DIR)/%.moc : $(HARBOUR_SRC_DIR)/%.cpp +$(BUILD_DIR)/%.moc : $(APP_DIR)/%.cpp $(MOC) $< -o $@ $(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp @@ -169,22 +163,31 @@ $(COVERAGE_BUILD_DIR)/moc_h_%.o : $(BUILD_DIR)/moc_%.cpp $(BUILD_DIR) $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(DEBUG_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_SRC_DIR)/%.cpp $(BUILD_DIR)/%.moc +$(DEBUG_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(RELEASE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_SRC_DIR)/%.cpp $(BUILD_DIR)/%.moc +$(RELEASE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(COVERAGE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_SRC_DIR)/%.cpp $(BUILD_DIR)/%.moc +$(COVERAGE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(DEBUG_BUILD_DIR)/harbour_%.o : $(HARBOUR_SRC_DIR)/%.cpp +$(DEBUG_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(RELEASE_BUILD_DIR)/harbour_%.o : $(HARBOUR_SRC_DIR)/%.cpp +$(RELEASE_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(COVERAGE_BUILD_DIR)/harbour_%.o : $(HARBOUR_SRC_DIR)/%.cpp +$(COVERAGE_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp + $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ + +$(DEBUG_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp + $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ + +$(RELEASE_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp + $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ + +$(COVERAGE_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ $(DEBUG_EXE): $(DEBUG_OBJS) | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/harbour-lib/test/coverage/run ^ |
@@ -5,9 +5,7 @@ TESTS="\ TestHarbourBase32 \ -TestHarbourBase45 \ -TestHarbourProtoBuf \ -TestHarbourUtil" +TestHarbourBase45" function err() { echo "*** ERROR!" $1 | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/Makefile ^ |
@@ -23,7 +23,7 @@ VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 10 +VERSION_RELEASE = 9 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) @@ -55,8 +55,7 @@ nfcdc_log.c \ nfcdc_peer.c \ nfcdc_peer_service.c \ - nfcdc_tag.c \ - nfcdc_util.c + nfcdc_tag.c GEN_SRC = \ org.sailfishos.nfc.Adapter.c \ | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/include/nfcdc_tag.h ^ |
@@ -56,17 +56,6 @@ NFC_TAG_PROPERTY_COUNT } NFC_TAG_PROPERTY; -typedef enum nfc_tag_poll_param { - /* NFC-A */ - NFC_TAG_POLL_PARAM_SELRES, /* SEL_RES Response */ - NFC_TAG_POLL_PARAM_NFCID1, /* NFCID1 */ - /* NFC-B */ - NFC_TAG_POLL_PARAM_NFCID0, /* NFCID0 (optional) */ - NFC_TAG_POLL_PARAM_APPDATA, /* SENSB_RES */ - NFC_TAG_POLL_PARAM_PROTINFO, /* SENSB_RES/PROTINFO (optional) */ - NFC_TAG_POLL_PARAM_COUNT -} NFC_TAG_POLL_PARAM; /* Since 1.0.10 */ - struct nfc_tag_client { const char* path; gboolean valid; @@ -124,11 +113,6 @@ void* user_data, GDestroyNotify destroy); -const GUtilData* -nfc_tag_client_poll_param( - NfcTagClient* tag, - NFC_TAG_POLL_PARAM param); /* Since 1.0.10 */ - gboolean nfc_tag_client_deactivate( NfcTagClient* tag, | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/rpm/libgnfcdc.spec ^ |
@@ -1,6 +1,6 @@ Name: libgnfcdc -Version: 1.0.10 +Version: 1.0.9 Release: 0 Summary: Glib based NFC Daemon Client Group: Development/Libraries | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/spec/org.sailfishos.nfc.Tag.xml ^ |
@@ -21,18 +21,6 @@ 32 - NFC-DEP Protocol (ISO 18092) The above codes are bitmasks elsewhere, but here used as enum values. - - Poll Parameters: - - NFC-A: - "SEL_RES" - "ay", SEL_RES Response - "NFCID1" - "ay", Device identifier - - NFC-B: - "NFCID0" - "ay", NFCID0 (device identifier) part of SENSB_RES - "APPDATA" - "ay", Application Data part of SENSB_RES - "PROTINFO" - "ay", Protocol Info part of SENSB_RES - --> <method name="GetAll"> <arg name="version" type="i" direction="out"/> @@ -73,39 +61,5 @@ <arg name="wait" type="b" direction="in"/> </method> <method name="Release"/> - <!-- Interface version 3 --> - <method name="GetAll3"> - <arg name="version" type="i" direction="out"/> - <arg name="present" type="b" direction="out"/> - <arg name="technology" type="u" direction="out"/> - <arg name="protocol" type="u" direction="out"/> - <arg name="type" type="u" direction="out"/> - <arg name="interfaces" type="as" direction="out"/> - <arg name="ndef_records" type="ao" direction="out"/> - <arg name="poll_parameters" type="a{sv}" direction="out"/> - </method> - <!-- - <method name="GetPollParameters"> - <arg name="poll_parameters" type="a{sv}" direction="out"/> - </method> - --> - <!-- Interface version 4 --> - <!-- - <method name="Transceive"> - <arg name="data" type="ay" direction="in"> - <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> - </arg> - <arg name="response" type="ay" direction="out"> - <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> - </arg> - </method> - --> - <!-- Interface version 5 --> - <!-- - <method name="Acquire2"> - <arg name="wait" type="b" direction="in"/> - </method> - <method name="Release2"/> - --> </interface> </node> | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/src/nfcdc_isodep.c ^ |
@@ -38,9 +38,8 @@ #include "nfcdc_isodep.h" #include "nfcdc_base.h" #include "nfcdc_dbus.h" -#include "nfcdc_log.h" #include "nfcdc_tag_p.h" -#include "nfcdc_util_p.h" +#include "nfcdc_log.h" #include <gutil_macros.h> #include <gutil_misc.h> @@ -114,8 +113,8 @@ } static -int -nfc_isodep_client_act_param_key( +NFC_ISODEP_ACT_PARAM +nfc_isodep_client_parse_act_param( const char* key) { if (key) { @@ -137,7 +136,7 @@ return NFC_ISODEP_ACT_PARAM_HLR; } } - return -1; + return NFC_ISODEP_ACT_PARAM_UNKNOWN; } static @@ -280,25 +279,79 @@ { NfcIsoDepClientObject* self = THIS(user_data); GError* error = NULL; - GVariant* dict = NULL; + GVariant* act_params = NULL; int version = 0; GASSERT(self->proxy_initializing); self->proxy_initializing = FALSE; if (!org_sailfishos_nfc_iso_dep_call_get_all2_finish(self->proxy, - &version, &dict, result, &error)) { + &version, &act_params, result, &error)) { GERR("%s", GERRMSG(error)); g_error_free(error); /* Need to retry? */ nfc_isodep_client_drop_proxy(self); } else { - GDEBUG("%s: ISO-DEP activation parameters", self->name); - self->act_params = nfc_parse_dict(self->act_params, dict, - nfc_isodep_client_act_param_key); + GVariantIter it; + GVariant* entry; + + if (!self->act_params) { + self->act_params = g_hash_table_new_full(g_direct_hash, + g_direct_equal, NULL, g_free); + } + + /* Parse the activation parameters */ + for (g_variant_iter_init(&it, act_params); + (entry = g_variant_iter_next_value(&it)) != NULL; + g_variant_unref(entry)) { + GVariant* key = g_variant_get_child_value(entry, 0); + GVariant* value = g_variant_get_child_value(entry, 1); + const char* ap_name = g_variant_get_string(key, NULL); + const NFC_ISODEP_ACT_PARAM ap = + nfc_isodep_client_parse_act_param(ap_name); + + if (ap != NFC_ISODEP_ACT_PARAM_UNKNOWN) { + GUtilData* value_data = NULL; + + if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT)) { + GVariant* tmp = g_variant_get_variant(value); + g_variant_unref(value); + value = tmp; + } + + /* Allocate value as a single memory block */ + if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) { + const gsize variant_size = g_variant_get_size(value); + void* data; + + value_data = g_malloc(sizeof(GUtilData) + variant_size); + data = value_data + 1; + value_data->size = variant_size; + value_data->bytes = data; + memcpy(data, g_variant_get_data(value), variant_size); + } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTE)) { + guint8* data; + + value_data = g_malloc(sizeof(GUtilData) + 1); + data = (guint8*)(value_data + 1); + value_data->size = 1; + value_data->bytes = data; + *data = g_variant_get_byte(value); + } + + if (value_data) { + DUMP_DATA(self->name, ap_name, "=", value_data); + g_hash_table_insert(self->act_params, GINT_TO_POINTER(ap), + value_data); + } + } + + g_variant_unref(key); + g_variant_unref(value); + } + self->version = version; nfc_isodep_client_update_valid_and_present(self); nfc_isodep_client_emit_queued_signals(self); - g_variant_unref(dict); } g_object_unref(self); } @@ -330,8 +383,8 @@ self->version = version; self->proxy_initializing = FALSE; nfc_isodep_client_update_valid_and_present(self); + nfc_isodep_client_emit_queued_signals(self); } - nfc_isodep_client_emit_queued_signals(self); g_object_unref(self); } | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/src/nfcdc_log.c ^ |
@@ -42,14 +42,6 @@ #if GUTIL_LOG_DEBUG -static inline -gboolean -nfcdc_blank_str( - const char* prefix) -{ - return !prefix[strspn(prefix," \t")]; -} - void nfcdc_dump_strv( const char* prefix, @@ -70,8 +62,7 @@ } if (prefix) { if (sep) { - GDEBUG("%s%s%s %s {%s}", prefix, nfcdc_blank_str(prefix) ? - "" : ": ", name, sep, buf->str); + GDEBUG("%s: %s %s {%s}", prefix, name, sep, buf->str); } else { GDEBUG("%s: %s {%s}", prefix, name, buf->str); } @@ -83,8 +74,7 @@ g_string_free(buf, TRUE); } else { if (prefix) { - GDEBUG("%s%s%s %s", prefix, nfcdc_blank_str(prefix) ? - "" : ": ", name, sep); + GDEBUG("%s: %s %s", prefix, name, sep); } else if (sep) { GDEBUG("%s %s", name, sep); } else { @@ -111,15 +101,13 @@ g_string_append_printf(buf, ":%02X", data->bytes[i]); } if (prefix) { - GDEBUG("%s%s%s %s %s", prefix, nfcdc_blank_str(prefix) ? - "" : ": ", name, sep, buf->str); + GDEBUG("%s: %s %s %s", prefix, name, sep, buf->str); } else { GDEBUG("%s %s %s", name, sep, buf->str); } g_string_free(buf, TRUE); } else if (prefix) { - GDEBUG("%s%s%s %s", prefix, nfcdc_blank_str(prefix) ? - "" : ": ", name, sep); + GDEBUG("%s: %s %s", prefix, name, sep); } else if (sep) { GDEBUG("%s %s", name, sep); } else { | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/libgnfcdc/src/nfcdc_tag.c ^ |
@@ -38,9 +38,8 @@ #include "nfcdc_adapter_p.h" #include "nfcdc_base.h" #include "nfcdc_dbus.h" -#include "nfcdc_log.h" #include "nfcdc_tag_p.h" -#include "nfcdc_util_p.h" +#include "nfcdc_log.h" #include <gutil_macros.h> #include <gutil_misc.h> @@ -63,7 +62,6 @@ NfcAdapterClient* adapter; gulong adapter_event_id[ADAPTER_SIGNAL_COUNT]; OrgSailfishosNfcTag* proxy; - GHashTable* poll_params; gboolean proxy_initializing; gint version; const char* name; @@ -340,27 +338,6 @@ } static -int -nfc_tag_client_poll_param_key( - const char* key) -{ - if (key) { - if (!strcmp(key, "SEL_RES")) { - return NFC_TAG_POLL_PARAM_SELRES; - } else if (!strcmp(key, "NFCID1")) { - return NFC_TAG_POLL_PARAM_NFCID1; - } else if (!strcmp(key, "NFCID0")) { - return NFC_TAG_POLL_PARAM_NFCID0; - } else if (!strcmp(key, "APPDATA")) { - return NFC_TAG_POLL_PARAM_APPDATA; - } else if (!strcmp(key, "PROTINFO")) { - return NFC_TAG_POLL_PARAM_PROTINFO; - } - } - return -1; -} - -static void nfc_tag_client_call_cancelled( GCancellable* cancel, @@ -496,110 +473,54 @@ static void -nfc_tag_client_init_finished( - NfcTagClientObject* self, - gboolean present, - gchar** interfaces, - gchar** ndef_records, - GVariant* dict) -{ - NfcTagClient* tag = &self->pub; - - if (tag->present != present) { - tag->present = present; - nfc_tag_client_queue_signal(self, PRESENT); - } - if (gutil_strv_equal(self->interfaces, interfaces)) { - g_strfreev(interfaces); - } else { - g_strfreev(self->interfaces); - tag->interfaces = self->interfaces = interfaces; - nfc_tag_client_queue_signal(self, INTERFACES); - } - if (gutil_strv_equal(self->ndef_records, ndef_records)) { - g_strfreev(ndef_records); - } else { - g_strfreev(self->ndef_records); - tag->ndef_records = self->ndef_records = ndef_records; - nfc_tag_client_queue_signal(self, NDEF_RECORDS); - } - if (dict) { - GDEBUG("%s: Poll parameters", self->name); - self->poll_params = nfc_parse_dict(self->poll_params, dict, - nfc_tag_client_poll_param_key); - g_variant_unref(dict); - } -} - -static -void -nfc_tag_client_init_5( +nfc_tag_client_init_4( GObject* proxy, GAsyncResult* result, gpointer user_data) { NfcTagClientObject* self = THIS(user_data); + NfcTagClient* tag = &self->pub; GError* error = NULL; gboolean present; gchar** interfaces; gchar** ndef_records; - GVariant* dict; GASSERT(self->proxy_initializing); self->proxy_initializing = FALSE; - if (org_sailfishos_nfc_tag_call_get_all3_finish(self->proxy, - NULL, &present, NULL, NULL, NULL, &interfaces, - &ndef_records, &dict, result, &error)) { - nfc_tag_client_init_finished(self, present, interfaces, - ndef_records, dict); - nfc_tag_client_update_valid_and_present(self); + if (org_sailfishos_nfc_tag_call_get_all_finish(self->proxy, &self->version, + &present, NULL, NULL, NULL, &interfaces, &ndef_records, + result, &error)) { + if (tag->present != present) { + tag->present = present; + nfc_tag_client_queue_signal(self, PRESENT); + } + if (gutil_strv_equal(self->interfaces, interfaces)) { + g_strfreev(interfaces); + } else { + g_strfreev(self->interfaces); + tag->interfaces = self->interfaces = interfaces; + nfc_tag_client_queue_signal(self, INTERFACES); + } + if (gutil_strv_equal(self->ndef_records, ndef_records)) { + g_strfreev(ndef_records); + } else { + g_strfreev(self->ndef_records); + tag->ndef_records = self->ndef_records = ndef_records; + nfc_tag_client_queue_signal(self, NDEF_RECORDS); + } } else { GERR("%s", GERRMSG(error)); g_error_free(error); + /* Need to retry? */ nfc_tag_client_drop_proxy(self); } + nfc_tag_client_update_valid_and_present(self); nfc_tag_client_emit_queued_signals(self); g_object_unref(self); } static void -nfc_tag_client_init_4( - GObject* proxy, - GAsyncResult* result, - gpointer user_data) -{ - NfcTagClientObject* self = THIS(user_data); - GError* error = NULL; - gboolean present; - gchar** interfaces; - gchar** ndef_records; - - GASSERT(self->proxy_initializing); - if (!org_sailfishos_nfc_tag_call_get_all_finish(self->proxy, - &self->version, &present, NULL, NULL, NULL, &interfaces, - &ndef_records, result, &error)) { - GERR("%s", GERRMSG(error)); - self->proxy_initializing = FALSE; - g_error_free(error); - nfc_tag_client_drop_proxy(self); - } else if (self->version >= 3) { - g_strfreev(interfaces); - g_strfreev(ndef_records); - org_sailfishos_nfc_tag_call_get_all3(self->proxy, NULL, - nfc_tag_client_init_5, g_object_ref(self)); - } else { - self->proxy_initializing = FALSE; - nfc_tag_client_init_finished(self, present, interfaces, - ndef_records, NULL); - nfc_tag_client_update_valid_and_present(self); - nfc_tag_client_emit_queued_signals(self); - } - g_object_unref(self); -} - -static -void nfc_tag_client_init_3( GObject* connection, GAsyncResult* result, @@ -816,18 +737,6 @@ } } -const GUtilData* -nfc_tag_client_poll_param( - NfcTagClient* tag, - NFC_TAG_POLL_PARAM param) /* Since 1.0.10 */ -{ - NfcTagClientObject* self = nfc_tag_client_object_cast(tag); - - return (self && self->poll_params) ? - g_hash_table_lookup(self->poll_params, GINT_TO_POINTER(param)) : - NULL; -} - gboolean nfc_tag_client_deactivate( NfcTagClient* tag, @@ -939,9 +848,6 @@ if (self->connection) { g_object_unref(self->connection); } - if (self->poll_params) { - g_hash_table_destroy(self->poll_params); - } g_strfreev(self->interfaces); g_strfreev(self->ndef_records); g_hash_table_remove(nfc_tag_client_table, pub->path); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/qml/ScanPage.qml ^ |
@@ -1,9 +1,7 @@ import QtQuick 2.0 import QtMultimedia 5.4 import Sailfish.Silica 1.0 -import Sailfish.Media 1.0 import org.nemomobile.notifications 1.0 -import org.nemomobile.policy 1.0 import harbour.yubikey 1.0 import "harbour" @@ -11,16 +9,12 @@ Page { id: thisPage - property Item _viewFinder - readonly property bool _canUseVolumeKeys: YubiKeySettings.volumeZoom && Qt.application.active && - (status === PageStatus.Active) - readonly property bool canScan: _viewFinder && _viewFinder.source.cameraState === Camera.ActiveState + property Item viewFinder + readonly property bool canScan: viewFinder && viewFinder.source.cameraState === Camera.ActiveState readonly property bool canShowViewFinder: Qt.application.active && (status === PageStatus.Active || status === PageStatus.Deactivating) - signal tokenDetected(var token) - signal tokensDetected(var tokens) - signal skip() + signal done(var token) onStatusChanged: { if (status === PageStatus.Active) { @@ -30,22 +24,22 @@ onCanShowViewFinderChanged: { if (canShowViewFinder) { - _viewFinder = viewFinderComponent.createObject(viewFinderContainer, { + viewFinder = viewFinderComponent.createObject(viewFinderContainer, { viewfinderResolution: viewFinderContainer.viewfinderResolution, digitalZoom: YubiKeySettings.scanZoom, orientation: orientationAngle() }) - if (_viewFinder.source.availability === Camera.Available) { + if (viewFinder.source.availability === Camera.Available) { console.log("created viewfinder") - _viewFinder.source.start() + viewFinder.source.start() } else { console.log("oops, couldn't create viewfinder...") } } else { - _viewFinder.source.stop() - _viewFinder.destroy() - _viewFinder = null + viewFinder.source.stop() + viewFinder.destroy() + viewFinder = null } } @@ -67,15 +61,11 @@ } onOrientationChanged: { - if (_viewFinder) { - _viewFinder.orientation = orientationAngle() + if (viewFinder) { + viewFinder.orientation = orientationAngle() } } - YubiKeyImportModel { - id: importModel - } - QrCodeScanner { id: scanner @@ -84,22 +74,27 @@ rotation: orientationAngle() onScanFinished: { - importModel.otpUri = result.text - if (importModel.count > 0) { - markImageProvider.image = image - markImage.visible = true - unsupportedCodeNotification.close() - pageStackPopTimer.start() - } else if (lastInvalidCode !== result.text) { - lastInvalidCode = result.text - markImageProvider.image = image - markImage.visible = true - unsupportedCodeNotification.publish() - restartScanTimer.start() - } else { - if (thisPage.canScan) { - scanner.start() + if (result.valid) { + var token = YubiKeyUtil.parseOtpAuthUri(result.text) + if (token.valid) { + markImageProvider.image = image + markImage.visible = true + unsupportedCodeNotification.close() + pageStackPopTimer.token = token + pageStackPopTimer.start() + } else if (lastInvalidCode !== result.text) { + lastInvalidCode = result.text + markImageProvider.image = image + markImage.visible = true + unsupportedCodeNotification.publish() + restartScanTimer.start() + } else { + if (thisPage.canScan) { + scanner.start() + } } + } else if (thisPage.canScan) { + scanner.start() } } } @@ -107,15 +102,10 @@ Timer { id: pageStackPopTimer + property var token + interval: 1000 - onTriggered: { - var n = importModel.count - if (n === 1) { - thisPage.tokenDetected(importModel.getToken(0)) - } else if (n > 1) { - thisPage.tokensDetected(importModel) - } - } + onTriggered: thisPage.done(token) } Timer { @@ -185,16 +175,15 @@ Rectangle { id: viewFinderContainer - readonly property bool canSwitchResolutions: - YubiKeySettings.wideCameraResolution.width > 0 && YubiKeySettings.wideCameraResolution.height > 0 && - YubiKeySettings.narrowCameraResolution.width > 0 && YubiKeySettings.narrowCameraResolution.height > 0 + readonly property real ratio_4_3: 4./3. + readonly property real ratio_16_9: 16./9. + readonly property bool canSwitchResolutions: typeof ViewfinderResolution_4_3 !== "undefined" && + typeof ViewfinderResolution_16_9 !== "undefined" readonly property size viewfinderResolution: canSwitchResolutions ? - (YubiKeySettings.wideScan ? YubiKeySettings.wideCameraResolution : YubiKeySettings.narrowCameraResolution) : + (FoilAuthSettings.scanWideMode ? ViewfinderResolution_4_3 : ViewfinderResolution_16_9) : Qt.size(0,0) - readonly property real ratio: canSwitchResolutions ? - (YubiKeySettings.wideScan ? YubiKeySettings.wideCameraRatio : YubiKeySettings.narrowCameraRatio) : - (YubiKeySettings.wideCameraResolution.width > 0 && YubiKeySettings.wideCameraResolution.height > 0) ? - YubiKeySettings.wideCameraRatio : YubiKeySettings.narrowCameraRatio + readonly property real ratio: canSwitchResolutions ? (FoilAuthSettings.scanWideMode ? ratio_4_3 : ratio_16_9) : + typeof ViewfinderResolution_4_3 !== "undefined" ? ratio_4_3 : ratio_16_9 readonly property int portraitWidth: Math.floor((parent.height/parent.width > ratio) ? parent.width : parent.height/ratio) readonly property int portraitHeight: Math.floor((parent.height/parent.width > ratio) ? (parent.width * ratio) : parent.height) @@ -212,31 +201,13 @@ onYChanged: updateViewFinderPosition() onViewfinderResolutionChanged: { - if (_viewFinder && viewfinderResolution && canSwitchResolutions) { - _viewFinder.viewfinderResolution = viewfinderResolution + if (viewFinder && viewfinderResolution && canSwitchResolutions) { + viewFinder.viewfinderResolution = viewfinderResolution } } function updateViewFinderPosition() { - scanner.viewFinderRect = Qt.rect(x + parent.x, y + parent.y, _viewFinder ? _viewFinder.width : width, _viewFinder ? _viewFinder.height : height) - } - - function updateSupportedResolution_4_3(res) { - if (res.width > YubiKeySettings.wideCameraResolution.width) { - YubiKeySettings.wideCameraResolution = res - } - } - - function updateSupportedResolution_16_9(res) { - if (res.width > YubiKeySettings.narrowCameraResolution.width) { - YubiKeySettings.narrowCameraResolution = res - } - } - - Connections { - target: _viewFinder - onSupportedWideResolutionChanged: viewFinderContainer.updateSupportedResolution_4_3(_viewFinder.supportedWideResolution) - onSupportedNarrowResolutionChanged: viewFinderContainer.updateSupportedResolution_16_9(_viewFinder.supportedNarrowResolution) + scanner.viewFinderRect = Qt.rect(x + parent.x, y + parent.y, viewFinder ? viewFinder.width : width, viewFinder ? viewFinder.height : height) } } } @@ -271,40 +242,16 @@ maximumValue: YubiKeySettings.maxZoom value: 1.0 stepSize: (maximumValue - minimumValue)/100 - onValueChanged: { YubiKeySettings.scanZoom = value - if (_viewFinder) { - _viewFinder.digitalZoom = value + if (viewFinder) { + viewFinder.digitalZoom = value } } - Component.onCompleted: { value = YubiKeySettings.scanZoom - if (_viewFinder) { - _viewFinder.digitalZoom = value - } - } - - function zoomIn() { - if (value < maximumValue) { - var newValue = value + stepSize - if (newValue < maximumValue) { - value = newValue - } else { - value = maximumValue - } - } - } - - function zoomOut() { - if (value > minimumValue) { - var newValue = value - stepSize - if (newValue > minimumValue) { - value = newValue - } else { - value = minimumValue - } + if (viewFinder) { + viewFinder.digitalZoom = value } } } @@ -317,7 +264,7 @@ //: Button label (skip scanning) //% "Skip" text: qsTrId("yubikey-scan-skip_button") - onClicked: thisPage.skip() + onClicked: thisPage.done({ "valid" : false }) } Image { @@ -337,31 +284,6 @@ id: markImageProvider } - MediaKey{ - enabled: _canUseVolumeKeys - key: Qt.Key_VolumeUp - onPressed: zoomSlider.zoomIn() - onRepeat: zoomSlider.zoomIn() - } - - MediaKey{ - enabled: _canUseVolumeKeys - key: Qt.Key_VolumeDown - onPressed: zoomSlider.zoomOut() - onRepeat: zoomSlider.zoomOut() - } - - Permissions{ - autoRelease: true - applicationClass: "camera" - enabled: _canUseVolumeKeys - - Resource{ - type: Resource.ScaleButton - optional: true - } - } - states: [ State { name: "portrait" | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/qml/ViewFinder.qml ^ |
@@ -12,11 +12,11 @@ property alias beepSource: beep.source property bool playingBeep: false property size viewfinderResolution + property bool completed property real digitalZoom: 1.0 - property size supportedWideResolution: Qt.size(0,0) // 4:3 - property size supportedNarrowResolution: Qt.size(0,0) // 16:9 readonly property bool cameraActive: camera.cameraState === Camera.ActiveState + readonly property bool tapFocusActive: focusTimer.running readonly property bool flashOn: camera.flash.mode !== Camera.FlashOff // Not sure why not just camera.orientation but this makes the camera // behave similar to what it does for Jolla Camera @@ -26,12 +26,6 @@ // Camera.ActiveStatus and doesn't emit maximumDigitalZoomChanged signal signal maximumDigitalZoom(var value) - // Internal properties - readonly property bool _tapFocusActive: focusTimer.running - readonly property real _ratio_4_3: 4./3. - readonly property real _ratio_16_9: 16./9. - property bool _completed - onOrientationChanged: { if (camera.cameraState !== Camera.UnloadedState) { reloadTimer.restart() @@ -58,7 +52,7 @@ if (viewfinderResolution) { camera.viewfinder.resolution = viewfinderResolution } - _completed = true + completed = true } function turnFlashOn() { @@ -146,15 +140,15 @@ imageProcessing.whiteBalanceMode: flashOn ? CameraImageProcessing.WhiteBalanceFlash : CameraImageProcessing.WhiteBalanceTungsten - cameraState: (_completed && !reloadTimer.running) ? + cameraState: (completed && !reloadTimer.running) ? Camera.ActiveState : Camera.UnloadedState exposure { exposureCompensation: 1.0 exposureMode: Camera.ExposureAuto } focus { - focusMode: _tapFocusActive ? Camera.FocusAuto : Camera.FocusContinuous - focusPointMode: _tapFocusActive ? Camera.FocusPointCustom : Camera.FocusPointAuto + focusMode: tapFocusActive ? Camera.FocusAuto : Camera.FocusContinuous + focusPointMode: tapFocusActive ? Camera.FocusPointCustom : Camera.FocusPointAuto } onCameraStatusChanged: { if (cameraStatus === Camera.ActiveStatus) { @@ -162,7 +156,6 @@ viewFinder.maximumDigitalZoom(maximumDigitalZoom) digitalZoom = viewFinder.digitalZoom } - updateSupportedResolutions() } onCameraStateChanged: { if (cameraState === Camera.ActiveState) { @@ -174,32 +167,6 @@ } } } - function updateSupportedResolutions() { - var list = camera.supportedViewfinderResolutions() - var max_4_3 = Qt.size(0,0) - var max_16_9 = Qt.size(0,0) - for (var i = 0; i < list.length; i++) { - var size = list[i] - var ratio = size.width / size.height - if (ratio === _ratio_4_3) { - if (size.width > max_4_3.width) { - max_4_3 = size - } - } else if (ratio === _ratio_16_9) { - if (size.width > max_16_9.width) { - max_16_9 = size - } - } - } - if (supportedWideResolution.width !== max_4_3.width && - supportedWideResolution.height !== max_4_3.height) { - supportedWideResolution = Qt.size(max_4_3.width, max_4_3.height) - } - if (supportedNarrowResolution.width !== max_16_9.width && - supportedNarrowResolution.height !== max_16_9.height) { - supportedNarrowResolution = Qt.size(max_16_9.width, max_16_9.height) - } - } } Timer { | ||
[-] [+] | Added | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/qml/YubiKeyAddTokenDialog.qml ^ |
@@ -0,0 +1,192 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import harbour.yubikey 1.0 + +Dialog { + id: thisDialog + + canAccept: (!(type === YubiKeyCard.TypeHOTP) || counterField.acceptableInput) && digitsField.acceptableInput && _acceptableSecret && name !== "" + + property bool canScan: true + property alias acceptText: header.acceptText + property int type: YubiKeyCard.TypeTOTP + property int algorithm: YubiKeyCard.HMAC_SHA1 + property alias name: nameField.text + property alias secret: secretField.text + property alias digits: digitsField.text + property alias counter: counterField.text + + property string yubiKeyId + + signal tokenAccepted(var dialog) + signal replacedWith(var page) + + readonly property bool _acceptableSecret: YubiKeyUtil.isValidBase32(secret) + + onAccepted: tokenAccepted(thisDialog) + + SilicaFlickable { + id: flickable + + anchors.fill: parent + contentHeight: column.height + Theme.paddingLarge + visible: opacity > 0 + Behavior on opacity { FadeAnimation { } } + + Column { + id: column + + width: parent.width + + DialogHeader { + id: header + + //: Dialog button + //% "Save" + acceptText: qsTrId("yubikey-add_token-save") + + //: Dialog title + //% "Add token" + title: qsTrId("yubikey-add_token-title") + } + + TextField { + id: nameField + + width: parent.width + //: Text field label (OTP label) + //% "Name" + label: qsTrId("yubikey-token-name-text") + + EnterKey.enabled: text.length > 0 + EnterKey.iconSource: "image://theme/icon-m-enter-next" + EnterKey.onClicked: secretField.focus = true + } + + TextField { + id: secretField + + width: parent.width + //: Text field label (OTP secret) + //% "Secret" + label: qsTrId("yubikey-token-secret-text") + //: Text field placeholder (OTP secret) + //% "Secret OTP key" + placeholderText: qsTrId("yubikey-token-secret-placeholder") + errorHighlight: !_acceptableSecret + + EnterKey.enabled: text.length > 10 + EnterKey.iconSource: "image://theme/icon-m-enter-next" + EnterKey.onClicked: digitsField.focus = true + } + + + Grid { + columns: isLandscape ? 2 : 1 + width: parent.width + + readonly property real columnWidth: width/columns + + TextField { + id: digitsField + + width: counterField.visible ? parent.columnWidth : parent.width + //: Text field label (number of password digits) + //% "Digits" + label: qsTrId("yubikey-token-digits-text") + //: Text field placeholder (number of password digits) + //% "Number of password digits" + placeholderText: qsTrId("yubikey-token-digits-placeholder") + text: YubiKeyUtil.DefaultDigits + validator: IntValidator { + bottom: 6 + top: 8 + } + + EnterKey.iconSource: "image://theme/icon-m-enter-next" + EnterKey.onClicked: counterField.focus = true + } + + Item { + width: parent.columnWidth + height: (type === YubiKeyCard.TypeHOTP) ? counterField.height : 0 + visible: height > 0 + clip: true + + Behavior on height { + enabled: isPortrait + + SmoothedAnimation { duration: 250 } + } + + TextField { + id: counterField + + width: parent.width + //: Text field label (HOTP counter value) + //% "Initial counter value" + label: qsTrId("yubikey-token-counter-text") + placeholderText: label + text: "" + validator: IntValidator {} + + EnterKey.iconSource: "image://theme/icon-m-enter-accept" + EnterKey.onClicked: parent.forceActiveFocus() + } + } + } + + Grid { + columns: isLandscape ? 2 : 1 + width: parent.width + + readonly property real columnWidth: width/columns + + ComboBox { + id: typeComboBox + + width: parent.columnWidth + //: Combo box label (OTP type) + //% "Type" + label: qsTrId("yubikey-token-type-label") + menu: ContextMenu { + x: 0 + width: typeComboBox.width + //: Menu item for counter based token + //% "Counter-based (HOTP)" + MenuItem { text: qsTrId("yubikey-token-type-hotp") } + //: Menu item for time based token + //% "Time-based (TOTP)" + MenuItem { text: qsTrId("yubikey-token-type-totp") } + } + // AuthType enum is off by 1 + Component.onCompleted: currentIndex = type - 1 + onCurrentIndexChanged: type = currentIndex + 1 + } + + ComboBox { + id: algorithmComboBox + + width: parent.columnWidth + //: Combo box label + //% "Digest algorithm" + label: qsTrId("yubikey-token-digest_algorithm-label") + menu: ContextMenu { + x: 0 + width: algorithmComboBox.width + //: Menu item for the default digest algorithm + //% "%1 (default)" + MenuItem { text: qsTrId("yubikey-token-digest_algorithm-default").arg("SHA1") } + MenuItem { text: "SHA256" } + MenuItem { text: "SHA512" } + } + // YubiKeyAlgorithm enum is off by 1 + Component.onCompleted: currentIndex = algorithm - 1 + onCurrentIndexChanged: algorithm = currentIndex + 1 + } + } + } + + VerticalScrollDecorator { } + } +} | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/qml/YubiKeyAuthListItem.qml ^ |
@@ -10,7 +10,6 @@ property int type property alias name: nameLabel.text property string password - property bool steam property bool favorite property bool expired property bool refreshable @@ -70,7 +69,7 @@ bold: favorite } truncationMode: TruncationMode.Fade - text: steam ? "Steam" : type === YubiKeyCard.TypeTOTP ? "TOTP" : "HOTP" + text: type === YubiKeyCard.TypeTOTP ? "TOTP" : "HOTP" } } | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/qml/YubiKeyPage.qml ^ |
@@ -46,33 +46,6 @@ } } - function renameToken(tokenName) { - var renamePage = pageStack.push("YubiKeyRenameTokenPage.qml", { - "tokenList": otpListModel, - "allowedOrientations": allowedOrientations, - "currentName": tokenName - }) - renamePage.rename.connect(function(name) { - renamePage.forwardNavigation = true - if (yubiKey.renameToken(tokenName, name)) { - replace() - } else { - pageStack.push(waitPageComponent, { - //: Status label - //% "Touch the same YubiKey to rename the token" - "text": qsTrId("yubikey-wait-rename_token"), - "complete": function(page,keyState,waitId,success) { - if (!waitId || !success) { - page.waitForId(yubiKey.renameToken(tokenName, name)) - } else { - page.tryAgain() - } - } - }).waitDone.connect(replace) - } - }) - } - YubiKeyCard { id: yubiKey @@ -108,7 +81,6 @@ } onYubiKeyReset: thisPage.yubiKeyReset() onTotpCodesExpired: otpListModel.totpCodesExpired() - onTokenRenamed: otpListModel.tokenRenamed(from, to) } Buzz { @@ -152,15 +124,9 @@ Component { id: addTokenDialogComponent - YubiKeyTokenDialog { + YubiKeyAddTokenDialog { allowedOrientations: thisPage.allowedOrientations yubiKeyId: thisPage.yubiKeyId - //: Dialog title - //% "Add token" - dialogTitle: qsTrId("yubikey-add_token-title") - //: Dialog button - //% "Save" - acceptText: qsTrId("yubikey-add_token-save") acceptDestinationAction: PageStackAction.Push acceptDestination: waitPageComponent acceptDestinationProperties: { @@ -174,13 +140,13 @@ pageStack.pop(thisPage) } else { var dialog = pageStack.previousPage(page) - page.waitForId(yubiKey.putToken(dialog.type, - dialog.algorithm, dialog.label, dialog.secret, - dialog.digits, dialog.counter ? dialog.counter : 0)) + page.waitForId(yubiKey.putToken(dialog.type, dialog.algorithm, + dialog.name, dialog.secret, dialog.digits, dialog.counter ? dialog.counter : 0)) } } else { page.tryAgain() } + } } } @@ -295,47 +261,21 @@ enabled: !NfcAdapter.targetPresent && _authorized onEnabledChanged: pulleyMenu.updateVisibility() onClicked: { - var page = pageStack.push("ScanPage.qml", { + pageStack.push("ScanPage.qml", { "allowedOrientations": allowedOrientations - }) - page.skip.connect(function() { - pageStack.push(addTokenDialogComponent) - }) - page.tokenDetected.connect(function(token) { - pageStack.push(addTokenDialogComponent, { - "type": token.type, - "algorithm": token.algorithm, - "label": token.label, - "secret": token.secret, - "digits": token.digits, - "counter": token.counter - }) - }) - page.tokensDetected.connect(function(model) { - pageStack.push("YubiKeyImportDialog.qml", { - "allowedOrientations": allowedOrientations, - "model": model, - "acceptDestinationAction": PageStackAction.Push, - "acceptDestination": waitPageComponent, - "acceptDestinationProperties": { - "destinationPage": thisPage, - //: Status label - //% "Touch YubiKey to save the selected tokens" - "text": qsTrId("yubikey-wait-put_selected_tokens"), - "complete": function(page,keyState,waitId,success) { - if (keyState === YubiKeyCard.YubiKeyStateReady) { - if (success) { - pageStack.pop(thisPage) - } else { - var dialog = pageStack.previousPage(page) - page.waitForId(yubiKey.putTokens(dialog.selectedTokens)) - } - } else { - page.tryAgain() - } - } - } - }) + }).done.connect(function(token) { + if (token.valid) { + pageStack.push(addTokenDialogComponent, { + "type": token.type, + "name": token.label, + "secret": token.secret, + "digits": token.digits, + "counter": token.counter ? token.counter : 0, + "algorithm": token.algorithm + }) + } else { + pageStack.push(addTokenDialogComponent) + } }) } } @@ -395,7 +335,7 @@ width: parent.width height: Math.max(contentHeight, contentFlickable.height - authDataColumn.y - (headerItem.visible ? headerItem.height : 0) - - cardInfoColumn.height - 2 * Theme.paddingLarge) + versionLabel.height - cardIdLabel.height - 2 * Theme.paddingLarge) header: Component { ListSeparator { @@ -406,21 +346,16 @@ delegate: YubiKeyAuthListItem { id: delegate - readonly property string itemName: model.name readonly property string itemPassword: model.password readonly property bool itemFavorite: model.favorite - readonly property bool itemCanBeSteamToken: model.type === YubiKeyCard.TypeTOTP readonly property bool itemMarkedForRefresh: model.markedForRefresh readonly property bool itemMarkedForDeletion: model.markedForDeletion readonly property bool itemCanCopyPassword: !itemMarkedForRefresh && !itemMarkedForDeletion && itemPassword !== "" - readonly property bool itemCanRename: !itemMarkedForRefresh && !itemMarkedForDeletion && - yubiKey.yubiKeyVersion >= YubiKeyCard.Version_5_3_0 landscape: thisPage.isLandscape - name: itemName + name: model.name type: model.type password: itemPassword - steam: model.steam favorite: itemFavorite expired: model.expired refreshable: model.refreshable @@ -442,14 +377,14 @@ } } MenuItem { - id: renameMenuItem + id: copyMenuItem - //: Generic menu item - //% "Rename" - text: qsTrId("yubikey-menu-rename") + //: Context menu item (copy password to clipboard) + //% "Copy password" + text: qsTrId("yubikey-menu-copy_password") onEnabledChanged: contextMenu.updateVisibility() - enabled: delegate.itemCanRename - onClicked: renameToken(itemName) + enabled: delegate.itemCanCopyPassword + onClicked: delegate.copyPassword() } MenuItem { id: deleteMenuItem @@ -489,31 +424,16 @@ enabled: !delegate.itemMarkedForDeletion onClicked: delegate.toggleFavorite() } - MenuItem { - id: steamMenuItem - - text: model.steam ? - //: Context menu item - //% "Standard token" - qsTrId("yubikey-menu-use_as_standard_token") : - //: Context menu item - //% "Steam token" - qsTrId("yubikey-menu-use_as_steam_token") - onEnabledChanged: contextMenu.updateVisibility() - enabled: delegate.itemCanBeSteamToken && !delegate.itemMarkedForDeletion - onClicked: model.steam = !model.steam - } Component.onCompleted: updateVisibility() onMenuExpandedChanged: updateVisibility() function updateVisibility() { if (!menuExpanded) { - renameMenuItem.visible = renameMenuItem.enabled + copyMenuItem.visible = copyMenuItem.enabled deleteMenuItem.visible = deleteMenuItem.enabled cancelMenuItem.visible = cancelMenuItem.enabled favoriteMenuItem.visible = favoriteMenuItem.enabled - steamMenuItem.visible = steamMenuItem.enabled } } } @@ -555,9 +475,6 @@ function toggleFavorite() { model.favorite = !model.favorite } - - ListView.onAdd: AddAnimation { target: delegate } - ListView.onRemove: RemoveAnimation { target: delegate } } InfoLabel { @@ -574,44 +491,31 @@ VerticalPadding{ } - Column { - id: cardInfoColumn + Label { + id: versionLabel x: Theme.horizontalPageMargin width: parent.width - 2 * x + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeSmall + color: Theme.secondaryHighlightColor + visible: yubiKey.yubiKeyVersion !== "" + //: Card info label + //% "Version: %1" + text: qsTrId("yubikey-info-version").arg(yubiKey.yubiKeyVersion) + } - Label { - width: parent.width - horizontalAlignment: Text.AlignHCenter - font.pixelSize: Theme.fontSizeSmall - color: Theme.secondaryHighlightColor - visible: yubiKey.yubiKeySerial !== 0 - //: Card info label - //% "Serial: %1" - text: qsTrId("yubikey-info-serial").arg(yubiKey.yubiKeySerial) - } - - Label { - width: parent.width - horizontalAlignment: Text.AlignHCenter - font.pixelSize: Theme.fontSizeSmall - color: Theme.secondaryHighlightColor - visible: yubiKey.yubiKeyVersionString !== "" - //: Card info label - //% "Version: %1" - text: qsTrId("yubikey-info-version").arg(yubiKey.yubiKeyVersionString) - } + Label { + id: cardIdLabel - Label { - width: parent.width - horizontalAlignment: Text.AlignHCenter - font.pixelSize: Theme.fontSizeSmall - color: Theme.secondaryHighlightColor - text: yubiKeyId - } + x: Theme.horizontalPageMargin + width: parent.width - 2 * x + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeSmall + color: Theme.secondaryHighlightColor + text: yubiKeyId } } - VerticalScrollDecorator { } } | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKey.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -54,7 +56,6 @@ // s(SignalName,signalName) #define YUBIKEY_SIGNALS(s) \ s(YubiKeyVersion,yubiKeyVersion) \ - s(YubiKeySerial,yubiKeySerial) \ s(OtpListFetched,otpListFetched) \ s(OtpList,otpList) \ s(OtpData,otpData) \ @@ -85,6 +86,7 @@ #define RESET_RESP_METHOD resetResp #define SET_CODE_RESP_METHOD setCodeResp #define REMOVE_CODE_RESP_METHOD removeCodeResp +#define PUT_RESP_METHOD putResp class YubiKey::Private : public QObject, @@ -195,40 +197,6 @@ int iNextName; }; - // Put - class PutOperation : public KeyOperation { - public: - PutOperation(YubiKey*, const QList<YubiKeyToken>); - - protected: - bool startOperation() Q_DECL_OVERRIDE; - - private: - bool putNext(); - static void putResp(Operation*, const GUtilData*, guint, const GError*); - - private: - const QList<YubiKeyToken> iTokens; - int iNextToken; - }; - - // Rename - class RenameOperation : public KeyOperation { - public: - RenameOperation(YubiKey*, const QString, const QString); - - protected: - bool startOperation() Q_DECL_OVERRIDE; - void finished(bool aSuccess) Q_DECL_OVERRIDE; - - private: - static void renameResp(Operation*, const GUtilData*, guint, const GError*); - - private: - const QString iFrom; - const QString iTo; - }; - public: static QMap<QByteArray,YubiKey*> gMap; @@ -240,7 +208,6 @@ static const NfcIsoDepApdu CMD_SET_CODE; static const NfcIsoDepApdu CMD_PUT_TEMPLATE; static const NfcIsoDepApdu CMD_DELETE_TEMPLATE; - static const NfcIsoDepApdu CMD_RENAME_TEMPLATE; static const NfcIsoDepApdu CMD_SEND_REMAINING; static const uchar CMD_SET_CODE_DATA[]; @@ -259,10 +226,12 @@ void verifyAuthorization(); void recheckAuthorization(); void authorized(YubiKeyAuthAccess); - int submit(YubiKeyTag::Operation*, bool aForceSelect = false); + void submit(YubiKeyTag::Operation*, bool aForceSelect = false); void submitUnique(YubiKeyTag::Operation*, bool aForceSelect = false); void requestList(bool aRightAway = false); void submitCalculateAll(); + int submitPutHotpToken(YubiKeyAlgorithm, const QString, const QByteArray, int, int); + int submitPutTotpToken(YubiKeyAlgorithm, const QString, const QByteArray, int); int setPassword(const QString); bool submitPassword(const QString, bool); int reset(); @@ -272,7 +241,6 @@ void updateAuthAccess(YubiKeyAuthAccess); void updateAuthAlgorithm(); void updateYubiKeyVersion(); - void updateYubiKeySerial(); void updateOperationIds(); void calculateAllOk(const QByteArray); void updateOtpList(const QByteArray); @@ -290,10 +258,10 @@ YUBIKEY_TRANSMIT_RESP_SLOT(RESET_RESP_METHOD); YUBIKEY_TRANSMIT_RESP_SLOT(SET_CODE_RESP_METHOD); YUBIKEY_TRANSMIT_RESP_SLOT(REMOVE_CODE_RESP_METHOD); + YUBIKEY_TRANSMIT_RESP_SLOT(PUT_RESP_METHOD); void onTagStateChanged(); void onYubiKeyIdChanged(); void onYubiKeyVersionChanged(); - void onYubiKeySerialChanged(); void onYubiKeyAuthAlgorithmChanged(); void onYubiKeyAuthChallengeChanged(); void onOperationIdsChanged(); @@ -315,9 +283,7 @@ const QByteArray iYubiKeyId; const QString iYubiKeyIdString; QByteArray iYubiKeyVersion; - uint iYubiKeyVersionNumber; QString iYubiKeyVersionString; - uint iYubiKeySerial; QByteArray iOtpList; QString iOtpListString; QByteArray iOtpData; @@ -361,9 +327,6 @@ const NfcIsoDepApdu YubiKey::Private::CMD_DELETE_TEMPLATE = { 0x00, 0x02, 0x00, 0x00, { NULL, 0 }, 0 }; -const NfcIsoDepApdu YubiKey::Private::CMD_RENAME_TEMPLATE = { - 0x00, 0x05, 0x00, 0x00, { NULL, 0 }, 0 -}; const NfcIsoDepApdu YubiKey::Private::CMD_SEND_REMAINING = { 0x00, 0xa5, 0x00, 0x00, { NULL, 0 }, 0 }; @@ -384,8 +347,6 @@ iAuthAccess(YubiKeyAuthAccessUnknown), iYubiKeyId(aYubiKeyId), iYubiKeyIdString(YubiKeyUtil::toHex(aYubiKeyId)), - iYubiKeyVersionNumber(0), - iYubiKeySerial(0), iOtpListFetched(false), iTotpTimer(new QTimer(this)), iLastRequestedPeriod(0), @@ -580,13 +541,6 @@ } void -YubiKey::Private::onYubiKeySerialChanged() -{ - updateYubiKeySerial(); - emitQueuedSignals(); -} - -void YubiKey::Private::onYubiKeyAuthAlgorithmChanged() { updateAuthAlgorithm(); @@ -658,9 +612,6 @@ SIGNAL(yubiKeyVersionChanged()), SLOT(onYubiKeyVersionChanged())); connect(iTag, - SIGNAL(yubiKeySerialChanged()), - SLOT(onYubiKeySerialChanged())); - connect(iTag, SIGNAL(yubiKeyAuthAlgorithmChanged()), SLOT(onYubiKeyAuthAlgorithmChanged())); connect(iTag, @@ -713,7 +664,6 @@ if (iYubiKeyVersion != version) { iYubiKeyVersion = version; iYubiKeyVersionString = YubiKeyUtil::versionToString(version); - iYubiKeyVersionNumber = YubiKeyUtil::versionToNumber(version); HDEBUG(qPrintable(iYubiKeyVersionString)); queueSignal(SignalYubiKeyVersionChanged); } @@ -721,20 +671,6 @@ } void -YubiKey::Private::updateYubiKeySerial() -{ - if (validTag()) { - const uint serial(iTag->yubiKeySerial()); - - if (iYubiKeySerial != serial) { - iYubiKeySerial = serial; - HDEBUG(iYubiKeySerial); - queueSignal(SignalYubiKeySerialChanged); - } - } -} - -void YubiKey::Private::updateAuthAlgorithm() { if (validTag()) { @@ -795,7 +731,7 @@ // +---------------+----------------------------------------------+ while ((tag = YubiKeyUtil::readTLV(&resp, &data)) != 0) { switch (tag) { - case TLV_TAG_NAME: + case YubiKeyConstants::TLV_TAG_NAME: name = QString::fromUtf8((char*)data.bytes, (int)data.size); break; case TLV_TAG_NO_RESPONSE: @@ -879,7 +815,6 @@ updateOperationIds(); if (present) { updateAuthAlgorithm(); - updateYubiKeySerial(); updateYubiKeyVersion(); verifyAuthorization(); } @@ -906,14 +841,13 @@ requestList(); } -int +void YubiKey::Private::submit( YubiKeyTag::Operation* aOperation, // Takes ownership bool aToFront) { - const int id = aOperation->submit(iTag, aToFront); + aOperation->submit(iTag, aToFront); aOperation->unref(); - return id; } void @@ -1212,6 +1146,144 @@ } } +int +YubiKey::Private::submitPutHotpToken( + YubiKeyAlgorithm aAlgorithm, + const QString aName, + const QByteArray aSecret, + int aDigits, + int aCounter) +{ + int id = 0; + + if (!canTransmit()) { + HDEBUG("Can't send TOTP token"); + } else { + // Put Data + // + // +-----------------+----------------------------------------------+ + // | Name tag | 0x71 | + // | Name length | Length of name data, max 64 bytes | + // | Name data | Name | + // +-----------------+----------------------------------------------+ + // | Key tag | 0x73 | + // | Key length | Length of key data + 2 | + // | Key algorithm | High 4 bits is type, low 4 bits is algorithm | + // | Digits | Number of digits in OATH code | + // | Key data | Key | + // +-----------------+----------------------------------------------+ + // | Property tag(o) | 0x78 | + // | Property(o) | Property byte | + // +-----------------+----------------------------------------------+ + // | IMF tag(o) | 0x7a (only valid for HOTP) | + // | IMF length(o) | Length of imf data, always 4 bytes | + // | IMF data(o) | Imf | + // +-----------------+----------------------------------------------+ + const QByteArray nameUtf8(nameToUtf8(aName)); + + // YubiKey seems to require at least 14 bytes of key data + // Pad the key with zeros if necessary + const int keySize = qMax(aSecret.size(), (int) MinKeySize); + const int padding = keySize - aSecret.size(); + const guint32 imf = htobe32(aCounter); + + NfcIsoDepApdu cmd = CMD_PUT_TEMPLATE; + QByteArray data; + + data.reserve(nameUtf8.size() + keySize + 16); + YubiKeyUtil::appendTLV(&data, TLV_TAG_NAME, nameUtf8); + data.append((char)TLV_TAG_KEY); + data.append((char)(keySize + 2)); + data.append((char)(TYPE_HOTP | YubiKeyUtil::algorithmValue(aAlgorithm))); + data.append((char)aDigits); + data.append(aSecret); + for (int i = 0; i < padding; i++) { + data.append((char)0); + } + data.append((char)TLV_TAG_PROPERTY); + data.append((char)PROP_REQUIRE_TOUCH); + YubiKeyUtil::appendTLV(&data, TLV_TAG_IMF, sizeof(imf), &imf); + + cmd.data.bytes = (const guint8*)data.constData(); + cmd.data.size = data.size(); + id = iTag->transmit(&cmd, this, G_STRINGIFY(PUT_RESP_METHOD), iCancel); + DUMP_CMD("PUT", cmd, id); + } + return id; +} + +int +YubiKey::Private::submitPutTotpToken( + YubiKeyAlgorithm aAlgorithm, + const QString aName, + const QByteArray aSecret, + int aDigits) +{ + int id = 0; + + if (!canTransmit()) { + HDEBUG("Can't send TOTP token"); + } else { + // Put Data + // + // +-----------------+----------------------------------------------+ + // | Name tag | 0x71 | + // | Name length | Length of name data, max 64 bytes | + // | Name data | Name | + // +-----------------+----------------------------------------------+ + // | Key tag | 0x73 | + // | Key length | Length of key data + 2 | + // | Key algorithm | High 4 bits is type, low 4 bits is algorithm | + // | Digits | Number of digits in OATH code | + // | Key data | Key | + // +-----------------+----------------------------------------------+ + // | Property tag(o) | 0x78 | + // | Property(o) | Property byte | + // +-----------------+----------------------------------------------+ + + // YubiKey seems to require at least 14 bytes of key data + // Pad the key with zeros if necessary + const int keySize = qMax(aSecret.size(), (int) MinKeySize); + const int padding = keySize - aSecret.size(); + + const QByteArray nameUtf8(nameToUtf8(aName)); + NfcIsoDepApdu cmd = CMD_PUT_TEMPLATE; + QByteArray data; + + data.reserve(nameUtf8.size() + keySize + 8); + YubiKeyUtil::appendTLV(&data, TLV_TAG_NAME, nameUtf8); + data.append((char)TLV_TAG_KEY); + data.append((char)(keySize + 2)); + data.append((char)(TYPE_TOTP | YubiKeyUtil::algorithmValue(aAlgorithm))); + data.append((char)aDigits); + data.append(aSecret); + for (int i = 0; i < padding; i++) { + data.append((char)0); + } + + cmd.data.bytes = (const guint8*)data.constData(); + cmd.data.size = data.size(); + id = iTag->transmit(&cmd, this, G_STRINGIFY(PUT_RESP_METHOD), iCancel); + DUMP_CMD("PUT", cmd, id); + } + return id; +} + +void +YubiKey::Private::PUT_RESP_METHOD( + const GUtilData* aResp, + guint aSw, + const GError* aError) +{ + if (!aError && aSw == RC_OK) { + HDEBUG("PUT ok" << qPrintable(YubiKeyUtil::toHex(aResp))); + requestList(); + emitQueuedSignals(); + } else { + REPORT_ERROR("PUT", aSw, aError); + } +} + // ========================================================================== // YubiKey::Private::AuthorizeOperation // ========================================================================== @@ -1662,210 +1734,6 @@ } // ========================================================================== -// YubiKey::Private::PutOperation -// ========================================================================== - -YubiKey::Private::PutOperation::PutOperation( - YubiKey* aKey, - const QList<YubiKeyToken> aTokens) : - KeyOperation("Put", aKey), - iTokens(aTokens), - iNextToken(0) -{ -} - -bool -YubiKey::Private::PutOperation::startOperation() -{ - return putNext(); -} - -bool -YubiKey::Private::PutOperation::putNext() -{ - if (iNextToken < iTokens.count()) { - // Put Data - // - // +-----------------+----------------------------------------------+ - // | Name tag | 0x71 | - // | Name length | Length of name data, max 64 bytes | - // | Name data | Name | - // +-----------------+----------------------------------------------+ - // | Key tag | 0x73 | - // | Key length | Length of key data + 2 | - // | Key algorithm | High 4 bits is type, low 4 bits is algorithm | - // | Digits | Number of digits in OATH code | - // | Key data | Key | - // +-----------------+----------------------------------------------+ - // | Property tag(o) | 0x78 | - // | Property(o) | Property byte | - // +-----------------+----------------------------------------------+ - // | IMF tag(o) | 0x7a (only valid for HOTP) | - // | IMF length(o) | Length of imf data, always 4 bytes | - // | IMF data(o) | Imf | - // +-----------------+----------------------------------------------+ - - const YubiKeyToken token(iTokens.at(iNextToken)); - - // YubiKey seems to require at least 14 bytes of key data - // Pad the key with zeros if necessary - const QByteArray secret(token.secret()); - const int keySize = qMax(secret.size(), (int) MinKeySize); - const int padding = keySize - secret.size(); - const QByteArray nameUtf8(nameToUtf8(token.label())); - QByteArray data; - uchar type; - - if (token.type() == YubiKeyTokenType_HOTP) { - type = TYPE_HOTP; - data.reserve(nameUtf8.size() + keySize + 16); - } else { - type = TYPE_TOTP; - data.reserve(nameUtf8.size() + keySize + 8); - } - - YubiKeyUtil::appendTLV(&data, TLV_TAG_NAME, nameUtf8); - data.append((char)TLV_TAG_KEY); - data.append((char)(keySize + 2)); - data.append((char)(type | YubiKeyUtil::algorithmValue(token.algorithm()))); - data.append((char)token.digits()); - data.append(secret); - for (int i = 0; i < padding; i++) { - data.append((char)0); - } - - if (token.type() == YubiKeyTokenType_HOTP) { - const guint32 imf = htobe32(token.counter()); - - data.append((char)TLV_TAG_PROPERTY); - data.append((char)PROP_REQUIRE_TOUCH); - YubiKeyUtil::appendTLV(&data, TLV_TAG_IMF, sizeof(imf), &imf); - } - - NfcIsoDepApdu putCmd = CMD_PUT_TEMPLATE; - - putCmd.data.bytes = (const guint8*)data.constData(); - putCmd.data.size = data.size(); - HDEBUG("PUT" << iNextToken << token); - if (transmit(&putCmd, putResp)) { - iNextToken++; - return true; - } - } - return false; -} - -void -YubiKey::Private::PutOperation::putResp( - Operation* aOperation, - const GUtilData*, - guint aSw, - const GError* aError) -{ - PutOperation* self = (PutOperation*)aOperation; - YubiKey* key = self->iYubiKey; - YubiKey::Private* priv = key->iPrivate; - - if (!aError) { -#if HARBOUR_DEBUG - if (aSw == RC_OK) { - HDEBUG("PUT ok"); - } else{ - HDEBUG("PUT error" << hex << aSw); - } -#endif // HARBOUR_DEBUG - // Try the next one anyway - if (self->putNext()) { - // Not finished yet - return; - } else { - priv->requestList(true); - } - } else { - REPORT_ERROR("PUT", aSw, aError); - } - self->finished(!aError); -} - -// ========================================================================== -// YubiKey::Private::RenameOperation -// ========================================================================== - -YubiKey::Private::RenameOperation::RenameOperation( - YubiKey* aKey, - const QString aFrom, - const QString aTo) : - KeyOperation("Rename", aKey), - iFrom(aFrom), - iTo(aTo) -{ -} - -bool -YubiKey::Private::RenameOperation::startOperation() -{ - // Rename credential - // - // +-----------------+----------------------------------------------+ - // | Name tag | 0x71 | - // | Name length | Length of name data, max 64 bytes | - // | Name data | The current credential's name | - // +-----------------+----------------------------------------------+ - // | Name tag | 0x71 | - // | Name length | Length of name data, max 64 bytes | - // | Name data | The new credential's name | - // +-----------------+----------------------------------------------+ - - QByteArray data; - - YubiKeyUtil::appendTLV(&data, TLV_TAG_NAME, nameToUtf8(iFrom)); - YubiKeyUtil::appendTLV(&data, TLV_TAG_NAME, nameToUtf8(iTo)); - - NfcIsoDepApdu renameCmd = CMD_RENAME_TEMPLATE; - - renameCmd.data.bytes = (const guint8*) data.constData(); - renameCmd.data.size = data.size(); - HDEBUG("RENAME" << iFrom << "=>" << iTo); - return transmit(&renameCmd, renameResp); -} - -void -YubiKey::Private::RenameOperation::renameResp( - Operation* aOperation, - const GUtilData*, - guint aSw, - const GError* aError) -{ - RenameOperation* self = (RenameOperation*)aOperation; - YubiKey* key = self->iYubiKey; - YubiKey::Private* priv = key->iPrivate; - - if (!aError) { -#if HARBOUR_DEBUG - if (aSw == RC_OK) { - HDEBUG("RENAME ok"); - } else{ - HDEBUG("RENAME error" << hex << aSw); - } -#endif // HARBOUR_DEBUG - priv->requestList(true); - } else { - REPORT_ERROR("RENAME", aSw, aError); - } - self->finished(!aError); -} - -void -YubiKey::Private::RenameOperation::finished( - bool aSuccess) -{ - if (aSuccess) { - Q_EMIT iYubiKey->tokenRenamed(iFrom, iTo); - } - KeyOperation::finished(aSuccess); -} - -// ========================================================================== // YubiKey // ========================================================================== @@ -1940,16 +1808,16 @@ return iPrivate->iYubiKeyId; } -const QString -YubiKey::yubiKeyIdString() const +const QByteArray +YubiKey::yubiKeyVersion() const { - return iPrivate->iYubiKeyIdString; + return iPrivate->iYubiKeyVersion; } -uint -YubiKey::yubiKeyVersion() const +const QString +YubiKey::yubiKeyIdString() const { - return iPrivate->iYubiKeyVersionNumber; + return iPrivate->iYubiKeyIdString; } const QString @@ -1958,12 +1826,6 @@ return iPrivate->iYubiKeyVersionString; } -uint -YubiKey::yubiKeySerial() const -{ - return iPrivate->iYubiKeySerial; -} - const QByteArray YubiKey::otpList() const { @@ -2045,22 +1907,34 @@ } int -YubiKey::putTokens( - const QList<YubiKeyToken> aTokens) -{ - if (!aTokens.isEmpty() && iPrivate->canTransmit()) { - HDEBUG(aTokens); - return iPrivate->submit(new Private::PutOperation(this, aTokens)); +YubiKey::putHotpToken( + YubiKeyAlgorithm aAlgorithm, + const QString aName, + const QByteArray aSecret, + int aDigits, + int aCounter) +{ + if (aDigits >= YubiKeyUtil::MinDigits && + aDigits <= YubiKeyUtil::MaxDigits) { + return iPrivate->submitPutHotpToken(aAlgorithm, aName, aSecret, + aDigits, aCounter); } - return 0; + return false; } int -YubiKey::renameToken( - const QString aFrom, - const QString aTo) -{ - return iPrivate->submit(new Private::RenameOperation(this, aFrom, aTo)); +YubiKey::putTotpToken( + YubiKeyAlgorithm aAlgorithm, + const QString aName, + const QByteArray aSecret, + int aDigits) +{ + if (aDigits >= YubiKeyUtil::MinDigits && + aDigits <= YubiKeyUtil::MaxDigits) { + return iPrivate->submitPutTotpToken(aAlgorithm, aName, aSecret, + aDigits); + } + return false; } bool | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKey.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -36,11 +38,10 @@ #ifndef _YUBIKEY_H #define _YUBIKEY_H -#include "YubiKeyToken.h" +#include "YubiKeyTypes.h" #include <QByteArray> #include <QDebug> -#include <QList> #include <QObject> #include <QString> #include <QStringList> @@ -63,13 +64,12 @@ void unref(); const QByteArray yubiKeyId() const; + const QByteArray yubiKeyVersion() const; const QByteArray otpList() const; const QByteArray otpData() const; bool otpListFetched() const; bool present() const; YubiKeyAuthAccess authAccess() const; - uint yubiKeySerial() const; - uint yubiKeyVersion() const; const QString yubiKeyIdString() const; const QString yubiKeyVersionString() const; @@ -80,8 +80,8 @@ bool totpValid() const; int totpTimeLeft() const; // seconds - int putTokens(const QList<YubiKeyToken>); - int renameToken(const QString, const QString); + int putHotpToken(YubiKeyAlgorithm, const QString, const QByteArray, int, int); + int putTotpToken(YubiKeyAlgorithm, const QString, const QByteArray, int); bool submitPassword(const QString, bool); void refreshTokens(const QStringList); void deleteTokens(const QStringList); @@ -89,7 +89,6 @@ int reset(); Q_SIGNALS: - void yubiKeySerialChanged(); void yubiKeyVersionChanged(); void otpListFetchedChanged(); void otpListChanged(); @@ -105,7 +104,6 @@ void totpCodesExpired(); void passwordChanged(); void passwordRemoved(); - void tokenRenamed(const QString, const QString); void yubiKeyReset(); private: | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyAuthListModel.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,45 +8,46 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing * any official policies, either expressed or implied. */ -#include "YubiKeyAuthListModel.h" -#include "YubiKeyCardSettings.h" #include "YubiKeyConstants.h" +#include "YubiKeyAuthListModel.h" #include "YubiKeyUtil.h" #include "HarbourDebug.h" -#include <ctype.h> +#include <QDir> +#include <QSettings> // Model roles #define MODEL_ROLES_(first,role,last) \ first(Name,name) \ role(Type,type) \ - role(Steam,steam) \ role(Algorithm,algorithm) \ role(Password,password) \ role(Favorite,favorite) \ @@ -102,8 +103,6 @@ ModelData(const QByteArray, YubiKeyTokenType, YubiKeyAlgorithm); QVariant get(Role) const; - bool canBeSteamToken() const; - bool updatePassword(); static YubiKeyTokenType toAuthType(uchar); static YubiKeyAlgorithm toAuthAlgorithm(uchar); @@ -111,17 +110,12 @@ public: const QByteArray iUtf8Name; const QString iName; - const QString iNameHash; - const QString iSteamHash; const YubiKeyTokenType iType; const YubiKeyAlgorithm iAlgorithm; QString iPassword; - bool iSteam; bool iFavorite; bool iExpired; bool iRefreshable; - uint iDigits; - uint iMiniHash; Mark iMark; }; @@ -131,16 +125,11 @@ YubiKeyAlgorithm aAlgorithm) : iUtf8Name(aUtf8Name), iName(QString::fromUtf8(aUtf8Name)), - iNameHash(YubiKeyUtil::hashUtf8(aUtf8Name)), - iSteamHash(YubiKeyUtil::steamHashUtf8(aUtf8Name)), iType(aType), iAlgorithm(aAlgorithm), - iSteam(false), iFavorite(false), iExpired(false), iRefreshable(aType == YubiKeyTokenType_HOTP), - iDigits(0), - iMiniHash(0), iMark(MarkNone) { } @@ -152,7 +141,6 @@ switch (aRole) { case NameRole: return iName; case TypeRole: return iType; - case SteamRole: return iSteam; case AlgorithmRole: return iAlgorithm; case PasswordRole: return iPassword; case FavoriteRole: return iFavorite; @@ -164,44 +152,6 @@ return QVariant(); } -bool -YubiKeyAuthListModel::ModelData::canBeSteamToken() const -{ - return iType == YubiKeyTokenType_TOTP; -} - -bool -YubiKeyAuthListModel::ModelData::updatePassword() -{ - QString strPass; - - if (iSteam) { - static const QString ALPHABET("23456789BCDFGHJKMNPQRTVWXY"); - uint pass = iMiniHash; - // Steam codes always have 5 symbols, ignore the digit count. - // And YubiKey requires the number of digits to be at least 6, - // PUT command with 5 digits fails with code 6A80 (Wrong syntax) - for (uint i = 0; i < 5; i++) { - strPass.append(ALPHABET.at(pass % ALPHABET.size())); - pass /= ALPHABET.size(); - } - } else { - uint maxPass = 10; - for (uint i = 1; i < iDigits; i++) { - maxPass *= 10; - } - const uint pass = iMiniHash % maxPass; - strPass = QString().sprintf("%0*u", iDigits, pass); - } - - if (iPassword != strPass) { - iPassword = strPass; - return true; - } else { - return false; - } -} - YubiKeyTokenType YubiKeyAuthListModel::ModelData::toAuthType( uchar aTypeAlg) @@ -225,8 +175,7 @@ // YubiKeyAuthListModel::ModelData::List // ========================================================================== -class YubiKeyAuthListModel::ModelData::List : - public QList<ModelData*> +class YubiKeyAuthListModel::ModelData::List : public QList<ModelData*> { public: List() {} @@ -234,7 +183,6 @@ ModelData* dataAt(int) const; int findUtf8(const QByteArray, int) const; - int findName(const QString) const; }; YubiKeyAuthListModel::ModelData::List::List( @@ -318,19 +266,6 @@ } } -int -YubiKeyAuthListModel::ModelData::List::findName( - const QString aName) const -{ - const int n = count(); - for (int i = 0; i < n; i++) { - if (at(i)->iName == aName) { - return i; - } - } - return -1; -} - // ========================================================================== // YubiKeyAuthListModel::Private // ========================================================================== @@ -347,6 +282,9 @@ SignalCount }; + static const QString SETTINGS_FILE; + static const QString FAVORITE_ENTRY; + public: Private(YubiKeyAuthListModel*); ~Private(); @@ -363,15 +301,15 @@ void updateMarkedForRefresh(); void updateMarkedForDeletion(); void markChanged(ModelData::Mark, QVector<int>*); - QString getFavoriteHash(); QVector<int> toggleMark(ModelData*, ModelData::Mark, bool); - QStringList marked(ModelData::Mark); + QStringList marked(ModelData::Mark aMark); public: SignalMask iQueuedSignals; Signal iFirstQueuedSignal; YubiKeyAuthListModel* iModel; - YubiKeyCardSettings* iCardSettings; + QDir iConfigDir; + QSettings* iSettings; QString iYubiKeyId; QString iHexAuthList; QString iHexAuthData; @@ -387,12 +325,17 @@ bool iHaveExpiringTotpCodes; }; + +const QString YubiKeyAuthListModel::Private::SETTINGS_FILE("settings"); +const QString YubiKeyAuthListModel::Private::FAVORITE_ENTRY("Favorite"); + YubiKeyAuthListModel::Private::Private( YubiKeyAuthListModel* aModel) : iQueuedSignals(0), iFirstQueuedSignal(SignalCount), iModel(aModel), - iCardSettings(Q_NULLPTR), + iConfigDir(YubiKeyUtil::configDir()), + iSettings(Q_NULLPTR), iFavoriteTokenType(YubiKeyTokenType_Unknown), iFavoriteMarkedForRefresh(false), iFavoritePasswordExpired(false), @@ -402,7 +345,7 @@ YubiKeyAuthListModel::Private::~Private() { - delete iCardSettings; + delete iSettings; qDeleteAll(iList); } @@ -449,12 +392,6 @@ } } -QString -YubiKeyAuthListModel::Private::getFavoriteHash() -{ - return iCardSettings ? iCardSettings->favoriteHash() : QString(); -} - void YubiKeyAuthListModel::Private::setYubiKeyId( const QString aYubiKeyId) @@ -462,52 +399,43 @@ if (iYubiKeyId != aYubiKeyId) { iYubiKeyId = aYubiKeyId; queueSignal(SignalYubiKeyIdChanged); - delete iCardSettings; + delete iSettings; if (iYubiKeyId.isEmpty()) { - iCardSettings = Q_NULLPTR; + iSettings = Q_NULLPTR; } else { - iCardSettings = new YubiKeyCardSettings(iYubiKeyId); + const QString settingsFile(iConfigDir.absoluteFilePath(iYubiKeyId) + + QDir::separator() + SETTINGS_FILE); - const QString favoriteHash(iCardSettings->favoriteHash()); + HDEBUG("Settings" << qPrintable(settingsFile)); + iConfigDir.mkpath("."); + iSettings = new QSettings(settingsFile, QSettings::IniFormat); + + const QString favoriteName(iSettings->value(FAVORITE_ENTRY).toString()); + const QVector<int> roles(1, ModelData::FavoriteRole); QString realFavoriteName, favoritePassword; YubiKeyTokenType favoriteTokenType = YubiKeyTokenType_Unknown; bool favoriteExpired = false, favoriteMfR = false; - QVector<int> roles; // Update the roles to match the settings for (int i = 0; i < iList.count(); i++) { ModelData* entry = iList.at(i); - roles.resize(0); - - if (entry->iNameHash == favoriteHash) { - realFavoriteName = entry->iName; + if (entry->iName == favoriteName) { + realFavoriteName = favoriteName; favoritePassword = entry->iPassword; favoriteTokenType = entry->iType; favoriteExpired = entry->iExpired; favoriteMfR = (entry->iMark == ModelData::MarkForRefresh); if (!entry->iFavorite) { + const QModelIndex idx(iModel->index(i)); + entry->iFavorite = true; - roles.append(ModelData::FavoriteRole); + Q_EMIT iModel->dataChanged(idx, idx, roles); } } else if (entry->iFavorite) { - entry->iFavorite = false; - roles.append(ModelData::FavoriteRole); - } - - if (iCardSettings->isSteamHash(entry->iSteamHash)) { - if (!entry->iSteam) { - entry->iSteam = true; - roles.append(ModelData::SteamRole); - } - } else if (entry->iSteam) { - entry->iSteam = false; - roles.append(ModelData::SteamRole); - } - - if (!roles.isEmpty()) { const QModelIndex idx(iModel->index(i)); + entry->iFavorite = false; Q_EMIT iModel->dataChanged(idx, idx, roles); } } @@ -537,24 +465,19 @@ iMarkedForRefresh.clear(); iMarkedForDeletion.clear(); - const QString favoriteHash(getFavoriteHash()); bool favoriteExpired = false, favoriteMfR = false; YubiKeyTokenType favoriteTokenType = YubiKeyTokenType_Unknown; QString realFavoriteName, favoritePassword; - QStringList steamHashes; + const QString favoriteName(iSettings ? + iSettings->value(FAVORITE_ENTRY).toString() : + QString()); for (int i = 0; i < n; i++) { ModelData* entry = iList.at(i); - entry->iSteam = iCardSettings && - iCardSettings->isSteamHash(entry->iSteamHash); - if (entry->iSteam) { - steamHashes.append(entry->iSteamHash); - } - - entry->iFavorite = (entry->iNameHash == favoriteHash); + entry->iFavorite = (entry->iName == favoriteName); if (entry->iFavorite) { - realFavoriteName = entry->iName; + realFavoriteName = favoriteName; favoritePassword = entry->iPassword; favoriteTokenType = entry->iType; favoriteExpired = entry->iExpired; @@ -588,13 +511,6 @@ if (hadExpiringTotpCodes != iHaveExpiringTotpCodes) { queueSignal(SignalHaveExpiringTotpCodesChanged); } - if (iCardSettings) { - steamHashes.sort(); - iCardSettings->setSteamHashes(steamHashes); - if (realFavoriteName.isEmpty()) { - iCardSettings->clearFavorite(); - } - } } void @@ -865,13 +781,19 @@ ModelData* entry = iPrivate->iList.at(currentPos); // First byte: Number of digits in the OATH code - entry->iDigits = data.bytes[0]; + const uint digits = data.bytes[0]; + uint maxPass = 10; + for (uint i = 1; i < digits; i++) { + maxPass *= 10; + } // The rest is the calculated hash data.bytes++; data.size--; const uint off = data.bytes[data.size - 1] & 0x0f; - entry->iMiniHash = be32toh(*(guint32*)(data.bytes + off)) & 0x7fffffff; + const uint miniHash = be32toh(*(guint32*)(data.bytes + off)) & 0x7fffffff; + const uint pass = miniHash % maxPass; + const QString strPass(QString().sprintf("%0*u", digits, pass)); roles.resize(0); // Refresh is considered done even if the code didn't change @@ -880,11 +802,12 @@ roles.append(ModelData::MarkedForRefreshRole); refreshMarksUpdated = true; } - if (entry->updatePassword()) { + if (entry->iPassword != strPass) { + entry->iPassword = strPass; roles.append(ModelData::PasswordRole); - HDEBUG((currentPos + 1) << entry->iPassword); + HDEBUG((currentPos + 1) << strPass); if (entry->iFavorite) { - iPrivate->setFavoritePassword(entry->iPassword); + iPrivate->setFavoritePassword(strPass); iPrivate->setFavoritePasswordExpired(false); } if (entry->iExpired) { @@ -1024,26 +947,6 @@ } } -void -YubiKeyAuthListModel::tokenRenamed( - const QString aFrom, - const QString aTo) -{ - // There is a refresh after each rename, the new (renamed) token will - // be recognized as a favorite - HDEBUG(aFrom << "=>" << aTo); - if (iPrivate->iCardSettings) { - iPrivate->iCardSettings->tokenRenamed(aFrom, aTo); - } -} - -bool -YubiKeyAuthListModel::containsName( - const QString aName) const -{ - return iPrivate->iList.findName(aName) >= 0; -} - Qt::ItemFlags YubiKeyAuthListModel::flags( const QModelIndex& aIndex) const @@ -1095,15 +998,19 @@ b = aValue.toBool(); HDEBUG(aIndex.row() << "favorite" << b); if (data->iFavorite != b) { + QSettings* settings = iPrivate->iSettings; + roles.append(aRole); data->iFavorite = b; - if (iPrivate->iCardSettings) { + + if (settings) { if (b) { - iPrivate->iCardSettings->setFavoriteHash(data->iNameHash); + settings->setValue(Private::FAVORITE_ENTRY, data->iName); } else { - iPrivate->iCardSettings->clearFavorite(); + settings->remove(Private::FAVORITE_ENTRY); } } + if (b) { // There is only one favorite iPrivate->setFavoriteName(data->iName); @@ -1130,25 +1037,6 @@ } ok = true; break; - case ModelData::SteamRole: - b = aValue.toBool(); - HDEBUG(aIndex.row() << "stream" << b); - if (data->iSteam != b && (!b || data->canBeSteamToken())) { - data->iSteam = b; - roles.append(ModelData::SteamRole); - if (data->updatePassword()) { - roles.append(ModelData::PasswordRole); - } - if (iPrivate->iCardSettings) { - if (b) { - iPrivate->iCardSettings->addSteamHash(data->iSteamHash); - } else { - iPrivate->iCardSettings->removeSteamHash(data->iSteamHash); - } - } - } - ok = true; - break; case ModelData::MarkedForRefreshRole: b = aValue.toBool(); HDEBUG(aIndex.row() << "markedForRefresh" << b); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyAuthListModel.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -84,8 +86,6 @@ QStringList markedForDeletion() const; bool haveExpiringTotpCodes() const; - Q_INVOKABLE bool containsName(const QString) const; - // QAbstractItemModel Qt::ItemFlags flags(const QModelIndex&) const Q_DECL_OVERRIDE; QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE; @@ -95,7 +95,6 @@ public Q_SLOTS: void totpCodesExpired(); - void tokenRenamed(const QString, const QString); Q_SIGNALS: void yubiKeyIdChanged(); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyCard.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -83,7 +85,6 @@ // s(SignalName,signalName) #define PARENT_SIGNALS(s) \ s(YubiKeyId,yubiKeyId) \ - s(YubiKeySerial,yubiKeySerial) \ s(YubiKeyVersion,yubiKeyVersion) \ s(YubiKeyOtpList,yubiKeyOtpList) \ s(YubiKeyOtpData,yubiKeyOtpData) \ @@ -96,8 +97,7 @@ s(TotpTimeLeft,totpTimeLeft) \ s(TotpValid,totpValid) -class YubiKeyCard::Private : - public QObject +class YubiKeyCard::Private : public QObject { Q_OBJECT @@ -289,9 +289,6 @@ if (iYubiKey->otpListFetched()) { queueSignal(SignalOtpListFetchedChanged); } - if (!iYubiKey->yubiKeySerial()) { - queueSignal(SignalYubiKeySerialChanged); - } if (!iYubiKey->yubiKeyVersionString().isEmpty()) { queueSignal(SignalYubiKeyVersionChanged); } @@ -318,8 +315,7 @@ const bool totpWasValid = totpValid(); const int prevTotpTimeLeft = totpTimeLeft(); const int otpListWasFetched = otpListFetched(); - const uint prevSerial = iYubiKey ? iYubiKey->yubiKeySerial() : 0; - const uint prevVersion = iYubiKey ? iYubiKey->yubiKeyVersion() : 0; + const QByteArray prevVersion(iYubiKey ? iYubiKey->yubiKeyVersion() : QByteArray()); const QByteArray prevOtpList(iYubiKey ? iYubiKey->otpList() : QByteArray()); const QByteArray prevOtpData(iYubiKey ? iYubiKey->otpData() : QByteArray()); const QList<int> prevOperationIds(iYubiKey ? iYubiKey->operationIds() : QList<int>()); @@ -337,9 +333,6 @@ SIGNAL(yubiKeyReset()), SIGNAL(yubiKeyReset()))); HVERIFY(card->connect(iYubiKey, - SIGNAL(yubiKeySerialChanged()), - SIGNAL(yubiKeySerialChanged()))); - HVERIFY(card->connect(iYubiKey, SIGNAL(yubiKeyVersionChanged()), SIGNAL(yubiKeyVersionChanged()))); HVERIFY(card->connect(iYubiKey, @@ -382,9 +375,6 @@ SIGNAL(operationIdsChanged()), SIGNAL(operationIdsChanged()))); HVERIFY(card->connect(iYubiKey, - SIGNAL(tokenRenamed(QString,QString)), - SIGNAL(tokenRenamed(QString,QString)))); - HVERIFY(card->connect(iYubiKey, SIGNAL(operationFinished(int,bool)), SIGNAL(operationFinished(int,bool)))); HVERIFY(connect(iYubiKey, @@ -406,9 +396,6 @@ if (iYubiKey->otpListFetched() != otpListWasFetched) { queueSignal(SignalOtpListFetchedChanged); } - if (iYubiKey->yubiKeySerial() != prevSerial) { - queueSignal(SignalYubiKeySerialChanged); - } if (iYubiKey->yubiKeyVersion() != prevVersion) { queueSignal(SignalYubiKeyVersionChanged); } @@ -539,20 +526,8 @@ return iPrivate->iYubiKeyState; } -uint -YubiKeyCard::yubiKeySerial() const -{ - return iPrivate->iYubiKey ? iPrivate->iYubiKey->yubiKeySerial() : 0; -} - -uint -YubiKeyCard::yubiKeyVersion() const -{ - return iPrivate->iYubiKey ? iPrivate->iYubiKey->yubiKeyVersion() : 0; -} - QString -YubiKeyCard::yubiKeyVersionString() const +YubiKeyCard::yubiKeyVersion() const { return iPrivate->iYubiKey ? iPrivate->iYubiKey->yubiKeyVersionString() : @@ -611,41 +586,31 @@ YubiKeyCard::putToken( int aType, int aAlgorithm, - const QString aLabel, + const QString aName, const QString aSecret, int aDigits, int aCounter) { if (iPrivate->present()) { - const YubiKeyTokenType type = YubiKeyUtil::validType(aType); const YubiKeyAlgorithm alg = YubiKeyUtil::validAlgorithm(aAlgorithm); const QByteArray secret(HarbourBase32::fromBase32(aSecret)); - if (type != YubiKeyTokenType_Unknown && - alg != YubiKeyAlgorithm_Unknown && - !secret.isEmpty()) { - QList<YubiKeyToken> list; - - list.append(YubiKeyToken(type, alg, aLabel, QString(), - secret, aDigits, aCounter)); - return iPrivate->iYubiKey->putTokens(list); + if (alg != YubiKeyAlgorithm_Unknown && !secret.isEmpty()) { + YubiKey* key = iPrivate->iYubiKey; + + switch (aType) { + case YubiKeyTokenType_HOTP: + return key->putHotpToken(alg, aName, secret, aDigits, aCounter); + case YubiKeyTokenType_TOTP: + return key->putTotpToken(alg, aName, secret, aDigits); + case YubiKeyTokenType_Unknown: + break; + } } } return 0; } -int -YubiKeyCard::putTokens( - const QList<YubiKeyToken> aTokens) -{ - if (iPrivate->present()) { - return iPrivate->iYubiKey->putTokens(aTokens); - } else { - HDEBUG("Can't save tokens (YubiKey is not present)"); - return 0; - } -} - void YubiKeyCard::refreshTokens( const QStringList aList) @@ -664,20 +629,6 @@ } } -int -YubiKeyCard::renameToken( - const QString aFrom, - const QString aTo) -{ - if (iPrivate->present()) { - HDEBUG("Renaming" << aFrom << "=>" << aTo); - return iPrivate->iYubiKey->renameToken(aFrom, aTo); - } else { - HDEBUG("Can't rename token (YubiKey is not present)"); - return 0; - } -} - bool YubiKeyCard::submitPassword( const QString aPassword, @@ -693,7 +644,9 @@ { if (iPrivate->present()) { HDEBUG("Changing YubiKey password"); - return iPrivate->iYubiKey->setPassword(aPassword); + const int id = iPrivate->iYubiKey->setPassword(aPassword); + iPrivate->emitQueuedSignals(); + return id; } else { HDEBUG("Can't change password (YubiKey is not present)"); return 0; @@ -705,7 +658,9 @@ { if (iPrivate->present()) { HDEBUG("Resetting YubiKey"); - return iPrivate->iYubiKey->reset(); + const int id = iPrivate->iYubiKey->reset(); + iPrivate->emitQueuedSignals(); + return id; } else { HDEBUG("Can't reset (YubiKey is not present)"); return 0; | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyCard.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -36,8 +38,8 @@ #ifndef _YUBIKEY_CARD_H #define _YUBIKEY_CARD_H +#include "YubiKeyTypes.h" #include "YubiKeyConstants.h" -#include "YubiKeyToken.h" #include <QObject> #include <QString> @@ -49,9 +51,7 @@ Q_OBJECT Q_DISABLE_COPY(YubiKeyCard) Q_PROPERTY(QString yubiKeyId READ yubiKeyId WRITE setYubiKeyId NOTIFY yubiKeyIdChanged) - Q_PROPERTY(uint yubiKeySerial READ yubiKeySerial NOTIFY yubiKeySerialChanged) - Q_PROPERTY(uint yubiKeyVersion READ yubiKeyVersion NOTIFY yubiKeyVersionChanged) - Q_PROPERTY(QString yubiKeyVersionString READ yubiKeyVersionString NOTIFY yubiKeyVersionChanged) + Q_PROPERTY(QString yubiKeyVersion READ yubiKeyVersion NOTIFY yubiKeyVersionChanged) Q_PROPERTY(QString yubiKeyOtpList READ yubiKeyOtpList NOTIFY yubiKeyOtpListChanged) Q_PROPERTY(QString yubiKeyOtpData READ yubiKeyOtpData NOTIFY yubiKeyOtpDataChanged) Q_PROPERTY(YubiKeyState yubiKeyState READ yubiKeyState NOTIFY yubiKeyStateChanged) @@ -76,9 +76,7 @@ TypeUnknown = YubiKeyTokenType_Unknown, TypeHOTP = YubiKeyTokenType_HOTP, - TypeTOTP = YubiKeyTokenType_TOTP, - - Version_5_3_0 = 0x050300 + TypeTOTP = YubiKeyTokenType_TOTP }; enum YubiKeyState { @@ -99,9 +97,7 @@ void setYubiKeyId(const QString); QString yubiKeyId() const; - uint yubiKeySerial() const; - uint yubiKeyVersion() const; - QString yubiKeyVersionString() const; + QString yubiKeyVersion() const; QString yubiKeyOtpList() const; QString yubiKeyOtpData() const; YubiKeyState yubiKeyState() const; @@ -115,10 +111,8 @@ Q_INVOKABLE bool validOperationId(int); Q_INVOKABLE int putToken(int, int, const QString, const QString, int, int); - Q_INVOKABLE int putTokens(const QList<YubiKeyToken>); Q_INVOKABLE void refreshTokens(const QStringList); Q_INVOKABLE void deleteTokens(const QStringList); - Q_INVOKABLE int renameToken(const QString, const QString); Q_INVOKABLE bool submitPassword(const QString, bool); Q_INVOKABLE int setPassword(const QString); Q_INVOKABLE int reset(); @@ -126,7 +120,6 @@ Q_SIGNALS: void yubiKeyReset(); void yubiKeyIdChanged(); - void yubiKeySerialChanged(); void yubiKeyVersionChanged(); void yubiKeyOtpListChanged(); void yubiKeyOtpDataChanged(); @@ -142,7 +135,6 @@ void accessKeyNotAccepted(); void passwordChanged(); void passwordRemoved(); - void tokenRenamed(const QString from, const QString to); void operationFinished(int operationId, bool success); private: | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyRecognizer.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -276,7 +276,8 @@ // s(SignalName,signalName) #define YUBIKEY_RECOGNIZER_SIGNALS(s) \ - s(YubiKeyId,yubiKeyId) + s(YubiKeyVersion,yubiKeyVersion) \ + s(YubiKeyId,yubiKeyId) // Must be signalled after YubiKeyVersion class YubiKeyRecognizer::Private: public QObject @@ -315,6 +316,7 @@ public Q_SLOTS: void onTagStateChanged(); void onTagYubiKeyIdChanged(); + void onTagYubiKeyVersionChanged(); public: SignalMask iQueuedSignals; @@ -322,7 +324,9 @@ NfcDefaultAdapter* iAdapter; gulong iAdapterEventId; QByteArray iLastId; + QByteArray iLastVersion; QString iLastIdString; + QString iLastVersionString; Handler* iHandler; YubiKeyTag* iTag; }; @@ -434,6 +438,11 @@ iLastIdString.clear(); queueSignal(SignalYubiKeyIdChanged); } + if (!iLastVersion.isEmpty()) { + iLastVersion.clear(); + iLastVersionString.clear(); + queueSignal(SignalYubiKeyVersionChanged); + } emitQueuedSignals(emitSignal); } @@ -463,7 +472,11 @@ connect(iTag, SIGNAL(yubiKeyIdChanged()), SLOT(onTagYubiKeyIdChanged())); + connect(iTag, + SIGNAL(yubiKeyVersionChanged()), + SLOT(onTagYubiKeyVersionChanged())); updateYubiKeyId(); + updateYubiKeyVersion(); } } else { dropTag(); @@ -484,6 +497,19 @@ } void +YubiKeyRecognizer::Private::updateYubiKeyVersion() +{ + const QByteArray version(iTag->yubiKeyVersion()); + + if (!version.isEmpty() && version != iLastVersion) { + iLastVersion = version; + iLastVersionString = iTag->yubiKeyVersionString(); + HDEBUG(qPrintable(iLastVersionString)); + queueSignal(SignalYubiKeyVersionChanged); + } +} + +void YubiKeyRecognizer::Private::onTagStateChanged() { iHandler->handleTagStateChange(iTag); @@ -497,6 +523,13 @@ } void +YubiKeyRecognizer::Private::onTagYubiKeyVersionChanged() +{ + updateYubiKeyVersion(); + emitQueuedSignals(emitSignal); +} + +void YubiKeyRecognizer::Private::staticAdapterEvent( NfcDefaultAdapter* aAdapter, NFC_DEFAULT_ADAPTER_PROPERTY, @@ -533,6 +566,12 @@ return iPrivate->iLastIdString; } +QString +YubiKeyRecognizer::yubiKeyVersion() const +{ + return iPrivate->iLastVersionString; +} + void YubiKeyRecognizer::clearState() { | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyRecognizer.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -50,6 +50,7 @@ Q_OBJECT Q_DISABLE_COPY(YubiKeyRecognizer) Q_PROPERTY(QString yubiKeyId READ yubiKeyId NOTIFY yubiKeyIdChanged) + Q_PROPERTY(QString yubiKeyVersion READ yubiKeyVersion NOTIFY yubiKeyVersionChanged) public: explicit YubiKeyRecognizer(QObject* aParent = Q_NULLPTR); @@ -58,11 +59,13 @@ static QObject* createSingleton(QQmlEngine*, QJSEngine*); QString yubiKeyId() const; + QString yubiKeyVersion() const; Q_INVOKABLE void clearState(); Q_SIGNALS: void yubiKeyIdChanged(); + void yubiKeyVersionChanged(); private: class Adaptor; | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeySettings.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -45,20 +45,9 @@ #define DCONF_KEY(x) YUBIKEY_DCONF_ROOT x #define KEY_MAX_ZOOM DCONF_KEY("maxZoom") #define KEY_SCAN_ZOOM DCONF_KEY("scanZoom") -#define KEY_VOLUME_ZOOM DCONF_KEY("volumeZoom") -#define KEY_WIDE_SCAN DCONF_KEY("wideScan") -#define KEY_RESOLUTION_4_3 DCONF_KEY("resolution_4_3") // Width is stored -#define KEY_RESOLUTION_16_9 DCONF_KEY("resolution_16_9") // Width is stored #define DEFAULT_MAX_ZOOM 10.f #define DEFAULT_SCAN_ZOOM 3.f -#define DEFAULT_VOLUME_ZOOM true -#define DEFAULT_WIDE_SCAN false - -// Camera configuration (got removed at some point) -#define CAMERA_DCONF_PATH_(x) "/apps/jolla-camera/primary/image/" x -#define CAMERA_DCONF_RESOLUTION_4_3 CAMERA_DCONF_PATH_("viewfinderResolution_4_3") -#define CAMERA_DCONF_RESOLUTION_16_9 CAMERA_DCONF_PATH_("viewfinderResolution_16_9") // ========================================================================== // YubiKeySettings::Private @@ -69,89 +58,21 @@ public: Private(YubiKeySettings* aParent); - static QSize toSize(const QVariant); - static QSize size_4_3(int); - static QSize size_16_9(int); - - QSize resolution_4_3(); - QSize resolution_16_9(); + static int validateQrCodeEcLevel(int aValue); public: - const int iDefaultResolution_4_3; - const int iDefaultResolution_16_9; MGConfItem* iMaxZoom; MGConfItem* iScanZoom; - MGConfItem* iVolumeZoom; - MGConfItem* iWideScan; - MGConfItem* iResolution_4_3; - MGConfItem* iResolution_16_9; }; YubiKeySettings::Private::Private(YubiKeySettings* aParent) : - iDefaultResolution_4_3(toSize(MGConfItem(CAMERA_DCONF_RESOLUTION_4_3).value()).width()), - iDefaultResolution_16_9(toSize(MGConfItem(CAMERA_DCONF_RESOLUTION_16_9).value()).width()), iMaxZoom(new MGConfItem(KEY_MAX_ZOOM, aParent)), - iScanZoom(new MGConfItem(KEY_SCAN_ZOOM, aParent)), - iVolumeZoom(new MGConfItem(KEY_VOLUME_ZOOM, aParent)), - iWideScan(new MGConfItem(KEY_WIDE_SCAN, aParent)), - iResolution_4_3(new MGConfItem(KEY_RESOLUTION_4_3, aParent)), - iResolution_16_9(new MGConfItem(KEY_RESOLUTION_16_9, aParent)) -{ - connect(iMaxZoom, SIGNAL(valueChanged()), aParent, SIGNAL(maxZoomChanged())); - connect(iScanZoom, SIGNAL(valueChanged()), aParent, SIGNAL(scanZoomChanged())); - connect(iVolumeZoom, SIGNAL(valueChanged()), aParent, SIGNAL(volumeZoomChanged())); - connect(iWideScan, SIGNAL(valueChanged()), aParent, SIGNAL(wideScanChanged())); - connect(iResolution_4_3, SIGNAL(valueChanged()), aParent, SIGNAL(wideCameraResolutionChanged())); - connect(iResolution_16_9, SIGNAL(valueChanged()), aParent, SIGNAL(narrowCameraResolutionChanged())); - HDEBUG("Default 4:3 resolution" << size_4_3(iDefaultResolution_4_3)); - HDEBUG("Default 16:9 resolution" << size_16_9(iDefaultResolution_16_9)); -} - -QSize -YubiKeySettings::Private::toSize( - const QVariant aVariant) -{ - // e.g. "1920x1080" - if (aVariant.isValid()) { - const QStringList values(aVariant.toString().split('x')); - if (values.count() == 2) { - bool ok = false; - int width = values.at(0).toInt(&ok); - if (ok && width > 0) { - int height = values.at(1).toInt(&ok); - if (ok && height > 0) { - return QSize(width, height); - } - } - } - } - return QSize(0, 0); -} - -QSize -YubiKeySettings::Private::size_4_3( - int aWidth) -{ - return QSize(aWidth, aWidth * 3 / 4); -} - -QSize -YubiKeySettings::Private::size_16_9( - int aWidth) -{ - return QSize(aWidth, aWidth * 9 / 16); -} - -QSize -YubiKeySettings::Private::resolution_4_3() -{ - return size_4_3(qMax(iResolution_4_3->value(iDefaultResolution_4_3).toInt(), 0)); -} - -QSize -YubiKeySettings::Private::resolution_16_9() + iScanZoom(new MGConfItem(KEY_SCAN_ZOOM, aParent)) { - return size_16_9(qMax(iResolution_16_9->value(iDefaultResolution_16_9).toInt(), 0)); + QObject::connect(iMaxZoom, SIGNAL(valueChanged()), + aParent, SIGNAL(maxZoomChanged())); + QObject::connect(iScanZoom, SIGNAL(valueChanged()), + aParent, SIGNAL(scanZoomChanged())); } // ========================================================================== @@ -209,80 +130,3 @@ HDEBUG(aValue); iPrivate->iMaxZoom->set(aValue); } - -// volumeZoom - -bool -YubiKeySettings::volumeZoom() const -{ - return iPrivate->iVolumeZoom->value(DEFAULT_VOLUME_ZOOM).toBool(); -} - -void -YubiKeySettings::setVolumeZoom( - bool aValue) -{ - HDEBUG(aValue); - iPrivate->iVolumeZoom->set(aValue); -} - -// wideScan - -bool -YubiKeySettings::wideScan() const -{ - return iPrivate->iWideScan->value(DEFAULT_WIDE_SCAN).toBool(); -} - -void -YubiKeySettings::setWideScan( - bool aValue) -{ - iPrivate->iWideScan->set(aValue); -} - -// wideCameraRatio - -qreal -YubiKeySettings::wideCameraRatio() const -{ - return 4./3; -} - -// wideCameraResolution - -QSize -YubiKeySettings::wideCameraResolution() const -{ - return iPrivate->resolution_4_3(); -} - -void -YubiKeySettings::setWideCameraResolution( - QSize aSize) -{ - HDEBUG(aSize); - iPrivate->iResolution_4_3->set(aSize.width()); -} - -// narrowCameraRatio - -qreal -YubiKeySettings::narrowCameraRatio() const -{ - return 16./9; -} - -QSize -YubiKeySettings::narrowCameraResolution() const -{ - return iPrivate->resolution_16_9(); -} - -void -YubiKeySettings::setNarrowCameraResolution( - QSize aSize) -{ - HDEBUG(aSize); - iPrivate->iResolution_16_9->set(aSize.width()); -} | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeySettings.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -39,7 +39,6 @@ #define _YUBIKEY_SETTINGS_H #include <QObject> -#include <QSize> class QQmlEngine; class QJSEngine; @@ -51,12 +50,6 @@ Q_DISABLE_COPY(YubiKeySettings) Q_PROPERTY(qreal scanZoom READ scanZoom WRITE setScanZoom NOTIFY scanZoomChanged) Q_PROPERTY(qreal maxZoom READ maxZoom WRITE setMaxZoom NOTIFY maxZoomChanged) - Q_PROPERTY(bool volumeZoom READ volumeZoom WRITE setVolumeZoom NOTIFY volumeZoomChanged) - Q_PROPERTY(bool wideScan READ wideScan WRITE setWideScan NOTIFY wideScanChanged) - Q_PROPERTY(qreal wideCameraRatio READ wideCameraRatio CONSTANT) - Q_PROPERTY(qreal narrowCameraRatio READ narrowCameraRatio CONSTANT) - Q_PROPERTY(QSize wideCameraResolution READ wideCameraResolution WRITE setWideCameraResolution NOTIFY wideCameraResolutionChanged) - Q_PROPERTY(QSize narrowCameraResolution READ narrowCameraResolution WRITE setNarrowCameraResolution NOTIFY narrowCameraResolutionChanged) public: explicit YubiKeySettings(QObject* aParent = Q_NULLPTR); @@ -71,27 +64,9 @@ qreal maxZoom() const; void setMaxZoom(qreal); - bool volumeZoom() const; - void setVolumeZoom(bool); - - bool wideScan() const; - void setWideScan(bool); - - qreal wideCameraRatio() const; - QSize wideCameraResolution() const; - void setWideCameraResolution(QSize); - - qreal narrowCameraRatio() const; - QSize narrowCameraResolution() const; - void setNarrowCameraResolution(QSize); - Q_SIGNALS: void maxZoomChanged(); void scanZoomChanged(); - void volumeZoomChanged(); - void wideScanChanged(); - void wideCameraResolutionChanged(); - void narrowCameraResolutionChanged(); private: class Private; | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyTag.cpp ^ |
@@ -94,7 +94,6 @@ #define YUBIKEY_TAG_SIGNALS(s) \ s(TagState,tagState) \ s(OperationIds,operationIds) \ - s(YubiKeySerial,yubiKeySerial) \ s(YubiKeyVersion,yubiKeyVersion) \ s(YubiKeyAuthChallenge,yubiKeyAuthChallenge) \ s(YubiKeyAuthAlgorithm,yubiKeyAuthAlgorithm) \ @@ -354,7 +353,6 @@ void updateYubiKeyVersion(const QByteArray); void updateYubiKeyAuthChallenge(const QByteArray); void updateYubiKeyAuthAlgorithm(YubiKeyAlgorithm); - void updateYubiKeySerial(); void ref(); void unref(); @@ -377,7 +375,6 @@ YubiKeyAlgorithm iYubiKeyAuthAlgorithm; QString iYubiKeyIdString; QString iYubiKeyVersionString; - uint iSerial; NfcTagClient* iTag; NfcIsoDepClient* iIsoDep; GCancellable* iCancel; @@ -401,7 +398,6 @@ iQueuedSignals(0), iFirstQueuedSignal(SignalCount), iYubiKeyAuthAlgorithm(YubiKeyAlgorithm_Unknown), - iSerial(0), iIsoDep(Q_NULLPTR), iCancel(Q_NULLPTR), iIsoDepEventId(0), @@ -587,7 +583,6 @@ iYubiKeyIdString = YubiKeyUtil::toHex(aId); HDEBUG(qPrintable(iYubiKeyIdString)); queueSignal(SignalYubiKeyIdChanged); - updateYubiKeySerial(); } } @@ -626,46 +621,6 @@ } void -YubiKeyTag::Private::updateYubiKeySerial() -{ - uint serial = 0; - - if (iTag->valid && iTag->present && !iYubiKeyId.isEmpty()) { - const GUtilData* nfcid1 = nfc_tag_client_poll_param(iTag, - NFC_TAG_POLL_PARAM_NFCID1); - - if (nfcid1) { - // https://docs.yubico.com/hardware/yubikey/yk-5/tech-manual/yk5-nfc-id-tech-desc.html - // serial_0 is the most significant byte - if (nfcid1->size == 7 && nfcid1->bytes[0] == 0x27) { - if (nfcid1->bytes[1] == 0 && nfcid1->bytes[2] == 0) { - // YubiKey 5.2.x and lower versions - // 0x27 0 0 serial_3 serial_2 serial_1 serial_0 - serial = (uint)nfcid1->bytes[3] + - (((uint)nfcid1->bytes[4]) << 8) + - (((uint)nfcid1->bytes[5]) << 16) + - (((uint)nfcid1->bytes[6]) << 24); - } else if (nfcid1->bytes[1] == nfcid1->bytes[6] && - nfcid1->bytes[2] == nfcid1->bytes[5]) { - // YubiKey v5.3.0 and Above - // 0x27 serial_3 serial_2 serial_1 serial_0 serial_2 serial_3 - serial = (uint)nfcid1->bytes[1] + - (((uint)nfcid1->bytes[2]) << 8) + - (((uint)nfcid1->bytes[3]) << 16) + - (((uint)nfcid1->bytes[4]) << 24); - } - } - } - } - - if (iSerial != serial) { - HDEBUG(serial); - iSerial = serial; - queueSignal(SignalYubiKeySerialChanged); - } -} - -void YubiKeyTag::Private::tagEvent( NfcTagClient*, NFC_TAG_PROPERTY, @@ -694,7 +649,6 @@ void YubiKeyTag::Private::updateTagState() { - updateYubiKeySerial(); if (iTag->valid) { if (iTag->present) { if (gutil_strv_contains(iTag->interfaces, NFC_TAG_INTERFACE_ISODEP)) { @@ -1320,7 +1274,7 @@ YubiKeyTag::Operation::lockFailed( const GError* aError) { - GERR("%s", GERRMSG(aError)); + GERR(GERRMSG(aError)); } void @@ -1587,12 +1541,6 @@ return iPrivate->iYubiKeyAuthAlgorithm; } -uint -YubiKeyTag::yubiKeySerial() const -{ - return iPrivate->iSerial; -} - bool YubiKeyTag::hasAuthChallenge() const { | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyTag.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -88,10 +90,10 @@ virtual bool startOperation() = 0; // Locked and selected virtual void operationCancelled(); virtual void operationFailed(); - virtual void finished(bool aSuccess = true); bool transmit(const NfcIsoDepApdu*); bool transmit(const NfcIsoDepApdu*, TransmitDone); + void finished(bool aSuccess = true); public: class Private; @@ -113,7 +115,6 @@ const QByteArray yubiKeyVersion() const; const QByteArray yubiKeyAuthChallenge() const; YubiKeyAlgorithm yubiKeyAuthAlgorithm() const; - uint yubiKeySerial() const; bool hasAuthChallenge() const; const QList<int> operationIds() const; @@ -133,7 +134,6 @@ void yubiKeyVersionChanged(); void yubiKeyAuthChallengeChanged(); void yubiKeyAuthAlgorithmChanged(); - void yubiKeySerialChanged(); void operationIdsChanged(); void operationFinished(int, bool); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyUtil.cpp ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,31 +8,35 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing * any official policies, either expressed or implied. */ +#include "foil_util.h" + #include "gutil_misc.h" #include "YubiKeyDefs.h" @@ -42,12 +46,41 @@ #include "HarbourBase32.h" #include "HarbourDebug.h" +#include <QUrl> #include <QStandardPaths> -#include <QCryptographicHash> -const QString YubiKeyUtil::ALGORITHM_SHA1("SHA1"); -const QString YubiKeyUtil::ALGORITHM_SHA256("SHA256"); -const QString YubiKeyUtil::ALGORITHM_SHA512("SHA512"); +#define TOKEN_TYPE_TOTP "totp" +#define TOKEN_TYPE_HOTP "hotp" + +#define TOKEN_ALGORITHM_SHA1 "SHA1" +#define TOKEN_ALGORITHM_SHA256 "SHA256" +#define TOKEN_ALGORITHM_SHA512 "SHA512" + +#define TOKEN_KEY_TYPE "type" +#define TOKEN_KEY_LABEL "label" +#define TOKEN_KEY_SECRET "secret" +#define TOKEN_KEY_ISSUER "issuer" +#define TOKEN_KEY_DIGITS "digits" +#define TOKEN_KEY_COUNTER "counter" +#define TOKEN_KEY_ALGORITHM "algorithm" + +const QString YubiKeyUtil::KEY_VALID("valid"); +const QString YubiKeyUtil::KEY_TYPE(TOKEN_KEY_TYPE); +const QString YubiKeyUtil::KEY_LABEL(TOKEN_KEY_LABEL); +const QString YubiKeyUtil::KEY_SECRET(TOKEN_KEY_SECRET); +const QString YubiKeyUtil::KEY_ISSUER(TOKEN_KEY_ISSUER); +const QString YubiKeyUtil::KEY_DIGITS(TOKEN_KEY_DIGITS); +const QString YubiKeyUtil::KEY_COUNTER(TOKEN_KEY_COUNTER); +const QString YubiKeyUtil::KEY_ALGORITHM(TOKEN_KEY_ALGORITHM); + +const QString YubiKeyUtil::TYPE_TOTP(TOKEN_TYPE_TOTP); +const QString YubiKeyUtil::TYPE_HOTP(TOKEN_TYPE_HOTP); + +const QString YubiKeyUtil::ALGORITHM_SHA1(TOKEN_ALGORITHM_SHA1); +const QString YubiKeyUtil::ALGORITHM_SHA256(TOKEN_ALGORITHM_SHA256); +const QString YubiKeyUtil::ALGORITHM_SHA512(TOKEN_ALGORITHM_SHA512); + +#define OTPAUTH_SCHEME "otpauth" QDir YubiKeyUtil::configDir() @@ -64,38 +97,6 @@ } QString -YubiKeyUtil::hashUtf8( - const QByteArray& aUtf8) -{ - return QCryptographicHash::hash(aUtf8, QCryptographicHash::Sha1).toHex(); -} - -QString -YubiKeyUtil::steamHashUtf8( - const QByteArray& aUtf8) -{ - // The same name gets a different hash for Steam and Favorite purposes - static QByteArray STEAM_PREFIX("steam:"); - QCryptographicHash hash(QCryptographicHash::Sha1); - hash.addData(STEAM_PREFIX); - hash.addData(aUtf8); - return hash.result().toHex(); -} - -uint -YubiKeyUtil::versionToNumber( - const uchar* aData, - gsize aSize) -{ - // The version is typically 3 bytes long - uint v = 0; - for (gsize i = 0; i < aSize; i++) { - v = (v << 8) | aData[i]; - } - return v; -} - -QString YubiKeyUtil::versionToString( const uchar* aData, gsize aSize) @@ -297,19 +298,6 @@ return YubiKeyAlgorithm_Unknown; } -YubiKeyTokenType -YubiKeyUtil::validType( - int aValue) -{ - switch (aValue) { - case YubiKeyTokenType_Unknown: break; - case YubiKeyTokenType_HOTP: // fallthrough - case YubiKeyTokenType_TOTP: // fallthrough - return (YubiKeyTokenType)aValue; - } - return YubiKeyTokenType_Unknown; -} - bool YubiKeyUtil::isValidBase32( const QString aBase32) @@ -317,6 +305,117 @@ return HarbourBase32::isValidBase32(aBase32); } +QVariantMap +YubiKeyUtil::parseOtpAuthUri( + const QString aUri) +{ + const QByteArray uri(aUri.trimmed().toUtf8()); + QVariantMap result; + FoilParsePos pos; + + pos.ptr = (guint8*)uri.constData(); + pos.end = pos.ptr + uri.size(); + + // Check scheme + type prefix + FoilBytes prefixBytes; + + foil_bytes_from_string(&prefixBytes, OTPAUTH_SCHEME "://" + TOKEN_TYPE_TOTP "/"); + + if (foil_parse_skip_bytes(&pos, &prefixBytes)) { + result.insert(KEY_TYPE, YubiKeyTokenType_TOTP); + } else { + foil_bytes_from_string(&prefixBytes, OTPAUTH_SCHEME "://" + TOKEN_TYPE_HOTP "/"); + if (foil_parse_skip_bytes(&pos, &prefixBytes)) { + result.insert(KEY_TYPE, YubiKeyTokenType_HOTP); + } + } + + if (!result.isEmpty()) { + QByteArray label, secret, issuer, algorithm, digits, counter; + + while (pos.ptr < pos.end && pos.ptr[0] != '?') { + label.append(*pos.ptr++); + } + + FoilBytes secretTag; + FoilBytes issuerTag; + FoilBytes digitsTag; + FoilBytes counterTag; + FoilBytes algorithmTag; + + foil_bytes_from_string(&secretTag, TOKEN_KEY_SECRET "="); + foil_bytes_from_string(&issuerTag, TOKEN_KEY_ISSUER "="); + foil_bytes_from_string(&digitsTag, TOKEN_KEY_DIGITS "="); + foil_bytes_from_string(&counterTag, TOKEN_KEY_COUNTER "="); + foil_bytes_from_string(&algorithmTag, TOKEN_KEY_ALGORITHM "="); + + while (pos.ptr < pos.end) { + pos.ptr++; + + QByteArray* value = + foil_parse_skip_bytes(&pos, &secretTag) ? &secret : + foil_parse_skip_bytes(&pos, &issuerTag) ? &issuer : + foil_parse_skip_bytes(&pos, &digitsTag) ? &digits : + foil_parse_skip_bytes(&pos, &counterTag) ? &counter : + foil_parse_skip_bytes(&pos, &algorithmTag) ? &algorithm : + Q_NULLPTR; + + if (value) { + value->truncate(0); + while (pos.ptr < pos.end && pos.ptr[0] != '&') { + value->append(*pos.ptr++); + } + } else { + while (pos.ptr < pos.end && pos.ptr[0] != '&') { + pos.ptr++; + } + } + } + + if (!secret.isEmpty()) { + const QByteArray bytes(HarbourBase32::fromBase32(QUrl::fromPercentEncoding(secret))); + + if (!bytes.isEmpty()) { + const int alg = algorithm.isEmpty() ? YubiKeyAlgorithm_Default : + algorithmFromName(QString::fromLatin1(algorithm)); + + if (alg != YubiKeyAlgorithm_Unknown) { + int dig = DefaultDigits; + + if (!digits.isEmpty()) { + bool ok; + const int n = digits.toInt(&ok); + + if (ok && n >= MinDigits && n <= MaxDigits) { + dig = n; + } + } + + if (!counter.isEmpty()) { + bool ok; + const quint64 n = counter.toULongLong(&ok); + + if (ok) { + result.insert(KEY_COUNTER, n); + } + } + + result.insert(KEY_VALID, true); + result.insert(KEY_DIGITS, dig); + result.insert(KEY_ALGORITHM, alg); + result.insert(KEY_SECRET, HarbourBase32::toBase32(bytes)); + result.insert(KEY_LABEL, QUrl::fromPercentEncoding(label)); + result.insert(KEY_ISSUER, QUrl::fromPercentEncoding(issuer)); + return result; + } + } + } + } + return QVariantMap(); +} + QObject* YubiKeyUtil::createSingleton( QQmlEngine*, | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/YubiKeyUtil.h ^ |
@@ -1,6 +1,6 @@ /* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich <slava@monich.com> * * You may use this file under the terms of the BSD license as follows: * @@ -8,25 +8,27 @@ * modification, are permitted provided that the following conditions * are met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing @@ -38,12 +40,13 @@ #include "foil_types.h" -#include "YubiKeyToken.h" +#include "YubiKeyTypes.h" #include <QByteArray> #include <QDir> #include <QString> #include <QObject> +#include <QVariantMap> class QQmlEngine; class QJSEngine; @@ -57,12 +60,23 @@ public: enum Constants { - // To expose these to QML: - DefaultDigits = YubiKeyToken::DefaultDigits, - MinDigits = YubiKeyToken::MinDigits, - MaxDigits = YubiKeyToken::MaxDigits + DefaultDigits = 6, + MinDigits = 6, + MaxDigits = 8 }; + static const QString KEY_VALID; // valid + static const QString KEY_TYPE; // type + static const QString KEY_LABEL; // label + static const QString KEY_SECRET; // secret + static const QString KEY_ISSUER; // issuer + static const QString KEY_DIGITS; // digits + static const QString KEY_COUNTER; // counter + static const QString KEY_ALGORITHM; // algorithm + + static const QString TYPE_TOTP; + static const QString TYPE_HOTP; + static const QString ALGORITHM_SHA1; static const QString ALGORITHM_SHA256; static const QString ALGORITHM_SHA512; @@ -70,17 +84,6 @@ static QDir configDir(); static QDir configDir(const QByteArray); - static QString hashUtf8(const QByteArray&); - static QString steamHashUtf8(const QByteArray&); - static QString steamNameHash(const QString& aName) - { return steamHashUtf8(aName.toUtf8()); } - static QString nameHash(const QString& aName) - { return hashUtf8(aName.toUtf8()); } - - static uint versionToNumber(const uchar*, gsize); - static inline uint versionToNumber(const QByteArray& aData) - { return versionToNumber((uchar*)aData.constData(), aData.size()); } - static QString versionToString(const uchar*, gsize); static inline QString versionToString(const QByteArray& aData) { return versionToString((uchar*)aData.constData(), aData.size()); } @@ -106,9 +109,8 @@ static YubiKeyAlgorithm algorithmFromValue(uchar); static YubiKeyAlgorithm validAlgorithm(int); - static YubiKeyTokenType validType(int); - Q_INVOKABLE static bool isValidBase32(const QString); + Q_INVOKABLE static QVariantMap parseOtpAuthUri(const QString); // Callback for qmlRegisterSingletonType<YubiKeyUtil> static QObject* createSingleton(QQmlEngine*, QJSEngine*); | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/src/main.cpp ^ |
@@ -38,7 +38,6 @@ #include "YubiKeyAuthListModel.h" #include "YubiKeyCard.h" #include "YubiKeyDefs.h" -#include "YubiKeyImportModel.h" #include "YubiKeyRecognizer.h" #include "YubiKeySettings.h" #include "YubiKeyUtil.h" @@ -48,10 +47,12 @@ #include "NfcAdapter.h" #include "NfcMode.h" #include "NfcSystem.h" +#include "NfcTag.h" #include "HarbourDebug.h" #include "HarbourTheme.h" #include "HarbourSingleImageProvider.h" +#include "HarbourSystemInfo.h" #include "gutil_log.h" @@ -71,6 +72,7 @@ qmlRegisterUncreatableType<Class>(uri, v1, v2, #Class, \ QString()) + REGISTER_SINGLETON_TYPE(uri, v1, v2, HarbourSystemInfo); REGISTER_SINGLETON_TYPE(uri, v1, v2, NfcAdapter); REGISTER_SINGLETON_TYPE(uri, v1, v2, NfcSystem); REGISTER_SINGLETON_TYPE(uri, v1, v2, YubiKeyRecognizer); @@ -78,9 +80,9 @@ REGISTER_SINGLETON_TYPE(uri, v1, v2, YubiKeyUtil); REGISTER_TYPE(uri, v1, v2, HarbourSingleImageProvider); REGISTER_TYPE(uri, v1, v2, NfcMode); + REGISTER_TYPE(uri, v1, v2, NfcTag); REGISTER_TYPE(uri, v1, v2, YubiKeyCard); REGISTER_TYPE(uri, v1, v2, YubiKeyAuthListModel); - REGISTER_TYPE(uri, v1, v2, YubiKeyImportModel); REGISTER_TYPE(uri, v1, v2, QrCodeScanner); } | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/translations/harbour-yubikey-ru.ts ^ |
@@ -48,15 +48,10 @@ <extracomment>Pulley menu item</extracomment> <translation>Убрать пароль</translation> </message> - <message id="yubikey-menu-edit"> - <source>Edit</source> - <extracomment>Generic menu item</extracomment> - <translation>Изменить</translation> - </message> - <message id="yubikey-menu-rename"> - <source>Rename</source> - <extracomment>Generic menu item</extracomment> - <translation>Переименовать</translation> + <message id="yubikey-menu-copy_password"> + <source>Copy password</source> + <extracomment>Context menu item (copy password to clipboard)</extracomment> + <translation>Скопировать пароль</translation> </message> <message id="yubikey-menu-delete"> <source>Delete</source> @@ -83,16 +78,6 @@ <extracomment>Context menu item</extracomment> <translation>Убрать с обложки</translation> </message> - <message id="yubikey-menu-use_as_standard_token"> - <source>Standard token</source> - <extracomment>Context menu item</extracomment> - <translation>Стандартный пароль</translation> - </message> - <message id="yubikey-menu-use_as_steam_token"> - <source>Steam token</source> - <extracomment>Context menu item</extracomment> - <translation>Пароль Steam</translation> - </message> <message id="yubikey-status-waiting_to_reset"> <source>Touch the same YubiKey to reset it</source> <extracomment>Status label</extracomment> @@ -123,11 +108,6 @@ <extracomment>Card info label</extracomment> <translation>Версия: %1</translation> </message> - <message id="yubikey-info-serial"> - <source>Serial: %1</source> - <extracomment>Card info label</extracomment> - <translation>Серийный номер: %1</translation> - </message> <message id="yubikey-info-no_creds"> <source>No credentials are stored on this YubiKey</source> <extracomment>Card info label</extracomment> @@ -198,11 +178,6 @@ <extracomment>Status label</extracomment> <translation>Поднесите тот же самый YubiKey для записи кода</translation> </message> - <message id="yubikey-wait-put_selected_tokens"> - <source>Touch YubiKey to save the selected tokens</source> - <extracomment>Status label</extracomment> - <translation>Поднесите тот же самый YubiKey для записи выбранных кодов</translation> - </message> <message id="yubikey-add_token-save"> <source>Save</source> <extracomment>Dialog button</extracomment> @@ -254,9 +229,9 @@ <translation>%1 (по умолчанию)</translation> </message> <message id="yubikey-token-digits-text"> - <source>Digits (leave it 6 for Steam tokens)</source> + <source>Digits</source> <extracomment>Text field label (number of password digits)</extracomment> - <translation>Длина пароля (оставьте 6 для паролей Steam)</translation> + <translation>Длина пароля</translation> </message> <message id="yubikey-token-digits-placeholder"> <source>Number of password digits</source> @@ -311,7 +286,7 @@ <message id="yubikey-scan-title"> <source>Scan QR code</source> <extracomment>Page title (suggestion to scan QR code)</extracomment> - <translation>Отсканируйте QR-код</translation> + <translation>Отсканировать QR-код</translation> </message> <message id="yubikey-scan-zoom_label"> <source>Zoom</source> @@ -333,35 +308,5 @@ <extracomment>Warning text</extracomment> <translation>Сброс YubiKey безвозвратно уничтожает все коды, которые в нём хранились. Всё будет утеряно навсегда, восстановить ничего не получится. Вы уверены, что действительно этого хотите?</translation> </message> - <message id="yubikey-select_dialog-title"> - <source>Select tokens</source> - <extracomment>Dialog title</extracomment> - <translation>Выберите коды для записи на ключ</translation> - </message> - <message id="yubikey-rename_token-prompt"> - <source>Enter new name for %1</source> - <extracomment>Input prompt to rename the token</extracomment> - <translation>Введите новое имя вместо %1</translation> - </message> - <message id="yubikey-rename_token-placeholder"> - <source>Enter new name</source> - <extracomment>Placeholder for the new token name</extracomment> - <translation>Введите новое имя</translation> - </message> - <message id="yubikey-rename_token-duplicate_name"> - <source>Duplicate name</source> - <extracomment>Label for a duplicate token name</extracomment> - <translation>Такое имя уже есть</translation> - </message> - <message id="yubikey-rename_token-button"> - <source>Rename</source> - <extracomment>Button label (rename token)</extracomment> - <translation>Переименовать</translation> - </message> - <message id="yubikey-wait-rename_token"> - <source>Touch the same YubiKey to rename the token</source> - <extracomment>Status label</extracomment> - <translation>Поднесите тот же самый YubiKey для сохранения изменений</translation> - </message> </context> </TS> | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/translations/harbour-yubikey-sv.ts ^ |
@@ -48,15 +48,10 @@ <extracomment>Pulley menu item</extracomment> <translation>Ta bort lösenord</translation> </message> - <message id="yubikey-menu-edit"> - <source>Edit</source> - <extracomment>Generic menu item</extracomment> - <translation>Redigera</translation> - </message> - <message id="yubikey-menu-rename"> - <source>Rename</source> - <extracomment>Generic menu item</extracomment> - <translation>Byt namn</translation> + <message id="yubikey-menu-copy_password"> + <source>Copy password</source> + <extracomment>Context menu item (copy password to clipboard)</extracomment> + <translation>Kopiera lösenord</translation> </message> <message id="yubikey-menu-delete"> <source>Delete</source> @@ -83,16 +78,6 @@ <extracomment>Context menu item</extracomment> <translation>Ta bort från programminiatyr</translation> </message> - <message id="yubikey-menu-use_as_standard_token"> - <source>Standard token</source> - <extracomment>Context menu item</extracomment> - <translation type="unfinished">Standard token</translation> - </message> - <message id="yubikey-menu-use_as_steam_token"> - <source>Steam token</source> - <extracomment>Context menu item</extracomment> - <translation type="unfinished">Steam-token</translation> - </message> <message id="yubikey-status-waiting_to_reset"> <source>Touch the same YubiKey to reset it</source> <extracomment>Status label</extracomment> @@ -123,11 +108,6 @@ <extracomment>Card info label</extracomment> <translation>Version: %1</translation> </message> - <message id="yubikey-info-serial"> - <source>Serial: %1</source> - <extracomment>Card info label</extracomment> - <translation>Serienummer: %1</translation> - </message> <message id="yubikey-info-no_creds"> <source>No credentials are stored on this YubiKey</source> <extracomment>Card info label</extracomment> @@ -198,11 +178,6 @@ <extracomment>Status label</extracomment> <translation>Håll telefonen mot YubiKey för att spara token</translation> </message> - <message id="yubikey-wait-put_selected_tokens"> - <source>Touch YubiKey to save the selected tokens</source> - <extracomment>Status label</extracomment> - <translation>Håll telefonen mot YubiKey för att spara de valda tokens</translation> - </message> <message id="yubikey-add_token-save"> <source>Save</source> <extracomment>Dialog button</extracomment> @@ -254,9 +229,9 @@ <translation>%1 (standard)</translation> </message> <message id="yubikey-token-digits-text"> - <source>Digits (leave it 6 for Steam tokens)</source> + <source>Digits</source> <extracomment>Text field label (number of password digits)</extracomment> - <translation type="unfinished">Siffror (låt det vara 6 för Steam-tokens)</translation> + <translation>Siffror</translation> </message> <message id="yubikey-token-digits-placeholder"> <source>Number of password digits</source> @@ -333,35 +308,5 @@ <extracomment>Warning text</extracomment> <translation>Återställning av din YubiKey tar irreversibelt bort alla hemligheter som lagras i den. Den här åtgärden kan inte ångras. Är du säker på att du verkligen vill göra det?</translation> </message> - <message id="yubikey-select_dialog-title"> - <source>Select tokens</source> - <extracomment>Dialog title</extracomment> - <translation>Välj token</translation> - </message> - <message id="yubikey-rename_token-prompt"> - <source>Enter new name for %1</source> - <extracomment>Input prompt to rename the token</extracomment> - <translation>Ange ett nytt namn för %1</translation> - </message> - <message id="yubikey-rename_token-placeholder"> - <source>Enter new name</source> - <extracomment>Placeholder for the new token name</extracomment> - <translation>Ange nytt namn</translation> - </message> - <message id="yubikey-rename_token-duplicate_name"> - <source>Duplicate name</source> - <extracomment>Label for a duplicate token name</extracomment> - <translation>Dubblettnamn</translation> - </message> - <message id="yubikey-rename_token-button"> - <source>Rename</source> - <extracomment>Button label (rename token)</extracomment> - <translation>Byt namn</translation> - </message> - <message id="yubikey-wait-rename_token"> - <source>Touch the same YubiKey to rename the token</source> - <extracomment>Status label</extracomment> - <translation>Håll telefonen mot samma YubiKey för att byta namn på token</translation> - </message> </context> </TS> | ||
[-] [+] | Changed | _service:tar_git:harbour-yubikey-1.0.3.tar.gz/translations/harbour-yubikey.ts ^ |
@@ -48,15 +48,10 @@ <extracomment>Pulley menu item</extracomment> <translation>Clear password</translation> </message> - <message id="yubikey-menu-edit"> - <source>Edit</source> - <extracomment>Generic menu item</extracomment> - <translation>Edit</translation> - </message> - <message id="yubikey-menu-rename"> - <source>Rename</source> - <extracomment>Generic menu item</extracomment> - <translation>Rename</translation> + <message id="yubikey-menu-copy_password"> + <source>Copy password</source> + <extracomment>Context menu item (copy password to clipboard)</extracomment> + <translation>Copy password</translation> </message> <message id="yubikey-menu-delete"> <source>Delete</source> @@ -83,16 +78,6 @@ <extracomment>Context menu item</extracomment> <translation>Remove from cover</translation> </message> - <message id="yubikey-menu-use_as_standard_token"> - <source>Standard token</source> - <extracomment>Context menu item</extracomment> - <translation>Standard token</translation> - </message> - <message id="yubikey-menu-use_as_steam_token"> - <source>Steam token</source> - <extracomment>Context menu item</extracomment> - <translation>Steam token</translation> - </message> <message id="yubikey-status-waiting_to_reset"> <source>Touch the same YubiKey to reset it</source> <extracomment>Status label</extracomment> @@ -123,11 +108,6 @@ <extracomment>Card info label</extracomment> <translation>Version: %1</translation> </message> - <message id="yubikey-info-serial"> - <source>Serial: %1</source> - <extracomment>Card info label</extracomment> - <translation>Serial: %1</translation> - </message> <message id="yubikey-info-no_creds"> <source>No credentials are stored on this YubiKey</source> <extracomment>Card info label</extracomment> @@ -198,11 +178,6 @@ <extracomment>Status label</extracomment> <translation>Touch YubiKey to save the token</translation> </message> - <message id="yubikey-wait-put_selected_tokens"> - <source>Touch YubiKey to save the selected tokens</source> - <extracomment>Status label</extracomment> - <translation>Touch YubiKey to save the selected tokens</translation> - </message> <message id="yubikey-add_token-save"> <source>Save</source> <extracomment>Dialog button</extracomment> @@ -254,9 +229,9 @@ <translation>%1 (default)</translation> </message> <message id="yubikey-token-digits-text"> - <source>Digits (leave it 6 for Steam tokens)</source> + <source>Digits</source> <extracomment>Text field label (number of password digits)</extracomment> - <translation>Digits (leave it 6 for Steam tokens)</translation> + <translation>Digits</translation> </message> <message id="yubikey-token-digits-placeholder"> <source>Number of password digits</source> @@ -333,35 +308,5 @@ <extracomment>Warning text</extracomment> <translation>Resetting the YubiKey irreversibly removes all secrets stored in it. This action cannot be undone. Are you sure that you really want to do it?</translation> </message> - <message id="yubikey-select_dialog-title"> - <source>Select tokens</source> - <extracomment>Dialog title</extracomment> - <translation>Select tokens</translation> - </message> - <message id="yubikey-rename_token-prompt"> - <source>Enter new name for %1</source> - <extracomment>Input prompt to rename the token</extracomment> - <translation>Enter new name for %1</translation> - </message> - <message id="yubikey-rename_token-placeholder"> - <source>Enter new name</source> - <extracomment>Placeholder for the new token name</extracomment> - <translation>Enter new name</translation> - </message> - <message id="yubikey-rename_token-duplicate_name"> - <source>Duplicate name</source> - <extracomment>Label for a duplicate token name</extracomment> - <translation>Duplicate name</translation> - </message> - <message id="yubikey-rename_token-button"> - <source>Rename</source> - <extracomment>Button label (rename token)</extracomment> - <translation>Rename</translation> - </message> - <message id="yubikey-wait-rename_token"> - <source>Touch the same YubiKey to rename the token</source> - <extracomment>Status label</extracomment> - <translation>Touch the same YubiKey to rename the token</translation> - </message> </context> </TS> | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/include/HarbourBattery.h ^ |
@@ -1,89 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef HARBOUR_BATTERY_H -#define HARBOUR_BATTERY_H - -#include <QObject> - -class QQmlEngine; -class QJSEngine; - -// D-Bus calls used by this object require mce 1.86.0 (Sailfish OS 2.1) -class HarbourBattery: public QObject -{ - Q_OBJECT - Q_PROPERTY(BatteryStatus batteryStatus READ batteryStatus NOTIFY batteryStatusChanged) - Q_PROPERTY(BatteryState batteryState READ batteryState NOTIFY batteryStateChanged) - Q_PROPERTY(int batteryLevel READ batteryLevel NOTIFY batteryLevelChanged) - Q_ENUMS(BatteryStatus) - Q_ENUMS(BatteryState) - -public: - enum BatteryStatus { - BatteryStatusUnknown, - BatteryStatusEmpty, - BatteryStatusLow, - BatteryStatusOk, - BatteryStatusFull - }; - - enum BatteryState { - BatteryStateUnknown, - BatteryStateCharging, - BatteryStateDischarging, - BatteryStateNotCharging, - BatteryStateFull - }; - - explicit HarbourBattery(QObject* aParent = Q_NULLPTR); - ~HarbourBattery(); - - // Callback for qmlRegisterSingletonType<HarbourBattery> - static QObject* createSingleton(QQmlEngine*, QJSEngine*); - - BatteryStatus batteryStatus() const; - BatteryState batteryState() const; - int batteryLevel() const; - -Q_SIGNALS: - void batteryStatusChanged(); - void batteryStateChanged(); - void batteryLevelChanged(); - -private: - class Private; - Private* iPrivate; -}; - -#endif // HARBOUR_BATTERY_H | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/include/HarbourProtoBuf.h ^ |
@@ -1,64 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef HARBOUR_PROTOBUF_H -#define HARBOUR_PROTOBUF_H - -#include <QByteArray> - -#include <gutil_types.h> - -// https://developers.google.com/protocol-buffers/docs/encoding - -class HarbourProtoBuf -{ - HarbourProtoBuf() Q_DECL_EQ_DELETE; - -public: - enum { - TYPE_SHIFT = 3, - TYPE_MASK = ((1 << TYPE_SHIFT)-1), - TYPE_VARINT = 0, - TYPE_DELIMITED = 2 - }; - - static QByteArray* appendVarInt(QByteArray*, quint64); - static QByteArray* appendVarIntKeyValue(QByteArray*, quint64, quint64); - static QByteArray* appendDelimitedValue(QByteArray*, const QByteArray); - static QByteArray* appendDelimitedKeyValue(QByteArray*, quint64, const QByteArray); - - static bool parseVarInt(GUtilRange*, quint64*); - static bool parseDelimitedValue(GUtilRange*, GUtilData*); -}; - -#endif // HARBOUR_PROTOBUF_H | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/include/HarbourUtil.h ^ |
@@ -1,69 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef HARBOUR_UTIL_H -#define HARBOUR_UTIL_H - -#include <QByteArray> -#include <QColor> -#include <QObject> -#include <QRgb> -#include <QString> - -class QQmlEngine; -class QJSEngine; - -class HarbourUtil : - public QObject -{ - Q_OBJECT - class Private; - -public: - explicit HarbourUtil(QObject* aParent = Q_NULLPTR); - - // Callback for qmlRegisterSingletonType<HarbourUtil> - static QObject* createSingleton(QQmlEngine*, QJSEngine*); - - // QML (and possibly native) utilities - Q_INVOKABLE static QColor invertedColor(const QColor&); - - // Static utilities - static QRgb invertedRgb(QRgb); - static QByteArray toHexBytes(const void*, size_t); - static QString toHex(const void*, size_t); - static inline QString toHex(const QByteArray& aData) - { return toHex(aData.constData(), aData.size()); } -}; - -#endif // HARBOUR_UTIL_H | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/qml/HarbourInvertEffect.qml ^ |
@@ -1,13 +0,0 @@ -import QtQuick 2.0 - -ShaderEffect { - property variant source - fragmentShader: " - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying highp vec2 qt_TexCoord0; - void main(void) { - highp vec4 pixelColor = texture2D(source, qt_TexCoord0); - gl_FragColor = vec4(vec3(1,1,1) - pixelColor.rgb, pixelColor.a) * qt_Opacity; - }" -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/src/HarbourBattery.cpp ^ |
@@ -1,266 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "HarbourBattery.h" -#include "HarbourDebug.h" -#include "HarbourMce.h" - -#include <QDBusPendingCallWatcher> -#include <QDBusPendingReply> - -// ========================================================================== -// HarbourBattery::Private -// ========================================================================== - -class HarbourBattery::Private : public HarbourMce -{ - Q_OBJECT - -public: - static const QString MCE_BATTERY_STATUS_UNKNOWN; - static const QString MCE_BATTERY_STATUS_FULL; - static const QString MCE_BATTERY_STATUS_OK; - static const QString MCE_BATTERY_STATUS_LOW; - static const QString MCE_BATTERY_STATUS_EMPTY; - - static const QString MCE_BATTERY_STATE_UNKNOWN; - static const QString MCE_BATTERY_STATE_DISCHARGING; - static const QString MCE_BATTERY_STATE_CHARGING; - static const QString MCE_BATTERY_STATE_NOT_CHARGING; - static const QString MCE_BATTERY_STATE_FULL; - - Private(HarbourBattery*); - - HarbourBattery* parentObject() const; - -public Q_SLOTS: - void updateBatteryStatus(const QString); - void updateBatteryState(const QString); - void updateBatteryLevel(int); - void onBatteryStatusQueryDone(QDBusPendingCallWatcher*); - void onBatteryStateQueryDone(QDBusPendingCallWatcher*); - void onBatteryLevelQueryDone(QDBusPendingCallWatcher*); - -public: - BatteryStatus iBatteryStatus; - BatteryState iBatteryState; - int iBatteryLevel; -}; - -const QString HarbourBattery::Private::MCE_BATTERY_STATUS_UNKNOWN("unknown"); -const QString HarbourBattery::Private::MCE_BATTERY_STATUS_FULL("full"); -const QString HarbourBattery::Private::MCE_BATTERY_STATUS_OK("ok"); -const QString HarbourBattery::Private::MCE_BATTERY_STATUS_LOW("low"); -const QString HarbourBattery::Private::MCE_BATTERY_STATUS_EMPTY("empty"); - -const QString HarbourBattery::Private::MCE_BATTERY_STATE_UNKNOWN("unknown"); -const QString HarbourBattery::Private::MCE_BATTERY_STATE_DISCHARGING("discharging"); -const QString HarbourBattery::Private::MCE_BATTERY_STATE_CHARGING("charging"); -const QString HarbourBattery::Private::MCE_BATTERY_STATE_NOT_CHARGING("not_charging"); -const QString HarbourBattery::Private::MCE_BATTERY_STATE_FULL("full"); - -HarbourBattery::Private::Private( - HarbourBattery* aParent) : - HarbourMce(aParent), - iBatteryStatus(BatteryStatusUnknown), - iBatteryState(BatteryStateUnknown), - iBatteryLevel(0) -{ - setupProperty("get_battery_status", "battery_status_ind", - SLOT(onBatteryStatusQueryDone(QDBusPendingCallWatcher*)), - SLOT(updateBatteryStatus(QString))); - setupProperty("get_battery_state", "battery_state_ind", - SLOT(onBatteryStateQueryDone(QDBusPendingCallWatcher*)), - SLOT(updateBatteryState(QString))); - setupProperty("get_battery_level", "battery_level_ind", - SLOT(onBatteryLevelQueryDone(QDBusPendingCallWatcher*)), - SLOT(updateBatteryLevel(int))); -} - -inline -HarbourBattery* -HarbourBattery::Private::parentObject() const -{ - return qobject_cast<HarbourBattery*>(parent()); -} - -void -HarbourBattery::Private::updateBatteryStatus( - const QString aStatus) -{ - BatteryStatus status = BatteryStatusUnknown; - - if (aStatus == MCE_BATTERY_STATUS_OK) { - status = BatteryStatusOk; - } else if (aStatus == MCE_BATTERY_STATUS_FULL) { - status = BatteryStatusFull; - } else if (aStatus == MCE_BATTERY_STATUS_LOW) { - status = BatteryStatusLow; - } else if (aStatus == MCE_BATTERY_STATUS_EMPTY) { - status = BatteryStatusEmpty; - } else if (aStatus != MCE_BATTERY_STATUS_UNKNOWN) { - HWARN("Unexpected battery status" << aStatus); - return; - } - - if (iBatteryStatus != status) { - iBatteryStatus = status; - HDEBUG(aStatus); - Q_EMIT parentObject()->batteryStatusChanged(); - } -} - -void -HarbourBattery::Private::updateBatteryState( - const QString aState) -{ - BatteryState state = BatteryStateUnknown; - - if (aState == MCE_BATTERY_STATE_CHARGING) { - state = BatteryStateCharging; - } else if (aState == MCE_BATTERY_STATE_DISCHARGING) { - state = BatteryStateDischarging; - } else if (aState == MCE_BATTERY_STATE_NOT_CHARGING) { - state = BatteryStateNotCharging; - } else if (aState == MCE_BATTERY_STATE_FULL) { - state = BatteryStateFull; - } else if (aState != MCE_BATTERY_STATE_UNKNOWN) { - HWARN("Unexpected battery state" << aState); - return; - } - - if (iBatteryState != state) { - iBatteryState = state; - HDEBUG(aState); - Q_EMIT parentObject()->batteryStateChanged(); - } -} - -void -HarbourBattery::Private::updateBatteryLevel( - int aLevel) -{ - if (iBatteryLevel != aLevel) { - iBatteryLevel = aLevel; - HDEBUG(aLevel); - Q_EMIT parentObject()->batteryLevelChanged(); - } -} - -void -HarbourBattery::Private::onBatteryStatusQueryDone( - QDBusPendingCallWatcher* aWatcher) -{ - QDBusPendingReply<QString> reply(*aWatcher); - - if (reply.isError()) { - HWARN(reply.error().message()); - } else { - updateBatteryStatus(reply.value()); - } - aWatcher->deleteLater(); -} - -void -HarbourBattery::Private::onBatteryStateQueryDone( - QDBusPendingCallWatcher* aWatcher) -{ - QDBusPendingReply<QString> reply(*aWatcher); - - if (reply.isError()) { - HWARN(reply.error().message()); - } else { - updateBatteryState(reply.value()); - } - aWatcher->deleteLater(); -} - -void -HarbourBattery::Private::onBatteryLevelQueryDone( - QDBusPendingCallWatcher* aWatcher) -{ - QDBusPendingReply<int> reply(*aWatcher); - - if (reply.isError()) { - HWARN(reply.error().message()); - } else { - updateBatteryLevel(reply.value()); - } - aWatcher->deleteLater(); -} - -// ========================================================================== -// HarbourBattery -// ========================================================================== - -HarbourBattery::HarbourBattery( - QObject* aParent) : - QObject(aParent), - iPrivate(new Private(this)) -{ - HDEBUG("created"); -} - -HarbourBattery::~HarbourBattery() -{ - HDEBUG("destroyed"); -} - -// Callback for qmlRegisterSingletonType<HarbourBattery> -QObject* -HarbourBattery::createSingleton( - QQmlEngine*, - QJSEngine*) -{ - return new HarbourBattery(); -} - -HarbourBattery::BatteryState -HarbourBattery::batteryState() const -{ - return iPrivate->iBatteryState; -} - -HarbourBattery::BatteryStatus -HarbourBattery::batteryStatus() const -{ - return iPrivate->iBatteryStatus; -} - -int -HarbourBattery::batteryLevel() const -{ - return iPrivate->iBatteryLevel; -} - -#include "HarbourBattery.moc" | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/src/HarbourProtoBuf.cpp ^ |
@@ -1,144 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "HarbourDebug.h" -#include "HarbourProtoBuf.h" - -// https://developers.google.com/protocol-buffers/docs/encoding - -QByteArray* -HarbourProtoBuf::appendVarInt( - QByteArray* aOutput, - quint64 aValue) -{ - if (aOutput) { - uchar out[10]; - quint64 value = aValue; - int i = sizeof(out) - 1; - - out[i] = value & 0x7f; - value >>= 7; - while (value) { - out[--i] = 0x80 | (uchar)value; - value >>= 7; - } - - const int n = sizeof(out) - i; - - aOutput->reserve(aOutput->size() + n); - aOutput->append((char*)(out + i), n); - } - return aOutput; -} - -QByteArray* -HarbourProtoBuf::appendVarIntKeyValue( - QByteArray* aOutput, - quint64 aKey, - quint64 aValue) -{ - HASSERT((aKey & TYPE_MASK) == TYPE_VARINT); - return appendVarInt(appendVarInt(aOutput, aKey), aValue); -} - -QByteArray* -HarbourProtoBuf::appendDelimitedValue( - QByteArray* aOutput, - const QByteArray aValue) -{ - if (aOutput) { - appendVarInt(aOutput, aValue.size())->append(aValue); - } - return aOutput; -} - -QByteArray* -HarbourProtoBuf::appendDelimitedKeyValue( - QByteArray* aOutput, - quint64 aKey, - const QByteArray aValue) -{ - HASSERT((aKey & TYPE_MASK) == TYPE_DELIMITED); - return appendDelimitedValue(appendVarInt(aOutput, aKey), aValue); -} - -bool -HarbourProtoBuf::parseVarInt( - GUtilRange* aPos, - quint64* aResult) -{ - if (aPos) { - quint64 value = 0; - const guint8* ptr = aPos->ptr; - - for (int i = 0; i < 10 && ptr < aPos->end; i++, ptr++) { - value = (value << 7) | (*ptr & 0x7f); - if (!(*ptr & 0x80)) { - aPos->ptr = ptr + 1; - if (aResult) { - *aResult = value; - } - return true; - } - } - - // Premature end of stream or too many bytes - if (aResult) { - *aResult = 0; - } - } - return false; -} - -// A delimited value is stored as a size, encoded as a varint, followed -// by the payload of type (message | string | bytes | packed) -bool -HarbourProtoBuf::parseDelimitedValue( - GUtilRange* aPos, - GUtilData* aPayload) -{ - if (aPos) { - GUtilRange pos = *aPos; - quint64 size; - - if (parseVarInt(&pos, &size) && (pos.ptr + size) <= pos.end) { - if (aPayload) { - aPayload->bytes = pos.ptr; - aPayload->size = size; - } - aPos->ptr = pos.ptr + size; - return true; - } - } - return false; -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/src/HarbourUtil.cpp ^ |
@@ -1,116 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "HarbourUtil.h" - -// ========================================================================== -// HarbourUtil::Private -// ========================================================================== - -class HarbourUtil::Private -{ -public: - static const char hex[]; -}; - -const char HarbourUtil::Private::hex[] = "0123456789abcdef"; - -// ========================================================================== -// HarbourUtil -// ========================================================================== - -HarbourUtil::HarbourUtil( - QObject* aParent) : - QObject(aParent) -{ -} - -// Callback for qmlRegisterSingletonType<HarbourUtil> -QObject* -HarbourUtil::createSingleton( - QQmlEngine*, - QJSEngine*) -{ - return new HarbourUtil(); -} - -QColor -HarbourUtil::invertedColor( - const QColor& aColor) -{ - if (aColor.isValid()) { - const QRgb inv = invertedRgb(aColor.rgba()); - - return QColor(qRed(inv), qGreen(inv), qBlue(inv), qAlpha(inv)); - } else { - return aColor; - } -} - -QRgb -HarbourUtil::invertedRgb( - QRgb aRgb) -{ - return ((~(aRgb & RGB_MASK)) & RGB_MASK) | (aRgb & (~RGB_MASK)); -} - -QString -HarbourUtil::toHex( - const void* aData, - size_t aSize) -{ - QString hex; - - if (aSize > 0) { - const uchar* bytes = (const uchar*)aData; - - hex.reserve(2 * aSize); - for (size_t i = 0; i < aSize; i++) { - const uchar b = bytes[i]; - - hex.append(QChar(Private::hex[(b & 0xf0) >> 4])); - hex.append(QChar(Private::hex[b & 0x0f])); - } - } - return hex; -} - -QByteArray -HarbourUtil::toHexBytes( - const void* aData, - size_t aSize) -{ - return aSize ? - QByteArray::fromRawData((const char*) aData, (int) aSize).toHex() : - QByteArray(); -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/test/TestHarbourProtoBuf/Makefile ^ |
@@ -1,7 +0,0 @@ -# -*- Mode: makefile-gmake -*- - -PKGS = libglibutil -EXE = TestHarbourProtoBuf -HARBOUR_SRC = HarbourProtoBuf.cpp - -include ../Makefile.common | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/test/TestHarbourProtoBuf/TestHarbourProtoBuf.cpp ^ |
@@ -1,168 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "HarbourProtoBuf.h" - -#include <glib.h> - -/*==========================================================================* - * null - *==========================================================================*/ - -static -void -test_null( - void) -{ - g_assert(!HarbourProtoBuf::appendVarInt(NULL, 0)); - g_assert(!HarbourProtoBuf::appendVarIntKeyValue(NULL, 0, 0)); - g_assert(!HarbourProtoBuf::appendDelimitedValue(NULL, QByteArray())); - g_assert(!HarbourProtoBuf::appendDelimitedKeyValue(NULL, - HarbourProtoBuf::TYPE_DELIMITED, QByteArray())); - g_assert(!HarbourProtoBuf::parseVarInt(NULL, NULL)); - g_assert(!HarbourProtoBuf::parseDelimitedValue(NULL, NULL)); -} - -/*==========================================================================* - * int - *==========================================================================*/ - -static -void -test_int( - void) -{ - QByteArray buf; - GUtilRange range; - quint64 res; - - static const guint8 enc0[] = { 0 }; - - g_assert(HarbourProtoBuf::appendVarInt(&buf, 0) == &buf); - g_assert(buf == QByteArray::fromRawData((char*)enc0, sizeof(enc0))); - - range.end = (range.ptr = enc0); - g_assert(!HarbourProtoBuf::parseVarInt(&range, NULL)); - range.end = (range.ptr = enc0); - - res = 42; - g_assert(!HarbourProtoBuf::parseVarInt(&range, &res)); - g_assert_cmpuint(res, == ,0); - - range.end = (range.ptr = enc0) + sizeof(enc0); - g_assert(HarbourProtoBuf::parseVarInt(&range, NULL)); - g_assert(range.ptr == range.end); - - res = 42; - range.end = (range.ptr = enc0) + sizeof(enc0); - g_assert(HarbourProtoBuf::parseVarInt(&range, &res)); - g_assert_cmpuint(res, == ,0); - - static const guint8 enc257[] = { 0x82, 0x01 }; - - buf.clear(); - g_assert(HarbourProtoBuf::appendVarInt(&buf, 257) == &buf); - g_assert(buf == QByteArray::fromRawData((char*)enc257, sizeof(enc257))); - - res = 42; - range.end = (range.ptr = enc257) + 1; - g_assert(!HarbourProtoBuf::parseVarInt(&range, &res)); - g_assert_cmpuint(res, == ,0); - - res = 42; - range.end = (range.ptr = enc257) + sizeof(enc257); - g_assert(HarbourProtoBuf::parseVarInt(&range, &res)); - g_assert(range.ptr == range.end); - g_assert_cmpuint(res, == ,257); -} - -/*==========================================================================* - * delimited - *==========================================================================*/ - -static -void -test_delimited( - void) -{ - QByteArray buf; - GUtilRange range; - GUtilData payload; - static const guint8 value[] = { 0x01, 0x02 }; - static const guint8 encodedValue[] = { 0x02, 0x01, 0x02 }; - - g_assert(HarbourProtoBuf::appendDelimitedValue(&buf, - QByteArray::fromRawData((char*)value, sizeof(value))) == &buf); - g_assert(buf == QByteArray::fromRawData((char*)encodedValue, - sizeof(encodedValue))); - - range.end = (range.ptr = encodedValue); - g_assert(!HarbourProtoBuf::parseDelimitedValue(&range, NULL)); - g_assert(range.ptr == encodedValue); - - range.end = (range.ptr = encodedValue) + sizeof(encodedValue) - 1; - g_assert(!HarbourProtoBuf::parseDelimitedValue(&range, NULL)); - g_assert(range.ptr == encodedValue); - - range.end = (range.ptr = encodedValue) + sizeof(encodedValue); - g_assert(HarbourProtoBuf::parseDelimitedValue(&range, NULL)); - - memset(&payload, 0, sizeof(payload)); - range.end = (range.ptr = encodedValue) + sizeof(encodedValue); - g_assert(HarbourProtoBuf::parseDelimitedValue(&range, &payload)); - g_assert_cmpuint(payload.size, == ,sizeof(value)); - g_assert(!memcmp(payload.bytes, value, sizeof(value))); -} - -/*==========================================================================* - * Common - *==========================================================================*/ - -#define TEST_(name) "/HarbourProtoBuf/" name - -int main(int argc, char* argv[]) -{ - g_test_init(&argc, &argv, NULL); - g_test_add_func(TEST_("null"), test_null); - g_test_add_func(TEST_("int"), test_int); - g_test_add_func(TEST_("delimited"), test_delimited); - return g_test_run(); -} - -/* - * Local Variables: - * mode: C++ - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/test/TestHarbourUtil/Makefile ^ |
@@ -1,8 +0,0 @@ -# -*- Mode: makefile-gmake -*- - -PKGS = Qt5Gui -EXE = TestHarbourUtil -MOC_H = HarbourUtil.h -HARBOUR_SRC = HarbourUtil.cpp - -include ../Makefile.common | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/harbour-lib/test/TestHarbourUtil/TestHarbourUtil.cpp ^ |
@@ -1,115 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "HarbourUtil.h" - -#include <glib.h> - -/*==========================================================================* - * object - *==========================================================================*/ - -static -void -test_object( - void) -{ - QObject* obj = HarbourUtil::createSingleton(Q_NULLPTR, Q_NULLPTR); - - g_assert(qobject_cast<HarbourUtil*>(obj)); - delete obj; -} - -/*==========================================================================* - * invertColor - *==========================================================================*/ - -static -void -test_invertColor( - void) -{ - g_assert_cmpuint(HarbourUtil::invertedRgb(0x12345678), == ,0x12cba987); - const QColor original(0xcb,0xa9,0x87,0x12); - const QColor inverted(0x34,0x56,0x78,0x12); - g_assert(HarbourUtil::invertedColor(original) == inverted); - g_assert(!HarbourUtil::invertedColor(QColor()).isValid()); -} - -/*==========================================================================* - * toHex - *==========================================================================*/ - -static -void -test_toHex( - void) -{ - static const char data[] = { - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, - 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14 - }; - - // Lower case is assumed - const QByteArray hex("0102030405060708090a0b0c0d0e0f1011121314"); - - g_assert(HarbourUtil::toHex(QByteArray()).isEmpty()); - g_assert(HarbourUtil::toHex(Q_NULLPTR, 0).isEmpty()); - g_assert(HarbourUtil::toHexBytes(Q_NULLPTR, 0).isEmpty()); - g_assert(HarbourUtil::toHex(data, sizeof(data)) == QString::fromLatin1(hex)); - const QByteArray out(HarbourUtil::toHexBytes(data, sizeof(data))); - g_assert_cmpstr(out.constData(), == ,hex.constData()); -} - -/*==========================================================================* - * Common - *==========================================================================*/ - -#define TEST_(name) "/HarbourUtil/" name - -int main(int argc, char* argv[]) -{ - g_test_init(&argc, &argv, NULL); - g_test_add_func(TEST_("object"), test_object); - g_test_add_func(TEST_("invertColor"), test_invertColor); - g_test_add_func(TEST_("toHex"), test_toHex); - return g_test_run(); -} - -/* - * Local Variables: - * mode: C++ - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/libgnfcdc/src/nfcdc_util.c ^ |
@@ -1,164 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava@monich.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#include "nfcdc_util_p.h" -#include "nfcdc_log.h" - -#include <gutil_misc.h> - -GUtilData* -nfc_data_copy( - const void* data, - gsize size) -{ - /* Allocates GUtilData and the actual data from a single memory block */ - if (data) { - GUtilData* copy = g_malloc(sizeof(GUtilData) + size); - void* buf = copy + 1; - - copy->size = size; - copy->bytes = buf; - memcpy(buf, data, size); - return copy; - } else { - return g_new0(GUtilData, 1); - } -} - -GUtilData* -nfc_data_from_variant( - GVariant* var) -{ - GUtilData* data = NULL; - GVariant* tmp = NULL; - - if (g_variant_is_of_type(var, G_VARIANT_TYPE_VARIANT)) { - var = tmp = g_variant_get_variant(var); - } - - /* Allocate value as a single memory block */ - if (g_variant_is_of_type(var, G_VARIANT_TYPE_BYTESTRING)) { - data = nfc_data_copy(g_variant_get_data(var), g_variant_get_size(var)); - } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_BYTE)) { - const guint8 b = g_variant_get_byte(var); - data = nfc_data_copy(&b, 1); - } - - if (tmp) { - g_variant_unref(tmp); - } - - /* Dispose of GUtilData and its contents with a single g_free() */ - return data; -} - -GHashTable* -nfc_parse_dict( - GHashTable* params, - GVariant* dict, - NfcStringKeyFunc string_key) -{ - if (dict) { - GVariantIter it; - GVariant* entry; - - if (!params) { - params = g_hash_table_new_full(g_direct_hash, g_direct_equal, - NULL, g_free); - } - - for (g_variant_iter_init(&it, dict); - (entry = g_variant_iter_next_value(&it)) != NULL; - g_variant_unref(entry)) { - GVariant* dict_key = g_variant_get_child_value(entry, 0); - const char* name = g_variant_get_string(dict_key, NULL); - const int key = string_key(name); - - if (key >= 0) { - GVariant* dict_value = g_variant_get_child_value(entry, 1); - GUtilData* data = nfc_data_from_variant(dict_value); - - if (data) { - DUMP_DATA(" ", name, "=", data); - g_hash_table_insert(params, GINT_TO_POINTER(key), data); - } - g_variant_unref(dict_value); - } - g_variant_unref(dict_key); - } - } - return params; -} - -gboolean -nfc_params_equal( - GHashTable* params1, - GHashTable* params2) -{ - if (params1 == params2) { - return TRUE; - } else if (!params1 || !params2) { - return FALSE; - } else { - const guint size1 = g_hash_table_size(params1); - const guint size2 = g_hash_table_size(params2); - - if (size1 != size2) { - return FALSE; - } else if (size1) { - GHashTableIter it; - gpointer key, value; - - g_hash_table_iter_init(&it, params1); - while (g_hash_table_iter_next(&it, &key, &value)) { - if (!gutil_data_equal(g_hash_table_lookup(params2, - key), value)) { - return FALSE; - } - } - } - return TRUE; - } -} - -/* - * Local Variables: - * mode: C - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/libgnfcdc/src/nfcdc_util_p.h ^ |
@@ -1,80 +0,0 @@ -/* - * Copyright (C) 2022 Jolla Ltd. - * Copyright (C) 2022 Slava Monich <slava@monich.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#ifndef NFCDC_UTIL_PRIVATE_H -#define NFCDC_UTIL_PRIVATE_H - -#include "nfcdc_types.h" - -typedef -int -(*NfcStringKeyFunc)( - const char*); - -GUtilData* -nfc_data_copy( - const void* data, - gsize size) - G_GNUC_INTERNAL; - -GUtilData* -nfc_data_from_variant( - GVariant* var) - G_GNUC_INTERNAL; - -GHashTable* -nfc_parse_dict( - GHashTable* table, - GVariant* params, - NfcStringKeyFunc key) - G_GNUC_INTERNAL; - -gboolean -nfc_params_equal( - GHashTable* params1, - GHashTable* params2) - G_GNUC_INTERNAL; - -#endif /* NFCDC_UTIL_PRIVATE_H */ - -/* - * Local Variables: - * mode: C - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/qml/YubiKeyImportDialog.qml ^ |
@@ -1,123 +0,0 @@ -import QtQuick 2.0 -import Sailfish.Silica 1.0 -import harbour.yubikey 1.0 - -import "harbour" - -Dialog { - id: thisDialog - - canAccept: model && model.haveSelectedTokens - - property alias model: list.model - readonly property var selectedTokens: model.selectedTokens - - readonly property color _selectionBackground: Theme.rgba(Theme.highlightBackgroundColor, 0.1) - - SilicaListView { - id: list - anchors.fill: parent - - header: DialogHeader { - //: Dialog button - //% "Save" - acceptText: qsTrId("yubikey-add_token-save") - //: Dialog title - //% "Select tokens" - title: qsTrId("yubikey-select_dialog-title") - } - - delegate: ListItem { - id: delegate - - contentHeight: Theme.itemSizeMedium - - readonly property int itemIndex: model.index - readonly property bool itemSelected: model.selected - - ListSeparator { - anchors.top: parent.top - } - - Rectangle { - width: parent.width - height: delegate.contentHeight - color: (delegate.itemSelected && !delegate.highlighted) ? _selectionBackground : "transparent" - } - - Column { - spacing: Theme.paddingMedium - anchors { - left: parent.left - leftMargin: Theme.horizontalPageMargin - right: icon.left - rightMargin: Theme.paddingLarge - verticalCenter: parent.verticalCenter - } - - Label { - width: parent.width - color: Theme.highlightColor - truncationMode: TruncationMode.Fade - font.bold: delegate.itemSelected - text: model.label - } - - Label { - width: parent.width - color: Theme.secondaryHighlightColor - truncationMode: TruncationMode.Fade - font.pixelSize: Theme.fontSizeExtraSmall - text: model.type === YubiKeyCard.TypeTOTP ? "TOTP" : "HOTP" - } - } - - HarbourHighlightIcon { - id: icon - - source: model.selected ? "images/checked.svg" : "images/unchecked.svg" - sourceSize.width: Theme.iconSizeMedium - highlightColor: delegate.down ? Theme.highlightColor : Theme.primaryColor - anchors { - right: parent.right - rightMargin: Theme.horizontalPageMargin - verticalCenter: parent.verticalCenter - } - } - - menu: Component { - ContextMenu { - hasContent: delegate.itemSelected - MenuItem { - //: Generic menu item - //% "Edit" - text: qsTrId("yubikey-menu-edit") - onClicked: { - var token = list.model.getToken(delegate.itemIndex) - pageStack.push("YubiKeyTokenDialog.qml", { - "allowedOrientations": allowedOrientations, - "type": token.type, - "algorithm": token.algorithm, - "label": token.label, - "secret": token.secret, - "digits": token.digits, - "counter": token.counter - }).tokenAccepted.connect(delegate.applyChanges) - } - } - } - } - - onClicked: model.selected = !model.selected - - function applyChanges(dialog) { - // Leave issuer as is - list.model.setToken(itemIndex, dialog.type, dialog.algorithm, - dialog.label, model.issuer, dialog.secret, dialog.digits, - dialog.counter) - } - } - - footer: ListSeparator { } - } -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/qml/YubiKeyRenameTokenPage.qml ^ |
@@ -1,165 +0,0 @@ -import QtQuick 2.0 -import Sailfish.Silica 1.0 -import harbour.yubikey 1.0 - -import "harbour" - -Page { - id: thisPage - - forwardNavigation: false - - property var tokenList - property string currentName - - signal rename(var name) - - readonly property int _fullHeight: isPortrait ? Screen.height : Screen.width - readonly property bool _duplicateName: nameField.text.length > 0 && - nameField.text != currentName && tokenList.containsName(nameField.text) - readonly property bool _acceptableName: nameField.text.length > 0 && - nameField.text != currentName && !tokenList.containsName(nameField.text) - - onStatusChanged: { - switch (status) { - case DialogStatus.Opening: - nameField.forceActiveFocus() - nameField.text = currentName - break - case DialogStatus.Opened: - forwardNavigation = false - break - } - } - - // Otherwise width is changing with a delay, causing visible layout changes - onIsLandscapeChanged: width = isLandscape ? Screen.height : Screen.width - - InfoLabel { - id: promptLabel - - //: Input prompt to rename the token - //% "Enter new name for %1" - text: qsTrId("yubikey-rename_token-prompt").arg(currentName) - x: Theme.horizontalPageMargin - width: parent.width - 2 * x - anchors { - bottom: panel.top - bottomMargin: Theme.paddingLarge - } - - // Hide it when it's only partially visible - opacity: (y < Theme.paddingSmall) ? 0 : 1 - Behavior on opacity { - enabled: !orientationTransitionRunning - FadeAnimation { } - } - } - - Item { - id: panel - - width: parent.width - height: childrenRect.height - y: Math.min((_fullHeight - height)/2, thisPage.height - panel.height - Theme.paddingLarge) - - TextField { - id: nameField - - anchors { - left: panel.left - top: parent.top - } - - //: Placeholder for the new token name - //% "Enter new name" - placeholderText: qsTrId("yubikey-rename_token-placeholder") - //: Label for a duplicate token name - //% "Duplicate name" - label: _duplicateName ? qsTrId("yubikey-rename_token-duplicate_name") : "" - EnterKey.enabled: _acceptableName - EnterKey.onClicked: accept() - - function accept() { - rename(text) - } - } - - Button { - id: button - - anchors { - topMargin: Theme.paddingLarge - bottomMargin: 2 * Theme.paddingSmall - } - //: Button label (rename token) - //% "Rename" - text: qsTrId("yubikey-rename_token-button") - enabled: _acceptableName - onClicked: nameField.accept() - } - } - - states: [ - State { - name: "portrait" - when: !isLandscape - changes: [ - AnchorChanges { - target: nameField - anchors.right: panel.right - }, - PropertyChanges { - target: nameField - anchors { - rightMargin: 0 - bottomMargin: Theme.paddingLarge - } - }, - AnchorChanges { - target: button - anchors { - top: nameField.bottom - right: undefined - horizontalCenter: parent.horizontalCenter - bottom: undefined - } - }, - PropertyChanges { - target: button - anchors.rightMargin: 0 - } - ] - }, - State { - name: "landscape" - when: isLandscape - changes: [ - AnchorChanges { - target: nameField - anchors.right: button.left - }, - PropertyChanges { - target: nameField - anchors { - rightMargin: Theme.horizontalPageMargin - bottomMargin: Theme.paddingSmall - } - }, - AnchorChanges { - target: button - anchors { - top: undefined - right: panel.right - horizontalCenter: undefined - bottom: nameField.bottom - } - }, - PropertyChanges { - target: button - anchors.rightMargin: Theme.horizontalPageMargin - } - ] - } - ] -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/qml/YubiKeyTokenDialog.qml ^ |
@@ -1,178 +0,0 @@ -import QtQuick 2.0 -import Sailfish.Silica 1.0 -import harbour.yubikey 1.0 - -Dialog { - id: thisDialog - - canAccept: ((type !== YubiKeyCard.TypeHOTP) || counterField.acceptableInput) && digitsField.acceptableInput && _acceptableSecret && label !== "" - - property string yubiKeyId - property alias dialogTitle: header.title - property alias acceptText: header.acceptText - property int type: YubiKeyCard.TypeTOTP - property int algorithm: YubiKeyCard.HMAC_SHA1 - property alias label: labelField.text - property alias secret: secretField.text - property alias digits: digitsField.text - property alias counter: counterField.text - - signal tokenAccepted(var dialog) - - readonly property bool _acceptableSecret: YubiKeyUtil.isValidBase32(secret) - - onAccepted: tokenAccepted(thisDialog) - - SilicaFlickable { - id: flickable - - anchors.fill: parent - contentHeight: column.height + Theme.paddingLarge - - Column { - id: column - - width: parent.width - - DialogHeader { id: header } - - TextField { - id: labelField - - width: parent.width - //: Text field label (OTP label) - //% "Name" - label: qsTrId("yubikey-token-name-text") - - EnterKey.enabled: text.length > 0 - EnterKey.iconSource: "image://theme/icon-m-enter-next" - EnterKey.onClicked: secretField.focus = true - } - - TextField { - id: secretField - - width: parent.width - //: Text field label (OTP secret) - //% "Secret" - label: qsTrId("yubikey-token-secret-text") - //: Text field placeholder (OTP secret) - //% "Secret OTP key" - placeholderText: qsTrId("yubikey-token-secret-placeholder") - errorHighlight: !_acceptableSecret - - EnterKey.enabled: text.length > 10 - EnterKey.iconSource: "image://theme/icon-m-enter-next" - EnterKey.onClicked: digitsField.focus = true - } - - - Grid { - columns: isLandscape ? 2 : 1 - width: parent.width - - readonly property real columnWidth: width/columns - - TextField { - id: digitsField - - width: counterField.visible ? parent.columnWidth : parent.width - //: Text field label (number of password digits) - //% "Digits (leave it 6 for Steam tokens)" - label: qsTrId("yubikey-token-digits-text") - //: Text field placeholder (number of password digits) - //% "Number of password digits" - placeholderText: qsTrId("yubikey-token-digits-placeholder") - text: YubiKeyUtil.DefaultDigits - validator: IntValidator { - bottom: YubiKeyUtil.MinDigits - top: YubiKeyUtil.MaxDigits - } - - EnterKey.iconSource: "image://theme/icon-m-enter-next" - EnterKey.onClicked: counterField.focus = true - } - - Item { - width: parent.columnWidth - height: (type === YubiKeyCard.TypeHOTP) ? counterField.height : 0 - visible: height > 0 - clip: true - - Behavior on height { - enabled: isPortrait - - SmoothedAnimation { duration: 250 } - } - - TextField { - id: counterField - - width: parent.width - //: Text field label (HOTP counter value) - //% "Initial counter value" - label: qsTrId("yubikey-token-counter-text") - placeholderText: label - text: "" - validator: IntValidator {} - - EnterKey.iconSource: "image://theme/icon-m-enter-accept" - EnterKey.onClicked: parent.forceActiveFocus() - } - } - } - - Grid { - columns: isLandscape ? 2 : 1 - width: parent.width - - readonly property real columnWidth: width/columns - - ComboBox { - id: typeComboBox - - width: parent.columnWidth - //: Combo box label (OTP type) - //% "Type" - label: qsTrId("yubikey-token-type-label") - menu: ContextMenu { - x: 0 - width: typeComboBox.width - //: Menu item for counter based token - //% "Counter-based (HOTP)" - MenuItem { text: qsTrId("yubikey-token-type-hotp") } - //: Menu item for time based token - //% "Time-based (TOTP)" - MenuItem { text: qsTrId("yubikey-token-type-totp") } - } - // YubiKeyTokenType enum is off by 1 - Component.onCompleted: currentIndex = type - 1 - onCurrentIndexChanged: type = currentIndex + 1 - } - - ComboBox { - id: algorithmComboBox - - width: parent.columnWidth - //: Combo box label - //% "Digest algorithm" - label: qsTrId("yubikey-token-digest_algorithm-label") - menu: ContextMenu { - x: 0 - width: algorithmComboBox.width - //: Menu item for the default digest algorithm - //% "%1 (default)" - MenuItem { text: qsTrId("yubikey-token-digest_algorithm-default").arg("SHA1") } - MenuItem { text: "SHA256" } - MenuItem { text: "SHA512" } - } - // YubiKeyAlgorithm enum is off by 1 - Component.onCompleted: currentIndex = algorithm - 1 - onCurrentIndexChanged: algorithm = currentIndex + 1 - } - } - } - - VerticalScrollDecorator { } - } -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/qml/images/checked.svg ^ |
@@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - version="1.1" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - x="0px" - y="0px" - width="64px" - height="64px" - viewBox="0 0 64 64" - style="enable-background:new 0 0 64 64" - xml:space="preserve"> - <g> - <rect - style="opacity:0;fill:#ffffff" - width="64" - height="64"/> - <circle - style="opacity:0.2;fill:none;stroke:#ffffff;stroke-opacity:1;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none" - cx="32" - cy="32" - r="24"/> - <path - style="fill:#ffffff;stroke-width:0" - d="M 28.46611,43 H 28.44073 C 27.83965,42.9909 27.272618,42.664 26.886342,42.1 L 19.1,30.819337 c -0.191281,-0.276737 0.04332,-0.93 0.326828,-1.116433 0.283517,-0.1861 0.965214,-0.195319 1.155876,0.08142 L 27.913315,40.629 c 0.16,0.230816 0.353467,0.368583 0.546605,0.371 0.278195,0 0.41378,-0.265627 0.557757,-0.355 L 43.44965,21.035359 c 0.198709,-0.270695 0.902641,-0.306581 1.179967,-0.111415 0.277945,0.194562 0.453774,0.76186 0.253827,1.033159 l -14.86,20.19335 C 29.624318,42.691239 29.058523,43 28.46611,43 Z"/> - </g> -</svg> | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/qml/images/unchecked.svg ^ |
@@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - version="1.1" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - x="0px" - y="0px" - width="64px" - height="64px" - viewBox="0 0 64 64" - style="enable-background:new 0 0 64 64" - xml:space="preserve"> - <g> - <rect - style="opacity:0;fill:#ffffff" - width="64" - height="64"/> - <circle - style="opacity:0.2;fill:none;stroke:#ffffff;stroke-opacity:1;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none" - cx="32" - cy="32" - r="24"/> - </g> -</svg> | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/src/YubiKeyCardSettings.cpp ^ |
@@ -1,375 +0,0 @@ -/* - * Copyright (C) 2023 Slava Monich <slava@monich.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#include "YubiKeyCardSettings.h" -#include "YubiKeyUtil.h" - -#include "HarbourDebug.h" - -#include <QAtomicInt> -#include <QSettings> - -// ========================================================================== -// YubiKeyCardSettings::Private -// ========================================================================== - -class YubiKeyCardSettings::Private : - public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(Private) - - static QMap<QString,Private*> gMap; - static const QChar LIST_SEPARATOR; - static const QString SETTINGS_FILE; - static const QString FAVORITE_ENTRY; - static const QString STEAM_ENTRY; - - Private(const QString); - ~Private(); - -public: - static Private* get(const QString); - static QString getFavoriteHash(QSettings*); - - Private* ref(); - void unref(); - - bool isFavoriteName(const QString); - void setFavoriteHash(const QString); - void setSteamHashes(const QStringList); - void addSteamHash(const QString); - void removeSteamHash(const QString); - void steamHashesUpdated(); - void tokenRenamed(const QString, const QString); - -Q_SIGNALS: - void favoriteHashChanged(); - void steamHashesChanged(); - -private: - QAtomicInt iRef; - QSettings* iSettings; - -public: - const QString iYubiKeyId; - QString iFavoriteHash; - QStringList iSteamHashes; -}; - -QMap<QString,YubiKeyCardSettings::Private*> YubiKeyCardSettings::Private::gMap; -const QChar YubiKeyCardSettings::Private::LIST_SEPARATOR(':'); -const QString YubiKeyCardSettings::Private::SETTINGS_FILE("settings"); -const QString YubiKeyCardSettings::Private::FAVORITE_ENTRY("Favorite"); -const QString YubiKeyCardSettings::Private::STEAM_ENTRY("Steam"); - -YubiKeyCardSettings::Private::Private( - const QString aYubiKeyId) : - iRef(1), - iSettings(Q_NULLPTR), - iYubiKeyId(aYubiKeyId) -{ - // Add is to the static map - HDEBUG(qPrintable(iYubiKeyId)); - HASSERT(!gMap.value(iYubiKeyId)); - gMap.insert(iYubiKeyId, this); - - if (!iYubiKeyId.isEmpty()) { - QDir configDir(YubiKeyUtil::configDir()); - const QString settingsFile(configDir.absoluteFilePath(iYubiKeyId) + - QDir::separator() + SETTINGS_FILE); - - HDEBUG("Settings" << qPrintable(settingsFile)); - configDir.mkpath("."); - iSettings = new QSettings(settingsFile, QSettings::IniFormat); - iFavoriteHash = getFavoriteHash(iSettings); - iSteamHashes = iSettings->value(STEAM_ENTRY).toString().split(LIST_SEPARATOR); - } -} - -YubiKeyCardSettings::Private::~Private() -{ - // Remove it from the static map - HDEBUG(qPrintable(iYubiKeyId)); - HASSERT(gMap.value(iYubiKeyId) == this); - gMap.remove(iYubiKeyId); - - delete iSettings; -} - -YubiKeyCardSettings::Private* -YubiKeyCardSettings::Private::get( - const QString aYubiKeyId) -{ - Private* self = gMap.value(aYubiKeyId); - if (self) { - return self->ref(); - } else { - return new Private(aYubiKeyId); - } -} - -YubiKeyCardSettings::Private* -YubiKeyCardSettings::Private::ref() -{ - iRef.ref(); - return this; -} - -void -YubiKeyCardSettings::Private::unref() -{ - if (!iRef.deref()) { - delete this; - } -} - -QString -YubiKeyCardSettings::Private::getFavoriteHash( - QSettings* aSettings) -{ - if (aSettings) { - QString favorite(aSettings->value(FAVORITE_ENTRY).toString()); - const int len = favorite.length(); - - if (len > 0) { - // Favorite name was originally stored in plain text - static const int Sha1Len = 20 * 2; // 2 hex digits per byte - bool isSha1 = false; - - if (len == Sha1Len) { - isSha1 = true; - const QChar* chars = favorite.constData(); - for (int i = 0; i < len && isSha1; i++) { - isSha1 = isxdigit(chars[i].unicode()); - } - } - if (isSha1) { - return favorite; - } else { - QString hash(YubiKeyUtil::nameHash(favorite)); - - HDEBUG("Replacing favorite name" << favorite << "with" << hash); - aSettings->setValue(FAVORITE_ENTRY, hash); - return hash; - } - } - } - return QString(); -} - -bool -YubiKeyCardSettings::Private::isFavoriteName( - const QString aName) -{ - return !aName.isEmpty() && iFavoriteHash == YubiKeyUtil::nameHash(aName); -} - -void -YubiKeyCardSettings::Private::setFavoriteHash( - const QString aHash) -{ - if (iFavoriteHash != aHash) { - iFavoriteHash = aHash; - if (iSettings) { - if (iFavoriteHash.isEmpty()) { - iSettings->remove(FAVORITE_ENTRY); - } else { - iSettings->setValue(FAVORITE_ENTRY, iFavoriteHash); - } - } - Q_EMIT favoriteHashChanged(); - } -} - -void -YubiKeyCardSettings::Private::steamHashesUpdated() -{ - HDEBUG("Steam hashes" << iSteamHashes); - if (iSettings) { - if (iSteamHashes.isEmpty()) { - iSettings->remove(STEAM_ENTRY); - } else { - iSettings->setValue(STEAM_ENTRY, iSteamHashes.join(LIST_SEPARATOR)); - } - } - Q_EMIT steamHashesChanged(); -} - -void -YubiKeyCardSettings::Private::setSteamHashes( - const QStringList aList) -{ - if (iSteamHashes != aList) { - iSteamHashes = aList; - steamHashesUpdated(); - } -} - -void -YubiKeyCardSettings::Private::addSteamHash( - const QString aHash) -{ - if (!aHash.isEmpty() && !iSteamHashes.contains(aHash)) { - iSteamHashes.append(aHash); - iSteamHashes.sort(); - steamHashesUpdated(); - } -} - -void -YubiKeyCardSettings::Private::removeSteamHash( - const QString aHash) -{ - if (iSteamHashes.removeOne(aHash)) { - steamHashesUpdated(); - } -} - -void -YubiKeyCardSettings::Private::tokenRenamed( - const QString aFrom, - const QString aTo) -{ - if (aFrom != aTo) { - if (isFavoriteName(aFrom)) { - HDEBUG("Favorite token renamed"); - setFavoriteHash(aTo.isEmpty() ? QString() : YubiKeyUtil::nameHash(aTo)); - } - if (iSteamHashes.removeOne(YubiKeyUtil::steamNameHash(aFrom))) { - iSteamHashes.append(YubiKeyUtil::steamNameHash(aTo)); - iSteamHashes.sort(); - steamHashesUpdated(); - } - } -} - -// ========================================================================== -// YubiKeyCardSettings -// Acts as a wrapper around a shared YubiKeyCardSettings::Private object -// ========================================================================== - -YubiKeyCardSettings::YubiKeyCardSettings( - const QString aYubiKeyId, - QObject* aParent) : - QObject(aParent), - iPrivate(Private::get(aYubiKeyId)) -{ - connect(iPrivate, SIGNAL(favoriteHashChanged()), SIGNAL(favoriteHashChanged())); - connect(iPrivate, SIGNAL(steamHashesChanged()), SIGNAL(steamHashesChanged())); -} - -YubiKeyCardSettings::~YubiKeyCardSettings() -{ - iPrivate->disconnect(this); - iPrivate->unref(); -} - -QString -YubiKeyCardSettings::favoriteHash() const -{ - return iPrivate->iFavoriteHash; -} - -void -YubiKeyCardSettings::setFavoriteHash( - const QString aHash) -{ - iPrivate->setFavoriteHash(aHash); -} - -bool -YubiKeyCardSettings::isFavoriteName( - const QString aName) const -{ - return iPrivate->isFavoriteName(aName); -} - -void -YubiKeyCardSettings::setFavoriteName( - const QString aName) -{ - iPrivate->setFavoriteHash(aName.isEmpty() ? - QString() : YubiKeyUtil::nameHash(aName)); -} - -void -YubiKeyCardSettings::clearFavorite() -{ - iPrivate->setFavoriteHash(QString()); -} - -QStringList -YubiKeyCardSettings::steamHashes() const -{ - return iPrivate->iSteamHashes; -} - -bool -YubiKeyCardSettings::isSteamHash( - const QString aHash) const -{ - return iPrivate->iSteamHashes.contains(aHash); -} - -void -YubiKeyCardSettings::setSteamHashes( - const QStringList aHashes) -{ - iPrivate->setSteamHashes(aHashes); -} - -void -YubiKeyCardSettings::addSteamHash( - const QString aHash) -{ - iPrivate->addSteamHash(aHash); -} - -void -YubiKeyCardSettings::removeSteamHash( - const QString aHash) -{ - iPrivate->removeSteamHash(aHash); -} - -void -YubiKeyCardSettings::tokenRenamed( - const QString aFrom, - const QString aTo) -{ - iPrivate->tokenRenamed(aFrom, aTo); -} - -#include "YubiKeyCardSettings.moc" | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/src/YubiKeyCardSettings.h ^ |
@@ -1,74 +0,0 @@ -/* - * Copyright (C) 2023 Slava Monich <slava@monich.com> - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING - * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#ifndef _YUBIKEY_CARD_SETTINGS_H -#define _YUBIKEY_CARD_SETTINGS_H - -#include <QObject> -#include <QStringList> - -class YubiKeyCardSettings : - public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(YubiKeyCardSettings) - -public: - YubiKeyCardSettings(const QString, QObject* aParent = Q_NULLPTR); - ~YubiKeyCardSettings(); - - QString favoriteHash() const; - void setFavoriteHash(const QString); - bool isFavoriteName(const QString) const; - void setFavoriteName(const QString); - void clearFavorite(); - - QStringList steamHashes() const; - bool isSteamHash(const QString) const; - void setSteamHashes(const QStringList); - void addSteamHash(const QString); - void removeSteamHash(const QString); - - void tokenRenamed(const QString, const QString); - -Q_SIGNALS: - void favoriteHashChanged(); - void steamHashesChanged(); - -private: - class Private; - Private* iPrivate; -}; - -#endif // _YUBIKEY_CARD_SETTINGS_H | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/src/YubiKeyImportModel.cpp ^ |
@@ -1,1022 +0,0 @@ -/* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> - * Copyright (C) 2022 Jolla Ltd. - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#include "YubiKeyImportModel.h" -#include "YubiKeyTypes.h" -#include "YubiKeyUtil.h" - -#include "HarbourBase32.h" -#include "HarbourDebug.h" -#include "HarbourProtoBuf.h" - -#include <gutil_misc.h> - -#include <foil_input.h> -#include <foil_util.h> - -#include <QUrl> - -// Model roles -#define MODEL_ROLES_(first,role,last) \ - first(Type,type) \ - role(Algorithm,algorithm) \ - role(Label,label) \ - role(Issuer,issuer) \ - role(Secret,secret) \ - role(Digits,digits) \ - role(Counter,counter) \ - last(Selected,selected) - -#define MODEL_ROLES(role) \ - MODEL_ROLES_(role,role,role) - -#define TOKEN_TYPE_TOTP "totp" -#define TOKEN_TYPE_HOTP "hotp" - -#define TOKEN_ALGORITHM_SHA1 "SHA1" -#define TOKEN_ALGORITHM_SHA256 "SHA256" -#define TOKEN_ALGORITHM_SHA512 "SHA512" - -#define TOKEN_KEY_TYPE "type" -#define TOKEN_KEY_SECRET "secret" -#define TOKEN_KEY_ISSUER "issuer" -#define TOKEN_KEY_DIGITS "digits" -#define TOKEN_KEY_COUNTER "counter" -#define TOKEN_KEY_ALGORITHM "algorithm" - -#define OTPAUTH_SCHEME "otpauth" -#define OTPAUTH_TOTP_PREFIX OTPAUTH_SCHEME "://" TOKEN_TYPE_TOTP "/" -#define OTPAUTH_HOTP_PREFIX OTPAUTH_SCHEME "://" TOKEN_TYPE_HOTP "/" -#define OTPAUTH_MIGRATION_PREFIX "otpauth-migration://offline?data=" - -// ========================================================================== -// YubiKeyImportModel::OtpParameters -// -// Represents otpauth-migration payload: -// -// message MigrationPayload { -// enum Algorithm { -// ALGORITHM_UNSPECIFIED = 0; -// ALGORITHM_SHA1 = 1; -// ALGORITHM_SHA256 = 2; -// ALGORITHM_SHA512 = 3; -// ALGORITHM_MD5 = 4; really??? -// } -// -// enum DigitCount { -// DIGIT_COUNT_UNSPECIFIED = 0; -// DIGIT_COUNT_SIX = 1; -// DIGIT_COUNT_EIGHT = 2; -// } -// -// enum OtpType { -// OTP_TYPE_UNSPECIFIED = 0; -// OTP_TYPE_HOTP = 1; -// OTP_TYPE_TOTP = 2; -// } -// -// message OtpParameters { -// bytes secret = 1; -// string name = 2; -// string issuer = 3; -// Algorithm algorithm = 4; -// DigitCount digits = 5; -// OtpType type = 6; -// int64 counter = 7; -// } -// -// repeated OtpParameters otp_parameters = 1; -// int32 version = 2; -// int32 batch_size = 3; -// int32 batch_index = 4; -// int32 batch_id = 5; -// } -// -// ========================================================================== - -class YubiKeyImportModel::OtpParameters -{ -public: - enum Algorithm { - ALGORITHM_UNSPECIFIED, - ALGORITHM_SHA1, - ALGORITHM_SHA256, - ALGORITHM_SHA512, - ALGORITHM_MD5 - }; - - enum DigitCount { - DIGIT_COUNT_UNSPECIFIED, - DIGIT_COUNT_SIX, - DIGIT_COUNT_EIGHT, - }; - - enum OtpType { - OTP_TYPE_UNSPECIFIED, - OTP_TYPE_HOTP, - OTP_TYPE_TOTP - }; - -#define DELIMITED_TAG(x) (((x) << HarbourProtoBuf::TYPE_SHIFT) | HarbourProtoBuf::TYPE_DELIMITED) -#define VARINT_TAG(x) (((x) << HarbourProtoBuf::TYPE_SHIFT) | HarbourProtoBuf::TYPE_VARINT) - - static const uchar OTP_PARAMETERS_TAG = DELIMITED_TAG(1); - static const uchar SECRET_TAG = DELIMITED_TAG(1); - static const uchar NAME_TAG = DELIMITED_TAG(2); - static const uchar ISSUER_TAG = DELIMITED_TAG(3); - static const uchar ALGORITHM_TAG = VARINT_TAG(4); - static const uchar DIGITS_TAG = VARINT_TAG(5); - static const uchar TYPE_TAG = VARINT_TAG(6); - static const uchar COUNTER_TAG = VARINT_TAG(7); - - static const uchar VERSION_TAG = VARINT_TAG(2); - static const uchar BATCH_SIZE_TAG = VARINT_TAG(3); - static const uchar BATCH_INDEX_TAG = VARINT_TAG(4); - static const uchar BATCH_ID_TAG = VARINT_TAG(5); - - static const uchar VERSION = 1; - -public: - OtpParameters(); - - bool parse(GUtilRange*); - void clear(); - bool isValid() const; - int numDigits() const; - YubiKeyAlgorithm yubiKeyAlgorithm() const; - YubiKeyTokenType yubiKeyTokenType() const; - -public: - QByteArray iSecret; - QString iName; - QString iIssuer; - Algorithm iAlgorithm; - DigitCount iDigits; - OtpType iType; - quint64 iCounter; -}; - -YubiKeyImportModel::OtpParameters::OtpParameters() -{ - clear(); -} - -void -YubiKeyImportModel::OtpParameters::clear() -{ - iSecret.clear(); - iName.clear(); - iIssuer.clear(); - iAlgorithm = ALGORITHM_SHA1; - iDigits = DIGIT_COUNT_SIX; - iType = OTP_TYPE_TOTP; - iCounter = 0; -} - -bool -YubiKeyImportModel::OtpParameters::isValid() const -{ - return !iSecret.isEmpty() && - (iAlgorithm == ALGORITHM_SHA1 || iAlgorithm == ALGORITHM_SHA256 || - iAlgorithm == ALGORITHM_SHA512) && - (iDigits == DIGIT_COUNT_SIX || iDigits == DIGIT_COUNT_EIGHT) && - (iType == OTP_TYPE_TOTP || iType == OTP_TYPE_HOTP); -} - -int -YubiKeyImportModel::OtpParameters::numDigits() const -{ - switch (iDigits) { - case DIGIT_COUNT_UNSPECIFIED: break; - case DIGIT_COUNT_SIX: return 6; - case DIGIT_COUNT_EIGHT: return 8; - } - return 0; -} - -YubiKeyAlgorithm -YubiKeyImportModel::OtpParameters::yubiKeyAlgorithm() const -{ - switch (iAlgorithm) { - case ALGORITHM_MD5: break; // Not supported - case ALGORITHM_UNSPECIFIED: break; - case ALGORITHM_SHA1: return YubiKeyAlgorithm_HMAC_SHA1; - case ALGORITHM_SHA256: return YubiKeyAlgorithm_HMAC_SHA256; - case ALGORITHM_SHA512: return YubiKeyAlgorithm_HMAC_SHA512; - } - return YubiKeyAlgorithm_Unknown; -} - -YubiKeyTokenType -YubiKeyImportModel::OtpParameters::yubiKeyTokenType() const -{ - switch (iType) { - case OTP_TYPE_UNSPECIFIED: break; - case OTP_TYPE_HOTP: return YubiKeyTokenType_HOTP; - case OTP_TYPE_TOTP: return YubiKeyTokenType_TOTP; - } - return YubiKeyTokenType_Unknown; -} - -bool -YubiKeyImportModel::OtpParameters::parse( - GUtilRange* aPos) -{ - quint64 tag, value; - GUtilData payload; - GUtilRange pos = *aPos; - - clear(); - - // Skip leading varints - while (HarbourProtoBuf::parseVarInt(&pos, &tag) && - (tag & HarbourProtoBuf::TYPE_MASK) == HarbourProtoBuf::TYPE_VARINT) { - if (!HarbourProtoBuf::parseVarInt(&pos, &value)) { - return false; - } - } - - // If parseVarInt failed, tag is zero - if (tag == OTP_PARAMETERS_TAG && - HarbourProtoBuf::parseDelimitedValue(&pos, &payload)) { - // Looks like OtpParameters - quint64 value; - - pos.end = (pos.ptr = payload.bytes) + payload.size; - while (HarbourProtoBuf::parseVarInt(&pos, &tag)) { - switch (tag) { - case SECRET_TAG: - if (HarbourProtoBuf::parseDelimitedValue(&pos, &payload)) { - iSecret = YubiKeyUtil::toByteArray(&payload); - } else { - return false; - } - break; - case NAME_TAG: - if (HarbourProtoBuf::parseDelimitedValue(&pos, &payload)) { - iName = QString::fromUtf8((const char*) payload.bytes, payload.size); - } else { - return false; - } - break; - case ISSUER_TAG: - if (HarbourProtoBuf::parseDelimitedValue(&pos, &payload)) { - iIssuer = QString::fromUtf8((const char*) payload.bytes, payload.size); - } else { - return false; - } - break; - case ALGORITHM_TAG: - if (HarbourProtoBuf::parseVarInt(&pos, &value)) { - iAlgorithm = (Algorithm)value; - } else { - return false; - } - break; - case DIGITS_TAG: - if (HarbourProtoBuf::parseVarInt(&pos, &value)) { - iDigits = (DigitCount)value; - } else { - return false; - } - break; - case TYPE_TAG: - if (HarbourProtoBuf::parseVarInt(&pos, &value)) { - iType = (OtpType)value; - } else { - return false; - } - break; - case COUNTER_TAG: - if (HarbourProtoBuf::parseVarInt(&pos, &value)) { - iCounter = value; - } else { - return false; - } - break; - default: - // Something unintelligible - return false; - } - } - if (pos.ptr == pos.end && isValid()) { - // The whole thing has been parsed and looks legit - aPos->ptr = pos.end; - return true; - } - } - return false; -} - -// ========================================================================== -// YubiKeyImportModel::ModelData -// ========================================================================== - -class YubiKeyImportModel::ModelData -{ -public: - typedef QList<ModelData*> List; - - enum Role { -#define FIRST(X,x) FirstRole = Qt::UserRole, X##Role = FirstRole, -#define ROLE(X,x) X##Role, -#define LAST(X,x) X##Role, LastRole = X##Role - MODEL_ROLES_(FIRST,ROLE,LAST) -#undef FIRST -#undef ROLE -#undef LAST - }; - - ModelData(const YubiKeyToken); - ModelData(const OtpParameters*); - - QVariant get(Role) const; - -public: - bool iSelected; - YubiKeyToken iToken; -}; - -YubiKeyImportModel::ModelData::ModelData( - const YubiKeyToken aToken) : - iSelected(true), - iToken(aToken) -{ -} - -YubiKeyImportModel::ModelData::ModelData( - const OtpParameters* aOtpParams) : - iSelected(true), - iToken(aOtpParams->yubiKeyTokenType(), - aOtpParams->yubiKeyAlgorithm(), - aOtpParams->iName, - aOtpParams->iIssuer, - aOtpParams->iSecret, - aOtpParams->numDigits(), - (int)aOtpParams->iCounter) -{ -} - -QVariant -YubiKeyImportModel::ModelData::get( - Role aRole) const -{ - switch (aRole) { - case TypeRole: return (int) iToken.type(); - case AlgorithmRole: return (int) iToken.algorithm(); - case LabelRole: return iToken.label(); - case IssuerRole: return iToken.issuer(); - case SecretRole: return iToken.secretBase32(); - case DigitsRole: return iToken.digits(); - case CounterRole: return iToken.counter(); - case SelectedRole: return iSelected; - } - return QVariant(); -} - -// ========================================================================== -// YubiKeyImportModel::Private -// ========================================================================== - -class YubiKeyImportModel::Private -{ -public: - Private(YubiKeyImportModel*); - ~Private(); - - ModelData* dataAt(int); - void setOtpUri(const QString); - void setItems(const ModelData::List); - void updateSelectedTokens(); - - static YubiKeyToken parseOtpAuthUri(const QByteArray); - static ModelData::List parseMigrationUri(const QByteArray); - static ModelData::List parseProtoBuf(gconstpointer, gsize); - -public: - YubiKeyImportModel* iModel; - ModelData::List iList; - QList<YubiKeyToken> iSelectedTokens; - QString iOtpUri; -}; - -YubiKeyImportModel::Private::Private( - YubiKeyImportModel* aModel) : - iModel(aModel) -{ -} - -YubiKeyImportModel::Private::~Private() -{ - qDeleteAll(iList); -} - -inline -YubiKeyImportModel::ModelData* -YubiKeyImportModel::Private::dataAt( - int aIndex) -{ - return (aIndex >= 0 && aIndex < iList.count()) ? - iList.at(aIndex) : Q_NULLPTR; -} - -YubiKeyImportModel::ModelData::List -YubiKeyImportModel::Private::parseProtoBuf( - gconstpointer aData, - gsize aSize) -{ - ModelData::List list; - OtpParameters otp; - GUtilRange pos; - - pos.end = (pos.ptr = (const guint8*) aData) + aSize; - while (otp.parse(&pos)) { - list.append(new ModelData(&otp)); - } - return list; -} - -YubiKeyImportModel::ModelData::List -YubiKeyImportModel::Private::parseMigrationUri( - const QByteArray aUri) -{ - GUtilRange pos; - GUtilData prefixBytes; - ModelData::List list; - - pos.end = (pos.ptr = (const guint8*)aUri.constData()) + aUri.size(); - if (gutil_range_skip_prefix(&pos, gutil_data_from_string(&prefixBytes, - OTPAUTH_MIGRATION_PREFIX))) { - // QByteArray is NULL-terminated - char* unescaped = g_uri_unescape_string((char*)pos.ptr, NULL); - - if (unescaped) { - pos.end = (pos.ptr = (const guint8*) unescaped) + strlen(unescaped); - - GBytes* bytes = foil_parse_base64(&pos, FOIL_INPUT_BASE64_VALIDATE); - if (bytes) { - gsize size; - gconstpointer data = g_bytes_get_data(bytes, &size); - -#if HARBOUR_DEBUG - pos.end = (pos.ptr = (const guint8*) data) + size; - HDEBUG("Decoded" << size << "bytes"); - while (pos.ptr < pos.end) { - char line[GUTIL_HEXDUMP_BUFSIZE]; - - pos.ptr += gutil_hexdump(line, pos.ptr, pos.end - pos.ptr); - HDEBUG(line); - } -#endif // HARBOUR_DEBUG - - list = parseProtoBuf(data, size); - HDEBUG(list.count() << "tokens"); - g_bytes_unref(bytes); - } - g_free(unescaped); - } - } - return list; -} - -YubiKeyToken -YubiKeyImportModel::Private::parseOtpAuthUri( - const QByteArray aUri) -{ - YubiKeyTokenType type = YubiKeyTokenType_Unknown; - GUtilData prefixBytes; - GUtilRange pos; - - // Check scheme + type prefix - pos.end = (pos.ptr = (const guint8*)aUri.constData()) + aUri.size(); - gutil_data_from_string(&prefixBytes, OTPAUTH_TOTP_PREFIX); - - if (gutil_range_skip_prefix(&pos, &prefixBytes)) { - type = YubiKeyTokenType_TOTP; - } else { - gutil_data_from_string(&prefixBytes, OTPAUTH_HOTP_PREFIX); - if (gutil_range_skip_prefix(&pos, &prefixBytes)) { - type = YubiKeyTokenType_HOTP; - } - } - - if (type != YubiKeyTokenType_Unknown) { - QByteArray label, secret, issuer, algorithm, digits, counter; - - while (pos.ptr < pos.end && pos.ptr[0] != '?') { - label.append(*pos.ptr++); - } - - GUtilData secretTag; - GUtilData issuerTag; - GUtilData digitsTag; - GUtilData counterTag; - GUtilData algorithmTag; - - gutil_data_from_string(&secretTag, TOKEN_KEY_SECRET "="); - gutil_data_from_string(&issuerTag, TOKEN_KEY_ISSUER "="); - gutil_data_from_string(&digitsTag, TOKEN_KEY_DIGITS "="); - gutil_data_from_string(&counterTag, TOKEN_KEY_COUNTER "="); - gutil_data_from_string(&algorithmTag, TOKEN_KEY_ALGORITHM "="); - - while (pos.ptr < pos.end) { - pos.ptr++; - - QByteArray* value = - gutil_range_skip_prefix(&pos, &secretTag) ? &secret : - gutil_range_skip_prefix(&pos, &issuerTag) ? &issuer : - gutil_range_skip_prefix(&pos, &digitsTag) ? &digits : - gutil_range_skip_prefix(&pos, &counterTag) ? &counter : - gutil_range_skip_prefix(&pos, &algorithmTag) ? &algorithm : - Q_NULLPTR; - - if (value) { - value->truncate(0); - while (pos.ptr < pos.end && pos.ptr[0] != '&') { - value->append(*pos.ptr++); - } - } else { - while (pos.ptr < pos.end && pos.ptr[0] != '&') { - pos.ptr++; - } - } - } - - if (!secret.isEmpty()) { - const QByteArray bytes(HarbourBase32:: - fromBase32(QUrl::fromPercentEncoding(secret))); - - if (!bytes.isEmpty()) { - const YubiKeyAlgorithm alg = algorithm.isEmpty() ? - YubiKeyAlgorithm_Default : YubiKeyUtil:: - algorithmFromName(QString::fromLatin1(algorithm)); - - if (alg != YubiKeyAlgorithm_Unknown) { - int dig = YubiKeyToken::DefaultDigits; - int imf = 0; - - if (!digits.isEmpty()) { - bool ok; - const int n = digits.toInt(&ok); - - if (ok && - n >= YubiKeyToken::MinDigits && - n <= YubiKeyToken::MaxDigits) { - dig = n; - } - } - - if (!counter.isEmpty()) { - bool ok; - const int n = counter.toInt(&ok); - - if (ok && n >= 0) { - imf = n; - } - } - - return YubiKeyToken(type, alg, - QUrl::fromPercentEncoding(label), - QUrl::fromPercentEncoding(issuer), - bytes, dig, imf); - } - } - } - } - return YubiKeyToken(); -} - -void -YubiKeyImportModel::Private::setOtpUri( - const QString aOtpUri) -{ - if (iOtpUri != aOtpUri) { - iOtpUri = aOtpUri; - - const QByteArray uri(iOtpUri.trimmed().toUtf8()); - HDEBUG(uri.constData()); - - ModelData::List list; - const YubiKeyToken singleToken(parseOtpAuthUri(uri)); - - if (singleToken.valid()) { - list.append(new ModelData(singleToken)); - HDEBUG("single token" << singleToken); - } else { - list = parseMigrationUri(uri); - } - - if (!list.isEmpty()) { - setItems(list); - } else if (iList.count() > 0) { - iModel->beginRemoveRows(QModelIndex(), 0, iList.count() - 1); - qDeleteAll(iList); - iList.clear(); - iModel->endRemoveRows(); - } - - Q_EMIT iModel->otpUriChanged(); - } -} - -void -YubiKeyImportModel::Private::setItems( - const ModelData::List aList) -{ - const int prevCount = iList.count(); - const int newCount = aList.count(); - const int changed = qMin(prevCount, newCount); - const QList<YubiKeyToken> prevSelectedTokens(iSelectedTokens); - - if (newCount < prevCount) { - iModel->beginRemoveRows(QModelIndex(), newCount, prevCount - 1); - qDeleteAll(iList); - iList = aList; - iModel->endRemoveRows(); - } else if (newCount > prevCount) { - iModel->beginInsertRows(QModelIndex(), prevCount, newCount - 1); - qDeleteAll(iList); - iList = aList; - iModel->endInsertRows(); - } else { - qDeleteAll(iList); - iList = aList; - } - - updateSelectedTokens(); - if (prevSelectedTokens != iSelectedTokens) { - if (!prevSelectedTokens.count() != !iSelectedTokens.count()) { - Q_EMIT iModel->haveSelectedTokensChanged(); - } - Q_EMIT iModel->selectedTokensChanged(); - } - if (changed > 0) { - Q_EMIT iModel->dataChanged(iModel->index(0), iModel->index(changed - 1)); - } -} - -void -YubiKeyImportModel::Private::updateSelectedTokens() -{ - QList<YubiKeyToken> list; - const int n = iList.count(); - - for (int i = 0; i < n; i++) { - const ModelData* entry = iList.at(i); - - if (entry->iSelected) { - list.append(entry->iToken); - } - } - - HDEBUG("selected" << list); - iSelectedTokens = list; -} - -// ========================================================================== -// YubiKeyImportModel -// ========================================================================== - -YubiKeyImportModel::YubiKeyImportModel( - QObject* aParent) : - QAbstractListModel(aParent), - iPrivate(new Private(this)) -{ - connect(this, SIGNAL(modelReset()), SIGNAL(countChanged())); - connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(countChanged())); - connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(countChanged())); - qRegisterMetaType<YubiKeyToken>(); - qRegisterMetaType<QList<YubiKeyToken> >(); -} - -YubiKeyImportModel::~YubiKeyImportModel() -{ - delete iPrivate; -} - -QString -YubiKeyImportModel::otpUri() const -{ - return iPrivate->iOtpUri; -} - -void -YubiKeyImportModel::setOtpUri( - const QString aOtpUri) -{ - iPrivate->setOtpUri(aOtpUri); -} - -QVariantMap -YubiKeyImportModel::getToken( - int aIndex) const -{ - const ModelData* entry = iPrivate->dataAt(aIndex); - - return entry ? entry->iToken.toVariantMap() : QVariantMap(); -} - -QList<YubiKeyToken> -YubiKeyImportModel::selectedTokens() const -{ - return iPrivate->iSelectedTokens; -} - -bool -YubiKeyImportModel::haveSelectedTokens() const -{ - return !iPrivate->iSelectedTokens.isEmpty(); -} - -Qt::ItemFlags -YubiKeyImportModel::flags( - const QModelIndex& aIndex) const -{ - return QAbstractListModel::flags(aIndex) | Qt::ItemIsEditable; -} - -QHash<int,QByteArray> -YubiKeyImportModel::roleNames() const -{ - QHash<int,QByteArray> roles; -#define ROLE(X,x) roles.insert(ModelData::X##Role, #x); -MODEL_ROLES(ROLE) -#undef ROLE - return roles; -} - -int -YubiKeyImportModel::rowCount( - const QModelIndex& aParent) const -{ - return iPrivate->iList.count(); -} - -QVariant -YubiKeyImportModel::data( - const QModelIndex& aIndex, - int aRole) const -{ - const ModelData* entry = iPrivate->dataAt(aIndex.row()); - - return entry ? entry->get((ModelData::Role)aRole) : QVariant(); -} - -bool -YubiKeyImportModel::setData( - const QModelIndex& aIndex, - const QVariant& aValue, - int aRole) -{ - ModelData* entry = iPrivate->dataAt(aIndex.row()); - bool ok = false; - - if (entry) { - QVector<int> roles; - QString s; - bool b; - int i; - - switch ((ModelData::Role)aRole) { - case ModelData::TypeRole: - i = aValue.toInt(&ok); - if (ok) { - const YubiKeyTokenType type = YubiKeyUtil::validType(i); - - if (type != YubiKeyTokenType_Unknown) { - HDEBUG(aIndex.row() << "type" << type); - if (entry->iToken.type() != type) { - entry->iToken = entry->iToken.withType(type); - roles.append(aRole); - } - } else { - ok = false; - } - } - break; - - case ModelData::AlgorithmRole: - i = aValue.toInt(&ok); - if (ok) { - const YubiKeyAlgorithm alg = YubiKeyUtil::validAlgorithm(i); - - if (alg != YubiKeyAlgorithm_Unknown) { - HDEBUG(aIndex.row() << "algorithm" << alg); - if (entry->iToken.algorithm() != alg) { - entry->iToken = entry->iToken.withAlgorithm(alg); - roles.append(aRole); - } - } else { - ok = false; - } - } - break; - - case ModelData::LabelRole: - s = aValue.toString(); - HDEBUG(aIndex.row() << "label" << s); - if (entry->iToken.label() != s) { - entry->iToken = entry->iToken.withLabel(s); - roles.append(aRole); - } - ok = true; - break; - - case ModelData::IssuerRole: - s = aValue.toString(); - HDEBUG(aIndex.row() << "issuer" << s); - if (entry->iToken.issuer() != s) { - entry->iToken = entry->iToken.withIssuer(s); - roles.append(aRole); - } - ok = true; - break; - - case ModelData::SecretRole: - s = aValue.toString().trimmed().toLower(); - ok = HarbourBase32::isValidBase32(s); - if (ok) { - const QByteArray secret(HarbourBase32::fromBase32(s)); - - HDEBUG(aIndex.row() << "secret" << s); - if (entry->iToken.secret() != secret) { - entry->iToken = entry->iToken.withSecret(secret); - roles.append(aRole); - } - } - break; - - case ModelData::DigitsRole: - i = aValue.toInt(&ok); - if (ok) { - if (i >= YubiKeyToken::MinDigits && - i <= YubiKeyToken::MaxDigits) { - HDEBUG(aIndex.row() << "digits" << i); - if (entry->iToken.digits() != i) { - entry->iToken = entry->iToken.withDigits(i); - roles.append(aRole); - } - } else { - ok = false; - } - } - break; - - case ModelData::CounterRole: - i = aValue.toInt(&ok); - if (ok) { - HDEBUG(aIndex.row() << "counter" << i); - if (entry->iToken.counter() != i) { - entry->iToken = entry->iToken.withCounter(i); - roles.append(aRole); - } - } - break; - - case ModelData::SelectedRole: - b = aValue.toBool(); - HDEBUG(aIndex.row() << "selected" << b); - if (entry->iSelected != b) { - entry->iSelected = b; - roles.append(aRole); - - // Selection has changed, update the list of selected tokens - const bool hadSelectedTokens = haveSelectedTokens(); - iPrivate->updateSelectedTokens(); - if (hadSelectedTokens != haveSelectedTokens()) { - Q_EMIT haveSelectedTokensChanged(); - } - // If the entry is selected, the signal will be emitted from - // common place below - if (!entry->iSelected) { - Q_EMIT selectedTokensChanged(); - } - } - ok = true; - break; - } - - if (!roles.isEmpty()) { - if (entry->iSelected) { - iPrivate->updateSelectedTokens(); - Q_EMIT selectedTokensChanged(); - } - Q_EMIT dataChanged(aIndex, aIndex, roles); - } - } - return ok; -} - -void -YubiKeyImportModel::setToken( - int aRow, - int aType, - int aAlgorithm, - const QString aLabel, - const QString aIssuer, - const QString aSecretBase32, - int aDigits, - int aCounter) -{ - ModelData* entry = iPrivate->dataAt(aRow); - - if (entry) { - QVector<int> roles; - const YubiKeyTokenType type = YubiKeyUtil::validType(aType); - const YubiKeyAlgorithm alg = YubiKeyUtil::validAlgorithm(aAlgorithm); - const QString secret(aSecretBase32.trimmed()); - - if (type != YubiKeyTokenType_Unknown && - type != entry->iToken.type()) { - entry->iToken = entry->iToken.withType(type); - HDEBUG(aRow << "type" << type); - roles.append(ModelData::TypeRole); - } - - if (alg != YubiKeyAlgorithm_Unknown && - alg != entry->iToken.algorithm()) { - entry->iToken = entry->iToken.withAlgorithm(alg); - HDEBUG(aRow << "algorithm" << alg); - roles.append(ModelData::AlgorithmRole); - } - - if (entry->iToken.label() != aLabel) { - entry->iToken = entry->iToken.withLabel(aLabel); - HDEBUG(aRow << "label" << aLabel); - roles.append(ModelData::LabelRole); - } - - if (entry->iToken.issuer() != aIssuer) { - entry->iToken = entry->iToken.withIssuer(aIssuer); - HDEBUG(aRow << "issuer" << aIssuer); - roles.append(ModelData::IssuerRole); - } - - if (HarbourBase32::isValidBase32(secret)) { - const QByteArray bytes(HarbourBase32::fromBase32(secret)); - - if (entry->iToken.secret() != bytes) { - entry->iToken = entry->iToken.withSecret(bytes); - HDEBUG(aRow << "secret" << entry->iToken.secretBase32()); - roles.append(ModelData::SecretRole); - } - } - - if (aDigits != entry->iToken.digits() && - aDigits >= YubiKeyToken::MinDigits && - aDigits <= YubiKeyToken::MaxDigits) { - entry->iToken = entry->iToken.withDigits(aDigits); - HDEBUG(aRow << "digits" << aDigits); - roles.append(ModelData::DigitsRole); - } - - if (entry->iToken.counter() != aCounter) { - entry->iToken = entry->iToken.withCounter(aCounter); - HDEBUG(aRow << "counter" << aCounter); - roles.append(ModelData::CounterRole); - } - - if (!roles.isEmpty()) { - if (entry->iSelected) { - iPrivate->updateSelectedTokens(); - Q_EMIT selectedTokensChanged(); - } - const QModelIndex idx(index(aRow)); - Q_EMIT dataChanged(idx, idx, roles); - } - } -} | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/src/YubiKeyImportModel.h ^ |
@@ -1,88 +0,0 @@ -/* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> - * Copyright (C) 2022 Jolla Ltd. - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#ifndef _YUBIKEY_IMPORT_MODEL_H -#define _YUBIKEY_IMPORT_MODEL_H - -#include "YubiKeyToken.h" - -#include <QAbstractListModel> - -class YubiKeyImportModel : - public QAbstractListModel -{ - Q_OBJECT - Q_DISABLE_COPY(YubiKeyImportModel) - Q_PROPERTY(int count READ rowCount NOTIFY countChanged) - Q_PROPERTY(QString otpUri READ otpUri WRITE setOtpUri NOTIFY otpUriChanged) - Q_PROPERTY(QList<YubiKeyToken> selectedTokens READ selectedTokens NOTIFY selectedTokensChanged) - Q_PROPERTY(bool haveSelectedTokens READ haveSelectedTokens NOTIFY haveSelectedTokensChanged) - -public: - YubiKeyImportModel(QObject* aParent = Q_NULLPTR); - ~YubiKeyImportModel(); - - QString otpUri() const; - void setOtpUri(const QString); - - QList<YubiKeyToken> selectedTokens() const; - bool haveSelectedTokens() const; - - Q_INVOKABLE QVariantMap getToken(int) const; - Q_INVOKABLE void setToken(int, int, int, const QString, const QString, const QString, int, int); - - // QAbstractItemModel - Qt::ItemFlags flags(const QModelIndex&) const Q_DECL_OVERRIDE; - QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE; - int rowCount(const QModelIndex& aParent = QModelIndex()) const Q_DECL_OVERRIDE; - QVariant data(const QModelIndex&, int) const Q_DECL_OVERRIDE; - bool setData(const QModelIndex&, const QVariant&, int) Q_DECL_OVERRIDE; - -Q_SIGNALS: - void countChanged(); - void otpUriChanged(); - void selectedTokensChanged(); - void haveSelectedTokensChanged(); - -private: - class OtpParameters; - class ModelData; - class Private; - Private* iPrivate; -}; - -#endif // _YUBIKEY_IMPORT_MODEL_H | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/src/YubiKeyToken.cpp ^ |
@@ -1,406 +0,0 @@ -/* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> - * Copyright (C) 2022 Jolla Ltd. - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#include "YubiKeyToken.h" - -#include "HarbourBase32.h" -#include "HarbourDebug.h" - -#include <QAtomicInt> - -// ========================================================================== -// YubiKeyToken::Private -// ========================================================================== - -class YubiKeyToken::Private -{ -public: - Private(YubiKeyTokenType, YubiKeyAlgorithm, const QString, const QString, - const QByteArray, const QString, int, int); - ~Private(); - -public: - QAtomicInt iRef; - YubiKeyTokenType iType; - YubiKeyAlgorithm iAlgorithm; - QString iLabel; - QString iIssuer; - QByteArray iSecret; - QString iSecretBase32; - int iDigits; - int iCounter; -}; - -YubiKeyToken::Private::Private( - YubiKeyTokenType aType, - YubiKeyAlgorithm aAlgorithm, - const QString aLabel, - const QString aIssuer, - const QByteArray aSecret, - const QString aSecretBase32, - int aDigits, - int aCounter) : - iRef(1), - iType(aType), - iAlgorithm(aAlgorithm), - iLabel(aLabel), - iIssuer(aIssuer), - iSecret(aSecret), - iSecretBase32(aSecretBase32), - iDigits(aDigits), - iCounter(aCounter) -{ -} - -YubiKeyToken::Private::~Private() -{ -} - -// ========================================================================== -// YubiKeyToken -// ========================================================================== - -YubiKeyToken::YubiKeyToken( - YubiKeyTokenType aType, - YubiKeyAlgorithm aAlgorithm, - const QString aLabel, - const QString aIssuer, - const QByteArray aSecret, - int aDigits, - int aCounter) : - iPrivate(new Private(aType, aAlgorithm, aLabel, aIssuer, aSecret, - HarbourBase32::toBase32(aSecret, true), aDigits, aCounter)) -{ -} - -YubiKeyToken::YubiKeyToken( - const YubiKeyToken& aToken) : - iPrivate(aToken.iPrivate) -{ - if (iPrivate) { - iPrivate->iRef.ref(); - } -} - -YubiKeyToken::YubiKeyToken( - Private* aPrivate) : - iPrivate(aPrivate) -{ -} - -YubiKeyToken::YubiKeyToken() : - iPrivate(NULL) -{ -} - -YubiKeyToken::~YubiKeyToken() -{ - if (iPrivate && !iPrivate->iRef.deref()) { - delete iPrivate; - } -} - -YubiKeyToken& -YubiKeyToken::operator=( - const YubiKeyToken& aToken) -{ - if (iPrivate != aToken.iPrivate) { - if (iPrivate && !iPrivate->iRef.deref()) { - delete iPrivate; - } - iPrivate = aToken.iPrivate; - if (iPrivate) { - iPrivate->iRef.ref(); - } - } - return *this; -} - -bool -YubiKeyToken::equals( - const YubiKeyToken& aToken) const -{ - if (iPrivate == aToken.iPrivate) { - return true; - } else if (iPrivate && aToken.iPrivate) { - const Private* other = aToken.iPrivate; - - return iPrivate->iType == other->iType && - iPrivate->iAlgorithm == other->iAlgorithm && - iPrivate->iDigits == other->iDigits && - iPrivate->iCounter == other->iCounter && - iPrivate->iLabel == other->iLabel && - iPrivate->iIssuer == other->iIssuer && - iPrivate->iSecret == other->iSecret; - } else { - return false; - } -} - -bool -YubiKeyToken::valid() const -{ - return iPrivate != Q_NULLPTR; -} - -YubiKeyTokenType -YubiKeyToken::type() const -{ - return iPrivate ? iPrivate->iType : YubiKeyTokenType_Unknown; -} - -YubiKeyAlgorithm -YubiKeyToken::algorithm() const -{ - return iPrivate ? iPrivate->iAlgorithm : YubiKeyAlgorithm_Unknown; -} - -QString -YubiKeyToken::label() const -{ - return iPrivate ? iPrivate->iLabel : QString(); -} - -QString -YubiKeyToken::issuer() const -{ - return iPrivate ? iPrivate->iIssuer : QString(); -} - -QString -YubiKeyToken::secretBase32() const -{ - return iPrivate ? iPrivate->iSecretBase32 : QString(); -} - -const QByteArray -YubiKeyToken::secret() const -{ - return iPrivate ? iPrivate->iSecret : QByteArray(); -} - -int -YubiKeyToken::digits() const -{ - return iPrivate ? iPrivate->iDigits : 0; -} - -int -YubiKeyToken::counter() const -{ - return iPrivate ? iPrivate->iCounter : 0; -} - -bool -YubiKeyToken::operator==( - const YubiKeyToken& aToken) const -{ - return equals(aToken); -} - -bool -YubiKeyToken::operator!=( - const YubiKeyToken& aToken) const -{ - return !equals(aToken); -} - -QVariantMap -YubiKeyToken::toVariantMap() const -{ - QVariantMap out; - - out.insert(QStringLiteral("valid"), valid()); - if (valid()) { - out.insert(QStringLiteral("type"), (int) iPrivate->iType); - out.insert(QStringLiteral("algorithm"), (int) iPrivate->iAlgorithm); - out.insert(QStringLiteral("label"), iPrivate->iLabel); - out.insert(QStringLiteral("issuer"), iPrivate->iIssuer); - out.insert(QStringLiteral("secret"), iPrivate->iSecretBase32); - out.insert(QStringLiteral("digits"), iPrivate->iDigits); - out.insert(QStringLiteral("counter"), iPrivate->iCounter); - } - return out; -} - -YubiKeyToken -YubiKeyToken::withType( - YubiKeyTokenType aType) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iType == aType) { - return *this; - } else { - return YubiKeyToken(new Private(aType, iPrivate->iAlgorithm, - iPrivate->iLabel, iPrivate->iIssuer, iPrivate->iSecret, - iPrivate->iSecretBase32, iPrivate->iDigits, iPrivate->iCounter)); - } -} - -YubiKeyToken -YubiKeyToken::withAlgorithm( - YubiKeyAlgorithm aAlgorithm) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iAlgorithm == aAlgorithm) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, aAlgorithm, - iPrivate->iLabel, iPrivate->iIssuer, iPrivate->iSecret, - iPrivate->iSecretBase32, iPrivate->iDigits, iPrivate->iCounter)); - } -} - -YubiKeyToken -YubiKeyToken::withLabel( - const QString aLabel) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iLabel == aLabel) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, iPrivate->iAlgorithm, - aLabel, iPrivate->iIssuer, iPrivate->iSecret, - iPrivate->iSecretBase32, iPrivate->iDigits, iPrivate->iCounter)); - } -} - -YubiKeyToken -YubiKeyToken::withIssuer( - const QString aIssuer) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iIssuer == aIssuer) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, iPrivate->iAlgorithm, - iPrivate->iLabel, aIssuer, iPrivate->iSecret, - iPrivate->iSecretBase32, iPrivate->iDigits, iPrivate->iCounter)); - } -} - -YubiKeyToken -YubiKeyToken::withSecret( - const QByteArray aSecret) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iSecret == aSecret) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, iPrivate->iAlgorithm, - iPrivate->iLabel, iPrivate->iIssuer, aSecret, - HarbourBase32::toBase32(aSecret, true), iPrivate->iDigits, - iPrivate->iCounter)); - } - -} - -YubiKeyToken -YubiKeyToken::withSecretBase32( - const QString aBase32) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (!HarbourBase32::isValidBase32(aBase32)) { - return *this; - } else { - const QByteArray secret(HarbourBase32::fromBase32(aBase32)); - - if (iPrivate->iSecret == secret) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, iPrivate->iAlgorithm, - iPrivate->iLabel, iPrivate->iIssuer, secret, - HarbourBase32::toBase32(secret, true), iPrivate->iDigits, - iPrivate->iCounter)); - } - } -} - -YubiKeyToken -YubiKeyToken::withDigits( - int aDigits) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iDigits == aDigits) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, iPrivate->iAlgorithm, - iPrivate->iLabel, iPrivate->iIssuer, iPrivate->iSecret, - iPrivate->iSecretBase32, aDigits, iPrivate->iCounter)); - } -} - -YubiKeyToken -YubiKeyToken::withCounter( - int aCounter) const -{ - if (!iPrivate) { - return YubiKeyToken(); - } else if (iPrivate->iCounter == aCounter) { - return *this; - } else { - return YubiKeyToken(new Private(iPrivate->iType, iPrivate->iAlgorithm, - iPrivate->iLabel, iPrivate->iIssuer, iPrivate->iSecret, - iPrivate->iSecretBase32, iPrivate->iDigits, aCounter)); - } -} - -#if HARBOUR_DEBUG -QDebug -operator<<( - QDebug aDebug, - const YubiKeyToken& aToken) -{ - if (aToken.valid()) { - QDebugStateSaver saver(aDebug); - aDebug.nospace() << "YubiKeyToken(" << aToken.label() << - ", " << aToken.issuer() << ", " <<aToken.type() << - ", " << aToken.algorithm() << ", " << aToken.secretBase32() << - ", " << aToken.digits() << ", " << aToken.counter() << ")"; - } else { - aDebug << "YubiKeyToken()"; - } - return aDebug; -} -#endif // HARBOUR_DEBUG | ||
[-] [+] | Deleted | _service:tar_git:harbour-yubikey-1.0.8.tar.gz/src/YubiKeyToken.h ^ |
@@ -1,110 +0,0 @@ -/* - * Copyright (C) 2022-2023 Slava Monich <slava@monich.com> - * Copyright (C) 2022 Jolla Ltd. - * - * You may use this file under the terms of the BSD license as follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation - * are those of the authors and should not be interpreted as representing - * any official policies, either expressed or implied. - */ - -#ifndef _YUBIKEY_TOKEN_H -#define _YUBIKEY_TOKEN_H - -#include "YubiKeyTypes.h" - -#include <QByteArray> -#include <QDebug> -#include <QMetaType> -#include <QVariantMap> -#include <QString> - -class YubiKeyToken -{ - Q_GADGET - Q_PROPERTY(bool valid READ valid CONSTANT) - Q_PROPERTY(int type READ type CONSTANT) - Q_PROPERTY(int algorithm READ algorithm CONSTANT) - Q_PROPERTY(QString label READ label CONSTANT) - Q_PROPERTY(QString issuer READ issuer CONSTANT) - Q_PROPERTY(QString secret READ secretBase32 CONSTANT) - Q_PROPERTY(int digits READ digits CONSTANT) - Q_PROPERTY(int counter READ counter CONSTANT) - -public: - enum Constants { - DefaultDigits = 6, - MinDigits = 6, - MaxDigits = 8 - }; - - YubiKeyToken(); - YubiKeyToken(const YubiKeyToken&); - YubiKeyToken(YubiKeyTokenType, YubiKeyAlgorithm, const QString, - const QString, const QByteArray, int, int); - ~YubiKeyToken(); - - YubiKeyToken& operator = (const YubiKeyToken&); - bool operator == (const YubiKeyToken&) const; - bool operator != (const YubiKeyToken&) const; - bool equals(const YubiKeyToken&) const; - - bool valid() const; - YubiKeyTokenType type() const; - YubiKeyAlgorithm algorithm() const; - QString label() const; - QString issuer() const; - QString secretBase32() const; - const QByteArray secret() const; - int digits() const; - int counter() const; - - Q_REQUIRED_RESULT QVariantMap toVariantMap() const; - Q_REQUIRED_RESULT YubiKeyToken withType(YubiKeyTokenType) const; - Q_REQUIRED_RESULT YubiKeyToken withAlgorithm(YubiKeyAlgorithm) const; - Q_REQUIRED_RESULT YubiKeyToken withLabel(const QString) const; - Q_REQUIRED_RESULT YubiKeyToken withIssuer(const QString) const; - Q_REQUIRED_RESULT YubiKeyToken withSecret(const QByteArray) const; - Q_REQUIRED_RESULT YubiKeyToken withSecretBase32(const QString) const; - Q_REQUIRED_RESULT YubiKeyToken withDigits(int) const; - Q_REQUIRED_RESULT YubiKeyToken withCounter(int) const; - -private: - class Private; - YubiKeyToken(Private*); - Private* iPrivate; -}; - -// Debug output -QDebug operator<<(QDebug, const YubiKeyToken&); - -Q_DECLARE_METATYPE(YubiKeyToken) - -#endif // _YUBIKEY_TOKEN_H |
Comments for request 2357 (0)
There's nothing to be done right now
Request History
slava | created request | 1659909664 over 1 year ago |
slava | Request got superseded by request 2359 | 1660172228 over 1 year ago |