From 5dd70d9bcffc2e4fffc254a73506754c51dcfe0d Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Mar 2022 14:16:13 +0100 Subject: [PATCH 1/6] =?UTF-8?q?Regex=20:=20quelques=20impl=C3=A9mentations?= 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 2/6] =?UTF-8?q?Regex=20:=20toutes=20iml=C3=A9ment=C3=A9es?= 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 3/6] 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 4/6] 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 5/6] =?UTF-8?q?Regex=20:=20anciennes=20utilis=C3=A9es=20ca?= =?UTF-8?q?r=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 f87c81aba4bf009a92887d330bc059d100772f0c Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 15 Mar 2022 21:10:34 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Correction=20bugs=20de=20suppression=20de?= =?UTF-8?q?=20fichiers=20sur=20le=20FFE=20apr=C3=A8s=20upload=20et=20r?= =?UTF-8?q?=C3=A9cup=C3=A9ration,=20optimisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/reader/RetrieveOkRule.java | 11 ++++++++++- .../protocol/rules/writer/GetFileOkRule.java | 8 +++++++- .../protocol/rules/writer/SaveFileOkRule.java | 3 +-- .../java/lightcontainer/utils/FileReceiver.java | 17 ++++++++--------- .../java/lightcontainer/utils/FileSender.java | 11 +++++------ app/src/main/java/lightcontainer/utils/SHA.java | 6 +++++- app/src/main/resources/appdata.json | 2 +- 7 files changed, 37 insertions(+), 21 deletions(-) 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 226e2f5..3d7044d 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -43,6 +43,14 @@ public class RetrieveOkRule extends ProtocolReader { this.hashedFileContent = hashedFileContent; } + public String getFilename() { + return filename; + } + + public int getFilesize() { + return filesize; + } + /** * Bitch has bettern than my money * @param reader Buffer rempli du fichier @@ -70,7 +78,8 @@ 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", Integer.parseInt(data[FILE_SIZE])); // TODO to long ?! + context.putDataInt("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); 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 87dc71d..8b5078a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -6,6 +6,8 @@ import lightcontainer.utils.FileSender; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; public class GetFileOkRule extends ProtocolWriter { // Constants @@ -47,12 +49,16 @@ public class GetFileOkRule extends ProtocolWriter { System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize")+" normal: "+getContext().getDataInt("fileSize")); FileSender fileSender = new FileSender(storagePath); fileSender.sendFile( - getContext().getHashedFileName(this.filename), + getContext().getDataString("hashedFileName"), writer, getContext().getDataInt("encryptedFileSize"), // Encrypted file size (because data is parsing into AES system) getContext().getAesKey(), getContext().getDataString("fileIV") ); + + try { + Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, getContext().getDataString("hashedFileName")))); + } 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 fac890f..13473f5 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -34,8 +34,7 @@ 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 ignore) {} return result; } } diff --git a/app/src/main/java/lightcontainer/utils/FileReceiver.java b/app/src/main/java/lightcontainer/utils/FileReceiver.java index 826bb1f..f852587 100644 --- a/app/src/main/java/lightcontainer/utils/FileReceiver.java +++ b/app/src/main/java/lightcontainer/utils/FileReceiver.java @@ -8,18 +8,17 @@ public class FileReceiver { public FileReceiver(String path) { this.path = path; } public int receiveFile(InputStream input, String fileName, int fileSize, String key, String iv) { - BufferedOutputStream bosFile = null; - try { - bosFile = new BufferedOutputStream(new FileOutputStream(String.format("%s/%s", path, fileName))); - - AES_GCM.encryptStream(input, bosFile, fileSize, key, iv); - - File f = new File(String.format("%s/%s", path, fileName)); - return (int)f.length(); // TODO change the size to LONG + File file = new File(String.format("%s/%s", path, fileName)); + if (file.createNewFile()) { + try (BufferedOutputStream bufferedStream = new BufferedOutputStream(new FileOutputStream(file))) { + // AES close l'outputstream mais on le try with ressources au cas ou ;) + AES_GCM.encryptStream(input, bufferedStream, fileSize, key, iv); + } + } + return (int)file.length(); // TODO change the size to LONG } catch(IOException | AES_GCM.AesGcmException ex) { ex.printStackTrace(); - if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} } return -1; } } diff --git a/app/src/main/java/lightcontainer/utils/FileSender.java b/app/src/main/java/lightcontainer/utils/FileSender.java index 008618a..227855d 100644 --- a/app/src/main/java/lightcontainer/utils/FileSender.java +++ b/app/src/main/java/lightcontainer/utils/FileSender.java @@ -27,13 +27,12 @@ public class FileSender { public boolean sendFile(String filename, OutputStream out) throws IOException { BufferedInputStream bisFile; int bytesReaded = 0; - try { - File f = new File(String.format("%s/%s", path, filename)); - long fileSize = f.length(); - if(f.exists()) { + File file = new File(String.format("%s/%s", path, filename)); + long fileSize = file.length(); + if(file.exists()) { byte[] buffer = new byte[DEFAULT_BUFFER]; - bisFile = new BufferedInputStream(new FileInputStream(f)); + bisFile = new BufferedInputStream(new FileInputStream(file)); long currentOffset = 0; while((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { out.write(buffer, 0, bytesReaded); out.flush(); @@ -43,7 +42,7 @@ public class FileSender { return true; } else return false; - } catch(IOException ex) { + } catch(IOException ex) {// todo change throw ex; } } diff --git a/app/src/main/java/lightcontainer/utils/SHA.java b/app/src/main/java/lightcontainer/utils/SHA.java index 0f76efa..25cd806 100644 --- a/app/src/main/java/lightcontainer/utils/SHA.java +++ b/app/src/main/java/lightcontainer/utils/SHA.java @@ -87,7 +87,11 @@ public class SHA { public static String hashFile(String rootPath, String fileName) throws ShaException { try { File file = new File(String.format("%s/%s", rootPath, fileName)); - return hashStream(new FileInputStream(file), file.length()); + String hash; + try (InputStream inStream = new FileInputStream(file)) { + hash = hashStream(inStream, file.length()); + } + return hash; } catch (Exception e) { throw new ShaException(e); } diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 1b71617..e26d31b 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":"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