Académique Documents
Professionnel Documents
Culture Documents
chat cryptée
par l’ AES
24 JANVIER 2021
GSTR 3
Réalisé par : AZGAOUI Hamza DARIF Rania
1
SOMMAIRE
INTRODUCTION
CRYPTAGE AES
DEVELOPPEMENT DE L’APPLICATION
TEST DE L’APPLICATION
2
Introduction:
Dans le cadre du module système embarqué 2, enseigné par Mr. Samir Adib,
nous avons été chargés de créer une application de chat cryptée avec l’AES
(Advanced Encryption Standard), nous avions alors développé deux applications, la
première était une application desktop programmée entièrement à l’aide du
langage python ; cette application est basée sur l’échange des messages texts
cryptés avec l’AES, ainsi que des fichiers et peu importe leurs formats, en outre
cette application fait appel à deux interfaces graphiques une pour le client et une
pour le server. La deuxième application est une application mobile développée en
Android Studio à l’aide du langage JAVA, permettant aussi l’échange des messages
texts cryptés avec l’AES, fonctionnant au niveau des équipements Android.
Le cryptage AES est une norme ou spécification de chiffrement comme RSA, DES, ...
On utilise l’AES, par exemple, pour chiffrer un fichier ou disque dur ou le stockage
de mot de passe comme les gestionnaires de mots de passe, la protection par mot
de passe de fichiers PDF ou de fichiers ZIP.
En effet, les applications telles que WhatsApp, Signal, VeraCrypt ou 7-zip et WinZip
utilisent AES pour chiffrer (crypter) les communications ou le contenu.
En clair donc, AES est très utilise pour protéger ses données.
Nous avons comme objectif principal d’implémenter le cryptage AES au
niveau de notre application de chat afin d’assurer le cryptage et le décryptage
des messages texts envoyés/reçus par deux clients.
3
Cryptage AES:
L'algorithme prend en entrée un bloc de 128 bits (16 octets), la clé fait 128, 192 ou
256 bits. Les 16 octets en entrée sont permutés selon une table définie au
préalable. Ces octets sont ensuite placés dans une matrice de 4x4 éléments et ses
lignes subissent une rotation vers la droite. L'incrément pour la rotation varie
selon le numéro de la ligne. Une transformation linéaire est ensuite appliquée sur
la matrice, elle consiste en la multiplication binaire de chaque élément de la
matrice avec des polynô mes issus d'une matrice auxiliaire, cette multiplication est
soumise à des règles spéciales selon GF(28) (groupe de Galois ou corps fini). La
transformation linéaire garantit une meilleure diffusion (propagation des bits dans
la structure) sur plusieurs tours.
4
Développement de l’application :
5
Code du fichier AES.java (SERVEUR)
6
Code du fichier AES.java
(MESSENGER)
7
Le code Script Serveur
@SuppressWarnings("deprecation")
public void run(){
SAES rsa=new SAES();
ui.jTextArea1.append("\nServer Thread " + ID + " running.");
while (true){
try{
Message msg = (Message) streamIn.readObject();
server.handle(ID, msg,rsa);
}
catch(Exception ioe){
System.out.println(ID + " ERROR reading: " + ioe.getMessage());
server.remove(ID);
stop();
}
}
}
9
public Database db;
try{
server = new ServerSocket(port);
port = server.getLocalPort();
ui.jTextArea1.append("Server startet. IP : " + InetAddress.getLocalHost() + ",
Port : " + server.getLocalPort());
start();
}
catch(IOException ioe){
ui.jTextArea1.append("Can not bind to port : " + port + "\nRetrying");
ui.RetryStart(0);
}
}
try{
server = new ServerSocket(port);
port = server.getLocalPort();
ui.jTextArea1.append("Server startet. IP : " + InetAddress.getLocalHost() + ",
Port : " + server.getLocalPort());
start();
}
catch(IOException ioe){
ui.jTextArea1.append("\nCan not bind to port " + port + ": " +
ioe.getMessage());
}
}
10
public void start(){
if (thread == null){
thread = new Thread(this);
thread.start();
}
}
@SuppressWarnings("deprecation")
public void stop(){
if (thread != null){
thread.stop();
thread = null;
}
}
11
}
}
else if(msg.type.equals("message")){
byte[] decrypte=rsa.decrypt(msg.chiffre);
12
String IP =
findUserThread(msg.sender).socket.getInetAddress().getHostAddress();
findUserThread(msg.recipient).send(new Message("upload_res", IP,
msg.content, msg.recipient));
}
else{
findUserThread(msg.recipient).send(new Message("upload_res",
msg.sender, msg.content, msg.recipient));
}
}
}
}
public void Announce(String type, String sender, String content){
Message msg = new Message(type, sender, content, "All");
for(int i = 0; i < clientCount; i++){
clients[i].send(msg);
}
}
@SuppressWarnings("deprecation")
public synchronized void remove(int ID){
int pos = findClient(ID);
if (pos >= 0){
ServerThread toTerminate = clients[pos];
ui.jTextArea1.append("\nRemoving client thread " + ID + " at " + pos);
if (pos < clientCount-1){
for (int i = pos+1; i < clientCount; i++){
clients[i-1] = clients[i];
}
}
clientCount--;
try{
toTerminate.close();
}
catch(IOException ioe){
ui.jTextArea1.append("\nError closing thread: " + ioe);
}
toTerminate.stop();
}
13
}
hist = ui.hist;
}
14
@Override
public void run()
{
boolean keepRunning = true;
while(keepRunning){
// try {
Message msg = null;
try {
msg = (Message) In.readObject();
System.out.println("brahim ");
} catch (IOException ex) {
Logger.getLogger(SocketClient.class.getName()).log(Level.SEVERE, null,
ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(SocketClient.class.getName()).log(Level.SEVERE, null,
ex);
}
System.out.println("Incoming : "+msg.toString());
if(msg.type.equals("rsacles")){
send(new Message("message",msg.sender,crypt,msg.recipient));
}
else if(msg.type.equals("message")){
if(msg.recipient.equals(ui.username)){
ui.jTextArea1.append("["+msg.sender +" > Me] : " + msg.content +
"\n");
}
else{
ui.jTextArea1.append("["+ msg.sender +" > "+ msg.recipient +"] : "
+ msg.content + "\n");
}
try{
hist.addMessage(msg, msgTime);
DefaultTableModel table = (DefaultTableModel)
ui.historyFrame.jTable1.getModel();
table.addRow(new Object[]{msg.sender, msg.content, "Me",
msgTime});
}
catch(Exception ex){}
}
}
else if(msg.type.equals("login")){
if(msg.content.equals("TRUE")){
ui.jButton2.setEnabled(false);
ui.jButton4.setEnabled(true); ui.jButton5.setEnabled(true);
ui.jTextArea1.append("[SERVER > Me] : Login Successful\n");
15
ui.jTextField3.setEnabled(false);
ui.jPasswordField1.setEnabled(false);
}
else{
ui.jTextArea1.append("[SERVER > Me] : Login Failed\n");
}
}
else if(msg.type.equals("test")){
ui.jButton1.setEnabled(false);
ui.jButton2.setEnabled(true);
ui.jTextField3.setEnabled(true); ui.jPasswordField1.setEnabled(true);
}
else if(msg.type.equals("newuser")){
if(!msg.content.equals(ui.username)){
boolean exists = false;
for(int i = 0; i < ui.model.getSize(); i++){
if(ui.model.getElementAt(i).equals(msg.content)){
exists = true; break;
}
}
if(!exists){ ui.model.addElement(msg.content); }
}
}
else if(msg.type.equals("signup")){
if(msg.content.equals("TRUE")){
ui.jButton2.setEnabled(false);
ui.jButton4.setEnabled(true); ui.jButton5.setEnabled(true);
ui.jTextArea1.append("[SERVER > Me] : Singup Successful\n");
}
else{
ui.jTextArea1.append("[SERVER > Me] : Signup Failed\n");
}
}
else if(msg.type.equals("signout")){
if(msg.content.equals(ui.username)){
ui.jTextArea1.append("["+ msg.sender +" > Me] : Bye\n");
ui.jButton1.setEnabled(true); ui.jButton4.setEnabled(false);
ui.clientThread.stop();
}
else{
ui.model.removeElement(msg.content);
ui.jTextArea1.append("["+ msg.sender +" > All] : "+ msg.content +"
has signed out\n");
}
}
else if(msg.type.equals("upload_req")){
16
if(JOptionPane.showConfirmDialog(ui, ("Accept '"+msg.content+"' from
"+msg.sender+" ?")) == 0){
ui.jButton5.setEnabled(false); ui.jButton6.setEnabled(false);
Upload upl = new Upload(addr, port, ui.file, ui);
Thread t = new Thread(upl);
t.start();
}
else{
ui.jTextArea1.append("[SERVER > Me] : "+msg.sender+" rejected file
request\n");
}
}
else{
ui.jTextArea1.append("[SERVER > Me] : Unknown message type\n");
}
/*}
catch(Exception ex) {
keepRunning = false;
ui.jTextArea1.append("[Application > Me] : Connection Failure\n");
ui.jButton4.setEnabled(false); ui.jButton5.setEnabled(false);
ui.jButton5.setEnabled(false);
17
ui.model.removeElementAt(i);
}
ui.clientThread.stop();
}
catch (IOException ex) {
System.out.println("Exception SocketClient send()");
}
}
18
19
Test de l’application :
Connexion Serveur
Inscription Utilisateur
20
Connexion Utilisateur
21
Messagerie
22
23