Online editing and collaboration have the related gaps in file security - in real-time data transfer and authorized sharing. Overcoming these limitations of previously existing individual document protection is the key objective of the encryption scheme in question.
Two-layer encryption model used in ONLYOFFICE involves:
With current model of encryption, it is possible to achieve the following:
If there are no keys in the DMS, they are generated with the NSOpenSSL::RSA_GenerateKeys method:
if (!bIsServerPrivateKeyExist) { unsigned char* publicKey = NULL; unsigned char* privateKey = NULL; NSOpenSSL::RSA_GenerateKeys(publicKey, privateKey); ... }
To encrypt the private key before saving it to the database, ONLYOFFICE uses the NSOpenSSL::AES_Encrypt_desktop algorithm based on AES-256 Cipher Block Chaining:
std::string privateEnc; NSOpenSSL::AES_Encrypt_desktop(U_TO_UTF8(tmpInfo->m_sPassword), sPrivate, privateEnc, CAscRendererProcessParams::getInstance().GetProperty("user")); info.PrivateKeyEnc = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(privateEnc);
The private key decryption is performed when a synchronised temporary file copy needs to be decrypted when editing it. To decrypt the key, the NSOpenSSL::AES_Decrypt_desktop algorithm is used:
std::string privateKey; if (nServerPrivateKeyVersion == 2) NSOpenSSL::AES_Decrypt_desktop_GCM(U_TO_UTF8(tmpInfo->m_sPassword), privateKeyEnc, privateKey, CAscRendererProcessParams::getInstance().GetProperty("user"), nServerPrivateKeyVersionOffset); else NSOpenSSL::AES_Decrypt_desktop(U_TO_UTF8(tmpInfo->m_sPassword), privateKeyEnc, privateKey, CAscRendererProcessParams::getInstance().GetProperty("user")); info.PrivateKey = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(privateKey);
To perform operations with encrypted files, including file encryption, decryption, creation, editing and sharing, ONLYOFFICE uses the individual credentials of users (RSA key pair) and a document password (document encryption key).
The encrypted files, besides the ciphertext itself, contain the arrays of public keys of all users and the document passwords encrypted with these keys. This makes it possible to establish collective access to the file, and therefore enable sharing and collaboration on the encrypted documents.
To encrypt the file password with each authorized user's public key, the NSOpenSSL::RSA_EncryptPublic_desktop algorithm is used:
std::string sKey = arguments[0]->GetStringValue().ToString(); NSStringUtils::string_replaceA(sKey, " ", "\n"); std::string sMessage = arguments[1]->GetStringValue().ToString(); std::string sOut; NSOpenSSL::RSA_EncryptPublic_desktop((unsigned char*)sKey.c_str(), sMessage, sOut); retval = CefV8Value::CreateString(sOut); return true;
The reverse NSOpenSSL::RSA_DecryptPrivate_desktop algorithm is used to decrypt the file using the user's private key:
std::string sKey = arguments[0]->GetStringValue().ToString(); std::string sMessage = arguments[1]->GetStringValue().ToString(); std::string sOut; NSOpenSSL::RSA_DecryptPrivate_desktop((unsigned char*)sKey.c_str(), sMessage, sOut); retval = CefV8Value::CreateString(sOut); return true;
When accessing the encrypted file, it is first is sent to the user's machine before the application begins the decryption.
The steps below explain the process of co-editing an encrypted document in ONLYOFFICE Docs.
ONLYOFFICE leverages data storage for documents and the encrypted data between the cloud storage and the user's local storage to maintain the applied scheme. The distribution of data looks as follows:
Item | Location within the instance | Location on device |
---|---|---|
Private key | Encrypted, in the Database | - |
Public key | Database and within encrypted files (in the file system) | - |
File encryption key | Encrypted, within the encrypted files (in the file system) | - |
User password | - | - |
Encrypted files at rest | On the server | - |
Encrypted files when editing | - | On machine, in temporary folder |
The desktop application stores all the read keys. To reset them and add new ones, please do the following: