From 5dd70d9bcffc2e4fffc254a73506754c51dcfe0d Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Mar 2022 14:16:13 +0100 Subject: [PATCH 01/39] =?UTF-8?q?Regex=20:=20quelques=20impl=C3=A9mentatio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/StandardizedDefinitions.java | 4 ++-- .../protocol/rules/reader/EraseErrorRule.java | 4 +++- .../protocol/rules/reader/EraseOkRule.java | 4 +++- .../protocol/rules/reader/FilelistRule.java | 4 +++- .../protocol/rules/reader/GetFileRule.java | 9 ++++++--- .../lightcontainer/protocol/rules/reader/HelloRule.java | 6 ++++-- .../protocol/rules/reader/RemoveFileRule.java | 4 +++- .../protocol/rules/reader/RetrieveErrorRule.java | 4 +++- .../protocol/rules/reader/RetrieveOkRule.java | 6 ++++-- app/src/main/resources/appdata.json | 2 +- 10 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java index 5848f78..3e0d120 100644 --- a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java +++ b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java @@ -18,7 +18,7 @@ public class StandardizedDefinitions { private final static String DOMAIN = "[a-z-A-Z0-9\\.]{5,20}"; private final static String HASH_FILENAME = DIGIT_LETTER + "{50,200}"; private final static String HASH_FILECONTENT = DIGIT_LETTER + "{50,200}"; - private final static String FILE_INFO = HASH_FILENAME + BL + SIZE + BL + HASH_FILECONTENT; + private final static String FILE_INFO = "(" + HASH_FILENAME + ")" + BL + "(" + SIZE + ")" + BL + "(" + HASH_FILECONTENT + ")"; private final static String LOGIN = DIGIT_LETTER + "{5,20}"; //Regex à utiliser dans les différents protocoles. @@ -33,7 +33,7 @@ public class StandardizedDefinitions { public final static String SBE_ERASE_RESULT_OK = "^ERASE_OK" + LINE + "$"; public final static String SBE_ERASE_RESULT_ERROR = "^ERASE_ERROR" + LINE + "$"; public final static String FFE_RETRIEVE_FILE = "^RETRIEVEFILE" + BL + HASH_FILENAME + LINE + "$"; - public final static String SBE_RETRIEVE_RESULT_OK = "^RETRIEVE_OK" + BL + "(" + FILE_INFO + ")" + LINE + "$"; + public final static String SBE_RETRIEVE_RESULT_OK = "^RETRIEVE_OK" + BL + FILE_INFO + LINE + "$"; public final static String SBE_RETRIEVE_RESULT_ERROR = "^RETRIEVE_ERROR" + LINE + "$"; //Client demande à FFE une tâche. FFE répond à client. diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java index 1ce0b0b..e9dd3b2 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_ERROR; + public class EraseErrorRule extends ProtocolReader { - private static final String PATTERN = "^ERASE_ERROR\r\n$"; + private static final String PATTERN = SBE_ERASE_RESULT_ERROR; private static final String NAME = "ERASE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java index 9125c7a..04c9ab7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_OK; + public class EraseOkRule extends ProtocolReader { - private static final String PATTERN = "^ERASE_OK\r\n$"; + private static final String PATTERN = SBE_ERASE_RESULT_OK; private static final String NAME = "ERASE_OK"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index 18bfeea..2974746 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -7,12 +7,14 @@ import lightcontainer.protocol.rules.writer.FilesRule; import java.util.List; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_FILE_LIST; + /** * Règle permettant de récupérer la liste des fichiers d'un utilisateur */ public class FilelistRule extends ProtocolReader { // Constants - private static final String PATTERN = "^FILELIST\r\n$"; + private static final String PATTERN = CLIENT_FILE_LIST; private static final String NAME = "FILELIST"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java index a667672..1f75281 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java @@ -4,15 +4,16 @@ import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileErrorRule; -import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; import lightcontainer.protocol.rules.writer.RetrieveFileRule; import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_GET_FILE; + public class GetFileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^GETFILE ([^ !]{1,20})\r\n$"; + private static final String PATTERN = CLIENT_GET_FILE; private static final String NAME = "GETFILE"; // -- arguments private static final int FILE_NAME = 0; // Index file name. @@ -80,9 +81,11 @@ public class GetFileRule extends ProtocolReader { return result; } - /** TMP + /** + * TMP * TODO : But futur est de pouvoir en avoir plusieurs (sbe) * Cette méthode permet de choisir le domaine voulu. + * * @param storageIterator Les domaines * @return Le domain choisi */ diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index b2b797d..9fa53a1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -3,14 +3,16 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_HELLO; + /** * Règle permettant d'être alerter de l'annoncement d'un SBE */ public class HelloRule extends ProtocolReader { - private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; + private static final String PATTERN = SBE_HELLO; - private static final String NAME = "HELLO"; + private static final String NAME = "HELLO"; // Index du domain dans le tableau de donnée private static final int DOMAIN = 0; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java index 7024478..efe5768 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java @@ -9,9 +9,11 @@ import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_REMOVE_FILE; + public class RemoveFileRule extends ProtocolReader { - private static final String PATTERN = "^REMOVEFILE ([^ !]{1,20})\r\n$"; + private static final String PATTERN = CLIENT_REMOVE_FILE; private static final String NAME = "REMOVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java index 9bb8339..6b3a425 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileErrorRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_ERROR; + public class RetrieveErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = "^RETRIEVE_ERROR\r\n$"; + private static final String PATTERN = SBE_RETRIEVE_RESULT_ERROR; private static final String NAME = "RETRIEVE_ERROR"; // Variables diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index 412681e..af326ab 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -6,13 +6,14 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileOkRule; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.utils.FileReceiver; -import lightcontainer.utils.FileSender; import java.io.InputStream; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_OK; + public class RetrieveOkRule extends ProtocolReader { // Constants - private static final String PATTERN = "^RETRIEVE_OK ([A-Za-z0-9.]{50,200}) ([0-9]{1,10}) ([A-Za-z0-9.]{50,200})\r\n$"; + private static final String PATTERN = SBE_RETRIEVE_RESULT_OK; private static final String NAME = "RETRIEVE_OK"; // -- arguments private static final int HASHED_FILE_NAME = 0; // Index hashed filename @@ -45,6 +46,7 @@ public class RetrieveOkRule extends ProtocolReader { /** * Bitch has bettern than my money + * * @param reader Buffer rempli du fichier */ @Override diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 2baebe3..f473592 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[]}]} \ No newline at end of file +{"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$pUtcOXsQvLWYq1TJHTT8peb7ev/0YJFhrGUpj39InIstnSq1QcFGy","aes_key":"msCPN6nRJ9brhfLAZqmVuBkddtLH2ub1oEnlh73sEw8=","files":[{"name":"Reoutage.txt","fileNameSalt":"HX9Rd6VQgAzACtDHJ7S1aQ==","size":168,"iv":"unBbaL17c4pSaVi315RKaw==","storage":["orglightcont01"]}]}]} \ No newline at end of file From dd033fd19c3161fcd1369e2d65a882dc6a794520 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Mar 2022 15:39:58 +0100 Subject: [PATCH 02/39] =?UTF-8?q?Regex=20:=20toutes=20iml=C3=A9ment=C3=A9e?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/StandardizedDefinitions.java | 6 +++--- .../protocol/rules/reader/SavefileRule.java | 7 +++---- .../protocol/rules/reader/SendErrorRule.java | 7 ++----- .../lightcontainer/protocol/rules/reader/SendOkRule.java | 6 ++---- .../lightcontainer/protocol/rules/reader/SigninRule.java | 4 +++- .../protocol/rules/reader/SignoutRule.java | 4 +++- .../lightcontainer/protocol/rules/reader/SignupRule.java | 4 +++- .../protocol/rules/writer/EraseFileRule.java | 6 +++++- .../lightcontainer/protocol/rules/writer/FilesRule.java | 6 ++++-- .../protocol/rules/writer/GetFileErrorRule.java | 5 ++++- .../protocol/rules/writer/GetFileOkRule.java | 6 +++++- .../protocol/rules/writer/RemoveFileErrorRule.java | 5 ++++- .../protocol/rules/writer/RemoveFileOkRule.java | 6 ++++-- .../protocol/rules/writer/RetrieveFileRule.java | 5 ++++- .../protocol/rules/writer/SaveFileErrorRule.java | 9 ++++++--- .../protocol/rules/writer/SaveFileOkRule.java | 9 ++++++--- .../protocol/rules/writer/SendfileRule.java | 8 +++++--- .../protocol/rules/writer/SignErrorRule.java | 6 ++++-- .../lightcontainer/protocol/rules/writer/SignOkRule.java | 6 ++++-- app/src/main/resources/appdata.json | 2 +- 20 files changed, 75 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java index 3e0d120..d4da8fa 100644 --- a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java +++ b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java @@ -8,7 +8,7 @@ public class StandardizedDefinitions { private final static String PASSCHAR = "[\\x20-\\xFF]"; private final static String BINARY = "[\\x00-\\xFF]"; private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]"; - private final static String DIGIT_LETTER = DIGIT + "|" + LETTER; + private final static String DIGIT_LETTER = "[\\x30-\\x39\\x41-\\x5A\\x61-\\x7A]"; private final static String PORT = "(6553[\\x30-\\x35])|(655[\\x30-\\x32][\\x30-\\x39])|(65[\\x30-\\x34][\\x30-\\x32]{2})|(6[\\x30-\\x34][\\x30-\\x39]{3})|([\\x31-\\x35][\\x30-\\x39]{4})|([\\x30-\\x35]{0,5})|([\\x30-\\x39]{1,4})"; private final static String SIZE = DIGIT + "{1,10}"; private final static String LINE = "\\x0D\\x0A"; @@ -29,10 +29,10 @@ public class StandardizedDefinitions { public final static String FFE_SENDFILE = "^SENDFILE" + BL + FILE_INFO + LINE + "$"; public final static String SBE_SEND_RESULT_OK = "^SEND_OK" + LINE + "$"; public final static String SBE_SEND_RESULT_ERROR = "^SEND_ERROR" + LINE + "$"; - public final static String FFE_ERASE_FILE = "^ERASEFILE" + BL + HASH_FILENAME + LINE + "$"; + public final static String FFE_ERASE_FILE = "^ERASEFILE" + BL + "(" + HASH_FILENAME + ")" + LINE + "$"; public final static String SBE_ERASE_RESULT_OK = "^ERASE_OK" + LINE + "$"; public final static String SBE_ERASE_RESULT_ERROR = "^ERASE_ERROR" + LINE + "$"; - public final static String FFE_RETRIEVE_FILE = "^RETRIEVEFILE" + BL + HASH_FILENAME + LINE + "$"; + public final static String FFE_RETRIEVE_FILE = "^RETRIEVEFILE" + BL + "(" + HASH_FILENAME + ")" + LINE + "$"; public final static String SBE_RETRIEVE_RESULT_OK = "^RETRIEVE_OK" + BL + FILE_INFO + LINE + "$"; public final static String SBE_RETRIEVE_RESULT_ERROR = "^RETRIEVE_ERROR" + LINE + "$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 2d089d0..fe47531 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -4,17 +4,16 @@ import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; -import lightcontainer.protocol.rules.writer.SaveFileOkRule; import lightcontainer.protocol.rules.writer.SendfileRule; import lightcontainer.utils.AES_GCM; import lightcontainer.utils.FileReceiver; import lightcontainer.utils.SHA; import lightcontainer.utils.ShaHasher; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.security.NoSuchAlgorithmException; + +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SAVE_FILE; /** * Règle permettant de sauvegarder un fichier sur le SBE. @@ -22,7 +21,7 @@ import java.security.NoSuchAlgorithmException; */ public class SavefileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + private static final String PATTERN = CLIENT_SAVE_FILE; private static final String NAME = "SAVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index 1f395f1..b0f940f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -4,18 +4,15 @@ import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; -import lightcontainer.utils.ShaHasher; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_ERROR; /** * Règle permettant de de confirmer la sauvegrade d'un fichier. */ public class SendErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SEND_ERROR\r\n$"; + private static final String PATTERN = SBE_SEND_RESULT_ERROR; private static final String NAME = "SEND_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java index 3c32bca..2827deb 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java @@ -5,9 +5,7 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SaveFileOkRule; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_OK; /** * Règle permettant de de confirmer la sauvegrade d'un fichier. @@ -15,7 +13,7 @@ import java.nio.file.Path; public class SendOkRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SEND_OK\r\n$"; + private static final String PATTERN = SBE_SEND_RESULT_OK; private static final String NAME = "SEND_OK"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index 6f697b5..22605f7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -6,12 +6,14 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_IN; + /** * Règle permettant de gérer la connection d'un utilisateur */ public class SigninRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; + private static final String PATTERN = CLIENT_SIGN_IN; private static final String NAME = "SIGNIN"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java index 2b7a39f..9bad94d 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java @@ -3,12 +3,14 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_OUT; + /** * Règle demandant la déconnexion du client */ public class SignoutRule extends ProtocolReader { - private static final String PATTERN = "^SIGNOUT\r\n$"; + private static final String PATTERN = CLIENT_SIGN_OUT; public static final String NAME = "SIGNOUT"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index fbb56ed..db6703c 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -6,12 +6,14 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_UP; + /** * Règle permettant de gérer la création d'un utilisateur */ public class SignupRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SIGNUP ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; + private static final String PATTERN = CLIENT_SIGN_UP; private static final String NAME = "SIGNUP"; private static final int LOGIN = 0; private static final int PASSWORD = 1; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java index 4fcba04..9de71f0 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java @@ -2,14 +2,18 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_ERASE_FILE; + public class EraseFileRule extends ProtocolWriter { - private static final String PATTERN = "^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$"; + //"^ERASEFILE ([A-Za-z0-9]{50,200})\r\n$" + private static final String PATTERN = FFE_ERASE_FILE; public static String NAME = "ERASEFILE"; public EraseFileRule() { super(NAME, PATTERN); + System.out.println(PATTERN); } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java index e0f50c4..5dde723 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java @@ -2,12 +2,14 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_FILE_LIST_RESULT; + /** * Règle permettant de construire une commande contenant la liste des fichiers d'un utilisateur */ public class FilesRule extends ProtocolWriter { - - private static final String PATTERN = "^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; + //"^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$" + private static final String PATTERN = FFE_FILE_LIST_RESULT; public static final String NAME = "FILES"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java index 4a963d6..f76597b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java @@ -2,13 +2,16 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_ERROR; + /** * Règle utilisé dans le cas ou une erreur survient lors * de la demande de récupération d'un fichier. */ public class GetFileErrorRule extends ProtocolWriter { // Constants - private static final String PATTERN = "^GETFILE_ERROR\r\n$"; + //"^GETFILE_ERROR\r\n$" + private static final String PATTERN = FFE_GET_FILE_RESULT_ERROR; public static final String NAME = "GETFILE_ERROR"; // Constructors diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java index 08390bb..486dd71 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -6,9 +6,12 @@ import lightcontainer.utils.FileSender; import java.io.OutputStream; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_OK; + public class GetFileOkRule extends ProtocolWriter { // Constants - private static final String PATTERN = "^GETFILE_OK ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + //"^GETFILE_OK ([^ !]{1,20}) ([0-9]{1,10})\r\n$" + private static final String PATTERN = FFE_GET_FILE_RESULT_OK; public static final String NAME = "GETFILE_OK"; // -- params private static final int FILE_NAME = 0; // Index file name hashed @@ -37,6 +40,7 @@ public class GetFileOkRule extends ProtocolWriter { /** * Oh yeahh baby + * * @param writer Buffer à remplir qui sera envoyer via le réseau */ @Override diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java index 5e7517f..5fc60f1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java @@ -2,9 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_ERROR; + public class RemoveFileErrorRule extends ProtocolWriter { - private static final String PATTERN = "^REMOVEFILE_ERROR\r\n$"; + //"^REMOVEFILE_ERROR\r\n$" + private static final String PATTERN = FFE_REMOVE_ERROR; public static String NAME = "REMOVEFILE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java index a4ae784..6e5ab3e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java @@ -2,9 +2,11 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -public class RemoveFileOkRule extends ProtocolWriter { +import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_OK; - private static final String PATTERN = "^REMOVEFILE_OK\r\n$"; +public class RemoveFileOkRule extends ProtocolWriter { + //"^REMOVEFILE_OK\r\n$" + private static final String PATTERN = FFE_REMOVE_OK; public static String NAME = "REMOVEFILE_OK"; public RemoveFileOkRule() { diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java index c397129..951f92d 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java @@ -2,9 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_RETRIEVE_FILE; + public class RetrieveFileRule extends ProtocolWriter { // Constants - private static final String PATTERN = "^RETRIEVEFILE ([A-Za-z0-9.]{50,200})\r\n$"; + //"^RETRIEVEFILE ([A-Za-z0-9]{50,200})\r\n$" + private static final String PATTERN = FFE_RETRIEVE_FILE; public static final String NAME = "RETRIEVEFILE"; // Constructor diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index 090564d..d85feaa 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -8,12 +8,14 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SAVE_FILE_ERROR; + /** * Règle signifiant que la sauvegarde d'un fichier a échoué */ public class SaveFileErrorRule extends ProtocolWriter { - - private static final String PATTERN = "^SAVEFILE_ERROR\r\n$"; + //"^SAVEFILE_ERROR\r\n$" + private static final String PATTERN = FFE_SAVE_FILE_ERROR; public static final String NAME = "SAVEFILE_ERROR"; @@ -37,7 +39,8 @@ public class SaveFileErrorRule extends ProtocolWriter { hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt"))) ) )); - } catch (IOException e) {} + } catch (IOException e) { + } return result; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index fac890f..be28e09 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -7,12 +7,14 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SAVE_FILE_OK; + /** * Règle signifiant que la sauvegarde d'un fichier fût un succès */ public class SaveFileOkRule extends ProtocolWriter { - - private static final String PATTERN = "^SAVEFILE_OK\r\n$"; + //"^SAVEFILE_OK\r\n$" + private static final String PATTERN = FFE_SAVE_FILE_OK; public static final String NAME = "SAVEFILE_OK"; @@ -34,7 +36,8 @@ public class SaveFileOkRule extends ProtocolWriter { String hashedFileName = context.getHashedFileName(context.getDataString("fileName")); try { Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName))); - } catch (IOException e) {} + } catch (IOException e) { + } return result; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index 36eabff..8503887 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -6,19 +6,21 @@ import lightcontainer.utils.FileSender; import java.io.OutputStream; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SENDFILE; + /** * Règle envoyée au SBE, demandant la sauvegarde d'un fichier. */ public class SendfileRule extends ProtocolWriter { - - private static final String PATTERN = "^SENDFILE [A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200}\r\n$"; + //"^SENDFILE [A-Za-z0-9]{50,200} [0-9]{1,10} [A-Za-z0-9]{50,200}\r\n$" + private static final String PATTERN = FFE_SENDFILE; public static final String NAME = "SENDFILE"; private static final int HASHED_FILE_NAME = 0; // Index file name hashed. private static final int FILE_SIZE = 1; // Index file size. private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed. - + private String storagePath; public SendfileRule(String storagePath) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java index 096bb9a..34dfba6 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java @@ -2,12 +2,14 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_ERROR; + /** * Règle renvoyée au client lorsque l'authentification a échoué. */ public class SignErrorRule extends ProtocolWriter { - - private static final String PATTERN = "^SIGN_ERROR\r\n$"; + //"^SIGN_ERROR\r\n$" + private static final String PATTERN = FFE_SIGN_ERROR; public static final String NAME = "SIGN_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java index 6d6ef04..63b5019 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java @@ -2,12 +2,14 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_OK; + /** * Règle renvoyée au client lorsque l'authentification a réusie. */ public class SignOkRule extends ProtocolWriter { - - private static final String PATTERN = "^SIGN_OK\r\n$"; + //"^SIGN_OK\r\n$" + private static final String PATTERN = FFE_SIGN_OK; public static final String NAME = "SIGN_OK"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index f473592..c9bd585 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"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$pUtcOXsQvLWYq1TJHTT8peb7ev/0YJFhrGUpj39InIstnSq1QcFGy","aes_key":"msCPN6nRJ9brhfLAZqmVuBkddtLH2ub1oEnlh73sEw8=","files":[{"name":"Reoutage.txt","fileNameSalt":"HX9Rd6VQgAzACtDHJ7S1aQ==","size":168,"iv":"unBbaL17c4pSaVi315RKaw==","storage":["orglightcont01"]}]}]} \ No newline at end of file +{"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"]}]}]} \ No newline at end of file From b3fc6379142717981640ba3887112c6d26cee13a Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Mar 2022 17:06:29 +0100 Subject: [PATCH 03/39] Regex : modif --- .../domains/client/ClientHandler.java | 60 ++++++++++--------- .../protocol/StandardizedDefinitions.java | 2 +- .../protocol/rules/reader/SavefileRule.java | 3 + app/src/main/resources/appdata.json | 18 +++++- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 4181b7b..36014e6 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -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 - * + *

* 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 + * @author Jérémi NIHART + * @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() { diff --git a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java index d4da8fa..4bb0058 100644 --- a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java +++ b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java @@ -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]"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index fe47531..9ee5feb 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -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 diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index c9bd585..e1dc4af 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -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"]}]}]} \ No newline at end of file +{ + "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": [ + ] + } + ] +} \ No newline at end of file From c0ec403ec25bfb385be09e2e8de2f9f6064de0f4 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Mar 2022 17:21:21 +0100 Subject: [PATCH 04/39] Regex : modif --- .../lightcontainer/protocol/rules/reader/SavefileRule.java | 4 +--- .../lightcontainer/protocol/rules/writer/SendfileRule.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 9ee5feb..9128f97 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -13,15 +13,13 @@ import lightcontainer.utils.ShaHasher; import java.io.IOException; import java.io.InputStream; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SAVE_FILE; - /** * Règle permettant de sauvegarder un fichier sur le SBE. * Celui-ci va chiffre le contenu du fichier à l'aide de AES. */ public class SavefileRule extends ProtocolReader { // Constants - private static final String PATTERN = CLIENT_SAVE_FILE; + private static final String PATTERN = "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; private static final String NAME = "SAVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index 8503887..2895da1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -6,14 +6,12 @@ import lightcontainer.utils.FileSender; import java.io.OutputStream; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_SENDFILE; - /** * Règle envoyée au SBE, demandant la sauvegarde d'un fichier. */ public class SendfileRule extends ProtocolWriter { //"^SENDFILE [A-Za-z0-9]{50,200} [0-9]{1,10} [A-Za-z0-9]{50,200}\r\n$" - private static final String PATTERN = FFE_SENDFILE; + private static final String PATTERN = "^SENDFILE [A-Za-z0-9]{50,200} [0-9]{1,10} [A-Za-z0-9]{50,200}\\r\\n$"; public static final String NAME = "SENDFILE"; From 6f97cb6fc76f55685eaa6fabc823c5a41473f0cd Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Mar 2022 19:49:06 +0100 Subject: [PATCH 05/39] =?UTF-8?q?Regex=20:=20anciennes=20utilis=C3=A9es=20?= =?UTF-8?q?car=20bug=20avec=20nouvelles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/reader/EraseErrorRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/EraseOkRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/FilelistRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/GetFileRule.java | 4 +--- .../java/lightcontainer/protocol/rules/reader/HelloRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/RemoveFileRule.java | 4 +--- .../protocol/rules/reader/RetrieveErrorRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/RetrieveOkRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/SendErrorRule.java | 4 +--- .../java/lightcontainer/protocol/rules/reader/SendOkRule.java | 4 +--- .../java/lightcontainer/protocol/rules/reader/SigninRule.java | 4 +--- .../lightcontainer/protocol/rules/reader/SignoutRule.java | 4 +--- .../java/lightcontainer/protocol/rules/reader/SignupRule.java | 4 +--- .../lightcontainer/protocol/rules/writer/EraseFileRule.java | 4 +--- .../java/lightcontainer/protocol/rules/writer/FilesRule.java | 4 +--- .../protocol/rules/writer/GetFileErrorRule.java | 4 +--- .../lightcontainer/protocol/rules/writer/GetFileOkRule.java | 4 +--- .../protocol/rules/writer/RemoveFileErrorRule.java | 4 +--- .../protocol/rules/writer/RemoveFileOkRule.java | 4 +--- .../protocol/rules/writer/RetrieveFileRule.java | 4 +--- .../protocol/rules/writer/SaveFileErrorRule.java | 4 +--- .../lightcontainer/protocol/rules/writer/SaveFileOkRule.java | 4 +--- .../lightcontainer/protocol/rules/writer/SignErrorRule.java | 4 +--- .../java/lightcontainer/protocol/rules/writer/SignOkRule.java | 4 +--- 24 files changed, 24 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java index e9dd3b2..1ce0b0b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java @@ -5,11 +5,9 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_ERROR; - public class EraseErrorRule extends ProtocolReader { - private static final String PATTERN = SBE_ERASE_RESULT_ERROR; + private static final String PATTERN = "^ERASE_ERROR\r\n$"; private static final String NAME = "ERASE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java index 04c9ab7..9125c7a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java @@ -5,11 +5,9 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileOkRule; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_OK; - public class EraseOkRule extends ProtocolReader { - private static final String PATTERN = SBE_ERASE_RESULT_OK; + private static final String PATTERN = "^ERASE_OK\r\n$"; private static final String NAME = "ERASE_OK"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index 2974746..18bfeea 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -7,14 +7,12 @@ import lightcontainer.protocol.rules.writer.FilesRule; import java.util.List; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_FILE_LIST; - /** * Règle permettant de récupérer la liste des fichiers d'un utilisateur */ public class FilelistRule extends ProtocolReader { // Constants - private static final String PATTERN = CLIENT_FILE_LIST; + private static final String PATTERN = "^FILELIST\r\n$"; private static final String NAME = "FILELIST"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java index 1f75281..116fb6d 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java @@ -9,11 +9,9 @@ import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_GET_FILE; - public class GetFileRule extends ProtocolReader { // Constants - private static final String PATTERN = CLIENT_GET_FILE; + private static final String PATTERN = "^GETFILE ([^ !]{1,20})\r\n$"; private static final String NAME = "GETFILE"; // -- arguments private static final int FILE_NAME = 0; // Index file name. diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index 9fa53a1..4c0aa4b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -3,14 +3,12 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_HELLO; - /** * Règle permettant d'être alerter de l'annoncement d'un SBE */ public class HelloRule extends ProtocolReader { - private static final String PATTERN = SBE_HELLO; + private static final String PATTERN = "^HELLO ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$"; private static final String NAME = "HELLO"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java index efe5768..7024478 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java @@ -9,11 +9,9 @@ import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_REMOVE_FILE; - public class RemoveFileRule extends ProtocolReader { - private static final String PATTERN = CLIENT_REMOVE_FILE; + private static final String PATTERN = "^REMOVEFILE ([^ !]{1,20})\r\n$"; private static final String NAME = "REMOVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java index 6b3a425..9bb8339 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java @@ -5,11 +5,9 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileErrorRule; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_ERROR; - public class RetrieveErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = SBE_RETRIEVE_RESULT_ERROR; + private static final String PATTERN = "^RETRIEVE_ERROR\r\n$"; private static final String NAME = "RETRIEVE_ERROR"; // Variables diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index af326ab..76be719 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -9,11 +9,9 @@ import lightcontainer.utils.FileReceiver; import java.io.InputStream; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_OK; - public class RetrieveOkRule extends ProtocolReader { // Constants - private static final String PATTERN = SBE_RETRIEVE_RESULT_OK; + private static final String PATTERN = "^RETRIEVE_OK ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$"; private static final String NAME = "RETRIEVE_OK"; // -- arguments private static final int HASHED_FILE_NAME = 0; // Index hashed filename diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index b0f940f..520fa19 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -5,14 +5,12 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_ERROR; - /** * Règle permettant de de confirmer la sauvegrade d'un fichier. */ public class SendErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = SBE_SEND_RESULT_ERROR; + private static final String PATTERN = "^SEND_ERROR\r\n$"; private static final String NAME = "SEND_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java index 2827deb..d7fb36d 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java @@ -5,15 +5,13 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SaveFileOkRule; -import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_OK; - /** * Règle permettant de de confirmer la sauvegrade d'un fichier. */ public class SendOkRule extends ProtocolReader { // Constants - private static final String PATTERN = SBE_SEND_RESULT_OK; + private static final String PATTERN = "^SEND_OK\r\n$"; private static final String NAME = "SEND_OK"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index 22605f7..6f697b5 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -6,14 +6,12 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_IN; - /** * Règle permettant de gérer la connection d'un utilisateur */ public class SigninRule extends ProtocolReader { // Constants - private static final String PATTERN = CLIENT_SIGN_IN; + private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; private static final String NAME = "SIGNIN"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java index 9bad94d..2b7a39f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java @@ -3,14 +3,12 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_OUT; - /** * Règle demandant la déconnexion du client */ public class SignoutRule extends ProtocolReader { - private static final String PATTERN = CLIENT_SIGN_OUT; + private static final String PATTERN = "^SIGNOUT\r\n$"; public static final String NAME = "SIGNOUT"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index db6703c..fbb56ed 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -6,14 +6,12 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; -import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_UP; - /** * Règle permettant de gérer la création d'un utilisateur */ public class SignupRule extends ProtocolReader { // Constants - private static final String PATTERN = CLIENT_SIGN_UP; + private static final String PATTERN = "^SIGNUP ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; private static final String NAME = "SIGNUP"; private static final int LOGIN = 0; private static final int PASSWORD = 1; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java index 9de71f0..f0d9794 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java @@ -2,12 +2,10 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_ERASE_FILE; - public class EraseFileRule extends ProtocolWriter { //"^ERASEFILE ([A-Za-z0-9]{50,200})\r\n$" - private static final String PATTERN = FFE_ERASE_FILE; + private static final String PATTERN = "^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$"; public static String NAME = "ERASEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java index 5dde723..457f978 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java @@ -2,14 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_FILE_LIST_RESULT; - /** * Règle permettant de construire une commande contenant la liste des fichiers d'un utilisateur */ public class FilesRule extends ProtocolWriter { //"^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$" - private static final String PATTERN = FFE_FILE_LIST_RESULT; + private static final String PATTERN = "^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; public static final String NAME = "FILES"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java index f76597b..e43ec21 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java @@ -2,8 +2,6 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_ERROR; - /** * Règle utilisé dans le cas ou une erreur survient lors * de la demande de récupération d'un fichier. @@ -11,7 +9,7 @@ import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESUL public class GetFileErrorRule extends ProtocolWriter { // Constants //"^GETFILE_ERROR\r\n$" - private static final String PATTERN = FFE_GET_FILE_RESULT_ERROR; + private static final String PATTERN = "^GETFILE_ERROR\r\n$"; public static final String NAME = "GETFILE_ERROR"; // Constructors diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java index 486dd71..83d355e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -6,12 +6,10 @@ import lightcontainer.utils.FileSender; import java.io.OutputStream; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_OK; - public class GetFileOkRule extends ProtocolWriter { // Constants //"^GETFILE_OK ([^ !]{1,20}) ([0-9]{1,10})\r\n$" - private static final String PATTERN = FFE_GET_FILE_RESULT_OK; + private static final String PATTERN = "^GETFILE_OK ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; public static final String NAME = "GETFILE_OK"; // -- params private static final int FILE_NAME = 0; // Index file name hashed diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java index 5fc60f1..c071683 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java @@ -2,12 +2,10 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_ERROR; - public class RemoveFileErrorRule extends ProtocolWriter { //"^REMOVEFILE_ERROR\r\n$" - private static final String PATTERN = FFE_REMOVE_ERROR; + private static final String PATTERN = "^REMOVEFILE_ERROR\r\n$"; public static String NAME = "REMOVEFILE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java index 6e5ab3e..bc9fc39 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java @@ -2,11 +2,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_OK; - public class RemoveFileOkRule extends ProtocolWriter { //"^REMOVEFILE_OK\r\n$" - private static final String PATTERN = FFE_REMOVE_OK; + private static final String PATTERN = "^REMOVEFILE_OK\r\n$"; public static String NAME = "REMOVEFILE_OK"; public RemoveFileOkRule() { diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java index 951f92d..b64d1bb 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java @@ -2,12 +2,10 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_RETRIEVE_FILE; - public class RetrieveFileRule extends ProtocolWriter { // Constants //"^RETRIEVEFILE ([A-Za-z0-9]{50,200})\r\n$" - private static final String PATTERN = FFE_RETRIEVE_FILE; + private static final String PATTERN = "^RETRIEVEFILE ([A-Za-z0-9]{50,200})\r\n$"; public static final String NAME = "RETRIEVEFILE"; // Constructor diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index d85feaa..abf15f1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -8,14 +8,12 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_SAVE_FILE_ERROR; - /** * Règle signifiant que la sauvegarde d'un fichier a échoué */ public class SaveFileErrorRule extends ProtocolWriter { //"^SAVEFILE_ERROR\r\n$" - private static final String PATTERN = FFE_SAVE_FILE_ERROR; + private static final String PATTERN = "^SAVEFILE_ERROR\r\n$"; public static final String NAME = "SAVEFILE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index be28e09..5a01eec 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -7,14 +7,12 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_SAVE_FILE_OK; - /** * Règle signifiant que la sauvegarde d'un fichier fût un succès */ public class SaveFileOkRule extends ProtocolWriter { //"^SAVEFILE_OK\r\n$" - private static final String PATTERN = FFE_SAVE_FILE_OK; + private static final String PATTERN = "^SAVEFILE_OK\r\n$"; public static final String NAME = "SAVEFILE_OK"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java index 34dfba6..ca02cc6 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java @@ -2,14 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_ERROR; - /** * Règle renvoyée au client lorsque l'authentification a échoué. */ public class SignErrorRule extends ProtocolWriter { //"^SIGN_ERROR\r\n$" - private static final String PATTERN = FFE_SIGN_ERROR; + private static final String PATTERN = "^SIGN_ERROR\r\n$"; public static final String NAME = "SIGN_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java index 63b5019..05e0295 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java @@ -2,14 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_OK; - /** * Règle renvoyée au client lorsque l'authentification a réusie. */ public class SignOkRule extends ProtocolWriter { //"^SIGN_OK\r\n$" - private static final String PATTERN = FFE_SIGN_OK; + private static final String PATTERN = "^SIGN_OK\r\n$"; public static final String NAME = "SIGN_OK"; From 58662b3398f32b5c589f062021dfe85f518e95db Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 15 Mar 2022 20:36:09 +0100 Subject: [PATCH 06/39] =?UTF-8?q?Path=20probl=C3=A8me=20qui=20emp=C3=AAcha?= =?UTF-8?q?it=20la=20sauvegarde=20des=20fichiers=20dont=20la=20taille=20?= =?UTF-8?q?=C3=A9tait=20inf=C3=A9rieur=20au=20BUFFER=20(1024)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/writer/SaveFileErrorRule.java | 3 +++ app/src/main/resources/appdata.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index 090564d..dca98d8 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -31,6 +31,7 @@ public class SaveFileErrorRule extends ProtocolWriter { // Suppression du fichier temporaire dans le stockage du FFE ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + context.getDataString("fileName")); + /* try { Files.deleteIfExists(Path.of( String.format("%s/%s", this.storagePath, @@ -39,6 +40,8 @@ public class SaveFileErrorRule extends ProtocolWriter { )); } catch (IOException e) {} + */ + return result; } } diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 1b71617..19b94ab 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"README.md","fileNameSalt":"QnjgVrrW2KADUYUdeD/KcQ==","size":17,"iv":"E5JtY/JrH1B447F/my8Hkg==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"main.py","fileNameSalt":"PLQB1QjPaKdfdM+zjywxcQ==","size":854,"iv":"UnkiNxFMYsRcw5fsEkr+5w==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From 88fe097c0161c13119272220f72d918af3b11ac1 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 11:46:09 +0100 Subject: [PATCH 07/39] =?UTF-8?q?Optimisation=20l=C3=A9g=C3=A8re=20du=20co?= =?UTF-8?q?de=20+=20correction=20orthographe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 8 +- .../java/lightcontainer/domains/Task.java | 14 +- .../domains/client/ClientHandler.java | 8 +- .../domains/client/Context.java | 8 +- .../domains/client/RequestBundle.java | 12 +- .../domains/client/StoreProcessor.java | 31 +++-- .../lightcontainer/enumerations/TaskType.java | 2 +- .../interfaces/ClientHandlerFFE.java | 1 + .../interfaces/MulticastSPR.java | 3 + .../interfaces/ProtocolRepository.java | 2 +- .../interfaces/StoreProcessorFFE.java | 6 +- .../lightcontainer/interfaces/UnicastCHR.java | 3 + .../protocol/ProtocolReader.java | 3 +- .../protocol/ProtocolWriter.java | 9 +- .../protocol/rules/reader/RemoveFileRule.java | 1 + .../protocol/rules/reader/RetrieveOkRule.java | 9 +- .../protocol/rules/reader/SavefileRule.java | 6 +- .../protocol/rules/reader/SendErrorRule.java | 2 +- .../protocol/rules/reader/SigninRule.java | 2 +- .../protocol/rules/reader/SignupRule.java | 2 +- .../protocol/rules/writer/GetFileOkRule.java | 12 +- .../protocol/rules/writer/SaveFileOkRule.java | 3 +- .../protocol/rules/writer/SendfileRule.java | 2 +- .../repository/ClientHandlerRepository.java | 24 ++-- .../repository/FileFrontEnd.java | 4 +- .../repository/StoreProcessorRepository.java | 22 +-- .../lightcontainer/storage/AppConfig.java | 1 + .../java/lightcontainer/utils/AES_GCM.java | 129 ++++++++---------- .../lightcontainer/utils/FileReceiver.java | 21 ++- .../java/lightcontainer/utils/FileSender.java | 21 +-- .../java/lightcontainer/utils/NetChooser.java | 12 +- .../main/java/lightcontainer/utils/SHA.java | 29 ++-- 32 files changed, 217 insertions(+), 195 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 862211f..31d329f 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -23,7 +23,7 @@ public class App { public static void main(String[] args) { setupVM(); Repository repositoryStorage = prepareStorage(); - + // Create all repository ClientHandlerRepository clientRep = new ClientHandlerRepository(); StoreProcessorRepository storeRep = new StoreProcessorRepository(); @@ -87,9 +87,9 @@ public class App { } private static void setupVM() { - System.setProperty("javax.net.ssl.keyStore","../ffe.labo.swilabus.com.p12"); - System.setProperty("javax.net.ssl.keyStorePassword","labo2022"); - System.setProperty("https.protocols","TLSv1.3"); + System.setProperty("javax.net.ssl.keyStore", "../ffe.labo.swilabus.com.p12"); + System.setProperty("javax.net.ssl.keyStorePassword", "labo2022"); + System.setProperty("https.protocols", "TLSv1.3"); } } diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 4a89b7b..2ae95ed 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -10,13 +10,13 @@ import lightcontainer.protocol.ProtocolWriter; public class Task { // Variables private TaskStatus status; - private ProtocolWriter.ProtocolResult command; + private final ProtocolWriter.ProtocolResult command; /** - * Défini le context courrant dans laquelle la tâche opère + * Défini le context courant dans laquelle la tâche opère */ - private Context context; + private final Context context; public Task(Context context, TaskStatus status, ProtocolWriter.ProtocolResult command) { this.context = context; @@ -26,17 +26,18 @@ public class Task { /** * Permet de créer une instance de la class {@link Task} + * * @param context Context à utiliser pour cette tâche * @param command Commande à exécuter * @return L'instance de la tâche créée */ public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) { - Task task = new Task(context, TaskStatus.PENDING, command); - return task; + return new Task(context, TaskStatus.PENDING, command); } /** * Permet de savoir si la réponse est destinée au client + * * @param storeDomain Nom du store back end fournissant la réponse. * @return TRUE si le client doit recevoir cette réponse. */ @@ -46,6 +47,7 @@ public class Task { /** * Permet de récupérer le login du client associé à la tâche + * * @return Login du client */ public String getClient() { @@ -54,6 +56,7 @@ public class Task { /** * Permet de récupérer la commande à executer + * * @return Commande à exécuter */ public ProtocolWriter.ProtocolResult getCommand() { @@ -62,6 +65,7 @@ public class Task { /** * Permet de définir le StorBackEnd à utiliser pour cette tâche + * * @param storeDomain Le StorBackEnd à utiliser */ public void setDomain(String storeDomain) { diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 36014e6..5a5b439 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -29,12 +29,12 @@ import java.nio.charset.StandardCharsets; */ public class ClientHandler implements Runnable, AutoCloseable { // Variables - private ClientHandlerFFE fileFrontEnd; + private final ClientHandlerFFE fileFrontEnd; private final Socket client; - private ProtocolRepository protocolRep; - private Context context; + private final ProtocolRepository protocolRep; + private final Context context; private boolean client_run; - private UnicastCHR repository; + private final UnicastCHR repository; private BufferedReader reader; diff --git a/app/src/main/java/lightcontainer/domains/client/Context.java b/app/src/main/java/lightcontainer/domains/client/Context.java index 7864ca4..dc143a1 100644 --- a/app/src/main/java/lightcontainer/domains/client/Context.java +++ b/app/src/main/java/lightcontainer/domains/client/Context.java @@ -107,7 +107,7 @@ public class Context { } /** - * Permet d'ajouter des données pour la requête courrante + * Permet d'ajouter des données pour la requête courante * * @param key La clé permettant de retrouver la valeur * @param value La valeur associée à la clé @@ -117,7 +117,7 @@ public class Context { } /** - * Permet d'ajouter des données pour la requête courrante + * Permet d'ajouter des données pour la requête courante * * @param key La clé permettant de retrouver la valeur * @param value La valeur associée à la clé @@ -127,7 +127,7 @@ public class Context { } /** - * Permet de récupérer des données pour la requête courrante + * Permet de récupérer des données pour la requête courante * * @param key La clé permettant de retrouver la valeur * @return La valeur associée à la clé ou null @@ -137,7 +137,7 @@ public class Context { } /** - * Permet de récupérer des données pour la requête courrante + * Permet de récupérer des données pour la requête courante * * @param key La clé permettant de retrouver la valeur * @return La valeur associée à la clé diff --git a/app/src/main/java/lightcontainer/domains/client/RequestBundle.java b/app/src/main/java/lightcontainer/domains/client/RequestBundle.java index 8e32156..6d9fd09 100644 --- a/app/src/main/java/lightcontainer/domains/client/RequestBundle.java +++ b/app/src/main/java/lightcontainer/domains/client/RequestBundle.java @@ -5,13 +5,14 @@ import java.util.Map; public class RequestBundle { - private Map stringData = new HashMap<>(); + private final Map stringData = new HashMap<>(); - private Map intData = new HashMap<>(); + private final Map intData = new HashMap<>(); /** * Permet d'ajouter des String - * @param key La clé permettant de retrouver la valeur + * + * @param key La clé permettant de retrouver la valeur * @param value La valeur associée à la clé */ public void putString(String key, String value) { @@ -20,7 +21,8 @@ public class RequestBundle { /** * Permet d'ajouter des int - * @param key La clé permettant de retrouver la valeur + * + * @param key La clé permettant de retrouver la valeur * @param value La valeur associée à la clé */ public void putInt(String key, int value) { @@ -29,6 +31,7 @@ public class RequestBundle { /** * Permet de récupérer des données string + * * @param key La clé permettant de retrouver la valeur * @return La valeur associée à la clé ou null */ @@ -38,6 +41,7 @@ public class RequestBundle { /** * Permet de récupérer des données int + * * @param key La clé permettant de retrouver la valeur * @return La valeur associée à la clé */ diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index d7158f6..9016510 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -8,23 +8,21 @@ import lightcontainer.protocol.ProtocolWriter; import java.io.*; import java.net.Socket; -import java.net.SocketException; import java.nio.charset.StandardCharsets; import java.util.Objects; /** * StoreProcessor - * + *

* MULTICAST CLIENT * Class communicating with the storebackend and * processing the tasks in the FileFrontEnd * - * @version 1.1 - * @since 1.0 - * - * @see Runnable - * @see AutoCloseable - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.1 + * @see Runnable + * @see AutoCloseable + * @since 1.0 */ public class StoreProcessor extends Thread implements AutoCloseable { // Variables @@ -37,7 +35,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { private Context context; private PrintWriter writer; private ProtocolWriter.ProtocolResult protocolResult; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe, ProtocolRepository protocolRep) { @@ -95,7 +93,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { } catch (IOException writeException) { // Si SBE fermé System.out.println("STOPPER"); // Envoie au client que la requête n'a pu être traitée - alertAvalaible(null); + alertAvailable(null); break; } @@ -110,14 +108,14 @@ public class StoreProcessor extends Thread implements AutoCloseable { this.store.getInputStream() ); - alertAvalaible(responseResult.getResultCommand()); + alertAvailable(responseResult.getResultCommand()); } else { System.out.println("StoreBackEnd result: Commande null"); - alertAvalaible(null); + alertAvailable(null); } } else { System.out.println("StoreBackEnd: Commande null"); - alertAvalaible(null); + alertAvailable(null); } } catch (IOException exception) { @@ -139,6 +137,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { /** * Permet de demander au StoreBackEnd d'effectuer une commande + * * @param protocolResult La commande à effectuer */ public void executeCommand(Context context, ProtocolWriter.ProtocolResult protocolResult) { @@ -152,7 +151,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { /** * Permet de déclarer le StoreBackEnd disponible */ - private void alertAvalaible(ProtocolWriter.ProtocolResult responseCommand) { + private void alertAvailable(ProtocolWriter.ProtocolResult responseCommand) { synchronized (this) { this.protocolResult = null; if (responseCommand == null) { @@ -169,7 +168,9 @@ public class StoreProcessor extends Thread implements AutoCloseable { synchronized (this) { try { this.wait(); - } catch (InterruptedException e) { e.printStackTrace(); } + } catch (InterruptedException e) { + e.printStackTrace(); + } } } diff --git a/app/src/main/java/lightcontainer/enumerations/TaskType.java b/app/src/main/java/lightcontainer/enumerations/TaskType.java index 347e6ce..6a59ca3 100644 --- a/app/src/main/java/lightcontainer/enumerations/TaskType.java +++ b/app/src/main/java/lightcontainer/enumerations/TaskType.java @@ -3,7 +3,7 @@ package lightcontainer.enumerations; import lightcontainer.domains.Task; /** - * enumeration to define the type of a {@link Task}. + * enumeration to define the type of {@link Task}. */ public enum TaskType { SEND, diff --git a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java index 30b6b1a..5e5074d 100644 --- a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java @@ -13,6 +13,7 @@ public interface ClientHandlerFFE { /** * Demande le traitement d'une commande + * * @param context Context de la requête * @param command Commande à traiter */ diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 5727721..7d5b83a 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -11,12 +11,14 @@ import lightcontainer.repository.StoreProcessorRepository; public interface MulticastSPR { /** * Setter, allow to define the ServerListener of a repository. + * * @param server ServerListener to set as default. */ void setServerListener(MulticastServerListener server); /** * Add a StorePorcessor. + * * @param store Store processor to add. */ boolean addStore(StoreProcessor store); @@ -36,6 +38,7 @@ public interface MulticastSPR { /** * Permet de déconnecter un SBE + * * @param domain Le domaine du SBE à déconnecter */ void closeStore(String domain); diff --git a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java index ccae2fe..d707f39 100644 --- a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java +++ b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java @@ -8,7 +8,7 @@ public interface ProtocolRepository { T executeReader(Context context, String data); - T executeWriter(Context context, String cmdName, String... data); + T executeWriter(Context context, String cmdName, String... data); void addReader(ProtocolReader reader); diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java index 15e3561..8848242 100644 --- a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -10,13 +10,15 @@ import lightcontainer.repository.FileFrontEnd; public interface StoreProcessorFFE { /** * Allows a {@link StoreProcessor} to notify the FFE that it's available. - * @param store The store processor that is now available. - * @param responseCommand + * + * @param store The store processor that is now available. + * @param response */ void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response); /** * Permet de déconnecter un SBE + * * @param domain Le domaine du SBE à déconnecter */ void onStoreDisconnect(String domain); diff --git a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java index 53af817..21441b3 100644 --- a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java +++ b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java @@ -12,18 +12,21 @@ import lightcontainer.repository.ClientHandlerRepository; public interface UnicastCHR { /** * Setter, allow to define the ServerListener of a repository. + * * @param server ServerListener to set as default. */ void setServerListener(UnicastServerListener server); /** * Add a ClientHandler. + * * @param client Client Handler to add. */ void addClient(ClientHandler client); /** * Permet de demander la déconnection d'un client + * * @param client Le client à déconnecter */ void disconnect(ClientHandler client); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 634f0af..b6e4c0f 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -95,7 +95,8 @@ public abstract class ProtocolReader { * * @param reader Buffer rempli du fichier */ - public void read(InputStream reader) { } + public void read(InputStream reader) { + } /** * Permet de récupérer le context courant diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 6449229..2f15e98 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -23,6 +23,7 @@ public abstract class ProtocolWriter { /** * Permet de récupérer le nom de la commande. + * * @return Nom de la commande. */ public final String getCmdName() { @@ -50,12 +51,15 @@ public abstract class ProtocolWriter { /** * Permet d'écrire un fichier sur le réseau. Cad envoyer le contenu d'un fichier sur le réseau. * Redéfinissez cette méthode pour l'utiliser. + * * @param writer Buffer à remplir qui sera envoyer via le réseau */ - public void write(OutputStream writer) throws IOException {} + public void write(OutputStream writer) throws IOException { + } /** * Accesseur au contexte courant sur lequel opère la commande + * * @return Context */ public Context getContext() { @@ -66,6 +70,7 @@ public abstract class ProtocolWriter { /** * Permet de contruire une commande selon une règle établie. + * * @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande * @return La commande construites */ @@ -74,7 +79,7 @@ public abstract class ProtocolWriter { StringBuilder builder = new StringBuilder(this.cmdName); for (String param : data) - builder.append(" " + param); + builder.append(" ").append(param); String command = builder + "\r\n"; Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java index 7024478..2ec6135 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java @@ -69,6 +69,7 @@ public class RemoveFileRule extends ProtocolReader { /** * TODO : But futur est de pouvoir en avoir plusieurs * Cette méthode permet de choisir le domaine voulu. + * * @param storageIterator Les domaines * @return Le domain choisi */ diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index 3d7044d..7b4cf26 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -20,8 +20,8 @@ public class RetrieveOkRule extends ProtocolReader { private static final int HASHED_FILE_CONTENT = 2; // Index hashed file content // Variables - private ProtocolRepository protocolRep; - private String storagePath; + private final ProtocolRepository protocolRep; + private final String storagePath; // Variables public RetrieveOkRule(ProtocolRepository protocolRep, String storagePath) { @@ -32,8 +32,8 @@ public class RetrieveOkRule extends ProtocolReader { public class Result extends ProtocolResult { // Variables - private String filename; - private int filesize; + private final String filename; + private final int filesize; private String hashedFileContent; public Result(Context context, String filename, int filesize, String hashedFileContent) { @@ -52,7 +52,6 @@ public class RetrieveOkRule extends ProtocolReader { } /** - * Bitch has bettern than my money * @param reader Buffer rempli du fichier */ @Override diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 9128f97..c1ec1b1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -26,8 +26,8 @@ public class SavefileRule extends ProtocolReader { private static final int FILE_NAME = 0; // Index file name. private static final int FILE_SIZE = 1; // Index file size. - private ProtocolRepository protocolRep; - private String storagePath; + private final ProtocolRepository protocolRep; + private final String storagePath; // Constructor public SavefileRule(ProtocolRepository protocolRep, String storagePath) { @@ -39,7 +39,7 @@ public class SavefileRule extends ProtocolReader { public class Result extends ProtocolResult { // Variables private String filename; - private int size; + private final int size; // Construct public Result(Context context, String filename, int size) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index 520fa19..132f20f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -14,7 +14,7 @@ public class SendErrorRule extends ProtocolReader { private static final String NAME = "SEND_ERROR"; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor public SendErrorRule(ProtocolRepository protocolRep) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index 6f697b5..e61a307 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -18,7 +18,7 @@ public class SigninRule extends ProtocolReader { private static final int LOGIN = 0; // Index du domain dans le tableau de données private static final int PASSWORD = 1; // Index du port dans le tableau de données - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor public SigninRule(ProtocolRepository protocolRep) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index fbb56ed..8f27cb4 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -16,7 +16,7 @@ public class SignupRule extends ProtocolReader { private static final int LOGIN = 0; private static final int PASSWORD = 1; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; public SignupRule(ProtocolRepository protocolRep) { super(NAME, PATTERN); diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java index 8b5078a..48c363f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -18,7 +18,7 @@ public class GetFileOkRule extends ProtocolWriter { private static final int FILE_SIZE = 1; // Index file size // Variables - private String storagePath; + private final String storagePath; // Constructors public GetFileOkRule(String storagePath) { @@ -28,8 +28,8 @@ public class GetFileOkRule extends ProtocolWriter { public class Result extends ProtocolWriter.ProtocolResult { // Variables - private String filename; - private int filesize; + private final String filename; + private final int filesize; // Constructors public Result(Context context, String filename, int filesize) { @@ -40,13 +40,14 @@ public class GetFileOkRule extends ProtocolWriter { /** * Oh yeahh baby by tonton EndMove ;-) + * * @param writer Buffer à remplir qui sera envoyer via le réseau */ @Override public void write(OutputStream writer) throws IOException { System.out.printf("Sauvegarde du fichier : %s %d\n", this.filename, this.filesize); - System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize")+" normal: "+getContext().getDataInt("fileSize")); + System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize") + " normal: " + getContext().getDataInt("fileSize")); FileSender fileSender = new FileSender(storagePath); fileSender.sendFile( getContext().getDataString("hashedFileName"), @@ -58,7 +59,8 @@ public class GetFileOkRule extends ProtocolWriter { try { Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, getContext().getDataString("hashedFileName")))); - } catch (IOException ignore) { } + } catch (IOException ignore) { + } } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 13473f5..230cccd 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -34,7 +34,8 @@ public class SaveFileOkRule extends ProtocolWriter { String hashedFileName = context.getHashedFileName(context.getDataString("fileName")); try { Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName))); - } catch (IOException ignore) {} + } catch (IOException ignore) { + } return result; } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index 3eae4bd..19abaca 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -20,7 +20,7 @@ public class SendfileRule extends ProtocolWriter { private static final int FILE_SIZE = 1; // Index file size. private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed. - private String storagePath; + private final String storagePath; public SendfileRule(String storagePath) { super(NAME, PATTERN); diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index ff17247..9c69784 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -8,18 +8,18 @@ import lightcontainer.protocol.ProtocolWriter; import java.util.ArrayList; import java.util.List; // TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) + /** * ClientHandlerRepository - * + *

* Repository storing ClientHandler class. * Contains some utility functions. * - * @version 1.0 - * @since 1.0 - * - * @see ClientHandler - * @see AutoCloseable - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see ClientHandler + * @see AutoCloseable + * @since 1.0 */ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { // Variable @@ -34,9 +34,9 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { /** * Setter, allow to define the ServerListener of a repository. * & Start the server. - * @param server ServerListener to set as default. * - * @since 1.0 + * @param server ServerListener to set as default. + * @since 1.0 */ @Override public void setServerListener(UnicastServerListener server) { @@ -46,9 +46,9 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { /** * Add a ClientHandler. - * @param client Client Handler to add. * - * @since 1.0 + * @param client Client Handler to add. + * @since 1.0 */ @Override public void addClient(ClientHandler client) { @@ -75,7 +75,7 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { * AutoClosable Function * Closes all ClientHandlers stored in this repository and deallocates all resources. * - * @since 1.0 + * @since 1.0 */ @Override public void close() { diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index acde83e..39d4809 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -16,8 +16,8 @@ import java.util.concurrent.ConcurrentLinkedDeque; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // Variables private Deque tasks = new ConcurrentLinkedDeque<>(); - private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end - private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end + private final ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end + private final StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end private ProtocolRepository protocolRepository; // Constructor diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 163ee96..0d21f9d 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -9,17 +9,17 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; // TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) + /** * StoreProcessorRepository - * + *

* Repository storing StorePorcessor class. * Contains some utility functions. * - * @version 1.0 - * @since 1.0 - * - * @see StoreProcessor - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see StoreProcessor + * @since 1.0 */ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { // Variables @@ -34,9 +34,9 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { /** * Setter, allow to define the ServerListener of a repository. * & start the server. - * @param server ServerListener to set as default. * - * @since 1.0 + * @param server ServerListener to set as default. + * @since 1.0 */ @Override public void setServerListener(MulticastServerListener server) { @@ -46,9 +46,9 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { /** * Add a StorePorcessor. - * @param store Store processor to add. * - * @since 1.0 + * @param store Store processor to add. + * @since 1.0 */ @Override public boolean addStore(StoreProcessor store) { @@ -129,7 +129,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { * AutoClosable Function * Closes all StoreProcessor stored in this repository and deallocates all resources. * - * @since 1.0 + * @since 1.0 */ @Override public void close() { diff --git a/app/src/main/java/lightcontainer/storage/AppConfig.java b/app/src/main/java/lightcontainer/storage/AppConfig.java index 7cc0033..9bc6945 100644 --- a/app/src/main/java/lightcontainer/storage/AppConfig.java +++ b/app/src/main/java/lightcontainer/storage/AppConfig.java @@ -90,6 +90,7 @@ public class AppConfig { /** * Méthode permettant de récupérer le chemin de sauvegarde des fichiers + * * @return Chemin de sauvegarde */ public String getStoragePath() { diff --git a/app/src/main/java/lightcontainer/utils/AES_GCM.java b/app/src/main/java/lightcontainer/utils/AES_GCM.java index 020d5de..8addb45 100644 --- a/app/src/main/java/lightcontainer/utils/AES_GCM.java +++ b/app/src/main/java/lightcontainer/utils/AES_GCM.java @@ -11,10 +11,9 @@ import java.util.Base64; /** * AES GCM 256 Encryption Class [DO NOT EDIT] * - * @since 1.0 - * @version 1.0 - * * @author Jérémi Nihart + * @version 1.0 + * @since 1.0 */ public class AES_GCM { // Constants @@ -23,8 +22,7 @@ public class AES_GCM { public static final int GCM_TAG_LENGTH = 16; // Main method for testing - public static void main(String[] args) throws Exception - { + public static void main(String[] args) throws Exception { /* * FILE ENCRYPTION DEMO */ @@ -38,20 +36,20 @@ public class AES_GCM { String IVFile = generateIV(); String keyFile = generateSecretKey(); // Show options - System.out.println("IV : "+IVFile); - System.out.println("Key : "+keyFile); + System.out.println("IV : " + IVFile); + System.out.println("Key : " + keyFile); // Encrypt encryptStream( - new FileInputStream(inFile), - new FileOutputStream(outFile), + new FileInputStream(inFile), + new FileOutputStream(outFile), inFile.length(), IVFile, keyFile ); // Decrypt decryptStream( - new FileInputStream(outFile), - new FileOutputStream(clearFile), + new FileInputStream(outFile), + new FileOutputStream(clearFile), outFile.length(), IVFile, keyFile @@ -65,8 +63,8 @@ public class AES_GCM { String IV = generateIV(); String key = generateSecretKey(); // Show options - System.out.println("IV : "+IV); - System.out.println("Key : "+key); + System.out.println("IV : " + IV); + System.out.println("Key : " + key); System.out.println("Original text : " + plainText); // Crypt String cryptText = encrypt(plainText, key, IV); @@ -79,8 +77,8 @@ public class AES_GCM { /** * Decoder to decode base64 vector to byte vector. * - * @param base64Vector A base64 encoded vector. - * @return Byte vector. + * @param base64Vector A base64 encoded vector. + * @return Byte vector. */ private static byte[] decodeBase64Vector(String base64Vector) { Base64.Decoder b64Decoder = Base64.getDecoder(); @@ -90,10 +88,9 @@ public class AES_GCM { /** * Decoder to decode base64 string to plain string. * - * @param base64String A base64 encoded string. - * @return Plain string. - * - * @see AES_GCM#decodeBase64Vector(String) + * @param base64String A base64 encoded string. + * @return Plain string. + * @see AES_GCM#decodeBase64Vector(String) */ private static String decodeBase64String(String base64String) { return new String(decodeBase64Vector(base64String)); @@ -101,8 +98,9 @@ public class AES_GCM { /** * Encoder to encode vector to base64 string. - * @param rawVector A raw vector. - * @return A base64 encoded vector. + * + * @param rawVector A raw vector. + * @return A base64 encoded vector. */ private static String encodeBase64(byte[] rawVector) { Base64.Encoder b64Encoder = Base64.getEncoder(); @@ -111,10 +109,10 @@ public class AES_GCM { /** * Encoder to encode string to base64 string. - * @param rawString A raw string. - * @return A base64 encoded string. * - * @see AES_GCM#encodeBase64(byte[])) + * @param rawString A raw string. + * @return A base64 encoded string. + * @see AES_GCM#encodeBase64(byte[])) */ private static String encodeBase64(String rawString) { return encodeBase64(rawString.getBytes(StandardCharsets.UTF_8)); @@ -123,14 +121,12 @@ public class AES_GCM { /** * FACTORY, to setting up a Java cryptographic cypher. * - * @param op_mode the operation mode of this cipher (this is one of the - * following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE) - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @return A Cryptography cypher. - * - * @throws AesGcmException Throw an exception in case of an error occur while setting up the the cypher. + * @param op_mode the operation mode of this cipher (this is one of the + * following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE) + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return A Cryptography cypher. + * @throws AesGcmException Throw an exception in case of an error occur while setting up the the cypher. */ private static Cipher createCipher(int op_mode, String key, String IV) throws AesGcmException { try { @@ -151,9 +147,8 @@ public class AES_GCM { /** * Generate a secret key base64 encoded. * - * @return New Secret key b64 encoded. - * - * @throws AesGcmException Exception if an error occur. + * @return New Secret key b64 encoded. + * @throws AesGcmException Exception if an error occur. */ public static String generateSecretKey() throws AesGcmException { try { @@ -169,7 +164,7 @@ public class AES_GCM { /** * Generate an IV (initialisation vector) base64 encoded. * - * @return New generated IV b64 encoded. + * @return New generated IV b64 encoded. */ public static String generateIV() { byte[] IV = new byte[GCM_IV_LENGTH]; @@ -181,13 +176,11 @@ public class AES_GCM { /** * Encrypt text, with AES GCM. * - * @param plainText Plain text to encrypt. - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @return The encrypted plain text Base64 encoded. - * - * @throws AesGcmException Exception if an error occur. + * @param plainText Plain text to encrypt. + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return The encrypted plain text Base64 encoded. + * @throws AesGcmException Exception if an error occur. */ public static String encrypt(String plainText, String key, String IV) throws AesGcmException { try { @@ -204,13 +197,12 @@ public class AES_GCM { * Encrypt stream, with AES GCM. * The output stream is automatically closed after processing. * - * @param in InputStream to the input, flux to encrypt. - * @param out OutputStream to the output, encrypted flux. - * @param fileSize Stream/file size (! unencrypted size !). - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @throws AesGcmException Exception if an error occur. + * @param in InputStream to the input, flux to encrypt. + * @param out OutputStream to the output, encrypted flux. + * @param fileSize Stream/file size (! unencrypted size !). + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @throws AesGcmException Exception if an error occur. */ public static void encryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException { byte[] buffer = new byte[1024]; @@ -222,7 +214,7 @@ public class AES_GCM { // Initialize a CipherOutputStream CipherOutputStream cipherOut = new CipherOutputStream(out, cipher); // Encryption Process - while((currentSize < fileSize) && (bytes = in.read(buffer)) > 0) { + while ((currentSize < fileSize) && (bytes = in.read(buffer)) > 0) { cipherOut.write(buffer, 0, bytes); cipherOut.flush(); currentSize += bytes; @@ -237,13 +229,11 @@ public class AES_GCM { /** * Decrypt, with AES GCM. * - * @param cryptText The encrypted text. - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @return The decrypted plain text. - * - * @throws AesGcmException Exception if an error occur. + * @param cryptText The encrypted text. + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return The decrypted plain text. + * @throws AesGcmException Exception if an error occur. */ public static String decrypt(String cryptText, String key, String IV) throws AesGcmException { try { @@ -260,13 +250,12 @@ public class AES_GCM { * Decrypt stream, with AES GCM. * The input stream is automatically closed after processing. * - * @param in InputStream to the input, flux to decrypt. - * @param out OutputStream to the output, decrypted flux. - * @param fileSize Stream/file size (! encrypted size !). - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @throws AesGcmException Exception if an error occur. + * @param in InputStream to the input, flux to decrypt. + * @param out OutputStream to the output, decrypted flux. + * @param fileSize Stream/file size (! encrypted size !). + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @throws AesGcmException Exception if an error occur. */ public static void decryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException { byte[] buffer = new byte[1024]; @@ -278,7 +267,7 @@ public class AES_GCM { // Initialize a CipherOutputStream CipherInputStream cipherIn = new CipherInputStream(in, cipher); // Encryption Process - while((currentSize < fileSize) && (bytes = cipherIn.read(buffer)) > 0) { + while ((currentSize < fileSize) && (bytes = cipherIn.read(buffer)) > 0) { out.write(buffer, 0, bytes); out.flush(); currentSize += bytes; @@ -301,7 +290,7 @@ public class AES_GCM { * Constructor of AesGcmException, * which define it's own detail message. * - * @param msg The detail message. + * @param msg The detail message. */ public AesGcmException(String msg) { super(msg); @@ -312,7 +301,7 @@ public class AES_GCM { * which propagates the error triggering * a crash of the encryption system. * - * @param e Previous exception throwable. + * @param e Previous exception throwable. */ public AesGcmException(Throwable e) { super(e); @@ -324,8 +313,8 @@ public class AES_GCM { * a crash of the encryption system with * a chosen detail message. * - * @param e Previous exception throwable. - * @param msg The detail message. + * @param e Previous exception throwable. + * @param msg The detail message. */ public AesGcmException(GeneralSecurityException e, String msg) { super(msg, e); diff --git a/app/src/main/java/lightcontainer/utils/FileReceiver.java b/app/src/main/java/lightcontainer/utils/FileReceiver.java index f852587..634e5ec 100644 --- a/app/src/main/java/lightcontainer/utils/FileReceiver.java +++ b/app/src/main/java/lightcontainer/utils/FileReceiver.java @@ -3,9 +3,11 @@ package lightcontainer.utils; import java.io.*; public class FileReceiver { - private String path; + private final String path; - public FileReceiver(String path) { this.path = path; } + public FileReceiver(String path) { + this.path = path; + } public int receiveFile(InputStream input, String fileName, int fileSize, String key, String iv) { try { @@ -16,8 +18,8 @@ public class FileReceiver { AES_GCM.encryptStream(input, bufferedStream, fileSize, key, iv); } } - return (int)file.length(); // TODO change the size to LONG - } catch(IOException | AES_GCM.AesGcmException ex) { + return (int) file.length(); // TODO change the size to LONG + } catch (IOException | AES_GCM.AesGcmException ex) { ex.printStackTrace(); return -1; } @@ -32,7 +34,7 @@ public class FileReceiver { bosFile = new BufferedOutputStream(new FileOutputStream(String.format("%s/%s", path, fileName))); long currentOffset = 0; - while((currentOffset < fileSize) && ((bytesReceived = input.read(buffer)) > 0)) { + while ((currentOffset < fileSize) && ((bytesReceived = input.read(buffer)) > 0)) { bosFile.write(buffer, 0, bytesReceived); currentOffset += bytesReceived; } @@ -40,9 +42,14 @@ public class FileReceiver { bosFile.close(); return true; - } catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); - if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} } + if (bosFile != null) { + try { + bosFile.close(); + } catch (Exception e) { + } + } return false; } } diff --git a/app/src/main/java/lightcontainer/utils/FileSender.java b/app/src/main/java/lightcontainer/utils/FileSender.java index 227855d..fe97aa3 100644 --- a/app/src/main/java/lightcontainer/utils/FileSender.java +++ b/app/src/main/java/lightcontainer/utils/FileSender.java @@ -3,23 +3,25 @@ package lightcontainer.utils; import java.io.*; public class FileSender { - private static final int DEFAULT_BUFFER=8000; + private static final int DEFAULT_BUFFER = 8000; private final String path; - public FileSender(String path) { this.path = path; } + public FileSender(String path) { + this.path = path; + } public boolean sendFile(String filename, OutputStream out, int fileSize, String aesKey, String iv) throws IOException { BufferedInputStream bisFile; System.out.printf("Envoie fichier : %s - %s - %s \n", filename, aesKey, iv); try { File f = new File(String.format("%s/%s", path, filename)); - if(f.exists()) { + if (f.exists()) { bisFile = new BufferedInputStream(new FileInputStream(f)); AES_GCM.decryptStream(bisFile, out, fileSize, aesKey, iv); return true; } else return false; - } catch(IOException | AES_GCM.AesGcmException ex) { + } catch (IOException | AES_GCM.AesGcmException ex) { throw new IOException(); } } @@ -30,19 +32,20 @@ public class FileSender { try { File file = new File(String.format("%s/%s", path, filename)); long fileSize = file.length(); - if(file.exists()) { + if (file.exists()) { byte[] buffer = new byte[DEFAULT_BUFFER]; bisFile = new BufferedInputStream(new FileInputStream(file)); long currentOffset = 0; - while((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { - out.write(buffer, 0, bytesReaded); out.flush(); - currentOffset+= bytesReaded; + while ((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { + out.write(buffer, 0, bytesReaded); + out.flush(); + currentOffset += bytesReaded; } bisFile.close(); return true; } else return false; - } catch(IOException ex) {// todo change + } catch (IOException ex) {// todo change throw ex; } } diff --git a/app/src/main/java/lightcontainer/utils/NetChooser.java b/app/src/main/java/lightcontainer/utils/NetChooser.java index d7ebcbe..d46de32 100644 --- a/app/src/main/java/lightcontainer/utils/NetChooser.java +++ b/app/src/main/java/lightcontainer/utils/NetChooser.java @@ -18,7 +18,7 @@ public class NetChooser { public NetworkInterface requestInterface() { Scanner console = new Scanner(System.in); String[] allInterfaceNames = getInterfaces(); - for(int index=0; index < allInterfaceNames.length; ++index) { + for (int index = 0; index < allInterfaceNames.length; ++index) { System.out.printf("%d. %s\n", index, allInterfaceNames[index]); } System.out.printf("Select your interface :"); @@ -35,28 +35,28 @@ public class NetChooser { NetworkInterface currentInterface = discoveredInterfaces.nextElement(); Enumeration inetAddresses = currentInterface.getInetAddresses(); int ipCount = 0; - while(inetAddresses.hasMoreElements()) { + while (inetAddresses.hasMoreElements()) { InetAddress currentAddress = inetAddresses.nextElement(); ipCount++; } - if(ipCount > 0) + if (ipCount > 0) interfaces.add(currentInterface); } - } catch(SocketException ex) { + } catch (SocketException ex) { ex.printStackTrace(); } } public NetworkInterface getInterfacesByIndex(int i) { - if(i >= 0) + if (i >= 0) return interfaces.get(i); else return null; } public String[] getInterfaces() { - if(interfaces.size() > 0) { + if (interfaces.size() > 0) { String[] result = new String[interfaces.size()]; for (int i = 0; i < interfaces.size(); ++i) { result[i] = interfaces.get(i).getDisplayName() + " --> " + interfaces.get(i).getName(); diff --git a/app/src/main/java/lightcontainer/utils/SHA.java b/app/src/main/java/lightcontainer/utils/SHA.java index 25cd806..5c1963a 100644 --- a/app/src/main/java/lightcontainer/utils/SHA.java +++ b/app/src/main/java/lightcontainer/utils/SHA.java @@ -13,10 +13,9 @@ import java.util.Base64; /** * SHA 256 Hashing and borrowing Class [DO NOT EDIT] * - * @since 1.0 - * @version 1.0 - * * @author Jérémi Nihart + * @version 1.0 + * @since 1.0 */ public class SHA { // Constants @@ -42,12 +41,10 @@ public class SHA { /** * Make a borrowing of the stream. * - * @param in InputStream to the input, flux to hash. - * @param fileSize Stream/file size. - * - * @return Borrowing of the full current flux. - * - * @throws ShaException if an error occur. + * @param in InputStream to the input, flux to hash. + * @param fileSize Stream/file size. + * @return Borrowing of the full current flux. + * @throws ShaException if an error occur. */ public static String hashStream(InputStream in, long fileSize) throws ShaException { StringBuilder sb = new StringBuilder(); @@ -58,7 +55,7 @@ public class SHA { // Init Digest algo MessageDigest digest = MessageDigest.getInstance(SHA_VERSION); // Process flux - while ((currentSize < fileSize) && (bytes=in.read(buffer)) > 0) { + while ((currentSize < fileSize) && (bytes = in.read(buffer)) > 0) { digest.update(buffer, 0, bytes); currentSize += bytes; } @@ -77,12 +74,10 @@ public class SHA { /** * Make a borrowing of the file. * - * @param rootPath Root path of the file. - * @param fileName File Name. - * - * @return Borrowing of the file. - * - * @throws ShaException if an error occur. + * @param rootPath Root path of the file. + * @param fileName File Name. + * @return Borrowing of the file. + * @throws ShaException if an error occur. */ public static String hashFile(String rootPath, String fileName) throws ShaException { try { @@ -109,7 +104,7 @@ public class SHA { * which propagates the error triggering * a crash of the hash system. * - * @param e Previous exception throwable. + * @param e Previous exception throwable. */ public ShaException(Throwable e) { super(e); From 99835cf73e5bb89aaed17470603573601e23b922 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 19 Mar 2022 11:53:26 +0100 Subject: [PATCH 08/39] - Activation suppression fichier temp lors d'une erreur pour l'ajout de ceului-ci au SBE --- .../lightcontainer/protocol/rules/reader/SavefileRule.java | 2 -- .../protocol/rules/writer/SaveFileErrorRule.java | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 9128f97..634cadf 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -85,8 +85,6 @@ public class SavefileRule extends ProtocolReader { this.setResultCommand(protocolRep.executeWriter(getContext(), SendfileRule.NAME, this.filename, String.valueOf(encryptedFileSize), fileHash), ResultCmdReceiver.STOREBACKEND); } catch (IOException | SHA.ShaException e) { - // TODO : Supprimer le fichier - System.out.println("HEYHEYHEYHEYHEY OHOHOH"); this.setResultCommand(protocolRep.executeWriter(getContext(), SaveFileErrorRule.NAME), ResultCmdReceiver.CLIENT); e.printStackTrace(); } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index 98a138c..ef9a9b7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -31,17 +31,13 @@ public class SaveFileErrorRule extends ProtocolWriter { // Suppression du fichier temporaire dans le stockage du FFE ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + context.getDataString("fileName")); - /* try { Files.deleteIfExists(Path.of( String.format("%s/%s", this.storagePath, hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt"))) ) )); - } catch (IOException e) { - } - - */ + } catch (IOException e) {} return result; } From b65310399f772a94a8053b9b1dc9f52a1ffa8455 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:36:28 +0100 Subject: [PATCH 09/39] =?UTF-8?q?Nouvelles=20Regex=20:=20HELLO=20valid?= =?UTF-8?q?=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/HelloRule.java | 6 ++++-- app/src/main/resources/appdata.json | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index 4c0aa4b..fbed0e3 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -3,12 +3,14 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_HELLO; + /** * Règle permettant d'être alerter de l'annoncement d'un SBE */ public class HelloRule extends ProtocolReader { - - private static final String PATTERN = "^HELLO ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$"; + //"^HELLO ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$" + private static final String PATTERN = SBE_HELLO; private static final String NAME = "HELLO"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index e26d31b..a99218c 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,16 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"D:\\ffe","users":[{"name":"aaaaa","password":"$2a$10$HAupXer5aVEDgIAtFQchyOSB.SyCq7irV7EZNcMTE3R9k.1UJGOLu","aes_key":"FvsflaQGR+OoV11chJTCxd24owRPvyz1T42JXIU9fwE=","files":[{"name":"map_91.dat","fileNameSalt":"vtUOlQQ6Vt4bbpNexyBvog==","size":693,"iv":"ylk0R79Fq2/eDccVi8GTfA==","storage":["orglightcont01"]},{"name":"OutPutStream.mp3","fileNameSalt":"3qw+LauZUc13xh6fwnMHnQ==","size":53037,"iv":"40sIX0VtASM9man5XkM64Q==","storage":["orglightcont01"]},{"name":"wait.mp4","fileNameSalt":"1wnuehjUPI895TgCy2e/EQ==","size":1210962,"iv":"fCM6WG1PxOu9ieEjPuQiFg==","storage":["orglightcont01"]},{"name":"loader.gif","fileNameSalt":"05nNafgD/SNPg+y/MzI2DA==","size":89594,"iv":"GLoY4/PybIz72Sbz9jFgRQ==","storage":["orglightcont01"]},{"name":"extensions.mp4","fileNameSalt":"BYam5baM4WUPdaQZDu2eyw==","size":1501471,"iv":"ugCXHr7yVsY8rnB1znEfew==","storage":["orglightcont01"]},{"name":"007.mp4","fileNameSalt":"12jEfd3/dT9akqzdWn1vsg==","size":1742707,"iv":"CyKf2OHPABn//ez5L2o3Jg==","storage":["orglightcont01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "lo", + "tls": true, + "storagePath": "C:\\Users\\ledou\\Documents\\ffe", + "users": [ + { + "name": "aaaaa", + "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", + "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", + "files": [] + } + ] +} \ No newline at end of file From 83cf1c4c20fabc7c84971de3e765ef2cb7e01f28 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:38:33 +0100 Subject: [PATCH 10/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FSIGN=5FI?= =?UTF-8?q?N=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/reader/SigninRule.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index e61a307..9dc7e3a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -3,15 +3,19 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_IN; + /** * Règle permettant de gérer la connection d'un utilisateur */ public class SigninRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; + //"^SIGNIN ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$" + private static final String PATTERN = CLIENT_SIGN_IN; private static final String NAME = "SIGNIN"; From 4128efdefc87d24607cb83d1574bcf46d49ac0fe Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:42:41 +0100 Subject: [PATCH 11/39] =?UTF-8?q?Nouvelles=20Regex=20:=20ERASE=5FRESULT=5F?= =?UTF-8?q?ERROR=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/EraseErrorRule.java | 7 +++++-- .../protocol/rules/reader/SavefileRule.java | 2 +- app/src/main/resources/appdata.json | 12 +++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java index 1ce0b0b..cb25c5e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java @@ -3,11 +3,14 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; -public class EraseErrorRule extends ProtocolReader { +import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_ERROR; - private static final String PATTERN = "^ERASE_ERROR\r\n$"; +public class EraseErrorRule extends ProtocolReader { + //"^ERASE_ERROR\r\n$" + private static final String PATTERN = SBE_ERASE_RESULT_ERROR; private static final String NAME = "ERASE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index c1ec1b1..4cd2e57 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -19,7 +19,7 @@ import java.io.InputStream; */ public class SavefileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; private static final String NAME = "SAVEFILE"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index a99218c..e781d45 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -10,7 +10,17 @@ "name": "aaaaa", "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", - "files": [] + "files": [ + { + "name": "test.txt", + "fileNameSalt": "a+Nyu4hArJSdKdG6EvdxjQ==", + "size": 301, + "iv": "dzQdyPXANcb8sToyY84YzA==", + "storage": [ + "lightcontainerSB01" + ] + } + ] } ] } \ No newline at end of file From dedfeeff7d51122e4893f3461647893a32dfa1ef Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:44:31 +0100 Subject: [PATCH 12/39] =?UTF-8?q?Nouvelles=20Regex=20:=20ERASE=5FRESULT=5F?= =?UTF-8?q?OK=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/EraseOkRule.java | 4 +++- app/src/main/resources/appdata.json | 12 +----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java index 9125c7a..04c9ab7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_OK; + public class EraseOkRule extends ProtocolReader { - private static final String PATTERN = "^ERASE_OK\r\n$"; + private static final String PATTERN = SBE_ERASE_RESULT_OK; private static final String NAME = "ERASE_OK"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index e781d45..a99218c 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -10,17 +10,7 @@ "name": "aaaaa", "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", - "files": [ - { - "name": "test.txt", - "fileNameSalt": "a+Nyu4hArJSdKdG6EvdxjQ==", - "size": 301, - "iv": "dzQdyPXANcb8sToyY84YzA==", - "storage": [ - "lightcontainerSB01" - ] - } - ] + "files": [] } ] } \ No newline at end of file From d17cd59af81b6d485fd141d52cb9ef31d755e816 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:46:13 +0100 Subject: [PATCH 13/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FFILE=5FL?= =?UTF-8?q?IST=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/FilelistRule.java | 6 ++++-- app/src/main/resources/appdata.json | 17 +---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index 18bfeea..fea0128 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -7,16 +7,18 @@ import lightcontainer.protocol.rules.writer.FilesRule; import java.util.List; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_FILE_LIST; + /** * Règle permettant de récupérer la liste des fichiers d'un utilisateur */ public class FilelistRule extends ProtocolReader { // Constants - private static final String PATTERN = "^FILELIST\r\n$"; + private static final String PATTERN = CLIENT_FILE_LIST; private static final String NAME = "FILELIST"; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor public FilelistRule(ProtocolRepository protocolRep) { diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index a99218c..e3bd969 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1,16 +1 @@ -{ - "unicast_port": 8000, - "multicast_ip": "224.66.66.1", - "multicast_port": 15502, - "network_interface": "lo", - "tls": true, - "storagePath": "C:\\Users\\ledou\\Documents\\ffe", - "users": [ - { - "name": "aaaaa", - "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", - "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", - "files": [] - } - ] -} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km","aes_key":"a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=","files":[{"name":"test.txt","fileNameSalt":"3yLVBqM/zf8CcCFPqdh15Q==","size":301,"iv":"WfokhcAIefnnZnk3sYLjiA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From fdcccc178892e2ef94ecb08559a4afdbc9075ea2 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:48:00 +0100 Subject: [PATCH 14/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FGET=5FFI?= =?UTF-8?q?LE=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/GetFileRule.java | 6 ++++- app/src/main/resources/appdata.json | 27 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java index 116fb6d..12d5a45 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java @@ -3,15 +3,19 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.GetFileErrorRule; import lightcontainer.protocol.rules.writer.RetrieveFileRule; import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_GET_FILE; + public class GetFileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^GETFILE ([^ !]{1,20})\r\n$"; + //"^GETFILE ([^ !]{1,20})\r\n$" + private static final String PATTERN = CLIENT_GET_FILE; private static final String NAME = "GETFILE"; // -- arguments private static final int FILE_NAME = 0; // Index file name. diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index e3bd969..5be4580 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,26 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km","aes_key":"a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=","files":[{"name":"test.txt","fileNameSalt":"3yLVBqM/zf8CcCFPqdh15Q==","size":301,"iv":"WfokhcAIefnnZnk3sYLjiA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "lo", + "tls": true, + "storagePath": "C:\\Users\\ledou\\Documents\\ffe", + "users": [ + { + "name": "aaaaa", + "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", + "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", + "files": [ + { + "name": "test.txt", + "fileNameSalt": "3yLVBqM/zf8CcCFPqdh15Q==", + "size": 301, + "iv": "WfokhcAIefnnZnk3sYLjiA==", + "storage": [ + "lightcontainerSB01" + ] + } + ] + } + ] +} \ No newline at end of file From 4fac3a6d52c826a506aeb26593a59c74dd81bfc4 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:49:49 +0100 Subject: [PATCH 15/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FREMOVE?= =?UTF-8?q?=5FFILE=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/RemoveFileRule.java | 7 +++++-- app/src/main/resources/appdata.json | 12 +----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java index 2ec6135..07ba95e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java @@ -3,15 +3,18 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.EraseFileRule; import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; -public class RemoveFileRule extends ProtocolReader { +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_REMOVE_FILE; - private static final String PATTERN = "^REMOVEFILE ([^ !]{1,20})\r\n$"; +public class RemoveFileRule extends ProtocolReader { + //"^REMOVEFILE ([^ !]{1,20})\r\n$" + private static final String PATTERN = CLIENT_REMOVE_FILE; private static final String NAME = "REMOVEFILE"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 5be4580..a99218c 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -10,17 +10,7 @@ "name": "aaaaa", "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", - "files": [ - { - "name": "test.txt", - "fileNameSalt": "3yLVBqM/zf8CcCFPqdh15Q==", - "size": 301, - "iv": "WfokhcAIefnnZnk3sYLjiA==", - "storage": [ - "lightcontainerSB01" - ] - } - ] + "files": [] } ] } \ No newline at end of file From 90329d26e3811af2e3b79581f441066c09454c84 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 12:57:55 +0100 Subject: [PATCH 16/39] =?UTF-8?q?Nouvelles=20Regex=20:=20SBE=5FRETRIEVE=5F?= =?UTF-8?q?RESULT=5FERROR=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/RetrieveErrorRule.java | 6 +++++- app/src/main/resources/appdata.json | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java index 9bb8339..c686075 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java @@ -3,11 +3,15 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.GetFileErrorRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_ERROR; + public class RetrieveErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = "^RETRIEVE_ERROR\r\n$"; + //"^RETRIEVE_ERROR\r\n$" + private static final String PATTERN = SBE_RETRIEVE_RESULT_ERROR; private static final String NAME = "RETRIEVE_ERROR"; // Variables diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index a99218c..ec60f88 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -10,7 +10,17 @@ "name": "aaaaa", "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", - "files": [] + "files": [ + { + "name": "test.txt", + "fileNameSalt": "LvFNF7uz324NgsISSpUbwg==", + "size": 301, + "iv": "lGvyIzgGMiaiHeGwIaCESg==", + "storage": [ + "lightcontainerSB01" + ] + } + ] } ] } \ No newline at end of file From be133a55dc99df0ce7735360b8a8558ebdda5e6c Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:00:15 +0100 Subject: [PATCH 17/39] =?UTF-8?q?Nouvelles=20Regex=20:=20SBE=5FRETRIEVE=5F?= =?UTF-8?q?RESULT=5FOK=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/RetrieveOkRule.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index 7b4cf26..24d1fc9 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -3,6 +3,7 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.GetFileOkRule; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.utils.FileReceiver; @@ -10,9 +11,12 @@ import lightcontainer.utils.FileSender; import java.io.InputStream; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_OK; + public class RetrieveOkRule extends ProtocolReader { // Constants - private static final String PATTERN = "^RETRIEVE_OK ([A-Za-z0-9.]{50,200}) ([0-9]{1,10}) ([A-Za-z0-9.]{50,200})\r\n$"; + //"^RETRIEVE_OK ([A-Za-z0-9.]{50,200}) ([0-9]{1,10}) ([A-Za-z0-9.]{50,200})\r\n$" + private static final String PATTERN = SBE_RETRIEVE_RESULT_OK; private static final String NAME = "RETRIEVE_OK"; // -- arguments private static final int HASHED_FILE_NAME = 0; // Index hashed filename From 5a909b65aa3b6a95a5c8f281c364f60a5f0ff0d4 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:02:37 +0100 Subject: [PATCH 18/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FSAVE=5FF?= =?UTF-8?q?ILE=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/reader/SavefileRule.java | 6 +++++- app/src/main/resources/appdata.json | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 4cd2e57..b573454 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -3,6 +3,7 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.protocol.rules.writer.SendfileRule; import lightcontainer.utils.AES_GCM; @@ -13,13 +14,16 @@ import lightcontainer.utils.ShaHasher; import java.io.IOException; import java.io.InputStream; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SAVE_FILE; + /** * Règle permettant de sauvegarder un fichier sur le SBE. * Celui-ci va chiffre le contenu du fichier à l'aide de AES. */ public class SavefileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + //"^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$" + private static final String PATTERN = CLIENT_SAVE_FILE; private static final String NAME = "SAVEFILE"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index ec60f88..fc861fd 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -13,9 +13,9 @@ "files": [ { "name": "test.txt", - "fileNameSalt": "LvFNF7uz324NgsISSpUbwg==", + "fileNameSalt": "4DMHDs7+7lS8iw/SZYsdbA==", "size": 301, - "iv": "lGvyIzgGMiaiHeGwIaCESg==", + "iv": "Yuq6QN1WYFm7DZzO+svKGw==", "storage": [ "lightcontainerSB01" ] From 1a124f609f19298b927c84378abc80ca05ebdd7b Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:06:48 +0100 Subject: [PATCH 19/39] =?UTF-8?q?Nouvelles=20Regex=20:=20SBE=5FSEND=5FRESU?= =?UTF-8?q?LT=5FERROR=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/SendErrorRule.java | 6 +++++- app/src/main/resources/appdata.json | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index 132f20f..976ee8a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -3,14 +3,18 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_ERROR; + /** * Règle permettant de de confirmer la sauvegrade d'un fichier. */ public class SendErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SEND_ERROR\r\n$"; + //"^SEND_ERROR\r\n$" + private static final String PATTERN = SBE_SEND_RESULT_ERROR; private static final String NAME = "SEND_ERROR"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index fc861fd..db1f233 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -12,10 +12,10 @@ "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", "files": [ { - "name": "test.txt", - "fileNameSalt": "4DMHDs7+7lS8iw/SZYsdbA==", - "size": 301, - "iv": "Yuq6QN1WYFm7DZzO+svKGw==", + "name": "tes", + "fileNameSalt": "DlxEqOb4l9rbbRi8E8k+EA==", + "size": 0, + "iv": "HpJr8VZOFEIRuxj9z1Uzig==", "storage": [ "lightcontainerSB01" ] From a2419d0ba15afb9a2dbaecfabcbfb4d07ad34279 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:08:22 +0100 Subject: [PATCH 20/39] =?UTF-8?q?Nouvelles=20Regex=20:=20SBE=5FSEND=5FRESU?= =?UTF-8?q?LT=5FOK=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/SendOkRule.java | 6 ++++- app/src/main/resources/appdata.json | 27 +------------------ 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java index d7fb36d..1336eb6 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java @@ -3,15 +3,19 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.SaveFileOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_OK; + /** * Règle permettant de de confirmer la sauvegrade d'un fichier. */ public class SendOkRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SEND_OK\r\n$"; + //"^SEND_OK\r\n$" + private static final String PATTERN = SBE_SEND_RESULT_OK; private static final String NAME = "SEND_OK"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index db1f233..27d00bb 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1,26 +1 @@ -{ - "unicast_port": 8000, - "multicast_ip": "224.66.66.1", - "multicast_port": 15502, - "network_interface": "lo", - "tls": true, - "storagePath": "C:\\Users\\ledou\\Documents\\ffe", - "users": [ - { - "name": "aaaaa", - "password": "$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km", - "aes_key": "a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=", - "files": [ - { - "name": "tes", - "fileNameSalt": "DlxEqOb4l9rbbRi8E8k+EA==", - "size": 0, - "iv": "HpJr8VZOFEIRuxj9z1Uzig==", - "storage": [ - "lightcontainerSB01" - ] - } - ] - } - ] -} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km","aes_key":"a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=","files":[{"name":"test.txt","fileNameSalt":"RlrRzOXSrcetsVQjqOKB6g==","size":301,"iv":"NHrHwZRdshh5JQQA5Sw/UA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From 182fc39ebec802c0dff6ff6286e6ea58ca689ceb Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:09:44 +0100 Subject: [PATCH 21/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FSIGN=5FO?= =?UTF-8?q?UT=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/reader/SignoutRule.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java index 2b7a39f..17276ae 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java @@ -2,13 +2,16 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; + +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_OUT; /** * Règle demandant la déconnexion du client */ public class SignoutRule extends ProtocolReader { - - private static final String PATTERN = "^SIGNOUT\r\n$"; + //"^SIGNOUT\r\n$" + private static final String PATTERN = CLIENT_SIGN_OUT; public static final String NAME = "SIGNOUT"; From 6a002327db0dc9f313cd5ca1585e85d2783431a0 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 19 Mar 2022 13:11:08 +0100 Subject: [PATCH 22/39] =?UTF-8?q?-=20R=C3=A9solution=20probl=C3=A8me=20emp?= =?UTF-8?q?=C3=AAchant=20l'utilisation=20de=20deux=20SBE=20diff=C3=A9rents?= =?UTF-8?q?=20lors=20la=20la=20sauvegarde=20d'un=20fichier=20et=20donc=20e?= =?UTF-8?q?m=C3=AAchant=20le=20parall=C3=A9lisme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/domains/Task.java | 1 + .../domains/client/ClientHandler.java | 9 ++-- .../domains/client/StoreProcessor.java | 6 ++- .../interfaces/MulticastSPR.java | 2 +- .../protocol/rules/reader/SavefileRule.java | 2 +- .../protocol/rules/reader/SendErrorRule.java | 2 +- .../rules/writer/SaveFileErrorRule.java | 24 +++++++---- .../protocol/rules/writer/SaveFileOkRule.java | 1 + .../repository/FileFrontEnd.java | 6 +-- .../repository/ProtocolRepositoryImpl.java | 1 - .../repository/StoreProcessorRepository.java | 10 ++--- app/src/main/resources/appdata.json | 43 ++++++++++++++++++- 12 files changed, 79 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 2ae95ed..d073814 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -42,6 +42,7 @@ public class Task { * @return TRUE si le client doit recevoir cette réponse. */ public boolean isResponseOfClient(String storeDomain) { + System.out.println(status + " - " + context.getDomain() + " | " + storeDomain); return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain)); } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 5a5b439..dc9136f 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -110,30 +110,33 @@ public class ClientHandler implements Runnable, AutoCloseable { ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand(); // TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) { + System.out.println("[1] 1"); writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client writer.flush(); } else if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { - + System.out.println("[1] 2"); fileFrontEnd.newCommand(context, writerCommand); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd // Attend la fin de la réalisation de la tâche waitTaskResponse(); - + System.out.println("[1] 4"); if (response != null) { + System.out.println("[1] 5"); writer.write(response.getCommand()); // Renvoie au client writer.flush(); response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire } else { + System.out.println("[1] 6"); writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client writer.flush(); } } else { + System.out.println("[1] 3"); writer.print(writerCommand.getCommand()); // Renvoie au client writer.flush(); } } else { - System.out.println(4); accessDenied(); } } catch (IOException e) { diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 9016510..7a90ddf 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -92,6 +92,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { protocolResult.write(this.store.getOutputStream()); } catch (IOException writeException) { // Si SBE fermé System.out.println("STOPPER"); + writeException.printStackTrace(); // Envoie au client que la requête n'a pu être traitée alertAvailable(null); break; @@ -103,7 +104,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { responseCommand += "\r\n"; ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand); if (responseResult != null) { - System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand()); + System.out.println("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand()); responseResult.read( this.store.getInputStream() ); @@ -207,7 +208,8 @@ public class StoreProcessor extends Thread implements AutoCloseable { return Objects.hash(domain); } - public boolean canProcessTask(Task task) { + public boolean canProcessTask() { + System.out.println("[OK 2] " + protocolResult + " - " + domain); return this.protocolResult == null; // Vérifier si tâche veut ce SBE } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 7d5b83a..7aee90a 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -23,7 +23,7 @@ public interface MulticastSPR { */ boolean addStore(StoreProcessor store); - String findDomain(Task task); + String findDomain(); void assignTask(String stor, Task task); diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 0b97a1c..8b94735 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -19,7 +19,7 @@ import java.io.InputStream; */ public class SavefileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; private static final String NAME = "SAVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index 132f20f..3fb0d57 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -12,7 +12,7 @@ public class SendErrorRule extends ProtocolReader { // Constants private static final String PATTERN = "^SEND_ERROR\r\n$"; - private static final String NAME = "SEND_ERROR"; + private static final String NAME = "SENDERROR"; private final ProtocolRepository protocolRep; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index ef9a9b7..2873e48 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -28,16 +28,22 @@ public class SaveFileErrorRule extends ProtocolWriter { @Override protected ProtocolResult onExecuted(Context context, String... data) { ProtocolResult result = new ProtocolResult(context); + String fileName = context.getDataString("fileName"); + String fileNameSalt = context.getDataString("fileNameSalt"); - // Suppression du fichier temporaire dans le stockage du FFE - ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + context.getDataString("fileName")); - try { - Files.deleteIfExists(Path.of( - String.format("%s/%s", this.storagePath, - hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt"))) - ) - )); - } catch (IOException e) {} + + if (fileName != null && fileNameSalt != null) { + // Suppression du fichier temporaire dans le stockage du FFE + ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + fileName); + try { + Files.deleteIfExists(Path.of( + String.format("%s/%s", this.storagePath, + hasher.fromSalt(hasher.saltToByte(fileNameSalt)) + ) + )); + } catch (IOException e) { + } + } return result; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 230cccd..d13aef2 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -27,6 +27,7 @@ public class SaveFileOkRule extends ProtocolWriter { protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) { ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context); + System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin()); // Sauvegarder dans JSON context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain()); diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index 39d4809..b816212 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -32,7 +32,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche - String stor = storeRepository.findDomain(task); + String stor = storeRepository.findDomain(); if (stor != null) { storeRepository.assignTask(stor, task); task.setDomain(stor); @@ -51,9 +51,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { Iterator it = tasks.iterator(); while (it.hasNext()) { Task task = it.next(); - System.out.println("Cherche"); if (task.isResponseOfClient(store.getDomain())) { - System.out.println("Task trouvée"); clientRepository.respondToClient(task.getClient(), response); it.remove(); // Suppression de la tâche break; @@ -73,7 +71,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { while (it.hasNext()) { Task task = it.next(); - if (store.canProcessTask(task)) { + if (task.getDomain() == null && store.canProcessTask()) { storeRepository.assignTask(store.getDomain(), task); task.setDomain(store.getDomain()); return; diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index aed6995..277636b 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -31,7 +31,6 @@ public class ProtocolRepositoryImpl implements ProtocolRepository { return command; } } - System.out.println("COMMANDE NULL"); return null; } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 0d21f9d..78783d6 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -60,14 +60,14 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { } @Override - public String findDomain(Task task) { - StoreProcessor handler = findSBE(task); + public String findDomain() { + StoreProcessor handler = findSBE(); return handler == null ? null : handler.getDomain(); } - private StoreProcessor findSBE(Task task) { + private StoreProcessor findSBE() { for (StoreProcessor handler : handlers) { - if (handler.canProcessTask(task)) { + if (handler.canProcessTask()) { return handler; } } @@ -77,7 +77,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void assignTask(String stor, Task task) { - StoreProcessor handler = findSBE(task); + StoreProcessor handler = findSBE(); System.out.println("Find stor : " + handler); handler.executeCommand(task.getContext(), task.getCommand()); } diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 19b94ab..c053453 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,42 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"main.py","fileNameSalt":"PLQB1QjPaKdfdM+zjywxcQ==","size":854,"iv":"UnkiNxFMYsRcw5fsEkr+5w==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "wlp1s0", + "tls": true, + "storagePath": "/home/benjamin/ffe", + "users": [ + { + "name": "benjamin", + "password": "$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG", + "aes_key": "mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=", + "files": [ + { + "name": "README.md", + "fileNameSalt": "5k8bd3/hn5ehdkCRJ0MGRQ==", + "size": 17, + "iv": "/sEVBG7kKnMaJcg5Wpz2bQ==", + "storage": [ + "lightcontainerSB02" + ] + } + ] + }, + { + "name": "aaaaa", + "password": "$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W", + "aes_key": "kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=", + "files": [ + { + "name": "ca.crt", + "fileNameSalt": "JmISh065QAtDIePgl8IG2A==", + "size": 4207, + "iv": "Tg3aeOm1U0hQI1VqSZbAJw==", + "storage": [ + "lightcontainerSB01" + ] + } + ] + } + ] +} \ No newline at end of file From 713e930eb935ea2627e2841e2e1e721c0284ec53 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:13:02 +0100 Subject: [PATCH 23/39] =?UTF-8?q?Nouvelles=20Regex=20:=20CLIENT=5FSIGN=5FU?= =?UTF-8?q?P=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/SignupRule.java | 6 +++++- app/src/main/resources/appdata.json | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index 8f27cb4..ebf7468 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -3,15 +3,19 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_UP; + /** * Règle permettant de gérer la création d'un utilisateur */ public class SignupRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SIGNUP ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; + //"^SIGNUP ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$" + private static final String PATTERN = CLIENT_SIGN_UP; private static final String NAME = "SIGNUP"; private static final int LOGIN = 0; private static final int PASSWORD = 1; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 27d00bb..84b0f15 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,16 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Tuh5xmGEy0g26hQO1SHNY.TNy8rY9VCkpzRLP3rlpnVHtwYew4.km","aes_key":"a68CqbWmmf0cuvgvMhm9OC+Y24ut3DY/0WBqtd3nGfU=","files":[{"name":"test.txt","fileNameSalt":"RlrRzOXSrcetsVQjqOKB6g==","size":301,"iv":"NHrHwZRdshh5JQQA5Sw/UA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "lo", + "tls": true, + "storagePath": "C:\\Users\\ledou\\Documents\\ffe", + "users": [ + { + "name": "aaaaa", + "password": "$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2", + "aes_key": "4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=", + "files": [] + } + ] +} \ No newline at end of file From 5d723d9acfbfa2da973cc4f65ccd827108420554 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:17:25 +0100 Subject: [PATCH 24/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FERASE=5FFIL?= =?UTF-8?q?E=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/writer/EraseFileRule.java | 7 +++++-- app/src/main/resources/appdata.json | 17 +---------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java index f0d9794..19f57a7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/EraseFileRule.java @@ -1,11 +1,14 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; + +import static lightcontainer.protocol.StandardizedDefinitions.FFE_ERASE_FILE; public class EraseFileRule extends ProtocolWriter { - //"^ERASEFILE ([A-Za-z0-9]{50,200})\r\n$" - private static final String PATTERN = "^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$"; + //"^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$" + private static final String PATTERN = FFE_ERASE_FILE; public static String NAME = "ERASEFILE"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 84b0f15..f8ee259 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1,16 +1 @@ -{ - "unicast_port": 8000, - "multicast_ip": "224.66.66.1", - "multicast_port": 15502, - "network_interface": "lo", - "tls": true, - "storagePath": "C:\\Users\\ledou\\Documents\\ffe", - "users": [ - { - "name": "aaaaa", - "password": "$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2", - "aes_key": "4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=", - "files": [] - } - ] -} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[]}]} \ No newline at end of file From e43d0595d4b54f0410f46dabc2e3b2914aa41052 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:28:42 +0100 Subject: [PATCH 25/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FFILE=5FLIST?= =?UTF-8?q?=5FRESULT=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/StandardizedDefinitions.java | 2 +- .../java/lightcontainer/protocol/rules/writer/FilesRule.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java index 4bb0058..c7b449b 100644 --- a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java +++ b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java @@ -42,7 +42,7 @@ public class StandardizedDefinitions { public final static String FFE_SIGN_OK = "^SIGN_OK" + LINE + "$"; public final static String FFE_SIGN_ERROR = "^SIGN_ERROR" + LINE + "$"; public final static String CLIENT_FILE_LIST = "^FILELIST" + LINE + "$"; - public final static String FFE_FILE_LIST_RESULT = "^FILES" + "((" + PASSCHAR + "{1,20})!(" + DIGIT + "{1,10})){0,50}" + LINE + "$"; + public final static String FFE_FILE_LIST_RESULT = "^FILES" + "( (" + PASSCHAR + "{1,20})!(" + DIGIT + "{1,10})){0,50}" + LINE + "$"; public final static String CLIENT_SAVE_FILE = "^SAVEFILE" + BL + "(" + FILENAME + ")" + BL + "(" + SIZE + ")" + LINE + "$"; public final static String FFE_SAVE_FILE_OK = "^SAVEFILE_OK" + LINE + "$"; public final static String FFE_SAVE_FILE_ERROR = "^SAVEFILE_ERROR" + LINE + "$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java index 457f978..5749704 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java @@ -1,13 +1,16 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; + +import static lightcontainer.protocol.StandardizedDefinitions.FFE_FILE_LIST_RESULT; /** * Règle permettant de construire une commande contenant la liste des fichiers d'un utilisateur */ public class FilesRule extends ProtocolWriter { //"^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$" - private static final String PATTERN = "^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; + private static final String PATTERN = FFE_FILE_LIST_RESULT; public static final String NAME = "FILES"; From 0f84ed83556b678954e25d222baf546959c8d701 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:31:23 +0100 Subject: [PATCH 26/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FGET=5FFILE?= =?UTF-8?q?=5FRESULT=5FERROR=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/writer/GetFileErrorRule.java | 5 ++++- app/src/main/resources/appdata.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java index e43ec21..59af4fb 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileErrorRule.java @@ -1,6 +1,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; + +import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_ERROR; /** * Règle utilisé dans le cas ou une erreur survient lors @@ -9,7 +12,7 @@ import lightcontainer.protocol.ProtocolWriter; public class GetFileErrorRule extends ProtocolWriter { // Constants //"^GETFILE_ERROR\r\n$" - private static final String PATTERN = "^GETFILE_ERROR\r\n$"; + private static final String PATTERN = FFE_GET_FILE_RESULT_ERROR; public static final String NAME = "GETFILE_ERROR"; // Constructors diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index f8ee259..51fa9da 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[]}]} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"FIjFt/hfscPkTLksP0IT4A==","size":301,"iv":"ATf85tYHY7WoGmyy3XRqyA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From 67d85200a75d26db778b5f5ae55cb97eb9764b23 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:33:03 +0100 Subject: [PATCH 27/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FGET=5FFILE?= =?UTF-8?q?=5FRESULT=5FOK=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/writer/GetFileOkRule.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java index 48c363f..2f7e66c 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -2,6 +2,7 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.utils.FileSender; import java.io.IOException; @@ -9,9 +10,12 @@ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_OK; + public class GetFileOkRule extends ProtocolWriter { // Constants - private static final String PATTERN = "^GETFILE_OK ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + //"^GETFILE_OK ([^ !]{1,20}) ([0-9]{1,10})\r\n$" + private static final String PATTERN = FFE_GET_FILE_RESULT_OK; public static final String NAME = "GETFILE_OK"; // -- params private static final int FILE_NAME = 0; // Index file name hashed From febff3a8e001c7411382e1ca83c16d40bbb83c93 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:34:25 +0100 Subject: [PATCH 28/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FREMOVE=5FER?= =?UTF-8?q?ROR=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rules/writer/RemoveFileErrorRule.java | 4 ++- app/src/main/resources/appdata.json | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java index c071683..5fc60f1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileErrorRule.java @@ -2,10 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_ERROR; + public class RemoveFileErrorRule extends ProtocolWriter { //"^REMOVEFILE_ERROR\r\n$" - private static final String PATTERN = "^REMOVEFILE_ERROR\r\n$"; + private static final String PATTERN = FFE_REMOVE_ERROR; public static String NAME = "REMOVEFILE_ERROR"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 51fa9da..09d21cd 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,26 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"FIjFt/hfscPkTLksP0IT4A==","size":301,"iv":"ATf85tYHY7WoGmyy3XRqyA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "lo", + "tls": true, + "storagePath": "C:\\Users\\ledou\\Documents\\ffe", + "users": [ + { + "name": "aaaaa", + "password": "$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2", + "aes_key": "4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=", + "files": [ + { + "name": "test.txt", + "fileNameSalt": "FIjFt/hfscPkTLksP0IT4A==", + "size": 301, + "iv": "ATf85tYHY7WoGmyy3XRqyA==", + "storage": [ + "lightcontainerSB01" + ] + } + ] + } + ] +} \ No newline at end of file From d10b547dc0c292207d0a2672827035eaad3cdee1 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:35:54 +0100 Subject: [PATCH 29/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FREMOVE=5FOK?= =?UTF-8?q?=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rules/writer/RemoveFileOkRule.java | 4 ++- app/src/main/resources/appdata.json | 27 +------------------ 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java index bc9fc39..6e5ab3e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RemoveFileOkRule.java @@ -2,9 +2,11 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_OK; + public class RemoveFileOkRule extends ProtocolWriter { //"^REMOVEFILE_OK\r\n$" - private static final String PATTERN = "^REMOVEFILE_OK\r\n$"; + private static final String PATTERN = FFE_REMOVE_OK; public static String NAME = "REMOVEFILE_OK"; public RemoveFileOkRule() { diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 09d21cd..7d07491 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1,26 +1 @@ -{ - "unicast_port": 8000, - "multicast_ip": "224.66.66.1", - "multicast_port": 15502, - "network_interface": "lo", - "tls": true, - "storagePath": "C:\\Users\\ledou\\Documents\\ffe", - "users": [ - { - "name": "aaaaa", - "password": "$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2", - "aes_key": "4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=", - "files": [ - { - "name": "test.txt", - "fileNameSalt": "FIjFt/hfscPkTLksP0IT4A==", - "size": 301, - "iv": "ATf85tYHY7WoGmyy3XRqyA==", - "storage": [ - "lightcontainerSB01" - ] - } - ] - } - ] -} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"QTWuH0rNYf0+8ondzDlFeA==","size":301,"iv":"r+Lw9Qpo5Ca7cO45MytKwA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From 314784f662de9ade23c8de9caa01b4cfbc384f8e Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:44:04 +0100 Subject: [PATCH 30/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FRETRIEVE=5F?= =?UTF-8?q?FILE=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/writer/RetrieveFileRule.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java index b64d1bb..951f92d 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/RetrieveFileRule.java @@ -2,10 +2,12 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_RETRIEVE_FILE; + public class RetrieveFileRule extends ProtocolWriter { // Constants //"^RETRIEVEFILE ([A-Za-z0-9]{50,200})\r\n$" - private static final String PATTERN = "^RETRIEVEFILE ([A-Za-z0-9]{50,200})\r\n$"; + private static final String PATTERN = FFE_RETRIEVE_FILE; public static final String NAME = "RETRIEVEFILE"; // Constructor From d7779fc95adc8733916741da07809af30b00735f Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:49:12 +0100 Subject: [PATCH 31/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FSAVE=5FFILE?= =?UTF-8?q?=5FERROR=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/writer/SaveFileErrorRule.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index abf15f1..25d3b62 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -2,18 +2,21 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.utils.ShaHasher; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SAVE_FILE_ERROR; + /** * Règle signifiant que la sauvegarde d'un fichier a échoué */ public class SaveFileErrorRule extends ProtocolWriter { //"^SAVEFILE_ERROR\r\n$" - private static final String PATTERN = "^SAVEFILE_ERROR\r\n$"; + private static final String PATTERN = FFE_SAVE_FILE_ERROR; public static final String NAME = "SAVEFILE_ERROR"; From 99c682015a3abb5bd44d4df05ad0c5e2aaea0eb5 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:54:36 +0100 Subject: [PATCH 32/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FSAVE=5FFILE?= =?UTF-8?q?=5FOK=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/writer/SaveFileOkRule.java | 7 +++++-- app/src/main/resources/appdata.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 230cccd..04e5d50 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -2,17 +2,20 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SAVE_FILE_OK; + /** * Règle signifiant que la sauvegarde d'un fichier fût un succès */ public class SaveFileOkRule extends ProtocolWriter { - - private static final String PATTERN = "^SAVEFILE_OK\r\n$"; + //"^SAVEFILE_OK\r\n$" + private static final String PATTERN = FFE_SAVE_FILE_OK; public static final String NAME = "SAVEFILE_OK"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 7d07491..267cc92 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"QTWuH0rNYf0+8ondzDlFeA==","size":301,"iv":"r+Lw9Qpo5Ca7cO45MytKwA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"QTWuH0rNYf0+8ondzDlFeA==","size":301,"iv":"r+Lw9Qpo5Ca7cO45MytKwA==","storage":["lightcontainerSB01"]},{"name":"regex.txt","fileNameSalt":"hPTgHiTySuUiJE0I4QD1Gw==","size":1320,"iv":"Uw7pAMKAEJRL/vn2NJ//wA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From 8718d9c4ea02bcbdee9dd324e8b9d349a72e1bde Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:56:23 +0100 Subject: [PATCH 33/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FSENDFILE=20?= =?UTF-8?q?valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/writer/SendfileRule.java | 5 ++++- app/src/main/resources/appdata.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index 19abaca..aa44928 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -2,17 +2,20 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.utils.FileSender; import java.io.IOException; import java.io.OutputStream; +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SENDFILE; + /** * Règle envoyée au SBE, demandant la sauvegarde d'un fichier. */ public class SendfileRule extends ProtocolWriter { //"^SENDFILE [A-Za-z0-9]{50,200} [0-9]{1,10} [A-Za-z0-9]{50,200}\r\n$" - private static final String PATTERN = "^SENDFILE [A-Za-z0-9]{50,200} [0-9]{1,10} [A-Za-z0-9]{50,200}\\r\\n$"; + private static final String PATTERN = FFE_SENDFILE; public static final String NAME = "SENDFILE"; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 267cc92..2f83c00 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"QTWuH0rNYf0+8ondzDlFeA==","size":301,"iv":"r+Lw9Qpo5Ca7cO45MytKwA==","storage":["lightcontainerSB01"]},{"name":"regex.txt","fileNameSalt":"hPTgHiTySuUiJE0I4QD1Gw==","size":1320,"iv":"Uw7pAMKAEJRL/vn2NJ//wA==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"JNJhoZl+MEBAZ+YSvpaCAg==","size":301,"iv":"eHHLWbm3Wry49SIkgofVTg==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From b5db3d91eaddd0b290f18ee01ba6fe5b02c95df2 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:57:25 +0100 Subject: [PATCH 34/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FSIGN=5FERRO?= =?UTF-8?q?R=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/writer/SignErrorRule.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java index ca02cc6..394ca0b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java @@ -1,13 +1,16 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; + +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_ERROR; /** * Règle renvoyée au client lorsque l'authentification a échoué. */ public class SignErrorRule extends ProtocolWriter { //"^SIGN_ERROR\r\n$" - private static final String PATTERN = "^SIGN_ERROR\r\n$"; + private static final String PATTERN = FFE_SIGN_ERROR; public static final String NAME = "SIGN_ERROR"; From dccd94c0c6074002f8acf056270a87048fbbde98 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 13:58:28 +0100 Subject: [PATCH 35/39] =?UTF-8?q?Nouvelles=20Regex=20:=20FFE=5FSIGN=5FOK?= =?UTF-8?q?=20valid=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/rules/writer/SignOkRule.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java index 05e0295..ee454f6 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java @@ -1,13 +1,16 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.StandardizedDefinitions; + +import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_OK; /** * Règle renvoyée au client lorsque l'authentification a réusie. */ public class SignOkRule extends ProtocolWriter { //"^SIGN_OK\r\n$" - private static final String PATTERN = "^SIGN_OK\r\n$"; + private static final String PATTERN = FFE_SIGN_OK; public static final String NAME = "SIGN_OK"; From bdc8e7cf226886ebc54c93ee8634e41215783cef Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 14:00:21 +0100 Subject: [PATCH 36/39] Nouvelles Regex : Test complet des commandes entre les 3 programmes --- app/src/main/resources/appdata.json | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 2f83c00..b03ebd0 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,16 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$Up/pME2iFKALVSu8/JDpG.8Vc2vidOm99SeVoayCB1th7KHMZ1gq2","aes_key":"4+D3geivckhduP14646nYBb91N71HJj+8uvHFb0su0o=","files":[{"name":"test.txt","fileNameSalt":"JNJhoZl+MEBAZ+YSvpaCAg==","size":301,"iv":"eHHLWbm3Wry49SIkgofVTg==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "lo", + "tls": true, + "storagePath": "C:\\Users\\ledou\\Documents\\ffe", + "users": [ + { + "name": "aaaaa", + "password": "$2a$10$bRdd0/8R60TNUbwtq2dMbun.TAPOZlqxJ/UB7qL2rgxHBuZownH0.", + "aes_key": "FwwA+Mkg94TsXeBuReE6wD3QEsVnrnuIXPtzCLFtdJM=", + "files": [] + } + ] +} \ No newline at end of file From 308bc783acef8031ccf892fd7760b41c48dcd29f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 19 Mar 2022 14:10:50 +0100 Subject: [PATCH 37/39] =?UTF-8?q?-=20Ajout=20possibilit=C3=A9=20de=20faire?= =?UTF-8?q?=20attendre=20une=20t=C3=A2che=20apr=C3=A8s=20un=20SBE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/client/StoreProcessor.java | 6 ++- .../repository/FileFrontEnd.java | 3 +- .../repository/StoreProcessorRepository.java | 17 ++++++-- app/src/main/resources/appdata.json | 43 +------------------ 4 files changed, 20 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 7a90ddf..80c49e0 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -79,9 +79,12 @@ public class StoreProcessor extends Thread implements AutoCloseable { @Override public void run() { this.client_run = true; + while (this.client_run) { try { - waitAction(); + if (protocolResult == null) { // Si on n'a pas encore la commande à envoyer + waitAction(); + } System.out.println("[SBE] Envoie commande : " + protocolResult.getCommand()); // Request @@ -209,7 +212,6 @@ public class StoreProcessor extends Thread implements AutoCloseable { } public boolean canProcessTask() { - System.out.println("[OK 2] " + protocolResult + " - " + domain); return this.protocolResult == null; // Vérifier si tâche veut ce SBE } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index b816212..b808ff0 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -68,12 +68,11 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { private void assignOtherTask(StoreProcessor store) { Iterator it = tasks.iterator(); - while (it.hasNext()) { Task task = it.next(); if (task.getDomain() == null && store.canProcessTask()) { - storeRepository.assignTask(store.getDomain(), task); task.setDomain(store.getDomain()); + store.executeCommand(task.getContext(), task.getCommand()); return; } } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 78783d6..5a3b617 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -75,11 +75,22 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { return null; } + private StoreProcessor getSBE(String stor) { + for (StoreProcessor handler : handlers) { + if (handler.getDomain().equals(stor)) { + return handler; + } + } + + return null; + } + @Override public void assignTask(String stor, Task task) { - StoreProcessor handler = findSBE(); - System.out.println("Find stor : " + handler); - handler.executeCommand(task.getContext(), task.getCommand()); + StoreProcessor handler = getSBE(stor); + if (handler != null) { + handler.executeCommand(task.getContext(), task.getCommand()); + } } @Override diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index c053453..5cd8dca 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1,42 +1 @@ -{ - "unicast_port": 8000, - "multicast_ip": "224.66.66.1", - "multicast_port": 15502, - "network_interface": "wlp1s0", - "tls": true, - "storagePath": "/home/benjamin/ffe", - "users": [ - { - "name": "benjamin", - "password": "$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG", - "aes_key": "mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=", - "files": [ - { - "name": "README.md", - "fileNameSalt": "5k8bd3/hn5ehdkCRJ0MGRQ==", - "size": 17, - "iv": "/sEVBG7kKnMaJcg5Wpz2bQ==", - "storage": [ - "lightcontainerSB02" - ] - } - ] - }, - { - "name": "aaaaa", - "password": "$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W", - "aes_key": "kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=", - "files": [ - { - "name": "ca.crt", - "fileNameSalt": "JmISh065QAtDIePgl8IG2A==", - "size": 4207, - "iv": "Tg3aeOm1U0hQI1VqSZbAJw==", - "storage": [ - "lightcontainerSB01" - ] - } - ] - } - ] -} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"benjamin","password":"$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG","aes_key":"mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=","files":[{"name":"README.md","fileNameSalt":"atK0eGo/J8IBOTCpIZpWow==","size":17,"iv":"fXPzefxl0cO4Hf02Qwi+BA==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"ca.crt","fileNameSalt":"qz6FoPGyJJ8Hy+1LIouvZA==","size":4207,"iv":"8v2H+cOzztD++NXHXw5Ofw==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file From 06c16a289e6ed217695623011fa56f635853d876 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 14:51:16 +0100 Subject: [PATCH 38/39] La taille du fichier est maintenant en long pour supporter les gros fichiers --- .../domains/client/Context.java | 18 +++++++++++++++++- .../domains/client/RequestBundle.java | 19 +++++++++++++++++++ .../protocol/rules/reader/EraseErrorRule.java | 1 - .../protocol/rules/reader/GetFileRule.java | 3 +-- .../protocol/rules/reader/RetrieveOkRule.java | 10 +++++----- .../protocol/rules/reader/SavefileRule.java | 8 ++++---- .../protocol/rules/reader/SignupRule.java | 1 - .../protocol/rules/writer/GetFileOkRule.java | 8 ++++---- .../protocol/rules/writer/SaveFileOkRule.java | 2 +- .../protocol/rules/writer/SendfileRule.java | 4 ++-- .../java/lightcontainer/storage/File.java | 6 +++--- .../lightcontainer/storage/ReadOnlyFile.java | 2 +- .../lightcontainer/utils/FileReceiver.java | 2 +- .../java/lightcontainer/utils/FileSender.java | 10 +++++----- app/src/main/resources/appdata.json | 17 ++++++++++++++++- 15 files changed, 79 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/client/Context.java b/app/src/main/java/lightcontainer/domains/client/Context.java index dc143a1..8e63323 100644 --- a/app/src/main/java/lightcontainer/domains/client/Context.java +++ b/app/src/main/java/lightcontainer/domains/client/Context.java @@ -126,6 +126,14 @@ public class Context { requestBundle.putInt(key, value); } + /** + * @param key La clé permettant de retrouver la valeur + * @param value La valeur associée à la clé + */ + public void putDataLong(String key, long value) { + requestBundle.putLong(key, value); + } + /** * Permet de récupérer des données pour la requête courante * @@ -146,6 +154,14 @@ public class Context { return requestBundle.getInt(key); } + /** + * @param key La clé permettant de retrouver la valeur + * @return La valeur associée à la clé + */ + public long getDataLong(String key) { + return requestBundle.getLong(key); + } + /** * Permet d'ajouter un fichier à l'utilisateur * @@ -156,7 +172,7 @@ public class Context { * @param domain Domain dans lequel est stocké le fichier * @return TRUE si le fichier a pu être enregistré. */ - public boolean addFile(String fileName, String fileNameSalt, int size, String iv, String domain) { + public boolean addFile(String fileName, String fileNameSalt, long size, String iv, String domain) { return this.repository.addFileFor(new File(fileName, fileNameSalt, size, iv, Set.of(domain)), getLogin()); } diff --git a/app/src/main/java/lightcontainer/domains/client/RequestBundle.java b/app/src/main/java/lightcontainer/domains/client/RequestBundle.java index 6d9fd09..99e0615 100644 --- a/app/src/main/java/lightcontainer/domains/client/RequestBundle.java +++ b/app/src/main/java/lightcontainer/domains/client/RequestBundle.java @@ -9,6 +9,8 @@ public class RequestBundle { private final Map intData = new HashMap<>(); + private final Map longData = new HashMap<>(); + /** * Permet d'ajouter des String * @@ -48,4 +50,21 @@ public class RequestBundle { public int getInt(String key) { return intData.get(key); } + + /** + * @param key La clé permettant de retrouver la valeur + * @param value La valeur associée à la clé + */ + public void putLong(String key, long value) { + longData.put(key, value); + } + + /** + * + * @param key La clé permettant de retrouver la valeur + * @return La valeur associée à la clé ou null + */ + public long getLong(String key) { + return longData.get(key); + } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java index cb25c5e..f9a4be3 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java @@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; -import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_ERROR; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java index 12d5a45..1fe4b87 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java @@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; -import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.GetFileErrorRule; import lightcontainer.protocol.rules.writer.RetrieveFileRule; import lightcontainer.storage.ReadOnlyFile; @@ -62,7 +61,7 @@ public class GetFileRule extends ProtocolReader { // Save into bundle context.putDataString("fileName", file.getName()); - context.putDataInt("fileSize", file.getSize()); + context.putDataLong("fileSize", file.getSize()); context.putDataString("fileIV", file.getIv()); // Create cmd for storebacked diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index 24d1fc9..a2ac0cb 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -37,10 +37,10 @@ public class RetrieveOkRule extends ProtocolReader { public class Result extends ProtocolResult { // Variables private final String filename; - private final int filesize; + private final long filesize; private String hashedFileContent; - public Result(Context context, String filename, int filesize, String hashedFileContent) { + public Result(Context context, String filename, long filesize, String hashedFileContent) { super(context); this.filename = filename; this.filesize = filesize; @@ -51,7 +51,7 @@ public class RetrieveOkRule extends ProtocolReader { return filename; } - public int getFilesize() { + public long getFilesize() { return filesize; } @@ -81,11 +81,11 @@ public class RetrieveOkRule extends ProtocolReader { RetrieveOkRule.Result result = new RetrieveOkRule.Result(context, data[HASHED_FILE_NAME], Integer.parseInt(data[FILE_SIZE]), data[HASHED_FILE_CONTENT]); // save encrypted file size into bundle - context.putDataInt("encryptedFileSize", result.getFilesize()); // TODO to long ?! + context.putDataLong("encryptedFileSize", result.getFilesize()); // TODO to long ?! context.putDataString("hashedFileName", result.getFilename()); // Set result command - result.setResultCommand(protocolRep.executeWriter(context, GetFileOkRule.NAME, context.getDataString("fileName"), String.valueOf(context.getDataInt("fileSize"))), ResultCmdReceiver.CLIENT); + result.setResultCommand(protocolRep.executeWriter(context, GetFileOkRule.NAME, context.getDataString("fileName"), String.valueOf(context.getDataLong("fileSize"))), ResultCmdReceiver.CLIENT); return result; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index b573454..8112cad 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -43,10 +43,10 @@ public class SavefileRule extends ProtocolReader { public class Result extends ProtocolResult { // Variables private String filename; - private final int size; + private final long size; // Construct - public Result(Context context, String filename, int size) { + public Result(Context context, String filename, long size) { super(context); this.filename = filename; this.size = size; @@ -75,7 +75,7 @@ public class SavefileRule extends ProtocolReader { String iv = AES_GCM.generateIV(); // retrieve file and new size - int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv); + long encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv); if (encryptedFileSize < 0) throw new IOException(); System.out.println(encryptedFileSize); @@ -83,7 +83,7 @@ public class SavefileRule extends ProtocolReader { String fileHash = SHA.hashFile(storagePath, this.filename); // On met les données de la requête actuelle - getContext().putDataInt("size", size); + getContext().putDataLong("size", size); getContext().putDataString("iv", iv); getContext().putDataString("fileNameSalt", fileNameSalt); diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index ebf7468..ce08172 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; -import lightcontainer.protocol.StandardizedDefinitions; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java index 2f7e66c..a0327b5 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -33,10 +33,10 @@ public class GetFileOkRule extends ProtocolWriter { public class Result extends ProtocolWriter.ProtocolResult { // Variables private final String filename; - private final int filesize; + private final long filesize; // Constructors - public Result(Context context, String filename, int filesize) { + public Result(Context context, String filename, long filesize) { super(context); this.filename = filename; this.filesize = filesize; @@ -51,12 +51,12 @@ public class GetFileOkRule extends ProtocolWriter { public void write(OutputStream writer) throws IOException { System.out.printf("Sauvegarde du fichier : %s %d\n", this.filename, this.filesize); - System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize") + " normal: " + getContext().getDataInt("fileSize")); + System.out.println("Encrypted size for parsing: " + getContext().getDataLong("encryptedFileSize") + " normal: " + getContext().getDataLong("fileSize")); FileSender fileSender = new FileSender(storagePath); fileSender.sendFile( getContext().getDataString("hashedFileName"), writer, - getContext().getDataInt("encryptedFileSize"), // Encrypted file size (because data is parsing into AES system) + getContext().getDataLong("encryptedFileSize"), // Encrypted file size (because data is parsing into AES system) getContext().getAesKey(), getContext().getDataString("fileIV") ); diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 6078af1..7debda1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -32,7 +32,7 @@ public class SaveFileOkRule extends ProtocolWriter { System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin()); // Sauvegarder dans JSON - context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain()); + context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataLong("size"), context.getDataString("iv"), context.getDomain()); // Suppression du fichier temporaire dans le stockage du FFE String hashedFileName = context.getHashedFileName(context.getDataString("fileName")); diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index aa44928..4dd9b18 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -33,10 +33,10 @@ public class SendfileRule extends ProtocolWriter { public class Result extends ProtocolWriter.ProtocolResult { private final String hashedFileName; - private final int fileSize; + private final long fileSize; private final String hashedFileContent; - public Result(Context context, String hashedFileName, int fileSize, String hashedFileContent) { + public Result(Context context, String hashedFileName, long fileSize, String hashedFileContent) { super(context); this.hashedFileName = hashedFileName; this.fileSize = fileSize; diff --git a/app/src/main/java/lightcontainer/storage/File.java b/app/src/main/java/lightcontainer/storage/File.java index 4c3ab3d..18ee90d 100644 --- a/app/src/main/java/lightcontainer/storage/File.java +++ b/app/src/main/java/lightcontainer/storage/File.java @@ -10,12 +10,12 @@ public class File implements ReadOnlyFile { // Variables private final String name; private final String fileNameSalt; - private final int size; + private final long size; private final String iv; private final Set storage; // Constructor - public File(String name, String fileNameSalt, int size, String iv, Set storage) { + public File(String name, String fileNameSalt, long size, String iv, Set storage) { this.name = name; this.fileNameSalt = fileNameSalt; this.size = size; @@ -34,7 +34,7 @@ public class File implements ReadOnlyFile { } @Override - public int getSize() { + public long getSize() { return size; } diff --git a/app/src/main/java/lightcontainer/storage/ReadOnlyFile.java b/app/src/main/java/lightcontainer/storage/ReadOnlyFile.java index ae7bf29..f5f77b7 100644 --- a/app/src/main/java/lightcontainer/storage/ReadOnlyFile.java +++ b/app/src/main/java/lightcontainer/storage/ReadOnlyFile.java @@ -8,7 +8,7 @@ public interface ReadOnlyFile { String getFileNameSalt(); - int getSize(); + long getSize(); String getIv(); diff --git a/app/src/main/java/lightcontainer/utils/FileReceiver.java b/app/src/main/java/lightcontainer/utils/FileReceiver.java index 634e5ec..3a6e4d1 100644 --- a/app/src/main/java/lightcontainer/utils/FileReceiver.java +++ b/app/src/main/java/lightcontainer/utils/FileReceiver.java @@ -9,7 +9,7 @@ public class FileReceiver { this.path = path; } - public int receiveFile(InputStream input, String fileName, int fileSize, String key, String iv) { + public int receiveFile(InputStream input, String fileName, long fileSize, String key, String iv) { try { File file = new File(String.format("%s/%s", path, fileName)); if (file.createNewFile()) { diff --git a/app/src/main/java/lightcontainer/utils/FileSender.java b/app/src/main/java/lightcontainer/utils/FileSender.java index fe97aa3..5781961 100644 --- a/app/src/main/java/lightcontainer/utils/FileSender.java +++ b/app/src/main/java/lightcontainer/utils/FileSender.java @@ -10,7 +10,7 @@ public class FileSender { this.path = path; } - public boolean sendFile(String filename, OutputStream out, int fileSize, String aesKey, String iv) throws IOException { + public boolean sendFile(String filename, OutputStream out, long fileSize, String aesKey, String iv) throws IOException { BufferedInputStream bisFile; System.out.printf("Envoie fichier : %s - %s - %s \n", filename, aesKey, iv); try { @@ -28,7 +28,7 @@ public class FileSender { public boolean sendFile(String filename, OutputStream out) throws IOException { BufferedInputStream bisFile; - int bytesReaded = 0; + int bytesRead = 0; try { File file = new File(String.format("%s/%s", path, filename)); long fileSize = file.length(); @@ -36,10 +36,10 @@ public class FileSender { byte[] buffer = new byte[DEFAULT_BUFFER]; bisFile = new BufferedInputStream(new FileInputStream(file)); long currentOffset = 0; - while ((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { - out.write(buffer, 0, bytesReaded); + while ((currentOffset < fileSize) && (bytesRead = bisFile.read(buffer)) > 0) { + out.write(buffer, 0, bytesRead); out.flush(); - currentOffset += bytesReaded; + currentOffset += bytesRead; } bisFile.close(); return true; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 5cd8dca..51a1b6b 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,16 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"benjamin","password":"$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG","aes_key":"mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=","files":[{"name":"README.md","fileNameSalt":"atK0eGo/J8IBOTCpIZpWow==","size":17,"iv":"fXPzefxl0cO4Hf02Qwi+BA==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"ca.crt","fileNameSalt":"qz6FoPGyJJ8Hy+1LIouvZA==","size":4207,"iv":"8v2H+cOzztD++NXHXw5Ofw==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "lo", + "tls": true, + "storagePath": "C:\\Users\\ledou\\Documents\\ffe", + "users": [ + { + "name": "aaaaa", + "password": "$2a$10$6KbB.cBqsWyRExIf2ugkhebsJOhUG9goXFEfOYWXJI4dOQNT1uXhu", + "aes_key": "2gYT1TeILBswvCbxAth24ZNLtFhaA1zvdJmtfh0unNE=", + "files": [] + } + ] +} \ No newline at end of file From 3cf0f66ae9e6da06484bb370267b4329cf3dbaf8 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 19 Mar 2022 16:48:59 +0100 Subject: [PATCH 39/39] =?UTF-8?q?-=20Syst=C3=A8eme=20de=20timer=20d=C3=A9t?= =?UTF-8?q?ectant=20les=20SBE=20innactif=20et=20les=20timeout=20si=20ceux-?= =?UTF-8?q?ci=20ne=20donnent=20pas=20signe=20d'activit=C3=A9=20apr=C3=A8s?= =?UTF-8?q?=2050=20secondes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 7 +++ .../java/lightcontainer/domains/FFETimer.java | 34 +++++++++++ .../domains/client/StoreProcessor.java | 22 ++++++- .../server/MulticastServerListener.java | 2 + .../interfaces/MulticastSPR.java | 22 +++++++ .../repository/FileFrontEnd.java | 1 - .../repository/StoreProcessorRepository.java | 60 +++++++++++++++---- app/src/main/resources/appdata.json | 25 +++++++- 8 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/lightcontainer/domains/FFETimer.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 31d329f..7e04d2c 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -3,6 +3,7 @@ */ package lightcontainer; +import lightcontainer.domains.FFETimer; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; import lightcontainer.interfaces.ProtocolRepository; @@ -17,6 +18,7 @@ import lightcontainer.storage.JsonAdapter; import lightcontainer.storage.Repository; import java.nio.file.Paths; +import java.util.Timer; public class App { @@ -36,6 +38,11 @@ public class App { FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep); new UnicastServerListener(ffe, clientRep, protocolRep, repositoryStorage, repositoryStorage.getUnicastPort()); new MulticastServerListener(ffe, storeRep, protocolRep, repositoryStorage.getMulticastIp(), repositoryStorage.getMulticastPort(), repositoryStorage.getNetworkInterface()); + + // S'occupe de distribué les timeout pour les SBE plus connecté et donc de Timeout les clients + Timer ffeTimer = new Timer(); + ffeTimer.schedule(new FFETimer(storeRep), 50000, 50000); + } private static void initProtocols(Repository repositoryStorage, ProtocolRepository protocolRep) { diff --git a/app/src/main/java/lightcontainer/domains/FFETimer.java b/app/src/main/java/lightcontainer/domains/FFETimer.java new file mode 100644 index 0000000..3a6193f --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/FFETimer.java @@ -0,0 +1,34 @@ +package lightcontainer.domains; + +import lightcontainer.interfaces.MulticastSPR; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.TimerTask; + +/** + * Class s'occupant de gérer les timeout des différents SBE + */ +public class FFETimer extends TimerTask { + + private final MulticastSPR processorRepository; + + public FFETimer(MulticastSPR processorRepository) { + this.processorRepository = processorRepository; + } + + @Override + public void run() { + System.out.println("Timer 1"); + for (String domain : processorRepository.getDomains()) { + LocalDateTime lastAnnounce = processorRepository.getLastAnnounce(domain); + long secondBetween = Math.abs(ChronoUnit.SECONDS.between(lastAnnounce, LocalDateTime.now())); + + System.out.println("Timer 2 : " + secondBetween); + if (secondBetween > 50) { + System.out.println("Timer 3"); + processorRepository.closeStore(domain); + } + } + } +} diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 80c49e0..9c938dc 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -8,7 +8,9 @@ import lightcontainer.protocol.ProtocolWriter; import java.io.*; import java.net.Socket; +import java.net.SocketException; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; import java.util.Objects; /** @@ -30,6 +32,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { private final Socket store; private final String domain; private boolean client_run; + private LocalDateTime lastAnnounce; private BufferedReader reader; private Context context; @@ -37,6 +40,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { private ProtocolWriter.ProtocolResult protocolResult; private final ProtocolRepository protocolRep; + // Constructor public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe, ProtocolRepository protocolRep) { this.domain = domain; @@ -94,8 +98,6 @@ public class StoreProcessor extends Thread implements AutoCloseable { try { protocolResult.write(this.store.getOutputStream()); } catch (IOException writeException) { // Si SBE fermé - System.out.println("STOPPER"); - writeException.printStackTrace(); // Envoie au client que la requête n'a pu être traitée alertAvailable(null); break; @@ -188,6 +190,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { public void close() { if (this.client_run) { this.client_run = false; + System.out.println("[FERMETURE SBE] " + domain); // TODO : Gérer déconnection (enlever du repo et prévenir client et FileFrontEnd) } } @@ -218,4 +221,19 @@ public class StoreProcessor extends Thread implements AutoCloseable { public String getDomain() { return this.domain; } + + + /** + * Permet de mettre à jours la dernière annonce de ce SBE au FFE + */ + public void setLastAnnounce(LocalDateTime lastAnnounce) { + this.lastAnnounce = lastAnnounce; + } + + /** + * Permet de mettre à jours la dernière annonce de ce SBE au FFE + */ + public LocalDateTime getLastAnnounce() { + return lastAnnounce; + } } diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index ba40f10..32e9c42 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -94,6 +94,8 @@ public class MulticastServerListener implements Runnable { // Add the store processor to its repository this.repository.addStore(storeProcessor); } + // Contient déjà le SBE donc maj de la dernière activité + this.repository.updateLastAnnounce(readerResult.getDomain()); } catch (IOException | ClassCastException exception) { System.out.println("[ERREUR] Une SBE essaye de se connecter avec une mauvaise configuration : " + exception.getMessage()); } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 7aee90a..08fff0f 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -5,6 +5,9 @@ import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.repository.StoreProcessorRepository; +import java.time.LocalDateTime; +import java.util.Collection; + /** * A communication interface between a {@link StoreProcessor} and the {@link StoreProcessorRepository}. */ @@ -42,4 +45,23 @@ public interface MulticastSPR { * @param domain Le domaine du SBE à déconnecter */ void closeStore(String domain); + + /** + * Permet de mettre à jours la dernière annonce de ce SBE au FFE + * @param domain Le domain s'annoncant + */ + void updateLastAnnounce(String domain); + + + /** + * Permet de récupérer les noms des domaines connectés au FFE + * @return Les noms des domaines connectés au FFE + */ + Collection getDomains(); + + /** + * Permet de récupérer la dernière annonce d'un SBE + * @return La dernière annonce d'un SBE + */ + LocalDateTime getLastAnnounce(String domain); } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index b808ff0..66a4f94 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -47,7 +47,6 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ @Override public void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response) { - // TODO : Chercher une tâche appropriée Iterator it = tasks.iterator(); while (it.hasNext()) { Task task = it.next(); diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 5a3b617..4616a42 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -5,6 +5,8 @@ import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.interfaces.MulticastSPR; +import java.time.LocalDateTime; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -123,19 +125,54 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { */ @Override public void closeStore(String domain) { - Iterator it = this.handlers.iterator(); - - System.out.println("1 Nombre de SBE : " + handlers.size()); - while (it.hasNext()) { - StoreProcessor storeProcessor = it.next(); - if (storeProcessor.getDomain().equals(domain)) { - storeProcessor.close(); - it.remove(); - return; - } + StoreProcessor storeProcessor = getSBE(domain); + if (storeProcessor != null) { + storeProcessor.close(); + handlers.remove(storeProcessor); } } + /** + * Permet de mettre à jours la dernière annonce de ce SBE au FFE + * + * @param domain Le domain s'annoncant + */ + @Override + public void updateLastAnnounce(String domain) { + StoreProcessor storeProcessor = getSBE(domain); + if (storeProcessor != null) { + storeProcessor.setLastAnnounce(LocalDateTime.now()); + } + } + + /** + * Permet de récupérer les noms des domaines connectés au FFE + * + * @return Les noms des domaines connectés au FFE + */ + @Override + public Collection getDomains() { + Set domains = new HashSet<>(); + + for (StoreProcessor domain : handlers) { + domains.add(domain.getDomain()); + } + + return domains; + } + + /** + * Permet de récupérer la dernière annonce d'un SBE + * + * @param domain + * @return La dernière annonce d'un SBE + */ + @Override + public LocalDateTime getLastAnnounce(String domain) { + StoreProcessor storeProcessor = getSBE(domain); + return storeProcessor == null ? null : storeProcessor.getLastAnnounce(); + } + /** * AutoClosable Function * Closes all StoreProcessor stored in this repository and deallocates all resources. @@ -149,4 +186,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { // Close each client. this.handlers.forEach(StoreProcessor::close); } + + + } diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 5cd8dca..7d33a47 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,24 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"benjamin","password":"$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG","aes_key":"mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=","files":[{"name":"README.md","fileNameSalt":"atK0eGo/J8IBOTCpIZpWow==","size":17,"iv":"fXPzefxl0cO4Hf02Qwi+BA==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"ca.crt","fileNameSalt":"qz6FoPGyJJ8Hy+1LIouvZA==","size":4207,"iv":"8v2H+cOzztD++NXHXw5Ofw==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "wlp1s0", + "tls": true, + "storagePath": "/home/benjamin/ffe", + "users": [ + { + "name": "benjamin", + "password": "$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG", + "aes_key": "mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=", + "files": [ + ] + }, + { + "name": "aaaaa", + "password": "$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W", + "aes_key": "kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=", + "files": [ + ] + } + ] +} \ No newline at end of file