Browse Source

Admin Server SSL verschlüsselt

Kolja Strohm 6 years ago
parent
commit
b022ffae42
3 changed files with 38 additions and 38 deletions
  1. 34 34
      NewsServer/NewsServer.cpp
  2. 3 3
      NewsServer/NewsServer.h
  3. 1 1
      NewsServer/main.cpp

+ 34 - 34
NewsServer/NewsServer.cpp

@@ -19,7 +19,10 @@ NewsServer::NewsServer( 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 << "IS: Starten des Admin Servers...\n";
 	if( !aServer->verbinde( (unsigned short)TextZuInt( ini->zWert( "AdminServerPort" )->getText(), 10 ), 10 ) )
 	{
@@ -58,7 +61,7 @@ void NewsServer::runn()
 {
 	while( !end )
 	{
-		SKlient *klient;
+		SSLSKlient *klient;
 		klient = aServer->getKlient();
 		if( end && klient )
 		{
@@ -298,13 +301,10 @@ NewsServer *NewsServer::release()
 
 // Inhalt der NSAKlient Klasse aus NewsServer.h
 // Konstruktor 
-NSAKlient::NSAKlient( SKlient *klient, NewsServer *ns )
+NSAKlient::NSAKlient( SSLSKlient *klient, NewsServer *ns )
 	: Thread()
 {
 	this->klient = klient;
-	unsigned char key[ 20 ] = { 118, 24, 81, 121, 254, 35, 132, 34, 118, 165, 132, 212, 137, 41, 253, 153, 239, 26, 1, 72 };
-	klient->setSendeKey( (char*)key, 20 );
-	klient->setEmpfangKey( (char*)key, 20 );
 	name = new Text( "" );
 	passwort = new Text( "" );
 	adminId = 0;
@@ -327,7 +327,7 @@ void NSAKlient::thread()
 	while( 1 )
 	{
 		char c = 0;
-		if( !klient->getNachrichtEncrypted( &c, 1 ) )
+		if( !klient->getNachricht( &c, 1 ) )
 			break;
 		else
 		{
@@ -337,23 +337,23 @@ void NSAKlient::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 = ns->zDB()->istAdministrator( n, p );
 					if( adminId )
 					{
-						klient->sendeEncrypted( "\1", 1 );
+						klient->sende( "\1", 1 );
 						name->setText( n );
 						passwort->setText( p );
 						this->adminId = adminId;
@@ -368,11 +368,11 @@ void NSAKlient::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 )
@@ -389,7 +389,7 @@ void NSAKlient::thread()
 							err->release();
 						}
 						else
-							klient->sendeEncrypted( "\1", 1 );
+							klient->sende( "\1", 1 );
 					}
 					else
 						errorZuKlient( "Du bist nicht berechtigt den Server zu starten." );
@@ -403,7 +403,7 @@ void NSAKlient::thread()
 					if( ns->zDB()->adminHatRecht( adminId, Admin_Recht::NSBeenden ) )
 					{
 						if( ns->serverBeenden() )
-							klient->sendeEncrypted( "\1", 1 );
+							klient->sende( "\1", 1 );
 						else
 						{
 							Text *err = new Text();
@@ -448,7 +448,7 @@ void NSAKlient::thread()
 					}
 					if( ok )
 					{
-						klient->sendeEncrypted( "\1", 1 );
+						klient->sende( "\1", 1 );
 						std::cout << "NS: Der Server wird von Benutzer " << adminId << " heruntergefahren.\n";
 						ns->close();
 						br = 1;
@@ -475,7 +475,7 @@ void NSAKlient::thread()
 						ok = 1;
 					if( ok )
 					{
-						klient->sendeEncrypted( "\1", 1 );
+						klient->sende( "\1", 1 );
 						std::cout << "NS: Der Server wurde von Benutzer " << adminId << " terminiert.\n";
 						ns->close();
 						br = 1;
@@ -492,8 +492,8 @@ void NSAKlient::thread()
 						if( ns->istAn() )
 							status = 2;
 					}
-					klient->sendeEncrypted( "\1", 1 );
-					klient->sendeEncrypted( &status, 1 );
+					klient->sende( "\1", 1 );
+					klient->sende( &status, 1 );
 				}
 				break;
 			case 9: // Server pausieren
@@ -501,9 +501,9 @@ void NSAKlient::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( ns->zDB()->adminHatRecht( adminId, Admin_Recht::NSPausieren ) )
 					{
 						bool ok = 0;
@@ -512,7 +512,7 @@ void NSAKlient::thread()
 						else
 							ok = ns->serverFortsetzen();
 						if( ok )
-							klient->sendeEncrypted( "\1", 1 );
+							klient->sende( "\1", 1 );
 						else
 						{
 							Text *err = new Text();
@@ -535,13 +535,13 @@ void NSAKlient::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( ns->zDB()->adminHatRecht( adminId, Admin_Recht::NSMCChange ) )
 					{
 						if( ns->setMaxKlients( maxC ) )
-							klient->sendeEncrypted( "\1", 1 );
+							klient->sende( "\1", 1 );
 						else
 						{
 							Text *err = new Text();
@@ -557,13 +557,13 @@ void NSAKlient::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 && ns->absturzKlient( klientId ) )
-                        klient->sendeEncrypted( "\1", 1 );
+                        klient->sende( "\1", 1 );
                     else
-                        klient->sendeEncrypted( "\0", 1 );
+                        klient->sende( "\0", 1 );
                 }
                 break;
 			default:
@@ -583,10 +583,10 @@ void NSAKlient::thread()
 
 void NSAKlient::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
NewsServer/NewsServer.h

@@ -17,7 +17,7 @@ class NewsServer : public Thread
 {
 private:
 	Server *server;
-	Server *aServer;
+	SSLServer *aServer;
 	InitDatei *ini;
 	NSDatenbank *db;
 	CRITICAL_SECTION cs;
@@ -64,7 +64,7 @@ public:
 class NSAKlient : public Thread
 {
 private:
-	SKlient *klient;
+	SSLSKlient *klient;
 	Text *name;
 	Text *passwort;
 	int adminId;
@@ -72,7 +72,7 @@ private:
 
 public:
 	// Konstruktor 
-	NSAKlient( SKlient *klient, NewsServer *ns );
+	NSAKlient( SSLSKlient *klient, NewsServer *ns );
 	// Destruktor 
 	virtual ~NSAKlient();
 	// nicht constant

+ 1 - 1
NewsServer/main.cpp

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