Эх сурвалжийг харах

Admin Server SSL verschlüsselt

Kolja Strohm 6 жил өмнө
parent
commit
d3109a84f3

+ 34 - 34
ShopServer/ShopServer.cpp

@@ -19,7 +19,10 @@ ShopServer::ShopServer( InitDatei *zIni )
     ini = zIni->getThis();
     id = *zIni->zWert( "ServerId" );
     server = new Server();
-    aServer = new Server();
+    aServer = new SSLServer();
+    aServer->setPrivateKeyPassword( zIni->zWert( "SSLPasswort" )->getText() );
+    aServer->setCertificateFile( zIni->zWert( "SSLCert" )->getText() );
+    aServer->setPrivateKeyFile( zIni->zWert( "SSLKey" )->getText() );
     std::cout << "ShS: Starten des Admin Servers...\n";
     if( !aServer->verbinde( (unsigned short)TextZuInt( ini->zWert( "AdminServerPort" )->getText(), 10 ), 10 ) )
     {
@@ -60,7 +63,7 @@ void ShopServer::runn()
 {
     while( !end )
     {
-        SKlient *klient;
+        SSLSKlient *klient;
         klient = aServer->getKlient();
         if( end && klient )
         {
@@ -305,13 +308,10 @@ ShopServer *ShopServer::release()
 
 // Inhalt der ShSAKlient Klasse aus ShopServer.h
 // Konstruktor 
-ShSAKlient::ShSAKlient( SKlient *klient, ShopServer *shs )
+ShSAKlient::ShSAKlient( SSLSKlient *klient, ShopServer *shs )
     : Thread()
 {
     this->klient = klient;
-    unsigned char key[ 20 ] = { 86, 90, 94, 69, 141, 246, 13, 206, 83, 174, 74, 243, 59, 156, 8, 202, 134, 62, 56, 11 };
-    klient->setSendeKey( (char*)key, 20 );
-    klient->setEmpfangKey( (char*)key, 20 );
     name = new Text( "" );
     passwort = new Text( "" );
     adminId = 0;
@@ -334,7 +334,7 @@ void ShSAKlient::thread()
     while( 1 )
     {
         char c = 0;
-        if( !klient->getNachrichtEncrypted( &c, 1 ) )
+        if( !klient->getNachricht( &c, 1 ) )
             break;
         else
         {
@@ -344,23 +344,23 @@ void ShSAKlient::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 = shs->zDB()->istAdministrator( n, p );
                     if( adminId )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         name->setText( n );
                         passwort->setText( p );
                         this->adminId = adminId;
@@ -375,11 +375,11 @@ void ShSAKlient::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 )
@@ -396,7 +396,7 @@ void ShSAKlient::thread()
                             err->release();
                         }
                         else
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                     }
                     else
                         errorZuKlient( "Du bist nicht berechtigt den Server zu starten." );
@@ -410,7 +410,7 @@ void ShSAKlient::thread()
                     if( shs->zDB()->adminHatRecht( adminId, Admin_Recht::ShSBeenden ) )
                     {
                         if( shs->serverBeenden() )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -455,7 +455,7 @@ void ShSAKlient::thread()
                     }
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "ShS: Der Server wird von Benutzer " << adminId << " heruntergefahren.\n";
                         shs->close();
                         br = 1;
@@ -482,7 +482,7 @@ void ShSAKlient::thread()
                         ok = 1;
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "ShS: Der Server wurde von Benutzer " << adminId << " terminiert.\n";
                         shs->close();
                         br = 1;
@@ -499,8 +499,8 @@ void ShSAKlient::thread()
                         if( shs->istAn() )
                             status = 2;
                     }
-                    klient->sendeEncrypted( "\1", 1 );
-                    klient->sendeEncrypted( &status, 1 );
+                    klient->sende( "\1", 1 );
+                    klient->sende( &status, 1 );
                 }
                 break;
             case 9: // Server pausieren
@@ -508,9 +508,9 @@ void ShSAKlient::thread()
                     errorZuKlient( "Du musst dich einloggen." );
                 else
                 {
-                    klient->sendeEncrypted( "\1", 1 );
+                    klient->sende( "\1", 1 );
                     char pause = 0;
-                    klient->getNachrichtEncrypted( &pause, 1 );
+                    klient->getNachricht( &pause, 1 );
                     if( shs->zDB()->adminHatRecht( adminId, Admin_Recht::ShSPausieren ) )
                     {
                         bool ok = 0;
@@ -519,7 +519,7 @@ void ShSAKlient::thread()
                         else
                             ok = shs->serverFortsetzen();
                         if( ok )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -542,13 +542,13 @@ void ShSAKlient::thread()
                     errorZuKlient( "Du musst dich einloggen." );
                 else
                 {
-                    klient->sendeEncrypted( "\1", 1 );
+                    klient->sende( "\1", 1 );
                     int maxK = 0;
-                    klient->getNachrichtEncrypted( (char*)&maxK, 4 );
+                    klient->getNachricht( (char*)&maxK, 4 );
                     if( shs->zDB()->adminHatRecht( adminId, Admin_Recht::ShSMKChange ) )
                     {
                         if( shs->setMaxKarten( maxK ) )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -564,13 +564,13 @@ void ShSAKlient::thread()
             case 0xC: // klient absturtz
                 if( 1 )
                 {
-                    klient->sendeEncrypted( "\1", 1 );
+                    klient->sende( "\1", 1 );
                     int klientId = 0;
-                    klient->getNachrichtEncrypted( (char*)&klientId, 4 );
+                    klient->getNachricht( (char*)&klientId, 4 );
                     if( klientId && shs->absturzKlient( klientId ) )
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                     else
-                        klient->sendeEncrypted( "\0", 1 );
+                        klient->sende( "\0", 1 );
                 }
                 break;
             default:
@@ -590,10 +590,10 @@ void ShSAKlient::thread()
 
 void ShSAKlient::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
ShopServer/ShopServer.h

@@ -18,7 +18,7 @@ class ShopServer : public Thread
 {
 private:
 	Server *server;
-	Server *aServer;
+	SSLServer *aServer;
 	InitDatei *ini;
 	ShSDatenbank *db;
 	CRITICAL_SECTION cs;
@@ -67,7 +67,7 @@ public:
 class ShSAKlient : public Thread
 {
 private:
-	SKlient *klient;
+	SSLSKlient *klient;
 	Text *name;
 	Text *passwort;
 	int adminId;
@@ -75,7 +75,7 @@ private:
 
 public:
 	// Konstruktor 
-	ShSAKlient( SKlient *klient, ShopServer *shs );
+	ShSAKlient( SSLSKlient *klient, ShopServer *shs );
 	// Destruktor 
 	virtual ~ShSAKlient();
 	// nicht constant

+ 1 - 1
ShopServer/main.cpp

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