Update of /cvsroot/mahogany/M/src/modules/viewflt
In directory sc8-pr-cvs1:/tmp/cvs-serv21592/src/modules/viewflt
Modified Files:
PGP.cpp
Log Message:
checking PGP signatures starts to work with GPG (nothing cn be configured yet)
Index: PGP.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/viewflt/PGP.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -u -2 -r1.3 -r1.4
--- PGP.cpp 2 Dec 2002 12:25:12 -0000 1.3
+++ PGP.cpp 3 Dec 2002 00:00:25 -0000 1.4
@@ -27,4 +27,6 @@
#include "ViewFilter.h"
+#include "modules/MCrypt.h"
+
// ----------------------------------------------------------------------------
// PGPFilter declaration
@@ -34,6 +36,5 @@
{
public:
- PGPFilter(MessageView *msgView, ViewFilter *next, bool enable)
- : ViewFilter(msgView, next, enable) { }
+ PGPFilter(MessageView *msgView, ViewFilter *next, bool enable);
protected:
@@ -41,4 +42,6 @@
MessageViewer *viewer,
MTextStyle& style);
+
+ MCryptoEngine *m_engine;
};
@@ -64,11 +67,7 @@
// ============================================================================
-// implementation
+// PGPFilter implementation
// ============================================================================
-// ----------------------------------------------------------------------------
-// PGPFilter
-// ----------------------------------------------------------------------------
-
// this filter has a rather high priority because it should be applied before
// all the filters working on the "real" message body, but after the trailer
@@ -81,4 +80,56 @@
"(c) 2002 Vadim Zeitlin <[EMAIL PROTECTED]>");
+// ----------------------------------------------------------------------------
+// PGPFilter ctor
+// ----------------------------------------------------------------------------
+
+PGPFilter::PGPFilter(MessageView *msgView, ViewFilter *next, bool enable)
+ : ViewFilter(msgView, next, enable)
+{
+ MModuleListing *listing =
+ MModule::ListAvailableModules(CRYPTO_ENGINE_INTERFACE);
+ if ( listing )
+ {
+ const size_t count = listing->Count();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ const MModuleListingEntry& entry = (*listing)[n];
+
+ const String& name = entry.GetName();
+ if ( name == _T("PGPEngine") )
+ {
+ MCryptoEngineFactory * const factory
+ = (MCryptoEngineFactory *)MModule::LoadModule(name);
+ if ( factory )
+ {
+ m_engine = factory->Get();
+
+ factory->DecRef();
+ }
+ else
+ {
+ FAIL_MSG( _T("failed to create PGPEngineFactory") );
+ }
+ }
+ }
+
+ listing->DecRef();
+ }
+
+ if ( !m_engine )
+ {
+ wxLogError(_("Failed to load PGP engine module.\n"
+ "\n"
+ "Support for PGP in message viewer will be unavailable") );
+
+ // TODO: disable completely
+ Enable(false);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// PGPFilter work function
+// ----------------------------------------------------------------------------
+
void
PGPFilter::DoProcess(String& text,
@@ -203,58 +254,25 @@
}
- if ( isSigned )
- {
- // TODO: pass everything between start and end to PGP for
- // verification
+ CHECK_RET( m_engine, _T("PGP filter can't work without PGP engine") );
- // if ( verified ok )
+ if ( isSigned )
{
- // remove the PGP signature and show just the text
-
- // (a) skip the header: it ends at first blank line
- const char *pc = start;
- while ( pc && (pc[1] != '\r' || pc[2] != '\n') )
+ // pass everything between start and end to PGP for verification
+ String in(start, end),
+ out;
+ if ( m_engine->VerifySignature(in, out) != MCryptoEngine::OK )
{
- pc = strchr(pc + 1, '\n');
- }
+ // TODO: more details...
+ wxLogWarning(_("The PGP signature of this message is invalid!"));
- if ( !pc )
- {
- FAIL_MSG( _T("no blank line after PGP BEGIN line?") );
- pc = start;
+ // use unmodified text
+ out = in;
}
else
{
- // skip "\n\r\n"
- pc += 3;
- }
-
- // (b) cut off the signature block
- end -= 2; // skip "\r\n"
- for ( ;; )
- {
- while ( *end != '\n' && end >= start )
- {
- end--;
+ // TODO: create an icon for the sig...
}
- end++;
-
- if ( strncmp(end, PGP_BEGIN_SIG, strlen(PGP_BEGIN_SIG)) == 0 )
- break;
-
- if ( end == start )
- {
- FAIL_MSG( _T("no PGP signature block in signed msg?") );
-
- end = start + text.length() - 1;
- }
-
- end -= 2; // skip "\r\n" again
- }
-
- m_next->Process(String(pc, end), viewer, style);
- }
- //else: complain about bad signature
+ m_next->Process(out, viewer, style);
}
else // encrypted
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T
handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates