Пример #1
0
 /**
  * @medium
  */
 public function testIsEncryptedContent()
 {
     $this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->dataUrl));
     $this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->legacyEncryptedData));
     $keyfileContent = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB');
     $this->assertTrue(\OCA\Files_Encryption\Crypt::isCatfileContent($keyfileContent));
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 /**
  * test webdav put random file
  */
 function testWebdavPUT()
 {
     // generate filename
     $filename = '/tmp-' . $this->getUniqueID() . '.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/keys/' . $filename . '/fileKey'));
     // check if shareKey-file was created
     $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/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(\OCA\Files_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;
 }