Переглянути джерело

Admin Server SSL verschlüsselt

Kolja Strohm 6 роки тому
батько
коміт
2721330798
3 змінених файлів з 32 додано та 32 видалено
  1. 28 28
      AppServer/AppServer.cpp
  2. 3 3
      AppServer/AppServer.h
  3. 1 1
      AppServer/main.cpp

+ 28 - 28
AppServer/AppServer.cpp

@@ -18,7 +18,10 @@ AppServer::AppServer( InitDatei *zDat )
     gesendet = 0;
     dat = zDat->getThis();
     server = new Server();
-    aServer = new Server();
+    aServer = new SSLServer();
+    aServer->setPrivateKeyPassword( zDat->zWert( "SSLPasswort" )->getText() );
+    aServer->setPrivateKeyFile( zDat->zWert( "SSLKey" )->getText() );
+    aServer->setCertificateFile( zDat->zWert( "SSLCert" )->getText() );
     std::cout << "AppS: Starten des Admin Servers...\n";
     if( !aServer->verbinde( (unsigned short)TextZuInt( zDat->zWert( "AppSAPort" )->getText(), 10 ), 10 ) )
     {
@@ -49,9 +52,9 @@ AppServer::~AppServer()
 // nicht constant 
 void AppServer::runn()
 {
-    while( !end )
+    while( !end && aServer->isConnected() )
     {
-        SKlient *klient;
+        SSLSKlient *klient;
         klient = aServer->getKlient();
         if( end && klient )
         {
@@ -61,7 +64,7 @@ void AppServer::runn()
             return;
         }
         if( !klient )
-            return;
+            continue;
         AppSAKlient *clHandle = new AppSAKlient( klient, getThis() );
         clHandle->start();
     }
@@ -69,12 +72,12 @@ void AppServer::runn()
 
 void AppServer::thread()
 {
-    while( 1 )
+    while( server->isConnected() )
     {
         SKlient *klient;
         klient = server->getKlient();
         if( !klient )
-            break;
+            continue;
         Framework::getThreadRegister()->cleanUpClosedThreads();
         AppSKlient *clHandle = new AppSKlient( klient, getThis() );
         clHandle->start();
@@ -185,13 +188,10 @@ AppServer *AppServer::release()
 
 // Inhalt der AppSKlient Klasse aus AppServer.h
 // Konstruktor 
-AppSAKlient::AppSAKlient( SKlient *klient, AppServer *appS )
+AppSAKlient::AppSAKlient( SSLSKlient *klient, AppServer *appS )
     : Thread()
 {
     this->klient = klient;
-    unsigned char key[ 20 ] = { 14, 143, 241, 74, 52, 68, 158, 32, 83, 67, 205, 80, 206, 243, 151, 156, 46, 72, 120, 161 };
-    klient->setSendeKey( (char*)key, 20 );
-    klient->setEmpfangKey( (char*)key, 20 );
     name = new Text( "" );
     passwort = new Text( "" );
     adminId = 0;
@@ -214,7 +214,7 @@ void AppSAKlient::thread()
     while( 1 )
     {
         char c = 0;
-        if( !klient->getNachrichtEncrypted( &c, 1 ) )
+        if( !klient->getNachricht( &c, 1 ) )
             break;
         else
         {
@@ -224,23 +224,23 @@ void AppSAKlient::thread()
             case 1: // Login
                 if( 1 )
                 {
-                    klient->sendeEncrypted( "\1", 1 );
+                    klient->sende( "\1", 1 );
                     unsigned char nLen = 0;
-                    klient->getNachrichtEncrypted( (char*)&nLen, 1 );
+                    klient->getNachricht( (char*)&nLen, 1 );
                     char *n = new char[ nLen + 1 ];
                     n[ (int)nLen ] = 0;
                     if( nLen )
-                        klient->getNachrichtEncrypted( n, nLen );
+                        klient->getNachricht( n, nLen );
                     unsigned char pLen = 0;
-                    klient->getNachrichtEncrypted( (char*)&pLen, 1 );
+                    klient->getNachricht( (char*)&pLen, 1 );
                     char *p = new char[ pLen + 1 ];
                     p[ (int)pLen ] = 0;
                     if( pLen )
-                        klient->getNachrichtEncrypted( p, pLen );
+                        klient->getNachricht( p, pLen );
                     int adminId = appS->zDB()->istAdministrator( n, p );
                     if( adminId )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         name->setText( n );
                         passwort->setText( p );
                         this->adminId = adminId;
@@ -255,11 +255,11 @@ void AppSAKlient::thread()
                 adminId = 0;
                 name->setText( "" );
                 passwort->setText( "" );
-                klient->sendeEncrypted( "\1", 1 );
+                klient->sende( "\1", 1 );
                 break;
             case 3: // Trennen
                 br = 1;
-                klient->sendeEncrypted( "\1", 1 );
+                klient->sende( "\1", 1 );
                 break;
             case 4: // Server starten
                 if( !adminId )
@@ -271,7 +271,7 @@ void AppSAKlient::thread()
                         if( !appS->serverStarten() )
                             errorZuKlient( "Beim starten des Servers ist ein Fehler aufgetreten." );
                         else
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                     }
                     else
                         errorZuKlient( "Du bist nicht berechtigt den Server zu starten." );
@@ -285,7 +285,7 @@ void AppSAKlient::thread()
                     if( appS->zDB()->adminHatRecht( adminId, Admin_Recht::AppSBeenden ) )
                     {
                         appS->serverBeenden();
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                     }
                     else
                         errorZuKlient( "Du bist nicht berechtigt den Server zu beenden." );
@@ -316,7 +316,7 @@ void AppSAKlient::thread()
                     }
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "AppS: Der Server wird von Benutzer " << adminId << " heruntergefahren.\n";
                         appS->close();
                         br = 1;
@@ -343,7 +343,7 @@ void AppSAKlient::thread()
                         ok = 1;
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "AppS: Der Server wurde von Benutzer " << adminId << " terminiert.\n";
                         appS->close();
                         br = 1;
@@ -353,9 +353,9 @@ void AppSAKlient::thread()
             case 8: // Status Frage
                 if( 1 )
                 {
-                    klient->sendeEncrypted( "\1", 1 );
+                    klient->sende( "\1", 1 );
                     char status = (int)appS->isRunning();
-                    klient->sendeEncrypted( &status, 1 );
+                    klient->sende( &status, 1 );
                 }
                 break;
             default:
@@ -376,10 +376,10 @@ void AppSAKlient::thread()
 
 void AppSAKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehlernachricht zum Klient
 {
-    klient->sendeEncrypted( "\3", 1 );
+    klient->sende( "\3", 1 );
     char len = (char)textLength( nachricht );
-    klient->sendeEncrypted( &len, 1 );
-    klient->sendeEncrypted( nachricht, len );
+    klient->sende( &len, 1 );
+    klient->sende( nachricht, len );
 }
 
 

+ 3 - 3
AppServer/AppServer.h

@@ -16,7 +16,7 @@ class AppServer : public Thread
 {
 private:
     Server *server;
-    Server *aServer;
+    SSLServer *aServer;
     InitDatei *dat;
     AppSDatenbank *db;
     CRITICAL_SECTION cs;
@@ -54,7 +54,7 @@ public:
 class AppSAKlient : public Thread
 {
 private:
-    SKlient *klient;
+    SSLSKlient *klient;
     Text *name;
     Text *passwort;
     int adminId;
@@ -62,7 +62,7 @@ private:
 
 public:
     // Konstruktor 
-    AppSAKlient( SKlient *klient, AppServer *appS );
+    AppSAKlient( SSLSKlient *klient, AppServer *appS );
     // Destruktor 
     virtual ~AppSAKlient();
     // nicht constant 

+ 1 - 1
AppServer/main.cpp

@@ -37,7 +37,7 @@ int main()
 		dat->release();
 		exit( 1 );
 	}
-	const char *wichtig[] = { "ServerId", "DBBenutzer", "DBPasswort", "DBName", "DBIP", "DBPort", "PHP", "AccountActivationMail", "Aktiv" };
+	const char *wichtig[] = { "ServerId", "DBBenutzer", "DBPasswort", "DBName", "DBIP", "DBPort", "PHP", "AccountActivationMail", "Aktiv", "SSLCert", "SSLKey", "SSLPasswort" };
 	for( const char *w : wichtig )
 	{
 		if( !dat->wertExistiert( w ) )