23 KGpgVerify::KGpgVerify(
QObject *parent,
const QString &text)
29 KGpgVerify::KGpgVerify(
QObject *parent,
const KUrl::List &files)
42 QStringList ret(QLatin1String(
"--verify"));
50 if (line.startsWith(QLatin1String(
"[GNUPG:] NO_PUBKEY "))) {
52 m_missingId = line.mid(19).simplified();
56 if (line.startsWith(QLatin1String(
"[GNUPG:] ")) &&
57 line.contains(QLatin1String(
"SIG"))) {
58 if (line.startsWith(QLatin1String(
"[GNUPG:] BADSIG")))
83 if (sigtime.contains(QLatin1Char(
'T'))) {
84 stamp = QDateTime::fromString(sigtime, Qt::ISODate);
87 qint64 secs = sigtime.toLongLong(&ok);
89 stamp = QDateTime::fromMSecsSinceEpoch(secs * 1000);
95 return i18nc(
"first argument is formatted date, second argument is formatted time",
96 "The signature was created at %1 %2",
97 KGlobal::locale()->formatDate(stamp.date(), KLocale::LongDate),
98 KGlobal::locale()->formatTime(stamp.time(), KLocale::LongDate)) +
99 QLatin1String(
"<br/>");
109 const QRegExp validsig(QLatin1String(
"^\\[GNUPG:\\] VALIDSIG([ ]+[^ ]+){10,}.*$"));
110 const bool useGoodSig = (model == NULL) || (log.indexOf(validsig) == -1);
113 foreach (
const QString &line, log) {
114 if (!line.startsWith(QLatin1String(
"[GNUPG:] ")))
117 const QString msg = line.mid(9);
119 if (!useGoodSig && msg.startsWith(QLatin1String(
"VALIDSIG "))) {
124 const QStringList vsig = msg.mid(9).split(QLatin1Char(
' '), QString::SkipEmptyParts);
125 Q_ASSERT(vsig.count() >= 10);
131 if (node->getEmail().isEmpty())
132 result += i18n(
"<qt>Good signature from:<br /><b>%1</b><br />Key ID: %2<br /></qt>",
133 node->getName(), vsig[9]);
135 result += i18nc(
"Good signature from: NAME <EMAIL>, Key ID: HEXID",
136 "<qt>Good signature from:<br /><b>%1 <%2></b><br />Key ID: %3<br /></qt>",
137 node->getName(), node->getEmail(), vsig[9]);
147 }
else if (msg.startsWith(QLatin1String(
"UNEXPECTED")) ||
148 msg.startsWith(QLatin1String(
"NODATA"))) {
149 result += i18n(
"No signature found.") + QLatin1Char(
'\n');
150 }
else if (useGoodSig && msg.startsWith(QLatin1String(
"GOODSIG "))) {
151 int sigpos = msg.indexOf(
' ' , 8);
152 const QString keyid = msg.mid(8, sigpos - 8);
156 QString name = msg.mid(sigpos + 1);
158 int oPos = name.indexOf(QLatin1Char(
'<'));
159 int cPos = name.indexOf(QLatin1Char(
'>'));
160 if ((oPos >= 0) && (cPos >= 0)) {
161 email = name.mid(oPos + 1, cPos - oPos - 1);
162 name = name.left(oPos).simplified();
166 result += i18n(
"<qt>Good signature from:<br /><b>%1</b><br />Key ID: %2<br /></qt>",
169 result += i18nc(
"Good signature from: NAME <EMAIL>, Key ID: HEXID",
170 "<qt>Good signature from:<br /><b>%1 <%2></b><br />Key ID: %3<br /></qt>",
172 if (!sigtime.isEmpty()) {
176 }
else if (msg.startsWith(QLatin1String(
"SIG_ID "))) {
177 const QStringList parts = msg.simplified().split(QLatin1Char(
' '));
178 if (parts.count() > 2)
180 }
else if (msg.startsWith(QLatin1String(
"BADSIG"))) {
181 int sigpos = msg.indexOf(
' ', 7);
182 result += i18n(
"<qt><b>BAD signature</b> from:<br /> %1<br />Key id: %2<br /><br /><b>The file is corrupted</b><br /></qt>",
183 msg.mid(sigpos + 1).replace(QLatin1Char(
'<'), QLatin1String(
"<")),
184 msg.mid(7, sigpos - 7));
185 }
else if (msg.startsWith(QLatin1String(
"TRUST_UNDEFINED"))) {
186 result += i18n(
"<qt>The signature is valid, but the key is untrusted<br /></qt>");
187 }
else if (msg.startsWith(QLatin1String(
"TRUST_ULTIMATE"))) {
188 result += i18n(
"<qt>The signature is valid, and the key is ultimately trusted<br /></qt>");
201 #include "kgpgverify.moc"
feed a text or file through gpg
int getSuccess() const
get the success value that will be returned with the done signal
virtual bool nextLine(const QString &line)
Called for every line the gpg process writes.
GPGProc * getProcess()
get a reference to the gpg process object
virtual QStringList command() const
A public key with or without corresponding secret key.
static QString sigTimeMessage(const QString &sigtime)
signing key not in keyring
KGpgKeyNode * findKeyNode(const QString &id) const
virtual void finish()
implement special handling for GnuPG return codes
the file is signed, but the signature is invalid
virtual bool nextLine(const QString &line)
Called for every line the gpg process writes.
static QString getReport(const QStringList &log, const KGpgItemModel *model=NULL)
get verification report
void setSuccess(const int v)
set the success value that will be returned with the done signal
QString missingId() const
get the missing key id
virtual void finish()
implement special handling for GnuPG return codes
virtual ~KGpgVerify()
destructor