/**
* @brief retrieve keyfile for an encrypted file
* @param \OC_FilesystemView $view
- * @param $userId
* @param $filePath
* @internal param \OCA\Encryption\file $string name
* @return string file key or false
* @note The keyfile returned is asymmetrically encrypted. Decryption
* of the keyfile must be performed by client code
*/
- public static function getFileKey(\OC_FilesystemView $view, $userId, $filePath) {
+ public static function getFileKey(\OC_FilesystemView $view, $filePath) {
$util = new Util($view, \OCP\User::getUser());
// Fetch and decrypt keyfile
// Fetch existing keyfile
- $this->encKeyfile = Keymanager::getFileKey($this->rootView, $this->userId, $this->relPath);
+ $this->encKeyfile = Keymanager::getFileKey($this->rootView, $this->relPath);
// If a keyfile already exists
if ($this->encKeyfile) {
// scanning every file like this
// will eat server resources :(
if (
- Keymanager::getFileKey($this->view, $this->userId, $relPath)
+ Keymanager::getFileKey($this->view, $relPath)
&& $isEncryptedPath
) {
*/
public function isEncryptedPath($path) {
- // Disable encryption proxy so data retrieved is in its
- // original form
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
+ $relPath = Helper::stripUserFilesPath($path);
- // we only need 24 byte from the last chunk
- $data = '';
- $handle = $this->view->fopen($path, 'r');
- if (is_resource($handle) && !fseek($handle, -24, SEEK_END)) {
- $data = fgets($handle);
- }
+ $fileKey = Keymanager::getFileKey($this->view, $relPath);
- // re-enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
+ if ($fileKey === false) {
+ return false;
+ }
- return Crypt::isCatfileContent($data);
+ return true;
}
private function decryptKeyfile($filePath, $privateKey) {
// Get the encrypted keyfile
- $encKeyfile = Keymanager::getFileKey($this->view, $this->userId, $filePath);
+ $encKeyfile = Keymanager::getFileKey($this->view, $filePath);
// The file has a shareKey and must use it for decryption
$shareKey = Keymanager::getShareKey($this->view, $this->userId, $filePath);
$this->assertNotEquals($this->dataShort, $retreivedCryptedFile);
// Get the encrypted keyfile
- $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $this->userId, $filename);
+ $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $filename);
// Attempt to fetch the user's shareKey
$shareKey = Encryption\Keymanager::getShareKey($this->view, $this->userId, $filename);
$i = 0;
while ($i < count($r)-1) {
$e[] = $r[$i] . $r[$i+1];
- $i = $i + 2;
+ $i = $i + 2;
}
//print_r($e);
// Get the encrypted keyfile
- $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $this->userId, $filename);
+ $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $filename);
// Attempt to fetch the user's shareKey
$shareKey = Encryption\Keymanager::getShareKey($this->view, $this->userId, $filename);
* @brief test decryption using legacy blowfish method
*/
function testLegacyDecryptShort() {
-
+
$crypted = $this->legacyEncrypt($this->dataShort, $this->pass);
$decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass);
* @brief test decryption using legacy blowfish method
*/
function testLegacyDecryptLong() {
-
+
$crypted = $this->legacyEncrypt($this->dataLong, $this->pass);
$decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass);
// tear down
$view->unlink($filename);
}
-
-
+
+
/**
* @brief encryption using legacy blowfish method
* @param $data string data to encrypt