Parcourir la source

Admin Server SSL verschlüsselt

Kolja Strohm il y a 6 ans
Parent
commit
17949aecb8
3 fichiers modifiés avec 38 ajouts et 38 suppressions
  1. 34 34
      KartenServer/KartenServer.cpp
  2. 3 3
      KartenServer/KartenServer.h
  3. 1 1
      KartenServer/main.cpp

+ 34 - 34
KartenServer/KartenServer.cpp

@@ -19,7 +19,10 @@ KartenServer::KartenServer( 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 << "KS: Starten des Admin Servers...\n";
     if( !aServer->verbinde( (unsigned short)TextZuInt( ini->zWert( "AdminServerPort" )->getText(), 10 ), 10 ) )
     {
@@ -61,7 +64,7 @@ void KartenServer::runn()
 {
     while( !end )
     {
-        SKlient *klient;
+        SSLSKlient *klient;
         klient = aServer->getKlient();
         if( end && klient )
         {
@@ -321,13 +324,10 @@ KartenServer *KartenServer::release()
 
 // Inhalt der KSAKlient Klasse aus KartenServer.h
 // Konstruktor 
-KSAKlient::KSAKlient( SKlient *klient, KartenServer *ks )
+KSAKlient::KSAKlient( SSLSKlient *klient, KartenServer *ks )
     : Thread()
 {
     this->klient = klient;
-    unsigned char key[ 20 ] = { 179, 126, 247, 108, 30, 201, 180, 160, 131, 216, 16, 47, 42, 31, 193, 200, 157, 86, 175, 133 };
-    klient->setSendeKey( (char*)key, 20 );
-    klient->setEmpfangKey( (char*)key, 20 );
     name = new Text( "" );
     passwort = new Text( "" );
     adminId = 0;
@@ -350,7 +350,7 @@ void KSAKlient::thread()
     while( 1 )
     {
         char c = 0;
-        if( !klient->getNachrichtEncrypted( &c, 1 ) )
+        if( !klient->getNachricht( &c, 1 ) )
             break;
         else
         {
@@ -360,23 +360,23 @@ void KSAKlient::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 = ks->zDB()->istAdministrator( n, p );
                     if( adminId )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         name->setText( n );
                         passwort->setText( p );
                         this->adminId = adminId;
@@ -391,11 +391,11 @@ void KSAKlient::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 )
@@ -412,7 +412,7 @@ void KSAKlient::thread()
                             err->release();
                         }
                         else
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                     }
                     else
                         errorZuKlient( "Du bist nicht berechtigt den Server zu starten." );
@@ -426,7 +426,7 @@ void KSAKlient::thread()
                     if( ks->zDB()->adminHatRecht( adminId, Admin_Recht::KSBeenden ) )
                     {
                         if( ks->serverBeenden() )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -471,7 +471,7 @@ void KSAKlient::thread()
                     }
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "KS: Der Server wird von Benutzer " << adminId << " heruntergefahren.\n";
                         ks->close();
                         br = 1;
@@ -498,7 +498,7 @@ void KSAKlient::thread()
                         ok = 1;
                     if( ok )
                     {
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                         std::cout << "KS: Der Server wurde von Benutzer " << adminId << " terminiert.\n";
                         ks->close();
                         br = 1;
@@ -515,8 +515,8 @@ void KSAKlient::thread()
                         if( ks->istAn() )
                             status = 2;
                     }
-                    klient->sendeEncrypted( "\1", 1 );
-                    klient->sendeEncrypted( &status, 1 );
+                    klient->sende( "\1", 1 );
+                    klient->sende( &status, 1 );
                 }
                 break;
             case 9: // Server pausieren
@@ -524,9 +524,9 @@ void KSAKlient::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( ks->zDB()->adminHatRecht( adminId, Admin_Recht::KSPausieren ) )
                     {
                         bool ok = 0;
@@ -535,7 +535,7 @@ void KSAKlient::thread()
                         else
                             ok = ks->serverFortsetzen();
                         if( ok )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -558,13 +558,13 @@ void KSAKlient::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( ks->zDB()->adminHatRecht( adminId, Admin_Recht::KSMKChange ) )
                     {
                         if( ks->setMaxKarten( maxK ) )
-                            klient->sendeEncrypted( "\1", 1 );
+                            klient->sende( "\1", 1 );
                         else
                         {
                             Text *err = new Text();
@@ -580,13 +580,13 @@ void KSAKlient::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 && ks->absturzKlient( klientId ) )
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                     else
-                        klient->sendeEncrypted( "\0", 1 );
+                        klient->sende( "\0", 1 );
                 }
                 break;
             default:
@@ -606,10 +606,10 @@ void KSAKlient::thread()
 
 void KSAKlient::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
KartenServer/KartenServer.h

@@ -18,7 +18,7 @@ class KartenServer : public Thread
 {
 private:
 	Server *server;
-	Server *aServer;
+	SSLServer *aServer;
 	InitDatei *ini;
 	KSDatenbank *db;
 	CRITICAL_SECTION cs;
@@ -71,7 +71,7 @@ public:
 class KSAKlient : public Thread
 {
 private:
-	SKlient *klient;
+	SSLSKlient *klient;
 	Text *name;
 	Text *passwort;
 	int adminId;
@@ -79,7 +79,7 @@ private:
 
 public:
 	// Konstruktor 
-	KSAKlient( SKlient *klient, KartenServer *ks );
+	KSAKlient( SSLSKlient *klient, KartenServer *ks );
 	// Destruktor 
 	virtual ~KSAKlient();
 	// nicht constant

+ 1 - 1
KartenServer/main.cpp

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