/** * test webdav put random file */ function testWebdavPUT() { // generate filename $filename = '/tmp-' . uniqid() . '.txt'; // set server vars $_SERVER['REQUEST_METHOD'] = 'OPTIONS'; $_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename; $_SERVER['HTTP_AUTHORIZATION'] = 'Basic dGVzdC13ZWJkYXYtdXNlcjE6dGVzdC13ZWJkYXYtdXNlcjE='; $_SERVER['CONTENT_TYPE'] = 'application/octet-stream'; $_SERVER['PATH_INFO'] = '/webdav' . $filename; $_SERVER['CONTENT_LENGTH'] = strlen($this->dataShort); // handle webdav request $this->handleWebdavRequest($this->dataShort); // check if file was created $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files' . $filename)); // check if key-file was created $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key')); // check if shareKey-file was created $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey')); // disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // get encrypted file content $encryptedContent = $this->view->file_get_contents('/' . $this->userId . '/files' . $filename); // restore proxy state \OC_FileProxy::$enabled = $proxyStatus; // check if encrypted content is valid $this->assertTrue(Encryption\Crypt::isCatfileContent($encryptedContent)); // get decrypted file contents $decrypt = file_get_contents('crypt:///' . $this->userId . '/files' . $filename); // check if file content match with the written content $this->assertEquals($this->dataShort, $decrypt); // return filename for next test return $filename; }
/** * @medium */ function testIsEncryptedContent() { $this->assertFalse(Encryption\Crypt::isCatfileContent($this->dataUrl)); $this->assertFalse(Encryption\Crypt::isCatfileContent($this->legacyEncryptedData)); $keyfileContent = Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat'); $this->assertTrue(Encryption\Crypt::isCatfileContent($keyfileContent)); }
/** * Check if a given path identifies an encrypted file * @param string $path * @return boolean */ public function isEncryptedPath($path) { // Disable encryption proxy so data retrieved is in its // original form $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $data = ''; // we only need 24 byte from the last chunk if ($this->view->file_exists($path)) { $handle = $this->view->fopen($path, 'r'); if (is_resource($handle)) { // suppress fseek warining, we handle the case that fseek doesn't // work in the else branch if (@fseek($handle, -24, SEEK_END) === 0) { $data = fgets($handle); } else { // if fseek failed on the storage we create a local copy from the file // and read this one fclose($handle); $localFile = $this->view->getLocalFile($path); $handle = fopen($localFile, 'r'); if (is_resource($handle) && fseek($handle, -24, SEEK_END) === 0) { $data = fgets($handle); } } fclose($handle); } } // re-enable proxy \OC_FileProxy::$enabled = $proxyStatus; return Crypt::isCatfileContent($data); }