start of SSL exception handling, to be continued...
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 24 Dec 2009 14:33:39 +0000 (14:33 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 24 Dec 2009 14:33:39 +0000 (14:33 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@347 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/msinterface.cpp
src/msinterface.h
src/smoke.pro
src/sslexception.cpp [new file with mode: 0644]
src/sslexception.h [new file with mode: 0644]
src/wbase/WInterface.cpp
src/wbase/WInterface.h

index 4c31080..1a7afe6 100644 (file)
 
 #include "msinterface.h"
 #include "main.h"
+#include "sslexception.h"
 
+#include <QDebug>
 #include <QDir>
+#include <QHttp>
 #include <QMessageBox>
 #include <QSettings>
 #include <QTranslator>
@@ -35,11 +38,14 @@ MSInterface::MSInterface(QString pid)
                );
        m_host=set.value("hostname").toString();
        m_hostkey=set.value("hostkey").toString();
+       sslexcept=new MSslExceptions(dataDir()+"/sslexceptions.xml");
 }
 
 MSInterface::~MSInterface()
 {
        logout();
+       if(sslexcept)delete sslexcept;
+       sslexcept=0;
 }
 
 bool MSInterface::login(QString username,QString passwd)
@@ -167,3 +173,19 @@ void MSInterface::initialize()
        //TODO: retrieve scripts
        script: ;
 }
+
+void MSInterface::sslErrors(const QList<QSslError>&errs)
+{
+       //get source of error
+       QHttp*src=qobject_cast<QHttp*>(sender());
+       if(!src)return;
+       //check against known exceptions
+       if(sslexcept->checksslexcept(errs)){
+               src->ignoreSslErrors();
+               return;
+       }
+       //message box
+       if(!didsslerror){
+               QMessageBox::warning(0,tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration."));
+       }
+}
index 61ddefc..f4532a2 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "MInterface.h"
 
+class MSslExceptions;
+
 /**the MagicSmoke specific interface class - enhances the basic interface by some functionality needed in the MagicSmoke context*/
 class MSInterface:public MInterface
 {
@@ -66,12 +68,16 @@ class MSInterface:public MInterface
                bool relogin();
                /**sets the session id to be transmitted*/
                void setSessionId(QString sid){m_sessid=sid;}
+               /**handles SSL errors*/
+               virtual void sslErrors(const QList<QSslError>&);
        
        private:
                QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey;
                mutable QList<Right>userrights;
                mutable QStringList userroles;
                QByteArray servertranslation;
+               MSslExceptions*sslexcept;
+               bool didsslerror;
 };
 
 
index c6e936e..fab326a 100644 (file)
@@ -47,7 +47,8 @@ SOURCES = \
        office.cpp \
        moneylog.cpp \
        domquery.cpp \
-       msinterface.cpp
+       msinterface.cpp \
+       sslexception.cpp
 
 HEADERS = \
        main.h \
@@ -75,7 +76,8 @@ HEADERS = \
        office.h \
        moneylog.h \
        domquery.h \
-       msinterface.h
+       msinterface.h \
+       sslexception.h
 
 RESOURCES += files.qrc
 
diff --git a/src/sslexception.cpp b/src/sslexception.cpp
new file mode 100644 (file)
index 0000000..c9decc0
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// C++ Implementation: sslexception
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "sslexception.h"
+
+#include <QDialog>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QDomNodeList>
+#include <QFile>
+#include <QSslCertificate>
+
+MSslExceptions::MSslExceptions(QString p)
+{
+       path=p;
+       //load...
+       QFile fd(p);
+       if(fd.open(QIODevice::ReadOnly)){
+               QDomDocument doc;
+               if(!doc.setContent(&fd))return;
+               fd.close();
+               QDomElement root=doc.documentElement();
+       }
+}
+
+void MSslExceptions::savesslexcept(){}
+
+void MSslExceptions::showdialog(QWidget*){}
+
+bool MSslExceptions::checksslexcept(const QList<QSslError>&errs)
+{
+       qDebug("!!!!!!!!!!!!!!!!!!! %i SSL Exceptions!",errs.size());
+       return true;
+       for(int i=0;i<errs.size();i++){
+               QByteArray cert=errs[i].certificate().toPem();
+               if(!sslexcept.contains(cert))return false;
+               if(!sslexcept[cert].contains(errs[i].error()))return false;
+       }
+       return true;
+}
diff --git a/src/sslexception.h b/src/sslexception.h
new file mode 100644 (file)
index 0000000..67bc157
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// C++ Interface: sslexception
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_SSLEXCEPTION_H
+#define MAGICSMOKE_SSLEXCEPTION_H
+
+#include <QByteArray>
+#include <QList>
+#include <QMap>
+#include <QSslError>
+#include <QString>
+
+class QWidget;
+
+class MSslExceptions
+{
+       public:
+               MSslExceptions(QString path);
+
+               //ssl helper: save the exceptions
+               void savesslexcept();
+               //ssl helper: check errors agains the exception list
+               bool checksslexcept(const QList<QSslError>&);
+               
+               void showdialog(QWidget*);
+       
+       private:
+               QMap<QByteArray,QList<int> > sslexcept;
+               QString path;
+};
+
+#endif
index f410437..aee9cf8 100644 (file)
@@ -56,7 +56,7 @@ QMap<QString,QString> WInterface::headers(QString)const
        return QMap<QString,QString>();
 }
 
-void WInterface::sslErrors(const QList<QSslError>&errs)
+void WInterface::sslErrors(const QList<QSslError>&)
 {
        QHttp*src=qobject_cast<QHttp*>(sender());
        if(!src)return;
index 2f51c3a..100f9db 100644 (file)
@@ -82,8 +82,8 @@ class WInterface:public QObject
                /**sets the URL of the interface*/
                void setUrl(QUrl u){m_url=u;}
                
-               /**handles SSL errors*/
-               void sslErrors(const QList<QSslError>&);
+               /**handles SSL errors, per default ignores them, overwrite it if you need more sophisticated behavior*/
+               virtual void sslErrors(const QList<QSslError>&);
                
        private:
                static QMap<QString,WInterface*>inst;