diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-18 11:40:41 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-18 11:40:45 +0200 |
commit | a7e7f7fdd2a9d38921476d57f305c9cd4459a556 (patch) | |
tree | d9ad3bdc3e275004a54f508025f0d52227ab18cb /examples/imapresource | |
parent | ea2e02ad656640c17d520b5a22c168c3c1faef56 (diff) | |
download | sink-a7e7f7fdd2a9d38921476d57f305c9cd4459a556.tar.gz sink-a7e7f7fdd2a9d38921476d57f305c9cd4459a556.zip |
Avoid storing the password in the configuration
The password (or any other secret), is now cached in the client process
(in-memory only), and delivered to the resource via command.
The resource avoids doing any operations against the source until the
secret is available.
Diffstat (limited to 'examples/imapresource')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 16 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 3 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 1 |
3 files changed, 12 insertions, 8 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 3ae7fd7..2aba6b0 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -470,7 +470,7 @@ public: | |||
470 | { | 470 | { |
471 | SinkTrace() << "Connecting to:" << mServer << mPort; | 471 | SinkTrace() << "Connecting to:" << mServer << mPort; |
472 | SinkTrace() << "as:" << mUser; | 472 | SinkTrace() << "as:" << mUser; |
473 | return imap->login(mUser, mPassword) | 473 | return imap->login(mUser, secret()) |
474 | .addToContext(imap); | 474 | .addToContext(imap); |
475 | } | 475 | } |
476 | 476 | ||
@@ -513,6 +513,8 @@ public: | |||
513 | return {ApplicationDomain::NoServerError, error.errorMessage}; | 513 | return {ApplicationDomain::NoServerError, error.errorMessage}; |
514 | case Imap::ConnectionLost: | 514 | case Imap::ConnectionLost: |
515 | return {ApplicationDomain::ConnectionLostError, error.errorMessage}; | 515 | return {ApplicationDomain::ConnectionLostError, error.errorMessage}; |
516 | case Imap::MissingCredentialsError: | ||
517 | return {ApplicationDomain::MissingCredentialsError, error.errorMessage}; | ||
516 | default: | 518 | default: |
517 | return {ApplicationDomain::UnknownError, error.errorMessage}; | 519 | return {ApplicationDomain::UnknownError, error.errorMessage}; |
518 | } | 520 | } |
@@ -631,7 +633,7 @@ public: | |||
631 | } | 633 | } |
632 | } | 634 | } |
633 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); | 635 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); |
634 | auto login = imap->login(mUser, mPassword); | 636 | auto login = imap->login(mUser, secret()); |
635 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); | 637 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); |
636 | if (operation == Sink::Operation_Creation) { | 638 | if (operation == Sink::Operation_Creation) { |
637 | const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); | 639 | const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); |
@@ -716,7 +718,7 @@ public: | |||
716 | } | 718 | } |
717 | } | 719 | } |
718 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); | 720 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); |
719 | auto login = imap->login(mUser, mPassword); | 721 | auto login = imap->login(mUser, secret()); |
720 | if (operation == Sink::Operation_Creation) { | 722 | if (operation == Sink::Operation_Creation) { |
721 | QString parentFolder; | 723 | QString parentFolder; |
722 | if (!folder.getParent().isEmpty()) { | 724 | if (!folder.getParent().isEmpty()) { |
@@ -736,7 +738,7 @@ public: | |||
736 | }); | 738 | }); |
737 | } else { //We try to merge special purpose folders first | 739 | } else { //We try to merge special purpose folders first |
738 | auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create(); | 740 | auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create(); |
739 | auto mergeJob = imap->login(mUser, mPassword) | 741 | auto mergeJob = imap->login(mUser, secret()) |
740 | .then(imap->fetchFolders([=](const Imap::Folder &folder) { | 742 | .then(imap->fetchFolders([=](const Imap::Folder &folder) { |
741 | if (SpecialPurpose::isSpecialPurposeFolderName(folder.name())) { | 743 | if (SpecialPurpose::isSpecialPurposeFolderName(folder.name())) { |
742 | specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.name()), folder.path()); | 744 | specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.name()), folder.path()); |
@@ -790,7 +792,6 @@ public: | |||
790 | QString mServer; | 792 | QString mServer; |
791 | int mPort; | 793 | int mPort; |
792 | QString mUser; | 794 | QString mUser; |
793 | QString mPassword; | ||
794 | int mDaysToSync = 0; | 795 | int mDaysToSync = 0; |
795 | QByteArray mResourceInstanceIdentifier; | 796 | QByteArray mResourceInstanceIdentifier; |
796 | Imap::SessionCache mSessionCache; | 797 | Imap::SessionCache mSessionCache; |
@@ -959,7 +960,6 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
959 | auto server = config.value("server").toString(); | 960 | auto server = config.value("server").toString(); |
960 | auto port = config.value("port").toInt(); | 961 | auto port = config.value("port").toInt(); |
961 | auto user = config.value("username").toString(); | 962 | auto user = config.value("username").toString(); |
962 | auto password = config.value("password").toString(); | ||
963 | if (server.startsWith("imap")) { | 963 | if (server.startsWith("imap")) { |
964 | server.remove("imap://"); | 964 | server.remove("imap://"); |
965 | server.remove("imaps://"); | 965 | server.remove("imaps://"); |
@@ -974,7 +974,6 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
974 | synchronizer->mServer = server; | 974 | synchronizer->mServer = server; |
975 | synchronizer->mPort = port; | 975 | synchronizer->mPort = port; |
976 | synchronizer->mUser = user; | 976 | synchronizer->mUser = user; |
977 | synchronizer->mPassword = password; | ||
978 | synchronizer->mDaysToSync = 14; | 977 | synchronizer->mDaysToSync = 14; |
979 | setupSynchronizer(synchronizer); | 978 | setupSynchronizer(synchronizer); |
980 | 979 | ||
@@ -982,7 +981,8 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
982 | inspector->mServer = server; | 981 | inspector->mServer = server; |
983 | inspector->mPort = port; | 982 | inspector->mPort = port; |
984 | inspector->mUser = user; | 983 | inspector->mUser = user; |
985 | inspector->mPassword = password; | 984 | //TODO |
985 | // inspector->mPassword = password; | ||
986 | setupInspector(inspector); | 986 | setupInspector(inspector); |
987 | 987 | ||
988 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor << new MailPropertyExtractor); | 988 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor << new MailPropertyExtractor); |
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 16887b1..317fbdc 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -139,6 +139,9 @@ ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCach | |||
139 | 139 | ||
140 | KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString &password) | 140 | KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString &password) |
141 | { | 141 | { |
142 | if (password.isEmpty()) { | ||
143 | return KAsync::error(Imap::MissingCredentialsError); | ||
144 | } | ||
142 | if (mSessionCache) { | 145 | if (mSessionCache) { |
143 | auto session = mSessionCache->getSession(); | 146 | auto session = mSessionCache->getSession(); |
144 | if (session.isValid()) { | 147 | if (session.isValid()) { |
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 86e3378..9e73f68 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -35,6 +35,7 @@ enum ErrorCode { | |||
35 | CouldNotConnectError, | 35 | CouldNotConnectError, |
36 | SslHandshakeError, | 36 | SslHandshakeError, |
37 | ConnectionLost, | 37 | ConnectionLost, |
38 | MissingCredentialsError, | ||
38 | UnknownError | 39 | UnknownError |
39 | }; | 40 | }; |
40 | 41 | ||