La taille du fichier est maintenant en long pour supporter les gros fichiers
This commit is contained in:
parent
a287bbdb59
commit
06c16a289e
@ -126,6 +126,14 @@ public class Context {
|
||||
requestBundle.putInt(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key La clé permettant de retrouver la valeur
|
||||
* @param value La valeur associée à la clé
|
||||
*/
|
||||
public void putDataLong(String key, long value) {
|
||||
requestBundle.putLong(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de récupérer des données pour la requête courante
|
||||
*
|
||||
@ -146,6 +154,14 @@ public class Context {
|
||||
return requestBundle.getInt(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key La clé permettant de retrouver la valeur
|
||||
* @return La valeur associée à la clé
|
||||
*/
|
||||
public long getDataLong(String key) {
|
||||
return requestBundle.getLong(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'ajouter un fichier à l'utilisateur
|
||||
*
|
||||
@ -156,7 +172,7 @@ public class Context {
|
||||
* @param domain Domain dans lequel est stocké le fichier
|
||||
* @return TRUE si le fichier a pu être enregistré.
|
||||
*/
|
||||
public boolean addFile(String fileName, String fileNameSalt, int size, String iv, String domain) {
|
||||
public boolean addFile(String fileName, String fileNameSalt, long size, String iv, String domain) {
|
||||
return this.repository.addFileFor(new File(fileName, fileNameSalt, size, iv, Set.of(domain)), getLogin());
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@ public class RequestBundle {
|
||||
|
||||
private final Map<String, Integer> intData = new HashMap<>();
|
||||
|
||||
private final Map<String, Long> longData = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Permet d'ajouter des String
|
||||
*
|
||||
@ -48,4 +50,21 @@ public class RequestBundle {
|
||||
public int getInt(String key) {
|
||||
return intData.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key La clé permettant de retrouver la valeur
|
||||
* @param value La valeur associée à la clé
|
||||
*/
|
||||
public void putLong(String key, long value) {
|
||||
longData.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key La clé permettant de retrouver la valeur
|
||||
* @return La valeur associée à la clé ou null
|
||||
*/
|
||||
public long getLong(String key) {
|
||||
return longData.get(key);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
||||
import lightcontainer.domains.client.Context;
|
||||
import lightcontainer.interfaces.ProtocolRepository;
|
||||
import lightcontainer.protocol.ProtocolReader;
|
||||
import lightcontainer.protocol.StandardizedDefinitions;
|
||||
import lightcontainer.protocol.rules.writer.RemoveFileErrorRule;
|
||||
|
||||
import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_ERROR;
|
||||
|
@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
||||
import lightcontainer.domains.client.Context;
|
||||
import lightcontainer.interfaces.ProtocolRepository;
|
||||
import lightcontainer.protocol.ProtocolReader;
|
||||
import lightcontainer.protocol.StandardizedDefinitions;
|
||||
import lightcontainer.protocol.rules.writer.GetFileErrorRule;
|
||||
import lightcontainer.protocol.rules.writer.RetrieveFileRule;
|
||||
import lightcontainer.storage.ReadOnlyFile;
|
||||
@ -62,7 +61,7 @@ public class GetFileRule extends ProtocolReader {
|
||||
|
||||
// Save into bundle
|
||||
context.putDataString("fileName", file.getName());
|
||||
context.putDataInt("fileSize", file.getSize());
|
||||
context.putDataLong("fileSize", file.getSize());
|
||||
context.putDataString("fileIV", file.getIv());
|
||||
|
||||
// Create cmd for storebacked
|
||||
|
@ -37,10 +37,10 @@ public class RetrieveOkRule extends ProtocolReader {
|
||||
public class Result extends ProtocolResult {
|
||||
// Variables
|
||||
private final String filename;
|
||||
private final int filesize;
|
||||
private final long filesize;
|
||||
private String hashedFileContent;
|
||||
|
||||
public Result(Context context, String filename, int filesize, String hashedFileContent) {
|
||||
public Result(Context context, String filename, long filesize, String hashedFileContent) {
|
||||
super(context);
|
||||
this.filename = filename;
|
||||
this.filesize = filesize;
|
||||
@ -51,7 +51,7 @@ public class RetrieveOkRule extends ProtocolReader {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public int getFilesize() {
|
||||
public long getFilesize() {
|
||||
return filesize;
|
||||
}
|
||||
|
||||
@ -81,11 +81,11 @@ public class RetrieveOkRule extends ProtocolReader {
|
||||
RetrieveOkRule.Result result = new RetrieveOkRule.Result(context, data[HASHED_FILE_NAME], Integer.parseInt(data[FILE_SIZE]), data[HASHED_FILE_CONTENT]);
|
||||
|
||||
// save encrypted file size into bundle
|
||||
context.putDataInt("encryptedFileSize", result.getFilesize()); // TODO to long ?!
|
||||
context.putDataLong("encryptedFileSize", result.getFilesize()); // TODO to long ?!
|
||||
context.putDataString("hashedFileName", result.getFilename());
|
||||
|
||||
// Set result command
|
||||
result.setResultCommand(protocolRep.executeWriter(context, GetFileOkRule.NAME, context.getDataString("fileName"), String.valueOf(context.getDataInt("fileSize"))), ResultCmdReceiver.CLIENT);
|
||||
result.setResultCommand(protocolRep.executeWriter(context, GetFileOkRule.NAME, context.getDataString("fileName"), String.valueOf(context.getDataLong("fileSize"))), ResultCmdReceiver.CLIENT);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,10 @@ public class SavefileRule extends ProtocolReader {
|
||||
public class Result extends ProtocolResult {
|
||||
// Variables
|
||||
private String filename;
|
||||
private final int size;
|
||||
private final long size;
|
||||
|
||||
// Construct
|
||||
public Result(Context context, String filename, int size) {
|
||||
public Result(Context context, String filename, long size) {
|
||||
super(context);
|
||||
this.filename = filename;
|
||||
this.size = size;
|
||||
@ -75,7 +75,7 @@ public class SavefileRule extends ProtocolReader {
|
||||
String iv = AES_GCM.generateIV();
|
||||
|
||||
// retrieve file and new size
|
||||
int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
||||
long encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
||||
if (encryptedFileSize < 0) throw new IOException();
|
||||
|
||||
System.out.println(encryptedFileSize);
|
||||
@ -83,7 +83,7 @@ public class SavefileRule extends ProtocolReader {
|
||||
String fileHash = SHA.hashFile(storagePath, this.filename);
|
||||
|
||||
// On met les données de la requête actuelle
|
||||
getContext().putDataInt("size", size);
|
||||
getContext().putDataLong("size", size);
|
||||
getContext().putDataString("iv", iv);
|
||||
getContext().putDataString("fileNameSalt", fileNameSalt);
|
||||
|
||||
|
@ -3,7 +3,6 @@ package lightcontainer.protocol.rules.reader;
|
||||
import lightcontainer.domains.client.Context;
|
||||
import lightcontainer.interfaces.ProtocolRepository;
|
||||
import lightcontainer.protocol.ProtocolReader;
|
||||
import lightcontainer.protocol.StandardizedDefinitions;
|
||||
import lightcontainer.protocol.rules.writer.SignErrorRule;
|
||||
import lightcontainer.protocol.rules.writer.SignOkRule;
|
||||
|
||||
|
@ -33,10 +33,10 @@ public class GetFileOkRule extends ProtocolWriter {
|
||||
public class Result extends ProtocolWriter.ProtocolResult {
|
||||
// Variables
|
||||
private final String filename;
|
||||
private final int filesize;
|
||||
private final long filesize;
|
||||
|
||||
// Constructors
|
||||
public Result(Context context, String filename, int filesize) {
|
||||
public Result(Context context, String filename, long filesize) {
|
||||
super(context);
|
||||
this.filename = filename;
|
||||
this.filesize = filesize;
|
||||
@ -51,12 +51,12 @@ public class GetFileOkRule extends ProtocolWriter {
|
||||
public void write(OutputStream writer) throws IOException {
|
||||
System.out.printf("Sauvegarde du fichier : %s %d\n", this.filename, this.filesize);
|
||||
|
||||
System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize") + " normal: " + getContext().getDataInt("fileSize"));
|
||||
System.out.println("Encrypted size for parsing: " + getContext().getDataLong("encryptedFileSize") + " normal: " + getContext().getDataLong("fileSize"));
|
||||
FileSender fileSender = new FileSender(storagePath);
|
||||
fileSender.sendFile(
|
||||
getContext().getDataString("hashedFileName"),
|
||||
writer,
|
||||
getContext().getDataInt("encryptedFileSize"), // Encrypted file size (because data is parsing into AES system)
|
||||
getContext().getDataLong("encryptedFileSize"), // Encrypted file size (because data is parsing into AES system)
|
||||
getContext().getAesKey(),
|
||||
getContext().getDataString("fileIV")
|
||||
);
|
||||
|
@ -32,7 +32,7 @@ public class SaveFileOkRule extends ProtocolWriter {
|
||||
|
||||
System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin());
|
||||
// Sauvegarder dans JSON
|
||||
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain());
|
||||
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataLong("size"), context.getDataString("iv"), context.getDomain());
|
||||
|
||||
// Suppression du fichier temporaire dans le stockage du FFE
|
||||
String hashedFileName = context.getHashedFileName(context.getDataString("fileName"));
|
||||
|
@ -33,10 +33,10 @@ public class SendfileRule extends ProtocolWriter {
|
||||
public class Result extends ProtocolWriter.ProtocolResult {
|
||||
|
||||
private final String hashedFileName;
|
||||
private final int fileSize;
|
||||
private final long fileSize;
|
||||
private final String hashedFileContent;
|
||||
|
||||
public Result(Context context, String hashedFileName, int fileSize, String hashedFileContent) {
|
||||
public Result(Context context, String hashedFileName, long fileSize, String hashedFileContent) {
|
||||
super(context);
|
||||
this.hashedFileName = hashedFileName;
|
||||
this.fileSize = fileSize;
|
||||
|
@ -10,12 +10,12 @@ public class File implements ReadOnlyFile {
|
||||
// Variables
|
||||
private final String name;
|
||||
private final String fileNameSalt;
|
||||
private final int size;
|
||||
private final long size;
|
||||
private final String iv;
|
||||
private final Set<String> storage;
|
||||
|
||||
// Constructor
|
||||
public File(String name, String fileNameSalt, int size, String iv, Set<String> storage) {
|
||||
public File(String name, String fileNameSalt, long size, String iv, Set<String> storage) {
|
||||
this.name = name;
|
||||
this.fileNameSalt = fileNameSalt;
|
||||
this.size = size;
|
||||
@ -34,7 +34,7 @@ public class File implements ReadOnlyFile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ public interface ReadOnlyFile {
|
||||
|
||||
String getFileNameSalt();
|
||||
|
||||
int getSize();
|
||||
long getSize();
|
||||
|
||||
String getIv();
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class FileReceiver {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public int receiveFile(InputStream input, String fileName, int fileSize, String key, String iv) {
|
||||
public int receiveFile(InputStream input, String fileName, long fileSize, String key, String iv) {
|
||||
try {
|
||||
File file = new File(String.format("%s/%s", path, fileName));
|
||||
if (file.createNewFile()) {
|
||||
|
@ -10,7 +10,7 @@ public class FileSender {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public boolean sendFile(String filename, OutputStream out, int fileSize, String aesKey, String iv) throws IOException {
|
||||
public boolean sendFile(String filename, OutputStream out, long fileSize, String aesKey, String iv) throws IOException {
|
||||
BufferedInputStream bisFile;
|
||||
System.out.printf("Envoie fichier : %s - %s - %s \n", filename, aesKey, iv);
|
||||
try {
|
||||
@ -28,7 +28,7 @@ public class FileSender {
|
||||
|
||||
public boolean sendFile(String filename, OutputStream out) throws IOException {
|
||||
BufferedInputStream bisFile;
|
||||
int bytesReaded = 0;
|
||||
int bytesRead = 0;
|
||||
try {
|
||||
File file = new File(String.format("%s/%s", path, filename));
|
||||
long fileSize = file.length();
|
||||
@ -36,10 +36,10 @@ public class FileSender {
|
||||
byte[] buffer = new byte[DEFAULT_BUFFER];
|
||||
bisFile = new BufferedInputStream(new FileInputStream(file));
|
||||
long currentOffset = 0;
|
||||
while ((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, bytesReaded);
|
||||
while ((currentOffset < fileSize) && (bytesRead = bisFile.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
out.flush();
|
||||
currentOffset += bytesReaded;
|
||||
currentOffset += bytesRead;
|
||||
}
|
||||
bisFile.close();
|
||||
return true;
|
||||
|
@ -1 +1,16 @@
|
||||
{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"benjamin","password":"$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG","aes_key":"mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=","files":[{"name":"README.md","fileNameSalt":"atK0eGo/J8IBOTCpIZpWow==","size":17,"iv":"fXPzefxl0cO4Hf02Qwi+BA==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"ca.crt","fileNameSalt":"qz6FoPGyJJ8Hy+1LIouvZA==","size":4207,"iv":"8v2H+cOzztD++NXHXw5Ofw==","storage":["lightcontainerSB01"]}]}]}
|
||||
{
|
||||
"unicast_port": 8000,
|
||||
"multicast_ip": "224.66.66.1",
|
||||
"multicast_port": 15502,
|
||||
"network_interface": "lo",
|
||||
"tls": true,
|
||||
"storagePath": "C:\\Users\\ledou\\Documents\\ffe",
|
||||
"users": [
|
||||
{
|
||||
"name": "aaaaa",
|
||||
"password": "$2a$10$6KbB.cBqsWyRExIf2ugkhebsJOhUG9goXFEfOYWXJI4dOQNT1uXhu",
|
||||
"aes_key": "2gYT1TeILBswvCbxAth24ZNLtFhaA1zvdJmtfh0unNE=",
|
||||
"files": []
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user