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 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 + "$";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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";

View File

@ -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

View File

@ -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

View File

@ -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";

View File

@ -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() {

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -6,12 +6,14 @@ 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";

View File

@ -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";

View File

@ -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";

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