Regex : toutes imlémentées

This commit is contained in:
Maximilien LEDOUX 2022-03-15 15:39:58 +01:00
parent 5dd70d9bcf
commit dd033fd19c
20 changed files with 75 additions and 42 deletions

View File

@ -8,7 +8,7 @@ public class StandardizedDefinitions {
private final static String PASSCHAR = "[\\x20-\\xFF]"; private final static String PASSCHAR = "[\\x20-\\xFF]";
private final static String BINARY = "[\\x00-\\xFF]"; private final static String BINARY = "[\\x00-\\xFF]";
private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]"; private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]";
private final static String DIGIT_LETTER = 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 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 SIZE = DIGIT + "{1,10}";
private final static String LINE = "\\x0D\\x0A"; 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 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_OK = "^SEND_OK" + LINE + "$";
public final static String SBE_SEND_RESULT_ERROR = "^SEND_ERROR" + 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_OK = "^ERASE_OK" + LINE + "$";
public final static String SBE_ERASE_RESULT_ERROR = "^ERASE_ERROR" + 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_OK = "^RETRIEVE_OK" + BL + FILE_INFO + LINE + "$";
public final static String SBE_RETRIEVE_RESULT_ERROR = "^RETRIEVE_ERROR" + LINE + "$"; public final static String SBE_RETRIEVE_RESULT_ERROR = "^RETRIEVE_ERROR" + LINE + "$";

View File

@ -4,17 +4,16 @@ import lightcontainer.domains.client.Context;
import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.ProtocolRepository;
import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.protocol.rules.writer.SaveFileErrorRule;
import lightcontainer.protocol.rules.writer.SaveFileOkRule;
import lightcontainer.protocol.rules.writer.SendfileRule; import lightcontainer.protocol.rules.writer.SendfileRule;
import lightcontainer.utils.AES_GCM; import lightcontainer.utils.AES_GCM;
import lightcontainer.utils.FileReceiver; import lightcontainer.utils.FileReceiver;
import lightcontainer.utils.SHA; import lightcontainer.utils.SHA;
import lightcontainer.utils.ShaHasher; import lightcontainer.utils.ShaHasher;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; 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. * Règle permettant de sauvegarder un fichier sur le SBE.
@ -22,7 +21,7 @@ import java.security.NoSuchAlgorithmException;
*/ */
public class SavefileRule extends ProtocolReader { public class SavefileRule extends ProtocolReader {
// Constants // 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"; private static final String NAME = "SAVEFILE";

View File

@ -4,18 +4,15 @@ import lightcontainer.domains.client.Context;
import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.ProtocolRepository;
import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.protocol.rules.writer.SaveFileErrorRule;
import lightcontainer.utils.ShaHasher;
import java.io.IOException; import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_ERROR;
import java.nio.file.Files;
import java.nio.file.Path;
/** /**
* Règle permettant de de confirmer la sauvegrade d'un fichier. * Règle permettant de de confirmer la sauvegrade d'un fichier.
*/ */
public class SendErrorRule extends ProtocolReader { public class SendErrorRule extends ProtocolReader {
// Constants // 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"; private static final String NAME = "SEND_ERROR";

View File

@ -5,9 +5,7 @@ import lightcontainer.interfaces.ProtocolRepository;
import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.rules.writer.SaveFileOkRule; import lightcontainer.protocol.rules.writer.SaveFileOkRule;
import java.io.IOException; import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_OK;
import java.nio.file.Files;
import java.nio.file.Path;
/** /**
* Règle permettant de de confirmer la sauvegrade d'un fichier. * 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 { public class SendOkRule extends ProtocolReader {
// Constants // 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"; private static final String NAME = "SEND_OK";

View File

@ -6,12 +6,14 @@ import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignErrorRule;
import lightcontainer.protocol.rules.writer.SignOkRule; 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 * Règle permettant de gérer la connection d'un utilisateur
*/ */
public class SigninRule extends ProtocolReader { public class SigninRule extends ProtocolReader {
// Constants // 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"; private static final String NAME = "SIGNIN";

View File

@ -3,12 +3,14 @@ package lightcontainer.protocol.rules.reader;
import lightcontainer.domains.client.Context; import lightcontainer.domains.client.Context;
import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.ProtocolReader;
import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_OUT;
/** /**
* Règle demandant la déconnexion du client * Règle demandant la déconnexion du client
*/ */
public class SignoutRule extends ProtocolReader { 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"; public static final String NAME = "SIGNOUT";

View File

@ -6,12 +6,14 @@ import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignErrorRule;
import lightcontainer.protocol.rules.writer.SignOkRule; 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 * Règle permettant de gérer la création d'un utilisateur
*/ */
public class SignupRule extends ProtocolReader { public class SignupRule extends ProtocolReader {
// Constants // 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 String NAME = "SIGNUP";
private static final int LOGIN = 0; private static final int LOGIN = 0;
private static final int PASSWORD = 1; private static final int PASSWORD = 1;

View File

@ -2,14 +2,18 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.ProtocolWriter;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_ERASE_FILE;
public class EraseFileRule extends ProtocolWriter { 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 static String NAME = "ERASEFILE";
public EraseFileRule() { public EraseFileRule() {
super(NAME, PATTERN); super(NAME, PATTERN);
System.out.println(PATTERN);
} }
} }

View File

@ -2,12 +2,14 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; 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 * Règle permettant de construire une commande contenant la liste des fichiers d'un utilisateur
*/ */
public class FilesRule extends ProtocolWriter { 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"; public static final String NAME = "FILES";

View File

@ -2,13 +2,16 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; 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 * Règle utilisé dans le cas ou une erreur survient lors
* de la demande de récupération d'un fichier. * de la demande de récupération d'un fichier.
*/ */
public class GetFileErrorRule extends ProtocolWriter { public class GetFileErrorRule extends ProtocolWriter {
// Constants // 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"; public static final String NAME = "GETFILE_ERROR";
// Constructors // Constructors

View File

@ -6,9 +6,12 @@ import lightcontainer.utils.FileSender;
import java.io.OutputStream; import java.io.OutputStream;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_GET_FILE_RESULT_OK;
public class GetFileOkRule extends ProtocolWriter { public class GetFileOkRule extends ProtocolWriter {
// Constants // 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"; public static final String NAME = "GETFILE_OK";
// -- params // -- params
private static final int FILE_NAME = 0; // Index file name hashed private static final int FILE_NAME = 0; // Index file name hashed
@ -37,6 +40,7 @@ public class GetFileOkRule extends ProtocolWriter {
/** /**
* Oh yeahh baby * Oh yeahh baby
*
* @param writer Buffer à remplir qui sera envoyer via le réseau * @param writer Buffer à remplir qui sera envoyer via le réseau
*/ */
@Override @Override

View File

@ -2,9 +2,12 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.ProtocolWriter;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_REMOVE_ERROR;
public class RemoveFileErrorRule extends ProtocolWriter { 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"; public static String NAME = "REMOVEFILE_ERROR";

View File

@ -2,9 +2,11 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; 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 static String NAME = "REMOVEFILE_OK";
public RemoveFileOkRule() { public RemoveFileOkRule() {

View File

@ -2,9 +2,12 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.ProtocolWriter;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_RETRIEVE_FILE;
public class RetrieveFileRule extends ProtocolWriter { public class RetrieveFileRule extends ProtocolWriter {
// Constants // 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"; public static final String NAME = "RETRIEVEFILE";
// Constructor // Constructor

View File

@ -8,12 +8,14 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; 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é * Règle signifiant que la sauvegarde d'un fichier a échoué
*/ */
public class SaveFileErrorRule extends ProtocolWriter { 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"; public static final String NAME = "SAVEFILE_ERROR";
@ -37,7 +39,8 @@ public class SaveFileErrorRule extends ProtocolWriter {
hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt"))) hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt")))
) )
)); ));
} catch (IOException e) {} } catch (IOException e) {
}
return result; return result;
} }

View File

@ -7,12 +7,14 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; 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 * Règle signifiant que la sauvegarde d'un fichier fût un succès
*/ */
public class SaveFileOkRule extends ProtocolWriter { public class SaveFileOkRule extends ProtocolWriter {
//"^SAVEFILE_OK\r\n$"
private static final String PATTERN = "^SAVEFILE_OK\r\n$"; private static final String PATTERN = FFE_SAVE_FILE_OK;
public static final String NAME = "SAVEFILE_OK"; public static final String NAME = "SAVEFILE_OK";
@ -34,7 +36,8 @@ public class SaveFileOkRule extends ProtocolWriter {
String hashedFileName = context.getHashedFileName(context.getDataString("fileName")); String hashedFileName = context.getHashedFileName(context.getDataString("fileName"));
try { try {
Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName))); Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName)));
} catch (IOException e) {} } catch (IOException e) {
}
return result; return result;
} }

View File

@ -6,19 +6,21 @@ import lightcontainer.utils.FileSender;
import java.io.OutputStream; import java.io.OutputStream;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SENDFILE;
/** /**
* Règle envoyée au SBE, demandant la sauvegarde d'un fichier. * Règle envoyée au SBE, demandant la sauvegarde d'un fichier.
*/ */
public class SendfileRule extends ProtocolWriter { 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"; public static final String NAME = "SENDFILE";
private static final int HASHED_FILE_NAME = 0; // Index file name hashed. 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 FILE_SIZE = 1; // Index file size.
private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed. private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed.
private String storagePath; private String storagePath;
public SendfileRule(String storagePath) { public SendfileRule(String storagePath) {

View File

@ -2,12 +2,14 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.ProtocolWriter;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_ERROR;
/** /**
* Règle renvoyée au client lorsque l'authentification a échoué. * Règle renvoyée au client lorsque l'authentification a échoué.
*/ */
public class SignErrorRule extends ProtocolWriter { 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"; public static final String NAME = "SIGN_ERROR";

View File

@ -2,12 +2,14 @@ package lightcontainer.protocol.rules.writer;
import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.ProtocolWriter;
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_OK;
/** /**
* Règle renvoyée au client lorsque l'authentification a réusie. * Règle renvoyée au client lorsque l'authentification a réusie.
*/ */
public class SignOkRule extends ProtocolWriter { 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"; public static final String NAME = "SIGN_OK";

View File

@ -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"]}]}]} {"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"]}]}]}