#include "msinterface.h"
#include "main.h"
+#include "sslexception.h"
+#include <QDebug>
#include <QDir>
+#include <QHttp>
#include <QMessageBox>
#include <QSettings>
#include <QTranslator>
);
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)
//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."));
+ }
+}
#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
{
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;
};
office.cpp \
moneylog.cpp \
domquery.cpp \
- msinterface.cpp
+ msinterface.cpp \
+ sslexception.cpp
HEADERS = \
main.h \
office.h \
moneylog.h \
domquery.h \
- msinterface.h
+ msinterface.h \
+ sslexception.h
RESOURCES += files.qrc
--- /dev/null
+//
+// 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;
+}
--- /dev/null
+//
+// 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
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;
/**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;