mirror of
https://github.com/LucasVbr/mini-chat.git
synced 2026-07-09 15:07:53 +00:00
Chat client serveur non securisé
This commit is contained in:
Generated
+97
-4
@@ -1,8 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" name="Changes" comment="" />
|
<list default="true" id="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" name="Changes" comment="">
|
||||||
<list id="84fd72d2-dba6-4275-83d3-958fab491b17" name="Changes by burgu" comment="" />
|
<change afterPath="$PROJECT_DIR$/src/reseau/AES.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/client/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/Client.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/serveur/Serveur.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/serveur/Serveur.java" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<list id="84fd72d2-dba6-4275-83d3-958fab491b17" name="Changes by burgu" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/client/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/Client.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/serveur/Serveur.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/serveur/Serveur.java" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@@ -18,6 +26,42 @@
|
|||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="LineStatusTrackerManager">
|
||||||
|
<file path="$PROJECT_DIR$/src/serveur/Serveur.java">
|
||||||
|
<ranges>
|
||||||
|
<range start1="5" end1="5" start2="5" end2="6" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="7" end1="7" start2="8" end2="12" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="9" end1="16" start2="14" end2="14" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="17" end1="17" start2="15" end2="17" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="18" end1="19" start2="18" end2="20" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="20" end1="21" start2="21" end2="22" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="24" end1="24" start2="25" end2="26" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="25" end1="26" start2="27" end2="29" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="28" end1="30" start2="31" end2="32" changelist="84fd72d2-dba6-4275-83d3-958fab491b17" />
|
||||||
|
<range start1="31" end1="31" start2="33" end2="35" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="32" end1="35" start2="36" end2="37" changelist="84fd72d2-dba6-4275-83d3-958fab491b17" />
|
||||||
|
<range start1="36" end1="37" start2="38" end2="42" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="38" end1="47" start2="43" end2="49" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="48" end1="48" start2="50" end2="51" changelist="84fd72d2-dba6-4275-83d3-958fab491b17" />
|
||||||
|
<range start1="49" end1="50" start2="52" end2="59" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="55" end1="56" start2="64" end2="64" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
</ranges>
|
||||||
|
</file>
|
||||||
|
<file path="$PROJECT_DIR$/src/client/Client.java">
|
||||||
|
<ranges>
|
||||||
|
<range start1="8" end1="8" start2="8" end2="9" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="10" end1="10" start2="11" end2="14" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="11" end1="12" start2="15" end2="16" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="14" end1="14" start2="18" end2="19" changelist="84fd72d2-dba6-4275-83d3-958fab491b17" />
|
||||||
|
<range start1="15" end1="15" start2="20" end2="21" changelist="84fd72d2-dba6-4275-83d3-958fab491b17" />
|
||||||
|
<range start1="16" end1="17" start2="22" end2="23" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="18" end1="20" start2="24" end2="26" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="28" end1="35" start2="34" end2="47" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
<range start1="36" end1="36" start2="48" end2="50" changelist="84fd72d2-dba6-4275-83d3-958fab491b17" />
|
||||||
|
<range start1="38" end1="40" start2="52" end2="53" changelist="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" />
|
||||||
|
</ranges>
|
||||||
|
</file>
|
||||||
|
</component>
|
||||||
<component name="MarkdownSettingsMigration">
|
<component name="MarkdownSettingsMigration">
|
||||||
<option name="stateVersion" value="1" />
|
<option name="stateVersion" value="1" />
|
||||||
</component>
|
</component>
|
||||||
@@ -34,10 +78,26 @@
|
|||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
"codeWithMe.voiceChat.enabledByDefault": "false"
|
"codeWithMe.voiceChat.enabledByDefault": "false",
|
||||||
|
"project.structure.last.edited": "Project",
|
||||||
|
"project.structure.proportion": "0.0",
|
||||||
|
"project.structure.side.proportion": "0.0"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RunManager" selected="Application.Client">
|
<component name="RunManager" selected="Application.AES">
|
||||||
|
<configuration name="AES" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="reseau.AES" />
|
||||||
|
<module name="projet-mini-chat" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="reseau.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<configuration name="Client" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
<configuration name="Client" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
<option name="MAIN_CLASS_NAME" value="client.Client" />
|
<option name="MAIN_CLASS_NAME" value="client.Client" />
|
||||||
<module name="projet-mini-chat" />
|
<module name="projet-mini-chat" />
|
||||||
@@ -51,6 +111,19 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="Client2" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="client.Client2" />
|
||||||
|
<module name="projet-mini-chat" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="client.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<configuration name="Serveur" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
<configuration name="Serveur" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
<option name="MAIN_CLASS_NAME" value="serveur.Serveur" />
|
<option name="MAIN_CLASS_NAME" value="serveur.Serveur" />
|
||||||
<module name="projet-mini-chat" />
|
<module name="projet-mini-chat" />
|
||||||
@@ -64,14 +137,33 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="Serveur2" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="serveur.Serveur2" />
|
||||||
|
<module name="projet-mini-chat" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="serveur.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Application.AES" />
|
||||||
|
<item itemvalue="Application.Client2" />
|
||||||
|
<item itemvalue="Application.Serveur2" />
|
||||||
<item itemvalue="Application.Client" />
|
<item itemvalue="Application.Client" />
|
||||||
<item itemvalue="Application.Serveur" />
|
<item itemvalue="Application.Serveur" />
|
||||||
</list>
|
</list>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Application.AES" />
|
||||||
<item itemvalue="Application.Client" />
|
<item itemvalue="Application.Client" />
|
||||||
<item itemvalue="Application.Serveur" />
|
<item itemvalue="Application.Serveur" />
|
||||||
|
<item itemvalue="Application.Client2" />
|
||||||
|
<item itemvalue="Application.Serveur2" />
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
@@ -84,6 +176,7 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1668515473737</updated>
|
<updated>1668515473737</updated>
|
||||||
<workItem from="1668515476841" duration="6049000" />
|
<workItem from="1668515476841" duration="6049000" />
|
||||||
|
<workItem from="1669119772164" duration="6834000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
+26
-13
@@ -6,18 +6,24 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.rmi.UnknownHostException;
|
import java.rmi.UnknownHostException;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
|
public static final Scanner scan = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
Socket echoSocket = null;
|
Socket serverSocket = null;
|
||||||
PrintWriter out = null;
|
PrintWriter out = null;
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
|
boolean ecoute = false;
|
||||||
|
|
||||||
|
// Création des Sockets
|
||||||
try {
|
try {
|
||||||
echoSocket = new Socket("localhost", 4444);
|
serverSocket = new Socket("localhost", 4444);
|
||||||
System.out.println("Connecté au serveur");
|
System.out.println("Connecté au serveur");
|
||||||
out = new PrintWriter(echoSocket.getOutputStream(), true);
|
out = new PrintWriter(serverSocket.getOutputStream(), true);
|
||||||
in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
|
in = new BufferedReader(new InputStreamReader(serverSocket.getInputStream()));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.out.println("Destination unknown");
|
System.out.println("Destination unknown");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
@@ -26,17 +32,24 @@ public class Client {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
|
String message = null;
|
||||||
String userInput;
|
do {
|
||||||
|
//ecoute d'un message
|
||||||
while ((userInput = stdIn.readLine()) != null) {
|
if (ecoute) {
|
||||||
out.println(userInput);
|
message = in.readLine();
|
||||||
System.out.println("echo: " + userInput);
|
System.out.printf("serveur > %s\n", message);
|
||||||
}
|
} else {
|
||||||
|
System.out.print("client > ");
|
||||||
|
message = scan.nextLine();
|
||||||
|
out.println(message);
|
||||||
|
}
|
||||||
|
ecoute = !ecoute;
|
||||||
|
} while (!message.equals("bye"));
|
||||||
|
|
||||||
|
//deconnexion
|
||||||
|
//fermeture des Sockets
|
||||||
out.close();
|
out.close();
|
||||||
in.close();
|
in.close();
|
||||||
stdIn.close();
|
serverSocket.close();
|
||||||
echoSocket.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package reseau;
|
||||||
|
|
||||||
|
import javax.crypto.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.security.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class AES {
|
||||||
|
|
||||||
|
public static byte[] genererCle() {
|
||||||
|
byte[] data;
|
||||||
|
byte[] result;
|
||||||
|
byte[] original = null;
|
||||||
|
try {
|
||||||
|
KeyGenerator kg = KeyGenerator.getInstance("DES");
|
||||||
|
Key key = kg.generateKey();
|
||||||
|
return key.getEncoded();
|
||||||
|
// Cipher cipher = Cipher.getInstance("DES") ;
|
||||||
|
// cipher.init(Cipher.ENCRYPT_MODE, key) ;
|
||||||
|
// data = "Hello World".getBytes() ;
|
||||||
|
// result = cipher.doFinal(data) ;
|
||||||
|
// cipher.init(Cipher.DECRYPT_MODE, key) ;
|
||||||
|
// original = cipher.doFinal(result) ;
|
||||||
|
// System.out.println("Decrypted data :" + Arrays.toString(original)) ;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] decrypter(byte[] msg, Key key) {
|
||||||
|
try {
|
||||||
|
Cipher cipher = Cipher.getInstance("DES") ;
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||||
|
return cipher.doFinal(msg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] encrypter(String msg, Key key){
|
||||||
|
try {
|
||||||
|
Cipher cipher = Cipher.getInstance("DES") ;
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, key) ;
|
||||||
|
return cipher.doFinal(msg.getBytes());
|
||||||
|
} catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sauvegarderFichier(Key key) {
|
||||||
|
Path fileName = Path.of("./cle.txt");
|
||||||
|
Files.writeString(fileName, new String(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
-27
@@ -3,56 +3,64 @@ package serveur;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Serveur {
|
public class Serveur {
|
||||||
|
|
||||||
|
private static final int PORT = 4444;
|
||||||
|
private static final Scanner scan = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ServerSocket serverSocket = null;
|
ServerSocket serverSocket = null;
|
||||||
try {
|
|
||||||
serverSocket = new ServerSocket(4444);
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Could not listen on port 4444");
|
|
||||||
System.exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket clientSocket = null;
|
Socket clientSocket = null;
|
||||||
|
|
||||||
|
// Connexion
|
||||||
try {
|
try {
|
||||||
clientSocket = serverSocket.accept();
|
serverSocket = new ServerSocket(PORT); // Crée le serveur
|
||||||
|
clientSocket = serverSocket.accept(); // On recherche un client
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Accept failed on port 4444");
|
System.out.printf("Erreur de connexion sur le port: %d\n", PORT);
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Un client a été trouvé
|
||||||
System.out.println("Client connecté");
|
System.out.println("Client connecté");
|
||||||
boolean quitte = false;
|
|
||||||
|
boolean connectee = true;
|
||||||
boolean reception = true;
|
boolean reception = true;
|
||||||
|
|
||||||
DataOutputStream envoi = null;
|
BufferedReader in = null;
|
||||||
BufferedReader recevoir = null;
|
|
||||||
|
PrintWriter out = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OutputStream outputStream = clientSocket.getOutputStream();
|
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||||
envoi = new DataOutputStream(outputStream);
|
|
||||||
recevoir = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
|
||||||
|
|
||||||
while (!quitte) {
|
out = new PrintWriter(clientSocket.getOutputStream(), true);
|
||||||
|
|
||||||
|
String message = null;
|
||||||
|
do {
|
||||||
if (reception) {
|
if (reception) {
|
||||||
String message = null;
|
message = in.readLine();
|
||||||
while (message == null){
|
System.out.printf("client > %s\n", message);
|
||||||
message = recevoir.readLine();
|
} else {
|
||||||
}
|
System.out.print("serveur > ");
|
||||||
while(message != null){
|
message = scan.nextLine();
|
||||||
System.out.println(message);
|
out.println(message);
|
||||||
message= recevoir.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reception = !reception;
|
reception = !reception;
|
||||||
}
|
} while (!message.equals("bye"));
|
||||||
|
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
|
clientSocket.close();
|
||||||
|
serverSocket.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user