Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
fd7484a81a
|
|||
|
575f22b42e
|
|||
|
2e07a6c736
|
|||
|
004dfc3c6a
|
|||
|
|
1cee0e63af | ||
|
|
f43d591de5 | ||
|
|
5dcd3c6405 | ||
|
|
82818f3c94 | ||
|
|
3fe127b497 | ||
|
|
2c6a2564b5 | ||
|
|
4974b64e18 | ||
|
14bebf12b9
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -148,6 +148,9 @@ gradle-app.setting
|
|||||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
!gradle-wrapper.jar
|
!gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Avoid ignore Gradle wrappper properties
|
||||||
|
!gradle-wrapper.properties
|
||||||
|
|
||||||
# Cache of project
|
# Cache of project
|
||||||
.gradletasknamecache
|
.gradletasknamecache
|
||||||
|
|
||||||
|
|||||||
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
6
.idea/compiler.xml
generated
6
.idea/compiler.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="11" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
7
.idea/discord.xml
generated
7
.idea/discord.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="PROJECT_FILES" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
6
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="InfiniteLoopStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
25
.idea/jarRepositories.xml
generated
25
.idea/jarRepositories.xml
generated
@@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="MavenRepo" />
|
|
||||||
<option name="name" value="MavenRepo" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="BintrayJCenter" />
|
|
||||||
<option name="name" value="BintrayJCenter" />
|
|
||||||
<option name="url" value="https://jcenter.bintray.com/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
65
.idea/libraries-with-intellij-classes.xml
generated
65
.idea/libraries-with-intellij-classes.xml
generated
@@ -1,65 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="libraries-with-intellij-classes">
|
|
||||||
<option name="intellijApiContainingLibraries">
|
|
||||||
<list>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="ideaIU" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.idea" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="ideaIU" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="ideaIC" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.idea" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="ideaIC" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="pycharmPY" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="pycharmPY" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="pycharmPC" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="pycharmPC" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="clion" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.clion" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="clion" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="riderRD" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.rider" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="riderRD" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="goland" />
|
|
||||||
<option name="groupId" value="com.jetbrains.intellij.goland" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
<LibraryCoordinatesState>
|
|
||||||
<option name="artifactId" value="goland" />
|
|
||||||
<option name="groupId" value="com.jetbrains" />
|
|
||||||
</LibraryCoordinatesState>
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
8
.idea/misc.xml
generated
8
.idea/misc.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
||||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
17
README.md
17
README.md
@@ -0,0 +1,17 @@
|
|||||||
|
# FileFrontEnd
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Technologies utilisées
|
||||||
|
|
||||||
|
* Java 11 (ressources informatiques)
|
||||||
|
* Gradle 7.1
|
||||||
|
|
||||||
|
### Projet
|
||||||
|
|
||||||
|
* src > main > resources > appdata.json -> Fichier de configuration à modifier
|
||||||
|
* storagePath : indiquer le dossier où les fichiers temporaires du FFE seront stockés
|
||||||
|
* network_interface : indiquer l'interface réseau à utiliser. Si elle n'est pas bonne, le programme demande laquelle utiliser au démarrage
|
||||||
|
|
||||||
|
`IMPORTANT: L'application doit absolument être démarré avec Gradle 7.1 !`
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ public class Task {
|
|||||||
* @return TRUE si le client doit recevoir cette réponse.
|
* @return TRUE si le client doit recevoir cette réponse.
|
||||||
*/
|
*/
|
||||||
public boolean isResponseOfClient(String storeDomain) {
|
public boolean isResponseOfClient(String storeDomain) {
|
||||||
System.out.println(status + " - " + context.getDomain() + " | " + storeDomain);
|
|
||||||
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
|
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import lightcontainer.protocol.rules.reader.SigninRule;
|
|||||||
import lightcontainer.protocol.rules.reader.SignoutRule;
|
import lightcontainer.protocol.rules.reader.SignoutRule;
|
||||||
import lightcontainer.protocol.rules.reader.SignupRule;
|
import lightcontainer.protocol.rules.reader.SignupRule;
|
||||||
import lightcontainer.protocol.rules.writer.SignErrorRule;
|
import lightcontainer.protocol.rules.writer.SignErrorRule;
|
||||||
|
import lightcontainer.utils.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@@ -58,7 +59,7 @@ public class ClientHandler extends UnicastThread implements AutoCloseable {
|
|||||||
try {
|
try {
|
||||||
String command = this.readLine();
|
String command = this.readLine();
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
System.out.println("Client: " + command);
|
Log.getInstance().infoln("Client: " + command);
|
||||||
} else {
|
} else {
|
||||||
this.repository.disconnect(this);
|
this.repository.disconnect(this);
|
||||||
break;
|
break;
|
||||||
@@ -73,7 +74,6 @@ public class ClientHandler extends UnicastThread implements AutoCloseable {
|
|||||||
if (checkAccess(ruleResult)) {
|
if (checkAccess(ruleResult)) {
|
||||||
// Lecture du fichier client
|
// Lecture du fichier client
|
||||||
ruleResult.read(this.getInputStream());
|
ruleResult.read(this.getInputStream());
|
||||||
System.out.println(getContext().getLogin() + " - " + 1);
|
|
||||||
ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand();
|
ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand();
|
||||||
// TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible
|
// TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible
|
||||||
if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) {
|
if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) {
|
||||||
@@ -181,9 +181,9 @@ public class ClientHandler extends UnicastThread implements AutoCloseable {
|
|||||||
try {
|
try {
|
||||||
super.close();
|
super.close();
|
||||||
this.repository.disconnect(this);
|
this.repository.disconnect(this);
|
||||||
System.out.printf("[CLIENT] %s s'est déconnecté\n", getContext().getLogin());
|
Log.getInstance().infof("[CLIENT] %s s'est déconnecté\n", getContext().getLogin());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("[CH] Error while closing client.");
|
Log.getInstance().infoln("[CH] Error while closing client.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package lightcontainer.domains.client;
|
package lightcontainer.domains.client;
|
||||||
|
|
||||||
import lightcontainer.repository.ClientHandlerRepository;
|
|
||||||
import lightcontainer.repository.ReadOnlyClientRepository;
|
import lightcontainer.repository.ReadOnlyClientRepository;
|
||||||
import lightcontainer.storage.File;
|
import lightcontainer.storage.File;
|
||||||
import lightcontainer.storage.ReadOnlyFile;
|
import lightcontainer.storage.ReadOnlyFile;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import lightcontainer.interfaces.ProtocolRepository;
|
|||||||
import lightcontainer.interfaces.StoreProcessorFFE;
|
import lightcontainer.interfaces.StoreProcessorFFE;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
|
import lightcontainer.utils.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@@ -21,7 +22,7 @@ import java.util.Objects;
|
|||||||
* @version 1.1
|
* @version 1.1
|
||||||
* @see Runnable
|
* @see Runnable
|
||||||
* @see AutoCloseable
|
* @see AutoCloseable
|
||||||
* @since 1.0Z
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class StoreProcessor extends UnicastThread implements AutoCloseable {
|
public class StoreProcessor extends UnicastThread implements AutoCloseable {
|
||||||
// Variables
|
// Variables
|
||||||
@@ -56,7 +57,7 @@ public class StoreProcessor extends UnicastThread implements AutoCloseable {
|
|||||||
if (protocolResult == null) { // Si on n'a pas encore la commande à envoyer
|
if (protocolResult == null) { // Si on n'a pas encore la commande à envoyer
|
||||||
waitAction();
|
waitAction();
|
||||||
}
|
}
|
||||||
System.out.println("[SBE] Envoie commande : " + protocolResult.getCommand());
|
Log.getInstance().infoln("[SBE] Envoie commande : " + protocolResult.getCommand());
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
this.write(protocolResult.getCommand());
|
this.write(protocolResult.getCommand());
|
||||||
@@ -74,23 +75,23 @@ public class StoreProcessor extends UnicastThread implements AutoCloseable {
|
|||||||
responseCommand += "\r\n";
|
responseCommand += "\r\n";
|
||||||
ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(getContext(), responseCommand);
|
ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(getContext(), responseCommand);
|
||||||
if (responseResult != null) {
|
if (responseResult != null) {
|
||||||
System.out.println("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand());
|
Log.getInstance().infoln("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand());
|
||||||
responseResult.read(
|
responseResult.read(
|
||||||
this.getInputStream()
|
this.getInputStream()
|
||||||
);
|
);
|
||||||
|
|
||||||
alertAvailable(responseResult.getResultCommand());
|
alertAvailable(responseResult.getResultCommand());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("StoreBackEnd result: Commande null");
|
Log.getInstance().infoln("StoreBackEnd result: Commande null");
|
||||||
alertAvailable(null);
|
alertAvailable(null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("StoreBackEnd: Commande null");
|
Log.getInstance().infoln("StoreBackEnd: Commande null");
|
||||||
alertAvailable(null);
|
alertAvailable(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
System.out.println("[ERROR] Problem with SBE (" + domain + ") : " + exception.getMessage());
|
Log.getInstance().infoln("[ERROR] Problem with SBE (" + domain + ") : " + exception.getMessage());
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +101,7 @@ public class StoreProcessor extends UnicastThread implements AutoCloseable {
|
|||||||
this.close();
|
this.close();
|
||||||
this.fileFrontEnd.onStoreDisconnect(this.domain);
|
this.fileFrontEnd.onStoreDisconnect(this.domain);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("[ERROR] Error while closing SBE (" + domain + ") : " + e.getMessage());
|
Log.getInstance().infoln("[ERROR] Error while closing SBE (" + domain + ") : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +154,7 @@ public class StoreProcessor extends UnicastThread implements AutoCloseable {
|
|||||||
public void close() {
|
public void close() {
|
||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
this.setRunning(false);
|
this.setRunning(false);
|
||||||
System.out.println("[SBE] Fermeture de " + domain);
|
Log.getInstance().infoln("[SBE] Fermeture de " + domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package lightcontainer.domains.server;
|
|||||||
import lightcontainer.domains.client.StoreProcessor;
|
import lightcontainer.domains.client.StoreProcessor;
|
||||||
import lightcontainer.interfaces.MulticastSPR;
|
import lightcontainer.interfaces.MulticastSPR;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
|
||||||
import lightcontainer.protocol.rules.reader.HelloRule;
|
import lightcontainer.protocol.rules.reader.HelloRule;
|
||||||
import lightcontainer.repository.FileFrontEnd;
|
import lightcontainer.repository.FileFrontEnd;
|
||||||
|
import lightcontainer.utils.Log;
|
||||||
import lightcontainer.utils.NetChooser;
|
import lightcontainer.utils.NetChooser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StoreMulticastRunnable
|
* StoreMulticastRunnable
|
||||||
@@ -28,7 +27,7 @@ public class MulticastServerListener implements Runnable {
|
|||||||
private final String multicast_address;
|
private final String multicast_address;
|
||||||
private final int multicast_port;
|
private final int multicast_port;
|
||||||
private final String network_interface;
|
private final String network_interface;
|
||||||
private FileFrontEnd ffe;
|
private final FileFrontEnd ffe;
|
||||||
private final MulticastSPR repository;
|
private final MulticastSPR repository;
|
||||||
private final ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
|
|
||||||
@@ -74,16 +73,17 @@ public class MulticastServerListener implements Runnable {
|
|||||||
onNewSbe(packet);
|
onNewSbe(packet);
|
||||||
}
|
}
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
System.out.println("[ERREUR] Multicast server can't start : " + ioException.getMessage());
|
Log.getInstance().infoln("[ERREUR] Multicast server can't start : " + ioException.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onNewSbe(DatagramPacket packet) {
|
private void onNewSbe(DatagramPacket packet) {
|
||||||
try {
|
try {
|
||||||
String data = new String(packet.getData(), 0, packet.getLength());
|
String data = new String(packet.getData(), 0, packet.getLength());
|
||||||
|
|
||||||
HelloRule.Result readerResult = protocolRep.executeReader(null, data);
|
HelloRule.Result readerResult = protocolRep.executeReader(null, data);
|
||||||
|
|
||||||
System.out.printf("Nouveau SBE : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort());
|
Log.getInstance().infof("Nouveau SBE : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort());
|
||||||
|
|
||||||
if (!this.repository.hasDomain(readerResult.getDomain())){
|
if (!this.repository.hasDomain(readerResult.getDomain())){
|
||||||
Socket socket = new Socket(packet.getAddress(), readerResult.getPort());
|
Socket socket = new Socket(packet.getAddress(), readerResult.getPort());
|
||||||
@@ -97,7 +97,7 @@ public class MulticastServerListener implements Runnable {
|
|||||||
// Contient déjà le SBE donc maj de la dernière activité
|
// Contient déjà le SBE donc maj de la dernière activité
|
||||||
this.repository.updateLastAnnounce(readerResult.getDomain());
|
this.repository.updateLastAnnounce(readerResult.getDomain());
|
||||||
} catch (IOException | ClassCastException exception) {
|
} catch (IOException | ClassCastException exception) {
|
||||||
System.out.println("[ERREUR] Une SBE essaye de se connecter avec une mauvaise configuration : " + exception.getMessage());
|
Log.getInstance().infoln("[ERREUR] Une SBE essaye de se connecter avec une mauvaise configuration : " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ import lightcontainer.domains.client.Context;
|
|||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.interfaces.UnicastCHR;
|
import lightcontainer.interfaces.UnicastCHR;
|
||||||
import lightcontainer.repository.FileFrontEnd;
|
import lightcontainer.repository.FileFrontEnd;
|
||||||
import lightcontainer.storage.AppData;
|
|
||||||
import lightcontainer.storage.Repository;
|
import lightcontainer.storage.Repository;
|
||||||
|
|
||||||
import javax.net.ssl.SSLServerSocket;
|
|
||||||
import javax.net.ssl.SSLServerSocketFactory;
|
import javax.net.ssl.SSLServerSocketFactory;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
public class UnicastServerListener implements Runnable {
|
public class UnicastServerListener implements Runnable {
|
||||||
// Variables
|
// Variables
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package lightcontainer.interfaces;
|
package lightcontainer.interfaces;
|
||||||
|
|
||||||
import lightcontainer.domains.client.ClientHandler;
|
import lightcontainer.domains.client.ClientHandler;
|
||||||
import lightcontainer.domains.server.MulticastServerListener;
|
|
||||||
import lightcontainer.domains.server.UnicastServerListener;
|
import lightcontainer.domains.server.UnicastServerListener;
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.repository.ClientHandlerRepository;
|
import lightcontainer.repository.ClientHandlerRepository;
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public abstract class ProtocolWriter {
|
|||||||
|
|
||||||
String command = builder + "\r\n";
|
String command = builder + "\r\n";
|
||||||
Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL
|
Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL
|
||||||
System.out.println("Crée la commande : " + command);
|
|
||||||
if (ruleMatcher.matches()) {
|
if (ruleMatcher.matches()) {
|
||||||
ProtocolResult result = onExecuted(context, data);
|
ProtocolResult result = onExecuted(context, data);
|
||||||
result.setCommand(command);
|
result.setCommand(command);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class StandardizedDefinitions {
|
|||||||
private final static String PASSWORD = PASSCHAR + "{5,50}";
|
private final static String PASSWORD = PASSCHAR + "{5,50}";
|
||||||
private final static String BL = "\\x20";
|
private final static String BL = "\\x20";
|
||||||
private final static String FILENAME = PASSCHAR + "{1,20}";
|
private final static String FILENAME = PASSCHAR + "{1,20}";
|
||||||
private final static String DOMAIN = "[a-z-A-Z0-9\\.]{5,20}";
|
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_FILENAME = DIGIT_LETTER + "{50,200}";
|
||||||
private final static String HASH_FILECONTENT = 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 + ")";
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
import lightcontainer.protocol.rules.writer.EraseFileRule;
|
import lightcontainer.protocol.rules.writer.EraseFileRule;
|
||||||
import lightcontainer.protocol.rules.writer.RemoveFileErrorRule;
|
import lightcontainer.protocol.rules.writer.RemoveFileErrorRule;
|
||||||
import lightcontainer.storage.ReadOnlyFile;
|
import lightcontainer.storage.ReadOnlyFile;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
import lightcontainer.protocol.rules.writer.GetFileErrorRule;
|
import lightcontainer.protocol.rules.writer.GetFileErrorRule;
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_ERROR;
|
import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_ERROR;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
// Variables
|
// Variables
|
||||||
private final String filename;
|
private final String filename;
|
||||||
private final long filesize;
|
private final long filesize;
|
||||||
private String hashedFileContent;
|
private final String hashedFileContent;
|
||||||
|
|
||||||
public Result(Context context, String filename, long filesize, String hashedFileContent) {
|
public Result(Context context, String filename, long filesize, String hashedFileContent) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -60,7 +60,7 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
@Override
|
@Override
|
||||||
public void read(InputStream reader) {
|
public void read(InputStream reader) {
|
||||||
super.read(reader);
|
super.read(reader);
|
||||||
System.out.println("Récupération du fichier du SBE");
|
|
||||||
try {
|
try {
|
||||||
FileReceiver fileReceiver = new FileReceiver(storagePath);
|
FileReceiver fileReceiver = new FileReceiver(storagePath);
|
||||||
if (!fileReceiver.receiveFile(reader, this.filename, this.filesize)) {
|
if (!fileReceiver.receiveFile(reader, this.filename, this.filesize)) {
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
import lightcontainer.protocol.rules.writer.SaveFileErrorRule;
|
import lightcontainer.protocol.rules.writer.SaveFileErrorRule;
|
||||||
import lightcontainer.protocol.rules.writer.SendfileRule;
|
import lightcontainer.protocol.rules.writer.SendfileRule;
|
||||||
import lightcontainer.utils.*;
|
import lightcontainer.utils.AES_GCM;
|
||||||
|
import lightcontainer.utils.FileReceiver;
|
||||||
|
import lightcontainer.utils.SHA;
|
||||||
|
import lightcontainer.utils.ShaHasher;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -47,13 +49,11 @@ public class SavefileRule extends ProtocolReader {
|
|||||||
super(context);
|
super(context);
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
System.out.println(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(InputStream reader) {
|
public void read(InputStream reader) {
|
||||||
super.read(reader);
|
super.read(reader);
|
||||||
System.out.printf("Sauvegarde du fichier : %s %d\n", filename, size);
|
|
||||||
|
|
||||||
if (getContext().canAddFile()) {
|
if (getContext().canAddFile()) {
|
||||||
try {
|
try {
|
||||||
@@ -75,8 +75,6 @@ public class SavefileRule extends ProtocolReader {
|
|||||||
long encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
long encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
||||||
if (encryptedFileSize < 0) throw new IOException();
|
if (encryptedFileSize < 0) throw new IOException();
|
||||||
|
|
||||||
System.out.println(encryptedFileSize);
|
|
||||||
|
|
||||||
String fileHash = SHA.hashFile(storagePath, this.filename);
|
String fileHash = SHA.hashFile(storagePath, this.filename);
|
||||||
|
|
||||||
// On met les données de la requête actuelle
|
// On met les données de la requête actuelle
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
import lightcontainer.protocol.rules.writer.SaveFileErrorRule;
|
import lightcontainer.protocol.rules.writer.SaveFileErrorRule;
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_ERROR;
|
import static lightcontainer.protocol.StandardizedDefinitions.SBE_SEND_RESULT_ERROR;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
import lightcontainer.protocol.rules.writer.SignErrorRule;
|
import lightcontainer.protocol.rules.writer.SignErrorRule;
|
||||||
import lightcontainer.protocol.rules.writer.SignOkRule;
|
import lightcontainer.protocol.rules.writer.SignOkRule;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
|
|
||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_OUT;
|
import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_SIGN_OUT;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package lightcontainer.protocol.rules.writer;
|
package lightcontainer.protocol.rules.writer;
|
||||||
|
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.FFE_ERASE_FILE;
|
import static lightcontainer.protocol.StandardizedDefinitions.FFE_ERASE_FILE;
|
||||||
|
|
||||||
@@ -15,6 +14,5 @@ public class EraseFileRule extends ProtocolWriter {
|
|||||||
|
|
||||||
public EraseFileRule() {
|
public EraseFileRule() {
|
||||||
super(NAME, PATTERN);
|
super(NAME, PATTERN);
|
||||||
System.out.println(PATTERN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package lightcontainer.protocol.rules.writer;
|
package lightcontainer.protocol.rules.writer;
|
||||||
|
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.FFE_FILE_LIST_RESULT;
|
import static lightcontainer.protocol.StandardizedDefinitions.FFE_FILE_LIST_RESULT;
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void write(OutputStream writer) throws IOException {
|
public void write(OutputStream writer) throws IOException {
|
||||||
System.out.printf("Sauvegarde du fichier : %s %d\n", this.filename, this.filesize);
|
|
||||||
|
|
||||||
System.out.println("Encrypted size for parsing: " + getContext().getDataLong("encryptedFileSize") + " normal: " + getContext().getDataLong("fileSize"));
|
|
||||||
FileSender fileSender = new FileSender(storagePath);
|
FileSender fileSender = new FileSender(storagePath);
|
||||||
fileSender.sendFile(
|
fileSender.sendFile(
|
||||||
getContext().getDataString("hashedFileName"),
|
getContext().getDataString("hashedFileName"),
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ public class SaveFileOkRule extends ProtocolWriter {
|
|||||||
protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) {
|
protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) {
|
||||||
ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context);
|
ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context);
|
||||||
|
|
||||||
System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin());
|
|
||||||
// Sauvegarder dans JSON
|
// Sauvegarder dans JSON
|
||||||
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataLong("size"), context.getDataString("iv"), context.getDomain());
|
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataLong("size"), context.getDataString("iv"), context.getDomain());
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package lightcontainer.protocol.rules.writer;
|
|||||||
|
|
||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
import lightcontainer.utils.FileSender;
|
import lightcontainer.utils.FileSender;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -46,7 +45,6 @@ public class SendfileRule extends ProtocolWriter {
|
|||||||
@Override
|
@Override
|
||||||
public void write(OutputStream writer) throws IOException {
|
public void write(OutputStream writer) throws IOException {
|
||||||
super.write(writer);
|
super.write(writer);
|
||||||
System.out.println("Envoie du fichier au SBE");
|
|
||||||
|
|
||||||
FileSender fileSender = new FileSender(storagePath);
|
FileSender fileSender = new FileSender(storagePath);
|
||||||
fileSender.sendFile(hashedFileName, writer);
|
fileSender.sendFile(hashedFileName, writer);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package lightcontainer.protocol.rules.writer;
|
package lightcontainer.protocol.rules.writer;
|
||||||
|
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_ERROR;
|
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_ERROR;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package lightcontainer.protocol.rules.writer;
|
package lightcontainer.protocol.rules.writer;
|
||||||
|
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.protocol.StandardizedDefinitions;
|
|
||||||
|
|
||||||
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_OK;
|
import static lightcontainer.protocol.StandardizedDefinitions.FFE_SIGN_OK;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package lightcontainer.repository;
|
package lightcontainer.repository;
|
||||||
|
|
||||||
|
import lightcontainer.domains.Task;
|
||||||
import lightcontainer.domains.client.Context;
|
import lightcontainer.domains.client.Context;
|
||||||
import lightcontainer.domains.client.StoreProcessor;
|
import lightcontainer.domains.client.StoreProcessor;
|
||||||
import lightcontainer.domains.Task;
|
|
||||||
import lightcontainer.interfaces.ClientHandlerFFE;
|
import lightcontainer.interfaces.ClientHandlerFFE;
|
||||||
import lightcontainer.interfaces.ProtocolRepository;
|
import lightcontainer.interfaces.ProtocolRepository;
|
||||||
import lightcontainer.interfaces.StoreProcessorFFE;
|
import lightcontainer.interfaces.StoreProcessorFFE;
|
||||||
@@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
|||||||
|
|
||||||
public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
||||||
// Variables
|
// Variables
|
||||||
private Deque<Task> tasks = new ConcurrentLinkedDeque<>();
|
private final Deque<Task> tasks = new ConcurrentLinkedDeque<>();
|
||||||
private final ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end
|
private final ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end
|
||||||
private final StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end
|
private final StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end
|
||||||
private ProtocolRepository protocolRepository;
|
private ProtocolRepository protocolRepository;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import lightcontainer.interfaces.MulticastSPR;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ public class AppData {
|
|||||||
*/
|
*/
|
||||||
public boolean verifyUser(String login, String password) {
|
public boolean verifyUser(String login, String password) {
|
||||||
User user = getUser(login);
|
User user = getUser(login);
|
||||||
System.out.println("OKOKOK " + password + " ok " + user);
|
|
||||||
return user != null && user.verifyPassword(password);
|
return user != null && user.verifyPassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package lightcontainer.storage;
|
package lightcontainer.storage;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
import lightcontainer.utils.Log;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ public class JsonAdapter implements Adapter {
|
|||||||
}
|
}
|
||||||
return appData;
|
return appData;
|
||||||
} catch (JsonParseException parseException) {
|
} catch (JsonParseException parseException) {
|
||||||
System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log
|
Log.getInstance().infoln("[FFE] : Error while loading configuration file"); //TODO - changer en log
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package lightcontainer.storage;
|
package lightcontainer.storage;
|
||||||
|
|
||||||
|
import lightcontainer.utils.Log;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -35,7 +37,7 @@ public class Repository {
|
|||||||
bufferedWriter.write(jsonAppData);
|
bufferedWriter.write(jsonAppData);
|
||||||
bufferedWriter.flush();
|
bufferedWriter.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error while saving configuration file !");
|
Log.getInstance().infoln("Error while saving configuration file !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,7 @@ public class Repository {
|
|||||||
builder.append(reader.readLine());
|
builder.append(reader.readLine());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error while reading configuration file");
|
Log.getInstance().infoln("Error while reading configuration file");
|
||||||
builder.setLength(0);
|
builder.setLength(0);
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ public class User {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
this.aesKey = aesKey;
|
this.aesKey = aesKey;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
System.out.println(files.size() + " fichiers trouvéssss pour " + name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package lightcontainer.utils;
|
|||||||
import javax.crypto.*;
|
import javax.crypto.*;
|
||||||
import javax.crypto.spec.GCMParameterSpec;
|
import javax.crypto.spec.GCMParameterSpec;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.io.*;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@@ -21,58 +22,6 @@ public class AES_GCM {
|
|||||||
public static final int GCM_IV_LENGTH = 16;
|
public static final int GCM_IV_LENGTH = 16;
|
||||||
public static final int GCM_TAG_LENGTH = 16;
|
public static final int GCM_TAG_LENGTH = 16;
|
||||||
|
|
||||||
// Main method for testing
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
/*
|
|
||||||
* FILE ENCRYPTION DEMO
|
|
||||||
*/
|
|
||||||
// Init files
|
|
||||||
File inFile = new File("D:\\HELMo.png");
|
|
||||||
File outFile = new File("D:\\HELMoCrypted.png");
|
|
||||||
File clearFile = new File("D:\\HELMoClear.png");
|
|
||||||
outFile.createNewFile();
|
|
||||||
clearFile.createNewFile();
|
|
||||||
// Make options
|
|
||||||
String IVFile = generateIV();
|
|
||||||
String keyFile = generateSecretKey();
|
|
||||||
// Show options
|
|
||||||
System.out.println("IV : " + IVFile);
|
|
||||||
System.out.println("Key : " + keyFile);
|
|
||||||
// Encrypt
|
|
||||||
encryptStream(
|
|
||||||
new FileInputStream(inFile),
|
|
||||||
new FileOutputStream(outFile),
|
|
||||||
inFile.length(),
|
|
||||||
IVFile,
|
|
||||||
keyFile
|
|
||||||
);
|
|
||||||
// Decrypt
|
|
||||||
decryptStream(
|
|
||||||
new FileInputStream(outFile),
|
|
||||||
new FileOutputStream(clearFile),
|
|
||||||
outFile.length(),
|
|
||||||
IVFile,
|
|
||||||
keyFile
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TEXT ENCRYPTION DEMO
|
|
||||||
*/
|
|
||||||
// Make option
|
|
||||||
String plainText = "Salut sombre fils de pute, comment vas tu ?";//TODO enlever le text chelou de Jérémi (ce fou là)
|
|
||||||
String IV = generateIV();
|
|
||||||
String key = generateSecretKey();
|
|
||||||
// Show options
|
|
||||||
System.out.println("IV : " + IV);
|
|
||||||
System.out.println("Key : " + key);
|
|
||||||
System.out.println("Original text : " + plainText);
|
|
||||||
// Crypt
|
|
||||||
String cryptText = encrypt(plainText, key, IV);
|
|
||||||
System.out.println("Encrypted text : " + cryptText);
|
|
||||||
// Decrypt
|
|
||||||
String decryptedText = decrypt(cryptText, key, IV);
|
|
||||||
System.out.println("Decrypted text : " + decryptedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decoder to decode base64 vector to byte vector.
|
* Decoder to decode base64 vector to byte vector.
|
||||||
|
|||||||
@@ -20,15 +20,6 @@ public class DeepFileEraser {
|
|||||||
public static final int DFE_STEP_MIN_FILL_VALUE = 0; // Minimum filling value of a writing phase
|
public static final int DFE_STEP_MIN_FILL_VALUE = 0; // Minimum filling value of a writing phase
|
||||||
public static final int DFE_STEP_MAX_FILL_VALUE = 15; // Maximum filling value of a writing phase
|
public static final int DFE_STEP_MAX_FILL_VALUE = 15; // Maximum filling value of a writing phase
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
|
||||||
{
|
|
||||||
System.out.println(random(1, 3));
|
|
||||||
try {
|
|
||||||
eraseFile("D:\\lol");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a number randomly.
|
* Generate a number randomly.
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ public class FileSender {
|
|||||||
|
|
||||||
public boolean sendFile(String filename, OutputStream out, long fileSize, String aesKey, String iv) throws IOException {
|
public boolean sendFile(String filename, OutputStream out, long fileSize, String aesKey, String iv) throws IOException {
|
||||||
BufferedInputStream bisFile;
|
BufferedInputStream bisFile;
|
||||||
System.out.printf("Envoie fichier : %s - %s - %s \n", filename, aesKey, iv);
|
|
||||||
try {
|
try {
|
||||||
File f = new File(String.format("%s/%s", path, filename));
|
File f = new File(String.format("%s/%s", path, filename));
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
|
|||||||
@@ -1,10 +1,35 @@
|
|||||||
package lightcontainer.utils;
|
package lightcontainer.utils;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.LogManager;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
|
|
||||||
|
public void infoln(String msg) {
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void infoln(int msg) {
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void infoln(long msg) {
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void infoln(Object msg) {
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void infof(String msg, Object... data) {
|
||||||
|
System.out.printf(msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Log instance;
|
||||||
|
|
||||||
|
public static Log getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new Log();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ public class NetChooser {
|
|||||||
Scanner console = new Scanner(System.in);
|
Scanner console = new Scanner(System.in);
|
||||||
String[] allInterfaceNames = getInterfaces();
|
String[] allInterfaceNames = getInterfaces();
|
||||||
for (int index = 0; index < allInterfaceNames.length; ++index) {
|
for (int index = 0; index < allInterfaceNames.length; ++index) {
|
||||||
System.out.printf("%d. %s\n", index, allInterfaceNames[index]);
|
Log.getInstance().infof("%d. %s\n", index, allInterfaceNames[index]);
|
||||||
}
|
}
|
||||||
System.out.printf("Select your interface :");
|
Log.getInstance().infof("Select your interface :");
|
||||||
NetworkInterface selected = getInterfacesByIndex(console.nextInt());
|
NetworkInterface selected = getInterfacesByIndex(console.nextInt());
|
||||||
System.out.printf("Selected interface: %s\n", selected.getDisplayName());
|
Log.getInstance().infof("Selected interface: %s\n", selected.getDisplayName());
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,4 @@ public class NetChooser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new NetChooser();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,7 @@ package lightcontainer.utils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA 256 Hashing and borrowing Class [DO NOT EDIT]
|
* SHA 256 Hashing and borrowing Class [DO NOT EDIT]
|
||||||
@@ -21,22 +16,6 @@ public class SHA {
|
|||||||
// Constants
|
// Constants
|
||||||
public static final String SHA_VERSION = "SHA-256";
|
public static final String SHA_VERSION = "SHA-256";
|
||||||
|
|
||||||
// Main method for testing
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
/*
|
|
||||||
* BORROWING ENCRYPTION DEMO
|
|
||||||
*/
|
|
||||||
File inFile = new File("D:\\HELMoCrypted.png");
|
|
||||||
System.out.println(hashStream(
|
|
||||||
new FileInputStream(inFile),
|
|
||||||
inFile.length()
|
|
||||||
));
|
|
||||||
|
|
||||||
System.out.println(hashFile( // caca5439dc02f2ced5094e95f1a3403d42127cda29feecd2eb1c68ff38a6fee3
|
|
||||||
"D:\\ffe",
|
|
||||||
"46ba86ddecd2fe80c3bdb9fb2f9480b4c92057447e9d1b43863dd1a6d540f3a316571684f9e3a7459f533a9792d4925e"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a borrowing of the stream.
|
* Make a borrowing of the stream.
|
||||||
|
|||||||
@@ -1 +1,10 @@
|
|||||||
{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"benjamin","password":"$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG","aes_key":"mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=","files":[{"name":"README.md","fileNameSalt":"5rB5fhj09F6ukJPRoJgTGQ==","size":17,"iv":"hY2yWRgIxB0dRettv/vPJw==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[]}]}
|
{
|
||||||
|
"unicast_port": 8000,
|
||||||
|
"multicast_ip": "224.66.66.1",
|
||||||
|
"multicast_port": 15502,
|
||||||
|
"network_interface": "Mon interface réseau",
|
||||||
|
"tls": true,
|
||||||
|
"storagePath": "Chemin vers le dossier FFE",
|
||||||
|
"users": [
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,9 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
package lightcontainer;
|
package lightcontainer;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class AppTest {
|
class AppTest {
|
||||||
// @Test void appHasAGreeting() {
|
// @Test void appHasAGreeting() {
|
||||||
// App classUnderTest = new App();
|
// App classUnderTest = new App();
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
|||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class HelloRuleTest {
|
class HelloRuleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package lightcontainer.protocol.rules.writer;
|
package lightcontainer.protocol.rules.writer;
|
||||||
|
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
|
||||||
import lightcontainer.protocol.rules.reader.SignoutRule;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class SignoutRuleTest {
|
class SignoutRuleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
package lightcontainer.storage;
|
package lightcontainer.storage;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class JsonAdapterTests {
|
public class JsonAdapterTests {
|
||||||
/*
|
/*
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
package lightcontainer.storage;
|
package lightcontainer.storage;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class RepositoryTests {
|
public class RepositoryTests {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -20,7 +8,7 @@ public class RepositoryTests {
|
|||||||
try {
|
try {
|
||||||
Files.deleteIfExists(Paths.get("src", "test", "resources", "test.json").toAbsolutePath());
|
Files.deleteIfExists(Paths.get("src", "test", "resources", "test.json").toAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error while destroying file");
|
Log.getInstance().infoln("Error while destroying file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user