Regex : modif

This commit is contained in:
Maximilien LEDOUX 2022-03-15 17:06:29 +01:00
parent dd033fd19c
commit b3fc637914
4 changed files with 52 additions and 31 deletions

View File

@ -1,6 +1,5 @@
package lightcontainer.domains.client;
import lightcontainer.domains.server.UnicastServerListener;
import lightcontainer.interfaces.ClientHandlerFFE;
import lightcontainer.interfaces.ProtocolRepository;
import lightcontainer.interfaces.UnicastCHR;
@ -10,27 +9,23 @@ import lightcontainer.protocol.rules.reader.SigninRule;
import lightcontainer.protocol.rules.reader.SignoutRule;
import lightcontainer.protocol.rules.reader.SignupRule;
import lightcontainer.protocol.rules.writer.SignErrorRule;
import lightcontainer.protocol.rules.writer.SignOkRule;
import javax.crypto.BadPaddingException;
import javax.net.ssl.SSLHandshakeException;
import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
/**
* ClientHandler
*
* <p>
* <!> UNICAST CLIENT <!>
* Class communicating with the client, and
* intercepting and sending files to the client.
*
* @version 1.1
* @since 1.0
*
* @see Runnable
* @see AutoCloseable
* @author Jérémi NIHART <j.nihart@student.helmo.be>
* @author Jérémi NIHART <j.nihart@student.helmo.be>
* @version 1.1
* @see Runnable
* @see AutoCloseable
* @since 1.0
*/
public class ClientHandler implements Runnable, AutoCloseable {
// Variables
@ -60,21 +55,20 @@ public class ClientHandler implements Runnable, AutoCloseable {
/**
* Initialise the Client's Reader and Writer.
*
* @since 1.0
*
* @see BufferedReader
* @see PrintWriter
* @see BufferedReader
* @see PrintWriter
* @since 1.0
*/
private void initClient() {
// Start the thread
try {
this.reader = new BufferedReader(new InputStreamReader(
this.client.getInputStream(),
StandardCharsets.UTF_8
this.client.getInputStream(),
StandardCharsets.UTF_8
));
this.writer = new PrintWriter(new OutputStreamWriter(
this.client.getOutputStream(),
StandardCharsets.UTF_8
this.client.getOutputStream(),
StandardCharsets.UTF_8
), true);
} catch (IOException e) {
e.printStackTrace();
@ -85,7 +79,7 @@ public class ClientHandler implements Runnable, AutoCloseable {
* Thread Function
* Start the dialogue with the client.
*
* @since 1.0
* @since 1.0
*/
@Override
public void run() {
@ -153,11 +147,13 @@ public class ClientHandler implements Runnable, AutoCloseable {
this.writer.close();
this.client.close();
System.out.printf("[CLIENT] %s s'est déconnecté\n", context.getLogin());
} catch (IOException ignored) { }
} catch (IOException ignored) {
}
}
/**
* Permet de vérifier si le client possède l'accès demandé
*
* @param ruleResult La règle
* @return TRUE si le client possède l'accès demandé
*/
@ -175,7 +171,8 @@ public class ClientHandler implements Runnable, AutoCloseable {
try {
ruleResult.getClass().asSubclass(SigninRule.Result.class);
return true;
} catch (ClassCastException e2) { }
} catch (ClassCastException e2) {
}
}
return false;
@ -193,23 +190,25 @@ public class ClientHandler implements Runnable, AutoCloseable {
/**
* Vérifie s'il s'âgit d'une demande de déconnexion
*
* @param ruleResult
*/
private void checkSignout(ProtocolReader.ProtocolResult ruleResult) {
try {
ruleResult.getClass().asSubclass(SignoutRule.Result.class);
repository.disconnect(this);
} catch (ClassCastException e2) { }
} catch (ClassCastException e2) {
}
}
/**
* Vérifie s'il s'âgit d'une demande de déconnexion
* @param ruleResult
private void checkSignError(ProtocolWriter.ProtocolResult ruleResult) {
if (ruleResult.getCommand().startsWith(SignErrorRule.NAME)) {
System.out.println("Pas pu connecter");
repository.disconnect(this);
}
if (ruleResult.getCommand().startsWith(SignErrorRule.NAME)) {
System.out.println("Pas pu connecter");
repository.disconnect(this);
}
}
*/
@ -220,12 +219,15 @@ public class ClientHandler implements Runnable, AutoCloseable {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) { e.printStackTrace(); }
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* Permet d'envoyer la réponse au client.
*
* @param response La réponse
*/
public void respond(ProtocolWriter.ProtocolResult response) {
@ -239,7 +241,7 @@ public class ClientHandler implements Runnable, AutoCloseable {
* AutoClosable Function
* Close the Client thread and resources.
*
* @since 1.0
* @since 1.0
*/
@Override
public void close() {

View File

@ -5,7 +5,7 @@ public class StandardizedDefinitions {
//Parties de regex non-utilisées en dehors de cette classe.
private final static String DIGIT = "[\\x30-\\x39]";
private final static String VISIBLECHAR = "[\\x20-\\xFF]";
private final static String PASSCHAR = "[\\x20-\\xFF]";
private final static String PASSCHAR = "[\\x22-\\xFF]";
private final static String BINARY = "[\\x00-\\xFF]";
private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]";
private final static String DIGIT_LETTER = "[\\x30-\\x39\\x41-\\x5A\\x61-\\x7A]";

View File

@ -48,6 +48,7 @@ public class SavefileRule extends ProtocolReader {
super(context);
this.filename = filename;
this.size = size;
System.out.println(size);
}
@Override
@ -75,6 +76,8 @@ public class SavefileRule extends ProtocolReader {
int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
if (encryptedFileSize < 0) throw new IOException();
System.out.println(encryptedFileSize);
String fileHash = SHA.hashFile(storagePath, this.filename);
// On met les données de la requête actuelle

View File

@ -1 +1,17 @@
{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"Wi-Fi","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$.nNfX6PkXw34xsA8n2mSlekmRIQ/cU0wUlbnJmvfwGxtivMFJroXe","aes_key":"nfwaw3k6SpbvzAkzYDoVwcak8SHdRn+jQ8fY3iEmXPg=","files":[{"name":"test.txt","fileNameSalt":"jW4uvNQxRB36d0CL+/68uA==","size":53,"iv":"sSZkzD1gcrJscFR4gMoNFQ==","storage":["orglightcont01"]}]}]}
{
"unicast_port": 8000,
"multicast_ip": "224.66.66.1",
"multicast_port": 15502,
"network_interface": "",
"tls": true,
"storagePath": "C:\\Users\\ledou\\Documents\\ffe",
"users": [
{
"name": "aaaaa",
"password": "$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W",
"aes_key": "kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=",
"files": [
]
}
]
}