diff options
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.cpp | 136 | ||||
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.h | 7 |
2 files changed, 51 insertions, 92 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index a4fc7265..89e71a68 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -700,95 +700,18 @@ bool SignedMessagePart::isSigned() const | |||
700 | return mMetaData.isSigned; | 700 | return mMetaData.isSigned; |
701 | } | 701 | } |
702 | 702 | ||
703 | bool SignedMessagePart::okVerify(const QByteArray &data, const QByteArray &signature, KMime::Content *textNode) | 703 | CryptoBodyPartMemento *SignedMessagePart::verifySignature(const QByteArray &data, const QByteArray &signature) |
704 | { | 704 | { |
705 | mMetaData.isSigned = false; | 705 | if (!signature.isEmpty()) { |
706 | mMetaData.keyTrust = GpgME::Signature::Unknown; | 706 | if (QGpgME::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob()) { |
707 | mMetaData.status = tr("Wrong Crypto Plug-In."); | 707 | return new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data); |
708 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | ||
709 | |||
710 | const QByteArray mementoName = "verification"; | ||
711 | |||
712 | //TODO for the async case remember the memento | ||
713 | CryptoBodyPartMemento *m = nullptr; | ||
714 | Q_ASSERT(!m || mCryptoProto); //No CryptoPlugin and having a bodyPartMemento -> there is something completely wrong | ||
715 | |||
716 | if (!m && mCryptoProto) { | ||
717 | if (!signature.isEmpty()) { | ||
718 | QGpgME::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob(); | ||
719 | if (job) { | ||
720 | m = new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data); | ||
721 | } | ||
722 | } else { | ||
723 | QGpgME::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob(); | ||
724 | if (job) { | ||
725 | m = new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data); | ||
726 | } | ||
727 | } | ||
728 | if (m) { | ||
729 | // if (mOtp->allowAsync()) { | ||
730 | // QObject::connect(m, &CryptoBodyPartMemento::update, | ||
731 | // nodeHelper, &NodeHelper::update); | ||
732 | // // QObject::connect(m, SIGNAL(update(MimeTreeParser::UpdateMode)), | ||
733 | // // _source->sourceObject(), SLOT(update(MimeTreeParser::UpdateMode))); | ||
734 | |||
735 | // if (m->start()) { | ||
736 | // mMetaData.inProgress = true; | ||
737 | // mOtp->mHasPendingAsyncJobs = true; | ||
738 | // } | ||
739 | // //FIXME delete memento once done | ||
740 | // } else { | ||
741 | m->exec(); | ||
742 | // } | ||
743 | } | ||
744 | //only relevant in async case | ||
745 | // } else if (m->isRunning()) { | ||
746 | // mMetaData.inProgress = true; | ||
747 | // mOtp->mHasPendingAsyncJobs = true; | ||
748 | // } else { | ||
749 | // mMetaData.inProgress = false; | ||
750 | // mOtp->mHasPendingAsyncJobs = false; | ||
751 | } | ||
752 | |||
753 | if (m && !mMetaData.inProgress) { | ||
754 | if (!signature.isEmpty()) { | ||
755 | mVerifiedText = data; | ||
756 | } | ||
757 | setVerificationResult(m, textNode); | ||
758 | } | ||
759 | |||
760 | if (!m && !mMetaData.inProgress) { | ||
761 | QString errorMsg; | ||
762 | QString cryptPlugLibName; | ||
763 | QString cryptPlugDisplayName; | ||
764 | if (mCryptoProto) { | ||
765 | cryptPlugLibName = mCryptoProto->name(); | ||
766 | cryptPlugDisplayName = mCryptoProto->displayName(); | ||
767 | } | 708 | } |
768 | 709 | } else { | |
769 | if (!mCryptoProto) { | 710 | if (QGpgME::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob()) { |
770 | if (cryptPlugDisplayName.isEmpty()) { | 711 | return new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data); |
771 | errorMsg = tr("No appropriate crypto plug-in was found."); | ||
772 | } else { | ||
773 | errorMsg = tr("%1 is either 'OpenPGP' or 'S/MIME'", | ||
774 | "No %1 plug-in was found.").arg( | ||
775 | cryptPlugDisplayName); | ||
776 | } | ||
777 | } else { | ||
778 | errorMsg = tr("Crypto plug-in \"%1\" cannot verify signatures.").arg( | ||
779 | cryptPlugLibName); | ||
780 | } | 712 | } |
781 | mMetaData.errorText = tr("The message is signed, but the " | ||
782 | "validity of the signature cannot be " | ||
783 | "verified.<br />" | ||
784 | "Reason: %1").arg(errorMsg); | ||
785 | } | ||
786 | //TODO don't delete in async case | ||
787 | if (m) { | ||
788 | delete m; | ||
789 | } | 713 | } |
790 | 714 | return nullptr; | |
791 | return mMetaData.isSigned; | ||
792 | } | 715 | } |
793 | 716 | ||
794 | static int signatureToStatus(const GpgME::Signature &sig) | 717 | static int signatureToStatus(const GpgME::Signature &sig) |
@@ -929,7 +852,48 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: | |||
929 | parseInternal(textNode, false); | 852 | parseInternal(textNode, false); |
930 | } | 853 | } |
931 | 854 | ||
932 | okVerify(text, signature, textNode); | 855 | mMetaData.isSigned = false; |
856 | mMetaData.keyTrust = GpgME::Signature::Unknown; | ||
857 | mMetaData.status = tr("Wrong Crypto Plug-In."); | ||
858 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | ||
859 | |||
860 | CryptoBodyPartMemento *m = verifySignature(text, signature); | ||
861 | m->exec(); | ||
862 | |||
863 | if (m && !mMetaData.inProgress) { | ||
864 | if (!signature.isEmpty()) { | ||
865 | mVerifiedText = text; | ||
866 | } | ||
867 | setVerificationResult(m, textNode); | ||
868 | } | ||
869 | |||
870 | if (!m && !mMetaData.inProgress) { | ||
871 | QString errorMsg; | ||
872 | QString cryptPlugLibName; | ||
873 | QString cryptPlugDisplayName; | ||
874 | if (mCryptoProto) { | ||
875 | cryptPlugLibName = mCryptoProto->name(); | ||
876 | cryptPlugDisplayName = mCryptoProto->displayName(); | ||
877 | } | ||
878 | |||
879 | if (!mCryptoProto) { | ||
880 | if (cryptPlugDisplayName.isEmpty()) { | ||
881 | errorMsg = tr("No appropriate crypto plug-in was found."); | ||
882 | } else { | ||
883 | errorMsg = tr("%1 is either 'OpenPGP' or 'S/MIME'", | ||
884 | "No %1 plug-in was found.").arg( | ||
885 | cryptPlugDisplayName); | ||
886 | } | ||
887 | } else { | ||
888 | errorMsg = tr("Crypto plug-in \"%1\" cannot verify signatures.").arg( | ||
889 | cryptPlugLibName); | ||
890 | } | ||
891 | mMetaData.errorText = tr("The message is signed, but the " | ||
892 | "validity of the signature cannot be " | ||
893 | "verified.<br />" | ||
894 | "Reason: %1").arg(errorMsg); | ||
895 | } | ||
896 | delete m; | ||
933 | 897 | ||
934 | if (!mMetaData.isSigned) { | 898 | if (!mMetaData.isSigned) { |
935 | mMetaData.creationTime = QDateTime(); | 899 | mMetaData.creationTime = QDateTime(); |
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h index 5cd186e6..2e0aac21 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.h +++ b/framework/src/domain/mime/mimetreeparser/messagepart.h | |||
@@ -373,12 +373,7 @@ public: | |||
373 | QString htmlContent() const Q_DECL_OVERRIDE; | 373 | QString htmlContent() const Q_DECL_OVERRIDE; |
374 | 374 | ||
375 | private: | 375 | private: |
376 | /** Handles the verification of data | 376 | CryptoBodyPartMemento *verifySignature(const QByteArray &data, const QByteArray &signature); |
377 | * If signature is empty it is handled as inline signature otherwise as detached signature mode. | ||
378 | * Returns true if the verfication was successfull and the block is signed. | ||
379 | * If used in async mode, check if mMetaData.inProgress is true, it inicates a running verification process. | ||
380 | */ | ||
381 | bool okVerify(const QByteArray &data, const QByteArray &signature, KMime::Content *textNode); | ||
382 | 377 | ||
383 | void sigStatusToMetaData(); | 378 | void sigStatusToMetaData(); |
384 | 379 | ||