Correction bug encryption fichier (taille) correction bug décryption ficher (taille)
This commit is contained in:
parent
031ac57368
commit
6cb59673f4
@ -55,7 +55,7 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
FileReceiver fileReceiver = new FileReceiver(storagePath);
|
FileReceiver fileReceiver = new FileReceiver(storagePath);
|
||||||
fileReceiver.receiveFile(reader, this.filename, this.filesize);
|
fileReceiver.receiveFile(reader, this.filename, this.filesize);
|
||||||
|
|
||||||
// TODO fingerprint
|
// TODO fingerprint <!!!!!!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +68,11 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
@Override
|
@Override
|
||||||
protected RetrieveOkRule.Result onExecuted(Context context, String... data) {
|
protected RetrieveOkRule.Result onExecuted(Context context, String... data) {
|
||||||
RetrieveOkRule.Result result = new RetrieveOkRule.Result(context, data[HASHED_FILE_NAME], Integer.parseInt(data[FILE_SIZE]), data[HASHED_FILE_CONTENT]);
|
RetrieveOkRule.Result result = new RetrieveOkRule.Result(context, data[HASHED_FILE_NAME], Integer.parseInt(data[FILE_SIZE]), data[HASHED_FILE_CONTENT]);
|
||||||
|
|
||||||
|
// save encrypted file size into bundle
|
||||||
|
context.putDataInt("encryptedFileSize", Integer.parseInt(data[FILE_SIZE])); // TODO to long ?!
|
||||||
|
|
||||||
|
// 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.getDataInt("fileSize"))), ResultCmdReceiver.CLIENT);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Oh yeahh baby
|
* Oh yeahh baby by tonton EndMove ;-)
|
||||||
* @param writer Buffer à remplir qui sera envoyer via le réseau
|
* @param writer Buffer à remplir qui sera envoyer via le réseau
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -44,8 +44,15 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
super.write(writer);
|
super.write(writer);
|
||||||
System.out.printf("Sauvegarde du fichier : %s %d\n", this.filename, this.filesize);
|
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"));
|
||||||
FileSender fileSender = new FileSender(storagePath);
|
FileSender fileSender = new FileSender(storagePath);
|
||||||
fileSender.sendFile(getContext().getHashedFileName(this.filename), writer, this.filesize, getContext().getAesKey(), getContext().getDataString("fileIV"));
|
fileSender.sendFile(
|
||||||
|
getContext().getHashedFileName(this.filename),
|
||||||
|
writer,
|
||||||
|
getContext().getDataInt("encryptedFileSize"), // Encrypted file size (because data is parsing into AES system)
|
||||||
|
getContext().getAesKey(),
|
||||||
|
getContext().getDataString("fileIV")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,10 +202,11 @@ public class AES_GCM {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt stream, with AES GCM.
|
* Encrypt stream, with AES GCM.
|
||||||
|
* The output stream is automatically closed after processing.
|
||||||
*
|
*
|
||||||
* @param in InputStream to the input, flux to encrypt.
|
* @param in InputStream to the input, flux to encrypt.
|
||||||
* @param out OutputStream to the output, encrypted flux.
|
* @param out OutputStream to the output, encrypted flux.
|
||||||
* @param fileSize Stream/file size.
|
* @param fileSize Stream/file size (! unencrypted size !).
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
*
|
||||||
@ -213,7 +214,7 @@ public class AES_GCM {
|
|||||||
*/
|
*/
|
||||||
public static void encryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
public static void encryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int currentSize = 0;
|
long currentSize = 0;
|
||||||
int bytes;
|
int bytes;
|
||||||
try {
|
try {
|
||||||
// Make the cipher for encryption
|
// Make the cipher for encryption
|
||||||
@ -257,10 +258,11 @@ public class AES_GCM {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt stream, with AES GCM.
|
* Decrypt stream, with AES GCM.
|
||||||
|
* The input stream is automatically closed after processing.
|
||||||
*
|
*
|
||||||
* @param in InputStream to the input, flux to decrypt.
|
* @param in InputStream to the input, flux to decrypt.
|
||||||
* @param out OutputStream to the output, decrypted flux.
|
* @param out OutputStream to the output, decrypted flux.
|
||||||
* @param fileSize Stream/file size.
|
* @param fileSize Stream/file size (! encrypted size !).
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
*
|
||||||
@ -268,7 +270,7 @@ public class AES_GCM {
|
|||||||
*/
|
*/
|
||||||
public static void decryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
public static void decryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int currentSize = 0;
|
long currentSize = 0;
|
||||||
int bytes;
|
int bytes;
|
||||||
try {
|
try {
|
||||||
// Make the cipher for decryption
|
// Make the cipher for decryption
|
||||||
|
@ -15,11 +15,8 @@ public class FileReceiver {
|
|||||||
|
|
||||||
AES_GCM.encryptStream(input, bosFile, fileSize, key, iv);
|
AES_GCM.encryptStream(input, bosFile, fileSize, key, iv);
|
||||||
|
|
||||||
bosFile.flush();
|
|
||||||
bosFile.close();
|
|
||||||
|
|
||||||
File f = new File(String.format("%s/%s", path, fileName));
|
File f = new File(String.format("%s/%s", path, fileName));
|
||||||
return (int)f.length();
|
return (int)f.length(); // TODO change the size to LONG
|
||||||
} catch(IOException | AES_GCM.AesGcmException ex) {
|
} catch(IOException | AES_GCM.AesGcmException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} }
|
if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} }
|
||||||
|
@ -15,10 +15,7 @@ public class FileSender {
|
|||||||
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()) {
|
||||||
bisFile = new BufferedInputStream(new FileInputStream(f));
|
bisFile = new BufferedInputStream(new FileInputStream(f));
|
||||||
|
|
||||||
AES_GCM.decryptStream(bisFile, out, fileSize, aesKey, iv);
|
AES_GCM.decryptStream(bisFile, out, fileSize, aesKey, iv);
|
||||||
|
|
||||||
bisFile.close();
|
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,9 +1 @@
|
|||||||
{
|
{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"lo","tls":true,"storagePath":"D:\\ffe","users":[{"name":"aaaaa","password":"$2a$10$639SgWZgYr9nfwEkruQUae8Y0ibNwa47IjWXOeNYjq5Cdc.AssyBW","aes_key":"oy+C8i9azdqof9/o4Do/karqP0bnLp3kBMAs/LW3Xn4=","files":[{"name":"dupli.zip","fileNameSalt":"vtI75a/mh9voNohJW6Or5A==","size":41264222,"iv":"Xj4QHP/dzLYCRNqfuYB4hw==","storage":["orglightcont01"]}]}]}
|
||||||
"unicast_port": 8000,
|
|
||||||
"multicast_ip": "224.66.66.1",
|
|
||||||
"multicast_port": 15502,
|
|
||||||
"network_interface": "lo",
|
|
||||||
"tls": true,
|
|
||||||
"storagePath": "D:\\ffe",
|
|
||||||
"users": []
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user