Skip to content

Commit

Permalink
[qmf] Mask login information in the IMAP login logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerio Valerio committed Dec 19, 2014
1 parent aa06c67 commit 88f2f64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions qmf/src/plugins/messageservices/imap/imapprotocol.cpp
Expand Up @@ -297,7 +297,7 @@ class ImapContext

virtual QString sendCommand(const QString &cmd) { return mProtocol->sendCommand(cmd); }
virtual QString sendCommandLiteral(const QString &cmd, uint length) { return mProtocol->sendCommandLiteral(cmd, length); }
virtual void sendData(const QString &data) { mProtocol->sendData(data); }
virtual void sendData(const QString &data, bool maskDebug = false) { mProtocol->sendData(data, maskDebug); }
virtual void sendDataLiteral(const QString &data, uint length) { mProtocol->sendDataLiteral(data, length); }

ImapProtocol *protocol() { return mProtocol; }
Expand Down Expand Up @@ -602,7 +602,7 @@ bool LoginState::continuationResponse(ImapContext *c, const QString &received)
QByteArray response(ImapAuthenticator::getResponse(_config.serviceConfiguration("imap4"), challenge));

if (!response.isEmpty()) {
c->sendData(response.toBase64());
c->sendData(response.toBase64(), true);
} else {
// Challenge response is empty
// send a empty response.
Expand Down Expand Up @@ -3277,18 +3277,27 @@ void ImapProtocol::errorHandling(int status, QString msg)
emit connectionError(status, msg);
}

void ImapProtocol::sendData(const QString &cmd)
void ImapProtocol::sendData(const QString &cmd, bool maskDebug)
{
QByteArray output(cmd.toLatin1());
output.append("\r\n");
_transport->imapWrite(&output);

QString logCmd(cmd);
QRegExp loginExp("^[^\\s]+\\sLOGIN\\s[^\\s]+\\s");
if (loginExp.indexIn(cmd) != -1) {
logCmd = cmd.left(loginExp.matchedLength()) + "<password hidden>";
if (maskDebug) {
qMailLog(IMAP) << objectName() << (compress() ? "SENDC:" : "SEND") << "SEND: <login hidden>";
} else {
QString logCmd(cmd);
QRegExp authExp("^[^\\s]+\\sAUTHENTICATE\\s[^\\s]+\\s");
if (authExp.indexIn(cmd) != -1) {
logCmd = cmd.left(authExp.matchedLength()) + "<password hidden>";
} else {
QRegExp loginExp("^[^\\s]+\\sLOGIN\\s[^\\s]+\\s");
if (loginExp.indexIn(cmd) != -1) {
logCmd = cmd.left(loginExp.matchedLength()) + "<password hidden>";
}
}
qMailLog(IMAP) << objectName() << (compress() ? "SENDC:" : "SEND") << qPrintable(logCmd);
}
qMailLog(IMAP) << objectName() << (compress() ? "SENDC:" : "SEND") << qPrintable(logCmd);
}

void ImapProtocol::sendDataLiteral(const QString &cmd, uint length)
Expand Down
2 changes: 1 addition & 1 deletion qmf/src/plugins/messageservices/imap/imapprotocol.h
Expand Up @@ -284,7 +284,7 @@ protected slots:
void processResponse(QString line);
void nextAction(const QString &line);

void sendData(const QString &cmd);
void sendData(const QString &cmd, bool maskDebug = false);
void sendDataLiteral(const QString &cmd, uint length);

QString newCommandId();
Expand Down

0 comments on commit 88f2f64

Please sign in to comment.