File indexing completed on 2024-04-21 05:50:41
0001 /* 0002 SPDX-FileCopyrightText: 2010-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "kgpgdelsign.h" 0007 0008 #include "model/kgpgitemnode.h" 0009 #include "gpgproc.h" 0010 0011 #include <QStringList> 0012 0013 KGpgDelSign::KGpgDelSign(QObject *parent, const KGpgSignNode::List &signids) 0014 : KGpgUidTransaction(parent, signids.at(0)->getParentKeyNode()->getId()) 0015 { 0016 addArgument(QLatin1String( "delsig" )); 0017 0018 const QStringList args = getProcess()->program(); 0019 0020 // If we run with --no-tty GnuPG will not tell which sign it is currently 0021 // asking to remove :( 0022 int ntty = args.indexOf(QLatin1String("--no-tty")); 0023 if (ntty >= 0) 0024 replaceArgument(ntty, QLatin1String("--with-colons")); 0025 else 0026 insertArgument(1, QLatin1String( "--with-colons" )); 0027 0028 if (signids.at(0)->getParentKeyNode()->getType() & KgpgCore::ITYPE_PUBLIC) 0029 setUid(QLatin1String( "1" )); 0030 else 0031 setUid(signids.at(0)->getParentKeyNode()->getId()); 0032 0033 #ifndef QT_NO_DEBUG 0034 for (const KGpgSignNode *snode : signids) { 0035 Q_ASSERT(signids.at(0)->getParentKeyNode() == snode->getParentKeyNode()); 0036 } 0037 #endif 0038 0039 setSignIds(signids); 0040 } 0041 0042 KGpgDelSign::KGpgDelSign(QObject* parent, KGpgSignNode *signid) 0043 : KGpgUidTransaction(parent, signid->getParentKeyNode()->getId()) 0044 { 0045 addArgument(QLatin1String( "delsig" )); 0046 insertArgument(1, QLatin1String( "--with-colons" )); 0047 0048 if (signid->getParentKeyNode()->getType() & KgpgCore::ITYPE_PUBLIC) 0049 setUid(QLatin1String( "1" )); 0050 else 0051 setUid(signid->getParentKeyNode()->getId()); 0052 0053 setSignId(signid); 0054 } 0055 0056 0057 KGpgSignNode::List KGpgDelSign::getSignIds(void) const 0058 { 0059 return m_signids; 0060 } 0061 0062 void KGpgDelSign::setSignId(KGpgSignNode* keyid) 0063 { 0064 m_signids.clear(); 0065 m_signids << keyid; 0066 } 0067 0068 void KGpgDelSign::setSignIds(const KGpgSignNode::List &keyids) 0069 { 0070 m_signids = keyids; 0071 } 0072 0073 bool 0074 KGpgDelSign::nextLine(const QString &line) 0075 { 0076 if (line.startsWith(QLatin1String("sig:"))) { 0077 m_cachedid = line; 0078 return false; 0079 } else if (line.startsWith(QLatin1String("[GNUPG:] "))) { 0080 return standardCommands(line); 0081 } else { 0082 // GnuPG will tell us a bunch of stuff because we are not in 0083 // --no-tty mode but we don't care. 0084 return false; 0085 } 0086 } 0087 0088 KGpgTransaction::ts_boolanswer 0089 KGpgDelSign::boolQuestion(const QString &line) 0090 { 0091 if (line.startsWith(QLatin1String("keyedit.delsig."))) { 0092 const QStringList parts = m_cachedid.split(QLatin1Char( ':' )); 0093 0094 if (parts.count() < 7) 0095 return KGpgTransaction::BA_NO; 0096 0097 const QString &sigid = parts[4]; 0098 const int snlen = sigid.length(); 0099 0100 auto it = std::find_if(m_signids.begin(), m_signids.end(), 0101 [sigid, snlen](const KGpgSignNode *snode) { 0102 return (snode->getId().right(snlen).compare(sigid) == 0); 0103 }); 0104 if (it == m_signids.end()) 0105 return KGpgTransaction::BA_NO; 0106 KGpgSignNode *signode = *it; 0107 0108 const QDateTime creation = QDateTime::fromSecsSinceEpoch(parts[5].toUInt()); 0109 if (creation != signode->getCreation()) 0110 return KGpgTransaction::BA_NO; 0111 0112 QDateTime sigexp; 0113 if (!parts[6].isEmpty() && (parts[6] != QLatin1String("0"))) 0114 sigexp = QDateTime::fromSecsSinceEpoch(parts[6].toUInt()); 0115 if (sigexp != signode->getExpiration()) 0116 return KGpgTransaction::BA_NO; 0117 0118 m_signids.erase(it); 0119 return KGpgTransaction::BA_YES; 0120 } else { 0121 return KGpgTransaction::boolQuestion(line); 0122 } 0123 }