proxy.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>,
  4. * and Robin Appelman <icewind@owncloud.com>
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. // require_once "PHPUnit/Framework/TestCase.php";
  10. // require_once realpath( dirname(__FILE__).'/../../../lib/base.php' );
  11. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery.php' );
  12. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Generator.php' );
  13. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/MockInterface.php' );
  14. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Mock.php' );
  15. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Container.php' );
  16. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Configuration.php' );
  17. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CompositeExpectation.php' );
  18. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/ExpectationDirector.php' );
  19. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Expectation.php' );
  20. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Exception.php' );
  21. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/CountValidatorAbstract.php' );
  22. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/Exception.php' );
  23. // require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/Exact.php' );
  24. //
  25. // use \Mockery as m;
  26. // use OCA\Encryption;
  27. // class Test_Util extends \PHPUnit_Framework_TestCase {
  28. //
  29. // public function setUp() {
  30. //
  31. // $this->proxy = new Encryption\Proxy();
  32. //
  33. // $this->tmpFileName = "tmpFile-".time();
  34. //
  35. // $this->privateKey = file_get_contents( realpath( dirname(__FILE__).'/data/admin.public.key' ) );
  36. // $this->publicKey = file_get_contents( realpath( dirname(__FILE__).'/data/admin.private.key' ) );
  37. // $this->encDataShort = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester-enc' ) );
  38. // $this->encDataShortKey = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester.key' ) );
  39. //
  40. // $this->dataShort = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester' ) );
  41. // $this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) );
  42. // $this->longDataPath = realpath( dirname(__FILE__).'/../lib/crypt.php' );
  43. //
  44. // $this->data1 = file_get_contents( realpath( dirname(__FILE__).'/../../../data/admin/files/enc-test.txt' ) );
  45. //
  46. // \OC_FileProxy::$enabled = false;
  47. // $this->Encdata1 = file_get_contents( realpath( dirname(__FILE__).'/../../../data/admin/files/enc-test.txt' ) );
  48. // \OC_FileProxy::$enabled = true;
  49. //
  50. // $this->userId = 'admin';
  51. // $this->pass = 'admin';
  52. //
  53. // $this->session = new Encryption\Session( $view ); // FIXME: Provide a $view object for use here
  54. //
  55. // $this->session->setPrivateKey(
  56. // '-----BEGIN PRIVATE KEY-----
  57. // MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDiH3EA4EpFA7Fx
  58. // s2dyyfL5jwXeYXrTqQJ6DqKgGn8VsbT3eu8R9KzM2XitVwZe8c8L52DvJ06o5vg0
  59. // GqPYxilFdOFJe/ggac5Tq8UmJiZS4EqYEMwxBIfIyWTxeGV06/0HOwnVAkqHMcBz
  60. // 64qldtgi5O8kZMEM2/gKBgU0kMLJzM+8oEWhL1+gsUWQhxd8cKLXypS6iWgqFJrz
  61. // f/X0hJsJR+gyYxNpahtnjzd/LxLAETrOMsl2tue+BAxmjbAM0aG0NEM0div+b59s
  62. // 2uz/iWbxImp5pOdYVKcVW89D4XBMyGegR40trV2VwiuX1blKCfdjMsJhiaL9pymp
  63. // ug1wzyQFAgMBAAECggEAK6c+PZkPPXuVCgpEcliiW6NM0r2m5K3AGKgypQ34csu3
  64. // z/8foCvIIFPrhCtEw5eTDQ1CHWlNOjY8vHJYJ0U6Onpx86nHIRrMBkMm8FJ1G5LJ
  65. // U8oKYXwqaozWu/cuPwA//OFc6I5krOzh5n8WaRMkbrgbor8AtebRX74By0AXGrXe
  66. // cswJI7zR96oFn4Dm7Pgvpg5Zhk1vFJ+w6QtH+4DDJ6PBvlZsRkGxYBLGVd/3qhAI
  67. // sBAyjFlSzuP4eCRhHOhHC/e4gmAH9evFVXB88jFyRZm3K+jQ5W5CwrVRBCV2lph6
  68. // 2B6P7CBJN+IjGKMhy+75y13UvvKPv9IwH8Fzl2x1gQKBgQD8qQOr7a6KhSj16wQE
  69. // jim2xqt9gQ2jH5No405NrKs/PFQQZnzD4YseQsiK//NUjOJiUhaT+L5jhIpzINHt
  70. // RJpt3bGkEZmLyjdjgTpB3GwZdXa28DNK9VdXZ19qIl/ZH0qAjKmJCRahUDASMnVi
  71. // M4Pkk9yx9ZIKkri4TcuMWqc0DQKBgQDlHKBTITZq/arYPD6Nl3NsoOdqVRqJrGay
  72. // 0TjXAVbBXe46+z5lnMsqwXb79nx14hdmSEsZULrw/3f+MnQbdjMTYLFP24visZg9
  73. // MN8vAiALiiiR1a+Crz+DTA1Q8sGOMVCMqMDmD7QBys3ZuWxuapm0txAiIYUtsjJZ
  74. // XN76T4nZ2QKBgQCHaT3igzwsWTmesxowJtEMeGWomeXpKx8h89EfqA8PkRGsyIDN
  75. // qq+YxEoe1RZgljEuaLhZDdNcGsjo8woPk9kAUPTH7fbRCMuutK+4ZJ469s1tNkcH
  76. // QX5SBcEJbOrZvv967ehe3VQXmJZq6kgnHVzuwKBjcC2ZJRGDFY6l5l/+cQKBgCqh
  77. // +Adf/8NK7paMJ0urqfPFwSodKfICXZ3apswDWMRkmSbqh4La+Uc8dsqN5Dz/VEFZ
  78. // JHhSeGbN8uMfOlG93eU2MehdPxtw1pZUWMNjjtj23XO9ooob2CKzbSrp8TBnZsi1
  79. // widNNr66oTFpeo7VUUK6acsgF6sYJJxSVr+XO1yJAoGAEhvitq8shNKcEY0xCipS
  80. // k1kbgyS7KKB7opVxI5+ChEqyUDijS3Y9FZixrRIWE6i2uGu86UG+v2lbKvSbM4Qm
  81. // xvbOcX9OVMnlRb7n8woOP10UMY+ZE2x+YEUXQTLtPYq7F66e1OfxltstMxLQA+3d
  82. // Y1d5piFV8PXK3Fg2F+Cj5qg=
  83. // -----END PRIVATE KEY-----
  84. // '
  85. // , $this->userId
  86. // );
  87. //
  88. // \OC_User::setUserId( $this->userId );
  89. //
  90. // }
  91. //
  92. // public function testpreFile_get_contents() {
  93. //
  94. // // This won't work for now because mocking of the static keymanager class isn't working :(
  95. //
  96. // // $mock = m::mock( 'alias:OCA\Encryption\Keymanager' );
  97. // //
  98. // // $mock->shouldReceive( 'getFileKey' )->times(2)->andReturn( $this->encDataShort );
  99. // //
  100. // // $encrypted = $this->proxy->postFile_get_contents( 'data/'.$this->tmpFileName, $this->encDataShortKey );
  101. // //
  102. // // $this->assertNotEquals( $this->dataShort, $encrypted );
  103. //
  104. // $decrypted = $this->proxy->postFile_get_contents( 'data/admin/files/enc-test.txt', $this->data1 );
  105. //
  106. // }
  107. //
  108. // }
  109. // class Test_CryptProxy extends PHPUnit_Framework_TestCase {
  110. // private $oldConfig;
  111. // private $oldKey;
  112. //
  113. // public function setUp(){
  114. // $user=OC_User::getUser();
  115. //
  116. // $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true');
  117. // OCP\Config::setAppValue('files_encryption','enable_encryption','true');
  118. // $this->oldKey=isset($_SESSION['privateKey'])?$_SESSION['privateKey']:null;
  119. //
  120. //
  121. // //set testing key
  122. // $_SESSION['privateKey']=md5(time());
  123. //
  124. // //clear all proxies and hooks so we can do clean testing
  125. // OC_FileProxy::clearProxies();
  126. // OC_Hook::clear('OC_Filesystem');
  127. //
  128. // //enable only the encryption hook
  129. // OC_FileProxy::register(new OC_FileProxy_Encryption());
  130. //
  131. // //set up temporary storage
  132. // OC_Filesystem::clearMounts();
  133. // OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/');
  134. //
  135. // OC_Filesystem::init('/'.$user.'/files');
  136. //
  137. // //set up the users home folder in the temp storage
  138. // $rootView=new OC_FilesystemView('');
  139. // $rootView->mkdir('/'.$user);
  140. // $rootView->mkdir('/'.$user.'/files');
  141. // }
  142. //
  143. // public function tearDown(){
  144. // OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig);
  145. // if(!is_null($this->oldKey)){
  146. // $_SESSION['privateKey']=$this->oldKey;
  147. // }
  148. // }
  149. //
  150. // public function testSimple(){
  151. // $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
  152. // $original=file_get_contents($file);
  153. //
  154. // OC_Filesystem::file_put_contents('/file',$original);
  155. //
  156. // OC_FileProxy::$enabled=false;
  157. // $stored=OC_Filesystem::file_get_contents('/file');
  158. // OC_FileProxy::$enabled=true;
  159. //
  160. // $fromFile=OC_Filesystem::file_get_contents('/file');
  161. // $this->assertNotEquals($original,$stored);
  162. // $this->assertEquals(strlen($original),strlen($fromFile));
  163. // $this->assertEquals($original,$fromFile);
  164. //
  165. // }
  166. //
  167. // public function testView(){
  168. // $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
  169. // $original=file_get_contents($file);
  170. //
  171. // $rootView=new OC_FilesystemView('');
  172. // $view=new OC_FilesystemView('/'.OC_User::getUser());
  173. // $userDir='/'.OC_User::getUser().'/files';
  174. //
  175. // $rootView->file_put_contents($userDir.'/file',$original);
  176. //
  177. // OC_FileProxy::$enabled=false;
  178. // $stored=$rootView->file_get_contents($userDir.'/file');
  179. // OC_FileProxy::$enabled=true;
  180. //
  181. // $this->assertNotEquals($original,$stored);
  182. // $fromFile=$rootView->file_get_contents($userDir.'/file');
  183. // $this->assertEquals($original,$fromFile);
  184. //
  185. // $fromFile=$view->file_get_contents('files/file');
  186. // $this->assertEquals($original,$fromFile);
  187. // }
  188. //
  189. // public function testBinary(){
  190. // $file=__DIR__.'/binary';
  191. // $original=file_get_contents($file);
  192. //
  193. // OC_Filesystem::file_put_contents('/file',$original);
  194. //
  195. // OC_FileProxy::$enabled=false;
  196. // $stored=OC_Filesystem::file_get_contents('/file');
  197. // OC_FileProxy::$enabled=true;
  198. //
  199. // $fromFile=OC_Filesystem::file_get_contents('/file');
  200. // $this->assertNotEquals($original,$stored);
  201. // $this->assertEquals(strlen($original),strlen($fromFile));
  202. // $this->assertEquals($original,$fromFile);
  203. //
  204. // $file=__DIR__.'/zeros';
  205. // $original=file_get_contents($file);
  206. //
  207. // OC_Filesystem::file_put_contents('/file',$original);
  208. //
  209. // OC_FileProxy::$enabled=false;
  210. // $stored=OC_Filesystem::file_get_contents('/file');
  211. // OC_FileProxy::$enabled=true;
  212. //
  213. // $fromFile=OC_Filesystem::file_get_contents('/file');
  214. // $this->assertNotEquals($original,$stored);
  215. // $this->assertEquals(strlen($original),strlen($fromFile));
  216. // }
  217. // }