Bläddra i källkod

Admin Server SSL verschlüsselt

Kolja Strohm 6 år sedan
förälder
incheckning
0897a369e0
3 ändrade filer med 44 tillägg och 44 borttagningar
  1. 40 40
      Minigame Server/MinigameServer.cpp
  2. 3 3
      Minigame Server/MinigameServer.h
  3. 1 1
      Minigame Server/main.cpp

+ 40 - 40
Minigame Server/MinigameServer.cpp

@@ -19,7 +19,10 @@ MinigameServer::MinigameServer( 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 << "MS: Starten des Admin Servers...\n";
     if( !aServer->verbinde( (unsigned short)TextZuInt( ini->zWert( "AdminServerPort" )->getText(), 10 ), 10 ) )
     {
@@ -58,7 +61,7 @@ void MinigameServer::runn()
 {
     while( !end )
     {
-        SKlient *klient;
+        SSLSKlient *klient;
         klient = aServer->getKlient();
         if( end && klient )
         {
@@ -303,13 +306,10 @@ MinigameServer *MinigameServer::release()
 
 // Inhalt der LSAKlient Klasse aus LoginServer.h
 // Konstruktor 
-MSAKlient::MSAKlient( SKlient *klient, MinigameServer *ls )
+MSAKlient::MSAKlient( SSLSKlient *klient, MinigameServer *ls )
     : Thread()
 {
     this->klient = klient;
-    unsigned char key[ 20 ] = { 168, 13, 57, 219, 1, 54, 176, 97, 163, 80, 63, 101, 137, 132, 45, 103, 204, 225, 53, 197 };
-    klient->setSendeKey( (char*)key, 20 );
-    klient->setEmpfangKey( (char*)key, 20 );
     name = new Text( "" );
     passwort = new Text( "" );
     adminId = 0;
@@ -333,7 +333,7 @@ void MSAKlient::thread()
     while( 1 )
     {
         char c = 0;
-        if( !klient->getNachrichtEncrypted( &c, 1 ) )
+        if( !klient->getNachricht( &c, 1 ) )
             break;
         else
         {
@@ -343,23 +343,23 @@ void MSAKlient::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 = ms->zDB()->istAdministrator( n, p );
                     if( adminId )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         name->setText( n );
                         passwort->setText( p );
                         this->adminId = adminId;
@@ -374,11 +374,11 @@ void MSAKlient::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 )
@@ -395,7 +395,7 @@ void MSAKlient::thread()
                             err->release();
                         }
                         else
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                     }
                     else
                         errorZuKlient( "Du bist nicht berechtigt den Server zu starten." );
@@ -409,7 +409,7 @@ void MSAKlient::thread()
                     if( ms->zDB()->adminHatRecht( adminId, Admin_Recht::MSBeenden ) )
                     {
                         if( ms->serverBeenden() )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -454,7 +454,7 @@ void MSAKlient::thread()
                     }
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "MS: Der Server wird von Benutzer " << adminId << " heruntergefahren.\n";
                         ms->close();
                         br = 1;
@@ -481,7 +481,7 @@ void MSAKlient::thread()
                         ok = 1;
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "MS: Der Server wurde von Benutzer " << adminId << " terminiert.\n";
                         ms->close();
                         br = 1;
@@ -498,8 +498,8 @@ void MSAKlient::thread()
                         if( ms->istAn() )
                             status = 2;
                     }
-                    klient->sendeEncrypted( "\1", 1 );
-                    klient->sendeEncrypted( &status, 1 );
+                    klient->sende( "\1", 1 );
+                    klient->sende( &status, 1 );
                 }
                 break;
             case 9: // Server pausieren
@@ -507,9 +507,9 @@ void MSAKlient::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( ms->zDB()->adminHatRecht( adminId, Admin_Recht::MSPausieren ) )
                     {
                         bool ok = 0;
@@ -518,7 +518,7 @@ void MSAKlient::thread()
                         else
                             ok = ms->serverFortsetzen();
                         if( ok )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -541,13 +541,13 @@ void MSAKlient::thread()
                     errorZuKlient( "Du musst dich einloggen." );
                 else
                 {
-                    klient->sendeEncrypted( "\1", 1 );
+                    klient->sende( "\1", 1 );
                     int maxC = 0;
-                    klient->getNachrichtEncrypted( (char*)&maxC, 4 );
+                    klient->getNachricht( (char*)&maxC, 4 );
                     if( ms->zDB()->adminHatRecht( adminId, Admin_Recht::MSMCChange ) )
                     {
                         if( ms->setMaxKlients( maxC ) )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -563,13 +563,13 @@ void MSAKlient::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 && ms->absturzKlient( klientId ) )
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                     else
-                        klient->sendeEncrypted( "\0", 1 );
+                        klient->sende( "\0", 1 );
                 }
                 break;
             default:
@@ -589,10 +589,10 @@ void MSAKlient::thread()
 
 void MSAKlient::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 );
 }
 
 
@@ -718,7 +718,7 @@ void MSKlient::thread()
                 for( auto t = oList.getArray(); t.set && t.var; t++ )
                 {
                     l = (char)t.var->getLength();
-                    klient->sendeEncrypted( &l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( t.var->getText(), l );
                 }
                 break;
@@ -742,10 +742,10 @@ void MSKlient::thread()
                     int s = sList.get( i );
                     klient->sendeEncrypted( (char*)&s, 4 );
                     l = (char)pList.z( i )->getLength();
-                    klient->sendeEncrypted( &l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( pList.z( i )->getText(), l );
                     l = (char)oList.z( i )->getLength();
-                    klient->sendeEncrypted( &l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( oList.z( i )->getText(), l );
                 }
                 break;
@@ -770,7 +770,7 @@ void MSKlient::thread()
                 if( score )
                 {
                     l = (char)player.getLength();
-                    klient->sendeEncrypted( &l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( player.getText(), l );
                 }
                 break;
@@ -892,10 +892,10 @@ void MSKlient::thread()
                             if( ret == 1 )
                             {
                                 l = (char)textLength( mName );
-                                k->sendeEncrypted( &l, 1 );
+                                k->sendeEncrypted( (char*)&l, 1 );
                                 k->sendeEncrypted( mName, l );
                                 l = (char)textLength( oName );
-                                k->sendeEncrypted( &l, 1 );
+                                k->sendeEncrypted( (char*)&l, 1 );
                                 k->sendeEncrypted( oName, l );
                                 k->getNachrichtEncrypted( &ret, 1 );
                                 if( ret == 1 )

+ 3 - 3
Minigame Server/MinigameServer.h

@@ -16,7 +16,7 @@ class MinigameServer : public Thread
 {
 private:
     Server *server;
-    Server *aServer;
+    SSLServer *aServer;
     InitDatei *ini;
     MSDatenbank *db;
     CRITICAL_SECTION cs;
@@ -64,7 +64,7 @@ public:
 class MSAKlient : public Thread
 {
 private:
-    SKlient *klient;
+    SSLSKlient *klient;
     Text *name;
     Text *passwort;
     int adminId;
@@ -73,7 +73,7 @@ private:
 
 public:
     // Konstruktor 
-    MSAKlient( SKlient *klient, MinigameServer *ls );
+    MSAKlient( SSLSKlient *klient, MinigameServer *ls );
     // Destruktor 
     virtual ~MSAKlient();
     // nicht constant

+ 1 - 1
Minigame Server/main.cpp

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