mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-27 23:17:13 +03:00
[CSE] Generate a random name for the temporary file
This commit is contained in:
parent
7e83f0591b
commit
dd0528037d
3 changed files with 21 additions and 4 deletions
|
@ -65,7 +65,21 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
QByteArray EncryptionHelper::generateRandom(int size) {
|
||||
QByteArray EncryptionHelper::generateRandomString(int size)
|
||||
{
|
||||
const QByteArray possibleCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
QByteArray randomString(size, '\0');
|
||||
for(int i=0; i < size; ++i)
|
||||
{
|
||||
int index = qrand() % possibleCharacters.length();
|
||||
randomString[i] = possibleCharacters.at(index);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
QByteArray EncryptionHelper::generateRandom(int size)
|
||||
{
|
||||
unsigned char *tmp = (unsigned char *)malloc(sizeof(unsigned char) * size);
|
||||
|
||||
int ret = RAND_bytes(tmp, size);
|
||||
|
|
|
@ -28,6 +28,7 @@ QString baseUrl();
|
|||
|
||||
class EncryptionHelper {
|
||||
public:
|
||||
static QByteArray generateRandomString(int size);
|
||||
static QByteArray generateRandom(int size);
|
||||
static QByteArray generatePassword(const QString &wordlist, const QByteArray& salt);
|
||||
static QByteArray encryptPrivateKey(
|
||||
|
|
|
@ -126,7 +126,7 @@ void PropagateUploadEncrypted::slotFolderEncriptedMetadataReceived(const QJsonDo
|
|||
qDebug() << "Creating the encrypted file metadata helper.";
|
||||
EncryptedFile encryptedFile;
|
||||
encryptedFile.authenticationTag = "NOISE"; // TODO: Remove the noise.
|
||||
encryptedFile.encryptedFilename = EncryptionHelper::generateRandom(20);
|
||||
encryptedFile.encryptedFilename = EncryptionHelper::generateRandomString(20);
|
||||
encryptedFile.encryptionKey = EncryptionHelper::generateRandom(16);
|
||||
encryptedFile.fileVersion = 1;
|
||||
encryptedFile.initializationVector = EncryptionHelper::generateRandom(16);
|
||||
|
@ -135,10 +135,12 @@ void PropagateUploadEncrypted::slotFolderEncriptedMetadataReceived(const QJsonDo
|
|||
metaData.addEncryptedFile(encryptedFile);
|
||||
|
||||
qDebug() << "Encrypting the file";
|
||||
QFile *input = new QFile(info.absoluteFilePath());
|
||||
auto *input = new QFile(info.absoluteFilePath());
|
||||
|
||||
//TODO: Perhaps I should use a QTemporaryFile?
|
||||
QFile *output = new QFile(QDir::tempPath() + encryptedFile.encryptedFilename);
|
||||
qDebug() << "Creating " << QDir::tempPath() + QDir::separator() + encryptedFile.encryptedFilename;
|
||||
|
||||
auto *output = new QFile(QDir::tempPath() + QDir::separator() + encryptedFile.encryptedFilename);
|
||||
|
||||
EncryptionHelper::fileEncryption(encryptedFile.encryptionKey,
|
||||
encryptedFile.initializationVector,
|
||||
|
|
Loading…
Reference in a new issue