diff ui/sslconnection.h @ 908:d1c951b3012d

Curl based implementation of sslconnection
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 13 Aug 2014 19:35:08 +0200
parents 17e1c8f37d72
children eaed02defe6a
line wrap: on
line diff
--- a/ui/sslconnection.h	Thu Aug 14 08:19:30 2014 +0200
+++ b/ui/sslconnection.h	Wed Aug 13 19:35:08 2014 +0200
@@ -18,13 +18,6 @@
 #include <QString>
 #include <QByteArray>
 
-#include <polarssl/entropy.h>
-#include <polarssl/net.h>
-#include <polarssl/ssl.h>
-#include <polarssl/ctr_drbg.h>
-#include <polarssl/error.h>
-#include <polarssl/certs.h>
-
 class SSLConnection
 {
 public:
@@ -47,12 +40,19 @@
      * @param[in] certificate optional certificate to validate https connection
      */
     SSLConnection(const QString& url,
-                  const QByteArray& certificate = QByteArray());
+                  const QByteArray& certificate = QByteArray()) :
+        mUrl(url),
+        mPinnedCert(certificate),
+        mInitialized(false),
+        mConnected(false),
+        mNeedsReset(false),
+        mServerFD(-1),
+        mErrorState(NoError) {};
 
-    ~SSLConnection();
+    virtual ~SSLConnection() {};
 
     /** @brief write */
-    int write(const QByteArray& request);
+    virtual int write(const QByteArray& request) = 0;
 
     /**
      * @brief read at most len bytes and reset the connection
@@ -61,7 +61,7 @@
      *
      * @returns a byte array containing the data or
      * a NULL byte array on error*/
-    QByteArray read(size_t len);
+    virtual QByteArray read(size_t len) = 0;
 
     bool initialized() { return mInitialized; }
     bool connected() { return mConnected; }
@@ -70,51 +70,19 @@
 
     /** @brief: Establish the connection
      *
-     * @returns 0 on success otherwise a polarssl error or -1 is returned
+     * @returns 0 on success otherwise an error or -1 is returned
      */
-    int connect();
+    virtual int connect() = 0;
 
-private:
+protected:
     QUrl mUrl;
     QByteArray mPinnedCert;
-    x509_crt mX509PinnedCert;
-    entropy_context mEntropy;
-    ctr_drbg_context mCtr_drbg;
-    ssl_context mSSL;
-    ssl_session mSavedSession;
     bool mInitialized;
     bool mConnected; /* A connection was established */
     bool mNeedsReset; /* The connection needs to be reset before the next
                          write */
     int mServerFD;
     SSLConnection::ErrorCode mErrorState;
-    /* @brief: Initialize polarssl structures
-     *
-     * This wraps polarssl initialization functions
-     * that can return an error.
-     * Sets the error state accordingly.
-     *
-     * @returns: 0 on success a polarssl error otherwise.
-     */
-    int init();
-
-    /* @brief Reset the connection.
-     *
-     * Resets the https connection and does another handshake.
-     *
-     * @returns: 0 on success a polarssl error or -1 otherwise. */
-    int reset();
-
-    /* @brief validates that the certificate matches the pinned one.
-     *
-     * Checks the peer certificate of mSSL and validates that the
-     * certificate matches mPinnedCertificate.
-     *
-     * @returns: 0 on success a polarssl error or -1 otherwise. */
-    int validateCertificate();
-
-    /* @brief disconnects the connection */
-    void disconnect();
 };
 
 #endif

http://wald.intevation.org/projects/trustbridge/