Regex : modif
This commit is contained in:
parent
dd033fd19c
commit
b3fc637914
@ -1,6 +1,5 @@
|
|||||||
package lightcontainer.domains.client;
|
package lightcontainer.domains.client;
|
||||||
|
|
||||||
import lightcontainer.domains.server.UnicastServerListener;
|
|
||||||
import lightcontainer.interfaces.ClientHandlerFFE;
|
import lightcontainer.interfaces.ClientHandlerFFE;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.interfaces.UnicastCHR;
|
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.SignoutRule;
|
||||||
import lightcontainer.protocol.rules.reader.SignupRule;
|
import lightcontainer.protocol.rules.reader.SignupRule;
|
||||||
import lightcontainer.protocol.rules.writer.SignErrorRule;
|
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.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClientHandler
|
* ClientHandler
|
||||||
*
|
* <p>
|
||||||
* <!> UNICAST CLIENT <!>
|
* <!> UNICAST CLIENT <!>
|
||||||
* Class communicating with the client, and
|
* Class communicating with the client, and
|
||||||
* intercepting and sending files to the client.
|
* intercepting and sending files to the client.
|
||||||
*
|
*
|
||||||
* @version 1.1
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
* @since 1.0
|
* @version 1.1
|
||||||
*
|
* @see Runnable
|
||||||
* @see Runnable
|
* @see AutoCloseable
|
||||||
* @see AutoCloseable
|
* @since 1.0
|
||||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
|
||||||
*/
|
*/
|
||||||
public class ClientHandler implements Runnable, AutoCloseable {
|
public class ClientHandler implements Runnable, AutoCloseable {
|
||||||
// Variables
|
// Variables
|
||||||
@ -60,21 +55,20 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
/**
|
/**
|
||||||
* Initialise the Client's Reader and Writer.
|
* Initialise the Client's Reader and Writer.
|
||||||
*
|
*
|
||||||
* @since 1.0
|
* @see BufferedReader
|
||||||
*
|
* @see PrintWriter
|
||||||
* @see BufferedReader
|
* @since 1.0
|
||||||
* @see PrintWriter
|
|
||||||
*/
|
*/
|
||||||
private void initClient() {
|
private void initClient() {
|
||||||
// Start the thread
|
// Start the thread
|
||||||
try {
|
try {
|
||||||
this.reader = new BufferedReader(new InputStreamReader(
|
this.reader = new BufferedReader(new InputStreamReader(
|
||||||
this.client.getInputStream(),
|
this.client.getInputStream(),
|
||||||
StandardCharsets.UTF_8
|
StandardCharsets.UTF_8
|
||||||
));
|
));
|
||||||
this.writer = new PrintWriter(new OutputStreamWriter(
|
this.writer = new PrintWriter(new OutputStreamWriter(
|
||||||
this.client.getOutputStream(),
|
this.client.getOutputStream(),
|
||||||
StandardCharsets.UTF_8
|
StandardCharsets.UTF_8
|
||||||
), true);
|
), true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -85,7 +79,7 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
* Thread Function
|
* Thread Function
|
||||||
* Start the dialogue with the client.
|
* Start the dialogue with the client.
|
||||||
*
|
*
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -153,11 +147,13 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
this.writer.close();
|
this.writer.close();
|
||||||
this.client.close();
|
this.client.close();
|
||||||
System.out.printf("[CLIENT] %s s'est déconnecté\n", context.getLogin());
|
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é
|
* Permet de vérifier si le client possède l'accès demandé
|
||||||
|
*
|
||||||
* @param ruleResult La règle
|
* @param ruleResult La règle
|
||||||
* @return TRUE si le client possède l'accès demandé
|
* @return TRUE si le client possède l'accès demandé
|
||||||
*/
|
*/
|
||||||
@ -175,7 +171,8 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
try {
|
try {
|
||||||
ruleResult.getClass().asSubclass(SigninRule.Result.class);
|
ruleResult.getClass().asSubclass(SigninRule.Result.class);
|
||||||
return true;
|
return true;
|
||||||
} catch (ClassCastException e2) { }
|
} catch (ClassCastException e2) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -193,23 +190,25 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérifie s'il s'âgit d'une demande de déconnexion
|
* Vérifie s'il s'âgit d'une demande de déconnexion
|
||||||
|
*
|
||||||
* @param ruleResult
|
* @param ruleResult
|
||||||
*/
|
*/
|
||||||
private void checkSignout(ProtocolReader.ProtocolResult ruleResult) {
|
private void checkSignout(ProtocolReader.ProtocolResult ruleResult) {
|
||||||
try {
|
try {
|
||||||
ruleResult.getClass().asSubclass(SignoutRule.Result.class);
|
ruleResult.getClass().asSubclass(SignoutRule.Result.class);
|
||||||
repository.disconnect(this);
|
repository.disconnect(this);
|
||||||
} catch (ClassCastException e2) { }
|
} catch (ClassCastException e2) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérifie s'il s'âgit d'une demande de déconnexion
|
* Vérifie s'il s'âgit d'une demande de déconnexion
|
||||||
* @param ruleResult
|
* @param ruleResult
|
||||||
private void checkSignError(ProtocolWriter.ProtocolResult ruleResult) {
|
private void checkSignError(ProtocolWriter.ProtocolResult ruleResult) {
|
||||||
if (ruleResult.getCommand().startsWith(SignErrorRule.NAME)) {
|
if (ruleResult.getCommand().startsWith(SignErrorRule.NAME)) {
|
||||||
System.out.println("Pas pu connecter");
|
System.out.println("Pas pu connecter");
|
||||||
repository.disconnect(this);
|
repository.disconnect(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -220,12 +219,15 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
this.wait();
|
this.wait();
|
||||||
} catch (InterruptedException e) { e.printStackTrace(); }
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet d'envoyer la réponse au client.
|
* Permet d'envoyer la réponse au client.
|
||||||
|
*
|
||||||
* @param response La réponse
|
* @param response La réponse
|
||||||
*/
|
*/
|
||||||
public void respond(ProtocolWriter.ProtocolResult response) {
|
public void respond(ProtocolWriter.ProtocolResult response) {
|
||||||
@ -239,7 +241,7 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
* AutoClosable Function
|
* AutoClosable Function
|
||||||
* Close the Client thread and resources.
|
* Close the Client thread and resources.
|
||||||
*
|
*
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
@ -5,7 +5,7 @@ public class StandardizedDefinitions {
|
|||||||
//Parties de regex non-utilisées en dehors de cette classe.
|
//Parties de regex non-utilisées en dehors de cette classe.
|
||||||
private final static String DIGIT = "[\\x30-\\x39]";
|
private final static String DIGIT = "[\\x30-\\x39]";
|
||||||
private final static String VISIBLECHAR = "[\\x20-\\xFF]";
|
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 BINARY = "[\\x00-\\xFF]";
|
||||||
private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]";
|
private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]";
|
||||||
private final static String DIGIT_LETTER = "[\\x30-\\x39\\x41-\\x5A\\x61-\\x7A]";
|
private final static String DIGIT_LETTER = "[\\x30-\\x39\\x41-\\x5A\\x61-\\x7A]";
|
||||||
|
@ -48,6 +48,7 @@ public class SavefileRule extends ProtocolReader {
|
|||||||
super(context);
|
super(context);
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
|
System.out.println(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,6 +76,8 @@ public class SavefileRule extends ProtocolReader {
|
|||||||
int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
||||||
if (encryptedFileSize < 0) throw new IOException();
|
if (encryptedFileSize < 0) throw new IOException();
|
||||||
|
|
||||||
|
System.out.println(encryptedFileSize);
|
||||||
|
|
||||||
String fileHash = SHA.hashFile(storagePath, this.filename);
|
String fileHash = SHA.hashFile(storagePath, this.filename);
|
||||||
|
|
||||||
// On met les données de la requête actuelle
|
// On met les données de la requête actuelle
|
||||||
|
@ -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": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user