|
@@ -256,9 +256,10 @@ void FileMan::putListData(vector<Json::Value> files) {
|
|
|
fileInfo["size"] = file["size"];
|
|
|
|
|
|
string headString = file["head"].asString();
|
|
|
- std::cerr << "checking decryptability of file " << file["name"].asString() << std::endl;
|
|
|
decryptability decr = isDecryptable(base64::decodeVector(headString));
|
|
|
- if (decr == FileMan::undecryptable) {
|
|
|
+ if (decr == FileMan::unknown) {
|
|
|
+ fileInfo["encrypted"] = "unknown";
|
|
|
+ } else if (decr == FileMan::undecryptable) {
|
|
|
fileInfo["encrypted"] = "undecryptable";
|
|
|
} else if (decr == FileMan::decryptable) {
|
|
|
fileInfo["encrypted"] = "decryptable";
|
|
@@ -457,8 +458,8 @@ FileMan::decryptability FileMan::isDecryptable(const vector<char> data) {
|
|
|
unsigned char plain[sizeof(signature)] = {0}, *cipher;
|
|
|
int plainlen;
|
|
|
// check if signature matches in plaintext
|
|
|
- if (memcmp(data.data(), signature, sizeof(signature))) {
|
|
|
- // it does not
|
|
|
+ if (data.size() < sizeof(signature) || memcmp(data.data(), signature, sizeof(signature))) {
|
|
|
+ // either size or signature dont match
|
|
|
if (data.size() >= (sizeof(signature) + sizeof(iv) + sizeof(tag)) && keyenabled) {
|
|
|
// enough data, key is enabled
|
|
|
memcpy(iv, data.data(), sizeof(iv));
|
|
@@ -484,8 +485,8 @@ FileMan::decryptability FileMan::isDecryptable(const vector<char> data) {
|
|
|
return decryptable;
|
|
|
}
|
|
|
}
|
|
|
- // no key enabled or decryption failed, assume undecryptable
|
|
|
- return undecryptable;
|
|
|
+ // size mismatch or no key enabled, consider unknown
|
|
|
+ return unknown;
|
|
|
}
|
|
|
// it does, assume plaintext
|
|
|
return plaintext;
|